Skip to content

Commit e917b01

Browse files
committed
1 parent 305ba73 commit e917b01

9 files changed

+30
-22
lines changed

clippy_lints/src/approx_const.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
55
use std::f64::consts as f64;
6-
use syntax::ast::{FloatTy, LitKind};
6+
use syntax::ast::{FloatTy, LitFloatType, LitKind};
77
use syntax::symbol;
88

99
declare_clippy_lint! {
@@ -62,9 +62,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
6262

6363
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
6464
match *lit {
65-
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
66-
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
67-
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
65+
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
66+
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
67+
FloatTy::F64 => check_known_consts(cx, e, s, "f64"),
68+
},
69+
LitKind::Float(s, LitFloatType::Unsuffixed) => check_known_consts(cx, e, s, "f{32, 64}"),
6870
_ => (),
6971
}
7072
}

clippy_lints/src/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
161161
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
162162
LitKind::Char(c) => Constant::Char(c),
163163
LitKind::Int(n, _) => Constant::Int(n),
164-
LitKind::Float(ref is, FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
165-
LitKind::Float(ref is, FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
166-
LitKind::FloatUnsuffixed(ref is) => match ty.expect("type of float is known").kind {
164+
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
165+
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
166+
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
167+
},
168+
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind {
167169
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
168170
ty::Float(FloatTy::F64) => Constant::F64(is.as_str().parse().unwrap()),
169171
_ => bug!(),

clippy_lints/src/excessive_precision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
4343
let ty = cx.tables.expr_ty(expr);
4444
if let ty::Float(fty) = ty.kind;
4545
if let hir::ExprKind::Lit(ref lit) = expr.kind;
46-
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
46+
if let LitKind::Float(sym, _) = lit.node;
4747
if let Some(sugg) = Self::check(sym, fty);
4848
then {
4949
span_lint_and_sugg(

clippy_lints/src/literal_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl LiteralDigitGrouping {
373373
}
374374
}
375375
},
376-
LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
376+
LitKind::Float(..) => {
377377
// Lint floating-point literals.
378378
if_chain! {
379379
if let Some(src) = snippet_opt(cx, lit.span);

clippy_lints/src/misc_early.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ impl MiscEarlyLints {
482482

483483
if let LitKind::Int(value, lit_int_type) = lit.kind {
484484
let suffix = match lit_int_type {
485-
LitIntType::Signed(ty) => ty.ty_to_string(),
486-
LitIntType::Unsigned(ty) => ty.ty_to_string(),
485+
LitIntType::Signed(ty) => ty.name_str(),
486+
LitIntType::Unsigned(ty) => ty.name_str(),
487487
LitIntType::Unsuffixed => "",
488488
};
489489

@@ -543,8 +543,8 @@ impl MiscEarlyLints {
543543
},
544544
);
545545
}
546-
} else if let LitKind::Float(_, float_ty) = lit.kind {
547-
let suffix = float_ty.ty_to_string();
546+
} else if let LitKind::Float(_, LitFloatType::Suffixed(float_ty)) = lit.kind {
547+
let suffix = float_ty.name_str();
548548
let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1;
549549
if lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {
550550
span_lint_and_sugg(

clippy_lints/src/precedence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl EarlyLintPass for Precedence {
9090
if let Some(slf) = args.first() {
9191
if let ExprKind::Lit(ref lit) = slf.kind {
9292
match lit.kind {
93-
LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => {
93+
LitKind::Int(..) | LitKind::Float(..) => {
9494
let mut applicability = Applicability::MachineApplicable;
9595
span_lint_and_sugg(
9696
cx,

clippy_lints/src/transmute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
390390
|db| {
391391
let arg = sugg::Sugg::hir(cx, &args[0], "..");
392392
let arg = if let ty::Int(_) = from_ty.kind {
393-
arg.as_ty(ast::UintTy::U32)
393+
arg.as_ty(ast::UintTy::U32.name_str())
394394
} else {
395395
arg
396396
};

clippy_lints/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1515
use rustc_errors::Applicability;
1616
use rustc_target::spec::abi::Abi;
1717
use rustc_typeck::hir_ty_to_ty;
18-
use syntax::ast::{FloatTy, IntTy, LitIntType, LitKind, UintTy};
18+
use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
1919
use syntax::errors::DiagnosticBuilder;
2020
use syntax::source_map::Span;
2121
use syntax::symbol::{sym, Symbol};
@@ -1186,7 +1186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
11861186
}
11871187
}
11881188
match lit.node {
1189-
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::FloatUnsuffixed(_) => {},
1189+
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
11901190
_ => {
11911191
if cast_from.kind == cast_to.kind && !in_external_macro(cx.sess(), expr.span) {
11921192
span_lint(

clippy_lints/src/utils/author.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
99
use rustc::session::Session;
1010
use rustc::{declare_lint_pass, declare_tool_lint};
1111
use rustc_data_structures::fx::FxHashMap;
12-
use syntax::ast::{Attribute, LitKind};
12+
use syntax::ast::{Attribute, LitFloatType, LitKind};
1313

1414
declare_clippy_lint! {
1515
/// **What it does:** Generates clippy code that detects the offending pattern
@@ -288,10 +288,14 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
288288
LitKind::Byte(b) => println!(" if let LitKind::Byte({}) = {}.node;", b, lit_pat),
289289
// FIXME: also check int type
290290
LitKind::Int(i, _) => println!(" if let LitKind::Int({}, _) = {}.node;", i, lit_pat),
291-
LitKind::Float(..) => println!(" if let LitKind::Float(..) = {}.node;", lit_pat),
292-
LitKind::FloatUnsuffixed(_) => {
293-
println!(" if let LitKind::FloatUnsuffixed(_) = {}.node;", lit_pat)
294-
},
291+
LitKind::Float(_, LitFloatType::Suffixed(_)) => println!(
292+
" if let LitKind::Float(_, LitFloatType::Suffixed(_)) = {}.node;",
293+
lit_pat
294+
),
295+
LitKind::Float(_, LitFloatType::Unsuffixed) => println!(
296+
" if let LitKind::Float(_, LitFloatType::Unsuffixed) = {}.node;",
297+
lit_pat
298+
),
295299
LitKind::ByteStr(ref vec) => {
296300
let vec_pat = self.next("vec");
297301
println!(" if let LitKind::ByteStr(ref {}) = {}.node;", vec_pat, lit_pat);

0 commit comments

Comments
 (0)