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: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter T/#1 (T/1) out of range when substituting, substs=[Self] #78671

Closed
chengniansun opened this issue Nov 2, 2020 · 5 comments · Fixed by #84379
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@chengniansun
Copy link

Code

trait CollectionFamily {
    type Member<T>;
}
fn floatify() {
    Family as CollectionFamily
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (b20253260 2020-11-01)
binary: rustc
commit-hash: b2025326088b54fb3f083bebeba14e0a15bf00d3
commit-date: 2020-11-01
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

warning: trait objects without an explicit `dyn` are deprecated
  --> mutant.rs:37:66
   |
37 | let mut res = < C :: Family as CollectionFamily > :: Member :: < CollectionFamily > :: empty ( ) ;
   |                                                                  ^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn CollectionFamily`
   |
   = note: `#[warn(bare_trait_objects)]` on by default

error[E0191]: the value of the associated type `Member` (from trait `CollectionFamily`) must be specified
  --> mutant.rs:37:66
   |
14 | type Member < T > : Collection < T , Family = Self > ;
   | ------------------------------------------------------ `Member` defined here
...
37 | let mut res = < C :: Family as CollectionFamily > :: Member :: < CollectionFamily > :: empty ( ) ;
   |                                                                  ^^^^^^^^^^^^^^^^ help: specify the associated type: `CollectionFamily<Member = Type>`

error[E0599]: no function or associated item named `empty` found for associated type `<<C as Collection<i32>>::Family as CollectionFamily>::Member<dyn CollectionFamily>` in the current scope
  --> mutant.rs:37:88
   |
13 | trait CollectionFamily {
   | ---------------------- doesn't satisfy `dyn CollectionFamily: Sized`
...
37 | let mut res = < C :: Family as CollectionFamily > :: Member :: < CollectionFamily > :: empty ( ) ;
   |                                                                                        ^^^^^ function or associated item not found in `<<C as Collection<i32>>::Family as CollectionFamily>::Member<dyn CollectionFamily>`
   |
   = note: the method `empty` exists but the following trait bounds were not satisfied:
           `dyn CollectionFamily: Sized`
           which is required by `<<C as Collection<i32>>::Family as CollectionFamily>::Member<dyn CollectionFamily>: Collection<dyn CollectionFamily>`

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter `T/#1` (T/1) out of range when substituting, substs=[Self]

thread 'rustc' panicked at 'Box<Any>', /rustc/b2025326088b54fb3f083bebeba14e0a15bf00d3/compiler/rustc_errors/src/lib.rs:904:9
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.49.0-nightly (b20253260 2020-11-01) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [object_safety_violations] determine object safety of trait `CollectionFamily`
#1 [typeck] type-checking `floatify`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0191, E0599.
For more information about an error, try `rustc --explain E0191`.

Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/b2025326088b54fb3f083bebeba14e0a15bf00d3/compiler/rustc_errors/src/lib.rs:904:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::span_bug_fmt
   8: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
   9: rustc_middle::ty::fold::TypeFoldable::fold_with
  10: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  11: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
  12: rustc_middle::ty::fold::TypeFoldable::fold_with
  13: rustc_middle::ty::fold::TypeFoldable::fold_with
  14: rustc_middle::ty::Predicate::subst_supertrait
  15: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
  16: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  17: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  18: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  19: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  20: rustc_middle::arena::Arena::alloc_from_iter
  21: rustc_trait_selection::traits::object_safety::object_safety_violations
  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::get_query_impl
  25: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::is_object_safe
  26: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  27: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  28: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  29: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_method_argument_types
  30: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  33: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_coercable_to_type
  34: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_local
  35: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  36: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  37: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  38: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  39: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  40: rustc_typeck::check::check::check_fn
  41: rustc_infer::infer::InferCtxtBuilder::enter
  42: rustc_typeck::check::typeck
  43: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::get_query_impl
  47: rustc_query_system::query::plumbing::ensure_query_impl
  48: rustc_typeck::check::typeck_item_bodies
  49: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  50: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  51: rustc_data_structures::stack::ensure_sufficient_stack
  52: rustc_query_system::query::plumbing::get_query_impl
  53: rustc_typeck::check_crate
  54: rustc_interface::passes::analysis
  55: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  56: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  57: rustc_data_structures::stack::ensure_sufficient_stack
  58: rustc_query_system::query::plumbing::get_query_impl
  59: rustc_interface::passes::QueryContext::enter

NOTE: The bug is found by our work-in-progress compiler testing tool Kira, and the test program is reduced/minimized by Perses

@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 Nov 2, 2020
@jonas-schievink jonas-schievink added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Nov 2, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Nov 8, 2020
@matthiaskrgr
Copy link
Member

This crashes in 1.49.0-beta.4 and 1.50.0-nightly but not 1.48.0.
@rustbot modify labels: +regression-from-stable-to-beta

@rustbot rustbot added regression-from-stable-to-beta Performance or correctness regression from stable to beta. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@matthiaskrgr
Copy link
Member

The ICE is caused by 08e2d46 cc @matthewjasper

@Mark-Simulacrum Mark-Simulacrum added this to the 1.49.0 milestone Dec 20, 2020
@rylev
Copy link
Member

rylev commented Dec 21, 2020

The following produces the same ICE but with less warnings and errors:

trait CollectionFamily {
    type Member<T>;
}
fn floatify() {
    Box::new(Family) as &dyn CollectionFamily<Member=usize>
}

struct Family;

@apiraino apiraino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 23, 2020
@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@Mark-Simulacrum Mark-Simulacrum added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jan 21, 2021
@matthewjasper matthewjasper added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 6, 2021
@estebank
Copy link
Contributor

estebank commented Feb 22, 2021

ICE fixed in beta, but the output has an incorrect suggestion:

error[E0658]: generic associated types are unstable
 --> src/lib.rs:2:5
  |
2 |     type Member<T>;
  |     ^^^^^^^^^^^^^^^
  |
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0107]: missing generics for associated type `CollectionFamily::Member`
 --> src/lib.rs:2:10
  |
2 |     type Member<T>;
  |          ^^^^^^ expected 1 type argument
  |
note: associated type defined here, with 1 type parameter: `T`
 --> src/lib.rs:2:10
  |
2 |     type Member<T>;
  |          ^^^^^^ -
help: use angle brackets to add missing type argument
  |
2 |     type Member<T><T>;
  |                ^^^

We need to correctly track the span for the obligation to suggest somewhat reasonable code.

marmeladema added a commit to marmeladema/rust that referenced this issue Apr 20, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 21, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Apr 21, 2021
@bors bors closed this as completed in e7f2033 Apr 22, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.