Auto merge of #30585 - Ms2ger:ExplicitSelfCategory, r=brson

This commit is contained in:
bors 2015-12-31 01:12:38 +00:00
commit 5892852168
12 changed files with 59 additions and 60 deletions

View File

@ -254,13 +254,13 @@ fn virtual_call_violation_for_method<'tcx>(tcx: &ty::ctxt<'tcx>,
// autorefs) to `&self`. For now, we only accept `self`, `&self`
// and `Box<Self>`.
match method.explicit_self {
ty::StaticExplicitSelfCategory => {
ty::ExplicitSelfCategory::Static => {
return Some(MethodViolationCode::StaticMethod);
}
ty::ByValueExplicitSelfCategory |
ty::ByReferenceExplicitSelfCategory(..) |
ty::ByBoxExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByValue |
ty::ExplicitSelfCategory::ByReference(..) |
ty::ExplicitSelfCategory::ByBox => {
}
}

View File

@ -12,7 +12,6 @@ pub use self::ImplOrTraitItemId::*;
pub use self::ClosureKind::*;
pub use self::Variance::*;
pub use self::DtorKind::*;
pub use self::ExplicitSelfCategory::*;
pub use self::ImplOrTraitItemContainer::*;
pub use self::BorrowKind::*;
pub use self::ImplOrTraitItem::*;
@ -2733,10 +2732,10 @@ impl<'tcx> ctxt<'tcx> {
/// The category of explicit self.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum ExplicitSelfCategory {
StaticExplicitSelfCategory,
ByValueExplicitSelfCategory,
ByReferenceExplicitSelfCategory(Region, hir::Mutability),
ByBoxExplicitSelfCategory,
Static,
ByValue,
ByReference(Region, hir::Mutability),
ByBox,
}
/// A free variable referred to in a function.

View File

@ -919,13 +919,13 @@ impl fmt::Display for ty::InferTy {
impl fmt::Display for ty::ExplicitSelfCategory {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
ty::StaticExplicitSelfCategory => "static",
ty::ByValueExplicitSelfCategory => "self",
ty::ByReferenceExplicitSelfCategory(_, hir::MutMutable) => {
ty::ExplicitSelfCategory::Static => "static",
ty::ExplicitSelfCategory::ByValue => "self",
ty::ExplicitSelfCategory::ByReference(_, hir::MutMutable) => {
"&mut self"
}
ty::ByReferenceExplicitSelfCategory(_, hir::MutImmutable) => "&self",
ty::ByBoxExplicitSelfCategory => "Box<self>",
ty::ExplicitSelfCategory::ByReference(_, hir::MutImmutable) => "&self",
ty::ExplicitSelfCategory::ByBox => "Box<self>",
})
}
}

View File

