Skip to content

Commit 929007a

Browse files
Pass spans around new solver
1 parent 49e1816 commit 929007a

File tree

14 files changed

+152
-61
lines changed

14 files changed

+152
-61
lines changed

compiler/rustc_infer/src/infer/at.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
137137
expected,
138138
ty::Contravariant,
139139
actual,
140+
self.cause.span,
140141
)
141142
.map(|goals| self.goals_to_obligations(goals))
142143
} else {
@@ -163,8 +164,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
163164
T: ToTrace<'tcx>,
164165
{
165166
if self.infcx.next_trait_solver {
166-
NextSolverRelate::relate(self.infcx, self.param_env, expected, ty::Covariant, actual)
167-
.map(|goals| self.goals_to_obligations(goals))
167+
NextSolverRelate::relate(
168+
self.infcx,
169+
self.param_env,
170+
expected,
171+
ty::Covariant,
172+
actual,
173+
self.cause.span,
174+
)
175+
.map(|goals| self.goals_to_obligations(goals))
168176
} else {
169177
let mut op = TypeRelating::new(
170178
self.infcx,
@@ -208,8 +216,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
208216
T: Relate<TyCtxt<'tcx>>,
209217
{
210218
if self.infcx.next_trait_solver {
211-
NextSolverRelate::relate(self.infcx, self.param_env, expected, ty::Invariant, actual)
212-
.map(|goals| self.goals_to_obligations(goals))
219+
NextSolverRelate::relate(
220+
self.infcx,
221+
self.param_env,
222+
expected,
223+
ty::Invariant,
224+
actual,
225+
self.cause.span,
226+
)
227+
.map(|goals| self.goals_to_obligations(goals))
213228
} else {
214229
let mut op = TypeRelating::new(
215230
self.infcx,

compiler/rustc_infer/src/infer/context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::fold::TypeFoldable;
55
use rustc_middle::ty::relate::RelateResult;
66
use rustc_middle::ty::relate::combine::PredicateEmittingRelation;
77
use rustc_middle::ty::{self, Ty, TyCtxt};
8-
use rustc_span::{DUMMY_SP, ErrorGuaranteed};
8+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
99

1010
use super::{BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin};
1111

@@ -203,23 +203,23 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
203203
self.probe(|_| probe())
204204
}
205205

206-
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>) {
206+
fn sub_regions(&self, sub: ty::Region<'tcx>, sup: ty::Region<'tcx>, span: Span) {
207207
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(
208-
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
208+
SubregionOrigin::RelateRegionParamBound(span, None),
209209
sub,
210210
sup,
211211
);
212212
}
213213

214-
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>) {
214+
fn equate_regions(&self, a: ty::Region<'tcx>, b: ty::Region<'tcx>, span: Span) {
215215
self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
216-
SubregionOrigin::RelateRegionParamBound(DUMMY_SP, None),
216+
SubregionOrigin::RelateRegionParamBound(span, None),
217217
a,
218218
b,
219219
);
220220
}
221221

222-
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>) {
223-
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy());
222+
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>, span: Span) {
223+
self.register_region_obligation_with_cause(ty, r, &ObligationCause::dummy_with_span(span));
224224
}
225225
}

compiler/rustc_next_trait_solver/src/delegate.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_type_ir::fold::TypeFoldable;
44
use rustc_type_ir::solve::{Certainty, Goal, NoSolution};
55
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
66

7-
pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Sized {
8-
type Infcx: InferCtxtLike<Interner = <Self as SolverDelegate>::Interner>;
7+
pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
8+
type Infcx: InferCtxtLike<Interner = Self::Interner>;
99
type Interner: Interner;
1010
fn cx(&self) -> Self::Interner {
1111
(**self).cx()
@@ -59,6 +59,7 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
5959
fn instantiate_canonical_var_with_infer(
6060
&self,
6161
cv_info: ty::CanonicalVarInfo<Self::Interner>,
62+
span: <Self::Interner as Interner>::Span,
6263
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
6364
) -> <Self::Interner as Interner>::GenericArg;
6465

@@ -84,6 +85,7 @@ pub trait SolverDelegate: Deref<Target = <Self as SolverDelegate>::Infcx> + Size
8485
&self,
8586
key: ty::OpaqueTypeKey<Self::Interner>,
8687
hidden_ty: <Self::Interner as Interner>::Ty,
88+
span: <Self::Interner as Interner>::Span,
8789
);
8890

8991
fn reset_opaque_types(&self);

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -250,25 +250,29 @@ where
250250
param_env: I::ParamEnv,
251251
original_values: Vec<I::GenericArg>,
252252
response: CanonicalResponse<I>,
253+
span: I::Span,
253254
) -> (NestedNormalizationGoals<I>, Certainty) {
254255
let instantiation = Self::compute_query_response_instantiation_values(
255256
self.delegate,
256257
&original_values,
257258
&response,
259+
span,
258260
);
259261

260262
let Response { var_values, external_constraints, certainty } =
261263
self.delegate.instantiate_canonical(response, instantiation);
262264

263-
Self::unify_query_var_values(self.delegate, param_env, &original_values, var_values);
265+
Self::unify_query_var_values(self.delegate, param_env, &original_values, var_values, span);
264266

265267
let ExternalConstraintsData {
266268
region_constraints,
267269
opaque_types,
268270
normalization_nested_goals,
269271
} = &*external_constraints;
270-
self.register_region_constraints(region_constraints);
271-
self.register_new_opaque_types(opaque_types);
272+
273+
self.register_region_constraints(region_constraints, span);
274+
self.register_new_opaque_types(opaque_types, span);
275+
272276
(normalization_nested_goals.clone(), certainty)
273277
}
274278

@@ -279,6 +283,7 @@ where
279283
delegate: &D,
280284
original_values: &[I::GenericArg],
281285
response: &Canonical<I, T>,
286+
span: I::Span,
282287
) -> CanonicalVarValues<I> {
283288
// FIXME: Longterm canonical queries should deal with all placeholders
284289
// created inside of the query directly instead of returning them to the
@@ -331,7 +336,7 @@ where
331336
// A variable from inside a binder of the query. While ideally these shouldn't
332337
// exist at all (see the FIXME at the start of this method), we have to deal with
333338
// them for now.
334-
delegate.instantiate_canonical_var_with_infer(info, |idx| {
339+
delegate.instantiate_canonical_var_with_infer(info, span, |idx| {
335340
ty::UniverseIndex::from(prev_universe.index() + idx.index())
336341
})
337342
} else if info.is_existential() {
@@ -345,7 +350,7 @@ where
345350
if let Some(v) = opt_values[ty::BoundVar::from_usize(index)] {
346351
v
347352
} else {
348-
delegate.instantiate_canonical_var_with_infer(info, |_| prev_universe)
353+
delegate.instantiate_canonical_var_with_infer(info, span, |_| prev_universe)
349354
}
350355
} else {
351356
// For placeholders which were already part of the input, we simply map this
@@ -376,32 +381,44 @@ where
376381
param_env: I::ParamEnv,
377382
original_values: &[I::GenericArg],
378383
var_values: CanonicalVarValues<I>,
384+
span: I::Span,
379385
) {
380386
assert_eq!(original_values.len(), var_values.len());
381387

382388
for (&orig, response) in iter::zip(original_values, var_values.var_values.iter()) {
383389
let goals =
384-
delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap();
390+
delegate.eq_structurally_relating_aliases(param_env, orig, response, span).unwrap();
385391
assert!(goals.is_empty());
386392
}
387393
}
388394

389395
fn register_region_constraints(
390396
&mut self,
391397
outlives: &[ty::OutlivesPredicate<I, I::GenericArg>],
398+
span: I::Span,
392399
) {
393400
for &ty::OutlivesPredicate(lhs, rhs) in outlives {
394401
match lhs.kind() {
395-
ty::GenericArgKind::Lifetime(lhs) => self.register_region_outlives(lhs, rhs),
396-
ty::GenericArgKind::Type(lhs) => self.register_ty_outlives(lhs, rhs),
402+
ty::GenericArgKind::Lifetime(lhs) => {
403+
self.delegate.sub_regions(rhs, lhs, span);
404+
}
405+
ty::GenericArgKind::Type(lhs) => {
406+
{
407+
self.delegate.register_ty_outlives(lhs, rhs, span);
408+
};
409+
}
397410
ty::GenericArgKind::Const(_) => panic!("const outlives: {lhs:?}: {rhs:?}"),
398411
}
399412
}
400413
}
401414

402-
fn register_new_opaque_types(&mut self, opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)]) {
415+
fn register_new_opaque_types(
416+
&mut self,
417+
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
418+
span: I::Span,
419+
) {
403420
for &(key, ty) in opaque_types {
404-
self.delegate.inject_new_hidden_type_unchecked(key, ty);
421+
self.delegate.inject_new_hidden_type_unchecked(key, ty, span);
405422
}
406423
}
407424
}
@@ -451,10 +468,10 @@ where
451468
}
452469

