From c857cbeb0610db7148682808c7305073546b6a63 Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Mon, 7 Dec 2020 18:10:48 -0500
Subject: [PATCH 1/4] Lint on redundant trailing semicolon after item

We now lint on code like this:

```rust
fn main() {
    fn foo() {};
    struct Bar {};
}
```

Previously, this caused warnings in Cargo, so it was disabled.
---
 .../rustc_lint/src/redundant_semicolon.rs     | 20 +++----------------
 .../redundant-semicolon/item-stmt-semi.rs     |  8 ++------
 .../redundant-semicolon/item-stmt-semi.stderr | 20 +++++++++++++++++++
 3 files changed, 25 insertions(+), 23 deletions(-)
 create mode 100644 src/test/ui/lint/redundant-semicolon/item-stmt-semi.stderr

diff --git a/compiler/rustc_lint/src/redundant_semicolon.rs b/compiler/rustc_lint/src/redundant_semicolon.rs
index 428198cae89..0fe6564880f 100644
--- a/compiler/rustc_lint/src/redundant_semicolon.rs
+++ b/compiler/rustc_lint/src/redundant_semicolon.rs
@@ -28,27 +28,19 @@ declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);
 
 impl EarlyLintPass for RedundantSemicolons {
     fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
-        let mut after_item_stmt = false;
         let mut seq = None;
         for stmt in block.stmts.iter() {
             match (&stmt.kind, &mut seq) {
                 (StmtKind::Empty, None) => seq = Some((stmt.span, false)),
                 (StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
-                (_, seq) => {
-                    maybe_lint_redundant_semis(cx, seq, after_item_stmt);
-                    after_item_stmt = matches!(stmt.kind, StmtKind::Item(_));
-                }
+                (_, seq) => maybe_lint_redundant_semis(cx, seq),
             }
         }
-        maybe_lint_redundant_semis(cx, &mut seq, after_item_stmt);
+        maybe_lint_redundant_semis(cx, &mut seq);
     }
 }
 
-fn maybe_lint_redundant_semis(
-    cx: &EarlyContext<'_>,
-    seq: &mut Option<(Span, bool)>,
-    after_item_stmt: bool,
-) {
+fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
     if let Some((span, multiple)) = seq.take() {
         // FIXME: Find a better way of ignoring the trailing
         // semicolon from macro expansion
@@ -56,12 +48,6 @@ fn maybe_lint_redundant_semis(
             return;
         }
 
-        // FIXME: Lint on semicolons after item statements
-        // once doing so doesn't break bootstrapping
-        if after_item_stmt {
-            return;
-        }
-
         cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
             let (msg, rem) = if multiple {
                 ("unnecessary trailing semicolons", "remove these semicolons")
diff --git a/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs
index 4592bc31a39..8c79630b7fd 100644
--- a/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs
+++ b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs
@@ -1,10 +1,6 @@
-// check-pass
-// This test should stop compiling
-// we decide to enable this lint for item statements.
-
 #![deny(redundant_semicolons)]
 
 fn main() {
-    fn inner() {};
-    struct Bar {};
+    fn inner() {}; //~ ERROR unnecessary
+    struct Bar {}; //~ ERROR unnecessary
 }
diff --git a/src/test/ui/lint/redundant-semicolon/item-stmt-semi.stderr b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.stderr
new file mode 100644
index 00000000000..451b152cbe5
--- /dev/null
+++ b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.stderr
@@ -0,0 +1,20 @@
+error: unnecessary trailing semicolon
+  --> $DIR/item-stmt-semi.rs:4:18
+   |
+LL |     fn inner() {};
+   |                  ^ help: remove this semicolon
+   |
+note: the lint level is defined here
+  --> $DIR/item-stmt-semi.rs:1:9
+   |
+LL | #![deny(redundant_semicolons)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+
+error: unnecessary trailing semicolon
+  --> $DIR/item-stmt-semi.rs:5:18
+   |
+LL |     struct Bar {};
+   |                  ^ help: remove this semicolon
+
+error: aborting due to 2 previous errors
+

From 21ed141b94c189a23f24832dd222dc28ee61bf12 Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Mon, 7 Dec 2020 21:52:13 -0500
Subject: [PATCH 2/4] Remove trailing semicolon in librustdoc

---
 src/librustdoc/html/markdown.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 2ae28dcd0c4..9c206dfce59 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1027,7 +1027,7 @@ fn markdown_summary_with_limit(md: &str, length_limit: usize) -> (String, bool)
     fn push(s: &mut String, text_length: &mut usize, text: &str) {
         s.push_str(text);
         *text_length += text.len();
-    };
+    }
 
     'outer: for event in Parser::new_ext(md, summary_opts()) {
         match &event {

From 4c4700d9e5da660a9322a658fd15b9401eedde3b Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Mon, 28 Dec 2020 14:44:33 -0500
Subject: [PATCH 3/4] Remove unnecessary semicolon from Rustdoc-generated code

---
 src/librustdoc/doctest.rs       | 4 ++--
 src/librustdoc/doctest/tests.rs | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 7313c761eae..02dd42ce0c1 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -558,12 +558,12 @@ crate fn make_test(
                     "fn main() {{ {}fn {}() -> Result<(), impl core::fmt::Debug> {{\n",
                     inner_attr, inner_fn_name
                 ),
-                format!("\n}}; {}().unwrap() }}", inner_fn_name),
+                format!("\n}} {}().unwrap() }}", inner_fn_name),
             )
         } else if test_id.is_some() {
             (
                 format!("fn main() {{ {}fn {}() {{\n", inner_attr, inner_fn_name),
-                format!("\n}}; {}() }}", inner_fn_name),
+                format!("\n}} {}() }}", inner_fn_name),
             )
         } else {
             ("fn main() {\n".into(), "\n}".into())
diff --git a/src/librustdoc/doctest/tests.rs b/src/librustdoc/doctest/tests.rs
index 1aea85e9970..465b2b1d69b 100644
--- a/src/librustdoc/doctest/tests.rs
+++ b/src/librustdoc/doctest/tests.rs
@@ -292,7 +292,7 @@ use std::io;
 let mut input = String::new();
 io::stdin().read_line(&mut input)?;
 Ok::<(), io:Error>(())
-}; _inner().unwrap() }"
+} _inner().unwrap() }"
         .to_string();
     let (output, len, _) = make_test(input, None, false, &opts, DEFAULT_EDITION, None);
     assert_eq!((output, len), (expected, 2));
@@ -306,7 +306,7 @@ fn make_test_named_wrapper() {
     let expected = "#![allow(unused)]
 fn main() { #[allow(non_snake_case)] fn _doctest_main__some_unique_name() {
 assert_eq!(2+2, 4);
-}; _doctest_main__some_unique_name() }"
+} _doctest_main__some_unique_name() }"
         .to_string();
     let (output, len, _) =
         make_test(input, None, false, &opts, DEFAULT_EDITION, Some("_some_unique_name"));

From 6bef37c8417c0357cf6ea43aba55c7ab376b2d70 Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Tue, 29 Dec 2020 17:15:53 -0500
Subject: [PATCH 4/4] Remove unnecessary semicolon from Clippy test

---
 src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed | 2 +-
 src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
index 7f4ebf56673..84981a52597 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
@@ -39,7 +39,7 @@ fn main() {
         B(i32),
         C,
         D,
-    };
+    }
     let x = E::A(2);
     {
         // lint
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
index aee56dd4a5e..94c7c3cadac 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
@@ -51,7 +51,7 @@ fn main() {
         B(i32),
         C,
         D,
-    };
+    }
     let x = E::A(2);
     {
         // lint