Skip to content

Commit db2f3d7

Browse files
committed
clarify why we're suggesting removing semicolon after braced items
Previously (issue rust-lang#46186, pull-request rust-lang#46258), a suggestion was added to remove the semicolon after we fail to parse an item, but issue rust-lang#51603 complains that it's still insufficiently obvious why. Let's add a note. Resolves rust-lang#51603.
1 parent 8772747 commit db2f3d7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/libsyntax/parse/parser.rs

+16
Original file line numberDiff line numberDiff line change
@@ -6132,6 +6132,22 @@ impl<'a> Parser<'a> {
61326132
err.span_suggestion_short_with_applicability(
61336133
self.span, msg, "".to_string(), Applicability::MachineApplicable
61346134
);
6135+
if !items.is_empty() { // Issue #51603
6136+
let previous_item = &items[items.len()-1];
6137+
let previous_item_kind_name = match previous_item.node {
6138+
// say "braced struct" because tuple-structs and
6139+
// braceless-empty-struct declarations do take a semicolon
6140+
ItemKind::Struct(..) => Some("braced struct"),
6141+
ItemKind::Enum(..) => Some("enum"),
6142+
ItemKind::Trait(..) => Some("trait"),
6143+
ItemKind::Union(..) => Some("union"),
6144+
_ => None,
6145+
};
6146+
if let Some(name) = previous_item_kind_name {
6147+
err.help(&format!("{} declarations are not followed by a semicolon",
6148+
name));
6149+
}
6150+
}
61356151
} else {
61366152
err.span_label(self.span, "expected item");
61376153
}

src/test/ui/issue-46186.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected item, found `;`
33
|
44
LL | }; //~ ERROR expected item, found `;`
55
| ^ help: consider removing this semicolon
6+
|
7+
= help: braced struct declarations are not followed by a semicolon
68

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)