Skip to content

Commit dd3b001

Browse files
committed
Auto merge of rust-lang#123016 - compiler-errors:no-type-var-origin, r=lcnr
Remove `TypeVariableOriginKind` and `ConstVariableOriginKind` It's annoying to have to import `TypeVariableOriginKind` just to fill it with `MiscVariable` for almost every use. Every other usage other than `TypeParameterDefinition` wasn't even used -- I can see how it may have been useful once for debugging, but I do quite a lot of typeck debugging and I've never really needed it. So let's just remove it, and keep around the only useful thing which is the `DefId` of the param for `var_for_def`. This is based on rust-lang#123006, which removed the special use of `TypeVariableOriginKind::OpaqueInference`, which I'm pretty sure I was the one that added. r? lcnr or re-roll to types
2 parents 83d0a94 + 7dead92 commit dd3b001

File tree

41 files changed

+196
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+196
-387
lines changed

compiler/rustc_borrowck/src/type_check/input_output.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::assert_matches::assert_matches;
1111

1212
use itertools::Itertools;
1313
use rustc_hir as hir;
14-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
14+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1515
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
1616
use rustc_middle::mir::*;
1717
use rustc_middle::ty::{self, Ty};
@@ -75,10 +75,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7575
);
7676

7777
let next_ty_var = || {
78-
self.infcx.next_ty_var(TypeVariableOrigin {
79-
span: body.span,
80-
kind: TypeVariableOriginKind::MiscVariable,
81-
})
78+
self.infcx.next_ty_var(TypeVariableOrigin { span: body.span, param_def_id: None })
8279
};
8380
let output_ty = Ty::new_coroutine(
8481
self.tcx(),

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::{IndexSlice, IndexVec};
1616
use rustc_infer::infer::canonical::QueryRegionConstraints;
1717
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1818
use rustc_infer::infer::region_constraints::RegionConstraintData;
19-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
19+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
2020
use rustc_infer::infer::{
2121
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
2222
};
@@ -2425,7 +2425,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24252425
ty::RawPtr(_, _) | ty::FnPtr(_) => {
24262426
let ty_right = right.ty(body, tcx);
24272427
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
2428-
kind: TypeVariableOriginKind::MiscVariable,
2428+
param_def_id: None,
24292429
span: body.source_info(location).span,
24302430
});
24312431
self.sub_types(

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_errors::ErrorGuaranteed;
3-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
44
use rustc_infer::infer::NllRegionVariableOrigin;
55
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
66
use rustc_infer::traits::{Obligation, PredicateObligations};
@@ -129,10 +129,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
129129
// the opaque.
130130
let mut enable_subtyping = |ty, opaque_is_expected| {
131131
let ty_vid = infcx.next_ty_var_id_in_universe(
132-
TypeVariableOrigin {
133-
kind: TypeVariableOriginKind::MiscVariable,
134-
span: self.span(),
135-
},
132+
TypeVariableOrigin { param_def_id: None, span: self.span() },
136133
ty::UniverseIndex::ROOT,
137134
);
138135

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::intravisit;
1010
use rustc_hir::{GenericParamKind, ImplItemKind};
1111
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
12-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
12+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1313
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1414
use rustc_infer::traits::{util, FulfillmentError};
1515
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -800,10 +800,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
800800
bug!("FIXME(RPITIT): error here");
801801
}
802802
// Replace with infer var
803-
let infer_ty = self.ocx.infcx.next_ty_var(TypeVariableOrigin {
804-
span: self.span,
805-
kind: TypeVariableOriginKind::MiscVariable,
806-
});
803+
let infer_ty = self
804+
.ocx
805+
.infcx
806+
.next_ty_var(TypeVariableOrigin { span: self.span, param_def_id: None });
807807
self.types.insert(proj.def_id, (infer_ty, proj.args));
808808
// Recurse into bounds
809809
for (pred, pred_span) in self

compiler/rustc_hir_typeck/src/_match.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
55
use rustc_hir::def_id::LocalDefId;
66
use rustc_hir::{self as hir, ExprKind, PatKind};
77
use rustc_hir_pretty::ty_to_string;
8-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
8+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
99
use rustc_middle::ty::{self, Ty};
1010
use rustc_span::Span;
1111
use rustc_trait_selection::traits::{
@@ -67,10 +67,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6767
// arm for inconsistent arms or to the whole match when a `()` type
6868
// is required).
6969
Expectation::ExpectHasType(ety) if ety != Ty::new_unit(self.tcx) => ety,
70-
_ => self.next_ty_var(TypeVariableOrigin {
71-
kind: TypeVariableOriginKind::MiscVariable,
72-
span: expr.span,
73-
}),
70+
_ => self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span }),
7471
};
7572
CoerceMany::with_coercion_sites(coerce_first, arms)
7673
};
@@ -578,10 +575,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578575
// ...but otherwise we want to use any supertype of the
579576
// scrutinee. This is sort of a workaround, see note (*) in
580577
// `check_pat` for some details.
581-
let scrut_ty = self.next_ty_var(TypeVariableOrigin {
582-
kind: TypeVariableOriginKind::TypeInference,
583-
span: scrut.span,
584-
});
578+
let scrut_ty =
579+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: scrut.span });
585580
self.check_expr_has_type_or_error(scrut, scrut_ty, |_| {});
586581
scrut_ty
587582
}

