Skip to content

Commit

Permalink
Rename ExplicitSelfCategory's variants and stop re-exporting them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Dec 28, 2015
1 parent 0e9f6ec commit b2c3703
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/librustc/middle/traits/object_safety.rs
Expand Up @@ -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 => {
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/ty/mod.rs
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/util/ppaux.rs
Expand Up @@ -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>",
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -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]))
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -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]);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/dump_csv.rs
Expand Up @@ -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);
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -1815,7 +1815,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)
};

Expand Down Expand Up @@ -1846,9 +1846,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 =
Expand All @@ -1862,7 +1862,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);
Expand All @@ -1878,12 +1878,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
// }
// ```
//
Expand All @@ -1894,7 +1894,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);
Expand All @@ -1908,12 +1908,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,
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/compare_method.rs
Expand Up @@ -55,17 +55,17 @@ 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",
trait_m.name,
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",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/mod.rs
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/method/probe.rs
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/wfcheck.rs
Expand Up @@ -398,15 +398,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,
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -1306,27 +1306,27 @@ 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))
}
_ => unreachable!(),
}
}
ty::ByBoxExplicitSelfCategory => {
ty::ExplicitSelfCategory::ByBox => {
SelfExplicit(self.fty.sig.0.inputs[0].clean(cx))
}
ty::StaticExplicitSelfCategory => unreachable!(),
ty::ExplicitSelfCategory::Static => unreachable!(),
};
(s, sig)
}
Expand Down

0 comments on commit b2c3703

Please sign in to comment.