Skip to content

Commit c9250fb

Browse files
committed
Auto merge of #5448 - Emerentius:update_new_ret_no_self_docs, r=phansch
Update documentation for new_ret_no_self changelog: Update documentation for lint new_ret_no_self to reflect that the return type must only contain `Self`, not be `Self` The lint was changed to be more lenient than the documentation implies in PR #3338 (Related issue #3313)
2 parents e29d550 + e98c7a4 commit c9250fb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Diff for: 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! {

Diff for: src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
14481448
Lint {
14491449
name: "new_ret_no_self",
14501450
group: "style",
1451-
desc: "not returning `Self` in a `new` method",
1451+
desc: "not returning type containing `Self` in a `new` method",
14521452
deprecation: None,
14531453
module: "methods",
14541454
},

0 commit comments

Comments
 (0)