diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-07-16 04:55:48 -0400 |
|---|---|---|
| committer | Sean Griffin <sean@seantheprogrammer.com> | 2018-03-01 08:04:26 -0700 |
| commit | b680b12e949097602dd6d39009fee8c95d86a261 (patch) | |
| tree | 46593a912516f5280aa78e26b34e7f9763c18eee | |
| parent | 047a8d016111c5a12beba2202c61df5b897eea45 (diff) | |
| download | rust-b680b12e949097602dd6d39009fee8c95d86a261.tar.gz rust-b680b12e949097602dd6d39009fee8c95d86a261.zip | |
kill supporting code from type-variable defaults
This was all unused anyway.
| -rw-r--r-- | src/librustc/infer/combine.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/mod.rs | 43 | ||||
| -rw-r--r-- | src/librustc/infer/type_variable.rs | 50 | ||||
| -rw-r--r-- | src/librustc/ty/error.rs | 45 | ||||
| -rw-r--r-- | src/librustc/ty/structural_impls.rs | 29 |
5 files changed, 18 insertions, 151 deletions
diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index f7bc092a3d7..bd175c510fb 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -424,7 +424,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, ' } let origin = variables.origin(vid); - let new_var_id = variables.new_var(false, origin, None); + let new_var_id = variables.new_var(false, origin); let u = self.tcx().mk_var(new_var_id); debug!("generalize: replacing original vid={:?} with new={:?}", vid, u); diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 349a2af5aa9..42928457925 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -695,22 +695,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } - /// Returns a type variable's default fallback if any exists. A default - /// must be attached to the variable when created, if it is created - /// without a default, this will return None. - /// - /// This code does not apply to integral or floating point variables, - /// only to use declared defaults. - /// - /// See `new_ty_var_with_default` to create a type variable with a default. - /// See `type_variable::Default` for details about what a default entails. - pub fn default(&self, ty: Ty<'tcx>) -> Option<type_variable::Default<'tcx>> { - match ty.sty { - ty::TyInfer(ty::TyVar(vid)) => self.type_variables.borrow().default(vid), - _ => None - } - } - pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> { let mut variables = Vec::new(); @@ -1029,7 +1013,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid { self.type_variables .borrow_mut() - .new_var(diverging, origin, None) + .new_var(diverging, origin) } pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> { @@ -1098,8 +1082,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let ty_var_id = self.type_variables .borrow_mut() .new_var(false, - TypeVariableOrigin::TypeParameterDefinition(span, def.name), - None); + TypeVariableOrigin::TypeParameterDefinition(span, def.name)); self.tcx.mk_var(ty_var_id) } @@ -1389,28 +1372,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.report_and_explain_type_error(trace, &err) } - pub fn report_conflicting_default_types(&self, - span: Span, - body_id: ast::NodeId, - expected: type_variable::Default<'tcx>, - actual: type_variable::Default<'tcx>) { - let trace = TypeTrace { - cause: ObligationCause::misc(span, body_id), - values: Types(ExpectedFound { - expected: expected.ty, - found: actual.ty - }) - }; - - self.report_and_explain_type_error( - trace, - &TypeError::TyParamDefaultMismatch(ExpectedFound { - expected, - found: actual - })) - .emit(); - } - pub fn replace_late_bound_regions_with_fresh_var<T>( &self, span: Span, diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 36afb8b5367..e07cc92ec21 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -9,7 +9,6 @@ // except according to those terms. use self::TypeVariableValue::*; -use hir::def_id::{DefId}; use syntax::ast; use syntax_pos::Span; use ty::{self, Ty}; @@ -82,20 +81,7 @@ enum TypeVariableValue<'tcx> { Known { value: Ty<'tcx> }, - Bounded { - default: Option<Default<'tcx>> - } -} - -// We will use this to store the required information to recapitulate what happened when -// an error occurs. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub struct Default<'tcx> { - pub ty: Ty<'tcx>, - /// The span where the default was incurred - pub origin_span: Span, - /// The definition that the default originates from - pub def_id: DefId + Unknown, } pub struct Snapshot { @@ -104,9 +90,8 @@ pub struct Snapshot { sub_snapshot: ut::Snapshot<ty::TyVid>, } -struct Instantiate<'tcx> { +struct Instantiate { vid: ty::TyVid, - default: Option<Default<'tcx>>, } struct Delegate<'tcx>(PhantomData<&'tcx ()>); @@ -120,13 +105,6 @@ impl<'tcx> TypeVariableTable<'tcx> { } } - pub fn default(&self, vid: ty::TyVid) -> Option<Default<'tcx>> { - match &self.values.get(vid.index as usize).value { - &Known { .. } => None, - &Bounded { default, .. } => default, - } - } - pub fn var_diverges<'a>(&'a self, vid: ty::TyVid) -> bool { self.values.get(vid.index as usize).diverging } @@ -167,8 +145,8 @@ impl<'tcx> TypeVariableTable<'tcx> { }; match old_value { - TypeVariableValue::Bounded { default } => { - self.values.record(Instantiate { vid: vid, default: default }); + TypeVariableValue::Unknown => { + self.values.record(Instantiate { vid: vid }); } TypeVariableValue::Known { value: old_ty } => { bug!("instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}", @@ -179,13 +157,13 @@ impl<'tcx> TypeVariableTable<'tcx> { pub fn new_var(&mut self, diverging: bool, - origin: TypeVariableOrigin, - default: Option<Default<'tcx>>,) -> ty::TyVid { + origin: TypeVariableOrigin) + -> ty::TyVid { debug!("new_var(diverging={:?}, origin={:?})", diverging, origin); self.eq_relations.new_key(()); self.sub_relations.new_key(()); let index = self.values.push(TypeVariableData { - value: Bounded { default }, + value: Unknown, origin, diverging, }); @@ -237,7 +215,7 @@ impl<'tcx> TypeVariableTable<'tcx> { pub fn probe_root(&mut self, vid: ty::TyVid) -> Option<Ty<'tcx>> { debug_assert!(self.root_var(vid) == vid); match self.values.get(vid.index as usize).value { - Bounded { .. } => None, + Unknown => None, Known { value } => Some(value) } } @@ -338,7 +316,7 @@ impl<'tcx> TypeVariableTable<'tcx> { // quick check to see if this variable was // created since the snapshot started or not. let escaping_type = match self.values.get(vid.index as usize).value { - Bounded { .. } => bug!(), + Unknown => bug!(), Known { value } => value, }; escaping_types.push(escaping_type); @@ -369,12 +347,10 @@ impl<'tcx> TypeVariableTable<'tcx> { impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> { type Value = TypeVariableData<'tcx>; - type Undo = Instantiate<'tcx>; + type Undo = Instantiate; - fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate<'tcx>) { - let Instantiate { vid, default } = action; - values[vid.index as usize].value = Bounded { - default, - }; + fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate) { + let Instantiate { vid } = action; + values[vid.index as usize].value = Unknown; } } diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 583612f9590..be89aeebdea 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -9,9 +9,8 @@ // except according to those terms. use hir::def_id::DefId; -use infer::type_variable; use middle::const_val::ConstVal; -use ty::{self, BoundRegion, DefIdTree, Region, Ty, TyCtxt}; +use ty::{self, BoundRegion, Region, Ty, TyCtxt}; use std::fmt; use syntax::abi; @@ -56,7 +55,6 @@ pub enum TypeError<'tcx> { CyclicTy(Ty<'tcx>), ProjectionMismatched(ExpectedFound<DefId>), ProjectionBoundsLength(ExpectedFound<usize>), - TyParamDefaultMismatch(ExpectedFound<type_variable::Default<'tcx>>), ExistentialMismatch(ExpectedFound<&'tcx ty::Slice<ty::ExistentialPredicate<'tcx>>>), OldStyleLUB(Box<TypeError<'tcx>>), @@ -167,11 +165,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.expected, values.found) }, - TyParamDefaultMismatch(ref values) => { - write!(f, "conflicting type parameter defaults `{}` and `{}`", - values.expected.ty, - values.found.ty) - } ExistentialMismatch(ref values) => { report_maybe_different(f, format!("trait `{}`", values.expected), format!("trait `{}`", values.found)) @@ -265,42 +258,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { db.help("consider boxing your closure and/or using it as a trait object"); } }, - TyParamDefaultMismatch(values) => { - let expected = values.expected; - let found = values.found; - db.span_note(sp, &format!("conflicting type parameter defaults `{}` and `{}`", - expected.ty, - found.ty)); - - match self.hir.span_if_local(expected.def_id) { - Some(span) => { - db.span_note(span, "a default was defined here..."); - } - None => { - let item_def_id = self.parent(expected.def_id).unwrap(); - db.note(&format!("a default is defined on `{}`", - self.item_path_str(item_def_id))); - } - } - - db.span_note( - expected.origin_span, - "...that was applied to an unconstrained type variable here"); - - match self.hir.span_if_local(found.def_id) { - Some(span) => { - db.span_note(span, "a second default was defined here..."); - } - None => { - let item_def_id = self.parent(found.def_id).unwrap(); - db.note(&format!("a second default is defined on `{}`", - self.item_path_str(item_def_id))); - } - } - - db.span_note(found.origin_span, - "...that also applies to the same type variable here"); - } OldStyleLUB(err) => { db.note("this was previously accepted by the compiler but has been phased out"); db.note("for more information, see https://github.com/rust-lang/rust/issues/45852"); diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 3a1ad8db9c2..6147b52844f 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -13,7 +13,6 @@ //! hand, though we've recently added some macros (e.g., //! `BraceStructLiftImpl!`) to help with the tedium. -use infer::type_variable; use middle::const_val::{self, ConstVal, ConstAggregate, ConstEvalErr}; use ty::{self, Lift, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; @@ -548,13 +547,6 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> { } } -BraceStructLiftImpl! { - impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> { - type Lifted = type_variable::Default<'tcx>; - ty, origin_span, def_id - } -} - impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { type Lifted = ty::error::TypeError<'tcx>; 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> { ProjectionBoundsLength(x) => ProjectionBoundsLength(x), Sorts(ref x) => return tcx.lift(x).map(Sorts), - TyParamDefaultMismatch(ref x) => { - return tcx.lift(x).map(TyParamDefaultMismatch) - } - ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch), OldStyleLUB(ref x) => return tcx.lift(x).map(OldStyleLUB), + ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch) }) } } @@ -1199,20 +1188,6 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFoun } } -impl<'tcx> TypeFoldable<'tcx> for type_variable::Default<'tcx> { - fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { - type_variable::Default { - ty: self.ty.fold_with(folder), - origin_span: self.origin_span, - def_id: self.def_id - } - } - - fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { - self.ty.visit_with(visitor) - } -} - impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { self.iter().map(|x| x.fold_with(folder)).collect() @@ -1252,7 +1227,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> { ProjectionMismatched(x) => ProjectionMismatched(x), ProjectionBoundsLength(x) => ProjectionBoundsLength(x), Sorts(x) => Sorts(x.fold_with(folder)), - TyParamDefaultMismatch(ref x) => TyParamDefaultMismatch(x.fold_with(folder)), ExistentialMismatch(x) => ExistentialMismatch(x.fold_with(folder)), OldStyleLUB(ref x) => OldStyleLUB(x.fold_with(folder)), } @@ -1273,7 +1247,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> { }, Sorts(x) => x.visit_with(visitor), OldStyleLUB(ref x) => x.visit_with(visitor), - TyParamDefaultMismatch(ref x) => x.visit_with(visitor), ExistentialMismatch(x) => x.visit_with(visitor), CyclicTy(t) => t.visit_with(visitor), Mismatch | |
