Skip to content

Commit c9c7f62

Browse files
authored
Unrolled build for rust-lang#125664
Rollup merge of rust-lang#125664 - compiler-errors:trace-tweaks, r=lcnr Tweak relations to no longer rely on `TypeTrace` Remove `At::trace`, and inline all of the `Trace::equate`,etc methods into `At`. The only nontrivial change is that we use `AliasTerm` to relate two unevaluated consts in the old-solver impl of `ConstEquate`, since `AliasTerm` does implement `ToTrace` and will relate the args structurally (shallowly). r? lcnr
2 parents da159eb + 2bd5050 commit c9c7f62

File tree

8 files changed

+96
-149
lines changed

8 files changed

+96
-149
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11581158
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
11591159
let sig = self
11601160
.at(cause, self.param_env)
1161-
.trace(prev_ty, new_ty)
11621161
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
11631162
.map(|ok| self.register_infer_ok_obligations(ok))?;
11641163

compiler/rustc_infer/src/infer/at.rs

+73-122
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ pub struct At<'a, 'tcx> {
4848
pub param_env: ty::ParamEnv<'tcx>,
4949
}
5050

51-
pub struct Trace<'a, 'tcx> {
52-
at: At<'a, 'tcx>,
53-
trace: TypeTrace<'tcx>,
54-
}
55-
5651
impl<'tcx> InferCtxt<'tcx> {
5752
#[inline]
5853
pub fn at<'a>(
@@ -109,9 +104,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109104
/// call like `foo(x)`, where `foo: fn(i32)`, you might have
110105
/// `sup(i32, x)`, since the "expected" type is the type that
111106
/// appears in the signature.
112-
///
113-
/// See [`At::trace`] and [`Trace::sub`] for a version of
114-
/// this method that only requires `T: Relate<'tcx>`
115107
pub fn sup<T>(
116108
self,
117109
define_opaque_types: DefineOpaqueTypes,
@@ -121,13 +113,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
121113
where
122114
T: ToTrace<'tcx>,
123115
{
124-
self.trace(expected, actual).sup(define_opaque_types, expected, actual)
116+
let mut fields = CombineFields::new(
117+
self.infcx,
118+
ToTrace::to_trace(self.cause, true, expected, actual),
119+
self.param_env,
120+
define_opaque_types,
121+
);
122+
fields
123+
.sup()
124+
.relate(expected, actual)
125+
.map(|_| InferOk { value: (), obligations: fields.obligations })
125126
}
126127

127128
/// Makes `expected <: actual`.
128-
///
129-
/// See [`At::trace`] and [`Trace::sub`] for a version of
130-
/// this method that only requires `T: Relate<'tcx>`
131129
pub fn sub<T>(
132130
self,
133131
define_opaque_types: DefineOpaqueTypes,
@@ -137,13 +135,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
137135
where
138136
T: ToTrace<'tcx>,
139137
{
140-
self.trace(expected, actual).sub(define_opaque_types, expected, actual)
138+
let mut fields = CombineFields::new(
139+
self.infcx,
140+
ToTrace::to_trace(self.cause, true, expected, actual),
141+
self.param_env,
142+
define_opaque_types,
143+
);
144+
fields
145+
.sub()
146+
.relate(expected, actual)
147+
.map(|_| InferOk { value: (), obligations: fields.obligations })
141148
}
142149

143-
/// Makes `expected <: actual`.
144-
///
145-
/// See [`At::trace`] and [`Trace::eq`] for a version of
146-
/// this method that only requires `T: Relate<'tcx>`
150+
/// Makes `expected == actual`.
147151
pub fn eq<T>(
148152
self,
149153
define_opaque_types: DefineOpaqueTypes,
@@ -153,7 +157,40 @@ impl<'a, 'tcx> At<'a, 'tcx> {
153157
where
154158
T: ToTrace<'tcx>,
155159
{
156-
self.trace(expected, actual).eq(define_opaque_types, expected, actual)
160+
let mut fields = CombineFields::new(
161+
self.infcx,
162+
ToTrace::to_trace(self.cause, true, expected, actual),
163+
self.param_env,
164+
define_opaque_types,
165+
);
166+
fields
167+
.equate(StructurallyRelateAliases::No)
168+
.relate(expected, actual)
169+
.map(|_| InferOk { value: (), obligations: fields.obligations })
170+
}
171+
172+
/// Equates `expected` and `found` while structurally relating aliases.
173+
/// This should only be used inside of the next generation trait solver
174+
/// when relating rigid aliases.
175+
pub fn eq_structurally_relating_aliases<T>(
176+
self,
177+
expected: T,
178+
actual: T,
179+
) -> InferResult<'tcx, ()>
180+
where
181+
T: ToTrace<'tcx>,
182+
{
183+
assert!(self.infcx.next_trait_solver());
184+
let mut fields = CombineFields::new(
185+
self.infcx,
186+
ToTrace::to_trace(self.cause, true, expected, actual),
187+
self.param_env,
188+
DefineOpaqueTypes::Yes,
189+
);
190+
fields
191+
.equate(StructurallyRelateAliases::Yes)
192+
.relate(expected, actual)
193+
.map(|_| InferOk { value: (), obligations: fields.obligations })
157194
}
158195

159196
pub fn relate<T>(
@@ -185,9 +222,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
185222
/// this can result in an error (e.g., if asked to compute LUB of
186223
/// u32 and i32), it is meaningful to call one of them the
187224
/// "expected type".
188-
///
189-
/// See [`At::trace`] and [`Trace::lub`] for a version of
190-
/// this method that only requires `T: Relate<'tcx>`
191225
pub fn lub<T>(
192226
self,
193227
define_opaque_types: DefineOpaqueTypes,
@@ -197,15 +231,21 @@ impl<'a, 'tcx> At<'a, 'tcx> {
197231
where
198232
T: ToTrace<'tcx>,
199233
{
200-
self.trace(expected, actual).lub(define_opaque_types, expected, actual)
234+
let mut fields = CombineFields::new(
235+
self.infcx,
236+
ToTrace::to_trace(self.cause, true, expected, actual),
237+
self.param_env,
238+
define_opaque_types,
239+
);
240+
fields
241+
.lub()
242+
.relate(expected, actual)
243+
.map(|value| InferOk { value, obligations: fields.obligations })
201244
}
202245

203246
/// Computes the greatest-lower-bound, or mutual subtype, of two
204247
/// values. As with `lub` order doesn't matter, except for error
205248
/// cases.
206-
///
207-
/// See [`At::trace`] and [`Trace::glb`] for a version of
208-
/// this method that only requires `T: Relate<'tcx>`
209249
pub fn glb<T>(
210250
self,
211251
define_opaque_types: DefineOpaqueTypes,
@@ -215,105 +255,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
215255
where
216256
T: ToTrace<'tcx>,
217257
{
218-
self.trace(expected, actual).glb(define_opaque_types, expected, actual)
219-
}
220-
221-
/// Sets the "trace" values that will be used for
222-
/// error-reporting, but doesn't actually perform any operation
223-
/// yet (this is useful when you want to set the trace using
224-
/// distinct values from those you wish to operate upon).
225-
pub fn trace<T>(self, expected: T, actual: T) -> Trace<'a, 'tcx>
226-
where
227-
T: ToTrace<'tcx>,
228-
{
229-
let trace = ToTrace::to_trace(self.cause, true, expected, actual);
230-
Trace { at: self, trace }
231-
}
232-
}
233-
234-
impl<'a, 'tcx> Trace<'a, 'tcx> {
235-
/// Makes `a <: b`.
236-
#[instrument(skip(self), level = "debug")]
237-
pub fn sub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()>
238-
where
239-
T: Relate<'tcx>,
240-
{
241-
let Trace { at, trace } = self;
242-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
243-
fields
244-
.sub()
245-
.relate(a, b)
246-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
247-
}
248-
249-
/// Makes `a :> b`.
250-
#[instrument(skip(self), level = "debug")]
251-
pub fn sup<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()>
252-
where
253-
T: Relate<'tcx>,
254-
{
255-
let Trace { at, trace } = self;
256-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
257-
fields
258-
.sup()
259-
.relate(a, b)
260-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
261-
}
262-
263-
/// Makes `a == b`.
264-
#[instrument(skip(self), level = "debug")]
265-
pub fn eq<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, ()>
266-
where
267-
T: Relate<'tcx>,
268-
{
269-
let Trace { at, trace } = self;
270-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
271-
fields
272-
.equate(StructurallyRelateAliases::No)
273-
.relate(a, b)
274-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
275-
}
276-
277-
/// Equates `a` and `b` while structurally relating aliases. This should only
278-
/// be used inside of the next generation trait solver when relating rigid aliases.
279-
#[instrument(skip(self), level = "debug")]
280-
pub fn eq_structurally_relating_aliases<T>(self, a: T, b: T) -> InferResult<'tcx, ()>
281-
where
282-
T: Relate<'tcx>,
283-
{
284-
let Trace { at, trace } = self;
285-
debug_assert!(at.infcx.next_trait_solver());
286-
let mut fields = at.infcx.combine_fields(trace, at.param_env, DefineOpaqueTypes::Yes);
287-
fields
288-
.equate(StructurallyRelateAliases::Yes)
289-
.relate(a, b)
290-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
291-
}
292-
293-
#[instrument(skip(self), level = "debug")]
294-
pub fn lub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, T>
295-
where
296-
T: Relate<'tcx>,
297-
{
298-
let Trace { at, trace } = self;
299-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
300-
fields
301-
.lub()
302-
.relate(a, b)
303-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
304-
}
305-
306-
#[instrument(skip(self), level = "debug")]
307-
pub fn glb<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferResult<'tcx, T>
308-
where
309-
T: Relate<'tcx>,
310-
{
311-
let Trace { at, trace } = self;
312-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
258+
let mut fields = CombineFields::new(
259+
self.infcx,
260+
ToTrace::to_trace(self.cause, true, expected, actual),
261+
self.param_env,
262+
define_opaque_types,
263+
);
313264
fields
314265
.glb()
315-
.relate(a, b)
316-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
266+
.relate(expected, actual)
267+
.map(|value| InferOk { value, obligations: fields.obligations })
317268
}
318269
}
319270

compiler/rustc_infer/src/infer/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -836,21 +836,6 @@ impl<'tcx> InferCtxt<'tcx> {
836836
.collect()
837837
}
838838

839-
fn combine_fields<'a>(
840-
&'a self,
841-
trace: TypeTrace<'tcx>,
842-
param_env: ty::ParamEnv<'tcx>,
843-
define_opaque_types: DefineOpaqueTypes,
844-
) -> CombineFields<'a, 'tcx> {
845-
CombineFields {
846-
infcx: self,
847-
trace,
848-
param_env,
849-
obligations: PredicateObligations::new(),
850-
define_opaque_types,
851-
}
852-
}
853-
854839
pub fn can_sub<T>(&self, param_env: ty::ParamEnv<'tcx>, expected: T, actual: T) -> bool
855840
where
856841
T: at::ToTrace<'tcx>,

compiler/rustc_infer/src/infer/relate/combine.rs

+11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ pub struct CombineFields<'infcx, 'tcx> {
4242
pub define_opaque_types: DefineOpaqueTypes,
4343
}
4444

45+
impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
46+
pub fn new(
47+
infcx: &'infcx InferCtxt<'tcx>,
48+
trace: TypeTrace<'tcx>,
49+
param_env: ty::ParamEnv<'tcx>,
50+
define_opaque_types: DefineOpaqueTypes,
51+
) -> Self {
52+
Self { infcx, trace, param_env, define_opaque_types, obligations: vec![] }
53+
}
54+
}
55+
4556
impl<'tcx> InferCtxt<'tcx> {
4657
pub fn super_combine_tys<R>(
4758
&self,

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

-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
363363
for (&orig, response) in iter::zip(original_values, var_values.var_values) {
364364
let InferOk { value: (), obligations } = infcx
365365
.at(&cause, param_env)
366-
.trace(orig, response)
367366
.eq_structurally_relating_aliases(orig, response)
368367
.unwrap();
369368
assert!(obligations.is_empty());

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
776776
let InferOk { value: (), obligations } = self
777777
.infcx
778778
.at(&ObligationCause::dummy(), param_env)
779-
.trace(term, ctor_term)
780779
.eq_structurally_relating_aliases(term, ctor_term)?;
781780
debug_assert!(obligations.is_empty());
782781
self.relate(param_env, alias, variance, rigid_ctor)
@@ -796,11 +795,8 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
796795
rhs: T,
797796
) -> Result<(), NoSolution> {
798797
let cause = ObligationCause::dummy();
799-
let InferOk { value: (), obligations } = self
800-
.infcx
801-
.at(&cause, param_env)
802-
.trace(lhs, rhs)
803-
.eq_structurally_relating_aliases(lhs, rhs)?;
798+
let InferOk { value: (), obligations } =
799+
self.infcx.at(&cause, param_env).eq_structurally_relating_aliases(lhs, rhs)?;
804800
assert!(obligations.is_empty());
805801
Ok(())
806802
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,13 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
566566
{
567567
if let Ok(new_obligations) = infcx
568568
.at(&obligation.cause, obligation.param_env)
569-
.trace(c1, c2)
570569
// Can define opaque types as this is only reachable with
571570
// `generic_const_exprs`
572-
.eq(DefineOpaqueTypes::Yes, a.args, b.args)
571+
.eq(
572+
DefineOpaqueTypes::Yes,
573+
ty::AliasTerm::from(a),
574+
ty::AliasTerm::from(b),
575+
)
573576
{
574577
return ProcessResult::Changed(mk_pending(
575578
new_obligations.into_obligations(),

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
910910
if let Ok(InferOk { obligations, value: () }) = self
911911
.infcx
912912
.at(&obligation.cause, obligation.param_env)
913-
.trace(c1, c2)
914913
// Can define opaque types as this is only reachable with
915914
// `generic_const_exprs`
916-
.eq(DefineOpaqueTypes::Yes, a.args, b.args)
915+
.eq(
916+
DefineOpaqueTypes::Yes,
917+
ty::AliasTerm::from(a),
918+
ty::AliasTerm::from(b),
919+
)
917920
{
918921
return self.evaluate_predicates_recursively(
919922
previous_stack,

0 commit comments

Comments
 (0)