Skip to content

Commit 4dcc49c

Browse files
committed
Refactor TypeVariableOrigin into TypeVariableOrigin and TypeVariableOriginKind
1 parent 05f5051 commit 4dcc49c

File tree

18 files changed

+196
-75
lines changed

18 files changed

+196
-75
lines changed

src/librustc/infer/canonical/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
//!
2222
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html
2323
24-
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, ConstVariableOrigin};
24+
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
25+
use crate::infer::ConstVariableOrigin;
2526
use crate::mir::interpret::ConstValue;
2627
use rustc_data_structures::indexed_vec::IndexVec;
2728
use rustc_macros::HashStable;
@@ -365,7 +366,10 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
365366
let ty = match ty_kind {
366367
CanonicalTyVarKind::General(ui) => {
367368
self.next_ty_var_in_universe(
368-
TypeVariableOrigin::MiscVariable(span),
369+
TypeVariableOrigin {
370+
kind: TypeVariableOriginKind::MiscVariable,
371+
span,
372+
},
369373
universe_map(ui)
370374
)
371375
}

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hir::def::Namespace;
22
use crate::hir::{self, Local, Pat, Body, HirId};
33
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
44
use crate::infer::InferCtxt;
5-
use crate::infer::type_variable::TypeVariableOrigin;
5+
use crate::infer::type_variable::TypeVariableOriginKind;
66
use crate::ty::{self, Ty, Infer, TyVar};
77
use crate::ty::print::Print;
88
use syntax::source_map::CompilerDesugaringKind;
@@ -83,8 +83,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8383
) -> String {
8484
if let ty::Infer(ty::TyVar(ty_vid)) = ty.sty {
8585
let ty_vars = self.type_variables.borrow();
86-
if let TypeVariableOrigin::TypeParameterDefinition(_, name) =
87-
*ty_vars.var_origin(ty_vid) {
86+
if let TypeVariableOriginKind::TypeParameterDefinition(name) =
87+
ty_vars.var_origin(ty_vid).kind {
8888
return name.to_string();
8989
}
9090
}

src/librustc/infer/lattice.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! a lattice.
2121
2222
use super::InferCtxt;
23-
use super::type_variable::TypeVariableOrigin;
23+
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2424

2525
use crate::traits::ObligationCause;
2626
use crate::ty::TyVar;
@@ -79,12 +79,18 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
7979
// iterate on the subtype obligations that are returned, but I
8080
// think this suffices. -nmatsakis
8181
(&ty::Infer(TyVar(..)), _) => {
82-
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
82+
let v = infcx.next_ty_var(TypeVariableOrigin {
83+
kind: TypeVariableOriginKind::LatticeVariable,
84+
span: this.cause().span,
85+
});
8386
this.relate_bound(v, b, a)?;
8487
Ok(v)
8588
}
8689
(_, &ty::Infer(TyVar(..))) => {
87-
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
90+
let v = infcx.next_ty_var(TypeVariableOrigin {
91+
kind: TypeVariableOriginKind::LatticeVariable,
92+
span: this.cause().span,
93+
});
8894
this.relate_bound(v, a, b)?;
8995
Ok(v)
9096
}

src/librustc/infer/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use self::lexical_region_resolve::LexicalRegionResolutions;
3939
use self::outlives::env::OutlivesEnvironment;
4040
use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound};
4141
use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
42-
use self::type_variable::TypeVariableOrigin;
42+
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
4343
use self::unify_key::{ToType, ConstVariableOrigin};
4444

4545
pub mod at;
@@ -1110,7 +1110,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11101110
let ty_var_id = self.type_variables.borrow_mut().new_var(
11111111
self.universe(),
11121112
false,
1113-
TypeVariableOrigin::TypeParameterDefinition(span, param.name),
1113+
TypeVariableOrigin {
1114+
kind: TypeVariableOriginKind::TypeParameterDefinition(param.name),
1115+
span,
1116+
},
11141117
);
11151118

11161119
self.tcx.mk_ty_var(ty_var_id).into()
@@ -1412,7 +1415,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14121415
T: TypeFoldable<'tcx>
14131416
{
14141417
let fld_r = |br| self.next_region_var(LateBoundRegion(span, br, lbrct));
1415-
let fld_t = |_| self.next_ty_var(TypeVariableOrigin::MiscVariable(span));
1418+
let fld_t = |_| {
1419+
self.next_ty_var(TypeVariableOrigin {
1420+
kind: TypeVariableOriginKind::MiscVariable,
1421+
span,
1422+
})
1423+
};
14161424
let fld_c = |_, ty| self.next_const_var(ty, ConstVariableOrigin::MiscVariable(span));
14171425
self.tcx.replace_bound_vars(value, fld_r, fld_t, fld_c)
14181426
}

src/librustc/infer/nll_relate/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,16 @@ where
270270
projection_ty: ty::ProjectionTy<'tcx>,
271271
value_ty: Ty<'tcx>,
272272
) -> Ty<'tcx> {
273-
use crate::infer::type_variable::TypeVariableOrigin;
273+
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
274274
use crate::traits::WhereClause;
275275
use syntax_pos::DUMMY_SP;
276276

