Skip to content

ICE: lazy_type_alias: cannot relate consts of different types #114456

Closed

Description

@matthiaskrgr

Code

#![feature(adt_const_params, lazy_type_alias)]

pub type Matrix = [usize; 1];
const EMPTY_MATRIX: Matrix = [0; 1];

pub struct Walk<const REMAINING: Matrix> {}

impl Walk<EMPTY_MATRIX> {
    pub const fn new() -> Self {
        Self {}
    }
}

fn main() {
    let _ = Walk::new();
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (474709a9a 2023-08-03)
binary: rustc
commit-hash: 474709a9a2a74a8bcf0055fadb335d0ca0d2d939
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

<output>
Backtrace

warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> treereduce.out:1:12
  |
1 | #![feature(adt_const_params, lazy_type_alias)]
  |            ^^^^^^^^^^^^^^^^
  |
  = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
 --> treereduce.out:1:30
  |
1 | #![feature(adt_const_params, lazy_type_alias)]
  |                              ^^^^^^^^^^^^^^^
  |
  = note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: cannot relate consts of different types (a=Const { ty: Matrix, kind: ?0c }, b=Const { ty: [usize; 1], kind: Branch([Leaf(0x0000000000000000)]) })
  |
  = note: delayed at /rustc/474709a9a2a74a8bcf0055fadb335d0ca0d2d939/compiler/rustc_infer/src/infer/combine.rs:178:31
             0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
             2: <rustc_infer::infer::InferCtxt>::super_combine_consts::<rustc_infer::infer::nll_relate::TypeRelating<rustc_infer::infer::canonical::query_response::QueryTypeRelatingDelegate>>
             3: <rustc_infer::infer::nll_relate::TypeRelating<rustc_infer::infer::canonical::query_response::QueryTypeRelatingDelegate> as rustc_middle::ty::relate::TypeRelation>::consts
             4: <rustc_infer::infer::InferCtxt>::instantiate_nll_query_response_and_region_obligations::<()>
             5: <rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::AscribeUserType> as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform
             6: <rustc_borrowck::type_check::TypeChecker>::ascribe_user_type
             7: rustc_borrowck::type_check::type_check
             8: rustc_borrowck::nll::compute_regions
             9: rustc_borrowck::do_mir_borrowck
            10: rustc_borrowck::mir_borrowck
            11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            12: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
            13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            14: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
            15: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
            16: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}>
            17: rustc_interface::passes::analysis
            18: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
            19: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
            20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            21: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            22: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            23: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
            24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/474709a9a2a74a8bcf0055fadb335d0ca0d2d939/library/alloc/src/boxed.rs:2007:9
            27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/474709a9a2a74a8bcf0055fadb335d0ca0d2d939/library/alloc/src/boxed.rs:2007:9
            28: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/474709a9a2a74a8bcf0055fadb335d0ca0d2d939/library/std/src/sys/unix/thread.rs:108:17
            29: <unknown>
            30: <unknown>


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 attach the file at `/tmp/im/rustc-ice-2023-08-04T10:13:31.528732612Z-1012286.txt` to your bug report

query stack during panic:
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

Activity

  1. 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.
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    F-checked_type_aliases`#![feature(checked_type_aliases)]` (formerly: `lazy_type_alias`)
    on Aug 4, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 4, 2023
  3. matthiaskrgr commented on Aug 4, 2023

    @matthiaskrgr
    MemberAuthor

    bisected to introduction in #112853

  4. fmease commented on Aug 4, 2023

    @fmease
    Member

    Lazy type aliases are not necessary to reproduce this:

    #![feature(adt_const_params)]
    
    const EMPTY_MATRIX: <Type as Trait>::Matrix = [0; 1];
    
    pub struct Walk<const REMAINING: <Type as Trait>::Matrix> {}
    
    impl Walk<EMPTY_MATRIX> {
        pub const fn new() -> Self {
            Self {}
        }
    }
    
    pub enum Type {}
    pub trait Trait { type Matrix; }
    impl Trait for Type { type Matrix = [usize; 1]; }
    
    fn main() {
        let _ = Walk::new();
    }
  5. fmease commented on Aug 4, 2023

    @fmease
    Member

    I'd like to clarify, we should definitely keep the label F-lazy_type_alias since this code will regress if / once we make lazy type aliases the default (in a new edition). However, my finding demonstrates that the bug is preexisting. The faulty code path doesn't handle alias types (ty::AliasTy) correctly (ty::Projection in the case of associated types and ty::Weak in the case of lazy type aliases).

    @rustbot label -needs-triage

  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 4, 2023
  7. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Apr 15, 2024
  8. added a commit that references this issue on May 30, 2024
    948faa2
  9. added a commit that references this issue on May 30, 2024
    32a3ed2
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.F-adt_const_params`#![feature(adt_const_params)]`F-checked_type_aliases`#![feature(checked_type_aliases)]` (formerly: `lazy_type_alias`)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions