ICE: Multi-file diagnostic: Patch span is beyond the end of buffer
Opened this issue · 0 comments
Jarcho commented
Details are copied from rust-lang/rust-clippy#16046
Since #148188 clippy has gained a few ICE's related to diagnostics with spans from multiple files. derivable_impls is just the reported one. The main connection seems to be that the suggestions are not all in the same file.
For derivable_impls suggestion spans are the entire impl Default for block, the start of the enum definition, and the start of the variant definition. The suggestion spans are retrieved via the HIR item span for the block and TyCtxt::def_span().shrink_to_lo() for the variant and enum definitions.
Code
// src/main.rs
#![warn(clippy::derivable_impls)]
#[macro_use]
mod macros;
my_enum!();
impl Default for Enum {
fn default() -> Self {
Enum::Variant
}
}
fn main() {}// src/macros.rs
macro_rules! my_enum {
() => {
pub enum Enum {
Variant,
}
};
}Meta
rustc --version --verbose:
rustc 1.93.0-nightly (c90bcb957 2025-11-06)
binary: rustc
commit-hash: c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38
commit-date: 2025-11-06
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3
Error output
warning: this `impl` can be derived
--> src/main.rs:10:1
|
10 | / impl Default for Enum {
11 | | fn default() -> Self {
12 | | Enum::Variant
13 | | }
14 | | }
| |_^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
note: the lint level is defined here
--> src/main.rs:3:9
|
3 | #![warn(clippy::derivable_impls)]
| ^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' (2243971) panicked at /rust/deps/annotate-snippets-0.12.8/src/renderer/source_map.rs:427:13:
Patch span `14..94` is beyond the end of buffer `14`
stack backtrace:
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: annotate_snippets::renderer::render::render
3: <rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter>::emit_messages_default
4: <rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
5: <rustc_errors::json::Diagnostic>::from_errors_diagnostic
6: <rustc_errors::json::JsonEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
7: <rustc_errors::DiagCtxtInner>::emit_diagnostic::{closure#3}
8: rustc_interface::callbacks::track_diagnostic::<core::option::Option<rustc_span::ErrorGuaranteed>>
9: <rustc_errors::DiagCtxtInner>::emit_diagnostic
10: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
11: <() as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: rustc_middle::lint::lint_level::lint_level_impl
13: clippy_lints::derivable_impls::check_enum
14: <clippy_lints::derivable_impls::DerivableImpls as rustc_lint::passes::LateLintPass>::check_item
15: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass> as rustc_hir::intravisit::Visitor>::visit_nested_item
16: <rustc_lint::late::LateContextAndPass<rustc_lint::late::RuntimeCombinedLateLintPass>>::process_mod
17: rustc_lint::late::check_crate::{closure#0}
18: rustc_lint::late::check_crate
19: rustc_interface::passes::analysis
[... omitted 1 frame ...]
20: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
21: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml
note: please make sure that you have updated to the latest nightly
note: please attach the file at `/git/repro/rustc-ice-2025-11-07T03_14_26-2243970.txt` to your bug report
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [analysis] running analysis passes on crate `repro`
end of query stack
note: Clippy version: clippy 0.1.93 (c90bcb9571 2025-11-06)