Skip to content

Commit 5892852

Browse files
committed
Auto merge of #30585 - Ms2ger:ExplicitSelfCategory, r=brson
2 parents 2370d46 + b2c3703 commit 5892852

File tree

12 files changed

+59
-60
lines changed

12 files changed

+59
-60
lines changed

src/librustc/middle/traits/object_safety.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ fn virtual_call_violation_for_method<'tcx>(tcx: &ty::ctxt<'tcx>,
254254
// autorefs) to `&self`. For now, we only accept `self`, `&self`
255255
// and `Box<Self>`.
256256
match method.explicit_self {
257-
ty::StaticExplicitSelfCategory => {
257+
ty::ExplicitSelfCategory::Static => {
258258
return Some(MethodViolationCode::StaticMethod);
259259
}
260260

261-
ty::ByValueExplicitSelfCategory |
262-
ty::ByReferenceExplicitSelfCategory(..) |
263-
ty::ByBoxExplicitSelfCategory => {
261+
ty::ExplicitSelfCategory::ByValue |
262+
ty::ExplicitSelfCategory::ByReference(..) |
263+
ty::ExplicitSelfCategory::ByBox => {
264264
}
265265
}
266266

src/librustc/middle/ty/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use self::ImplOrTraitItemId::*;
1212
pub use self::ClosureKind::*;
1313
pub use self::Variance::*;
1414
pub use self::DtorKind::*;
15-
pub use self::ExplicitSelfCategory::*;
1615
pub use self::ImplOrTraitItemContainer::*;
1716
pub use self::BorrowKind::*;
1817
pub use self::ImplOrTraitItem::*;
@@ -2733,10 +2732,10 @@ impl<'tcx> ctxt<'tcx> {
27332732
/// The category of explicit self.
27342733
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
27352734
pub enum ExplicitSelfCategory {
2736-
StaticExplicitSelfCategory,
2737-
ByValueExplicitSelfCategory,
2738-
ByReferenceExplicitSelfCategory(Region, hir::Mutability),
2739-
ByBoxExplicitSelfCategory,
2735+
Static,
2736+
ByValue,
2737+
ByReference(Region, hir::Mutability),
2738+
ByBox,
27402739
}
27412740

27422741
/// A free variable referred to in a function.

src/librustc/util/ppaux.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,13 +919,13 @@ impl fmt::Display for ty::InferTy {
919919
impl fmt::Display for ty::ExplicitSelfCategory {
920920
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
921921
f.write_str(match *self {
922-
ty::StaticExplicitSelfCategory => "static",
923-
ty::ByValueExplicitSelfCategory => "self",
924-
ty::ByReferenceExplicitSelfCategory(_, hir::MutMutable) => {
922+
ty::ExplicitSelfCategory::Static => "static",
923+
ty::ExplicitSelfCategory::ByValue => "self",
924+
ty::ExplicitSelfCategory::ByReference(_, hir::MutMutable) => {
925925
"&mut self"
926926
}
927-
ty::ByReferenceExplicitSelfCategory(_, hir::MutImmutable) => "&self",
928-
ty::ByBoxExplicitSelfCategory => "Box<self>",
927+
ty::ExplicitSelfCategory::ByReference(_, hir::MutImmutable) => "&self",
928+
ty::ExplicitSelfCategory::ByBox => "Box<self>",
929929
})
930930
}
931931
}

src/librustc_metadata/decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,12 +884,12 @@ fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
884884

885885
let explicit_self_kind = string.as_bytes()[0];
886886
match explicit_self_kind as char {
887-
's' => ty::StaticExplicitSelfCategory,
888-
'v' => ty::ByValueExplicitSelfCategory,
889-
'~' => ty::ByBoxExplicitSelfCategory,
887+
's' => ty::ExplicitSelfCategory::Static,
888+
'v' => ty::ExplicitSelfCategory::ByValue,
889+
'~' => ty::ExplicitSelfCategory::ByBox,
890890
// FIXME(#4846) expl. region
891891
'&' => {
892-
ty::ByReferenceExplicitSelfCategory(
892+
ty::ExplicitSelfCategory::ByReference(
893893
ty::ReEmpty,
894894
get_mutability(string.as_bytes()[1]))
895895
}
@@ -923,7 +923,7 @@ pub fn is_static_method(cdata: Cmd, id: DefIndex) -> bool {
923923
let doc = cdata.lookup_item(id);
924924
match item_sort(doc) {
925925
Some('r') | Some('p') => {
926-
get_explicit_self(doc) == ty::StaticExplicitSelfCategory
926+
get_explicit_self(doc) == ty::ExplicitSelfCategory::Static
927927
}
928928
_ => false
929929
}

src/librustc_metadata/encoder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,16 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
498498

499499
// Encode the base self type.
500500
match *explicit_self {
501-
ty::StaticExplicitSelfCategory => {
501+
ty::ExplicitSelfCategory::Static => {
502502
rbml_w.wr_tagged_bytes(tag, &['s' as u8]);
503503
}
504-
ty::ByValueExplicitSelfCategory => {
504+
ty::ExplicitSelfCategory::ByValue => {
505505
rbml_w.wr_tagged_bytes(tag, &['v' as u8]);
506506
}
507-
ty::ByBoxExplicitSelfCategory => {
507+
ty::ExplicitSelfCategory::ByBox => {
508508
rbml_w.wr_tagged_bytes(tag, &['~' as u8]);
509509
}
510-
ty::ByReferenceExplicitSelfCategory(_, m) => {
510+
ty::ExplicitSelfCategory::ByReference(_, m) => {
511511
// FIXME(#4846) encode custom lifetime
512512
let ch = encode_mutability(m);
513513
rbml_w.wr_tagged_bytes(tag, &['&' as u8, ch]);
@@ -675,7 +675,7 @@ fn encode_method_ty_fields<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
675675
encode_visibility(rbml_w, method_ty.vis);
676676
encode_explicit_self(rbml_w, &method_ty.explicit_self);
677677
match method_ty.explicit_self {
678-
ty::StaticExplicitSelfCategory => {
678+
ty::ExplicitSelfCategory::Static => {
679679
encode_family(rbml_w, STATIC_METHOD_FAMILY);
680680
}
681681
_ => encode_family(rbml_w, METHOD_FAMILY)
@@ -1340,7 +1340,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
13401340
path.clone().chain(Some(elem)));
13411341

13421342
match method_ty.explicit_self {
1343-
ty::StaticExplicitSelfCategory => {
1343+
ty::ExplicitSelfCategory::Static => {
13441344
encode_family(rbml_w,
13451345
STATIC_METHOD_FAMILY);
13461346
}
@@ -1353,7 +1353,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
13531353
ecx.local_id(method_def_id));
13541354

13551355
is_nonstatic_method = method_ty.explicit_self !=
1356-
ty::StaticExplicitSelfCategory;
1356+
ty::ExplicitSelfCategory::Static;
13571357
}
13581358
ty::TypeTraitItem(associated_type) => {
13591359
encode_name(rbml_w, associated_type.name);

src/librustc_trans/save/dump_csv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
682682
def::DefMethod(did) => {
683683
let ti = self.tcx.impl_or_trait_item(did);
684684
if let ty::MethodTraitItem(m) = ti {
685-
if m.explicit_self == ty::StaticExplicitSelfCategory {
685+
if m.explicit_self == ty::ExplicitSelfCategory::Static {
686686
self.write_sub_path_trait_truncated(path);
687687
}
688688
}

src/librustc_typeck/astconv.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
18191819
// reference) in the arguments, then any anonymous regions in the output
18201820
// have that lifetime.
18211821
let implied_output_region = match explicit_self_category {
1822-
Some(ty::ByReferenceExplicitSelfCategory(region, _)) => Ok(region),
1822+
Some(ty::ExplicitSelfCategory::ByReference(region, _)) => Ok(region),
18231823
_ => find_implied_output_region(this.tcx(), &arg_tys, arg_pats)
18241824
};
18251825

@@ -1850,9 +1850,9 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
18501850
{
18511851
let self_ty = self_info.untransformed_self_ty;
18521852
return match self_info.explicit_self.node {
1853-
hir::SelfStatic => (None, Some(ty::StaticExplicitSelfCategory)),
1853+
hir::SelfStatic => (None, Some(ty::ExplicitSelfCategory::Static)),
18541854
hir::SelfValue(_) => {
1855-
(Some(self_ty), Some(ty::ByValueExplicitSelfCategory))
1855+
(Some(self_ty), Some(ty::ExplicitSelfCategory::ByValue))
18561856
}
18571857
hir::SelfRegion(ref lifetime, mutability, _) => {
18581858
let region =
@@ -1866,7 +1866,7 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
18661866
ty: self_ty,
18671867
mutbl: mutability
18681868
})),
1869-
Some(ty::ByReferenceExplicitSelfCategory(region, mutability)))
1869+
Some(ty::ExplicitSelfCategory::ByReference(region, mutability)))
18701870
}
18711871
hir::SelfExplicit(ref ast_type, _) => {
18721872
let explicit_type = ast_ty_to_ty(this, rscope, &**ast_type);
@@ -1882,12 +1882,12 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
18821882
// ```
18831883
// impl Foo for &T {
18841884
// // Legal declarations:
1885-
// fn method1(self: &&T); // ByReferenceExplicitSelfCategory
1886-
// fn method2(self: &T); // ByValueExplicitSelfCategory
1887-
// fn method3(self: Box<&T>); // ByBoxExplicitSelfCategory
1885+
// fn method1(self: &&T); // ExplicitSelfCategory::ByReference
1886+
// fn method2(self: &T); // ExplicitSelfCategory::ByValue
1887+
// fn method3(self: Box<&T>); // ExplicitSelfCategory::ByBox
18881888
//
18891889
// // Invalid cases will be caught later by `check_method_self_type`:
1890-
// fn method_err1(self: &mut T); // ByReferenceExplicitSelfCategory
1890+
// fn method_err1(self: &mut T); // ExplicitSelfCategory::ByReference
18911891
// }
18921892
// ```
18931893
//
@@ -1898,7 +1898,7 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
18981898
// call it by-ref, by-box as appropriate. For method1, for
18991899
// example, the impl type has one modifier, but the method
19001900
// type has two, so we end up with
1901-
// ByReferenceExplicitSelfCategory.
1901+
// ExplicitSelfCategory::ByReference.
19021902

19031903
let impl_modifiers = count_modifiers(self_info.untransformed_self_ty);
19041904
let method_modifiers = count_modifiers(explicit_type);
@@ -1912,12 +1912,12 @@ fn determine_self_type<'a, 'tcx>(this: &AstConv<'tcx>,
19121912
method_modifiers);
19131913

19141914
let category = if impl_modifiers >= method_modifiers {
1915-
ty::ByValueExplicitSelfCategory
1915+
ty::ExplicitSelfCategory::ByValue
19161916
} else {
19171917
match explicit_type.sty {
1918-
ty::TyRef(r, mt) => ty::ByReferenceExplicitSelfCategory(*r, mt.mutbl),
1919-
ty::TyBox(_) => ty::ByBoxExplicitSelfCategory,
1920-
_ => ty::ByValueExplicitSelfCategory,
1918+
ty::TyRef(r, mt) => ty::ExplicitSelfCategory::ByReference(*r, mt.mutbl),
1919+
ty::TyBox(_) => ty::ExplicitSelfCategory::ByBox,
1920+
_ => ty::ExplicitSelfCategory::ByValue,
19211921
}
19221922
};
19231923

src/librustc_typeck/check/compare_method.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
5555
// inscrutable, particularly for cases where one method has no
5656
// self.
5757
match (&trait_m.explicit_self, &impl_m.explicit_self) {
58-
(&ty::StaticExplicitSelfCategory,
59-
&ty::StaticExplicitSelfCategory) => {}
60-
(&ty::StaticExplicitSelfCategory, _) => {
58+
(&ty::ExplicitSelfCategory::Static,
59+
&ty::ExplicitSelfCategory::Static) => {}
60+
(&ty::ExplicitSelfCategory::Static, _) => {
6161
span_err!(tcx.sess, impl_m_span, E0185,
6262
"method `{}` has a `{}` declaration in the impl, \
6363
but not in the trait",
6464
trait_m.name,
6565
impl_m.explicit_self);
6666
return;
6767
}
68-
(_, &ty::StaticExplicitSelfCategory) => {
68+
(_, &ty::ExplicitSelfCategory::Static) => {
6969
span_err!(tcx.sess, impl_m_span, E0186,
7070
"method `{}` has a `{}` declaration in the trait, \
7171
but not in the impl",

src/librustc_typeck/check/method/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
274274
method_ty.explicit_self);
275275

276276
match method_ty.explicit_self {
277-
ty::ByValueExplicitSelfCategory => {
277+
ty::ExplicitSelfCategory::ByValue => {
278278
// Trait method is fn(self), no transformation needed.
279279
assert!(!unsize);
280280
fcx.write_autoderef_adjustment(self_expr.id, autoderefs);
281281
}
282282

283-
ty::ByReferenceExplicitSelfCategory(..) => {
283+
ty::ExplicitSelfCategory::ByReference(..) => {
284284
// Trait method is fn(&self) or fn(&mut self), need an
285285
// autoref. Pull the region etc out of the type of first argument.
286286
match transformed_self_ty.sty {

src/librustc_typeck/check/method/probe.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
11441144
match *item {
11451145
ty::ImplOrTraitItem::MethodTraitItem(ref method) =>
11461146
match method.explicit_self {
1147-
ty::StaticExplicitSelfCategory => self.mode == Mode::Path,
1148-
ty::ByValueExplicitSelfCategory |
1149-
ty::ByReferenceExplicitSelfCategory(..) |
1150-
ty::ByBoxExplicitSelfCategory => true,
1147+
ty::ExplicitSelfCategory::Static => self.mode == Mode::Path,
1148+
ty::ExplicitSelfCategory::ByValue |
1149+
ty::ExplicitSelfCategory::ByReference(..) |
1150+
ty::ExplicitSelfCategory::ByBox => true,
11511151
},
11521152
ty::ImplOrTraitItem::ConstTraitItem(..) => self.mode == Mode::Path,
11531153
_ => false,

src/librustc_typeck/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
399399
method.name, method.explicit_self, self_ty, sig);
400400

401401
let rcvr_ty = match method.explicit_self {
402-
ty::StaticExplicitSelfCategory => return,
403-
ty::ByValueExplicitSelfCategory => self_ty,
404-
ty::ByReferenceExplicitSelfCategory(region, mutability) => {
402+
ty::ExplicitSelfCategory::Static => return,
403+
ty::ExplicitSelfCategory::ByValue => self_ty,
404+
ty::ExplicitSelfCategory::ByReference(region, mutability) => {
405405
fcx.tcx().mk_ref(fcx.tcx().mk_region(region), ty::TypeAndMut {
406406
ty: self_ty,
407407
mutbl: mutability
408408
})
409409
}
410-
ty::ByBoxExplicitSelfCategory => fcx.tcx().mk_box(self_ty)
410+
ty::ExplicitSelfCategory::ByBox => fcx.tcx().mk_box(self_ty)
411411
};
412412
let rcvr_ty = fcx.instantiate_type_scheme(span, free_substs, &rcvr_ty);
413413
let rcvr_ty = fcx.tcx().liberate_late_bound_regions(free_id_outlive,

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,27 +1306,27 @@ impl Clean<Item> for hir::ImplItem {
13061306
impl<'tcx> Clean<Item> for ty::Method<'tcx> {
13071307
fn clean(&self, cx: &DocContext) -> Item {
13081308
let (self_, sig) = match self.explicit_self {
1309-
ty::StaticExplicitSelfCategory => (hir::SelfStatic.clean(cx),
1310-
self.fty.sig.clone()),
1309+
ty::ExplicitSelfCategory::Static => (hir::SelfStatic.clean(cx),
1310+
self.fty.sig.clone()),
13111311
s => {
13121312
let sig = ty::Binder(ty::FnSig {
13131313
inputs: self.fty.sig.0.inputs[1..].to_vec(),
13141314
..self.fty.sig.0.clone()
13151315
});
13161316
let s = match s {
1317-
ty::ByValueExplicitSelfCategory => SelfValue,
1318-
ty::ByReferenceExplicitSelfCategory(..) => {
1317+
ty::ExplicitSelfCategory::ByValue => SelfValue,
1318+
ty::ExplicitSelfCategory::ByReference(..) => {
13191319
match self.fty.sig.0.inputs[0].sty {
13201320
ty::TyRef(r, mt) => {
13211321
SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx))
13221322
}
13231323
_ => unreachable!(),
13241324
}
13251325
}
1326-
ty::ByBoxExplicitSelfCategory => {
1326+
ty::ExplicitSelfCategory::ByBox => {
13271327
SelfExplicit(self.fty.sig.0.inputs[0].clean(cx))
13281328
}
1329-
ty::StaticExplicitSelfCategory => unreachable!(),
1329+
ty::ExplicitSelfCategory::Static => unreachable!(),
13301330
};
13311331
(s, sig)
13321332
}

0 commit comments

Comments
 (0)