@@ -725,6 +725,7 @@ declare_clippy_lint! {
725725 /// **Known problems:** None.
726726 ///
727727 /// **Example:**
728+ /// In an impl block:
728729 /// ```rust
729730 /// # struct Foo;
730731 /// # struct NotAFoo;
@@ -737,25 +738,40 @@ declare_clippy_lint! {
737738 ///
738739 /// ```rust
739740 /// # struct Foo;
740- /// # struct FooError ;
741+ /// struct Bar(Foo) ;
741742 /// impl Foo {
742- /// // Good. Return type contains `Self`
743- /// fn new() -> Result<Foo, FooError> {
744- /// # Ok (Foo)
743+ /// // Bad. The type name must contain `Self`
744+ /// fn new() -> Bar {
745+ /// # Bar (Foo)
745746 /// }
746747 /// }
747748 /// ```
748749 ///
749750 /// ```rust
750751 /// # struct Foo;
751- /// struct Bar(Foo) ;
752+ /// # struct FooError ;
752753 /// impl Foo {
753- /// // Bad. The type name must contain `Self`.
754- /// fn new() -> Bar {
755- /// # Bar (Foo)
754+ /// // Good. Return type contains `Self`
755+ /// fn new() -> Result<Foo, FooError> {
756+ /// # Ok (Foo)
756757 /// }
757758 /// }
758759 /// ```
760+ ///
761+ /// Or in a trait definition:
762+ /// ```rust
763+ /// pub trait Trait {
764+ /// // Bad. The type name must contain `Self`
765+ /// fn new();
766+ /// }
767+ /// ```
768+ ///
769+ /// ```rust
770+ /// pub trait Trait {
771+ /// // Good. Return type contains `Self`
772+ /// fn new() -> Self;
773+ /// }
774+ /// ```
759775 pub NEW_RET_NO_SELF ,
760776 style,
761777 "not returning type containing `Self` in a `new` method"
@@ -1679,8 +1695,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16791695
16801696 fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx TraitItem < ' _ > ) {
16811697 if_chain ! {
1682- if !in_external_macro( cx. tcx. sess, item. span) ;
1683- if !item. span. from_expansion( ) ;
16841698 if item. ident. name == sym!( new) ;
16851699 if let TraitItemKind :: Fn ( FnSig { decl, .. } , _) = & item. kind;
16861700 if let FnRetTy :: Return ( ret_ty) = & decl. output;
0 commit comments