Skip to content

Commit 283abbf

Browse files
committedOct 7, 2022
Change InferCtxtBuilder from enter to build
1 parent 91269fa commit 283abbf

File tree

53 files changed

+1984
-2200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1984
-2200
lines changed
 

‎compiler/rustc_borrowck/src/consumers.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ pub fn get_body_with_borrowck_facts<'tcx>(
3131
def: ty::WithOptConstParam<LocalDefId>,
3232
) -> BodyWithBorrowckFacts<'tcx> {
3333
let (input_body, promoted) = tcx.mir_promoted(def);
34-
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).enter(|infcx| {
35-
let input_body: &Body<'_> = &input_body.borrow();
36-
let promoted: &IndexVec<_, _> = &promoted.borrow();
37-
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
38-
})
34+
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build();
35+
let input_body: &Body<'_> = &input_body.borrow();
36+
let promoted: &IndexVec<_, _> = &promoted.borrow();
37+
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
3938
}

‎compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,11 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
238238
placeholder_region: ty::Region<'tcx>,
239239
error_region: Option<ty::Region<'tcx>>,
240240
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
241-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
242-
cause.span,
243-
&self.canonical_query,
244-
|ref infcx, key, _| {
245-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
246-
type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause);
247-
try_extract_error_from_fulfill_cx(
248-
fulfill_cx,
249-
infcx,
250-
placeholder_region,
251-
error_region,
252-
)
253-
},
254-
)
241+
let (ref infcx, key, _) =
242+
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
243+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
244+
type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause);
245+
try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
255246
}
256247
}
257248

@@ -288,37 +279,24 @@ where
288279
placeholder_region: ty::Region<'tcx>,
289280
error_region: Option<ty::Region<'tcx>>,
290281
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
291-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
292-
cause.span,
293-
&self.canonical_query,
294-
|ref infcx, key, _| {
295-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
296-
297-
let mut selcx = SelectionContext::new(infcx);
298-
299-
// FIXME(lqd): Unify and de-duplicate the following with the actual
300-
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
301-
// `ObligationCause`. The normalization results are currently different between
302-
// `AtExt::normalize` used in the query and `normalize` called below: the former fails
303-
// to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
304-
// after #85499 lands to see if its fixes have erased this difference.
305-
let (param_env, value) = key.into_parts();
306-
let Normalized { value: _, obligations } = rustc_trait_selection::traits::normalize(
307-
&mut selcx,
308-
param_env,
309-
cause,
310-
value.value,
311-
);
312-
fulfill_cx.register_predicate_obligations(infcx, obligations);
313-
314-
try_extract_error_from_fulfill_cx(
315-
fulfill_cx,
316-
infcx,
317-
placeholder_region,
318-
error_region,
319-
)
320-
},
321-
)
282+
let (ref infcx, key, _) =
283+
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
284+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
285+
286+
let mut selcx = SelectionContext::new(infcx);
287+
288+
// FIXME(lqd): Unify and de-duplicate the following with the actual
289+
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
290+
// `ObligationCause`. The normalization results are currently different between
291+
// `AtExt::normalize` used in the query and `normalize` called below: the former fails
292+
// to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
293+
// after #85499 lands to see if its fixes have erased this difference.
294+
let (param_env, value) = key.into_parts();
295+
let Normalized { value: _, obligations } =
296+
rustc_trait_selection::traits::normalize(&mut selcx, param_env, cause, value.value);
297+
fulfill_cx.register_predicate_obligations(infcx, obligations);
298+
299+
try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
322300
}
323301
}
324302

@@ -349,21 +327,11 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
349327
placeholder_region: ty::Region<'tcx>,
350328
error_region: Option<ty::Region<'tcx>>,
351329
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
352-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
353-
cause.span,
354-
&self.canonical_query,
355-
|ref infcx, key, _| {
356-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
357-
type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span))
358-
.ok()?;
359-
try_extract_error_from_fulfill_cx(
360-
fulfill_cx,
361-
infcx,
362-
placeholder_region,
363-
error_region,
364-
)
365-
},
366-
)
330+
let (ref infcx, key, _) =
331+
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
332+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
333+
type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span)).ok()?;
334+
try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region)
367335
}
368336
}
369337

0 commit comments

Comments
 (0)