diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-06-30 13:18:39 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-06-30 14:11:44 -0700 |
| commit | db2f3d7a8827055342b3385622470926d6056fc4 (patch) | |
| tree | c497a2e973b6f4d2ea51d1d8318ed0fa7336747d | |
| parent | 8772747c5f3a5809aea9abdb1586613b751db9ac (diff) | |
clarify why we're suggesting removing semicolon after braced items
Previously (issue #46186, pull-request #46258), a suggestion was added to remove the semicolon after we fail to parse an item, but issue #51603 complains that it's still insufficiently obvious why. Let's add a note. Resolves #51603.
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/issue-46186.stderr | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 673157d0ffa..4c0397dbb29 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6132,6 +6132,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"); } diff --git a/src/test/ui/issue-46186.stderr b/src/test/ui/issue-46186.stderr index f6847097dbe..c64d5c68a79 100644 --- a/src/test/ui/issue-46186.stderr +++ b/src/test/ui/issue-46186.stderr @@ -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 |
