about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-23 12:12:49 +0000
committerbors <bors@rust-lang.org>2024-02-23 12:12:49 +0000
commit52cea084bd5bbac12ecfa5c0499f5c777025c968 (patch)
treef7155f0eb0b91c6f832624f3195ecd193a95bd0a /src
parentea2cc4368e2b4f6c833206dec7bd21800cdb0315 (diff)
parent6ee43bc7de38f9a0ee6cf6faaa487b6d633c37ed (diff)
Auto merge of #121491 - matthiaskrgr:rollup-wkzqawy, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #121434 (Fix #121208 fallout)
 - #121471 (When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`)
 - #121476 (remove `llvm.assertions=true` in compiler profile)
 - #121479 (fix generalizer unsoundness)
 - #121480 (Fix more #121208 fallout)
 - #121482 (Allow for a missing `adt_def` in `NamePrivacyVisitor`.)
 - #121484 (coverage: Use variable name `this` in `CoverageGraph::from_mir`)
 - #121487 (Explicitly call `emit_stashed_diagnostics`.)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/defaults/config.compiler.toml6
-rw-r--r--src/tools/rustfmt/src/parse/parser.rs18
-rw-r--r--src/tools/rustfmt/src/test/parser.rs7
-rw-r--r--src/tools/rustfmt/tests/parser/stashed-diag.rs3
4 files changed, 26 insertions, 8 deletions
diff --git a/src/bootstrap/defaults/config.compiler.toml b/src/bootstrap/defaults/config.compiler.toml
index 178c6e9056c..e276f126211 100644
--- a/src/bootstrap/defaults/config.compiler.toml
+++ b/src/bootstrap/defaults/config.compiler.toml
@@ -19,9 +19,9 @@ lto = "off"
 frame-pointers = true
 
 [llvm]
-# This enables debug-assertions in LLVM,
-# catching logic errors in codegen much earlier in the process.
-assertions = true
+# Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true`
+# because we don't provide ci-llvm on the `rustc-alt-builds` server. Therefore, it is kept off by default.
+assertions = false
 # Enable warnings during the LLVM compilation (when LLVM is changed, causing a compilation)
 enable-warnings = true
 # Will download LLVM from CI if available on your platform.
diff --git a/src/tools/rustfmt/src/parse/parser.rs b/src/tools/rustfmt/src/parse/parser.rs
index 31226cf8c30..cca14353b5c 100644
--- a/src/tools/rustfmt/src/parse/parser.rs
+++ b/src/tools/rustfmt/src/parse/parser.rs
@@ -163,13 +163,21 @@ impl<'a> Parser<'a> {
     fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
         let mut parser = AssertUnwindSafe(&mut self.parser);
 
-        match catch_unwind(move || parser.parse_crate_mod()) {
-            Ok(Ok(k)) => Ok(k),
-            Ok(Err(db)) => {
+        // rustfmt doesn't use `run_compiler` like other tools, so it must emit
+        // any stashed diagnostics itself, otherwise the `DiagCtxt` will assert
+        // when dropped. The final result here combines the parsing result and
+        // the `emit_stashed_diagnostics` result.
+        let parse_res = catch_unwind(move || parser.parse_crate_mod());
+        let stashed_res = self.parser.dcx().emit_stashed_diagnostics();
+        let err = Err(ParserError::ParsePanicError);
+        match (parse_res, stashed_res) {
+            (Ok(Ok(k)), None) => Ok(k),
+            (Ok(Ok(_)), Some(_guar)) => err,
+            (Ok(Err(db)), _) => {
                 db.emit();
-                Err(ParserError::ParseError)
+                err
             }
-            Err(_) => Err(ParserError::ParsePanicError),
+            (Err(_), _) => err,
         }
     }
 }
diff --git a/src/tools/rustfmt/src/test/parser.rs b/src/tools/rustfmt/src/test/parser.rs
index ae4a4f94d92..da2a2ba62e0 100644
--- a/src/tools/rustfmt/src/test/parser.rs
+++ b/src/tools/rustfmt/src/test/parser.rs
@@ -55,3 +55,10 @@ fn crate_parsing_errors_on_unclosed_delims() {
     let filename = "tests/parser/unclosed-delims/issue_4466.rs";
     assert_parser_error(filename);
 }
+
+#[test]
+fn crate_parsing_stashed_diag() {
+    // See also https://github.com/rust-lang/rust/issues/121450
+    let filename = "tests/parser/stashed-diag.rs";
+    assert_parser_error(filename);
+}
diff --git a/src/tools/rustfmt/tests/parser/stashed-diag.rs b/src/tools/rustfmt/tests/parser/stashed-diag.rs
new file mode 100644
index 00000000000..3b0b543e610
--- /dev/null
+++ b/src/tools/rustfmt/tests/parser/stashed-diag.rs
@@ -0,0 +1,3 @@
+#![u={static N;}]
+
+fn main() {}