Skip to content

Commit 298c9a0

Browse files
authored
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
2 parents ad51354 + 813f00d commit 298c9a0

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

compiler/rustc_parse/src/parser/item.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,16 @@ impl<'a> Parser<'a> {
15341534
let name = self.parse_field_ident(adt_ty, lo)?;
15351535
self.expect_field_ty_separator()?;
15361536
let ty = self.parse_ty()?;
1537+
if self.token.kind == token::Colon && self.look_ahead(1, |tok| tok.kind != token::Colon) {
1538+
self.struct_span_err(self.token.span, "found single colon in a struct field type path")
1539+
.span_suggestion_verbose(
1540+
self.token.span,
1541+
"write a path separator here",
1542+
"::".to_string(),
1543+
Applicability::MaybeIncorrect,
1544+
)
1545+
.emit();
1546+
}
15371547
if self.token.kind == token::Eq {
15381548
self.bump();
15391549
let const_expr = self.parse_anon_const_expr()?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
mod foo {
2+
struct A;
3+
mod bar {
4+
struct B;
5+
}
6+
}
7+
8+
struct Foo {
9+
a: foo:A,
10+
//~^ ERROR found single colon in a struct field type path
11+
//~| expected `,`, or `}`, found `:`
12+
}
13+
14+
struct Bar {
15+
b: foo::bar:B,
16+
//~^ ERROR found single colon in a struct field type path
17+
//~| expected `,`, or `}`, found `:`
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: found single colon in a struct field type path
2+
--> $DIR/struct-field-type-including-single-colon.rs:9:11
3+
|
4+
LL | a: foo:A,
5+
| ^
6+
|
7+
help: write a path separator here
8+
|
9+
LL | a: foo::A,
10+
| ~~
11+
12+
error: expected `,`, or `}`, found `:`
13+
--> $DIR/struct-field-type-including-single-colon.rs:9:11
14+
|
15+
LL | a: foo:A,
16+
| ^
17+
18+
error: found single colon in a struct field type path
19+
--> $DIR/struct-field-type-including-single-colon.rs:15:16
20+
|
21+
LL | b: foo::bar:B,
22+
| ^
23+
|
24+
help: write a path separator here
25+
|
26+
LL | b: foo::bar::B,
27+
| ~~
28+
29+
error: expected `,`, or `}`, found `:`
30+
--> $DIR/struct-field-type-including-single-colon.rs:15:16
31+
|
32+
LL | b: foo::bar:B,
33+
| ^
34+
35+
error: aborting due to 4 previous errors
36+

0 commit comments

Comments
 (0)