compiler/rustc_hir_typeck/src/callee.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use rustc_infer::{
1313
infer,
1414
traits::{self, Obligation},
1515
};
16-
use rustc_infer::{
17-
infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind},
18-
traits::ObligationCause,
19-
};
16+
use rustc_infer::{infer::type_variable::TypeVariableOrigin, traits::ObligationCause};
2017
use rustc_middle::ty::adjustment::{
2118
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
2219
};
@@ -180,18 +177,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
180177
infer::FnCall,
181178
closure_args.coroutine_closure_sig(),
182179
);
183-
let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin {
184-
kind: TypeVariableOriginKind::TypeInference,
185-
span: callee_expr.span,
186-
});
180+
let tupled_upvars_ty = self
181+
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
187182
// We may actually receive a coroutine back whose kind is different
188183
// from the closure that this dispatched from. This is because when
189184
// we have no captures, we automatically implement `FnOnce`. This
190185
// impl forces the closure kind to `FnOnce` i.e. `u8`.
191-
let kind_ty = self.next_ty_var(TypeVariableOrigin {
192-
kind: TypeVariableOriginKind::TypeInference,
193-
span: callee_expr.span,
194-
});
186+
let kind_ty = self
187+
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
195188
let call_sig = self.tcx.mk_fn_sig(
196189
[coroutine_closure_sig.tupled_inputs_ty],
197190
coroutine_closure_sig.to_coroutine(
@@ -305,10 +298,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
305298
Ty::new_tup_from_iter(
306299
self.tcx,
307300
arg_exprs.iter().map(|e| {
308-
self.next_ty_var(TypeVariableOrigin {
309-
kind: TypeVariableOriginKind::TypeInference,
310-
span: e.span,
311-
})
301+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: e.span })
312302
}),
313303
)
314304
});

compiler/rustc_hir_typeck/src/check.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def::DefKind;
88
use rustc_hir::intravisit::Visitor;
99
use rustc_hir::lang_items::LangItem;
1010
use rustc_hir_analysis::check::{check_function_signature, forbid_intrinsic_abi};
11-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
11+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1212
use rustc_infer::infer::RegionVariableOrigin;
1313
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
1414
use rustc_span::def_id::LocalDefId;
@@ -123,8 +123,7 @@ pub(super) fn check_fn<'a, 'tcx>(
123123
// We have special-cased the case where the function is declared
124124
// `-> dyn Foo` and we don't actually relate it to the
125125
// `fcx.ret_coercion`, so just instantiate a type variable.
126-
actual_return_ty =
127-
fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::DynReturnFn, span });
126+
actual_return_ty = fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
128127
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
129128
}
130129

