rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.35k stars 12.59k forks source link

ICE: `Failed to normalize Alias(Weak, AliasTy {` with `feature(type_alias_impl_trait)` #127353

Open Naserume opened 3 months ago

Naserume commented 3 months ago

Code

#![feature(type_alias_impl_trait)]
trait Trait<T> {}
type Alias<'a, U> = impl Trait<U>;

fn f<'a>() -> Alias<'a, ()> {}

pub enum UninhabitedVariants {
    Tuple(Alias),
}

struct A;

fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything(x: UninhabitedVariants) -> A {
    match x {}
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (cc8da78a0 2024-07-04)
binary: rustc
commit-hash: cc8da78a036dc3c15c35a97651b02af9a6d30c1e
commit-date: 2024-07-04
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error[E0106]: missing lifetime specifier
 --> ./24D5A.rs:8:11
  |
8 |     Tuple(Alias),
  |           ^^^^^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
7 ~ pub enum UninhabitedVariants<'a> {
8 ~     Tuple(Alias<'a>),
  |

error[E0107]: missing generics for type alias `Alias`
 --> ./24D5A.rs:8:11
  |
8 |     Tuple(Alias),
  |           ^^^^^ expected 1 generic argument
  |
note: type alias defined here, with 1 generic parameter: `U`
 --> ./24D5A.rs:3:6
  |
3 | type Alias<'a, U> = impl Trait<U>;
  |      ^^^^^     -
help: add missing generic argument
  |
8 |     Tuple(Alias<U>),
  |                +++

error[E0792]: non-defining opaque type use in defining scope
 --> ./24D5A.rs:5:15
  |
5 | fn f<'a>() -> Alias<'a, ()> {}
  |               ^^^^^^^^^^^^^ argument `()` is not a generic parameter
  |
note: for this opaque type
 --> ./24D5A.rs:3:21
  |
3 | type Alias<'a, U> = impl Trait<U>;
  |                     ^^^^^^^^^^^^^

error[E0277]: the trait bound `(): Trait<()>` is not satisfied
 --> ./24D5A.rs:5:15
  |
5 | fn f<'a>() -> Alias<'a, ()> {}
  |               ^^^^^^^^^^^^^ the trait `Trait<()>` is not implemented for `()`
  |
help: this trait has no implementations, consider adding one
 --> ./24D5A.rs:2:1
  |
2 | trait Trait<T> {}
  | ^^^^^^^^^^^^^^

error[E0792]: non-defining opaque type use in defining scope
 --> ./24D5A.rs:8:11
  |
8 |     Tuple(Alias),
  |           ^^^^^ argument `'_` is not a generic parameter
  |
note: for this opaque type
 --> ./24D5A.rs:3:21
  |
3 | type Alias<'a, U> = impl Trait<U>;
  |                     ^^^^^^^^^^^^^

error: item does not constrain `Alias::{opaque#0}`, but has it in its signature
  --> ./24D5A.rs:13:4
   |
13 | fn cannot_empty_match_on_enum_with_empty_variants_struct_to_anything(x: UninhabitedVariants) -> A {
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: consider moving the opaque type's declaration and defining uses into a separate module
note: this opaque type is in the signature
  --> ./24D5A.rs:3:21
   |
3  | type Alias<'a, U> = impl Trait<U>;
   |                     ^^^^^^^^^^^^^
Backtrace

``` error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:168:90: Failed to normalize Alias(Weak, AliasTy { args: ['{erased}, {type error}], def_id: DefId(0:5 ~ 24D5A[2b49]::Alias) }), maybe try to call `try_normalize_erasing_regions` instead thread 'rustc' panicked at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:168:90: Box stack backtrace: 0: 0x107af2d93 - ::fmt::hfeb614152c5fc770 1: 0x107b3e17b - core::fmt::write::h19d9b55d1716a641 2: 0x107ae8b7e - std::io::Write::write_fmt::h65bfd6c063c93506 3: 0x107af2b81 - std::sys::backtrace::print::h6f13abc1d63a7b7a 4: 0x107af5959 - std::panicking::default_hook::{{closure}}::h53504a5e8286ae49 5: 0x107af56da - std::panicking::default_hook::h46ce4737ada06aa6 6: 0x110deb07c - std[96ba86566161595a]::panicking::update_hook::>::{closure#0} 7: 0x107af6699 - std::panicking::rust_panic_with_hook::h3ebbbfeff58c5313 8: 0x110e5f177 - std[96ba86566161595a]::panicking::begin_panic::::{closure#0} 9: 0x110e4afb9 - std[96ba86566161595a]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x115884fc9 - std[96ba86566161595a]::panicking::begin_panic:: 11: 0x110e712b6 - ::emit_producing_guarantee 12: 0x111b16315 - rustc_middle[3507220e01ce78dc]::util::bug::opt_span_bug_fmt::::{closure#0} 13: 0x111acbf57 - rustc_middle[3507220e01ce78dc]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 14: 0x111acba95 - rustc_middle[3507220e01ce78dc]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 15: 0x11594862b - rustc_middle[3507220e01ce78dc]::util::bug::bug_fmt 16: 0x1121c2343 - ::ctor_sub_tys 17: 0x1121ba4ee - >::wild_from_ctor 18: 0x1121ce5c3 - rustc_pattern_analysis[c69ad356d2d58605]::usefulness::compute_exhaustiveness_and_usefulness:: 19: 0x1121c6fa7 - rustc_pattern_analysis[c69ad356d2d58605]::analyze_match 20: 0x111c15814 - ::analyze_patterns 21: 0x111c4b85f - ::visit_expr 22: 0x111c4c0dd - ::visit_expr 23: 0x111c4b5f8 - ::visit_expr 24: 0x111b7f3ee - rustc_middle[3507220e01ce78dc]::thir::visit::walk_block:: 25: 0x111c4c0dd - ::visit_expr 26: 0x111c4b5f8 - ::visit_expr 27: 0x111c148e8 - rustc_mir_build[7e4b23411c86858b]::thir::pattern::check_match::check_match 28: 0x1124a50dc - rustc_query_impl[e04fdc29b284e1d7]::plumbing::__rust_begin_short_backtrace::> 29: 0x1123292af - rustc_query_system[31cd079b68d87400]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e04fdc29b284e1d7]::plumbing::QueryCtxt, false> 30: 0x1124d9200 - rustc_query_impl[e04fdc29b284e1d7]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace 31: 0x111bc8464 - rustc_mir_build[7e4b23411c86858b]::build::mir_build 32: 0x111eabb2c - rustc_mir_transform[7f80daa91ef18b2a]::mir_built 33: 0x1124ac36c - rustc_query_impl[e04fdc29b284e1d7]::plumbing::__rust_begin_short_backtrace::> 34: 0x11232265e - rustc_query_system[31cd079b68d87400]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e04fdc29b284e1d7]::plumbing::QueryCtxt, false> 35: 0x1124bc28b - rustc_query_impl[e04fdc29b284e1d7]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 36: 0x111c0e61b - rustc_mir_build[7e4b23411c86858b]::check_unsafety::check_unsafety 37: 0x1124a5bce - rustc_query_impl[e04fdc29b284e1d7]::plumbing::__rust_begin_short_backtrace::> 38: 0x1123249d8 - rustc_query_system[31cd079b68d87400]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e04fdc29b284e1d7]::plumbing::QueryCtxt, false> 39: 0x1124cb7a0 - rustc_query_impl[e04fdc29b284e1d7]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace 40: 0x1116c5512 - ::par_body_owners::::{closure#0} 41: 0x11176237c - rustc_interface[dea1eaaf15b0b7c8]::passes::run_required_analyses 42: 0x1117647f0 - rustc_interface[dea1eaaf15b0b7c8]::passes::analysis 43: 0x1124abeac - rustc_query_impl[e04fdc29b284e1d7]::plumbing::__rust_begin_short_backtrace::> 44: 0x11228ac1e - rustc_query_system[31cd079b68d87400]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[e04fdc29b284e1d7]::plumbing::QueryCtxt, false> 45: 0x1124b6407 - rustc_query_impl[e04fdc29b284e1d7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 46: 0x110d94bb7 - >::enter::, rustc_driver_impl[d6cc6074f4ffa8bf]::run_compiler::{closure#0}::{closure#1}::{closure#5}> 47: 0x110df23cb - rustc_interface[dea1eaaf15b0b7c8]::interface::run_compiler::, rustc_driver_impl[d6cc6074f4ffa8bf]::run_compiler::{closure#0}>::{closure#1} 48: 0x110ddc9f1 - std[96ba86566161595a]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[d6cc6074f4ffa8bf]::run_compiler::{closure#0}>::{closure#1}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>>::{closure#0}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>> 49: 0x110df8d96 - <::spawn_unchecked_, rustc_driver_impl[d6cc6074f4ffa8bf]::run_compiler::{closure#0}>::{closure#1}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>>::{closure#0}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[677ae2db44f68e98]::result::Result<(), rustc_span[9a6059d5c98a4f34]::ErrorGuaranteed>>::{closure#2} as core[677ae2db44f68e98]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 50: 0x107aff83b - std::sys::pal::unix::thread::Thread::new::thread_start::he8797374daece752 51: 0x7ff801f5318b - __pthread_start 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 `/Users/240703-nightly/rustc-ice-2024-07-05T02_05_23-90845.txt` to your bug report query stack during panic: #0 [check_match] match-checking `cannot_empty_match_on_enum_with_empty_variants_struct_to_anything` #1 [mir_built] building MIR for `cannot_empty_match_on_enum_with_empty_variants_struct_to_anything` end of query stack error: aborting due to 7 previous errors Some errors have detailed explanations: E0106, E0107, E0277, E0792. For more information about an error, try `rustc --explain E0106`. ```

Note

Ice location: https://github.com/rust-lang/rust/blob/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs#L161-L173

Similar Issue

109387 use same feature but has different query stack

120267 has same query stack, but mine uses (type_alias_impl_trait) and Alias(Weak, AliasTy { was something I'v never seen before

@rustbot label +F-type_alias_impl_trait

GrigorenkoPV commented 3 months ago

Bisects to #125667, just like #127351

gilescope commented 1 month ago

Just hit this same ICE in 1.80 stable. (Edit: We can't upgrade past 1.78 till this is fixed)