Skip to content

Commit 29bf75c

Browse files
authored
Merge pull request #3495 from flip1995/tykind_fix
Fix usage of ty::TyKind
2 parents 3f24cdf + 36ee927 commit 29bf75c

8 files changed

+19
-24
lines changed

clippy_lints/src/consts.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,12 @@ impl Hash for Constant {
119119
}
120120

121121
impl Constant {
122-
pub fn partial_cmp(
123-
tcx: TyCtxt<'_, '_, '_>,
124-
cmp_type: &ty::TyKind<'_>,
125-
left: &Self,
126-
right: &Self,
127-
) -> Option<Ordering> {
122+
pub fn partial_cmp(tcx: TyCtxt<'_, '_, '_>, cmp_type: ty::Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
128123
match (left, right) {
129124
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
130125
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),
131126
(&Constant::Int(l), &Constant::Int(r)) => {
132-
if let ty::Int(int_ty) = *cmp_type {
127+
if let ty::Int(int_ty) = cmp_type.sty {
133128
Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty)))
134129
} else {
135130
Some(l.cmp(&r))

clippy_lints/src/default_trait_access.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use crate::rustc::hir::*;
1111
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12-
use crate::rustc::ty::TyKind;
12+
use crate::rustc::ty;
1313
use crate::rustc::{declare_tool_lint, lint_array};
1414
use crate::rustc_errors::Applicability;
1515
use if_chain::if_chain;
@@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
7171
// TODO: Work out a way to put "whatever the imported way of referencing
7272
// this type in this file" rather than a fully-qualified type.
7373
let expr_ty = cx.tables.expr_ty(expr);
74-
if let TyKind::Adt(..) = expr_ty.sty {
74+
if let ty::Adt(..) = expr_ty.sty {
7575
let replacement = format!("{}::default()", expr_ty);
7676
span_lint_and_sugg(
7777
cx,

clippy_lints/src/excessive_precision.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use crate::rustc::hir;
1111
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
12-
use crate::rustc::ty::TyKind;
12+
use crate::rustc::ty;
1313
use crate::rustc::{declare_tool_lint, lint_array};
1414
use crate::rustc_errors::Applicability;
1515
use crate::syntax::ast::*;
@@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
5656
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
5757
if_chain! {
5858
let ty = cx.tables.expr_ty(expr);
59-
if let TyKind::Float(fty) = ty.sty;
59+
if let ty::Float(fty) = ty.sty;
6060
if let hir::ExprKind::Lit(ref lit) = expr.node;
6161
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
6262
if let Some(sugg) = self.check(sym, fty);

clippy_lints/src/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ fn is_end_eq_array_len(cx: &LateContext<'_, '_>, end: &Expr, limits: ast::RangeL
12521252
if_chain! {
12531253
if let ExprKind::Lit(ref lit) = end.node;
12541254
if let ast::LitKind::Int(end_int, _) = lit.node;
1255-
if let ty::TyKind::Array(_, arr_len_const) = indexed_ty.sty;
1255+
if let ty::Array(_, arr_len_const) = indexed_ty.sty;
12561256
if let Some(arr_len) = arr_len_const.assert_usize(cx.tcx);
12571257
then {
12581258
return match limits {
@@ -1375,7 +1375,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
13751375
match cx.tables.expr_ty(&args[0]).sty {
13761376
// If the length is greater than 32 no traits are implemented for array and
13771377
// therefore we cannot use `&`.
1378-
ty::TyKind::Array(_, size) if size.assert_usize(cx.tcx).expect("array size") > 32 => (),
1378+
ty::Array(_, size) if size.assert_usize(cx.tcx).expect("array size") > 32 => (),
13791379
_ => lint_iter_method(cx, args, arg, method_name),
13801380
};
13811381
} else {

clippy_lints/src/methods/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::rustc::hir;
1111
use crate::rustc::hir::def::Def;
1212
use crate::rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
13-
use crate::rustc::ty::{self, Predicate, Ty, TyKind};
13+
use crate::rustc::ty::{self, Predicate, Ty};
1414
use crate::rustc::{declare_tool_lint, lint_array};
1515
use crate::rustc_errors::Applicability;
1616
use crate::syntax::ast;
@@ -978,7 +978,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
978978
}
979979

980980
// if return type is impl trait, check the associated types
981-
if let TyKind::Opaque(def_id, _) = ret_ty.sty {
981+
if let ty::Opaque(def_id, _) = ret_ty.sty {
982982
// one of the associated types must be Self
983983
for predicate in &cx.tcx.predicates_of(def_id).predicates {
984984
match predicate {
@@ -2204,7 +2204,7 @@ fn ty_has_iter_method(
22042204
];
22052205

22062206
let (self_ty, mutbl) = match self_ref_ty.sty {
2207-
ty::TyKind::Ref(_, self_ty, mutbl) => (self_ty, mutbl),
2207+
ty::Ref(_, self_ty, mutbl) => (self_ty, mutbl),
22082208
_ => unreachable!(),
22092209
};
22102210
let method_name = match mutbl {
@@ -2213,8 +2213,8 @@ fn ty_has_iter_method(
22132213
};
22142214

22152215
let def_id = match self_ty.sty {
2216-
ty::TyKind::Array(..) => return Some((INTO_ITER_ON_ARRAY, "array", method_name)),
2217-
ty::TyKind::Slice(..) => return Some((INTO_ITER_ON_REF, "slice", method_name)),
2216+
ty::Array(..) => return Some((INTO_ITER_ON_ARRAY, "array", method_name)),
2217+
ty::Slice(..) => return Some((INTO_ITER_ON_REF, "slice", method_name)),
22182218
ty::Adt(adt, _) => adt.did,
22192219
_ => return None,
22202220
};

clippy_lints/src/minmax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
5151
}
5252
match (
5353
outer_max,
54-
Constant::partial_cmp(cx.tcx, &cx.tables.expr_ty(ie).sty, &outer_c, &inner_c),
54+
Constant::partial_cmp(cx.tcx, cx.tables.expr_ty(ie), &outer_c, &inner_c),
5555
) {
5656
(_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (),
5757
_ => {

clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
219219

220220
// Dereference suggestion
221221
let sugg = |db: &mut DiagnosticBuilder<'_>| {
222-
if let ty::TyKind::Adt(def, ..) = ty.sty {
222+
if let ty::Adt(def, ..) = ty.sty {
223223
if let Some(span) = cx.tcx.hir.span_if_local(def.did) {
224224
if cx.param_env.can_type_implement_copy(cx.tcx, ty).is_ok() {
225225
db.span_help(span, "consider marking this type as Copy");

clippy_lints/src/trivially_copy_pass_by_ref.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::rustc::hir::intravisit::FnKind;
1414
use crate::rustc::hir::*;
1515
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1616
use crate::rustc::session::config::Config as SessionConfig;
17-
use crate::rustc::ty::{FnSig, TyKind};
17+
use crate::rustc::ty::{self, FnSig};
1818
use crate::rustc::{declare_tool_lint, lint_array};
1919
use crate::rustc_errors::Applicability;
2020
use crate::rustc_target::abi::LayoutOf;
@@ -99,8 +99,8 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
9999
// argument. In that case we can't switch to pass-by-value as the
100100
// argument will not live long enough.
101101
let output_lts = match sig.output().sty {
102-
TyKind::Ref(output_lt, _, _) => vec![output_lt],
103-
TyKind::Adt(_, substs) => substs.regions().collect(),
102+
ty::Ref(output_lt, _, _) => vec![output_lt],
103+
ty::Adt(_, substs) => substs.regions().collect(),
104104
_ => vec![],
105105
};
106106

@@ -112,7 +112,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
112112
}
113113

114114
if_chain! {
115-
if let TyKind::Ref(input_lt, ty, Mutability::MutImmutable) = ty.sty;
115+
if let ty::Ref(input_lt, ty, Mutability::MutImmutable) = ty.sty;
116116
if !output_lts.contains(&input_lt);
117117
if is_copy(cx, ty);
118118
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());

0 commit comments

Comments
 (0)