Skip to content

Commit 3251227

Browse files
committed
kill supporting code from type-variable defaults
This was all unused anyway.
1 parent 5c69168 commit 3251227

File tree

5 files changed

+17
-156
lines changed

5 files changed

+17
-156
lines changed

src/librustc/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
410410
}
411411

412412
let origin = variables.origin(vid);
413-
let new_var_id = variables.new_var(false, origin, None);
413+
let new_var_id = variables.new_var(false, origin);
414414
let u = self.tcx().mk_var(new_var_id);
415415
debug!("generalize: replacing original vid={:?} with new={:?}",
416416
vid, u);

src/librustc/infer/mod.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -628,22 +628,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
628628
}
629629
}
630630

631-
/// Returns a type variable's default fallback if any exists. A default
632-
/// must be attached to the variable when created, if it is created
633-
/// without a default, this will return None.
634-
///
635-
/// This code does not apply to integral or floating point variables,
636-
/// only to use declared defaults.
637-
///
638-
/// See `new_ty_var_with_default` to create a type variable with a default.
639-
/// See `type_variable::Default` for details about what a default entails.
640-
pub fn default(&self, ty: Ty<'tcx>) -> Option<type_variable::Default<'tcx>> {
641-
match ty.sty {
642-
ty::TyInfer(ty::TyVar(vid)) => self.type_variables.borrow().default(vid),
643-
_ => None
644-
}
645-
}
646-
647631
pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> {
648632
let mut variables = Vec::new();
649633

@@ -956,7 +940,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
956940
pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid {
957941
self.type_variables
958942
.borrow_mut()
959-
.new_var(diverging, origin, None)
943+
.new_var(diverging, origin)
960944
}
961945

962946
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
@@ -1008,8 +992,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1008992
let ty_var_id = self.type_variables
1009993
.borrow_mut()
1010994
.new_var(false,
1011-
TypeVariableOrigin::TypeParameterDefinition(span, def.name),
1012-
None);
995+
TypeVariableOrigin::TypeParameterDefinition(span, def.name));
1013996

1014997
self.tcx.mk_var(ty_var_id)
1015998
}
@@ -1220,28 +1203,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12201203
self.report_and_explain_type_error(trace, &err)
12211204
}
12221205

1223-
pub fn report_conflicting_default_types(&self,
1224-
span: Span,
1225-
body_id: ast::NodeId,
1226-
expected: type_variable::Default<'tcx>,
1227-
actual: type_variable::Default<'tcx>) {
1228-
let trace = TypeTrace {
1229-
cause: ObligationCause::misc(span, body_id),
1230-
values: Types(ExpectedFound {
1231-
expected: expected.ty,
1232-
found: actual.ty
1233-
})
1234-
};
1235-
1236-
self.report_and_explain_type_error(
1237-
trace,
1238-
&TypeError::TyParamDefaultMismatch(ExpectedFound {
1239-
expected,
1240-
found: actual
1241-
}))
1242-
.emit();
1243-
}
1244-
12451206
pub fn replace_late_bound_regions_with_fresh_var<T>(
12461207
&self,
12471208
span: Span,

src/librustc/infer/type_variable.rs

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

1111
use self::TypeVariableValue::*;
12-
use hir::def_id::{DefId};
1312
use syntax::ast;
1413
use syntax_pos::Span;
1514
use ty::{self, Ty};
@@ -79,20 +78,7 @@ enum TypeVariableValue<'tcx> {
7978
Known {
8079
value: Ty<'tcx>
8180
},
82-
Bounded {
83-
default: Option<Default<'tcx>>
84-
}
85-
}
86-
87-
// We will use this to store the required information to recapitulate what happened when
88-
// an error occurs.
89-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
90-
pub struct Default<'tcx> {
91-
pub ty: Ty<'tcx>,
92-
/// The span where the default was incurred
93-
pub origin_span: Span,
94-
/// The definition that the default originates from
95-
pub def_id: DefId
81+
Unknown,
9682
}
9783

