Skip to content

Commit 0c0315c

Browse files
committedJul 8, 2018
Auto merge of rust-lang#51955 - zackmdavis:item_semi, r=oli-obk
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.

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
@@ -6135,6 +6135,22 @@ impl<'a> Parser<'a> {
61356135
err.span_suggestion_short_with_applicability(
61366136
self.span, msg, "".to_string(), Applicability::MachineApplicable
61376137
);
6138+
if !items.is_empty() { // Issue #51603
6139+
let previous_item = &items[items.len()-1];
6140+
let previous_item_kind_name = match previous_item.node {
6141+
// say "braced struct" because tuple-structs and
6142+
// braceless-empty-struct declarations do take a semicolon
6143+
ItemKind::Struct(..) => Some("braced struct"),
6144+
ItemKind::Enum(..) => Some("enum"),
6145+
ItemKind::Trait(..) => Some("trait"),
6146+
ItemKind::Union(..) => Some("union"),
6147+
_ => None,
6148+
};
6149+
if let Some(name) = previous_item_kind_name {
6150+
err.help(&format!("{} declarations are not followed by a semicolon",
6151+
name));
6152+
}
6153+
}
61386154
} else {
61396155
err.span_label(self.span, "expected item");
61406156
}

‎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)
Please sign in to comment.