Skip to content

Commit 06b97a6

Browse files
Remove TypeVariableOriginKind
1 parent 8af3f22 commit 06b97a6

File tree

39 files changed

+147
-298
lines changed

39 files changed

+147
-298
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
};
@@ -2409,7 +2409,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24092409
ty::RawPtr(_, _) | ty::FnPtr(_) => {
24102410
let ty_right = right.ty(body, tcx);
24112411
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
2412-
kind: TypeVariableOriginKind::MiscVariable,
2412+
param_def_id: None,
24132413
span: body.source_info(location).span,
24142414
});
24152415
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

+22-38
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>`,
@@ -104,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
104102
// It will be unified during the upvar inference phase (`upvar.rs`)
105103
None => self.next_ty_var(TypeVariableOrigin {
106104
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
107-
kind: TypeVariableOriginKind::ClosureSynthetic,
105+
param_def_id: None,
108106
span: expr_span,
109107
}),
110108
};
@@ -126,7 +124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126124
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
127125
| hir::CoroutineKind::Coroutine(_) => {
128126
let yield_ty = self.next_ty_var(TypeVariableOrigin {
129-
kind: TypeVariableOriginKind::ClosureSynthetic,
127+
param_def_id: None,
130128
span: expr_span,
131129
});
132130
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
@@ -138,7 +136,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
138136
// not a problem.
139137
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
140138
let yield_ty = self.next_ty_var(TypeVariableOrigin {
141-
kind: TypeVariableOriginKind::ClosureSynthetic,
139+
param_def_id: None,
142140
span: expr_span,
143141
});
144142
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
@@ -166,10 +164,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
166164
// Resume type defaults to `()` if the coroutine has no argument.
167165
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
168166

169-
let interior = self.next_ty_var(TypeVariableOrigin {
170-
kind: TypeVariableOriginKind::ClosureSynthetic,
171-
span: expr_span,
172-
});
167+
let interior =
168+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
173169
self.deferred_coroutine_interiors.borrow_mut().push((
174170
expr_def_id,
175171
body.id(),
@@ -181,11 +177,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
181177
// later during upvar analysis. Regular coroutines always have the kind
182178
// ty of `().`
183179
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-
}),
180+
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
181+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
182+
}
189183
_ => tcx.types.unit,
190184
};
191185

@@ -219,23 +213,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
219213
}
220214
};
221215
// 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-
});
216+
let resume_ty =
217+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
218+
let interior =
219+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
230220
let closure_kind_ty = self.next_ty_var(TypeVariableOrigin {
231221
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
232-
kind: TypeVariableOriginKind::ClosureSynthetic,
233-
span: expr_span,
234-
});
235-
let coroutine_captures_by_ref_ty = self.next_ty_var(TypeVariableOrigin {
236-
kind: TypeVariableOriginKind::ClosureSynthetic,
222+
param_def_id: None,
237223
span: expr_span,
238224
});
225+
let coroutine_captures_by_ref_ty =
226+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
239227
let closure_args = ty::CoroutineClosureArgs::new(
240228
tcx,
241229
ty::CoroutineClosureArgsParts {
@@ -262,14 +250,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
262250
},
263251
);
264252

265-
let coroutine_kind_ty = self.next_ty_var(TypeVariableOrigin {
266-
kind: TypeVariableOriginKind::ClosureSynthetic,
267-
span: expr_span,
268-
});
269-
let coroutine_upvars_ty = self.next_ty_var(TypeVariableOrigin {
270-
kind: TypeVariableOriginKind::ClosureSynthetic,
271-
span: expr_span,
272-
});
253+
let coroutine_kind_ty =
254+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
255+
let coroutine_upvars_ty =
256+
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
273257

274258
// We need to turn the liberated signature that we got from HIR, which
275259
// 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

+2-4
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(_) => {

compiler/rustc_hir_typeck/src/expectation.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
22
use rustc_middle::ty::{self, Ty};
33
use rustc_span::Span;
44

@@ -110,8 +110,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
110110
/// Like `only_has_type`, but instead of returning `None` if no
111111
/// hard constraint exists, creates a fresh type variable.
112112
pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> {
113-
self.only_has_type(fcx).unwrap_or_else(|| {
114-
fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span })
115-
})
113+
self.only_has_type(fcx)
114+
.unwrap_or_else(|| fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span }))
116115
}
117116
}

0 commit comments

Comments
 (0)