9884
pub struct Snapshot {
@@ -101,9 +87,8 @@ pub struct Snapshot {
10187
sub_snapshot: ut::Snapshot<ty::TyVid>,
10288
}
10389

104-
struct Instantiate<'tcx> {
90+
struct Instantiate {
10591
vid: ty::TyVid,
106-
default: Option<Default<'tcx>>,
10792
}
10893

10994
struct Delegate<'tcx>(PhantomData<&'tcx ()>);
@@ -117,13 +102,6 @@ impl<'tcx> TypeVariableTable<'tcx> {
117102
}
118103
}
119104

120-
pub fn default(&self, vid: ty::TyVid) -> Option<Default<'tcx>> {
121-
match &self.values.get(vid.index as usize).value {
122-
&Known { .. } => None,
123-
&Bounded { default, .. } => default,
124-
}
125-
}
126-
127105
pub fn var_diverges<'a>(&'a self, vid: ty::TyVid) -> bool {
128106
self.values.get(vid.index as usize).diverging
129107
}
@@ -164,8 +142,8 @@ impl<'tcx> TypeVariableTable<'tcx> {
164142
};
165143

166144
match old_value {
167-
TypeVariableValue::Bounded { default } => {
168-
self.values.record(Instantiate { vid: vid, default: default });
145+
TypeVariableValue::Unknown => {
146+
self.values.record(Instantiate { vid: vid });
169147
}
170148
TypeVariableValue::Known { value: old_ty } => {
171149
bug!("instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}",
@@ -176,13 +154,13 @@ impl<'tcx> TypeVariableTable<'tcx> {
176154

177155
pub fn new_var(&mut self,
178156
diverging: bool,
179-
origin: TypeVariableOrigin,
180-
default: Option<Default<'tcx>>,) -> ty::TyVid {
157+
origin: TypeVariableOrigin)
158+
-> ty::TyVid {
181159
debug!("new_var(diverging={:?}, origin={:?})", diverging, origin);
182160
self.eq_relations.new_key(());
183161
self.sub_relations.new_key(());
184162
let index = self.values.push(TypeVariableData {
185-
value: Bounded { default },
163+
value: Unknown,
186164
origin,
187165
diverging,
188166
});
@@ -234,7 +212,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
234212
pub fn probe_root(&mut self, vid: ty::TyVid) -> Option<Ty<'tcx>> {
235213
debug_assert!(self.root_var(vid) == vid);
236214
match self.values.get(vid.index as usize).value {
237-
Bounded { .. } => None,
215+
Unknown => None,
238216
Known { value } => Some(value)
239217
}
240218
}
@@ -335,7 +313,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
335313
// quick check to see if this variable was
336314
// created since the snapshot started or not.
337315
let escaping_type = match self.values.get(vid.index as usize).value {
338-
Bounded { .. } => bug!(),
316+
Unknown => bug!(),
339317
Known { value } => value,
340318
};
341319
escaping_types.push(escaping_type);
@@ -366,12 +344,10 @@ impl<'tcx> TypeVariableTable<'tcx> {
366344

367345
impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
368346
type Value = TypeVariableData<'tcx>;
369-
type Undo = Instantiate<'tcx>;
347+
type Undo = Instantiate;
370348

371-
fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate<'tcx>) {
372-
let Instantiate { vid, default } = action;
373-
values[vid.index as usize].value = Bounded {
374-
default,
375-
};
349+
fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate) {
350+
let Instantiate { vid } = action;
351+
values[vid.index as usize].value = Unknown;
376352
}
377353
}

src/librustc/ty/error.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use infer::type_variable;
1312
use middle::const_val::ConstVal;
14-
use ty::{self, BoundRegion, DefIdTree, Region, Ty, TyCtxt};
13+
use ty::{self, BoundRegion, Region, Ty, TyCtxt};
1514

1615
use std::fmt;
1716
use syntax::abi;
@@ -52,7 +51,6 @@ pub enum TypeError<'tcx> {
5251
CyclicTy,
5352
ProjectionMismatched(ExpectedFound<DefId>),
5453
ProjectionBoundsLength(ExpectedFound<usize>),
55-
TyParamDefaultMismatch(ExpectedFound<type_variable::Default<'tcx>>),
5654
ExistentialMismatch(ExpectedFound<&'tcx ty::Slice<ty::ExistentialPredicate<'tcx>>>),
5755
}
5856

@@ -161,11 +159,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
161159
values.expected,
162160
values.found)
163161
},
164-
TyParamDefaultMismatch(ref values) => {
165-
write!(f, "conflicting type parameter defaults `{}` and `{}`",
166-
values.expected.ty,
167-
values.found.ty)
168-
}
169162
ExistentialMismatch(ref values) => {
170163
report_maybe_different(f, format!("trait `{}`", values.expected),
171164
format!("trait `{}`", values.found))
@@ -257,42 +250,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
257250
"consider boxing your closure and/or using it as a trait object");
258251
}
259252
},
260-
TyParamDefaultMismatch(values) => {
261-
let expected = values.expected;
262-
let found = values.found;
263-
db.span_note(sp, &format!("conflicting type parameter defaults `{}` and `{}`",
264-
expected.ty,
265-
found.ty));
266-
267-
match self.hir.span_if_local(expected.def_id) {
268-
Some(span) => {
269-
db.span_note(span, "a default was defined here...");
270-
}
271-
None => {
272-
let item_def_id = self.parent(expected.def_id).unwrap();
273-
db.note(&format!("a default is defined on `{}`",
274-
self.item_path_str(item_def_id)));
275-
}
276-
}
277-
278-
db.span_note(
279-
expected.origin_span,
280-
"...that was applied to an unconstrained type variable here");
281-
282-
match self.hir.span_if_local(found.def_id) {
283-
Some(span) => {
284-
db.span_note(span, "a second default was defined here...");
285-
}
286-
None => {
287-
let item_def_id = self.parent(found.def_id).unwrap();
288-
db.note(&format!("a second default is defined on `{}`",
289-
self.item_path_str(item_def_id)));
290-
}
291-
}
292-
293-
db.span_note(found.origin_span,
294-
"...that also applies to the same type variable here");
295-
}
296253
_ => {}
297254
}
298255
}

