forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#100367 - fmease:fix-100365, r=compiler-errors
Suggest the path separator when a dot is used on a trait Fixes rust-lang#100365. `@rustbot` label A-diagnostics r? diagnostics
- Loading branch information
Showing
9 changed files
with
394 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
fn main() { | ||
let addr = Into::<std::net::IpAddr>.into([127, 0, 0, 1]); | ||
//~^ ERROR expected value, found trait `Into` | ||
//~| HELP use the path separator | ||
|
||
let _ = Into.into(()); | ||
//~^ ERROR expected value, found trait `Into` | ||
//~| HELP use the path separator | ||
|
||
let _ = Into::<()>.into; | ||
//~^ ERROR expected value, found trait `Into` | ||
//~| HELP use the path separator | ||
} | ||
|
||
macro_rules! Trait { | ||
() => { | ||
::std::iter::Iterator | ||
//~^ ERROR expected value, found trait `std::iter::Iterator` | ||
//~| ERROR expected value, found trait `std::iter::Iterator` | ||
}; | ||
} | ||
|
||
macro_rules! create { | ||
() => { | ||
Into::<String>.into("") | ||
//~^ ERROR expected value, found trait `Into` | ||
//~| HELP use the path separator | ||
}; | ||
} | ||
|
||
fn interaction_with_macros() { | ||
// | ||
// Note that if the receiver is a macro call, we do not want to suggest to replace | ||
// `.` with `::` as that would be a syntax error. | ||
// Since the receiver is a trait and not a type, we cannot suggest to surround | ||
// it with angle brackets. It would be interpreted as a trait object type void of | ||
// `dyn` which is most likely not what the user intended to write. | ||
// `<_ as Trait!()>::` is also not an option as it's equally syntactically invalid. | ||
// | ||
|
||
Trait!().map(std::convert::identity); // no `help` here! | ||
|
||
Trait!().map; // no `help` here! | ||
|
||
// | ||
// Ensure that the suggestion is shown for expressions inside of macro definitions. | ||
// | ||
|
||
let _ = create!(); | ||
} |
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,54 @@ | ||
error[E0423]: expected value, found trait `Into` | ||
--> $DIR/issue-100365.rs:2:16 | ||
| | ||
LL | let addr = Into::<std::net::IpAddr>.into([127, 0, 0, 1]); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` | ||
|
||
error[E0423]: expected value, found trait `Into` | ||
--> $DIR/issue-100365.rs:6:13 | ||
| | ||
LL | let _ = Into.into(()); | ||
| ^^^^- help: use the path separator to refer to an item: `::` | ||
|
||
error[E0423]: expected value, found trait `Into` | ||
--> $DIR/issue-100365.rs:10:13 | ||
| | ||
LL | let _ = Into::<()>.into; | ||
| ^^^^^^^^^^- help: use the path separator to refer to an item: `::` | ||
|
||
error[E0423]: expected value, found trait `std::iter::Iterator` | ||
--> $DIR/issue-100365.rs:17:9 | ||
| | ||
LL | ::std::iter::Iterator | ||
| ^^^^^^^^^^^^^^^^^^^^^ not a value | ||
... | ||
LL | Trait!().map(std::convert::identity); // no `help` here! | ||
| -------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `Trait` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0423]: expected value, found trait `std::iter::Iterator` | ||
--> $DIR/issue-100365.rs:17:9 | ||
| | ||
LL | ::std::iter::Iterator | ||
| ^^^^^^^^^^^^^^^^^^^^^ not a value | ||
... | ||
LL | Trait!().map; // no `help` here! | ||
| -------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `Trait` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0423]: expected value, found trait `Into` | ||
--> $DIR/issue-100365.rs:25:9 | ||
| | ||
LL | Into::<String>.into("") | ||
| ^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` | ||
... | ||
LL | let _ = create!(); | ||
| --------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0423`. |
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 |
---|---|---|
@@ -1,3 +1,60 @@ | ||
fn main() { | ||
let _ = String.new(); //~ ERROR expected value, found struct `String` | ||
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 | ||
} | ||
|
||
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` | ||
}; | ||
} | ||
|
||
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 | ||
}; | ||
} | ||
|
||
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 | ||
|
||
// | ||
// Ensure that the suggestion is shown for expressions inside of macro definitions. | ||
// | ||
|
||
let _ = create!(type method); | ||
let _ = create!(type field); | ||
let _ = create!(macro method); | ||
} |
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
Oops, something went wrong.