Skip to content

Commit 49ea3d4

Browse files
committed
Remove unnecessary accessor function VariantDefData::kind
1 parent 2cdd9f1 commit 49ea3d4

File tree

10 files changed

+21
-31
lines changed

10 files changed

+21
-31
lines changed

src/librustc/mir/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
10631063
Some(tcx.lookup_item_type(variant_def.did).generics)
10641064
})?;
10651065

1066-
match variant_def.kind() {
1066+
match variant_def.kind {
10671067
ty::VariantKind::Unit => Ok(()),
10681068
ty::VariantKind::Tuple => fmt_tuple(fmt, lvs),
10691069
ty::VariantKind::Struct => {

src/librustc/ty/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,14 +1925,6 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
19251925
self.fields.iter()
19261926
}
19271927

1928-
pub fn kind(&self) -> VariantKind {
1929-
self.kind
1930-
}
1931-
1932-
pub fn is_tuple_struct(&self) -> bool {
1933-
self.kind() == VariantKind::Tuple
1934-
}
1935-
19361928
#[inline]
19371929
pub fn find_field_named(&self,
19381930
name: ast::Name)

src/librustc_const_eval/check_match.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
246246
let pat_ty = cx.tcx.pat_ty(p);
247247
if let ty::TyEnum(edef, _) = pat_ty.sty {
248248
if let Def::Local(..) = cx.tcx.expect_def(p.id) {
249-
if edef.variants.iter().any(|variant|
250-
variant.name == name.node && variant.kind() == VariantKind::Unit
251-
) {
249+
if edef.variants.iter().any(|variant| {
250+
variant.name == name.node && variant.kind == VariantKind::Unit
251+
}) {
252252
let ty_path = cx.tcx.item_path_str(edef.did);
253253
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
254254
"pattern binding `{}` is named the same as one \
@@ -563,7 +563,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
563563

564564
ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => {
565565
let v = ctor.variant_for_adt(adt);
566-
match v.kind() {
566+
match v.kind {
567567
VariantKind::Struct => {
568568
let field_pats: hir::HirVec<_> = v.fields.iter()
569569
.zip(pats)

src/librustc_metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub fn get_adt_def<'a, 'tcx>(intr: &IdentInterner,
498498
// this needs to be done *after* the variant is interned,
499499
// to support recursive structures
500500
for variant in &adt.variants {
501-
if variant.kind() == ty::VariantKind::Tuple &&
501+
if variant.kind == ty::VariantKind::Tuple &&
502502
adt.adt_kind() == ty::AdtKind::Enum {
503503
// tuple-like enum variant fields aren't real items - get the types
504504
// from the ctor.

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
217217
fn encode_struct_fields(rbml_w: &mut Encoder,
218218
variant: ty::VariantDef) {
219219
for f in &variant.fields {
220-
if variant.is_tuple_struct() {
220+
if variant.kind == ty::VariantKind::Tuple {
221221
rbml_w.start_tag(tag_item_unnamed_field);
222222
} else {
223223
rbml_w.start_tag(tag_item_field);
@@ -250,7 +250,7 @@ fn encode_enum_variant_info<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
250250
let _task = index.record(vid, rbml_w);
251251
rbml_w.start_tag(tag_items_data_item);
252252
encode_def_id_and_key(ecx, rbml_w, vid);
253-
encode_family(rbml_w, match variant.kind() {
253+
encode_family(rbml_w, match variant.kind {
254254
ty::VariantKind::Struct => 'V',
255255
ty::VariantKind::Tuple => 'v',
256256
ty::VariantKind::Unit => 'w',

src/librustc_trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
901901
}
902902
Def::Variant(enum_did, variant_did) => {
903903
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);
904-
match vinfo.kind() {
904+
match vinfo.kind {
905905
ty::VariantKind::Unit => {
906906
let repr = adt::represent_type(cx, ety);
907907
adt::trans_const(cx, &repr, Disr::from(vinfo.disr_val), &[])

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ struct StructMemberDescriptionFactory<'tcx> {
11091109
impl<'tcx> StructMemberDescriptionFactory<'tcx> {
11101110
fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
11111111
-> Vec<MemberDescription> {
1112-
if let ty::VariantKind::Unit = self.variant.kind() {
1112+
if self.variant.kind == ty::VariantKind::Unit {
11131113
return Vec::new();
11141114
}
11151115

@@ -1126,7 +1126,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
11261126
};
11271127

11281128
self.variant.fields.iter().enumerate().map(|(i, f)| {
1129-
let name = if let ty::VariantKind::Tuple = self.variant.kind() {
1129+
let name = if self.variant.kind == ty::VariantKind::Tuple {
11301130
format!("__{}", i)
11311131
} else {
11321132
f.name.to_string()
@@ -1356,7 +1356,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
13561356
// For the metadata of the wrapper struct, we need to create a
13571357
// MemberDescription of the struct's single field.
13581358
let sole_struct_member_description = MemberDescription {
1359-
name: match non_null_variant.kind() {
1359+
name: match non_null_variant.kind {
13601360
ty::VariantKind::Tuple => "__0".to_string(),
13611361
ty::VariantKind::Struct => {
13621362
non_null_variant.fields[0].name.to_string()
@@ -1524,7 +1524,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
15241524
containing_scope);
15251525

15261526
// Get the argument names from the enum variant info
1527-
let mut arg_names: Vec<_> = match variant.kind() {
1527+
let mut arg_names: Vec<_> = match variant.kind {
15281528
ty::VariantKind::Unit => vec![],
15291529
ty::VariantKind::Tuple => {
15301530
variant.fields

src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,14 +1671,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
16711671
_ => return None
16721672
};
16731673

1674-
let var_kind = variant.kind();
1675-
if var_kind == ty::VariantKind::Struct {
1674+
if variant.kind == ty::VariantKind::Struct ||
1675+
variant.kind == ty::VariantKind::Unit {
16761676
Some((adt, variant))
1677-
} else if var_kind == ty::VariantKind::Unit {
1678-
Some((adt, variant))
1679-
} else {
1680-
None
1681-
}
1677+
} else {
1678+
None
1679+
}
16821680
}
16831681

16841682
pub fn write_nil(&self, node_id: ast::NodeId) {
@@ -2998,7 +2996,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29982996
while let Some((base_t, autoderefs)) = autoderef.next() {
29992997
let field = match base_t.sty {
30002998
ty::TyStruct(base_def, substs) => {
3001-
tuple_like = base_def.struct_variant().is_tuple_struct();
2999+
tuple_like = base_def.struct_variant().kind == ty::VariantKind::Tuple;
30023000
if !tuple_like { continue }
30033001

30043002
debug!("tuple struct named {:?}", base_t);

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
949949
scheme: ty::TypeScheme<'tcx>,
950950
predicates: ty::GenericPredicates<'tcx>) {
951951
let tcx = ccx.tcx;
952-
let ctor_ty = match variant.kind() {
952+
let ctor_ty = match variant.kind {
953953
VariantKind::Unit | VariantKind::Struct => scheme.ty,
954954
VariantKind::Tuple => {
955955
let inputs: Vec<_> =

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ impl Clean<Item> for doctree::Variant {
19041904

19051905
impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
19061906
fn clean(&self, cx: &DocContext) -> Item {
1907-
let kind = match self.kind() {
1907+
let kind = match self.kind {
19081908
ty::VariantKind::Unit => CLikeVariant,
19091909
ty::VariantKind::Tuple => {
19101910
TupleVariant(

0 commit comments

Comments
 (0)