From c856c74764006610e23de4210a17dfb7a1702127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 16 Jul 2023 12:38:43 +0200 Subject: [PATCH] Normalize lazy type aliases when probing for ADTs --- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 4 +++- .../type-alias/lazy-type-alias-enum-variant.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type-alias/lazy-type-alias-enum-variant.rs diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 1e8af6c6ed7..6a82b00211e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -302,7 +302,9 @@ fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option> { match ty.kind() { ty::Adt(adt_def, _) => Some(*adt_def), // FIXME(#104767): Should we handle bound regions here? - ty::Alias(ty::Projection | ty::Inherent, _) if !ty.has_escaping_bound_vars() => { + ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) + if !ty.has_escaping_bound_vars() => + { self.normalize(span, ty).ty_adt_def() } _ => None, diff --git a/tests/ui/type-alias/lazy-type-alias-enum-variant.rs b/tests/ui/type-alias/lazy-type-alias-enum-variant.rs new file mode 100644 index 00000000000..78c3159d1c2 --- /dev/null +++ b/tests/ui/type-alias/lazy-type-alias-enum-variant.rs @@ -0,0 +1,17 @@ +// Regression test for issue #113736. +// check-pass + +#![feature(lazy_type_alias)] + +enum Enum { + Unit, + Tuple(), + Struct {}, +} + +fn main() { + type Alias = Enum; + let _ = Alias::Unit; + let _ = Alias::Tuple(); + let _ = Alias::Struct {}; +}