Skip to content

Commit 75e15f7

Browse files
Deeply normalize obligations in refining_impl_trait
1 parent ef32456 commit 75e15f7

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
136136
// 1. Project the RPITIT projections from the trait to the opaques on the impl,
137137
// which means that they don't need to be mapped manually.
138138
//
139-
// 2. Project any other projections that show up in the bound. That makes sure that
140-
// we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs`
141-
// to be refining.
142-
let (trait_bounds, impl_bounds) =
143-
ocx.normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds));
139+
// 2. Deeply normalize any other projections that show up in the bound. That makes sure
140+
// that we don't consider `tests/ui/async-await/in-trait/async-associated-types.rs`
141+
// or `tests/ui/impl-trait/in-trait/refine-normalize.rs` to be refining.
142+
let Ok((trait_bounds, impl_bounds)) =
143+
ocx.deeply_normalize(&ObligationCause::dummy(), param_env, (trait_bounds, impl_bounds))
144+
else {
145+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
146+
return;
147+
};
144148

145149
// Since we've normalized things, we need to resolve regions, since we'll
146150
// possibly have introduced region vars during projection. We don't expect

compiler/rustc_trait_selection/src/traits/engine.rs

+9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
107107
self.register_infer_ok_obligations(infer_ok)
108108
}
109109

110+
pub fn deeply_normalize<T: TypeFoldable<TyCtxt<'tcx>>>(
111+
&self,
112+
cause: &ObligationCause<'tcx>,
113+
param_env: ty::ParamEnv<'tcx>,
114+
value: T,
115+
) -> Result<T, Vec<FulfillmentError<'tcx>>> {
116+
self.infcx.at(cause, param_env).deeply_normalize(value, &mut **self.engine.borrow_mut())
117+
}
118+
110119
/// Makes `expected <: actual`.
111120
pub fn eq_exp<T>(
112121
&self,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
//@ revisions: current next
4+
//@[next] compile-flags: -Znext-solver
5+
6+
#![deny(refining_impl_trait)]
7+
8+
pub trait Foo {
9+
type Item;
10+
11+
fn hello() -> impl Iterator<Item = Self::Item>;
12+
}
13+
14+
impl Foo for () {
15+
type Item = ();
16+
17+
fn hello() -> impl Iterator<Item = ()> { [()].into_iter() }
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)