diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 9f2d29a1b63..865b1c987c8 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -116,6 +116,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { // can't be implemented by default return; } + if sig.header.unsafety == hir::Unsafety::Unsafe { + // can't be implemented for unsafe new + return; + } if impl_item.generics.params.iter().any(|gen| match gen.kind { hir::GenericParamKind::Type { .. } => true, _ => false diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 46d2bc45f68..7fa369354b3 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -101,4 +101,10 @@ pub trait TraitWithNew: Sized { } } +pub struct IgnoreUnsafeNew; + +impl IgnoreUnsafeNew { + pub unsafe fn new() -> Self { IgnoreUnsafeNew } +} + fn main() {}