Skip to content

Commit dc56a2f

Browse files
committed
rustc: remove fmt::{Debug,Display} from ty::TyKind.
1 parent 4831932 commit dc56a2f

File tree

22 files changed

+73
-71
lines changed

22 files changed

+73
-71
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
786786
// FnMut | copied -> &'env mut | upvar -> &'env mut -> &'up bk
787787
// FnOnce | copied | upvar -> &'up bk
788788

789-
let kind = match self.node_ty(fn_hir_id)?.sty {
789+
let ty = self.node_ty(fn_hir_id)?;
790+
let kind = match ty.sty {
790791
ty::Generator(..) => ty::ClosureKind::FnOnce,
791792
ty::Closure(closure_def_id, closure_substs) => {
792793
match self.infcx {
@@ -803,7 +804,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
803804
.closure_kind(closure_def_id, self.tcx.global_tcx()),
804805
}
805806
}
806-
ref t => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", t),
807+
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),
807808
};
808809

809810
let closure_expr_def_id = self.tcx.hir().local_def_id(fn_node_id);
@@ -1064,7 +1065,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10641065
let bk = ty::BorrowKind::from_mutbl(mutbl);
10651066
BorrowedPtr(bk, r)
10661067
}
1067-
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
1068+
_ => bug!("unexpected type in cat_deref: {:?}", base_cmt.ty)
10681069
};
10691070
let ret = cmt_ {
10701071
hir_id: node.hir_id(),
@@ -1279,11 +1280,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12791280
self.tcx.adt_def(enum_def).variant_with_id(def_id).fields.len())
12801281
}
12811282
Def::StructCtor(_, CtorKind::Fn) | Def::SelfCtor(..) => {
1282-
match self.pat_ty_unadjusted(&pat)?.sty {
1283+
let ty = self.pat_ty_unadjusted(&pat)?;
1284+
match ty.sty {
12831285
ty::Adt(adt_def, _) => {
12841286
(cmt, adt_def.non_enum_variant().fields.len())
12851287
}
1286-
ref ty => {
1288+
_ => {
12871289
span_bug!(pat.span,
12881290
"tuple struct pattern unexpected type {:?}", ty);
12891291
}
@@ -1334,9 +1336,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13341336

13351337
PatKind::Tuple(ref subpats, ddpos) => {
13361338
// (p1, ..., pN)
1337-
let expected_len = match self.pat_ty_unadjusted(&pat)?.sty {
1339+
let ty = self.pat_ty_unadjusted(&pat)?;
1340+
let expected_len = match ty.sty {
13381341
ty::Tuple(ref tys) => tys.len(),
1339-
ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
1342+
_ => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
13401343
};
13411344
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
13421345
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)

src/librustc/traits/error_reporting.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
847847
_ => vec![ArgKind::empty()],
848848
};
849849

850-
let expected = match expected_trait_ref.skip_binder().substs.type_at(1).sty {
850+
let expected_ty = expected_trait_ref.skip_binder().substs.type_at(1);
851+
let expected = match expected_ty.sty {
851852
ty::Tuple(ref tys) => tys.iter()
852853
.map(|t| ArgKind::from_expected_ty(t, Some(span))).collect(),
853-
ref sty => vec![ArgKind::Arg("_".to_owned(), sty.to_string())],
854+
_ => vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())],
854855
};
855856

856857
if found.len() == expected.len() {
@@ -1640,10 +1641,10 @@ impl ArgKind {
16401641
ty::Tuple(ref tys) => ArgKind::Tuple(
16411642
span,
16421643
tys.iter()
1643-
.map(|ty| ("_".to_owned(), ty.sty.to_string()))
1644+
.map(|ty| ("_".to_owned(), ty.to_string()))
16441645
.collect::<Vec<_>>()
16451646
),
1646-
_ => ArgKind::Arg("_".to_owned(), t.sty.to_string()),
1647+
_ => ArgKind::Arg("_".to_owned(), t.to_string()),
16471648
}
16481649
}
16491650
}

src/librustc/ty/relate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,8 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
351351
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
352352
{
353353
let tcx = relation.tcx();
354-
let a_sty = &a.sty;
355-
let b_sty = &b.sty;
356-
debug!("super_relate_tys: a_sty={:?} b_sty={:?}", a_sty, b_sty);
357-
match (a_sty, b_sty) {
354+
debug!("super_relate_tys: a={:?} b={:?}", a, b);
355+
match (&a.sty, &b.sty) {
358356
(&ty::Infer(_), _) |
359357
(_, &ty::Infer(_)) =>
360358
{

src/librustc/ty/sty.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl BoundRegion {
8181

8282
/// N.B., if you change this, you'll probably want to change the corresponding
8383
/// AST structure in `libsyntax/ast.rs` as well.
84-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
84+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
8585
pub enum TyKind<'tcx> {
8686
/// The primitive boolean type. Written as `bool`.
8787
Bool,
@@ -377,9 +377,10 @@ impl<'tcx> ClosureSubsts<'tcx> {
377377
///
378378
/// If you have an inference context, use `infcx.closure_sig()`.
379379
pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> {
380-
match self.closure_sig_ty(def_id, tcx).sty {
380+
let ty = self.closure_sig_ty(def_id, tcx);
381+
match ty.sty {
381382
ty::FnPtr(sig) => sig,
382-
ref t => bug!("closure_sig_ty is not a fn-ptr: {:?}", t),
383+
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty),
383384
}
384385
}
385386
}

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,9 @@ define_print! {
11071107
}
11081108

11091109
define_print! {
1110-
('tcx) ty::TyKind<'tcx>, (self, f, cx) {
1110+
('tcx) ty::TyS<'tcx>, (self, f, cx) {
11111111
display {
1112-
match *self {
1112+
match self.sty {
11131113
Bool => write!(f, "bool"),
11141114
Char => write!(f, "char"),
11151115
Int(t) => write!(f, "{}", t.ty_to_string()),
@@ -1345,16 +1345,8 @@ define_print! {
13451345
}
13461346
}
13471347
}
1348-
}
1349-
}
1350-
1351-
define_print! {
1352-
('tcx) ty::TyS<'tcx>, (self, f, cx) {
1353-
display {
1354-
self.sty.print(f, cx)
1355-
}
13561348
debug {
1357-
self.sty.print_display(f, cx)
1349+
self.print_display(f, cx)
13581350
}
13591351
}
13601352
}

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
481481

482482
},
483483
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
484-
let sty = &arg_tys[0].sty;
485-
match float_type_width(sty) {
484+
match float_type_width(arg_tys[0]) {
486485
Some(_width) =>
487486
match name {
488487
"fadd_fast" => self.fadd_fast(args[0].immediate(), args[1].immediate()),
@@ -496,7 +495,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
496495
span_invalid_monomorphization_error(
497496
tcx.sess, span,
498497
&format!("invalid monomorphization of `{}` intrinsic: \
499-
expected basic float type, found `{}`", name, sty));
498+
expected basic float type, found `{}`", name, arg_tys[0]));
500499
return;
501500
}
502501
}
@@ -1406,8 +1405,8 @@ fn generic_simd_intrinsic(
14061405
require!(false, "expected element type `{}` of second argument `{}` \
14071406
to be a pointer to the element type `{}` of the first \
14081407
argument `{}`, found `{}` != `*_ {}`",
1409-
arg_tys[1].simd_type(tcx).sty, arg_tys[1], in_elem, in_ty,
1410-
arg_tys[1].simd_type(tcx).sty, in_elem);
1408+
arg_tys[1].simd_type(tcx), arg_tys[1], in_elem, in_ty,
1409+
arg_tys[1].simd_type(tcx), in_elem);
14111410
unreachable!();
14121411
}
14131412
};
@@ -1421,7 +1420,7 @@ fn generic_simd_intrinsic(
14211420
_ => {
14221421
require!(false, "expected element type `{}` of third argument `{}` \
14231422
to be a signed integer type",
1424-
arg_tys[2].simd_type(tcx).sty, arg_tys[2]);
1423+
arg_tys[2].simd_type(tcx), arg_tys[2]);
14251424
}
14261425
}
14271426

@@ -1506,8 +1505,8 @@ fn generic_simd_intrinsic(
15061505
require!(false, "expected element type `{}` of second argument `{}` \
15071506
to be a pointer to the element type `{}` of the first \
15081507
argument `{}`, found `{}` != `*mut {}`",
1509-
arg_tys[1].simd_type(tcx).sty, arg_tys[1], in_elem, in_ty,
1510-
arg_tys[1].simd_type(tcx).sty, in_elem);
1508+
arg_tys[1].simd_type(tcx), arg_tys[1], in_elem, in_ty,
1509+
arg_tys[1].simd_type(tcx), in_elem);
15111510
unreachable!();
15121511
}
15131512
};
@@ -1521,7 +1520,7 @@ fn generic_simd_intrinsic(
15211520
_ => {
15221521
require!(false, "expected element type `{}` of third argument `{}` \
15231522
to be a signed integer type",
1524-
arg_tys[2].simd_type(tcx).sty, arg_tys[2]);
1523+
arg_tys[2].simd_type(tcx), arg_tys[2]);
15251524
}
15261525
}
15271526

@@ -1842,10 +1841,10 @@ fn int_type_width_signed(ty: Ty, cx: &CodegenCx) -> Option<(u64, bool)> {
18421841
}
18431842
}
18441843

1845-
// Returns the width of a float TypeVariant
1844+
// Returns the width of a float Ty
18461845
// Returns None if the type is not a float
1847-
fn float_type_width<'tcx>(sty: &ty::TyKind<'tcx>) -> Option<u64> {
1848-
match *sty {
1846+
fn float_type_width(ty: Ty) -> Option<u64> {
1847+
match ty.sty {
18491848
ty::Float(t) => Some(t.bit_width() as u64),
18501849
_ => None,
18511850
}

src/librustc_codegen_ssa/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5353
let field_ty = c.ty.builtin_index().unwrap();
5454
let fields = match c.ty.sty {
5555
ty::Array(_, n) => n.unwrap_usize(bx.tcx()),
56-
ref other => bug!("invalid simd shuffle type: {}", other),
56+
_ => bug!("invalid simd shuffle type: {}", c.ty),
5757
};
5858
let values: Result<Vec<_>, ErrorHandled> = (0..fields).map(|field| {
5959
let field = const_field(

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
148148
match tail.sty {
149149
ty::Foreign(..) => false,
150150
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
151-
_ => bug!("unexpected unsized tail: {:?}", tail.sty),
151+
_ => bug!("unexpected unsized tail: {:?}", tail),
152152
}
153153
}
154154
}

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17861786
// (https://github.com/rust-lang/rfcs/pull/1546)
17871787
bug!(
17881788
"End-user description not implemented for field access on `{:?}`",
1789-
ty.sty
1789+
ty
17901790
);
17911791
}
17921792
}

src/librustc_mir/hair/cx/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,8 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
940940
let user_provided_types = cx.tables.user_provided_types();
941941
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
942942
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
943-
match cx.tables().node_id_to_type(expr.hir_id).sty {
943+
let ty = cx.tables().node_id_to_type(expr.hir_id);
944+
match ty.sty {
944945
// A unit struct/variant which is used as a value.
945946
// We return a completely different ExprKind here to account for this special case.
946947
ty::Adt(adt_def, substs) => {
@@ -953,7 +954,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
953954
base: None,
954955
}
955956
}
956-
ref sty => bug!("unexpected sty: {:?}", sty),
957+
_ => bug!("unexpected ty: {:?}", ty),
957958
}
958959
}
959960

0 commit comments

Comments
 (0)