Skip to content

Normalize lazy type aliases when probing for ADTs #113755

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

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
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() =>
Copy link
Member Author

@fmease fmease Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't come up with a snippet containing a weak type alias in expression position that has escaping bound vars.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't have it in path expressions, which is where this would be encountered afaict.

Also, should we only normalize away the layers of lazy type alias? This also has the side effect of an alias that normalizes to a regular projection gets normalized.

Why don't we normalize here to begin with? Does @aliemjay know?

self_ty.map(|ty| ty.raw),

Ideally, this would just pass ty.normalized instead of ty.raw...

{
self.normalize(span, ty).ty_adt_def()
}
_ => None,
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/type-alias/lazy-type-alias-enum-variant.rs
Original file line number Diff line number Diff line change
@@ -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 {};
}