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: !value.has_infer() in rustc_hir_typeck/src/writeback.rs #125760

Closed
cushionbadak opened this issue May 30, 2024 · 0 comments · Fixed by #125807
Closed

ICE: assertion failed: !value.has_infer() in rustc_hir_typeck/src/writeback.rs #125760

cushionbadak opened this issue May 30, 2024 · 0 comments · Fixed by #125807
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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.

Comments

@cushionbadak
Copy link

Code

(hand-reduced)

#![feature(type_alias_impl_trait)]
type Bar = impl std::fmt::Display;

async fn test<const N: crate::Bar>() {}

fn main () {}
(original)

//@ check-pass

#![feature(type_alias_impl_trait)]
#![allow(dead_code)]

// test that the type alias impl trait defining use is in a submodule

fn main() {}

type Foo = impl std::fmt::Display;
type Bar = impl std::fmt::Display;

mod foo {
    pub(crate) fn foo() -> super::Foo {
        "foo"
    }

    pub(crate) mod bar {
        pub(crate) fn bar() -> crate::Bar {
            1
        }
    }
}


//@ check-pass

trait Database: for<'r> HasValueRef<'r, Database = Self> {}

trait HasValueRef<'r> {
    type Database: Database;
}

struct Any;

impl Database for Any {}

impl<'r> HasValueRef<'r> for Any {
    // Make sure we don't have issues when the GAT assumption
    // `<Any as HasValue<'r>>::Database = Any` isn't universally
    // parameterized over `'r`.
    type Database = Any;
}

fn main() {}


async fn main() {
    // Adding an .await here avoids the ICE
    test()?;
}

// Removing the const generic parameter here avoids the ICE
async fn test<const N: crate::Bar>() {
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (debd22da6 2024-05-29)
binary: rustc
commit-hash: debd22da66cfa97c74040ebf68e420672ac8560e
commit-date: 2024-05-29
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc --edition=2018

  • --edition option is added to avoid async fn error message
error[E0283]: type annotations needed
 --> r_writeback_C9DEFA.rs:4:1
  |
4 | async fn test<const N: crate::Bar>() {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: cannot satisfy `_: std::fmt::Display`

(there exists another error at the end of the backtrace)

Backtrace

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/writeback.rs:749:9:
assertion failed: !value.has_infer()
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <rustc_hir_typeck::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
   4: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
   5: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
   6: <rustc_hir_analysis::collect::type_of::opaque::TaitConstraintLocator>::check
   7: rustc_hir_analysis::collect::type_of::type_of_opaque
      [... omitted 1 frame ...]
   8: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
   9: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 1 frame ...]
  10: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  11: rustc_hir_analysis::check::check::check_item_type
  12: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  13: 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]>>, ()>
  14: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  15: rustc_hir_analysis::check_crate
  16: rustc_interface::passes::run_required_analyses
  17: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  18: <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}>
  19: 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/240529_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-30T07_50_14-17949.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `test`
#1 [type_of_opaque] computing type of opaque `Bar::{opaque#0}`
#2 [type_of] computing type of `Bar::{opaque#0}`
#3 [check_well_formed] checking that `Bar::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack
error: `Bar` is forbidden as the type of a const generic parameter
 --> r_writeback_C9DEFA.rs:4:24
  |
4 | async fn test<const N: crate::Bar>() {}
  |                        ^^^^^^^^^^
  |
  = note: the only supported types are integers, `bool` and `char`

error: aborting due to 2 previous errors

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

Note

  • ICE location: rustc_hir_typeck/src/writeback.rs L749
    fn resolve<T>(&mut self, value: T, span: &dyn Locatable) -> T
    where
    T: TypeFoldable<TyCtxt<'tcx>>,
    {
    let value = self.fcx.resolve_vars_if_possible(value);
    let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body));
    assert!(!value.has_infer());
  • Might be related to unsolved ICE Issue-115806 (issue fixed by adding test-case), where the issue points to rustc_trait_selection/src/solve/canonicalize.rs L72
    let value = value.fold_with(&mut canonicalizer);
    assert!(!value.has_infer());
@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 May 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2024
@fmease fmease added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-lazy_type_alias `#![feature(lazy_type_alias)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-lazy_type_alias `#![feature(lazy_type_alias)]` labels May 30, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue May 31, 2024
…piler-errors

Also resolve the type of constants, even if we already turned it into an error constant

error constants can still have arbitrary types, and in this case it was turned into an error constant because there was an infer var in the *type* not the *const*.

fixes rust-lang#125760
@bors bors closed this as completed in 619b3e8 May 31, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 31, 2024
Rollup merge of rust-lang#125807 - oli-obk:resolve_const_types, r=compiler-errors

Also resolve the type of constants, even if we already turned it into an error constant

error constants can still have arbitrary types, and in this case it was turned into an error constant because there was an infer var in the *type* not the *const*.

fixes rust-lang#125760
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-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants