Skip to content

Commit b85ebef

Browse files
committed
Re-use the type op instead of calling the implied_outlives_bounds query directly
1 parent 14da30e commit b85ebef

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

compiler/rustc_typeck/src/outlives/outlives_bounds.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_hir as hir;
2-
use rustc_infer::traits::TraitEngineExt as _;
32
use rustc_middle::ty::{self, Ty};
43
use rustc_span::source_map::Span;
5-
use rustc_trait_selection::infer::canonical::OriginalQueryValues;
64
use rustc_trait_selection::infer::InferCtxt;
5+
use rustc_trait_selection::traits::query::type_op::{self, TypeOp, TypeOpOutput};
76
use rustc_trait_selection::traits::query::NoSolution;
87
use rustc_trait_selection::traits::{FulfillmentContext, ObligationCause, TraitEngine};
98

@@ -41,18 +40,18 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4140
/// - `ty`, the type that we are supposed to assume is WF.
4241
/// - `span`, a span to use when normalizing, hopefully not important,
4342
/// might be useful if a `bug!` occurs.
43+
#[instrument(level = "debug", skip(self, param_env, body_id, span))]
4444
fn implied_outlives_bounds(
4545
&self,
4646
param_env: ty::ParamEnv<'tcx>,
4747
body_id: hir::HirId,
4848
ty: Ty<'tcx>,
4949
span: Span,
5050
) -> Vec<OutlivesBound<'tcx>> {
51-
debug!("implied_outlives_bounds(ty = {:?})", ty);
52-
53-
let mut orig_values = OriginalQueryValues::default();
54-
let key = self.canonicalize_query(param_env.and(ty), &mut orig_values);
55-
let result = match self.tcx.implied_outlives_bounds(key) {
51+
let result = param_env
52+
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
53+
.fully_perform(self);
54+
let result = match result {
5655
Ok(r) => r,
5756
Err(NoSolution) => {
5857
self.tcx.sess.delay_span_bug(
@@ -62,32 +61,34 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
6261
return vec![];
6362
}
6463
};
65-
assert!(result.value.is_proven());
6664

67-
let result = self.instantiate_query_response_and_region_obligations(
68-
&ObligationCause::misc(span, body_id),
69-
param_env,
70-
&orig_values,
71-
result,
72-
);
73-
debug!("implied_outlives_bounds for {:?}: {:#?}", ty, result);
74-
let Ok(result) = result else {
75-
self.tcx.sess.delay_span_bug(span, "implied_outlives_bounds failed to instantiate");
76-
return vec![];
77-
};
65+
let TypeOpOutput { output, constraints, .. } = result;
7866

79-
// Instantiation may have produced new inference variables and constraints on those
80-
// variables. Process these constraints.
81-
let mut fulfill_cx = FulfillmentContext::new();
82-
fulfill_cx.register_predicate_obligations(self, result.obligations);
83-
let errors = fulfill_cx.select_all_or_error(self);
84-
if !errors.is_empty() {
85-
self.tcx.sess.delay_span_bug(
86-
span,
87-
"implied_outlives_bounds failed to solve obligations from instantiation",
88-
);
89-
}
67+
if let Some(constraints) = constraints {
68+
// Instantiation may have produced new inference variables and constraints on those
69+
// variables. Process these constraints.
70+
let mut fulfill_cx = FulfillmentContext::new();
71+
let cause = ObligationCause::misc(span, body_id);
72+
for &constraint in &constraints.outlives {
73+
let obligation = self.query_outlives_constraint_to_obligation(
74+
constraint,
75+
cause.clone(),
76+
param_env,
77+
);
78+
fulfill_cx.register_predicate_obligation(self, obligation);
79+
}
80+
if !constraints.member_constraints.is_empty() {
81+
span_bug!(span, "{:#?}", constraints.member_constraints);
82+
}
83+
let errors = fulfill_cx.select_all_or_error(self);
84+
if !errors.is_empty() {
85+
self.tcx.sess.delay_span_bug(
86+
span,
87+
"implied_outlives_bounds failed to solve obligations from instantiation",
88+
);
89+
}
90+
};
9091

91-
result.value
92+
output
9293
}
9394
}

0 commit comments

Comments
 (0)