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: assertion failed: !obligations.has_infer() in rustc_hir_analysis/src/impl_wf_check/min_specialization.rs with feature min_specialization #126268

Open
cushionbadak opened this issue Jun 11, 2024 · 3 comments
Labels
C-bug Category: This is a bug. F-min_specialization `#![feature(min_specialization)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(hand-reduced)

#![feature(min_specialization)]

trait Trait {}

impl<T> Trait for T {}

trait Data {
    type Elem;
}

struct DatasetIter<'a, R: Data> {
    data: &'a R::Elem,
}

pub struct ArrayBase {}

impl<'a> Trait for DatasetIter<'a, ArrayBase> {}

fn main() {}
(original, 190+ lines)

// Because of #109628, when we compute the implied bounds from `Foo<X>`,
// we incorrectly get `X: placeholder('x)`.
// Make sure we ignore these bogus bounds and not use them for anything useful.
//
//@ revisions: fail pass
//@ [fail] check-fail
//@ [pass] check-pass

trait Trait {
    type Ty<'a> where Self: 'a;
}

impl<T> Trait for T {
    type Ty<'a> = () where Self: 'a;
}

struct Foo<T: Trait>(T)
where
    for<'x> T::Ty<'x>: Sized;

trait AnotherTrait {
    type Ty2<'a>: 'a;
}

#[cfg(fail)]
mod fail {
    use super::*;

    // implied_bound: `'lt: placeholder('x)`.
    // don't use the bound to prove `'lt: 'static`.
    fn test_lifetime<'lt, T: Trait>(_: Foo<&'lt u8>) {}
    //[fail]~^ ERROR `&'lt u8` does not fulfill the required lifetime

    // implied bound: `T::Ty2<'lt>: placeholder('x)`.
    // don't use the bound to prove `T::Ty2<'lt>: 'static`.
    fn test_alias<'lt, T: AnotherTrait>(_: Foo<T::Ty2::<'lt>>) {}
    //[fail]~^ ERROR `<T as AnotherTrait>::Ty2<'lt>` does not fulfill the required lifetime
}


mod pass {
    use super::*;

    // implied_bound: 'static: placeholder('x).
    // don't ice.
    fn test_lifetime<T: Trait>(_: Foo<&'static u8>) {}

    // implied bound: T::Ty2<'static>: placeholder('x).
    // don't add the bound to the environment,
    // otherwise we would fail to infer a value for `'_`.
    fn test_alias<T: AnotherTrait>(_: Foo<T::Ty2::<'static>>) {
        None::<&'static T::Ty2<'_>>;
    }
}

fn main() {}


//@ check-pass

trait Data {
    type Elem;
}

impl<F, S: Data<Elem = F>> Data for ArrayBase<S> {
    type Elem = F;
}

struct DatasetIter<'a, R: Data> {
    data: &'a R::Elem,
}

pub struct ArrayBase<S> {
    data: S,
}

trait Trait {
    type Item;
    fn next() -> Option<Self::Item>;
}

impl<'a, D: Data> Trait for DatasetIter<'a, ArrayBase<D>> {
    type Item = ();

    fn next() -> Option<Self::Item> {
        None
    }
}

fn main() {}


// Make sure that built-in derives don't rely on the user not declaring certain
// names to work properlDebug, Hash)]
enum A<A> {
    A(A),
    A{ C  C: },
}

// Make sure that we aren't using `self::` in paths, since it doesn't work in
// non-module scopes.
const A: () = {
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A, }

    #[repr(i16)]
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A(A), A{ C  C: } }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
    struct A<A> {
        A: A,
    }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    struct A<A: A>(B)
    where
        A: A< {
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A(A), }

    #[repr(i16)]
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A, A{ C  C: } }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
    struct A<A> {
        A: A,
    }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    struct A<A: A< {
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A(A), }

    #[repr(i16)]
    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A { A, A{ C  C: } }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
    struct A<A> {
        A: A,
    }

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    struct A<A: Foo>(B)
    where
        A: D< continue >;

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A<A> {
        A(
),
        A { A: A },
    }
} >>(B)
    where
        A: A< continue >;

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A<A> {
        A(
),
        A { A: A },
    }
} >;

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum A<A> {
        A(
),
        A { A: A },
    }
};

macro A() {
    #[derive(CartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
    struct Y<B>(B)
    where
        B: From<B>;

    #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
    enum Z<C> {
        C(C),
        B { C: C },
    }
}

A!();

fn A() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (b5b13568f 2024-06-10)
binary: rustc
commit-hash: b5b13568fb5da4ac988bde370008d6134d3dfe6c
commit-date: 2024-06-10
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

Command: rustc

error: specialization impl does not specialize any associated items
  --> r_min_spec_9BA0891CC.rs:17:1
   |
17 | impl<'a> Trait for DatasetIter<'a, ArrayBase> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: impl is a specialization of this impl
  --> r_min_spec_9BA0891CC.rs:5:1
   |
5  | impl<T> Trait for T {}
   | ^^^^^^^^^^^^^^^^^^^
Backtrace

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs:417:9:
assertion failed: !obligations.has_infer()
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: rustc_hir_analysis::impl_wf_check::min_specialization::check_always_applicable
   4: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
   5: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
   6: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
   7: rustc_hir_analysis::check_crate
   8: rustc_interface::passes::run_required_analyses
   9: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  10: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  11: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, 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/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 `/Volumes/T7/workspace/240607_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-11T11_20_55-64291.txt` to your bug report

query stack during panic:
#0 [check_well_formed] checking that `<impl at r_min_spec_9BA0891CC.rs:17:1: 17:46>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error

Notes

@cushionbadak cushionbadak added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 11, 2024
@lqd lqd added requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue F-min_specialization `#![feature(min_specialization)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 11, 2024
@lqd
Copy link
Member

lqd commented Jun 11, 2024

This is quite old, and has been ICEing since the nightly where #68970 introduced min_specialization.

@matthiaskrgr
Copy link
Member

Looks like a duplicate of #102252

@cushionbadak
Copy link
Author

cushionbadak commented Jun 12, 2024

Both this report and issue #102252 point to the same ICE location. However, the trigger in #102252 relies on #![feature(rustc_attrs)], while this issue does not use internal features. Therefore I believe this could be considered as a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-min_specialization `#![feature(min_specialization)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants