From dce2262daea813f67fb8cce4e76eb5909ef510cb Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 12 Dec 2020 15:32:45 +0100 Subject: [PATCH] Use ty::{IntTy,UintTy,FloatTy} in rustdoc and clippy --- clippy_lints/src/bytecount.rs | 3 +-- clippy_lints/src/consts.rs | 8 ++++---- clippy_lints/src/enum_clike.rs | 3 +-- clippy_lints/src/float_literal.rs | 8 ++++---- clippy_lints/src/mutex_atomic.rs | 5 ++--- clippy_lints/src/transmute.rs | 6 +++--- clippy_lints/src/types.rs | 8 +++----- clippy_lints/src/utils/mod.rs | 13 ++++++------- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 38a0e27c4cf..ac9098a7584 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -2,11 +2,10 @@ use crate::utils::{ contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg, }; use if_chain::if_chain; -use rustc_ast::ast::UintTy; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, UintTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; use rustc_span::Symbol; diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 166eadf86c1..640cffd24a7 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -2,14 +2,14 @@ use crate::utils::{clip, sext, unsext}; use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; +use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp}; use rustc_lint::LateContext; use rustc_middle::mir::interpret::Scalar; use rustc_middle::ty::subst::{Subst, SubstsRef}; -use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt}; +use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; @@ -167,8 +167,8 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { - FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), - FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), + ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()), + ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()), }, LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() { ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index fb80f48a9cc..ae56a8ba5ab 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -3,10 +3,9 @@ use crate::consts::{miri_to_const, Constant}; use crate::utils::span_lint; -use rustc_ast::ast::{IntTy, UintTy}; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, IntTy, UintTy}; use rustc_middle::ty::util::IntTypeExt; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::convert::TryFrom; diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 1fe4461533b..be646cbe4d0 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -1,10 +1,10 @@ use crate::utils::{numeric_literal, span_lint_and_sugg}; use if_chain::if_chain; -use rustc_ast::ast::{FloatTy, LitFloatType, LitKind}; +use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; +use rustc_middle::ty::{self, FloatTy}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt; @@ -75,8 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { let digits = count_digits(&sym_str); let max = max_digits(fty); let type_suffix = match lit_float_ty { - LitFloatType::Suffixed(FloatTy::F32) => Some("f32"), - LitFloatType::Suffixed(FloatTy::F64) => Some("f64"), + LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"), + LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"), LitFloatType::Unsuffixed => None }; let (is_whole, mut float_str) = match fty { diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index ea986874291..40b236493a3 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -3,7 +3,6 @@ //! This lint is **warn** by default use crate::utils::{is_type_diagnostic_item, span_lint}; -use rustc_ast::ast; use rustc_hir::Expr; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; @@ -77,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { atomic_name ); match *mutex_param.kind() { - ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), - ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), + ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), + ty::Int(t) if t != ty::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg), _ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg), }; } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index b0909f73177..d977cea4da5 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -443,7 +443,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { ); }, ), - (ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => { + (ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_CHAR, @@ -468,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => { if_chain! { if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind()); - if let ty::Uint(ast::UintTy::U8) = slice_ty.kind(); + if let ty::Uint(ty::UintTy::U8) = slice_ty.kind(); if from_mutbl == to_mutbl; then { let postfix = if *from_mutbl == Mutability::Mut { @@ -536,7 +536,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { } }, ), - (ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => { + (ty::Int(ty::IntTy::I8) | ty::Uint(ty::UintTy::U8), ty::Bool) => { span_lint_and_then( cx, TRANSMUTE_INT_TO_BOOL, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 3b5a83d2a0b..17cef0af3e9 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use std::collections::BTreeMap; use if_chain::if_chain; -use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; +use rustc_ast::{LitFloatType, LitIntType, LitKind}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; @@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::TypeFoldable; -use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults}; +use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults, UintTy}; use rustc_semver::RustcVersion; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -1106,9 +1106,7 @@ fn is_empty_block(expr: &Expr<'_>) -> bool { expr.kind, ExprKind::Block( Block { - stmts: &[], - expr: None, - .. + stmts: &[], expr: None, .. }, _, ) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 9b262517a98..46b2b06d1a2 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -35,7 +35,6 @@ use std::mem; use if_chain::if_chain; use rustc_ast::ast::{self, Attribute, LitKind}; -use rustc_attr as attr; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_hir as hir; @@ -1224,27 +1223,27 @@ pub fn get_arg_name(pat: &Pat<'_>) -> Option { } } -pub fn int_bits(tcx: TyCtxt<'_>, ity: ast::IntTy) -> u64 { - Integer::from_attr(&tcx, attr::IntType::SignedInt(ity)).size().bits() +pub fn int_bits(tcx: TyCtxt<'_>, ity: ty::IntTy) -> u64 { + Integer::from_int_ty(&tcx, ity).size().bits() } #[allow(clippy::cast_possible_wrap)] /// Turn a constant int byte representation into an i128 -pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ast::IntTy) -> i128 { +pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ty::IntTy) -> i128 { let amt = 128 - int_bits(tcx, ity); ((u as i128) << amt) >> amt } #[allow(clippy::cast_sign_loss)] /// clip unused bytes -pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ast::IntTy) -> u128 { +pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ty::IntTy) -> u128 { let amt = 128 - int_bits(tcx, ity); ((u as u128) << amt) >> amt } /// clip unused bytes -pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ast::UintTy) -> u128 { - let bits = Integer::from_attr(&tcx, attr::IntType::UnsignedInt(ity)).size().bits(); +pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ty::UintTy) -> u128 { + let bits = Integer::from_uint_ty(&tcx, ity).size().bits(); let amt = 128 - bits; (u << amt) >> amt }