new_ret_no_self fix false positive for impl trait return with associated type self

This commit is contained in:
Josh Mcguigan 2018-10-03 04:59:14 -07:00
parent 13ce96c4bf
commit 1c4fa419f3
3 changed files with 25 additions and 9 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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