Skip to content

Associated const with supertrait associated type (named the same) causes ICE #93553

Closed
@rodrimati1992

Description

@rodrimati1992

Code

trait Foo {
    type Bar;
}

trait Baz: Foo {
    const Bar: Self::Bar;
}

Meta

rust version:

1.60.0-nightly (2022-01-31 498eeb72f590e518e197)

(tried in the play.rust-lang.org playground)

This compiles successfully on the stable and beta channels.

Error output


error[E0221]: ambiguous associated type `Bar` in bounds of `Self`
 --> src/lib.rs:6:16
  |
2 |     type Bar;
  |     --------- ambiguous `Bar` from `Foo`
...
6 |     const Bar: Self::Bar;
  |                ^^^^^^^^^ ambiguous associated type `Bar`
  |
  = note: associated type `Self` could derive from `Baz`
help: use fully qualified syntax to disambiguate
  |
6 |     const Bar: <Self as Foo>::Bar;
  |                ~~~~~~~~~~~~~~~

thread 'rustc' panicked at 'missing associated type', compiler/rustc_typeck/src/astconv/mod.rs:1886:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.60.0-nightly (498eeb72f 2022-01-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [type_of] computing type of `Baz::Bar`
#1 [collect_mod_item_types] collecting item types in top-level module
end of query stack
For more information about this error, try `rustc --explain E0221`.
error: could not compile `playground` due to previous error
Backtrace


thread 'rustc' panicked at 'missing associated type', compiler/rustc_typeck/src/astconv/mod.rs:1886:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/498eeb72f590e518e19746b346be53713689e207/library/std/src/panicking.rs:577:5
   1: core::panicking::panic_fmt
             at /rustc/498eeb72f590e518e19746b346be53713689e207/library/core/src/panicking.rs:135:14
   2: core::panicking::panic_display
             at /rustc/498eeb72f590e518e19746b346be53713689e207/library/core/src/panicking.rs:65:5
   3: core::panicking::panic_str
             at /rustc/498eeb72f590e518e19746b346be53713689e207/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/498eeb72f590e518e19746b346be53713689e207/library/core/src/option.rs:1840:5
   5: <dyn rustc_typeck::astconv::AstConv>::associated_path_to_ty
   6: <dyn rustc_typeck::astconv::AstConv>::ast_ty_to_ty_inner
   7: rustc_typeck::collect::type_of::type_of
   8: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
   9: <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_trait_item
  10: <rustc_middle::hir::map::Map>::visit_item_likes_in_module::<rustc_hir::intravisit::DeepVisitor<rustc_typeck::collect::CollectItemTypesVisitor>>
  11: rustc_typeck::collect::collect_mod_item_types
  12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  13: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
  14: <rustc_middle::hir::map::Map>::for_each_module::<rustc_typeck::check_crate::{closure#0}::{closure#0}::{closure#0}>
  15: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#0}, ()>
  16: rustc_typeck::check_crate
  17: rustc_interface::passes::analysis
  18: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  19: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  20: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  21: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  22: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  23: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions