Skip to content

Commit

Permalink
Auto merge of rust-lang#5448 - Emerentius:update_new_ret_no_self_docs…
Browse files Browse the repository at this point in the history
…, 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 rust-lang#3338 (Related issue rust-lang#3313)
  • Loading branch information
bors committed Apr 13, 2020
2 parents 6d4cc56 + e98c7a4 commit 54344c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ declare_clippy_lint! {
}

declare_clippy_lint! {
/// **What it does:** Checks for `new` not returning `Self`.
/// **What it does:** Checks for `new` not returning a type that contains `Self`.
///
/// **Why is this bad?** As a convention, `new` methods are used to make a new
/// instance of a type.
Expand All @@ -747,9 +747,31 @@ declare_clippy_lint! {
/// }
/// }
/// ```
///
/// ```rust
/// # struct Foo;
/// # struct FooError;
/// impl Foo {
/// // Good. Return type contains `Self`
/// fn new() -> Result<Foo, FooError> {
/// # Ok(Foo)
/// }
/// }
/// ```
///
/// ```rust
/// # struct Foo;
/// struct Bar(Foo);
/// impl Foo {
/// // Bad. The type name must contain `Self`.
/// fn new() -> Bar {
/// # Bar(Foo)
/// }
/// }
/// ```
pub NEW_RET_NO_SELF,
style,
"not returning `Self` in a `new` method"
"not returning type containing `Self` in a `new` method"
}

declare_clippy_lint! {
Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
Lint {
name: "new_ret_no_self",
group: "style",
desc: "not returning `Self` in a `new` method",
desc: "not returning type containing `Self` in a `new` method",
deprecation: None,
module: "methods",
},
Expand Down

0 comments on commit 54344c7

Please sign in to comment.