From 59c4ff77f10deab8ff216f5019acf5a60ad77447 Mon Sep 17 00:00:00 2001 From: Daniele D'Orazio Date: Sun, 7 Oct 2018 12:39:54 +0200 Subject: [PATCH] new_without_default should not warn about unsafe new --- clippy_lints/src/new_without_default.rs | 4 ++++ tests/ui/new_without_default.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 9f2d29a1b..865b1c987 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 46d2bc45f..7fa369354 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() {}