diff options
| author | Philipp Hansch <dev@phansch.net> | 2018-10-07 13:09:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-07 13:09:37 +0100 |
| commit | 63ceabf0cf5758fa513b12b648608db7ff6f5166 (patch) | |
| tree | 28fff58fe4c6e430e2959e1bfd9514ff6ce4b601 | |
| parent | 5dcb90e29d1ce220c2729908ec1fb585a72d540f (diff) | |
| parent | 59c4ff77f10deab8ff216f5019acf5a60ad77447 (diff) | |
| download | rust-63ceabf0cf5758fa513b12b648608db7ff6f5166.tar.gz rust-63ceabf0cf5758fa513b12b648608db7ff6f5166.zip | |
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
| -rw-r--r-- | clippy_lints/src/new_without_default.rs | 4 | ||||
| -rw-r--r-- | tests/ui/new_without_default.rs | 6 |
2 files changed, 10 insertions, 0 deletions
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() {} |
