Skip to content

Commit d0bb095

Browse files
committed
fix clippy matches on FloatTy
1 parent f99b033 commit d0bb095

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎src/tools/clippy/clippy_lints/src/approx_const.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
55
use rustc_hir::attrs::RustcVersion;
66
use rustc_hir::{HirId, Lit};
77
use rustc_lint::{LateContext, LateLintPass, impl_lint_pass};
8+
use rustc_middle::bug;
89
use rustc_span::{Span, symbol};
910
use std::f64::consts as f64;
1011

@@ -84,6 +85,7 @@ impl LateLintPass<'_> for ApproxConstant {
8485
FloatTy::F32 => self.check_known_consts(cx, lit.span, s, "f32"),
8586
FloatTy::F64 => self.check_known_consts(cx, lit.span, s, "f64"),
8687
FloatTy::F128 => self.check_known_consts(cx, lit.span, s, "f128"),
88+
FloatTy::PpcF128 => bug!("there are no ppcf128 literals"),
8789
},
8890
// FIXME(f16_f128): add `f16` and `f128` when these types become stable.
8991
LitKind::Float(s, LitFloatType::Unsuffixed) => self.check_known_consts(cx, lit.span, s, "f{32, 64}"),

‎src/tools/clippy/clippy_lints/src/float_literal.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_ast::ast::{LitFloatType, LitKind};
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
77
use rustc_lint::{LateContext, LateLintPass, impl_lint_pass};
8+
use rustc_middle::bug;
89
use rustc_middle::ty::{self, FloatTy};
910
use std::fmt;
1011

@@ -93,6 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
9394
LitFloatType::Suffixed(FloatTy::F32) => Some("f32"),
9495
LitFloatType::Suffixed(FloatTy::F64) => Some("f64"),
9596
LitFloatType::Suffixed(FloatTy::F128) => Some("f128"),
97+
LitFloatType::Suffixed(FloatTy::PpcF128) => bug!("there are no ppcf128 literals"),
9698
LitFloatType::Unsuffixed => None,
9799
};
98100
let (is_whole, is_inf, mut float_str) = match fty {
@@ -110,6 +112,9 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
110112

111113
(value.fract() == 0.0, value.is_infinite(), formatter.format(value))
112114
},
115+
FloatTy::PpcF128 => {
116+
bug!("there are no ppcf128 literals")
117+
},
113118
};
114119

115120
if is_inf {
@@ -182,6 +187,7 @@ fn max_digits(fty: FloatTy) -> u32 {
182187
FloatTy::F32 => f32::DIGITS,
183188
FloatTy::F64 => f64::DIGITS,
184189
FloatTy::F128 => f128::DIGITS,
190+
FloatTy::PpcF128 => bug!("there are no ppcf128 literals"),
185191
}
186192
}
187193

‎src/tools/clippy/clippy_lints/src/utils/author.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
393393
FloatTy::F32 => "F32",
394394
FloatTy::F64 => "F64",
395395
FloatTy::F128 => "F128",
396+
FloatTy::PpcF128 => "PpcF128",
396397
};
397398
format!("LitFloatType::Suffixed(FloatTy::{t})")
398399
},

‎src/tools/clippy/clippy_utils/src/consts.rs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
428428
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
429429
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
430430
FloatTy::F128 => Constant::parse_f128(is.as_str()),
431+
FloatTy::PpcF128 => bug!("no ppcf128 literals"),
431432
},
432433
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() {
433434
ty::Float(FloatTy::F16) => Constant::parse_f16(is.as_str()),
@@ -991,8 +992,9 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
991992
let l = sext(self.tcx, l, ity);
992993
let r = sext(self.tcx, r, ity);
993994

994-
// Using / or %, where the left-hand argument is the smallest integer of a signed integer type and
995-
// the right-hand argument is -1 always panics, even with overflow-checks disabled
995+
// Using / or %, where the left-hand argument is the smallest integer of a
996+
// signed integer type and the right-hand argument is -1
997+
// always panics, even with overflow-checks disabled
996998
if let BinOpKind::Div | BinOpKind::Rem = op
997999
&& l == ty_min_value
9981000
&& r == -1
@@ -1106,10 +1108,14 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, val: ConstValue, ty: Ty<'tcx>) -> O
11061108
(ConstValue::Scalar(Scalar::Int(int)), _) => match ty.kind() {
11071109
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
11081110
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))),
1109-
ty::Float(FloatTy::F16) => Some(Constant::F16(int.into())),
1110-
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(int.into()))),
1111-
ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(int.into()))),
1112-
ty::Float(FloatTy::F128) => Some(Constant::F128(int.into())),
1111+
1112+
ty::Float(float) => match float {
1113+
FloatTy::F16 => Some(Constant::F16(int.into())),
1114+
FloatTy::F32 => Some(Constant::F32(f32::from_bits(int.into()))),
1115+
FloatTy::F64 => Some(Constant::F64(f64::from_bits(int.into()))),
1116+
FloatTy::F128 => Some(Constant::F128(int.into())),
1117+
FloatTy::PpcF128 => None,
1118+
},
11131119
ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))),
11141120
_ => None,
11151121
},
@@ -1133,6 +1139,7 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, val: ConstValue, ty: Ty<'tcx>) -> O
11331139
FloatTy::F32 => Constant::F32(f32::from_bits(val.to_u32().discard_err()?)),
11341140
FloatTy::F64 => Constant::F64(f64::from_bits(val.to_u64().discard_err()?)),
11351141
FloatTy::F128 => Constant::F128(val.to_u128().discard_err()?),
1142+
FloatTy::PpcF128 => return None,
11361143
});
11371144
}
11381145
Some(Constant::Vec(res))

0 commit comments

Comments
 (0)