about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2021-10-04 13:58:16 -0700
committerGitHub <noreply@github.com>2021-10-04 13:58:16 -0700
commit3d4467dfcc512fcb2dc2454c9cf77c23ff3de343 (patch)
treec48dd998c239d821f01baa71d55b557ec83d2a44 /src/test
parent5352e17df3b2500b4cf92ee86c7dbf002018600f (diff)
parenta28a78f247a0f02521e97eabf98e790085a4a753 (diff)
downloadrust-3d4467dfcc512fcb2dc2454c9cf77c23ff3de343.tar.gz
rust-3d4467dfcc512fcb2dc2454c9cf77c23ff3de343.zip
Rollup merge of #89500 - FabianWolff:issue-87308, r=petrochenkov
Fix ICE with buffered lint referring to AST node deleted by everybody_loops

Fixes #87308. Note the following comment:
https://github.com/rust-lang/rust/blob/08759c691e2e9799a3c6780ffdf910240ebd4a6b/compiler/rustc_lint/src/early.rs#L415-L417

As it turns out, this is not _always_ a bug, because `-Zunpretty=everybody_loops` causes a lot of AST nodes to be deleted, and thus some buffered lints will refer to non-existent node ids. To fix this, my changes simply ignore buffered lints if `-Zunpretty=everybody_loops` is enabled, which, from my understanding, shouldn't be a big issue because it only affects pretty-printing. Of course, a more elegant solution would only ignore buffered lints that actually point at deleted node ids, but I haven't figured out an easy way of achieving this.

For the concrete example in #87308, the buffered lint is created [here](https://github.com/rust-lang/rust/blob/08759c691e2e9799a3c6780ffdf910240ebd4a6b/compiler/rustc_expand/src/mbe/macro_rules.rs#L145-L151) with the `lint_node_id` from [here](https://github.com/rust-lang/rust/blob/08759c691e2e9799a3c6780ffdf910240ebd4a6b/compiler/rustc_expand/src/mbe/macro_rules.rs#L319), i.e. it points at the macro _expansion_, which then gets deleted by `ReplaceBodyWithLoop` [here](https://github.com/rust-lang/rust/blob/08759c691e2e9799a3c6780ffdf910240ebd4a6b/compiler/rustc_interface/src/passes.rs#L377).
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/lint/issue-87308.rs12
-rw-r--r--src/test/ui/lint/issue-87308.stdout14
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/ui/lint/issue-87308.rs b/src/test/ui/lint/issue-87308.rs
new file mode 100644
index 00000000000..48fbb2a0139
--- /dev/null
+++ b/src/test/ui/lint/issue-87308.rs
@@ -0,0 +1,12 @@
+// Regression test for issue #87308.
+
+// compile-flags: -Zunpretty=everybody_loops
+// check-pass
+
+macro_rules! foo {
+    () => { break 'x; }
+}
+
+pub fn main() {
+    'x: loop { foo!() }
+}
diff --git a/src/test/ui/lint/issue-87308.stdout b/src/test/ui/lint/issue-87308.stdout
new file mode 100644
index 00000000000..68a076c93be
--- /dev/null
+++ b/src/test/ui/lint/issue-87308.stdout
@@ -0,0 +1,14 @@
+#![feature(prelude_import)]
+#![no_std]
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+// Regression test for issue #87308.
+
+// compile-flags: -Zunpretty=everybody_loops
+// check-pass
+
+macro_rules! foo { () => { break 'x ; } }
+
+pub fn main() { loop { } }