Skip to content

Commit ac3d0a4

Browse files
Make sure to scrape region constraints from deeply normalizing type outlives assumptions in borrowck
1 parent f95c996 commit ac3d0a4

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+26-12
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use rustc_infer::infer::canonical::QueryRegionConstraints;
55
use rustc_infer::infer::outlives::env::RegionBoundPairs;
66
use rustc_infer::infer::region_constraints::GenericKind;
77
use rustc_infer::infer::{InferCtxt, outlives};
8+
use rustc_infer::traits::ScrubbedTraitError;
89
use rustc_middle::mir::ConstraintCategory;
910
use rustc_middle::traits::ObligationCause;
1011
use rustc_middle::traits::query::OutlivesBound;
1112
use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
1213
use rustc_span::{ErrorGuaranteed, Span};
13-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
14-
use rustc_trait_selection::solve::deeply_normalize;
14+
use rustc_trait_selection::solve::NoSolution;
15+
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
1516
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1617
use tracing::{debug, instrument};
1718
use type_op::TypeOpOutput;
@@ -233,16 +234,29 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
233234

234235
// In the new solver, normalize the type-outlives obligation assumptions.
235236
if self.infcx.next_trait_solver() {
236-
match deeply_normalize(
237-
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), param_env),
238-
outlives,
239-
) {
240-
Ok(normalized_outlives) => {
241-
outlives = normalized_outlives;
242-
}
243-
Err(e) => {
244-
self.infcx.err_ctxt().report_fulfillment_errors(e);
245-
}
237+
let Ok(TypeOpOutput {
238+
output: normalized_outlives,
239+
constraints: constraints_normalize,
240+
error_info: _,
241+
}) = CustomTypeOp::new(
242+
|ocx| {
243+
ocx.deeply_normalize(
244+
&ObligationCause::dummy_with_span(span),
245+
self.param_env,
246+
outlives,
247+
)
248+
.map_err(|_: Vec<ScrubbedTraitError<'tcx>>| NoSolution)
249+
},
250+
"normalize type outlives obligation",
251+
)
252+
.fully_perform(self.infcx, span)
253+
else {
254+
self.infcx.dcx().delayed_bug(format!("could not normalize {outlives:?}"));
255+
continue;
256+
};
257+
outlives = normalized_outlives;
258+
if let Some(c) = constraints_normalize {
259+
constraints.push(c);
246260
}
247261
}
248262

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
trait Norm {
5+
type Out;
6+
}
7+
impl<'a, T: 'a> Norm for &'a T {
8+
type Out = T;
9+
}
10+
11+
fn hello<'a, T: 'a>() where <&'a T as Norm>::Out: 'a {}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)