-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6093 - ebroto:6089_renamed_lifetimes, r=Manishearth
needless arbitrary self: handle macros This fixes two cases related to macros: * If the parameter comes from expansion, do not lint as the user has no possibility of changing it. This is not directly related to the fixed issue, but we should probably do that. * If *only* the lifetime name comes from expansion, lint, but allow the user decide the name of the lifetime. In the related issue, the lifetime was unnamed and then renamed by `async_trait`, so just removing the name in the suggestion would work, but in the general case a macro can rename a lifetime that was named differently, and we can't reliably know that name anymore. As a hint for the reviewer, the expanded code for the test can be checked with this command (from the root dir of the repo): ```sh rustc -L target/debug/test_build_base/needless_arbitrary_self_type_unfixable.stage-id.aux -Zunpretty=expanded tests/ui/needless_arbitrary_self_type_unfixable.rs ``` changelog: [`needless_arbitrary_self_type`]: handle macros Fixes #6089
- Loading branch information
Showing
4 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// aux-build:proc_macro_attr.rs | ||
|
||
#![warn(clippy::needless_arbitrary_self_type)] | ||
|
||
#[macro_use] | ||
extern crate proc_macro_attr; | ||
|
||
mod issue_6089 { | ||
// Check that we don't lint if the `self` parameter comes from expansion | ||
|
||
macro_rules! test_from_expansion { | ||
() => { | ||
trait T1 { | ||
fn test(self: &Self); | ||
} | ||
|
||
struct S1 {} | ||
|
||
impl T1 for S1 { | ||
fn test(self: &Self) {} | ||
} | ||
}; | ||
} | ||
|
||
test_from_expansion!(); | ||
|
||
// If only the lifetime name comes from expansion we will lint, but the suggestion will have | ||
// placeholders and will not be applied automatically, as we can't reliably know the original name. | ||
// This specific case happened with async_trait. | ||
|
||
trait T2 { | ||
fn call_with_mut_self(&mut self); | ||
} | ||
|
||
struct S2 {} | ||
|
||
// The method's signature will be expanded to: | ||
// fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} | ||
#[rename_my_lifetimes] | ||
impl T2 for S2 { | ||
fn call_with_mut_self(self: &mut Self) {} | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: the type of the `self` parameter does not need to be arbitrary | ||
--> $DIR/needless_arbitrary_self_type_unfixable.rs:41:31 | ||
| | ||
LL | fn call_with_mut_self(self: &mut Self) {} | ||
| ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'_ mut self` | ||
| | ||
= note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|