Skip to content

Commit 0fd7221

Browse files
committed
Make rustc check
1 parent 42872bb commit 0fd7221

File tree

17 files changed

+87
-32
lines changed

17 files changed

+87
-32
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionVid {
149149
}
150150
}
151151

152-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::ConstVid {
152+
impl<'gcx, 'tcx> HashStable<StableHashingContext<'gcx>> for ty::ConstVid<'tcx> {
153153
#[inline]
154154
fn hash_stable<W: StableHasherResult>(&self,
155155
hcx: &mut StableHashingContext<'gcx>,

src/librustc/infer/canonical/query_result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
434434
opt_values[index] = Some(*original_value);
435435
}
436436
}
437-
UnpackedKind::Const(_) => {
438-
if let &ConstValue(InferConst::Canonical(index)) = result_value {
437+
UnpackedKind::Const(result_value) => {
438+
if let ConstValue::Infer(InferConst::Canonical(index)) = result_value.val {
439439
opt_values[index] = Some(*original_value);
440440
}
441441
}

src/librustc/infer/combine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
153153
}
154154

155155

156-
(ConstValue::Infer(InferConst::Var(vid)), v) => {
157-
self.unify_const_variable(a_is_expected, vid, v)
156+
(ConstValue::Infer(InferConst::Var(vid)), _) => {
157+
self.unify_const_variable(a_is_expected, vid, b)
158158
}
159159

160-
(v, ConstValue::Infer(InferConst::Var(vid))) => {
161-
self.unify_const_variable(!a_is_expected, vid, v)
160+
(_, ConstValue::Infer(InferConst::Var(vid))) => {
161+
self.unify_const_variable(!a_is_expected, vid, a)
162162
}
163163

164164
_ => {
@@ -169,8 +169,8 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
169169

170170
fn unify_const_variable(&self,
171171
vid_is_expected: bool,
172-
vid: ty::ConstVid,
173-
val: &'tcx ty::Const<'tcx>)
172+
vid: ty::ConstVid<'tcx>,
173+
val: &'tcx Const<'tcx>)
174174
-> RelateResult<'tcx, &'tcx Const<'tcx>>
175175
{
176176
self.const_unification_table

src/librustc/infer/equate.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use super::combine::{CombineFields, RelationDir, const_unification_error};
12-
use super::{Subtype};
12+
use super::{Subtype, replace_const_if_possible};
1313

1414
use hir::def_id::DefId;
1515

@@ -117,8 +117,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
117117
if a == b { return Ok(a); }
118118

119119
let infcx = self.fields.infcx;
120-
let a = infcx.const_unification_table.borrow_mut().replace_if_possible(a);
121-
let b = infcx.const_unification_table.borrow_mut().replace_if_possible(b);
120+
let a = replace_const_if_possible(infcx.const_unification_table.borrow_mut(), a);
121+
let b = replace_const_if_possible(infcx.const_unification_table.borrow_mut(), b);
122122
match (a.val, b.val) {
123123
(ConstValue::Infer(InferConst::Var(a_vid)),
124124
ConstValue::Infer(InferConst::Var(b_vid))) => {
@@ -130,11 +130,11 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
130130
Ok(a)
131131
}
132132

133-
(ConstValue::Infer(InferConst::Var(a_vid)), _) => {
133+
(ConstValue::Infer(InferConst::Var(_)), _) => {
134134
Ok(a)
135135
}
136136

137-
(_, ConstValue::Infer(InferConst::Var(b_vid))) => {
137+
(_, ConstValue::Infer(InferConst::Var(_))) => {
138138
Ok(a)
139139
}
140140

@@ -153,3 +153,5 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
153153
self.fields.higher_ranked_sub(b, a, self.a_is_expected)
154154
}
155155
}
156+
157+

src/librustc/infer/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use middle::region;
2323
use middle::lang_items;
2424
use ty::subst::{Kind, Substs};
2525
use ty::{TyVid, IntVid, FloatVid, ConstVid};
26-
use ty::{self, Ty, TyCtxt, GenericParamDefKind};
26+
use ty::{self, Ty, TyCtxt, GenericParamDefKind, InferConst};
2727
use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
2828
use ty::fold::TypeFoldable;
2929
use ty::relate::RelateResult;
@@ -38,6 +38,7 @@ use syntax_pos::{self, Span};
3838
use syntax_pos::symbol::InternedString;
3939
use util::nodemap::FxHashMap;
4040
use arena::SyncDroplessArena;
41+
use mir::interpret::ConstValue;
4142

4243
use self::combine::CombineFields;
4344
use self::higher_ranked::HrMatchResult;
@@ -101,7 +102,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
101102
pub type_variables: RefCell<type_variable::TypeVariableTable<'tcx>>,
102103

103104
// Map from const parameter variable to the kind of const it represents
104-
const_unification_table: RefCell<ut::UnificationTable<ut::InPlace<ty::ConstVid>>>,
105+
const_unification_table: RefCell<ut::UnificationTable<ut::InPlace<ty::ConstVid<'tcx>>>>,
105106

106107
// Map from integral variable to the kind of integer it represents
107108
int_unification_table: RefCell<ut::UnificationTable<ut::InPlace<ty::IntVid>>>,
@@ -530,7 +531,7 @@ impl<'tcx> InferOk<'tcx, ()> {
530531
pub struct CombinedSnapshot<'a, 'tcx:'a> {
531532
projection_cache_snapshot: traits::ProjectionCacheSnapshot,
532533
type_snapshot: type_variable::Snapshot<'tcx>,
533-
const_snapshot: ut::Snapshot<ut::InPlace<ty::ConstVid>>,
534+
const_snapshot: ut::Snapshot<ut::InPlace<ty::ConstVid<'tcx>>>,
534535
int_snapshot: ut::Snapshot<ut::InPlace<ty::IntVid>>,
535536
float_snapshot: ut::Snapshot<ut::InPlace<ty::FloatVid>>,
536537
region_constraints_snapshot: RegionSnapshot,
@@ -910,7 +911,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
910911
self.tcx.mk_const_var(self.next_const_var_id(origin), ty)
911912
}
912913

913-
pub fn next_const_var_id(&self) -> ConstVid {
914+
pub fn next_const_var_id(&self, _origin: ConstVariableOrigin) -> ConstVid<'tcx> {
915+
// TODO(const_generics): integrate _origin
914916
self.const_unification_table
915917
.borrow_mut()
916918
.new_key(None)
@@ -1567,3 +1569,18 @@ impl<'tcx> fmt::Debug for RegionObligation<'tcx> {
15671569
self.sup_type)
15681570
}
15691571
}
1572+
1573+
pub fn replace_const_if_possible<'tcx>(
1574+
mut table: RefMut<ut::UnificationTable<ut::InPlace<ty::ConstVid<'tcx>>>>,
1575+
c: &'tcx ty::Const<'tcx>,
1576+
) -> &'tcx ty::Const<'tcx> {
1577+
match c.val {
1578+
ConstValue::Infer(InferConst::Var(vid)) => {
1579+
match table.probe_value(vid) {
1580+
Some(c) => c,
1581+
None => c,
1582+
}
1583+
}
1584+
_ => c,
1585+
}
1586+
}

src/librustc/infer/sub.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::SubregionOrigin;
1211
use super::combine::{CombineFields, RelationDir, const_unification_error};
12+
use super::{SubregionOrigin, replace_const_if_possible};
1313

1414
use traits::Obligation;
1515
use ty::{self, Ty, TyCtxt, InferConst};
@@ -151,8 +151,8 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
151151
if a == b { return Ok(a); }
152152

153153
let infcx = self.fields.infcx;
154-
let a = infcx.const_unification_table.borrow_mut().replace_if_possible(a);
155-
let b = infcx.const_unification_table.borrow_mut().replace_if_possible(b);
154+
let a = replace_const_if_possible(infcx.const_unification_table.borrow_mut(), a);
155+
let b = replace_const_if_possible(infcx.const_unification_table.borrow_mut(), b);
156156

157157
// Consts can only be equal or unequal to each other: there's no subtyping
158158
// relation, so we're just going to perform equating here instead.

src/librustc/infer/unify_key.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use ty::{self, FloatVarValue, IntVarValue, Ty, TyCtxt, Const};
1212
use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue};
13+
use std::marker::PhantomData;
1314

1415
pub trait ToType {
1516
fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
@@ -18,7 +19,7 @@ pub trait ToType {
1819
impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
1920
type Value = Option<&'tcx Const<'tcx>>;
2021
fn index(&self) -> u32 { self.index }
21-
fn from_index(i: u32) -> ty::ConstVid { ty::ConstVid { index: i } }
22+
fn from_index(i: u32) -> ty::ConstVid<'tcx> { ty::ConstVid { index: i, phantom: PhantomData } }
2223
fn tag() -> &'static str { "ConstVid" }
2324
}
2425

src/librustc/mir/interpret/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub enum ConstValue<'tcx> {
1717
/// A const generic parameter.
1818
Param(ty::ParamConst),
1919
/// Infer the value of the const.
20-
Infer(ty::InferConst),
20+
Infer(ty::InferConst<'tcx>),
2121
/// Used only for types with layout::abi::Scalar ABI and ZSTs
2222
///
2323
/// Not using the enum `Value` to encode that this must not be `Undef`

src/librustc/ty/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use ty::query;
5151
use ty::steal::Steal;
5252
use ty::BindingMode;
5353
use ty::CanonicalTy;
54+
use ty::fold::TypeFoldable;
5455
use util::nodemap::{DefIdSet, ItemLocalMap};
5556
use util::nodemap::{FxHashMap, FxHashSet};
5657
use rustc_data_structures::accumulate_vec::AccumulateVec;
@@ -2523,7 +2524,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25232524
self.mk_infer(TyVar(v))
25242525
}
25252526

2526-
pub fn mk_const_var(self, v: ConstVid, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
2527+
pub fn mk_const_var(self, v: ConstVid<'tcx>, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
25272528
self.mk_const(ty::Const {
25282529
val: ConstValue::Infer(InferConst::Var(v)),
25292530
ty,

src/librustc/ty/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
177177
OldStyleLUB(ref err) => {
178178
write!(f, "{}", err)
179179
}
180+
ConstError(..) => {
181+
unreachable!() // TODO(const_generics)
182+
}
180183
}
181184
}
182185
}

0 commit comments

Comments
 (0)