Skip to content

Commit f8ae2f5

Browse files
committed
fix box-default linting no_std non-boxes
1 parent 50f192f commit f8ae2f5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

clippy_lints/src/box_default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl LateLintPass<'_> for BoxDefault {
4646
&& !in_external_macro(cx.sess(), expr.span)
4747
&& (expr.span.eq_ctxt(arg.span) || is_vec_expn(cx, arg))
4848
&& seg.ident.name == sym::new
49-
&& path_def_id(cx, ty) == cx.tcx.lang_items().owned_box()
49+
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
5050
&& is_default_equivalent(cx, arg)
5151
{
5252
let arg_ty = cx.typeck_results().expr_ty(arg);

tests/ui/box_default_no_std.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(lang_items, start, libc)]
2+
#![warn(clippy::box_default)]
3+
#![no_std]
4+
5+
pub struct NotBox<T> {
6+
_value: T,
7+
}
8+
9+
impl<T> NotBox<T> {
10+
pub fn new(value: T) -> Self {
11+
Self { _value: value }
12+
}
13+
}
14+
15+
impl<T: Default> Default for NotBox<T> {
16+
fn default() -> Self {
17+
Self::new(T::default())
18+
}
19+
}
20+
21+
#[start]
22+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
23+
let _p = NotBox::new(isize::default());
24+
0
25+
}
26+
27+
#[panic_handler]
28+
fn panic(_info: &core::panic::PanicInfo) -> ! {
29+
loop {}
30+
}
31+
32+
#[lang = "eh_personality"]
33+
extern "C" fn eh_personality() {}

0 commit comments

Comments
 (0)