diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 59c55168232..035ca2b0496 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1920,7 +1920,6 @@ enum ImplicitHasherType<'tcx> { impl<'tcx> ImplicitHasherType<'tcx> { /// Checks that `ty` is a target type without a BuildHasher. - #[allow(clippy::new_ret_no_self)] fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty) -> Option { if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.node { let params: Vec<_> = path.segments.last().as_ref()?.args.as_ref()? diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index b267a3aecdf..b7daf3d49bc 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -140,3 +140,24 @@ impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { unimplemented!(); } } + +struct GenericReturnerOk; + +impl GenericReturnerOk { + // should not trigger lint + pub fn new() -> Option { unimplemented!(); } +} + +struct GenericReturnerBad; + +impl GenericReturnerBad { + // should trigger lint + pub fn new() -> Option { unimplemented!(); } +} + +struct NestedReturnerOk; + +impl NestedReturnerOk { + // should trigger lint + pub fn new() -> (Option, u32) { unimplemented!(); } +} diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 20f0dbbe8a3..bab9627ca22 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -36,5 +36,11 @@ error: methods called `new` usually return `Self` 141 | pub fn new() -> *mut V { unimplemented!(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: methods called `new` usually return `Self` + --> $DIR/new_ret_no_self.rs:155:5 + | +155 | pub fn new() -> Option { unimplemented!(); } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors