Skip to content

Commit ed72dc4

Browse files
authored
Update documentation for new_ret_no_self
The lint was changed to be more lenient than the documentation implies in PR rust-lang#3338. Related issue rust-lang#3313
1 parent 34763a5 commit ed72dc4

File tree

1 file changed

+24
-2
lines changed
  • clippy_lints/src/methods

1 file changed

+24
-2
lines changed

clippy_lints/src/methods/mod.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ declare_clippy_lint! {
730730
}
731731

732732
declare_clippy_lint! {
733-
/// **What it does:** Checks for `new` not returning `Self`.
733+
/// **What it does:** Checks for `new` not returning a type that contains `Self`.
734734
///
735735
/// **Why is this bad?** As a convention, `new` methods are used to make a new
736736
/// instance of a type.
@@ -747,9 +747,31 @@ declare_clippy_lint! {
747747
/// }
748748
/// }
749749
/// ```
750+
///
751+
/// ```rust
752+
/// # struct Foo;
753+
/// # struct FooError;
754+
/// impl Foo {
755+
/// // Good. Return type contains `Self`
756+
/// fn new() -> Result<Foo, FooError> {
757+
/// # Ok(Foo)
758+
/// }
759+
/// }
760+
/// ```
761+
///
762+
/// ```rust
763+
/// # struct Foo;
764+
/// struct Bar(Foo);
765+
/// impl Foo {
766+
/// // Bad. The type name must contain `Self`.
767+
/// fn new() -> Bar {
768+
/// # Bar(Foo)
769+
/// }
770+
/// }
771+
/// ```
750772
pub NEW_RET_NO_SELF,
751773
style,
752-
"not returning `Self` in a `new` method"
774+
"not returning type containing `Self` in a `new` method"
753775
}
754776

755777
declare_clippy_lint! {

0 commit comments

Comments
 (0)