mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
98332c108b
The current message for "`->` used for field access" is the following: ```rust error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->` --> src/main.rs:2:6 | 2 | a->b; | ^^ expected one of 8 possible tokens ``` (playground link[1]) This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is: ``` error: `->` used for field access or method call --> ./tiny_test.rs:2:6 | 2 | a->b; | ^^ help: try using `.` instead | = help: the `.` operator will dereference the value if needed ``` (feel free to bikeshed it as much as necessary) [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
34 lines
671 B
Rust
34 lines
671 B
Rust
//@ run-rustfix
|
|
#![allow(
|
|
dead_code,
|
|
unused_must_use
|
|
)]
|
|
|
|
struct Named {
|
|
foo: usize
|
|
}
|
|
|
|
struct Unnamed(usize);
|
|
|
|
fn named_struct_field_access(named: &Named) {
|
|
named->foo; //~ ERROR `->` used for field access or method call
|
|
}
|
|
|
|
fn unnamed_struct_field_access(unnamed: &Unnamed) {
|
|
unnamed->0; //~ ERROR `->` used for field access or method call
|
|
}
|
|
|
|
fn tuple_field_access(t: &(u8, u8)) {
|
|
t->0; //~ ERROR `->` used for field access or method call
|
|
t->1; //~ ERROR `->` used for field access or method call
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct Foo;
|
|
|
|
fn method_call(foo: &Foo) {
|
|
foo->clone(); //~ ERROR `->` used for field access or method call
|
|
}
|
|
|
|
fn main() {}
|