about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-08 02:51:54 +0000
committerbors <bors@rust-lang.org>2018-07-08 02:51:54 +0000
commit0c0315cfd9750db7793b83bc59dfd353c5dd1624 (patch)
tree968b4fa6ecdaa3f372a48ce8e92de2c5b81271ed /src/libsyntax/parse/parser.rs
parent9342f293e91fa3d8fa8ad456770ee7de2a914e66 (diff)
parentdb2f3d7a8827055342b3385622470926d6056fc4 (diff)
downloadrust-0c0315cfd9750db7793b83bc59dfd353c5dd1624.tar.gz
rust-0c0315cfd9750db7793b83bc59dfd353c5dd1624.zip
Auto merge of #51955 - zackmdavis:item_semi, r=oli-obk
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.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 1f062656b81..a1b78a23b8f 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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");
             }