compiler/rustc_hir_typeck/src/closure.rs

+27-45
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::ErrorGuaranteed;
66
use rustc_hir as hir;
77
use rustc_hir::lang_items::LangItem;
88
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
9-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
9+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1010
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
1111
use rustc_infer::infer::{InferOk, InferResult};
1212
use rustc_macros::{TypeFoldable, TypeVisitable};
@@ -72,10 +72,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
let parent_args =
7373
GenericArgs::identity_for_item(tcx, tcx.typeck_root_def_id(expr_def_id.to_def_id()));
7474

75-
let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin {
76-
kind: TypeVariableOriginKind::ClosureSynthetic,
77-
span: expr_span,
78-
});
75+
let tupled_upvars_ty =
76+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
7977

8078
// FIXME: We could probably actually just unify this further --
8179
// instead of having a `FnSig` and a `Option<CoroutineTypes>`,
@@ -102,11 +100,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
102100

103101
// Create a type variable (for now) to represent the closure kind.
104102
// It will be unified during the upvar inference phase (`upvar.rs`)
105-
None => self.next_ty_var(TypeVariableOrigin {
106-
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
107-
kind: TypeVariableOriginKind::ClosureSynthetic,
108-
span: expr_span,
109-
}),
103+
None => {
104+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
105+
}
110106
};
111107

