From b2c370370e066ca622b05629ed6fd2806b7ba653 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 28 Dec 2015 12:52:43 +0100 Subject: [PATCH] Rename ExplicitSelfCategory's variants and stop re-exporting them. --- src/librustc/middle/traits/object_safety.rs | 8 +++---- src/librustc/middle/ty/mod.rs | 9 ++++--- src/librustc/util/ppaux.rs | 10 ++++---- src/librustc_metadata/decoder.rs | 10 ++++---- src/librustc_metadata/encoder.rs | 14 +++++------ src/librustc_trans/save/dump_csv.rs | 2 +- src/librustc_typeck/astconv.rs | 26 ++++++++++----------- src/librustc_typeck/check/compare_method.rs | 8 +++---- src/librustc_typeck/check/method/mod.rs | 4 ++-- src/librustc_typeck/check/method/probe.rs | 8 +++---- src/librustc_typeck/check/wfcheck.rs | 8 +++---- src/librustdoc/clean/mod.rs | 12 +++++----- 12 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/librustc/middle/traits/object_safety.rs b/src/librustc/middle/traits/object_safety.rs index bd60d0a21225..c8e34165b902 100644 --- a/src/librustc/middle/traits/object_safety.rs +++ b/src/librustc/middle/traits/object_safety.rs @@ -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`. 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 => { } } diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index 50c9a1a31f22..5daa9bcd0d1a 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -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. diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 0b362be215df..11d3068f065b 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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", + ty::ExplicitSelfCategory::ByReference(_, hir::MutImmutable) => "&self", + ty::ExplicitSelfCategory::ByBox => "Box", }) } } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 8126970759e6..29fe9bc759dd 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -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 } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index cd70172e8fa2..f1c5d47df888 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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); diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 9c6b54e13796..c34013a7bbbb 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -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); } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 95d85964044d..4790c7392db1 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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) }; @@ -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 = @@ -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); @@ -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 // } // ``` // @@ -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); @@ -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, } }; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index d28a673f748c..554424a36b19 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -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", diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index e0ad51b4ea1b..a961268c6c49 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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 { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index ed819d46041e..3bf24aba6246 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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, diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 230422b7044c..e6bebaf7f75c 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 675eef637b10..d2a5fd457d2f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1306,16 +1306,16 @@ impl Clean for hir::ImplItem { impl<'tcx> Clean 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 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) }