Skip to content

Commit 9f47d13

Browse files
Anonymize binders for refining_impl_trait check
1 parent af68593 commit 9f47d13

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_infer::infer::{outlives::env::OutlivesEnvironment, TyCtxtInferExt};
55
use rustc_lint_defs::builtin::REFINING_IMPL_TRAIT;
66
use rustc_middle::traits::{ObligationCause, Reveal};
77
use rustc_middle::ty::{
8-
self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor,
8+
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor,
99
};
1010
use rustc_span::{Span, DUMMY_SP};
1111
use rustc_trait_selection::traits::{
@@ -178,7 +178,8 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
178178

179179
// For quicker lookup, use an `IndexSet`
180180
// (we don't use one earlier because it's not foldable..)
181-
let trait_bounds = FxIndexSet::from_iter(trait_bounds);
181+
let trait_bounds = FxIndexSet::from_iter(trait_bounds.fold_with(&mut Anonymize { tcx }));
182+
let impl_bounds = impl_bounds.fold_with(&mut Anonymize { tcx });
182183

183184
// Find any clauses that are present in the impl's RPITITs that are not
184185
// present in the trait's RPITITs. This will trigger on trivial predicates,
@@ -309,3 +310,20 @@ fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibili
309310
_ => None,
310311
}
311312
}
313+
314+
struct Anonymize<'tcx> {
315+
tcx: TyCtxt<'tcx>,
316+
}
317+
318+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Anonymize<'tcx> {
319+
fn interner(&self) -> TyCtxt<'tcx> {
320+
self.tcx
321+
}
322+
323+
fn fold_binder<T>(&mut self, t: ty::Binder<'tcx, T>) -> ty::Binder<'tcx, T>
324+
where
325+
T: TypeFoldable<TyCtxt<'tcx>>,
326+
{
327+
self.tcx.anonymize_bound_vars(t)
328+
}
329+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: --crate-type=lib
2+
// check-pass
3+
4+
#![feature(return_position_impl_trait_in_trait)]
5+
#![deny(refining_impl_trait)]
6+
7+
pub trait Tr<T> {
8+
fn foo() -> impl for<'a> Tr<&'a Self>;
9+
}
10+
11+
impl<T> Tr<T> for () {
12+
fn foo() -> impl for<'a> Tr<&'a Self> {}
13+
}

0 commit comments

Comments
 (0)