453470
let instantiation =
454-
EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state);
471+
EvalCtxt::compute_query_response_instantiation_values(delegate, orig_values, &state, span);
455472

456473
let inspect::State { var_values, data } = delegate.instantiate_canonical(state, instantiation);
457474

458-
EvalCtxt::unify_query_var_values(delegate, param_env, orig_values, var_values);
475+
EvalCtxt::unify_query_var_values(delegate, param_env, orig_values, var_values, span);
459476
data
460477
}

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+38-14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
134134
&self,
135135
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
136136
generate_proof_tree: GenerateProofTree,
137+
span: <Self::Interner as Interner>::Span,
137138
) -> (
138139
Result<(HasChanged, Certainty), NoSolution>,
139140
Option<inspect::GoalEvaluation<Self::Interner>>,
@@ -174,9 +175,10 @@ where
174175
&self,
175176
goal: Goal<I, I::Predicate>,
176177
generate_proof_tree: GenerateProofTree,
178+
span: I::Span,
177179
) -> (Result<(HasChanged, Certainty), NoSolution>, Option<inspect::GoalEvaluation<I>>) {
178180
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
179-
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
181+
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal, span)
180182
})
181183
}
182184

@@ -187,7 +189,12 @@ where
187189
) -> bool {
188190
self.probe(|| {
189191
EvalCtxt::enter_root(self, root_depth, GenerateProofTree::No, |ecx| {
190-
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
192+
ecx.evaluate_goal(
193+
GoalEvaluationKind::Root,
194+
GoalSource::Misc,
195+
goal,
196+
I::Span::dummy(),
197+
)
191198
})
192199
.0
193200
})
@@ -204,7 +211,12 @@ where
204211
Option<inspect::GoalEvaluation<I>>,
205212
) {
206213
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
207-
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
214+
ecx.evaluate_goal_raw(
215+
GoalEvaluationKind::Root,
216+
GoalSource::Misc,
217+
goal,
218+
I::Span::dummy(),
219+
)
208220
})
209221
}
210222
}
@@ -294,7 +306,7 @@ where
294306
};
295307