277277
match value_ty.sty {
278278
ty::Projection(other_projection_ty) => {
279-
let var = self
280-
.infcx
281-
.next_ty_var(TypeVariableOrigin::MiscVariable(DUMMY_SP));
279+
let var = self.infcx.next_ty_var(TypeVariableOrigin {
280+
kind: TypeVariableOriginKind::MiscVariable,
281+
span: DUMMY_SP,
282+
});
282283
self.relate_projection_ty(projection_ty, var);
283284
self.relate_projection_ty(other_projection_ty, var);
284285
var

src/librustc/infer/opaque_types/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syntax_pos::Span;
44
use crate::hir::def_id::DefId;
55
use crate::hir;
66
use crate::hir::Node;
7-
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
7+
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind};
88
use crate::infer::outlives::free_region_map::FreeRegionRelations;
99
use crate::traits::{self, PredicateObligation};
1010
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
@@ -864,7 +864,10 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
864864
return opaque_defn.concrete_ty;
865865
}
866866
let span = tcx.def_span(def_id);
867-
let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
867+
let ty_var = infcx.next_ty_var(TypeVariableOrigin {
868+
kind: TypeVariableOriginKind::TypeInference,
869+
span,
870+
});
868871

869872
let predicates_of = tcx.predicates_of(def_id);
870873
debug!(

src/librustc/infer/type_variable.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,28 @@ pub struct TypeVariableTable<'tcx> {
3737
sub_relations: ut::UnificationTable<ut::InPlace<ty::TyVid>>,
3838
}
3939

40+
#[derive(Copy, Clone, Debug)]
41+
pub struct TypeVariableOrigin {
42+
pub kind: TypeVariableOriginKind,
43+
pub span: Span,
44+
}
45+
4046
/// Reasons to create a type inference variable
4147
#[derive(Copy, Clone, Debug)]
42-
pub enum TypeVariableOrigin {
43-
MiscVariable(Span),
44-
NormalizeProjectionType(Span),
45-
TypeInference(Span),
46-
TypeParameterDefinition(Span, InternedString),
47-
48-
/// one of the upvars or closure kind parameters in a `ClosureSubsts`
49-
/// (before it has been determined)
50-
ClosureSynthetic(Span),
51-
SubstitutionPlaceholder(Span),
52-
AutoDeref(Span),
53-
AdjustmentType(Span),
54-
DivergingFn(Span),
55-
LatticeVariable(Span),
48+
pub enum TypeVariableOriginKind {
49+
MiscVariable,
50+
NormalizeProjectionType,
51+
TypeInference,
52+
TypeParameterDefinition(InternedString),
53+
54+
/// One of the upvars or closure kind parameters in a `ClosureSubsts`
55+
/// (before it has been determined).
56+
ClosureSynthetic,
57+
SubstitutionPlaceholder,
58+
AutoDeref,
59+
AdjustmentType,
60+
DivergingFn,
61+
LatticeVariable,
5662
}
5763

5864
struct TypeVariableData {

src/librustc/traits/error_reporting.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::hir;
2121
use crate::hir::Node;
2222
use crate::hir::def_id::DefId;
2323
use crate::infer::{self, InferCtxt};
24-
use crate::infer::type_variable::TypeVariableOrigin;
24+
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2525
use crate::session::DiagnosticMessageId;
2626
use crate::ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
2727
use crate::ty::GenericParamDefKind;
@@ -1464,7 +1464,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14641464
let infcx = self.infcx;
14651465
self.var_map.entry(ty).or_insert_with(||
14661466
infcx.next_ty_var(
1467-
TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, name)))
1467+
TypeVariableOrigin {
1468+
kind: TypeVariableOriginKind::TypeParameterDefinition(name),
1469+
span: DUMMY_SP,
1470+
}
1471+
)
1472+
)
14681473
} else {
14691474
ty.super_fold_with(self)
14701475
}

src/librustc/traits/project.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::util;
1414

1515
use crate::hir::def_id::DefId;
1616
use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
17-
use crate::infer::type_variable::TypeVariableOrigin;
17+
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1818
use crate::mir::interpret::{GlobalId, ConstValue};
1919
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
2020
use rustc_macros::HashStable;
@@ -475,7 +475,11 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
475475
let tcx = selcx.infcx().tcx;
476476
let def_id = projection_ty.item_def_id;
477477
let ty_var = selcx.infcx().next_ty_var(
478-
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
478+
TypeVariableOrigin {
479+
kind: TypeVariableOriginKind::NormalizeProjectionType,
480+
span: tcx.def_span(def_id),
481+
},
482+
);
479483
let projection = ty::Binder::dummy(ty::ProjectionPredicate {
480484
projection_ty,
481485
ty: ty_var
@@ -810,7 +814,11 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
810814
let tcx = selcx.infcx().tcx;
811815
let def_id = projection_ty.item_def_id;
812816
let new_value = selcx.infcx().next_ty_var(
813-
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
817+
TypeVariableOrigin {
818+
kind: TypeVariableOriginKind::NormalizeProjectionType,
819+
span: tcx.def_span(def_id),
820+
},
821+
);
814822
Normalized {
815823
value: new_value,
816824
obligations: vec![trait_obligation]

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc::hir::def_id::DefId;
2626
use rustc::infer::canonical::QueryRegionConstraint;
2727
use rustc::infer::outlives::env::RegionBoundPairs;
2828
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
29-
use rustc::infer::type_variable::TypeVariableOrigin;
29+
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3030
use rustc::mir::interpret::{InterpError::BoundsCheck, ConstValue};
3131
use rustc::mir::tcx::PlaceTy;
3232
use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext};
@@ -2209,7 +2209,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
22092209
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.sty {
22102210
let ty_right = right.ty(mir, tcx);
22112211
let common_ty = self.infcx.next_ty_var(
2212-
TypeVariableOrigin::MiscVariable(mir.source_info(location).span),
2212+
TypeVariableOrigin {
2213+
kind: TypeVariableOriginKind::MiscVariable,
2214+
span: mir.source_info(location).span,
2215+
}
22132216
);
22142217
self.sub_types(
22152218
common_ty,

0 commit comments

Comments
 (0)