From e917b012865d67f05e69da8d741f2be91f4e9a26 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 7 Nov 2019 13:27:00 +0100 Subject: [PATCH] Rustup to rust-lang/rust#65884 --- clippy_lints/src/approx_const.rs | 10 ++++++---- clippy_lints/src/consts.rs | 8 +++++--- clippy_lints/src/excessive_precision.rs | 2 +- clippy_lints/src/literal_representation.rs | 2 +- clippy_lints/src/misc_early.rs | 8 ++++---- clippy_lints/src/precedence.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- clippy_lints/src/types.rs | 4 ++-- clippy_lints/src/utils/author.rs | 14 +++++++++----- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 81555a4c533..fac75cffeba 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -3,7 +3,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; use std::f64::consts as f64; -use syntax::ast::{FloatTy, LitKind}; +use syntax::ast::{FloatTy, LitFloatType, LitKind}; use syntax::symbol; declare_clippy_lint! { @@ -62,9 +62,11 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) { match *lit { - LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"), - LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"), - LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"), + LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { + FloatTy::F32 => check_known_consts(cx, e, s, "f32"), + FloatTy::F64 => check_known_consts(cx, e, s, "f64"), + }, + LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"), _ => (), } } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index dc70de48503..fc5c8b2e379 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), - LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()), - LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), - LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind { + 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()), + }, + 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()), ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()), _ => bug!(), diff --git a/clippy_lints/src/excessive_precision.rs b/clippy_lints/src/excessive_precision.rs index fcc247974c5..8027a736c6b 100644 --- a/clippy_lints/src/excessive_precision.rs +++ b/clippy_lints/src/excessive_precision.rs @@ -43,7 +43,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { let ty = cx.tables.expr_ty(expr); if let ty::Float(fty) = ty.kind; if let hir::ExprKind::Lit(ref lit) = expr.kind; - if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node; + if let LitKind::Float(sym, _) = lit.node; if let Some(sugg) = Self::check(sym, fty); then { span_lint_and_sugg( diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index badd2237073..c526858a7a2 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -373,7 +373,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { } } }, - LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => { + LitKind::Float(..) => { // Lint floating-point literals. if_chain! { if let Some(src) = snippet_opt(cx, lit.span); diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 2f43daf4caf..d756980b354 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -482,8 +482,8 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { if let LitKind::Int(value, lit_int_type) = lit.kind { let suffix = match lit_int_type { - LitIntType::Signed(ty) => ty.ty_to_string(), - LitIntType::Unsigned(ty) => ty.ty_to_string(), + LitIntType::Signed(ty) => ty.name_str(), + LitIntType::Unsigned(ty) => ty.name_str(), LitIntType::Unsuffixed => "", }; @@ -543,8 +543,8 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit) { }, ); } - } else if let LitKind::Float(_, float_ty) = lit.kind { - let suffix = float_ty.ty_to_string(); + } else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind { + let suffix = float_ty.name_str(); let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1; if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' { span_lint_and_sugg( diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index a2d054c1de4..a0bcba17d55 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -90,7 +90,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { if let Some(slf) = args.first() { if let ExprKind::Lit(ref lit) = slf.kind { match lit.kind { - LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => { + LitKind::Int(..) | LitKind::Float(..) => { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( cx, diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 1339555f9ce..788d02ecb0a 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -390,7 +390,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); let arg = if let ty::Int(_) = from_ty.kind { - arg.as_ty(ast::UintTy::U32) + arg.as_ty(ast::UintTy::U32.name_str()) } else { arg }; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 6c1e0b808d9..62da724ffd9 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -15,7 +15,7 @@ use rustc_errors::Applicability; use rustc_target::spec::abi::Abi; use rustc_typeck::hir_ty_to_ty; -use syntax::ast::{FloatTy, IntTy, LitIntType, LitKind, UintTy}; +use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy}; use syntax::errors::DiagnosticBuilder; use syntax::source_map::Span; use syntax::symbol::{sym, Symbol}; @@ -1186,7 +1186,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { } } match lit.node { - LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::FloatUnsuffixed(_) => {}, + LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {}, _ => { if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) { span_lint( diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index a424c09ef40..f3fc0487b26 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -9,7 +9,7 @@ use rustc::session::Session; use rustc::{declare_lint_pass, declare_tool_lint}; use rustc_data_structures::fx::FxHashMap; -use syntax::ast::{Attribute, LitKind}; +use syntax::ast::{Attribute, LitFloatType, LitKind}; declare_clippy_lint! { /// **What it does:** Generates clippy code that detects the offending pattern @@ -288,10 +288,14 @@ fn visit_expr(&mut self, expr: &Expr) { LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat), // FIXME: also check int type LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat), - LitKind::Float(..) => println!(" if let LitKind::Float(..) = {}.node;", lit_pat), - LitKind::FloatUnsuffixed(_) => { - println!(" if let LitKind::FloatUnsuffixed(_) = {}.node;", lit_pat) - }, + LitKind::Float(_, LitFloatType::Suffixed(_)) => println!( + " if let LitKind::Float(_, LitFloatType::Suffixed(_)) = {}.node;", + lit_pat + ), + LitKind::Float(_, LitFloatType::Unsuffixed) => println!( + " if let LitKind::Float(_, LitFloatType::Unsuffixed) = {}.node;", + lit_pat + ), LitKind::ByteStr(ref vec) => { let vec_pat = self.next("vec"); println!(" if let LitKind::ByteStr(ref {}) = {}.node;", vec_pat, lit_pat);