296308
for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {
297-
ecx.delegate.inject_new_hidden_type_unchecked(key, ty);
309+
ecx.delegate.inject_new_hidden_type_unchecked(key, ty, I::Span::dummy());
298310
}
299311

300312
if !ecx.nested_goals.is_empty() {
@@ -370,9 +382,10 @@ where
370382
goal_evaluation_kind: GoalEvaluationKind,
371383
source: GoalSource,
372384
goal: Goal<I, I::Predicate>,
385+
span: I::Span,
373386
) -> Result<(HasChanged, Certainty), NoSolution> {
374387
let (normalization_nested_goals, has_changed, certainty) =
375-
self.evaluate_goal_raw(goal_evaluation_kind, source, goal)?;
388+
self.evaluate_goal_raw(goal_evaluation_kind, source, goal, span)?;
376389
assert!(normalization_nested_goals.is_empty());
377390
Ok((has_changed, certainty))
378391
}
@@ -391,6 +404,7 @@ where
391404
goal_evaluation_kind: GoalEvaluationKind,
392405
_source: GoalSource,
393406
goal: Goal<I, I::Predicate>,
407+
span: I::Span,
394408
) -> Result<(NestedNormalizationGoals<I>, HasChanged, Certainty), NoSolution> {
395409
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
396410
let mut goal_evaluation =
@@ -418,7 +432,7 @@ where
418432
};
419433

