Skip to content

Commit 581c1e0

Browse files
committed
Stop using old_defining_use_anchor except in select_where_possible
1 parent b0639e9 commit 581c1e0

File tree

9 files changed

+26
-20
lines changed

9 files changed

+26
-20
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

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

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

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

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
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).select(&obligation) {
1906+
match SelectionContext::new(&self).with_defining_use_anchor(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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14221422
let cause = traits::ObligationCause::misc(self.span, self.body_id);
14231423
let predicate = ty::Binder::dummy(trait_ref);
14241424
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
1425-
traits::SelectionContext::new(self).select(&obligation)
1425+
traits::SelectionContext::new(self)
1426+
.with_defining_use_anchor(self.defining_use_anchor)
1427+
.select(&obligation)
14261428
}
14271429

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

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_hir::GenericParam;
3030
use rustc_hir::Item;
3131
use rustc_hir::Node;
3232
use rustc_infer::infer::error_reporting::TypeErrCtxt;
33-
use rustc_infer::infer::{InferOk, TypeTrace};
33+
use rustc_infer::infer::{DefiningAnchor, InferOk, TypeTrace};
3434
use rustc_middle::traits::select::OverflowError;
3535
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
3636
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -2316,7 +2316,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23162316
};
23172317

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

compiler/rustc_trait_selection/src/traits/fulfill.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
137137
}
138138

139139
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>> {
140-
let selcx = SelectionContext::new(infcx);
140+
let selcx =
141+
SelectionContext::new(infcx).with_defining_use_anchor(infcx.old_defining_use_anchor);
141142
self.select(selcx)
142143
}
143144

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
217217
freshener: infcx.freshener_keep_static(),
218218
intercrate_ambiguity_causes: None,
219219
query_mode: TraitQueryMode::Standard,
220-
defining_use_anchor: infcx.old_defining_use_anchor,
220+
defining_use_anchor: DefiningAnchor::Error,
221221
}
222222
}
223223

224-
pub fn with_query_mode(
225-
infcx: &'cx InferCtxt<'tcx>,
226-
query_mode: TraitQueryMode,
227-
) -> SelectionContext<'cx, 'tcx> {
228-
debug!(?query_mode, "with_query_mode");
229-
SelectionContext { query_mode, ..SelectionContext::new(infcx) }
224+
pub fn with_defining_use_anchor(self, defining_use_anchor: DefiningAnchor) -> Self {
225+
Self { defining_use_anchor, ..self }
226+
}
227+
228+
pub fn new_in_canonical_query(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
229+
SelectionContext {
230+
query_mode: TraitQueryMode::Canonical,
231+
defining_use_anchor: DefiningAnchor::Bubble,
232+
..SelectionContext::new(infcx)
233+
}
230234
}
231235

232236
/// Enables tracking of intercrate ambiguity causes. See

compiler/rustc_traits/src/codegen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn codegen_select_candidate<'tcx>(
3636
.build();
3737
//~^ HACK `Bubble` is required for
3838
// this test to pass: type-alias-impl-trait/assoc-projection-ice.rs
39-
let mut selcx = SelectionContext::new(&infcx);
39+
let mut selcx = SelectionContext::new(&infcx).with_defining_use_anchor(DefiningAnchor::Bubble);
4040

4141
let obligation_cause = ObligationCause::dummy();
4242
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);

compiler/rustc_traits/src/evaluate_obligation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
44
use rustc_span::source_map::DUMMY_SP;
55
use rustc_trait_selection::traits::query::CanonicalPredicateGoal;
66
use rustc_trait_selection::traits::{
7-
EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext, TraitQueryMode,
7+
EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext,
88
};
99

1010
pub(crate) fn provide(p: &mut Providers) {
@@ -25,7 +25,7 @@ fn evaluate_obligation<'tcx>(
2525
debug!("evaluate_obligation: goal={:#?}", goal);
2626
let ParamEnvAnd { param_env, value: predicate } = goal;
2727

28-
let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
28+
let mut selcx = SelectionContext::new_in_canonical_query(&infcx);
2929
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
3030

3131
selcx.evaluate_root_obligation(&obligation)

tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
error[E0275]: overflow evaluating the requirement `Foo: Sized`
1+
error[E0275]: overflow evaluating the requirement `<fn() -> Foo {foo} as FnOnce<()>>::Output == fn() -> Foo {foo}`
22
--> $DIR/issue-53398-cyclic-types.rs:5:13
33
|
44
LL | fn foo() -> Foo {
55
| ^^^
6-
|
7-
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)
8-
= note: required because it appears within the type `fn() -> Foo {foo}`
96

107
error: aborting due to previous error
118

0 commit comments

Comments
 (0)