]> git.lizzy.rs Git - rust.git/commitdiff
clarify why we're suggesting removing semicolon after braced items
authorZack M. Davis <code@zackmdavis.net>
Sat, 30 Jun 2018 20:18:39 +0000 (13:18 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sat, 30 Jun 2018 21:11:44 +0000 (14:11 -0700)
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.

src/libsyntax/parse/parser.rs
src/test/ui/issue-46186.stderr

index 673157d0ffa0db871c61f7730fc79d91af923086..4c0397dbb2930efcb6ab94be05d8fcd754ea7129 100644 (file)
@@ -6132,6 +6132,22 @@ fn parse_mod_items(&mut self, term: &token::Token, inner_lo: Span) -> PResult<'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");
             }
index f6847097dbe980798fad5ee8e1366730216b1413..c64d5c68a79b0f1f69bb7c3b315510515e06d608 100644 (file)
@@ -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