}
}
- let ret_ty = return_ty(cx, implitem.id);
- if name == "new" &&
- !ret_ty.walk().any(|t| same_tys(cx, t, ty)) {
- span_lint(cx,
- NEW_RET_NO_SELF,
- implitem.span,
- "methods called `new` usually return `Self`");
+ 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)) {
+ span_lint(cx,
+ NEW_RET_NO_SELF,
+ implitem.span,
+ "methods called `new` usually return `Self`");
+ }
}
}
}
fn main(){}
-//trait R {
-// type Item;
-//}
-//
-//struct S;
-//
-//impl R for S {
-// type Item = Self;
-//}
-//
-//impl S {
-// // should not trigger the lint
-// pub fn new() -> impl R<Item = Self> {
-// S
-// }
-//}
-//
-//struct S2;
-//
-//impl R for S2 {
-// type Item = Self;
-//}
-//
-//impl S2 {
-// // should not trigger the lint
-// pub fn new(_: String) -> impl R<Item = Self> {
-// S2
-// }
-//}
-//
-//struct T;
-//
-//impl T {
-// // should not trigger lint
-// pub fn new() -> Self {
-// unimplemented!();
-// }
-//}
+trait R {
+ type Item;
+}
+
+struct S;
+
+impl R for S {
+ type Item = Self;
+}
+
+impl S {
+ // should not trigger the lint
+ pub fn new() -> impl R<Item = Self> {
+ S
+ }
+}
+
+struct S2;
+
+impl R for S2 {
+ type Item = Self;
+}
+
+impl S2 {
+ // should not trigger the lint
+ pub fn new(_: String) -> impl R<Item = Self> {
+ S2
+ }
+}
+
+struct T;
+
+impl T {
+ // should not trigger lint
+ pub fn new() -> Self {
+ unimplemented!();
+ }
+}
struct U;
--- /dev/null
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:51:5
+ |
+51 | / pub fn new() -> u32 {
+52 | | unimplemented!();
+53 | | }
+ | |_____^
+
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:60:5
+ |
+60 | / pub fn new(_: String) -> u32 {
+61 | | unimplemented!();
+62 | | }
+ | |_____^
+
+error: aborting due to 2 previous errors
+