@ -884,12 +884,12 @@ fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
let explicit_self_kind = string.as_bytes()[0];
match explicit_self_kind as char {
's' => ty::StaticExplicitSelfCategory,
'v' => ty::ByValueExplicitSelfCategory,
'~' => ty::ByBoxExplicitSelfCategory,
's' => ty::ExplicitSelfCategory::Static,
'v' => ty::ExplicitSelfCategory::ByValue,
'~' => ty::ExplicitSelfCategory::ByBox,
// FIXME(#4846) expl. region
'&' => {
ty::ByReferenceExplicitSelfCategory(
ty::ExplicitSelfCategory::ByReference(
ty::ReEmpty,
get_mutability(string.as_bytes()[1]))
}
@ -923,7 +923,7 @@ pub fn is_static_method(cdata: Cmd, id: DefIndex) -> bool {
let doc = cdata.lookup_item(id);
match item_sort(doc) {
Some('r') | Some('p') => {
get_explicit_self(doc) == ty::StaticExplicitSelfCategory
get_explicit_self(doc) == ty::ExplicitSelfCategory::Static
}
_ => false
}

View File

@ -498,16 +498,16 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
// Encode the base self type.
match *explicit_self {
ty::StaticExplicitSelfCategory => {
ty::ExplicitSelfCategory::Static => {
rbml_w.wr_tagged_bytes(tag, &['s' as u8]);
}
ty::ByValueExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByValue => {
rbml_w.wr_tagged_bytes(tag, &['v' as u8]);
}
ty::ByBoxExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByBox => {
rbml_w.wr_tagged_bytes(tag, &['~' as u8]);
}
ty::ByReferenceExplicitSelfCategory(_, m) => {
ty::ExplicitSelfCategory::ByReference(_, m) => {
// FIXME(#4846) encode custom lifetime
let ch = encode_mutability(m);
rbml_w.wr_tagged_bytes(tag, &['&' as u8, ch]);
@ -675,7 +675,7 @@ fn encode_method_ty_fields<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
encode_visibility(rbml_w, method_ty.vis);
encode_explicit_self(rbml_w, &method_ty.explicit_self);
match method_ty.explicit_self {
ty::StaticExplicitSelfCategory => {
ty::ExplicitSelfCategory::Static => {
encode_family(rbml_w, STATIC_METHOD_FAMILY);
}
_ => encode_family(rbml_w, METHOD_FAMILY)
@ -1340,7 +1340,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
path.clone().chain(Some(elem)));
match method_ty.explicit_self {
ty::StaticExplicitSelfCategory => {
ty::ExplicitSelfCategory::Static => {
encode_family(rbml_w,
STATIC_METHOD_FAMILY);
}
@ -1353,7 +1353,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
ecx.local_id(method_def_id));
is_nonstatic_method = method_ty.explicit_self !=
ty::StaticExplicitSelfCategory;
ty::ExplicitSelfCategory::Static;
}
ty::TypeTraitItem(associated_type) => {
encode_name(rbml_w, associated_type.name);

View File

@ -682,7 +682,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
def::DefMethod(did) => {
let ti = self.tcx.impl_or_trait_item(did);
if let ty::MethodTraitItem(m) = ti {
if m.explicit_self == ty::StaticExplicitSelfCategory {
if m.explicit_self == ty::ExplicitSelfCategory::Static {
self.write_sub_path_trait_truncated(path);
}
}

View File

@ -1819,7 +1819,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
// reference) in the arguments, then any anonymous regions in the output
// have that lifetime.
let implied_output_region = match explicit_self_category {
Some(ty::ByReferenceExplicitSelfCategory(region, _)) => Ok(region),
Some(ty::ExplicitSelfCategory::ByReference(region, _)) => Ok(region),
_ => find_implied_output_region(this.tcx(), &arg_tys, arg_pats)
};
@ -1850,9 +1850,9 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
{
let self_ty = self_info.untransformed_self_ty;
return match self_info.explicit_self.node {
hir::SelfStatic => (None, Some(ty::StaticExplicitSelfCategory)),
hir::SelfStatic => (None, Some(ty::ExplicitSelfCategory::Static)),
hir::SelfValue(_) => {
(Some(self_ty), Some(ty::ByValueExplicitSelfCategory))
(Some(self_ty), Some(ty::ExplicitSelfCategory::ByValue))
}
hir::SelfRegion(ref lifetime, mutability, _) => {
let region =
@ -1866,7 +1866,7 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
ty: self_ty,
mutbl: mutability
})),
Some(ty::ByReferenceExplicitSelfCategory(region, mutability)))
Some(ty::ExplicitSelfCategory::ByReference(region, mutability)))
}
hir::SelfExplicit(ref ast_type, _) => {
let explicit_type = ast_ty_to_ty(this, rscope, &**ast_type);
@ -1882,12 +1882,12 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
// ```
// impl Foo for &T {
// // Legal declarations:
// fn method1(self: &&T); // ByReferenceExplicitSelfCategory
// fn method2(self: &T); // ByValueExplicitSelfCategory
// fn method3(self: Box<&T>); // ByBoxExplicitSelfCategory
// fn method1(self: &&T); // ExplicitSelfCategory::ByReference
// fn method2(self: &T); // ExplicitSelfCategory::ByValue
// fn method3(self: Box<&T>); // ExplicitSelfCategory::ByBox
//
// // Invalid cases will be caught later by `check_method_self_type`:
// fn method_err1(self: &mut T); // ByReferenceExplicitSelfCategory
// fn method_err1(self: &mut T); // ExplicitSelfCategory::ByReference
// }
// ```
//
@ -1898,7 +1898,7 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
// call it by-ref, by-box as appropriate. For method1, for
// example, the impl type has one modifier, but the method
// type has two, so we end up with
// ByReferenceExplicitSelfCategory.
// ExplicitSelfCategory::ByReference.
let impl_modifiers = count_modifiers(self_info.untransformed_self_ty);
let method_modifiers = count_modifiers(explicit_type);
@ -1912,12 +1912,12 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
method_modifiers);
let category = if impl_modifiers >= method_modifiers {
ty::ByValueExplicitSelfCategory
ty::ExplicitSelfCategory::ByValue
} else {
match explicit_type.sty {
ty::TyRef(r, mt) => ty::ByReferenceExplicitSelfCategory(*r, mt.mutbl),
ty::TyBox(_) => ty::ByBoxExplicitSelfCategory,
_ => ty::ByValueExplicitSelfCategory,
ty::TyRef(r, mt) => ty::ExplicitSelfCategory::ByReference(*r, mt.mutbl),
ty::TyBox(_) => ty::ExplicitSelfCategory::ByBox,
_ => ty::ExplicitSelfCategory::ByValue,
}
};

View File

@ -55,9 +55,9 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
// inscrutable, particularly for cases where one method has no
// self.
match (&trait_m.explicit_self, &impl_m.explicit_self) {
(&ty::StaticExplicitSelfCategory,
&ty::StaticExplicitSelfCategory) => {}
(&ty::StaticExplicitSelfCategory, _) => {
(&ty::ExplicitSelfCategory::Static,
&ty::ExplicitSelfCategory::Static) => {}
(&ty::ExplicitSelfCategory::Static, _) => {
span_err!(tcx.sess, impl_m_span, E0185,
"method `{}` has a `{}` declaration in the impl, \
but not in the trait",
@ -65,7 +65,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
impl_m.explicit_self);
return;
}
(_, &ty::StaticExplicitSelfCategory) => {
(_, &ty::ExplicitSelfCategory::Static) => {
span_err!(tcx.sess, impl_m_span, E0186,
"method `{}` has a `{}` declaration in the trait, \
but not in the impl",

View File

@ -274,13 +274,13 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
method_ty.explicit_self);
match method_ty.explicit_self {
ty::ByValueExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByValue => {
// Trait method is fn(self), no transformation needed.
assert!(!unsize);
fcx.write_autoderef_adjustment(self_expr.id, autoderefs);
}
ty::ByReferenceExplicitSelfCategory(..) => {
ty::ExplicitSelfCategory::ByReference(..) => {
// Trait method is fn(&self) or fn(&mut self), need an
// autoref. Pull the region etc out of the type of first argument.
match transformed_self_ty.sty {

View File

@ -1144,10 +1144,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
match *item {
ty::ImplOrTraitItem::MethodTraitItem(ref method) =>
match method.explicit_self {
ty::StaticExplicitSelfCategory => self.mode == Mode::Path,
ty::ByValueExplicitSelfCategory |
ty::ByReferenceExplicitSelfCategory(..) |
ty::ByBoxExplicitSelfCategory => true,
ty::ExplicitSelfCategory::Static => self.mode == Mode::Path,
ty::ExplicitSelfCategory::ByValue |
ty::ExplicitSelfCategory::ByReference(..) |
ty::ExplicitSelfCategory::ByBox => true,
},
ty::ImplOrTraitItem::ConstTraitItem(..) => self.mode == Mode::Path,
_ => false,

View File

@ -399,15 +399,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
method.name, method.explicit_self, self_ty, sig);
let rcvr_ty = match method.explicit_self {
ty::StaticExplicitSelfCategory => return,
ty::ByValueExplicitSelfCategory => self_ty,
ty::ByReferenceExplicitSelfCategory(region, mutability) => {
ty::ExplicitSelfCategory::Static => return,
ty::ExplicitSelfCategory::ByValue => self_ty,
ty::ExplicitSelfCategory::ByReference(region, mutability) => {
fcx.tcx().mk_ref(fcx.tcx().mk_region(region), ty::TypeAndMut {
ty: self_ty,
mutbl: mutability
})
}
ty::ByBoxExplicitSelfCategory => fcx.tcx().mk_box(self_ty)
ty::ExplicitSelfCategory::ByBox => fcx.tcx().mk_box(self_ty)
};
let rcvr_ty = fcx.instantiate_type_scheme(span, free_substs, &rcvr_ty);
let rcvr_ty = fcx.tcx().liberate_late_bound_regions(free_id_outlive,

View File

@ -1306,16 +1306,16 @@ impl Clean<Item> for hir::ImplItem {
impl<'tcx> Clean<Item> for ty::Method<'tcx> {
fn clean(&self, cx: &DocContext) -> Item {
let (self_, sig) = match self.explicit_self {
ty::StaticExplicitSelfCategory => (hir::SelfStatic.clean(cx),
self.fty.sig.clone()),
ty::ExplicitSelfCategory::Static => (hir::SelfStatic.clean(cx),
self.fty.sig.clone()),
s => {
let sig = ty::Binder(ty::FnSig {
inputs: self.fty.sig.0.inputs[1..].to_vec(),
..self.fty.sig.0.clone()
});
let s = match s {
ty::ByValueExplicitSelfCategory => SelfValue,
ty::ByReferenceExplicitSelfCategory(..) => {
ty::ExplicitSelfCategory::ByValue => SelfValue,
ty::ExplicitSelfCategory::ByReference(..) => {
match self.fty.sig.0.inputs[0].sty {
ty::TyRef(r, mt) => {
SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx))
@ -1323,10 +1323,10 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
_ => unreachable!(),
}
}
ty::ByBoxExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByBox => {
SelfExplicit(self.fty.sig.0.inputs[0].clean(cx))
}
ty::StaticExplicitSelfCategory => unreachable!(),
ty::ExplicitSelfCategory::Static => unreachable!(),
};
(s, sig)
}