Skip to content

Commit

Permalink
Auto merge of rust-lang#51955 - zackmdavis:item_semi, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 8, 2018
2 parents 9342f29 + db2f3d7 commit 0c0315c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6135,6 +6135,22 @@ impl<'a> Parser<'a> {
err.span_suggestion_short_with_applicability(
self.span, msg, "".to_string(), Applicability::MachineApplicable
);
if !items.is_empty() { // Issue #51603
let previous_item = &items[items.len()-1];
let previous_item_kind_name = match previous_item.node {
// say "braced struct" because tuple-structs and
// braceless-empty-struct declarations do take a semicolon
ItemKind::Struct(..) => Some("braced struct"),
ItemKind::Enum(..) => Some("enum"),
ItemKind::Trait(..) => Some("trait"),
ItemKind::Union(..) => Some("union"),
_ => None,
};
if let Some(name) = previous_item_kind_name {
err.help(&format!("{} declarations are not followed by a semicolon",
name));
}
}
} else {
err.span_label(self.span, "expected item");
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issue-46186.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: expected item, found `;`
|
LL | }; //~ ERROR expected item, found `;`
| ^ help: consider removing this semicolon
|
= help: braced struct declarations are not followed by a semicolon

error: aborting due to previous error

0 comments on commit 0c0315c

Please sign in to comment.