420434
let (normalization_nested_goals, certainty) =
421-
self.instantiate_and_apply_query_response(goal.param_env, orig_values, response);
435+
self.instantiate_and_apply_query_response(goal.param_env, orig_values, response, span);
422436
self.inspect.goal_evaluation(goal_evaluation);
423437

424438
// FIXME: We previously had an assert here that checked that recomputing
@@ -546,6 +560,7 @@ where
546560
GoalEvaluationKind::Nested,
547561
GoalSource::Misc,
548562
unconstrained_goal,
563+
I::Span::dummy(),
549564
)?;
550565
// Add the nested goals from normalization to our own nested goals.
551566
trace!(?nested_goals);
@@ -591,7 +606,7 @@ where
591606

592607
for (source, goal) in goals.goals {
593608
let (has_changed, certainty) =
594-
self.evaluate_goal(GoalEvaluationKind::Nested, source, goal)?;
609+
self.evaluate_goal(GoalEvaluationKind::Nested, source, goal, I::Span::dummy())?;
595610
if has_changed == HasChanged::Yes {
596611
unchanged_certainty = None;
597612
}
@@ -822,8 +837,12 @@ where
822837
let identity_args = self.fresh_args_for_item(alias.def_id);
823838
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.def_id, identity_args);
824839
let ctor_term = rigid_ctor.to_term(cx);
825-
let obligations =
826-
self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?;
840+
let obligations = self.delegate.eq_structurally_relating_aliases(
841+
param_env,
842+
term,
843+
ctor_term,
844+
I::Span::dummy(),
845+
)?;
827846
debug_assert!(obligations.is_empty());
828847
self.relate(param_env, alias, variance, rigid_ctor)
829848
} else {
@@ -841,7 +860,12 @@ where
841860
lhs: T,
842861
rhs: T,
843862
) -> Result<(), NoSolution> {
844-
let result = self.delegate.eq_structurally_relating_aliases(param_env, lhs, rhs)?;
863+
let result = self.delegate.eq_structurally_relating_aliases(
864+
param_env,
865+
lhs,
866+
rhs,
867+
I::Span::dummy(),
868+
)?;
845869
assert_eq!(result, vec![]);
846870
Ok(())
847871
}
@@ -864,7 +888,7 @@ where
864888
variance: ty::Variance,
865889
rhs: T,
866890
) -> Result<(), NoSolution> {
867-
let goals = self.delegate.relate(param_env, lhs, variance, rhs)?;
891+
let goals = self.delegate.relate(param_env, lhs, variance, rhs, I::Span::dummy())?;
868892
self.add_goals(GoalSource::Misc, goals);
869893
Ok(())
870894
}
@@ -881,7 +905,7 @@ where
881905
lhs: T,
882906
rhs: T,
883907
) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
884-
Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs)?)
908+
Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, I::Span::dummy())?)
885909
}
886910

887911
pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(
@@ -917,12 +941,12 @@ where
917941
}
918942

919943
pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) {
920-
self.delegate.register_ty_outlives(ty, lt);
944+
self.delegate.register_ty_outlives(ty, lt, I::Span::dummy());
921945
}
922946

923947
pub(super) fn register_region_outlives(&self, a: I::Region, b: I::Region) {
924948
// `b : a` ==> `a <= b`
925-
self.delegate.sub_regions(b, a);
949+
self.delegate.sub_regions(b, a, I::Span::dummy());
926950
}
927951

928952
/// Computes the list of goals required for `arg` to be well-formed

0 commit comments

Comments
 (0)