提交 b680b12e 编写于 作者: N Niko Matsakis 提交者: Sean Griffin

kill supporting code from type-variable defaults

This was all unused anyway.
上级 047a8d01
......@@ -424,7 +424,7 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
}
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);
......
......@@ -695,22 +695,6 @@ pub fn type_is_unconstrained_numeric(&'a self, ty: Ty) -> UnconstrainedNumeric {
}
}
/// 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 @@ pub fn region_outlives_predicate(&self,
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 @@ pub fn type_var_for_def(&self,
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 @@ pub fn report_mismatched_types(&self,
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,
......
......@@ -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 @@ pub fn new() -> 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 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'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 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'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 @@ pub fn origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
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 @@ pub fn types_escaping_snapshot(&mut self, s: &Snapshot) -> Vec<Ty<'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 @@ pub fn unsolved_variables(&mut self) -> Vec<ty::TyVid> {
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;
}
}
......@@ -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 @@ fn report_maybe_different(f: &mut fmt::Formatter,
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 @@ pub fn note_and_explain_type_err(self,
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");
......
......@@ -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 @@ fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lif
}
}
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 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
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 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
}
}
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 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
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 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
},
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 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册