new_ret_no_self added test cases

This commit is contained in:
Josh Mcguigan 2018-10-20 06:29:17 -07:00
parent 079f9f45b5
commit a624583557
3 changed files with 28 additions and 2 deletions

View file

@ -1920,7 +1920,6 @@ enum ImplicitHasherType<'tcx> {
impl<'tcx> ImplicitHasherType<'tcx> { impl<'tcx> ImplicitHasherType<'tcx> {
/// Checks that `ty` is a target type without a BuildHasher. /// 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<Self> { fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty) -> Option<Self> {
if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.node { if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.node {
let params: Vec<_> = path.segments.last().as_ref()?.args.as_ref()? let params: Vec<_> = path.segments.last().as_ref()?.args.as_ref()?

View file

@ -140,3 +140,24 @@ impl MutPointerReturnerBad {
// should trigger lint // should trigger lint
pub fn new() -> *mut V { unimplemented!(); } pub fn new() -> *mut V { unimplemented!(); }
} }
struct GenericReturnerOk;
impl GenericReturnerOk {
// should not trigger lint
pub fn new() -> Option<Self> { unimplemented!(); }
}
struct GenericReturnerBad;
impl GenericReturnerBad {
// should trigger lint
pub fn new() -> Option<u32> { unimplemented!(); }
}
struct NestedReturnerOk;
impl NestedReturnerOk {
// should trigger lint
pub fn new() -> (Option<Self>, u32) { unimplemented!(); }
}

View file

@ -36,5 +36,11 @@ error: methods called `new` usually return `Self`
141 | pub fn new() -> *mut V { unimplemented!(); } 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<u32> { unimplemented!(); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 6 previous errors