@@ -725,6 +725,7 @@ declare_clippy_lint! {
725
725
/// **Known problems:** None.
726
726
///
727
727
/// **Example:**
728
+ /// In an impl block:
728
729
/// ```rust
729
730
/// # struct Foo;
730
731
/// # struct NotAFoo;
@@ -737,25 +738,40 @@ declare_clippy_lint! {
737
738
///
738
739
/// ```rust
739
740
/// # struct Foo;
740
- /// # struct FooError ;
741
+ /// struct Bar(Foo) ;
741
742
/// 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)
745
746
/// }
746
747
/// }
747
748
/// ```
748
749
///
749
750
/// ```rust
750
751
/// # struct Foo;
751
- /// struct Bar(Foo) ;
752
+ /// # struct FooError ;
752
753
/// 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)
756
757
/// }
757
758
/// }
758
759
/// ```
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
+ /// ```
759
775
pub NEW_RET_NO_SELF ,
760
776
style,
761
777
"not returning type containing `Self` in a `new` method"
@@ -1679,8 +1695,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1679
1695
1680
1696
fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx TraitItem < ' _ > ) {
1681
1697
if_chain ! {
1682
- if !in_external_macro( cx. tcx. sess, item. span) ;
1683
- if !item. span. from_expansion( ) ;
1684
1698
if item. ident. name == sym!( new) ;
1685
1699
if let TraitItemKind :: Fn ( FnSig { decl, .. } , _) = & item. kind;
1686
1700
if let FnRetTy :: Return ( ret_ty) = & decl. output;
0 commit comments