7
Recover from `&dyn mut ...` parse errors by FabianWolff · Pull Request #8681...
source link: https://github.com/rust-lang/rust/pull/86812
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Consider this example:
fn main() { let r: &dyn mut Trait; }
This currently leads to:
error: expected one of `!`, `(`, `;`, `=`, `?`, `for`, lifetime, or path, found keyword `mut`
--> src/main.rs:2:17
|
2 | let r: &dyn mut Trait;
| ^^^ expected one of 8 possible tokens
error: aborting due to previous error
However, especially for beginners, I think it is easy to get &dyn mut
and &mut dyn
confused. With my changes, I get a help message, and the parser even recovers:
error: `mut` must precede `dyn`
--> test.rs:2:12
|
2 | let r: &dyn mut Trait;
| ^^^^^^^^ help: place `mut` before `dyn`: `&mut dyn`
error[E0405]: cannot find trait `Trait` in this scope
--> test.rs:2:21
|
2 | let r: &dyn mut Trait;
| ^^^^^ not found in this scope
error: aborting due to 2 previous errors
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK