Skip to content

Commit b680b12

Browse files
nikomatsakissgrif
authored andcommitted
kill supporting code from type-variable defaults
This was all unused anyway.
1 parent 047a8d0 commit b680b12

File tree

5 files changed

+18
-151
lines changed

5 files changed

+18
-151
lines changed

src/librustc/infer/combine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
424424
}
425425

426426
let origin = variables.origin(vid);
427-
let new_var_id = variables.new_var(false, origin, None);
427+
let new_var_id = variables.new_var(false, origin);
428428
let u = self.tcx().mk_var(new_var_id);
429429
debug!("generalize: replacing original vid={:?} with new={:?}",
430430
vid, u);

src/librustc/infer/mod.rs

+2-41
Original file line numberDiff line numberDiff line change
@@ -695,22 +695,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
695695
}
696696
}
697697

698-
/// Returns a type variable's default fallback if any exists. A default
699-
/// must be attached to the variable when created, if it is created
700-
/// without a default, this will return None.
701-
///
702-
/// This code does not apply to integral or floating point variables,
703-
/// only to use declared defaults.
704-
///
705-
/// See `new_ty_var_with_default` to create a type variable with a default.
706-
/// See `type_variable::Default` for details about what a default entails.
707-
pub fn default(&self, ty: Ty<'tcx>) -> Option<type_variable::Default<'tcx>> {
708-
match ty.sty {
709-
ty::TyInfer(ty::TyVar(vid)) => self.type_variables.borrow().default(vid),
710-
_ => None
711-
}
712-
}
713-
714698
pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> {
715699
let mut variables = Vec::new();
716700

@@ -1029,7 +1013,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10291013
pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid {
10301014
self.type_variables
10311015
.borrow_mut()
1032-
.new_var(diverging, origin, None)
1016+
.new_var(diverging, origin)
10331017
}
10341018

10351019
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
@@ -1098,8 +1082,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10981082
let ty_var_id = self.type_variables
10991083
.borrow_mut()
11001084
.new_var(false,
1101-
TypeVariableOrigin::TypeParameterDefinition(span, def.name),
1102-
None);
1085+
TypeVariableOrigin::TypeParameterDefinition(span, def.name));
11031086

11041087
self.tcx.mk_var(ty_var_id)
11051088
}
@@ -1389,28 +1372,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13891372
self.report_and_explain_type_error(trace, &err)
13901373
}
13911374

1392-
pub fn report_conflicting_default_types(&self,
1393-
span: Span,
1394-
body_id: ast::NodeId,
1395-
expected: type_variable::Default<'tcx>,
1396-
actual: type_variable::Default<'tcx>) {
1397-
let trace = TypeTrace {
1398-
cause: ObligationCause::misc(span, body_id),
1399-
values: Types(ExpectedFound {
1400-
expected: expected.ty,
1401-
found: actual.ty
1402-
})
1403-
};
1404-
1405-
self.report_and_explain_type_error(
1406-
trace,
1407-
&TypeError::TyParamDefaultMismatch(ExpectedFound {
1408-
expected,
1409-
found: actual
1410-
}))
1411-
.emit();
1412-
}
1413-
14141375
pub fn replace_late_bound_regions_with_fresh_var<T>(
14151376
&self,
14161377
span: Span,

src/librustc/infer/type_variable.rs

+13-37
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};
@@ -82,20 +81,7 @@ enum TypeVariableValue<'tcx> {
8281
Known {
8382
value: Ty<'tcx>
8483
},
85-
Bounded {
86-
default: Option<Default<'tcx>>
87-
}
88-
}
89-
90-
// We will use this to store the required information to recapitulate what happened when
91-
// an error occurs.
92-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
93-
pub struct Default<'tcx> {
94-
pub ty: Ty<'tcx>,
95-
/// The span where the default was incurred
96-
pub origin_span: Span,
97-
/// The definition that the default originates from
98-
pub def_id: DefId
84+
Unknown,
9985
}
10086

10187
pub struct Snapshot {
@@ -104,9 +90,8 @@ pub struct Snapshot {
10490
sub_snapshot: ut::Snapshot<ty::TyVid>,
10591
}
10692

107-
struct Instantiate<'tcx> {
93+
struct Instantiate {
10894
vid: ty::TyVid,
109-
default: Option<Default<'tcx>>,
11095
}
11196

11297
struct Delegate<'tcx>(PhantomData<&'tcx ()>);
@@ -120,13 +105,6 @@ impl<'tcx> TypeVariableTable<'tcx> {
120105
}
121106
}
122107

123-
pub fn default(&self, vid: ty::TyVid) -> Option<Default<'tcx>> {
124-
match &self.values.get(vid.index as usize).value {
125-
&Known { .. } => None,
126-
&Bounded { default, .. } => default,
127-
}
128-
}
129-
130108
pub fn var_diverges<'a>(&'a self, vid: ty::TyVid) -> bool {
131109
self.values.get(vid.index as usize).diverging
132110
}
@@ -167,8 +145,8 @@ impl<'tcx> TypeVariableTable<'tcx> {
167145
};
168146

169147
match old_value {
170-
TypeVariableValue::Bounded { default } => {
171-
self.values.record(Instantiate { vid: vid, default: default });
148+
TypeVariableValue::Unknown => {
149+
self.values.record(Instantiate { vid: vid });
172150
}
173151
TypeVariableValue::Known { value: old_ty } => {
174152
bug!("instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}",
@@ -179,13 +157,13 @@ impl<'tcx> TypeVariableTable<'tcx> {
179157

180158
pub fn new_var(&mut self,
181159
diverging: bool,
182-
origin: TypeVariableOrigin,
183-
default: Option<Default<'tcx>>,) -> ty::TyVid {
160+
origin: TypeVariableOrigin)
161+
-> ty::TyVid {
184162
debug!("new_var(diverging={:?}, origin={:?})", diverging, origin);
185163
self.eq_relations.new_key(());
186164
self.sub_relations.new_key(());
187165
let index = self.values.push(TypeVariableData {
188-
value: Bounded { default },
166+
value: Unknown,
189167
origin,
190168
diverging,
191169
});
@@ -237,7 +215,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
237215
pub fn probe_root(&mut self, vid: ty::TyVid) -> Option<Ty<'tcx>> {
238216
debug_assert!(self.root_var(vid) == vid);
239217
match self.values.get(vid.index as usize).value {
240-
Bounded { .. } => None,
218+
Unknown => None,
241219
Known { value } => Some(value)
242220
}
243221
}
@@ -338,7 +316,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
338316
// quick check to see if this variable was
339317
// created since the snapshot started or not.
340318
let escaping_type = match self.values.get(vid.index as usize).value {
341-
Bounded { .. } => bug!(),
319+
Unknown => bug!(),
342320
Known { value } => value,
343321
};
344322
escaping_types.push(escaping_type);
@@ -369,12 +347,10 @@ impl<'tcx> TypeVariableTable<'tcx> {
369347

370348
impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
371349
type Value = TypeVariableData<'tcx>;
372-
type Undo = Instantiate<'tcx>;
350+
type Undo = Instantiate;
373351

374-
fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate<'tcx>) {
375-
let Instantiate { vid, default } = action;
376-
values[vid.index as usize].value = Bounded {
377-
default,
378-
};
352+
fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate) {
353+
let Instantiate { vid } = action;
354+
values[vid.index as usize].value = Unknown;
379355
}
380356
}

src/librustc/ty/error.rs

+1-44
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;
@@ -56,7 +55,6 @@ pub enum TypeError<'tcx> {
5655
CyclicTy(Ty<'tcx>),
5756
ProjectionMismatched(ExpectedFound<DefId>),
5857
ProjectionBoundsLength(ExpectedFound<usize>),
59-
TyParamDefaultMismatch(ExpectedFound<type_variable::Default<'tcx>>),
6058
ExistentialMismatch(ExpectedFound<&'tcx ty::Slice<ty::ExistentialPredicate<'tcx>>>),
6159

6260
OldStyleLUB(Box<TypeError<'tcx>>),
@@ -167,11 +165,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
167165
values.expected,
168166
values.found)
169167
},
170-
TyParamDefaultMismatch(ref values) => {
171-
write!(f, "conflicting type parameter defaults `{}` and `{}`",
172-
values.expected.ty,
173-
values.found.ty)
174-
}
175168
ExistentialMismatch(ref values) => {
176169
report_maybe_different(f, format!("trait `{}`", values.expected),
177170
format!("trait `{}`", values.found))
@@ -265,42 +258,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
265258
db.help("consider boxing your closure and/or using it as a trait object");
266259
}
267260
},
268-
TyParamDefaultMismatch(values) => {
269-
let expected = values.expected;
270-
let found = values.found;
271-
db.span_note(sp, &format!("conflicting type parameter defaults `{}` and `{}`",
272-
expected.ty,
273-
found.ty));
274-
275-
match self.hir.span_if_local(expected.def_id) {
276-
Some(span) => {
277-
db.span_note(span, "a default was defined here...");
278-
}
279-
None => {
280-
let item_def_id = self.parent(expected.def_id).unwrap();
281-
db.note(&format!("a default is defined on `{}`",
282-
self.item_path_str(item_def_id)));
283-
}
284-
}
285-
286-
db.span_note(
287-
expected.origin_span,
288-
"...that was applied to an unconstrained type variable here");
289-
290-
match self.hir.span_if_local(found.def_id) {
291-
Some(span) => {
292-
db.span_note(span, "a second default was defined here...");
293-
}
294-
None => {
295-
let item_def_id = self.parent(found.def_id).unwrap();
296-
db.note(&format!("a second default is defined on `{}`",
297-
self.item_path_str(item_def_id)));
298-
}
299-
}
300-
301-
db.span_note(found.origin_span,
302-
"...that also applies to the same type variable here");
303-
}
304261
OldStyleLUB(err) => {
305262
db.note("this was previously accepted by the compiler but has been phased out");
306263
db.note("for more information, see https://github.com/rust-lang/rust/issues/45852");

src/librustc/ty/structural_impls.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! hand, though we've recently added some macros (e.g.,
1414
//! `BraceStructLiftImpl!`) to help with the tedium.
1515
16-
use infer::type_variable;
1716
use middle::const_val::{self, ConstVal, ConstAggregate, ConstEvalErr};
1817
use ty::{self, Lift, Ty, TyCtxt};
1918
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
@@ -548,13 +547,6 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
548547
}
549548
}
550549

551-
BraceStructLiftImpl! {
552-
impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> {
553-
type Lifted = type_variable::Default<'tcx>;
554-
ty, origin_span, def_id
555-
}
556-
}
557-
558550
impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
559551
type Lifted = ty::error::TypeError<'tcx>;
560552
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@@ -586,11 +578,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
586578
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
587579

588580
Sorts(ref x) => return tcx.lift(x).map(Sorts),
589-
TyParamDefaultMismatch(ref x) => {
590-
return tcx.lift(x).map(TyParamDefaultMismatch)
591-
}
592-
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
593581
OldStyleLUB(ref x) => return tcx.lift(x).map(OldStyleLUB),
582+
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch)
594583
})
595584
}
596585
}
@@ -1199,20 +1188,6 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFoun
11991188
}
12001189
}
12011190

1202-
impl<'tcx> TypeFoldable<'tcx> for type_variable::Default<'tcx> {
1203-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1204-
type_variable::Default {
1205-
ty: self.ty.fold_with(folder),
1206-
origin_span: self.origin_span,
1207-
def_id: self.def_id
1208-
}
1209-
}
1210-
1211-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1212-
self.ty.visit_with(visitor)
1213-
}
1214-
}
1215-
12161191
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
12171192
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
12181193
self.iter().map(|x| x.fold_with(folder)).collect()
@@ -1252,7 +1227,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
12521227
ProjectionMismatched(x) => ProjectionMismatched(x),
12531228
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
12541229
Sorts(x) => Sorts(x.fold_with(folder)),
1255-
TyParamDefaultMismatch(ref x) => TyParamDefaultMismatch(x.fold_with(folder)),
12561230
ExistentialMismatch(x) => ExistentialMismatch(x.fold_with(folder)),
12571231
OldStyleLUB(ref x) => OldStyleLUB(x.fold_with(folder)),
12581232
}
@@ -1273,7 +1247,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
12731247
},
12741248
Sorts(x) => x.visit_with(visitor),
12751249
OldStyleLUB(ref x) => x.visit_with(visitor),
1276-
TyParamDefaultMismatch(ref x) => x.visit_with(visitor),
12771250
ExistentialMismatch(x) => x.visit_with(visitor),
12781251
CyclicTy(t) => t.visit_with(visitor),
12791252
Mismatch |

0 commit comments

Comments
 (0)