Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,7 @@ pub(crate) struct ReservedMultihashLint {

#[derive(Subdiagnostic)]
#[suggestion(
"if you meant to write a path, use a double colon:",
"if you meant to write a path, use a double colon",
code = "::",
applicability = "maybe-incorrect"
)]
Expand All @@ -4653,13 +4653,13 @@ pub(crate) struct UseDoubleColonSuggestion {

#[derive(Subdiagnostic)]
#[multipart_suggestion(
"if you meant to create a regular struct, use curly braces:",
"if you meant to create a regular struct, use curly braces",
applicability = "maybe-incorrect"
)]
pub(crate) struct UseRegularStructSuggestion {
#[suggestion_part(code = "{{")]
#[suggestion_part(code = " {{ ")]
pub open: Span,
#[suggestion_part(code = "}}")]
#[suggestion_part(code = " }}")]
pub close: Span,
#[suggestion_part(code = "")]
pub semicolon: Option<Span>,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,8 +2163,10 @@ impl<'a> Parser<'a> {
})
.map(|(r, _)| r)
.map_err(|mut error| {
if encountered_colon {
if self.token == token::Colon {
error.subdiagnostic(UseDoubleColonSuggestion { colon: self.token.span });
}
if encountered_colon {
self.eat_to_tokens(&[exp!(CloseParen)]);
self.bump();
error.subdiagnostic(UseRegularStructSuggestion {
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/parser/colon-in-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Suggest the user to use double colon when there's a colon in tuple struct

struct Foo(std::string:String);
//~^ ERROR expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
//~| HELP if you meant to write a path, use a double colon
13 changes: 13 additions & 0 deletions tests/ui/parser/colon-in-tuple-struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
--> $DIR/colon-in-tuple-struct.rs:3:23
|
LL | struct Foo(std::string:String);
| ^ expected one of 7 possible tokens
|
help: if you meant to write a path, use a double colon
|
LL | struct Foo(std::string::String);
| +

error: aborting due to 1 previous error

4 changes: 2 additions & 2 deletions tests/ui/parser/field-name-in-tuple-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

struct Foo(a:u8,b:u8);
//~^ ERROR expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
//~| HELP if you meant to write a path, use a double colon:
//~| HELP if you meant to create a regular struct, use curly braces:
//~| HELP if you meant to write a path, use a double colon
//~| HELP if you meant to create a regular struct, use curly braces
6 changes: 3 additions & 3 deletions tests/ui/parser/field-name-in-tuple-struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
LL | struct Foo(a:u8,b:u8);
| ^ expected one of 7 possible tokens
|
help: if you meant to write a path, use a double colon:
help: if you meant to write a path, use a double colon
|
LL | struct Foo(a::u8,b:u8);
| +
help: if you meant to create a regular struct, use curly braces:
help: if you meant to create a regular struct, use curly braces
|
LL - struct Foo(a:u8,b:u8);
LL + struct Foo{a:u8,b:u8}
LL + struct Foo { a:u8,b:u8 }
|

error: aborting due to 1 previous error
Expand Down
Loading