From 88193aad724279c938efd2d17332e08a751de106 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 12 Feb 2025 23:52:53 +0000 Subject: [PATCH] Use the right binder for rebinding PolyTraitRef --- .../rustc_trait_selection/src/traits/util.rs | 4 ++-- .../traits/alias/expand-higher-ranked-alias.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/ui/traits/alias/expand-higher-ranked-alias.rs diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index d30363ec1589a..15f5cf916a48b 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -47,11 +47,11 @@ pub fn expand_trait_aliases<'tcx>( queue.extend( tcx.explicit_super_predicates_of(trait_pred.def_id()) .iter_identity_copied() - .map(|(clause, span)| { + .map(|(super_clause, span)| { let mut spans = spans.clone(); spans.push(span); ( - clause.instantiate_supertrait( + super_clause.instantiate_supertrait( tcx, clause.kind().rebind(trait_pred.trait_ref), ), diff --git a/tests/ui/traits/alias/expand-higher-ranked-alias.rs b/tests/ui/traits/alias/expand-higher-ranked-alias.rs new file mode 100644 index 0000000000000..8a301d39f4c46 --- /dev/null +++ b/tests/ui/traits/alias/expand-higher-ranked-alias.rs @@ -0,0 +1,18 @@ +// Make sure we are using the right binder vars when expanding +// `for<'a> Foo<'a>` to `for<'a> Bar<'a>`. + +//@ check-pass + +#![feature(trait_alias)] + +trait Bar<'a> {} + +trait Foo<'a> = Bar<'a>; + +fn test2(_: &(impl for<'a> Foo<'a> + ?Sized)) {} + +fn test(x: &dyn for<'a> Foo<'a>) { + test2(x); +} + +fn main() {}