-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add #[rustc_confusables]
attribute to allow targeted "no method" error suggestions on standard library types
#112239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 1 commit into
rust-lang:master
from
jieyouxu:targeted-no-method-suggestions
Jul 16, 2023
+259
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
tests/ui/attributes/auxiliary/rustc_confusables_across_crate.rs
This file contains hidden or 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,11 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
pub struct BTreeSet; | ||
|
||
impl BTreeSet { | ||
#[rustc_confusables("push", "test_b")] | ||
pub fn insert(&self) {} | ||
|
||
#[rustc_confusables("pulled")] | ||
pub fn pull(&self) {} | ||
} |
This file contains hidden or 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,47 @@ | ||
// aux-build: rustc_confusables_across_crate.rs | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
extern crate rustc_confusables_across_crate; | ||
|
||
use rustc_confusables_across_crate::BTreeSet; | ||
|
||
fn main() { | ||
// Misspellings (similarly named methods) take precedence over `rustc_confusables`. | ||
let x = BTreeSet {}; | ||
x.inser(); | ||
//~^ ERROR no method named | ||
cjgillot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//~| HELP there is a method with a similar name | ||
x.foo(); | ||
//~^ ERROR no method named | ||
x.push(); | ||
//~^ ERROR no method named | ||
//~| HELP you might have meant to use `insert` | ||
x.test(); | ||
//~^ ERROR no method named | ||
x.pulled(); | ||
//~^ ERROR no method named | ||
//~| HELP there is a method with a similar name | ||
} | ||
|
||
struct Bar; | ||
|
||
impl Bar { | ||
#[rustc_confusables()] | ||
//~^ ERROR expected at least one confusable name | ||
fn baz() {} | ||
|
||
#[rustc_confusables] | ||
//~^ ERROR malformed `rustc_confusables` attribute input | ||
//~| HELP must be of the form | ||
fn qux() {} | ||
|
||
#[rustc_confusables(invalid_meta_item)] | ||
//~^ ERROR expected a quoted string literal | ||
//~| HELP consider surrounding this with quotes | ||
fn quux() {} | ||
} | ||
|
||
#[rustc_confusables("blah")] | ||
//~^ ERROR attribute should be applied to an inherent method | ||
fn not_inherent_impl_method() {} |
This file contains hidden or 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,68 @@ | ||
error: malformed `rustc_confusables` attribute input | ||
--> $DIR/rustc_confusables.rs:34:5 | ||
| | ||
LL | #[rustc_confusables] | ||
| ^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_confusables("name1", "name2", ...)]` | ||
|
||
error: attribute should be applied to an inherent method | ||
--> $DIR/rustc_confusables.rs:45:1 | ||
| | ||
LL | #[rustc_confusables("blah")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: expected at least one confusable name | ||
--> $DIR/rustc_confusables.rs:30:5 | ||
| | ||
LL | #[rustc_confusables()] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0539]: expected a quoted string literal | ||
--> $DIR/rustc_confusables.rs:39:25 | ||
| | ||
LL | #[rustc_confusables(invalid_meta_item)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider surrounding this with quotes | ||
| | ||
LL | #[rustc_confusables("invalid_meta_item")] | ||
| + + | ||
|
||
error[E0599]: no method named `inser` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:12:7 | ||
| | ||
LL | x.inser(); | ||
| ^^^^^ help: there is a method with a similar name: `insert` | ||
|
||
error[E0599]: no method named `foo` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:15:7 | ||
| | ||
LL | x.foo(); | ||
| ^^^ method not found in `BTreeSet` | ||
|
||
error[E0599]: no method named `push` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:17:7 | ||
| | ||
LL | x.push(); | ||
| ^^^^ method not found in `BTreeSet` | ||
| | ||
help: you might have meant to use `insert` | ||
| | ||
LL | x.insert(); | ||
| ~~~~~~ | ||
|
||
error[E0599]: no method named `test` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:20:7 | ||
| | ||
LL | x.test(); | ||
| ^^^^ method not found in `BTreeSet` | ||
|
||
error[E0599]: no method named `pulled` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:22:7 | ||
| | ||
LL | x.pulled(); | ||
| ^^^^^^ help: there is a method with a similar name: `pull` | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
Some errors have detailed explanations: E0539, E0599. | ||
For more information about an error, try `rustc --explain E0539`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think while it makes sense to have
#[rustc_confusables]
because#[doc(alias)]
pollutes the search, it still makes sense to actually check both for diagnostics, so that we don't have to write 2 annotations when#[doc(alias)]
is already presentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe #107108 already makes the
#[doc(alias)]
check to make suggestions.#[rustc_confusables]
shouldn't trigger if anysimilar_candidate
was present to make the#[doc(alias)]
"there is a similar method named ..." suggestion.