Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Parser: Diagnostic "box_syntax has been removed" crashes if the source isn't available #128442

Closed
fmease opened this issue Jul 31, 2024 · 1 comment · Fixed by #128496
Closed
Assignees
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Jul 31, 2024

Found by grepping through the compiler via rg 'span_to_snippet.+?(expect|unwrap)\(' compiler while reviewing an unrelated PR.

let code = self.psess.source_map().span_to_snippet(inner_span).unwrap();

Reproducer

File a.rs:

#[macro_export]
macro_rules! make { () => { box 0 } }

File b.rs:

fn main() { let _ = a::make!(); }
  1. Compile a: rustc a.rs --crate-type=lib.
  2. Remove or move source file a.rs.
  3. Compile b: rustc b.rs -L. --extern a --edition=2021.

Compiler Output

thread 'rustc' panicked at compiler/rustc_parse/src/parser/expr.rs:622:72:
called `Result::unwrap()` on an `Err` value: SourceNotAvailable { filename: Real(LocalPath("/home/fmease/programming/rust2/a.rs")) }
Full compiler output
thread 'rustc' panicked at compiler/rustc_parse/src/parser/expr.rs:622:72:
called `Result::unwrap()` on an `Err` value: SourceNotAvailable { filename: Real(LocalPath("/home/fmease/programming/rust2/a.rs")) }
stack backtrace:
   0:     0x7282e17fa055 - std::backtrace_rs::backtrace::libunwind::trace::h06bc9b86d9774048
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7282e17fa055 - std::backtrace_rs::backtrace::trace_unsynchronized::hdda4e98324ad77bc
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7282e17fa055 - std::sys::backtrace::_print_fmt::h1f4c993ef7e831ac
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:68:9
   3:     0x7282e17fa055 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h698f896ade9481b5
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:41:26
   4:     0x7282e184af2b - core::fmt::rt::Argument::fmt::haa88e56ba5e1296a
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/fmt/rt.rs:173:76
   5:     0x7282e184af2b - core::fmt::write::h3d0682ae14ea41eb
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/fmt/mod.rs:1182:21
   6:     0x7282e17ee94f - std::io::Write::write_fmt::hc60fd9ed89ca5cb9
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/io/mod.rs:1827:15
   7:     0x7282e17fc8f1 - std::sys::backtrace::BacktraceLock::print::h5f66c3d07f69e011
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:44:9
   8:     0x7282e17fc8f1 - std::panicking::default_hook::{{closure}}::h1a9e38caae8056a1
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:269:22
   9:     0x7282e17fc5cc - std::panicking::default_hook::h7e7b66ab2d01b158
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:296:9
  10:     0x7282ddc3c97a - std[aa7fdb062f64e277]::panicking::update_hook::<alloc[212cbeab23b2ab6c]::boxed::Box<rustc_driver_impl[248cc289afe8af4d]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7282e17fd2bf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h29dbd1b8e444e7ae
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2165:9
  12:     0x7282e17fd2bf - std::panicking::rust_panic_with_hook::hd02d3e24e17903a0
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:808:13
  13:     0x7282e17fcee7 - std::panicking::begin_panic_handler::{{closure}}::h7b7916e18a955842
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:674:13
  14:     0x7282e17fa519 - std::sys::backtrace::__rust_end_short_backtrace::h95ffcaec96e3d90f
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:172:18
  15:     0x7282e17fcb74 - rust_begin_unwind
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:665:5
  16:     0x7282e18474f3 - core::panicking::panic_fmt::h167c2e689054226b
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/panicking.rs:74:14
  17:     0x7282e1847b46 - core::result::unwrap_failed::h1c25385300420846
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/result.rs:1679:5
  18:     0x7282de489606 - <rustc_parse[186c60b7585857b1]::parser::Parser>::collect_tokens_for_expr::<<rustc_parse[186c60b7585857b1]::parser::Parser>::parse_expr_prefix::{closure#8}>::{closure#0}
  19:     0x7282dfd39fcc - <rustc_parse[186c60b7585857b1]::parser::Parser>::parse_expr_prefix
  20:     0x7282db8ab6f1 - <rustc_parse[186c60b7585857b1]::parser::Parser>::parse_expr_assoc_with
  21:     0x7282df9673e0 - <rustc_expand[e0179ee32ba7c290]::mbe::macro_rules::ParserAnyMacro>::make
  22:     0x7282df96565d - <rustc_expand[e0179ee32ba7c290]::mbe::macro_rules::ParserAnyMacro as rustc_expand[e0179ee32ba7c290]::base::MacResult>::make_expr
  23:     0x7282db828e79 - <rustc_expand[e0179ee32ba7c290]::expand::MacroExpander>::fully_expand_fragment
  24:     0x7282dfc11ad8 - <rustc_expand[e0179ee32ba7c290]::expand::MacroExpander>::expand_crate
  25:     0x7282df561ff3 - rustc_interface[508d3ee0c578cb86]::passes::resolver_for_lowering_raw
  26:     0x7282df5615b1 - rustc_query_impl[769f4fcdd066b612]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[769f4fcdd066b612]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8bb12d3a11dd28f7]::query::erase::Erased<[u8; 16usize]>>
  27:     0x7282df56159f - <rustc_query_impl[769f4fcdd066b612]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[6449c673ca1a28dc]::ops::function::FnOnce<(rustc_middle[8bb12d3a11dd28f7]::ty::context::TyCtxt, ())>>::call_once
  28:     0x7282e003c79d - rustc_query_system[ca3d605384301f62]::query::plumbing::try_execute_query::<rustc_query_impl[769f4fcdd066b612]::DynamicConfig<rustc_query_system[ca3d605384301f62]::query::caches::SingleCache<rustc_middle[8bb12d3a11dd28f7]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[769f4fcdd066b612]::plumbing::QueryCtxt, false>
  29:     0x7282e003c437 - rustc_query_impl[769f4fcdd066b612]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7282dff0bf63 - rustc_interface[508d3ee0c578cb86]::interface::run_compiler::<core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>, rustc_driver_impl[248cc289afe8af4d]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7282dfee2849 - std[aa7fdb062f64e277]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[508d3ee0c578cb86]::util::run_in_thread_with_globals<rustc_interface[508d3ee0c578cb86]::util::run_in_thread_pool_with_globals<rustc_interface[508d3ee0c578cb86]::interface::run_compiler<core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>, rustc_driver_impl[248cc289afe8af4d]::run_compiler::{closure#0}>::{closure#1}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>::{closure#0}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>
  32:     0x7282dfee25fa - <<std[aa7fdb062f64e277]::thread::Builder>::spawn_unchecked_<rustc_interface[508d3ee0c578cb86]::util::run_in_thread_with_globals<rustc_interface[508d3ee0c578cb86]::util::run_in_thread_pool_with_globals<rustc_interface[508d3ee0c578cb86]::interface::run_compiler<core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>, rustc_driver_impl[248cc289afe8af4d]::run_compiler::{closure#0}>::{closure#1}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>::{closure#0}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>>::{closure#1} as core[6449c673ca1a28dc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7282e180720b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h009d53349cd0b13e
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2151:9
  34:     0x7282e180720b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h497de5feb0301a41
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2151:9
  35:     0x7282e180720b - std::sys::pal::unix::thread::Thread::new::thread_start::hf327ce4ae0a5d31b
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/pal/unix/thread.rs:108:17
  36:     0x7282e15a6ded - <unknown>
  37:     0x7282e162a0dc - <unknown>
  38:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (2cbbe8b8b 2024-07-28) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack

Meta

rustc -Vv:

rustc 1.82.0-nightly (2cbbe8b8b 2024-07-28)
binary: rustc
commit-hash: 2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b
commit-date: 2024-07-28
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
@fmease fmease added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-parser Area: The parsing of Rust source code to an AST P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jul 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 31, 2024
@fmease
Copy link
Member Author

fmease commented Jul 31, 2024

Solution: Get rid of span_to_snippet altogether and use a multi-part suggestion (Box::new(, )).

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 31, 2024
@clubby789 clubby789 self-assigned this Aug 1, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 1, 2024
…compiler-errors

Fix removed `box_syntax` diagnostic if source isn't available

Fix rust-lang#128442
@bors bors closed this as completed in 29cd310 Aug 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 1, 2024
Rollup merge of rust-lang#128496 - clubby789:box-syntax-multipart, r=compiler-errors

Fix removed `box_syntax` diagnostic if source isn't available

Fix rust-lang#128442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants