Skip to content

Commit 01aacd4

Browse files
committed
Require SelectionContext to have a DefiningAnchor from the start
1 parent a5f9af2 commit 01aacd4

File tree

17 files changed

+31
-34
lines changed

17 files changed

+31
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
744744

745745
let implsrc = {
746746
let infcx = tcx.infer_ctxt().build();
747-
let mut selcx = SelectionContext::new(&infcx);
747+
let mut selcx = SelectionContext::new(&infcx, DefiningAnchor::Error);
748748
selcx.select(&obligation)
749749
};
750750

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::{
77
};
88
use rustc_hir as hir;
99
use rustc_hir::def_id::DefId;
10-
use rustc_infer::infer::TyCtxtInferExt;
10+
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
1111
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
1212
use rustc_middle::mir;
1313
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -149,7 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
149149
);
150150

151151
let infcx = tcx.infer_ctxt().build();
152-
let mut selcx = SelectionContext::new(&infcx);
152+
let mut selcx = SelectionContext::new(&infcx, DefiningAnchor::Error);
153153
let implsrc = selcx.select(&obligation);
154154

155155
if let Ok(Some(ImplSource::UserDefined(data))) = implsrc {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::LangItem;
7-
use rustc_infer::infer::TyCtxtInferExt;
7+
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
88
use rustc_middle::mir;
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
@@ -162,7 +162,7 @@ impl Qualif for NeedsNonConstDrop {
162162
);
163163

164164
let infcx = cx.tcx.infer_ctxt().build();
165-
let mut selcx = SelectionContext::new(&infcx);
165+
let mut selcx = SelectionContext::new(&infcx, DefiningAnchor::Error);
166166
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
167167
// If we couldn't select a const destruct candidate, then it's bad
168168
return true;

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
585585
}
586586
})?;
587587

588-
let mut selcx = traits::SelectionContext::new(self)
589-
.with_defining_use_anchor(self.defining_use_anchor());
588+
let mut selcx = traits::SelectionContext::new(self, self.defining_use_anchor());
590589

591590
// Create an obligation for `Source: CoerceUnsized<Target>`.
592591
let cause = ObligationCause::new(

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19031903
self.param_env,
19041904
ty::Binder::dummy(trait_ref),
19051905
);
1906-
match SelectionContext::new(&self).with_defining_use_anchor(self.defining_use_anchor()).select(&obligation) {
1906+
match SelectionContext::new(&self,self.defining_use_anchor()).select(&obligation) {
19071907
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
19081908
Some(impl_source.impl_def_id)
19091909
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14281428
let cause = traits::ObligationCause::misc(self.span, self.body_id);
14291429
let predicate = ty::Binder::dummy(trait_ref);
14301430
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
1431-
traits::SelectionContext::new(self)
1432-
.with_defining_use_anchor(self.defining_use_anchor())
1433-
.select(&obligation)
1431+
traits::SelectionContext::new(self, self.defining_use_anchor()).select(&obligation)
14341432
}
14351433

14361434
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
8989
let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);
9090

9191
let infcx = tcx.infer_ctxt().build();
92-
let mut selcx = SelectionContext::new(&infcx);
92+
let mut selcx = SelectionContext::new(&infcx, DefiningAnchor::Error);
9393
for polarity in [true, false] {
9494
let result = selcx.select(&Obligation::new(
9595
tcx,
@@ -256,7 +256,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
256256
fresh_preds.insert(self.clean_pred(infcx, predicate));
257257
}
258258

259-
let mut select = SelectionContext::new(&infcx);
259+
let mut select = SelectionContext::new(&infcx, DefiningAnchor::Error);
260260

261261
let mut already_visited = FxHashSet::default();
262262
let mut predicates = VecDeque::new();

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn overlapping_impls(
9696
}
9797

9898
let infcx = tcx.infer_ctxt().intercrate().build();
99-
let selcx = &mut SelectionContext::new(&infcx);
99+
let selcx = &mut SelectionContext::new(&infcx, DefiningAnchor::Error);
100100
let overlaps =
101101
overlap(selcx, skip_leak_check, impl1_def_id, impl2_def_id, overlap_mode).is_some();
102102
if !overlaps {
@@ -107,7 +107,7 @@ pub fn overlapping_impls(
107107
// this time tracking intercrate ambiguity causes for better
108108
// diagnostics. (These take time and can lead to false errors.)
109109
let infcx = tcx.infer_ctxt().intercrate().build();
110-
let selcx = &mut SelectionContext::new(&infcx);
110+
let selcx = &mut SelectionContext::new(&infcx, DefiningAnchor::Error);
111111
selcx.enable_tracking_intercrate_ambiguity_causes();
112112
Some(overlap(selcx, skip_leak_check, impl1_def_id, impl2_def_id, overlap_mode).unwrap())
113113
}
@@ -305,7 +305,7 @@ fn negative_impl(tcx: TyCtxt<'_>, impl1_def_id: DefId, impl2_def_id: DefId) -> b
305305
};
306306

307307
// Attempt to prove that impl2 applies, given all of the above.
308-
let selcx = &mut SelectionContext::new(&infcx);
308+
let selcx = &mut SelectionContext::new(&infcx, DefiningAnchor::Error);
309309
let impl2_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl2_def_id);
310310
let (subject2, obligations) =
311311
impl_subject_and_oblig(selcx, impl_env, impl2_def_id, impl2_substs);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23162316
};
23172317

23182318
let obligation = obligation.with(self.tcx, trait_ref);
2319-
let mut selcx =
2320-
SelectionContext::new(&self).with_defining_use_anchor(DefiningAnchor::Bubble);
2319+
let mut selcx = SelectionContext::new(&self, DefiningAnchor::Bubble);
23212320
match selcx.select_from_obligation(&obligation) {
23222321
Ok(None) => {
23232322
let ambiguities =

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
149149
}
150150

151151
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>> {
152-
let selcx = SelectionContext::new(infcx).with_defining_use_anchor(self.defining_use_anchor);
152+
let selcx = SelectionContext::new(infcx, self.defining_use_anchor);
153153
self.select(selcx)
154154
}
155155

0 commit comments

Comments
 (0)