Rollup merge of #94839 - TaKO8Ki:suggest-using-double-colon-for-struct-field-type, r=cjgillot
Suggest using double colon when a struct field type include single colon #92685
This commit is contained in:
commit
298c9a0e14
3 changed files with 66 additions and 0 deletions
|
@ -1534,6 +1534,16 @@ impl<'a> Parser<'a> {
|
||||||
let name = self.parse_field_ident(adt_ty, lo)?;
|
let name = self.parse_field_ident(adt_ty, lo)?;
|
||||||
self.expect_field_ty_separator()?;
|
self.expect_field_ty_separator()?;
|
||||||
let ty = self.parse_ty()?;
|
let ty = self.parse_ty()?;
|
||||||
|
if self.token.kind == token::Colon && self.look_ahead(1, |tok| tok.kind != token::Colon) {
|
||||||
|
self.struct_span_err(self.token.span, "found single colon in a struct field type path")
|
||||||
|
.span_suggestion_verbose(
|
||||||
|
self.token.span,
|
||||||
|
"write a path separator here",
|
||||||
|
"::".to_string(),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
if self.token.kind == token::Eq {
|
if self.token.kind == token::Eq {
|
||||||
self.bump();
|
self.bump();
|
||||||
let const_expr = self.parse_anon_const_expr()?;
|
let const_expr = self.parse_anon_const_expr()?;
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
mod foo {
|
||||||
|
struct A;
|
||||||
|
mod bar {
|
||||||
|
struct B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
a: foo:A,
|
||||||
|
//~^ ERROR found single colon in a struct field type path
|
||||||
|
//~| expected `,`, or `}`, found `:`
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
b: foo::bar:B,
|
||||||
|
//~^ ERROR found single colon in a struct field type path
|
||||||
|
//~| expected `,`, or `}`, found `:`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,36 @@
|
||||||
|
error: found single colon in a struct field type path
|
||||||
|
--> $DIR/struct-field-type-including-single-colon.rs:9:11
|
||||||
|
|
|
||||||
|
LL | a: foo:A,
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
help: write a path separator here
|
||||||
|
|
|
||||||
|
LL | a: foo::A,
|
||||||
|
| ~~
|
||||||
|
|
||||||
|
error: expected `,`, or `}`, found `:`
|
||||||
|
--> $DIR/struct-field-type-including-single-colon.rs:9:11
|
||||||
|
|
|
||||||
|
LL | a: foo:A,
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: found single colon in a struct field type path
|
||||||
|
--> $DIR/struct-field-type-including-single-colon.rs:15:16
|
||||||
|
|
|
||||||
|
LL | b: foo::bar:B,
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
help: write a path separator here
|
||||||
|
|
|
||||||
|
LL | b: foo::bar::B,
|
||||||
|
| ~~
|
||||||
|
|
||||||
|
error: expected `,`, or `}`, found `:`
|
||||||
|
--> $DIR/struct-field-type-including-single-colon.rs:15:16
|
||||||
|
|
|
||||||
|
LL | b: foo::bar:B,
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue