Skip to content

ICE:assertion left == right failed: all spans must be disjoint #146706

Description

@rucsesec

I found an ICE bug. I believe it is a duplicate of 146261, but what if it is not? So I am submitting this bug. If it is indeed a complete duplicate, I apologize for the trouble.

snippet:

type Variant<'a, T> = SomeEnum<T>;

enum SomeEnum<T> {
    SomeVariant { t: T }
}

fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
    let c = 66;
    Variant::SomeVariant::<&'a u32> { t: &c };
}

fn main() {}

Version information:

rustc 1.92.0-nightly (a9d0a6f15 2025-09-16)
binary: rustc
commit-hash: a9d0a6f15533a364816c4d81e2192009ef601d33
commit-date: 2025-09-16
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1
Program output

error[E0109]: type arguments are not allowed on this type
  --> <source>:11:28
   |
11 |     Variant::SomeVariant::<&'a u32> { t: &c };
   |              -----------   ^^^^^^^ type argument not allowed
   |              |
   |              not allowed on this type
   |
   = note: enum variants can't have type parameters

thread 'rustc' (3) panicked at compiler/rustc_errors/src/lib.rs:385:17:
assertion `left == right` failed: all spans must be disjoint
  left: Some([SubstitutionPart { span: <source>:11:12: 11:36 (#0), snippet: "::<&'a u32>" }, SubstitutionPart { span: <source>:11:25: 11:36 (#0), snippet: "" }])
 right: None
stack backtrace:
   0:     0x7d246524bdf3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h830fbe15fbab381b
   1:     0x7d2465a01b58 - core::fmt::write::hf661a9e75db120a3
   2:     0x7d2465200d71 - std::io::Write::write_fmt::he76c5adbbdfd1600
   3:     0x7d2465211d22 - std::sys::backtrace::BacktraceLock::print::hb87325f2dc6d4dfe
   4:     0x7d2465217c69 - std::panicking::default_hook::{{closure}}::h5e01ba9de3335cc4
   5:     0x7d2465217793 - std::panicking::default_hook::h47934e1f610fefc5
   6:     0x7d2464208797 - std[c207121dba9f4102]::panicking::update_hook::<alloc[fbc11b1b12ed36cd]::boxed::Box<rustc_driver_impl[d9438a736c8997f5]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7d246521808f - std::panicking::panic_with_hook::hfee0edaf348ac547
   8:     0x7d2465217e4a - std::panicking::panic_handler::{{closure}}::h6c6964ed9ca982a7
   9:     0x7d2465211e69 - std::sys::backtrace::__rust_end_short_backtrace::h232e83a0d4d66618
  10:     0x7d24651f27ad - __rustc[b07eb43dc0c79c3a]::rust_begin_unwind
  11:     0x7d24618e71f0 - core::panicking::panic_fmt::he0731d8485d264bd
  12:     0x7d2463bf7293 - core::panicking::assert_failed_inner::h8e762b1082fd3e64
  13:     0x7d2464237ff8 - core[c97f7de45acf1cc9]::panicking::assert_failed::<core[c97f7de45acf1cc9]::option::Option<&[rustc_errors[928f4f940c7c8cb7]::SubstitutionPart; 2usize]>, core[c97f7de45acf1cc9]::option::Option<&[rustc_errors[928f4f940c7c8cb7]::SubstitutionPart; 2usize]>>
  14:     0x7d2466e50fb1 - <core[c97f7de45acf1cc9]::iter::adapters::filter_map::FilterMap<core[c97f7de45acf1cc9]::iter::adapters::cloned::Cloned<core[c97f7de45acf1cc9]::iter::adapters::filter::Filter<core[c97f7de45acf1cc9]::slice::iter::Iter<rustc_errors[928f4f940c7c8cb7]::Substitution>, <rustc_errors[928f4f940c7c8cb7]::CodeSuggestion>::splice_lines::{closure#0}>>, <rustc_errors[928f4f940c7c8cb7]::CodeSuggestion>::splice_lines::{closure#1}> as core[c97f7de45acf1cc9]::iter::traits::iterator::Iterator>::next
  15:     0x7d2466e52c9d - <rustc_errors[928f4f940c7c8cb7]::emitter::HumanEmitter>::emit_suggestion_default
  16:     0x7d2466f58953 - <rustc_errors[928f4f940c7c8cb7]::emitter::HumanEmitter as rustc_errors[928f4f940c7c8cb7]::emitter::Emitter>::emit_diagnostic
  17:     0x7d2466f5fed8 - <rustc_errors[928f4f940c7c8cb7]::DiagCtxtInner>::emit_diagnostic::{closure#3}
  18:     0x7d2466f5d89a - rustc_interface[3a2987949cdbb48a]::callbacks::track_diagnostic::<core[c97f7de45acf1cc9]::option::Option<rustc_span[acd9e562735339de]::ErrorGuaranteed>>
  19:     0x7d2466f5c8b6 - <rustc_errors[928f4f940c7c8cb7]::DiagCtxtInner>::emit_diagnostic
  20:     0x7d2466f5c77f - <rustc_errors[928f4f940c7c8cb7]::DiagCtxtHandle>::emit_diagnostic
  21:     0x7d24622a012e - <rustc_span[acd9e562735339de]::ErrorGuaranteed as rustc_errors[928f4f940c7c8cb7]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  22:     0x7d2466357fe6 - <dyn rustc_hir_analysis[25a5ef209d74c11d]::hir_ty_lowering::HirTyLowerer>::prohibit_generic_args::<core[c97f7de45acf1cc9]::slice::iter::Iter<rustc_hir[73cd324757686b2b]::hir::PathSegment>>
  23:     0x7d246633b5c8 - <dyn rustc_hir_analysis[25a5ef209d74c11d]::hir_ty_lowering::HirTyLowerer>::lower_type_relative_path::{closure#0}
  24:     0x7d246633ae3b - <dyn rustc_hir_analysis[25a5ef209d74c11d]::hir_ty_lowering::HirTyLowerer>::lower_type_relative_ty_path::{closure#0}
  25:     0x7d2465f44b7c - <rustc_hir_typeck[8ddae7115abbbd15]::fn_ctxt::FnCtxt>::check_struct_path
  26:     0x7d2466b06dc6 - <rustc_hir_typeck[8ddae7115abbbd15]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27:     0x7d2465ce72d4 - <rustc_hir_typeck[8ddae7115abbbd15]::fn_ctxt::FnCtxt>::check_expr_block
  28:     0x7d2466b010be - <rustc_hir_typeck[8ddae7115abbbd15]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7d2465cf230b - rustc_hir_typeck[8ddae7115abbbd15]::check::check_fn
  30:     0x7d2465d6d4fb - rustc_hir_typeck[8ddae7115abbbd15]::typeck_with_inspect::{closure#0}
  31:     0x7d2465d6bcf6 - rustc_query_impl[d2194a968fe82a14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2194a968fe82a14]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca952e998b261ea0]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7d2465c94f45 - rustc_query_system[8aa47809e78cb5f0]::query::plumbing::try_execute_query::<rustc_query_impl[d2194a968fe82a14]::DynamicConfig<rustc_data_structures[9517fc3c6a0ce3dd]::vec_cache::VecCache<rustc_span[acd9e562735339de]::def_id::LocalDefId, rustc_middle[ca952e998b261ea0]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[8aa47809e78cb5f0]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d2194a968fe82a14]::plumbing::QueryCtxt, false>
  33:     0x7d2465c94989 - rustc_query_impl[d2194a968fe82a14]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7d2465c8caed - <rustc_middle[ca952e998b261ea0]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[25a5ef209d74c11d]::check_crate::{closure#2}>::{closure#0}
  35:     0x7d2465c8be6b - rustc_hir_analysis[25a5ef209d74c11d]::check_crate
  36:     0x7d2465c9c87e - rustc_interface[3a2987949cdbb48a]::passes::analysis
  37:     0x7d2465c9c54b - rustc_query_impl[d2194a968fe82a14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2194a968fe82a14]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca952e998b261ea0]::query::erase::Erased<[u8; 0usize]>>
  38:     0x7d2466b3e208 - rustc_query_system[8aa47809e78cb5f0]::query::plumbing::try_execute_query::<rustc_query_impl[d2194a968fe82a14]::DynamicConfig<rustc_query_system[8aa47809e78cb5f0]::query::caches::SingleCache<rustc_middle[ca952e998b261ea0]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d2194a968fe82a14]::plumbing::QueryCtxt, false>
  39:     0x7d2466b3de3e - rustc_query_impl[d2194a968fe82a14]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7d2466d7d063 - rustc_interface[3a2987949cdbb48a]::passes::create_and_enter_global_ctxt::<core[c97f7de45acf1cc9]::option::Option<rustc_interface[3a2987949cdbb48a]::queries::Linker>, rustc_driver_impl[d9438a736c8997f5]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  41:     0x7d2466cc10fe - rustc_interface[3a2987949cdbb48a]::interface::run_compiler::<(), rustc_driver_impl[d9438a736c8997f5]::run_compiler::{closure#0}>::{closure#1}
  42:     0x7d2466bf5b38 - std[c207121dba9f4102]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3a2987949cdbb48a]::util::run_in_thread_with_globals<rustc_interface[3a2987949cdbb48a]::util::run_in_thread_pool_with_globals<rustc_interface[3a2987949cdbb48a]::interface::run_compiler<(), rustc_driver_impl[d9438a736c8997f5]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  43:     0x7d2466bf581c - <<std[c207121dba9f4102]::thread::Builder>::spawn_unchecked_<rustc_interface[3a2987949cdbb48a]::util::run_in_thread_with_globals<rustc_interface[3a2987949cdbb48a]::util::run_in_thread_pool_with_globals<rustc_interface[3a2987949cdbb48a]::interface::run_compiler<(), rustc_driver_impl[d9438a736c8997f5]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c97f7de45acf1cc9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7d2466bfbecd - std::sys::thread::unix::Thread::new::thread_start::h44739fe3c92fa2b0
  45:     0x7d2460294ac3 - <unknown>
  46:     0x7d2460326850 - <unknown>
  47:                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: please attach the file at `/app/rustc-ice-2025-09-18T07_05_10-1.txt` to your bug report

note: compiler flags: -C debuginfo=2 --crate-type bin -C linker=/opt/compiler-explorer/gcc-15.2.0/bin/gcc

query stack during panic:
#0 [typeck] type-checking `annot_reference_named_lifetime`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0109`.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 18, 2025
  2. added
    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.
    on Sep 18, 2025
  3. cyrgani commented on Sep 18, 2025

    @cyrgani
    Contributor

    slightly smaller:

    type Alias<'a, T> = Foo<T>;
    
    enum Foo<T> {
        Bar { t: T }
    }
    
    fn main() {
        Alias::Bar::<u32> { t: 0 };
    }

    I wouldn't call this a duplicate of the other issue, as the other issue is caused by typo'd variants and this one is instead about the position of the type annotation.
    (I'm also surprised that this program does not compile on stable, because inlining the type alias by replacing Alias::Bar with Foo::Bar compiles file.)

  4. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Sep 18, 2025
  5. NKID00 commented on Sep 18, 2025

    @NKID00

    (I'm also surprised that this program does not compile on stable, because inlining the type alias by replacing Alias::Bar with Foo::Bar compiles file.)

    It is indeed surprising! According to #61682 (comment), Enum::Variant::<T> is only kept for compatibility. Enum::<T>::Variant and Alias::<T>::Variant were added later and are consistent with Type::<T>::AssociatedItem. Alias::Variant::<T> is never allowed.

  6. added
    D-non-disjoint-spansDiagnostics: Spans are non-disjoint / overlap.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 19, 2025
  7. NKID00 commented on Sep 19, 2025

    @NKID00

    Seems to be caused by the implicit lifetime generic argument having a zero length span at the end of the path instead of in the middle. That makes the to be replaced part of suggestion spans to the end.

  8. GrigorenkoPV commented on Sep 19, 2025

    @GrigorenkoPV
    Contributor

    slightly smaller:

    type Alias<'a, T> = Foo<T>;
    
    enum Foo<T> {
        Bar { t: T }
    }
    
    fn main() {
        Alias::Bar::<u32> { t: 0 };
    }

    regressed nightly: nightly-2025-09-06
    regressed commit: 99317ef (#146121)

  9. added a commit that references this issue on Sep 20, 2025
    976ada3
  10. added 2 commits that reference this issue on Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.D-non-disjoint-spansDiagnostics: Spans are non-disjoint / overlap.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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