Skip to content

Continue folding in query normalizer on weak aliases #112777

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
Jun 19, 2023
Merged
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
8 changes: 6 additions & 2 deletions compiler/rustc_trait_selection/src/traits/query/normalize.rs
Original file line number Diff line number Diff line change
@@ -322,8 +322,12 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
};
// `tcx.normalize_projection_ty` may normalize to a type that still has
// unevaluated consts, so keep normalizing here if that's the case.
if res != ty && res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) {
res.try_super_fold_with(self)?
// Similarly, `tcx.normalize_weak_ty` will only unwrap one layer of type
// and we need to continue folding it to reveal the TAIT behind it.
if res != ty
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) || kind == ty::Weak)
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we could instead modify the normalize_weak_ty query and do the deep normalization there, instead of here.

Copy link
Contributor

@oli-obk oli-obk Jun 19, 2023

Choose a reason for hiding this comment

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

that's not what we do for the other normalize queries. Maybe we should rename them to shallow_normalize_...

edit: ah, but we don't want to do this for things other than weak type aliases... hmm...

{
res.try_fold_with(self)?
Copy link
Member Author

@compiler-errors compiler-errors Jun 18, 2023

Choose a reason for hiding this comment

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

Whereas for the CT_PROJECTION case we didn't care about the difference between try_fold_with and try_super_fold_with, for the weak case, we need to call try_fold_with or else we'll skip one layer of the alias's type.

} else {
res
}
12 changes: 12 additions & 0 deletions tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// compile-flags: --crate-type=lib -Cdebuginfo=2
// build-pass

#![feature(type_alias_impl_trait)]

type Debuggable = impl core::fmt::Debug;

static mut TEST: Option<Debuggable> = None;

fn foo() -> Debuggable {
0u32
}