Skip to content

Commit 58f107a

Browse files
Use TraitEngine in more places that don't specifically need FulfillmentCtxt::new_in_snapshot
1 parent 6dbae3a commit 58f107a

File tree

11 files changed

+23
-22
lines changed

11 files changed

+23
-22
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::*;
1010
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
1111
use rustc_span::DUMMY_SP;
1212
use rustc_trait_selection::traits::{
13-
self, FulfillmentContext, ImplSource, Obligation, ObligationCause, SelectionContext,
13+
self, ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngineExt,
1414
};
1515

1616
use super::ConstCx;
@@ -191,7 +191,7 @@ impl Qualif for NeedsNonConstDrop {
191191

192192
// If we successfully found one, then select all of the predicates
193193
// implied by our const drop impl.
194-
let mut fcx = FulfillmentContext::new();
194+
let mut fcx = <dyn TraitEngine<'tcx>>::new(cx.tcx);
195195
for nested in impl_src.nested_obligations() {
196196
fcx.register_predicate_obligation(&infcx, nested);
197197
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
205205
// At this point, we already have all of the bounds we need. FulfillmentContext is used
206206
// to store all of the necessary region/lifetime bounds in the InferContext, as well as
207207
// an additional sanity check.
208-
let mut fulfill = FulfillmentContext::new();
208+
let mut fulfill = <dyn TraitEngine<'tcx>>::new(tcx);
209209
fulfill.register_bound(&infcx, full_env, ty, trait_did, ObligationCause::dummy());
210210
let errors = fulfill.select_all_or_error(&infcx);
211211

compiler/rustc_trait_selection/src/traits/codegen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use crate::infer::{DefiningAnchor, TyCtxtInferExt};
77
use crate::traits::{
8-
FulfillmentContext, ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngine,
8+
ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngine, TraitEngineExt,
99
Unimplemented,
1010
};
1111
use rustc_middle::traits::CodegenObligationError;
@@ -55,7 +55,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
5555
// Currently, we use a fulfillment context to completely resolve
5656
// all nested obligations. This is because they can inform the
5757
// inference of the impl's type parameters.
58-
let mut fulfill_cx = FulfillmentContext::new();
58+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(tcx);
5959
let impl_source = selection.map(|predicate| {
6060
fulfill_cx.register_predicate_obligation(&infcx, predicate);
6161
});

compiler/rustc_trait_selection/src/traits/coherence.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::traits::util::impl_subject_and_oblig;
1111
use crate::traits::SkipLeakCheck;
1212
use crate::traits::{
1313
self, FulfillmentContext, Normalized, Obligation, ObligationCause, PredicateObligation,
14-
PredicateObligations, SelectionContext,
14+
PredicateObligations, SelectionContext, TraitEngineExt,
1515
};
1616
use rustc_data_structures::fx::FxIndexSet;
1717
use rustc_errors::Diagnostic;
@@ -385,7 +385,7 @@ fn resolve_negative_obligation<'cx, 'tcx>(
385385
return false;
386386
};
387387

388-
let mut fulfillment_cx = FulfillmentContext::new();
388+
let mut fulfillment_cx = <dyn TraitEngine<'tcx>>::new(infcx.tcx);
389389
fulfillment_cx.register_predicate_obligation(infcx, o);
390390

391391
let errors = fulfillment_cx.select_all_or_error(infcx);

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
163163
// The handling of regions in this area of the code is terrible,
164164
// see issue #29149. We should be able to improve on this with
165165
// NLL.
166-
let mut fulfill_cx = FulfillmentContext::new();
166+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(infcx.tcx);
167167

168168
// We can use a dummy node-id here because we won't pay any mind
169169
// to region obligations that arise (there shouldn't really be any

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use specialization_graph::GraphExt;
1414

1515
use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt};
1616
use crate::traits::select::IntercrateAmbiguityCause;
17-
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
17+
use crate::traits::{
18+
self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine, TraitEngineExt,
19+
};
1820
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1921
use rustc_errors::{struct_span_err, EmissionGuarantee, LintDiagnosticBuilder};
2022
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -24,8 +26,8 @@ use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
2426
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
2527
use rustc_span::{Span, DUMMY_SP};
2628

27-
use super::util;
28-
use super::{FulfillmentContext, SelectionContext};
29+
use super::SelectionContext;
30+
use super::{util, FulfillmentContext};
2931

3032
/// Information pertinent to an overlapping impl error.
3133
#[derive(Debug)]
@@ -207,7 +209,7 @@ fn fulfill_implication<'a, 'tcx>(
207209
// (which are packed up in penv)
208210

209211
infcx.save_and_restore_in_snapshot_flag(|infcx| {
210-
let mut fulfill_cx = FulfillmentContext::new();
212+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(infcx.tcx);
211213
for oblig in obligations.chain(more_obligations) {
212214
fulfill_cx.register_predicate_obligation(&infcx, oblig);
213215
}

compiler/rustc_trait_selection/src/traits/structural_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::infer::{InferCtxt, TyCtxtInferExt};
22
use crate::traits::ObligationCause;
3-
use crate::traits::{self, TraitEngine};
3+
use crate::traits::{TraitEngine, TraitEngineExt};
44

55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_hir as hir;
@@ -78,7 +78,7 @@ fn type_marked_structural<'tcx>(
7878
adt_ty: Ty<'tcx>,
7979
cause: ObligationCause<'tcx>,
8080
) -> bool {
81-
let mut fulfillment_cx = traits::FulfillmentContext::new();
81+
let mut fulfillment_cx = <dyn TraitEngine<'tcx>>::new(infcx.tcx);
8282
// require `#[derive(PartialEq)]`
8383
let structural_peq_def_id =
8484
infcx.tcx.require_lang_item(LangItem::StructuralPeq, Some(cause.span));

compiler/rustc_traits/src/implied_outlives_bounds.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use rustc_span::source_map::DUMMY_SP;
1414
use rustc_trait_selection::infer::InferCtxtBuilderExt;
1515
use rustc_trait_selection::traits::query::{CanonicalTyGoal, Fallible, NoSolution};
1616
use rustc_trait_selection::traits::wf;
17-
use rustc_trait_selection::traits::FulfillmentContext;
18-
use rustc_trait_selection::traits::TraitEngine;
17+
use rustc_trait_selection::traits::{TraitEngine, TraitEngineExt};
1918
use smallvec::{smallvec, SmallVec};
2019

2120
pub(crate) fn provide(p: &mut Providers) {
@@ -52,7 +51,7 @@ fn compute_implied_outlives_bounds<'tcx>(
5251

5352
let mut implied_bounds = vec![];
5453

55-
let mut fulfill_cx = FulfillmentContext::new();
54+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(tcx);
5655

5756
while let Some(arg) = wf_args.pop() {
5857
if !checked_wf_args.insert(arg) {

compiler/rustc_typeck/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
117117
// it is not immediately clear why Copy is not implemented for a field, since
118118
// all we point at is the field itself.
119119
tcx.infer_ctxt().ignoring_regions().enter(|infcx| {
120-
let mut fulfill_cx = traits::FulfillmentContext::new();
120+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
121121
fulfill_cx.register_bound(
122122
&infcx,
123123
param_env,

compiler/rustc_typeck/src/hir_wf_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_infer::traits::TraitEngine;
77
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
88
use rustc_middle::ty::query::Providers;
99
use rustc_middle::ty::{self, Region, ToPredicate, TyCtxt, TypeFoldable, TypeFolder};
10-
use rustc_trait_selection::traits;
10+
use rustc_trait_selection::traits::{self, TraitEngineExt};
1111

1212
pub fn provide(providers: &mut Providers) {
1313
*providers = Providers { diagnostic_hir_wf_check, ..*providers };
@@ -66,7 +66,7 @@ fn diagnostic_hir_wf_check<'tcx>(
6666
impl<'tcx> Visitor<'tcx> for HirWfCheck<'tcx> {
6767
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
6868
self.tcx.infer_ctxt().enter(|infcx| {
69-
let mut fulfill = traits::FulfillmentContext::new();
69+
let mut fulfill = <dyn TraitEngine<'tcx>>::new(self.tcx);
7070
let tcx_ty =
7171
self.icx.to_ty(ty).fold_with(&mut EraseAllBoundRegions { tcx: self.tcx });
7272
let cause = traits::ObligationCause::new(

compiler/rustc_typeck/src/outlives/outlives_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_middle::ty::{self, Ty};
33
use rustc_trait_selection::infer::InferCtxt;
44
use rustc_trait_selection::traits::query::type_op::{self, TypeOp, TypeOpOutput};
55
use rustc_trait_selection::traits::query::NoSolution;
6-
use rustc_trait_selection::traits::{FulfillmentContext, ObligationCause, TraitEngine};
6+
use rustc_trait_selection::traits::{ObligationCause, TraitEngine, TraitEngineExt};
77

88
pub use rustc_middle::traits::query::OutlivesBound;
99

@@ -63,7 +63,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
6363
if let Some(constraints) = constraints {
6464
// Instantiation may have produced new inference variables and constraints on those
6565
// variables. Process these constraints.
66-
let mut fulfill_cx = FulfillmentContext::new();
66+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(self.tcx);
6767
let cause = ObligationCause::misc(span, body_id);
6868
for &constraint in &constraints.outlives {
6969
let obligation = self.query_outlives_constraint_to_obligation(

0 commit comments

Comments
 (0)