From 0006737ca11f83add31d702fabcedd5a8616adfc Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 9 Nov 2025 16:11:32 +0800 Subject: [PATCH 1/3] Fix the typo error caused span ice --- compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 5d22a8b8e30ab..99351f6b8161d 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -749,7 +749,7 @@ fn shrink_file( let hi_byte = spans.iter().map(|s| s.hi()).max()?; let hi_loc = sm.lookup_char_pos(hi_byte); - let hi = lo_loc.file.line_bounds(hi_loc.line.saturating_sub(1)).end; + let hi = hi_loc.file.line_bounds(hi_loc.line.saturating_sub(1)).end; let bounding_span = Span::with_root_ctxt(lo, hi); let source = sm.span_to_snippet(bounding_span).unwrap_or_default(); From 8573ee6478d390e6401615d2fc9202695af6dc62 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 9 Nov 2025 16:17:48 +0800 Subject: [PATCH 2/3] Fix ICE caused by span boundaries due to macro expansion --- .../src/annotate_snippet_emitter_writer.rs | 10 ++++- .../ice-line-bounds-issue-148732.rs | 8 ++++ .../ice-line-bounds-issue-148732.stderr | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/ui/delegation/ice-line-bounds-issue-148732.rs create mode 100644 tests/ui/delegation/ice-line-bounds-issue-148732.stderr diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 99351f6b8161d..b3254927a5826 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -745,14 +745,20 @@ fn shrink_file( ) -> Option<(Span, String, usize)> { let lo_byte = spans.iter().map(|s| s.lo()).min()?; let lo_loc = sm.lookup_char_pos(lo_byte); - let lo = lo_loc.file.line_bounds(lo_loc.line.saturating_sub(1)).start; let hi_byte = spans.iter().map(|s| s.hi()).max()?; let hi_loc = sm.lookup_char_pos(hi_byte); + + if lo_loc.file.name != hi_loc.file.name { + // this may happen when spans cross file boundaries due to macro expansion. + return None; + } + + let lo = lo_loc.file.line_bounds(lo_loc.line.saturating_sub(1)).start; let hi = hi_loc.file.line_bounds(hi_loc.line.saturating_sub(1)).end; let bounding_span = Span::with_root_ctxt(lo, hi); - let source = sm.span_to_snippet(bounding_span).unwrap_or_default(); + let source = sm.span_to_snippet(bounding_span).ok()?; let offset_line = sm.doctest_offset_line(file_name, lo_loc.line); Some((bounding_span, source, offset_line)) diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.rs b/tests/ui/delegation/ice-line-bounds-issue-148732.rs new file mode 100644 index 0000000000000..699e7d86f2581 --- /dev/null +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.rs @@ -0,0 +1,8 @@ +reuse a as b { + //~^ ERROR cannot find function `a` in this scope + //~| ERROR functions delegation is not yet fully implemented + dbg!(b); + //~^ ERROR missing lifetime specifier +} + +fn main() {} diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr new file mode 100644 index 0000000000000..7cbba401724a2 --- /dev/null +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr @@ -0,0 +1,37 @@ + WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/std/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/std/src/macros.rs" }) } +error[E0106]: missing lifetime specifier + --> $DIR/ice-line-bounds-issue-148732.rs:4:5 + | +LL | dbg!(b); + | ^^^^^^^ expected named lifetime parameter + | + = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) + | + +error[E0425]: cannot find function `a` in this scope + --> $DIR/ice-line-bounds-issue-148732.rs:1:7 + | +LL | reuse a as b { + | ^ not found in this scope + +error[E0658]: functions delegation is not yet fully implemented + --> $DIR/ice-line-bounds-issue-148732.rs:1:1 + | +LL | / reuse a as b { +LL | | +LL | | +LL | | dbg!(b); +LL | | +LL | | } + | |_^ + | + = note: see issue #118212 for more information + = help: add `#![feature(fn_delegation)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0106, E0425, E0658. +For more information about an error, try `rustc --explain E0106`. From 725b213606e229517c08c9a6e9ea54411118b46d Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 9 Nov 2025 17:13:35 +0800 Subject: [PATCH 3/3] add regression test for 148684 --- .../src/annotate_snippet_emitter_writer.rs | 2 +- .../structs/ice-line-bounds-issue-148684.rs | 9 ++++++++ .../ice-line-bounds-issue-148684.stderr | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/ui/structs/ice-line-bounds-issue-148684.rs create mode 100644 tests/ui/structs/ice-line-bounds-issue-148684.stderr diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index b3254927a5826..4756909d31874 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -749,7 +749,7 @@ fn shrink_file( let hi_byte = spans.iter().map(|s| s.hi()).max()?; let hi_loc = sm.lookup_char_pos(hi_byte); - if lo_loc.file.name != hi_loc.file.name { + if lo_loc.file.stable_id != hi_loc.file.stable_id { // this may happen when spans cross file boundaries due to macro expansion. return None; } diff --git a/tests/ui/structs/ice-line-bounds-issue-148684.rs b/tests/ui/structs/ice-line-bounds-issue-148684.rs new file mode 100644 index 0000000000000..56065fb0de309 --- /dev/null +++ b/tests/ui/structs/ice-line-bounds-issue-148684.rs @@ -0,0 +1,9 @@ +struct A { + b: Vec, + c: usize, +} + +fn main() { + A(2, vec![]) + //~^ ERROR expected function, tuple struct or tuple variant, found struct `A` +} diff --git a/tests/ui/structs/ice-line-bounds-issue-148684.stderr b/tests/ui/structs/ice-line-bounds-issue-148684.stderr new file mode 100644 index 0000000000000..d6900a9fd6ac1 --- /dev/null +++ b/tests/ui/structs/ice-line-bounds-issue-148684.stderr @@ -0,0 +1,22 @@ + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } + WARN rustc_errors::emitter Invalid span $SRC_DIR/alloc/src/macros.rs:LL:COL (#4), error=SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/alloc/src/macros.rs" }) } +error[E0423]: expected function, tuple struct or tuple variant, found struct `A` + --> $DIR/ice-line-bounds-issue-148684.rs:7:5 + | +LL | / struct A { +LL | | b: Vec, +LL | | c: usize, +LL | | } + | |_- `A` defined here +... +LL | A(2, vec![]) + | ^^^^^^^^^^^^ + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0423`.