Skip to content

Commit 63ceabf

Browse files
authored
Merge pull request #3280 from d-dorazio/fix-new_without_default-should-not-fire-unsafe-new
new_without_default should not warn about unsafe new
2 parents 5dcb90e + 59c4ff7 commit 63ceabf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clippy_lints/src/new_without_default.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
116116
// can't be implemented by default
117117
return;
118118
}
119+
if sig.header.unsafety == hir::Unsafety::Unsafe {
120+
// can't be implemented for unsafe new
121+
return;
122+
}
119123
if impl_item.generics.params.iter().any(|gen| match gen.kind {
120124
hir::GenericParamKind::Type { .. } => true,
121125
_ => false

tests/ui/new_without_default.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ pub trait TraitWithNew: Sized {
101101
}
102102
}
103103

104+
pub struct IgnoreUnsafeNew;
105+
106+
impl IgnoreUnsafeNew {
107+
pub unsafe fn new() -> Self { IgnoreUnsafeNew }
108+
}
109+
104110
fn main() {}

0 commit comments

Comments
 (0)