-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest replacing .
with ::
in more error diagnostics.
#136344
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe37ada
Suggest using :: instead of . in more cases.
zachs18 bfde43c
Suggest using :: instead of . for enums in some cases.
zachs18 ae7b45a
When giving a suggestion to use :: instead of . where the rhs is a ma…
zachs18 2c37250
Update `.` -> `::` tests for new diff suggestion format.
zachs18 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
123 changes: 123 additions & 0 deletions
123
tests/ui/resolve/dot-notation-type-namespace-suggest-path-sep.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,123 @@ | ||
// see also https://github.com/rust-lang/rust/issues/22692 | ||
|
||
type Alias = Vec<u32>; | ||
|
||
mod foo { | ||
fn bar() {} | ||
} | ||
|
||
fn main() { | ||
let _ = String.new(); | ||
//~^ ERROR expected value, found struct `String` | ||
//~| HELP use the path separator | ||
|
||
let _ = String.default; | ||
//~^ ERROR expected value, found struct `String` | ||
//~| HELP use the path separator | ||
|
||
let _ = Vec::<()>.with_capacity(1); | ||
//~^ ERROR expected value, found struct `Vec` | ||
//~| HELP use the path separator | ||
|
||
let _ = Alias.new(); | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| HELP use the path separator | ||
|
||
let _ = Alias.default; | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| HELP use the path separator | ||
|
||
let _ = foo.bar; | ||
//~^ ERROR expected value, found module `foo` | ||
//~| HELP use the path separator | ||
} | ||
|
||
macro_rules! Type { | ||
() => { | ||
::std::cell::Cell | ||
//~^ ERROR expected value, found struct `std::cell::Cell` | ||
//~| ERROR expected value, found struct `std::cell::Cell` | ||
//~| ERROR expected value, found struct `std::cell::Cell` | ||
}; | ||
(alias) => { | ||
Alias | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| ERROR expected value, found type alias `Alias` | ||
//~| ERROR expected value, found type alias `Alias` | ||
}; | ||
} | ||
|
||
macro_rules! create { | ||
(type method) => { | ||
Vec.new() | ||
//~^ ERROR expected value, found struct `Vec` | ||
//~| HELP use the path separator | ||
}; | ||
(type field) => { | ||
Vec.new | ||
//~^ ERROR expected value, found struct `Vec` | ||
//~| HELP use the path separator | ||
}; | ||
(macro method) => { | ||
Type!().new(0) | ||
//~^ HELP use the path separator | ||
}; | ||
(macro method alias) => { | ||
Type!(alias).new(0) | ||
//~^ HELP use the path separator | ||
}; | ||
} | ||
|
||
macro_rules! check_ty { | ||
($Ty:ident) => { | ||
$Ty.foo | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| HELP use the path separator | ||
}; | ||
} | ||
macro_rules! check_ident { | ||
($Ident:ident) => { | ||
Alias.$Ident | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| HELP use the path separator | ||
}; | ||
} | ||
macro_rules! check_ty_ident { | ||
($Ty:ident, $Ident:ident) => { | ||
$Ty.$Ident | ||
//~^ ERROR expected value, found type alias `Alias` | ||
//~| HELP use the path separator | ||
}; | ||
} | ||
|
||
fn interaction_with_macros() { | ||
// | ||
// Verify that we do not only suggest to replace `.` with `::` if the receiver is a | ||
// macro call but that we also correctly suggest to surround it with angle brackets. | ||
// | ||
|
||
Type!().get(); | ||
//~^ HELP use the path separator | ||
|
||
Type! {}.get; | ||
//~^ HELP use the path separator | ||
|
||
Type!(alias).get(); | ||
//~^ HELP use the path separator | ||
|
||
Type! {alias}.get; | ||
//~^ HELP use the path separator | ||
|
||
// | ||
// Ensure that the suggestion is shown for expressions inside of macro definitions. | ||
// | ||
|
||
let _ = create!(type method); | ||
let _ = create!(type field); | ||
let _ = create!(macro method); | ||
let _ = create!(macro method alias); | ||
|
||
let _ = check_ty!(Alias); | ||
let _ = check_ident!(foo); | ||
let _ = check_ty_ident!(Alias, foo); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.