Skip to content

Commit 3d4467d

Browse files
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).
2 parents 5352e17 + a28a78f commit 3d4467d

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

compiler/rustc_interface/src/passes.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,18 @@ pub fn configure_and_expand(
437437
});
438438

439439
// Add all buffered lints from the `ParseSess` to the `Session`.
440-
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
441-
info!("{} parse sess buffered_lints", buffered_lints.len());
442-
for early_lint in buffered_lints.drain(..) {
443-
resolver.lint_buffer().add_early_lint(early_lint);
444-
}
445-
});
440+
// The ReplaceBodyWithLoop pass may have deleted some AST nodes, potentially
441+
// causing a delay_span_bug later if a buffered lint refers to such a deleted
442+
// AST node (issue #87308). Since everybody_loops is for pretty-printing only,
443+
// anyway, we simply skip all buffered lints here.
444+
if !matches!(sess.opts.pretty, Some(PpMode::Source(PpSourceMode::EveryBodyLoops))) {
445+
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
446+
info!("{} parse sess buffered_lints", buffered_lints.len());
447+
for early_lint in buffered_lints.drain(..) {
448+
resolver.lint_buffer().add_early_lint(early_lint);
449+
}
450+
});
451+
}
446452

447453
Ok(krate)
448454
}

src/test/ui/lint/issue-87308.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Regression test for issue #87308.
2+
3+
// compile-flags: -Zunpretty=everybody_loops
4+
// check-pass
5+
6+
macro_rules! foo {
7+
() => { break 'x; }
8+
}
9+
10+
pub fn main() {
11+
'x: loop { foo!() }
12+
}

src/test/ui/lint/issue-87308.stdout

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#[prelude_import]
4+
use ::std::prelude::rust_2015::*;
5+
#[macro_use]
6+
extern crate std;
7+
// Regression test for issue #87308.
8+
9+
// compile-flags: -Zunpretty=everybody_loops
10+
// check-pass
11+
12+
macro_rules! foo { () => { break 'x ; } }
13+
14+
pub fn main() { loop { } }

0 commit comments

Comments
 (0)