mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
fix box-default
linting no_std
non-boxes
This commit is contained in:
parent
50f192f86a
commit
f8ae2f5807
2 changed files with 34 additions and 1 deletions
|
@ -46,7 +46,7 @@ impl LateLintPass<'_> for BoxDefault {
|
|||
&& !in_external_macro(cx.sess(), expr.span)
|
||||
&& (expr.span.eq_ctxt(arg.span) || is_vec_expn(cx, arg))
|
||||
&& seg.ident.name == sym::new
|
||||
&& path_def_id(cx, ty) == cx.tcx.lang_items().owned_box()
|
||||
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
|
||||
&& is_default_equivalent(cx, arg)
|
||||
{
|
||||
let arg_ty = cx.typeck_results().expr_ty(arg);
|
||||
|
|
33
tests/ui/box_default_no_std.rs
Normal file
33
tests/ui/box_default_no_std.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
#![feature(lang_items, start, libc)]
|
||||
#![warn(clippy::box_default)]
|
||||
#![no_std]
|
||||
|
||||
pub struct NotBox<T> {
|
||||
_value: T,
|
||||
}
|
||||
|
||||
impl<T> NotBox<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
Self { _value: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default> Default for NotBox<T> {
|
||||
fn default() -> Self {
|
||||
Self::new(T::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
let _p = NotBox::new(isize::default());
|
||||
0
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
Loading…
Reference in a new issue