src/librustc/ty/structural_impls.rs

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

11-
use infer::type_variable;
1211
use middle::const_val::{self, ConstVal, ConstAggregate, ConstEvalErr};
1312
use ty::{self, Lift, Ty, TyCtxt};
1413
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
@@ -382,19 +381,6 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
382381
}
383382
}
384383

385-
impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> {
386-
type Lifted = type_variable::Default<'tcx>;
387-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
388-
tcx.lift(&self.ty).map(|ty| {
389-
type_variable::Default {
390-
ty,
391-
origin_span: self.origin_span,
392-
def_id: self.def_id
393-
}
394-
})
395-
}
396-
}
397-
398384
impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
399385
type Lifted = ty::error::TypeError<'tcx>;
400386
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@@ -426,9 +412,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
426412
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
427413

428414
Sorts(ref x) => return tcx.lift(x).map(Sorts),
429-
TyParamDefaultMismatch(ref x) => {
430-
return tcx.lift(x).map(TyParamDefaultMismatch)
431-
}
432415
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch)
433416
})
434417
}
@@ -1131,20 +1114,6 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFoun
11311114
}
11321115
}
11331116

1134-
impl<'tcx> TypeFoldable<'tcx> for type_variable::Default<'tcx> {
1135-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1136-
type_variable::Default {
1137-
ty: self.ty.fold_with(folder),
1138-
origin_span: self.origin_span,
1139-
def_id: self.def_id
1140-
}
1141-
}
1142-
1143-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1144-
self.ty.visit_with(visitor)
1145-
}
1146-
}
1147-
11481117
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
11491118
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
11501119
self.iter().map(|x| x.fold_with(folder)).collect()
@@ -1184,7 +1153,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
11841153
ProjectionMismatched(x) => ProjectionMismatched(x),
11851154
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
11861155
Sorts(x) => Sorts(x.fold_with(folder)),
1187-
TyParamDefaultMismatch(ref x) => TyParamDefaultMismatch(x.fold_with(folder)),
11881156
ExistentialMismatch(x) => ExistentialMismatch(x.fold_with(folder)),
11891157
}
11901158
}
@@ -1203,7 +1171,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
12031171
b.visit_with(visitor)
12041172
},
12051173
Sorts(x) => x.visit_with(visitor),
1206-
TyParamDefaultMismatch(ref x) => x.visit_with(visitor),
12071174
ExistentialMismatch(x) => x.visit_with(visitor),
12081175
Mismatch |
12091176
Mutability |

0 commit comments

Comments
 (0)