112108
let closure_args = ty::ClosureArgs::new(
@@ -126,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126122
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
127123
| hir::CoroutineKind::Coroutine(_) => {
128124
let yield_ty = self.next_ty_var(TypeVariableOrigin {
129-
kind: TypeVariableOriginKind::ClosureSynthetic,
125+
param_def_id: None,
130126
span: expr_span,
131127
});
132128
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
@@ -138,7 +134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
138134
// not a problem.
139135
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
140136
let yield_ty = self.next_ty_var(TypeVariableOrigin {
141-
kind: TypeVariableOriginKind::ClosureSynthetic,
137+
param_def_id: None,
142138
span: expr_span,
143139
});
144140
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
@@ -166,10 +162,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166162
// Resume type defaults to `()` if the coroutine has no argument.
167163
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
168164

169-
let interior = self.next_ty_var(TypeVariableOrigin {
170-
kind: TypeVariableOriginKind::ClosureSynthetic,
171-
span: expr_span,
172-
});
165+
let interior =
166+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
173167
self.deferred_coroutine_interiors.borrow_mut().push((
174168
expr_def_id,
175169
body.id(),
@@ -181,11 +175,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
181175
// later during upvar analysis. Regular coroutines always have the kind
182176
// ty of `().`
183177
let kind_ty = match kind {
184-
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => self
185-
.next_ty_var(TypeVariableOrigin {
186-
kind: TypeVariableOriginKind::ClosureSynthetic,
187-
span: expr_span,
188-
}),
178+
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
179+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
180+
}
189181
_ => tcx.types.unit,
190182
};
191183

@@ -219,30 +211,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
219211
}
220212
};
221213
// Compute all of the variables that will be used to populate the coroutine.
222-
let resume_ty = self.next_ty_var(TypeVariableOrigin {
223-
kind: TypeVariableOriginKind::ClosureSynthetic,
224-
span: expr_span,
225-
});
226-
let interior = self.next_ty_var(TypeVariableOrigin {
227-
kind: TypeVariableOriginKind::ClosureSynthetic,
228-
span: expr_span,
229-
});
214+
let resume_ty =
215+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
216+
let interior =
217+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
230218

231219
let closure_kind_ty = match expected_kind {
232220
Some(kind) => Ty::from_closure_kind(tcx, kind),
233221

234222
// Create a type variable (for now) to represent the closure kind.
235223
// It will be unified during the upvar inference phase (`upvar.rs`)
236-
None => self.next_ty_var(TypeVariableOrigin {
237-
kind: TypeVariableOriginKind::ClosureSynthetic,
238-
span: expr_span,
239-
}),
224+
None => {
225+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
226+
}
240227
};
241228

242-
let coroutine_captures_by_ref_ty = self.next_ty_var(TypeVariableOrigin {
243-
kind: TypeVariableOriginKind::ClosureSynthetic,
244-
span: expr_span,
245-
});
229+
let coroutine_captures_by_ref_ty =
230+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
246231
let closure_args = ty::CoroutineClosureArgs::new(
247232
tcx,
248233
ty::CoroutineClosureArgsParts {
@@ -274,16 +259,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
274259

275260
// Create a type variable (for now) to represent the closure kind.
276261
// It will be unified during the upvar inference phase (`upvar.rs`)
277-
None => self.next_ty_var(TypeVariableOrigin {
278-
kind: TypeVariableOriginKind::ClosureSynthetic,
279-
span: expr_span,
280-
}),
262+
None => {
263+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
264+
}
281265
};
282266

283-
let coroutine_upvars_ty = self.next_ty_var(TypeVariableOrigin {
284-
kind: TypeVariableOriginKind::ClosureSynthetic,
285-
span: expr_span,
286-
});
267+
let coroutine_upvars_ty =
268+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
287269

288270
// We need to turn the liberated signature that we got from HIR, which
289271
// looks something like `|Args...| -> T`, into a signature that is suitable

compiler/rustc_hir_typeck/src/coercion.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
4343
use rustc_hir::intravisit::{self, Visitor};
4444
use rustc_hir::Expr;
4545
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
46-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
46+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
4747
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
4848
use rustc_infer::traits::TraitEngineExt as _;
4949
use rustc_infer::traits::{IfExpressionCause, MatchExpressionArmCause, TraitEngine};
@@ -279,10 +279,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
279279
if b.is_ty_var() {
280280
// Two unresolved type variables: create a `Coerce` predicate.
281281
let target_ty = if self.use_lub {
282-
self.next_ty_var(TypeVariableOrigin {
283-
kind: TypeVariableOriginKind::LatticeVariable,
284-
span: self.cause.span,
285-
})
282+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.cause.span })
286283
} else {
287284
b
288285
};
@@ -581,10 +578,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
581578
// the `CoerceUnsized` target type and the expected type.
582579
// We only have the latter, so we use an inference variable
583580
// for the former and let type inference do the rest.
584-
let origin = TypeVariableOrigin {
585-
kind: TypeVariableOriginKind::MiscVariable,
586-
span: self.cause.span,
587-
};
581+
let origin = TypeVariableOrigin { param_def_id: None, span: self.cause.span };
588582
let coerce_target = self.next_ty_var(origin);
589583
let mut coercion = self.unify_and(coerce_target, target, |target| {
590584
let unsize = Adjustment { kind: Adjust::Pointer(PointerCoercion::Unsize), target };

compiler/rustc_hir_typeck/src/demand.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
337337
ty_op: |ty| {
338338
if let ty::Infer(infer) = ty.kind() {
339339
match infer {
340-
ty::TyVar(_) => self.next_ty_var(TypeVariableOrigin {
341-
kind: TypeVariableOriginKind::MiscVariable,
342-
span: DUMMY_SP,
343-
}),
340+
ty::TyVar(_) => self
341+
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP }),
344342
ty::IntVar(_) => self.next_int_var(),
345343
ty::FloatVar(_) => self.next_float_var(),
346344
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
@@ -356,10 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
356354
if let ty::ConstKind::Infer(_) = ct.kind() {
357355
self.next_const_var(
358356
ct.ty(),
359-
ConstVariableOrigin {
360-
kind: ConstVariableOriginKind::MiscVariable,
361-
span: DUMMY_SP,
362-
},
357+
ConstVariableOrigin { param_def_id: None, span: DUMMY_SP },
363358
)
364359
} else {
365360
ct

0 commit comments

Comments
 (0)