Skip to content

ICE: compiler/rustc_typeck/src/variance/constraints.rs:332:17: unexpected type encountered in variance inference: FreshTy(0) #82927

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
chengniansun opened this issue Mar 9, 2021 · 5 comments · Fixed by #100247
Labels
A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@chengniansun
Copy link

chengniansun commented Mar 9, 2021

Code

trait SendEqAlias<T> = PartialEq;
struct Foo;
struct Bar<T>(SendEqAlias<T>);

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (8f349be27 2021-03-08)
binary: rustc
commit-hash: 8f349be27815d43d462a32faeb270a22a68486b6
commit-date: 2021-03-08
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

error[E0658]: trait aliases are experimental
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | trait SendEqAlias<T> = PartialEq;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #41517 <https://github.com/rust-lang/rust/issues/41517> for more information
  = help: add `#![feature(trait_alias)]` to the crate attributes to enable

warning: trait objects without an explicit `dyn` are deprecated
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:3:15
  |
3 | struct Bar<T>(SendEqAlias<T>);
  |               ^^^^^^^^^^^^^^ help: use `dyn`: `dyn SendEqAlias<T>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / trait SendEqAlias<T> = PartialEq;
2 | | struct Foo;
3 | | struct Bar<T>(SendEqAlias<T>);
  | |______________________________^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error: internal compiler error: compiler/rustc_typeck/src/variance/constraints.rs:332:17: unexpected type encountered in variance inference: FreshTy(0)

thread 'rustc' panicked at 'Box<Any>', /rustc/8f349be27815d43d462a32faeb270a22a68486b6/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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: rustc 1.52.0-nightly (8f349be27 2021-03-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [crate_variances] computing the variances for items in this crate
#1 [variances_of] computing the variances of `Foo`
end of query stack

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)
Backtrace

error[E0658]: trait aliases are experimental
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | trait SendEqAlias<T> = PartialEq;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #41517 <https://github.com/rust-lang/rust/issues/41517> for more information
  = help: add `#![feature(trait_alias)]` to the crate attributes to enable

warning: trait objects without an explicit `dyn` are deprecated
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:3:15
  |
3 | struct Bar<T>(SendEqAlias<T>);
  |               ^^^^^^^^^^^^^^ help: use `dyn`: `dyn SendEqAlias<T>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / trait SendEqAlias<T> = PartialEq;
2 | | struct Foo;
3 | | struct Bar<T>(SendEqAlias<T>);
  | |______________________________^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error: internal compiler error: compiler/rustc_typeck/src/variance/constraints.rs:332:17: unexpected type encountered in variance inference: FreshTy(0)

thread 'rustc' panicked at 'Box<Any>', /rustc/8f349be27815d43d462a32faeb270a22a68486b6/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_typeck::variance::constraints::ConstraintContext::add_constraints_from_ty
   8: rustc_typeck::variance::constraints::ConstraintContext::add_constraints_from_invariant_substs
   9: rustc_typeck::variance::constraints::ConstraintContext::add_constraints_from_ty
  10: rustc_typeck::variance::constraints::ConstraintContext::visit_node_helper
  11: <rustc_typeck::variance::constraints::ConstraintContext as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_item
  12: rustc_hir::hir::Crate::visit_all_item_likes
  13: rustc_typeck::variance::constraints::add_constraints_from_crate
  14: rustc_typeck::variance::crate_variances
  15: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::crate_variances>::compute
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::force_query_with_job
  19: rustc_query_system::query::plumbing::get_query_impl
  20: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::crate_variances
  21: rustc_typeck::variance::variances_of
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::force_query_with_job
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::variances_of
  27: rustc_typeck::check::wfcheck::check_variances_for_type_defn
  28: rustc_typeck::check::wfcheck::check_item_well_formed
  29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  30: rustc_query_system::query::plumbing::force_query_with_job
  31: rustc_query_system::query::plumbing::get_query_impl
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  33: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_item
  34: rustc_data_structures::sync::par_for_each_in
  35: rustc_hir::hir::Crate::par_visit_all_item_likes
  36: rustc_session::session::Session::track_errors
  37: rustc_typeck::check_crate
  38: rustc_interface::passes::analysis
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::force_query_with_job
  42: rustc_query_system::query::plumbing::get_query_impl
  43: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  44: rustc_interface::passes::QueryContext::enter
  45: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  46: rustc_span::with_source_map
  47: rustc_interface::interface::create_compiler_and_run
  48: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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: rustc 1.52.0-nightly (8f349be27 2021-03-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [crate_variances] computing the variances for items in this crate
#1 [variances_of] computing the variances of `Foo`
#2 [check_item_well_formed] checking that `Foo` is well-formed
#3 [analysis] running analysis passes on this crate
end of query stack

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)

@chengniansun chengniansun 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 Mar 9, 2021
@csmoe
Copy link
Member

csmoe commented Mar 9, 2021

https://rust.godbolt.org/z/ooz8v4
regression starts from rustc 1.37

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Mar 9, 2021

@rustbot claim

@ChayimFriedman2
Copy link
Contributor

Turns out that if you remove struct Foo; there's a stack overflow. Probably related, but I'm not sure yet.

fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 12, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 12, 2021
@ChayimFriedman2
Copy link
Contributor

@rustbot release-assignment

@BGR360
Copy link
Contributor

BGR360 commented Dec 27, 2021

@rustbot label +A-variance

@rustbot rustbot added the A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) label Dec 27, 2021
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 11, 2022
…faults, r=lcnr

Generalize trait object generic param check to aliases.

The current algorithm only checks that `Self` does not appear in defaults for traits.  This is not sufficient for trait aliases.
This PR moves the check to trait object elaboration, which sees through trait aliases.

Fixes rust-lang#82927.
Fixes rust-lang#84789.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 12, 2022
…faults, r=lcnr

Generalize trait object generic param check to aliases.

The current algorithm only checks that `Self` does not appear in defaults for traits.  This is not sufficient for trait aliases.
This PR moves the check to trait object elaboration, which sees through trait aliases.

Fixes rust-lang#82927.
Fixes rust-lang#84789.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 12, 2022
…faults, r=lcnr

Generalize trait object generic param check to aliases.

The current algorithm only checks that `Self` does not appear in defaults for traits.  This is not sufficient for trait aliases.
This PR moves the check to trait object elaboration, which sees through trait aliases.

Fixes rust-lang#82927.
Fixes rust-lang#84789.
@bors bors closed this as completed in caac670 Aug 12, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

6 participants