// 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 => {
}
}
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::*;
/// 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.
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>",
})
}
}
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]))
}
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
}
// 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]);
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)
path.clone().chain(Some(elem)));
match method_ty.explicit_self {
- ty::StaticExplicitSelfCategory => {
+ ty::ExplicitSelfCategory::Static => {
encode_family(rbml_w,
STATIC_METHOD_FAMILY);
}
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);
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);
}
}
// 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)
};
{
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 =
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);
// ```
// 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
// }
// ```
//
// 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);
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,
}
};
// 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",
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",
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 {
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,
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,
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))
_ => unreachable!(),
}
}
- ty::ByBoxExplicitSelfCategory => {
+ ty::ExplicitSelfCategory::ByBox => {
SelfExplicit(self.fty.sig.0.inputs[0].clean(cx))
}
- ty::StaticExplicitSelfCategory => unreachable!(),
+ ty::ExplicitSelfCategory::Static => unreachable!(),
};
(s, sig)
}