diff options
| author | Josh Mcguigan <joshmcg88@gmail.com> | 2018-10-03 04:59:14 -0700 |
|---|---|---|
| committer | Josh Mcguigan <joshmcg88@gmail.com> | 2018-10-13 06:20:39 -0700 |
| commit | 1c4fa419f33211db3fa60f3bc8d59a8f42992558 (patch) | |
| tree | 02eae0959335c516cbd3aa92f2ce13d961d0f577 | |
| parent | 13ce96c4bfd236ec49bcd7b63f42f9a51b0ee599 (diff) | |
| download | rust-1c4fa419f33211db3fa60f3bc8d59a8f42992558.tar.gz rust-1c4fa419f33211db3fa60f3bc8d59a8f42992558.zip | |
new_ret_no_self fix false positive for impl trait return with associated type self
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 3 | ||||
| -rw-r--r-- | tests/ui/new_ret_no_self.rs | 13 | ||||
| -rw-r--r-- | tests/ui/new_ret_no_self.stderr | 18 |
3 files changed, 25 insertions, 9 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 81cb1cd1182..7426ece5ba9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -934,7 +934,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if let hir::ImplItemKind::Method(ref sig, id) = implitem.node { let ret_ty = return_ty(cx, implitem.id); if name == "new" && - !ret_ty.walk().any(|t| same_tys(cx, t, ty)) { + !same_tys(cx, ret_ty, ty) && + !ret_ty.is_impl_trait() { span_lint(cx, NEW_RET_NO_SELF, implitem.span, diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 762dd582168..3b7ff7780ef 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -35,6 +35,19 @@ impl S2 { } } +struct S3; + +impl R for S3 { + type Item = u32; +} + +impl S3 { + // should trigger the lint, but currently does not + pub fn new(_: String) -> impl R<Item = u32> { + S3 + } +} + struct T; impl T { diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 1d698892449..cab5fa55cb6 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -1,17 +1,19 @@ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:51:5 + --> $DIR/new_ret_no_self.rs:64:5 | -51 | / pub fn new() -> u32 { -52 | | unimplemented!(); -53 | | } +64 | / pub fn new() -> u32 { +65 | | unimplemented!(); +66 | | } | |_____^ + | + = note: `-D clippy::new-ret-no-self` implied by `-D warnings` error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:60:5 + --> $DIR/new_ret_no_self.rs:73:5 | -60 | / pub fn new(_: String) -> u32 { -61 | | unimplemented!(); -62 | | } +73 | / pub fn new(_: String) -> u32 { +74 | | unimplemented!(); +75 | | } | |_____^ error: aborting due to 2 previous errors |
