-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure
#[rustc_confusables]
attribute to allow targeted
"no method" errors on standard library types The standard library developer can annotate methods on e.g. `BTreeSet::push` with `#[rustc_confusables("insert")]`. When the user mistypes `btreeset.push()`, `BTreeSet::insert` will be suggested if there are no other candidates to suggest.
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 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
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
11 changes: 11 additions & 0 deletions
11
tests/ui/attributes/auxiliary/rustc_confusables_across_crate.rs
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,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 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,20 @@ | ||
// aux-build: rustc_confusables_across_crate.rs | ||
|
||
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 | ||
x.foo(); | ||
//~^ ERROR no method named | ||
x.push(); | ||
//~^ ERROR no method named | ||
x.test(); | ||
//~^ ERROR no method named | ||
x.pulled(); | ||
//~^ ERROR no method named | ||
} |
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,38 @@ | ||
error[E0599]: no method named `inser` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope | ||
--> $DIR/rustc_confusables.rs:10: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:12: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:14: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:16: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:18:7 | ||
| | ||
LL | x.pulled(); | ||
| ^^^^^^ help: there is a method with a similar name: `pull` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |