Skip to content

ICE: Lint: Diagnostic "literal out of range" crashes if the source is not available #128445

Closed
@fmease

Description

@fmease

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

cx.sess().source_map().span_to_snippet(span).expect("must get snippet from literal");

Reproducer

File a.rs:

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

File b.rs:

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

Compiler Output

thread 'rustc' panicked at compiler/rustc_lint/src/types.rs:539:22:
must get snippet from literal: SourceNotAvailable { filename: Real(LocalPath("/home/fmease/programming/rust2/a.rs")) }
Full compiler output
thread 'rustc' panicked at compiler/rustc_lint/src/types.rs:539:22:
must get snippet from literal: SourceNotAvailable { filename: Real(LocalPath("/home/fmease/programming/rust2/a.rs")) }
stack backtrace:
   0:     0x7199067e8055 - std::backtrace_rs::backtrace::libunwind::trace::h06bc9b86d9774048
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7199067e8055 - std::backtrace_rs::backtrace::trace_unsynchronized::hdda4e98324ad77bc
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7199067e8055 - std::sys::backtrace::_print_fmt::h1f4c993ef7e831ac
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:68:9
   3:     0x7199067e8055 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h698f896ade9481b5
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:41:26
   4:     0x719906838f2b - core::fmt::rt::Argument::fmt::haa88e56ba5e1296a
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/fmt/rt.rs:173:76
   5:     0x719906838f2b - core::fmt::write::h3d0682ae14ea41eb
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/fmt/mod.rs:1182:21
   6:     0x7199067dc94f - std::io::Write::write_fmt::hc60fd9ed89ca5cb9
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/io/mod.rs:1827:15
   7:     0x7199067ea8f1 - std::sys::backtrace::BacktraceLock::print::h5f66c3d07f69e011
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:44:9
   8:     0x7199067ea8f1 - std::panicking::default_hook::{{closure}}::h1a9e38caae8056a1
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:269:22
   9:     0x7199067ea5cc - std::panicking::default_hook::h7e7b66ab2d01b158
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:296:9
  10:     0x719902c3c97a - std[aa7fdb062f64e277]::panicking::update_hook::<alloc[212cbeab23b2ab6c]::boxed::Box<rustc_driver_impl[248cc289afe8af4d]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7199067eb2bf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h29dbd1b8e444e7ae
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2165:9
  12:     0x7199067eb2bf - std::panicking::rust_panic_with_hook::hd02d3e24e17903a0
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:808:13
  13:     0x7199067eaee7 - std::panicking::begin_panic_handler::{{closure}}::h7b7916e18a955842
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:674:13
  14:     0x7199067e8519 - std::sys::backtrace::__rust_end_short_backtrace::h95ffcaec96e3d90f
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/backtrace.rs:172:18
  15:     0x7199067eab74 - rust_begin_unwind
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/panicking.rs:665:5
  16:     0x7199068354f3 - core::panicking::panic_fmt::h167c2e689054226b
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/panicking.rs:74:14
  17:     0x719906835b46 - core::result::unwrap_failed::h1c25385300420846
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/core/src/result.rs:1679:5
  18:     0x719904500d35 - <rustc_lint[d89544807353375f]::BuiltinCombinedModuleLateLintPass as rustc_lint[d89544807353375f]::passes::LateLintPass>::check_expr
  19:     0x7199044f4bf2 - <rustc_lint[d89544807353375f]::late::LateContextAndPass<rustc_lint[d89544807353375f]::BuiltinCombinedModuleLateLintPass> as rustc_hir[c900fadf12e10b12]::intravisit::Visitor>::visit_expr
  20:     0x7199044f2af2 - rustc_hir[c900fadf12e10b12]::intravisit::walk_block::<rustc_lint[d89544807353375f]::late::LateContextAndPass<rustc_lint[d89544807353375f]::BuiltinCombinedModuleLateLintPass>>
  21:     0x719904433528 - <rustc_lint[d89544807353375f]::late::LateContextAndPass<rustc_lint[d89544807353375f]::BuiltinCombinedModuleLateLintPass> as rustc_hir[c900fadf12e10b12]::intravisit::Visitor>::visit_nested_body
  22:     0x719904424ca6 - <rustc_lint[d89544807353375f]::late::LateContextAndPass<rustc_lint[d89544807353375f]::BuiltinCombinedModuleLateLintPass> as rustc_hir[c900fadf12e10b12]::intravisit::Visitor>::visit_nested_item
  23:     0x7199044232e4 - rustc_lint[d89544807353375f]::lint_mod
  24:     0x7199044230f3 - rustc_query_impl[769f4fcdd066b612]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[769f4fcdd066b612]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8bb12d3a11dd28f7]::query::erase::Erased<[u8; 0usize]>>
  25:     0x719904d13ef5 - rustc_query_system[ca3d605384301f62]::query::plumbing::try_execute_query::<rustc_query_impl[769f4fcdd066b612]::DynamicConfig<rustc_query_system[ca3d605384301f62]::query::caches::DefaultCache<rustc_span[e48981e571852391]::def_id::LocalModDefId, rustc_middle[8bb12d3a11dd28f7]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[769f4fcdd066b612]::plumbing::QueryCtxt, false>
  26:     0x719904d12c19 - rustc_query_impl[769f4fcdd066b612]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  27:     0x719904d12807 - rustc_lint[d89544807353375f]::late::check_crate::{closure#1}
  28:     0x719904d1221e - rustc_lint[d89544807353375f]::late::check_crate
  29:     0x7199046203f0 - rustc_interface[508d3ee0c578cb86]::passes::analysis
  30:     0x71990461f947 - rustc_query_impl[769f4fcdd066b612]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[769f4fcdd066b612]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8bb12d3a11dd28f7]::query::erase::Erased<[u8; 1usize]>>
  31:     0x71990503ba25 - 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; 1usize]>>, false, false, false>, rustc_query_impl[769f4fcdd066b612]::plumbing::QueryCtxt, false>
  32:     0x71990503b78f - rustc_query_impl[769f4fcdd066b612]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  33:     0x719904f0c245 - rustc_interface[508d3ee0c578cb86]::interface::run_compiler::<core[6449c673ca1a28dc]::result::Result<(), rustc_span[e48981e571852391]::ErrorGuaranteed>, rustc_driver_impl[248cc289afe8af4d]::run_compiler::{closure#0}>::{closure#1}
  34:     0x719904ee2849 - 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>>
  35:     0x719904ee25fa - <<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}
  36:     0x7199067f520b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h009d53349cd0b13e
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2151:9
  37:     0x7199067f520b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h497de5feb0301a41
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/alloc/src/boxed.rs:2151:9
  38:     0x7199067f520b - std::sys::pal::unix::thread::Thread::new::thread_start::hf327ce4ae0a5d31b
                               at /rustc/2cbbe8b8bb2be672b14cf741a2f0ec24a49f3f0b/library/std/src/sys/pal/unix/thread.rs:108:17
  39:     0x7198ff6a6ded - <unknown>
  40:     0x7198ff72a0dc - <unknown>
  41:                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 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions