mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
parent
28ec27b33a
commit
26a6891925
4 changed files with 34 additions and 12 deletions
|
@ -651,7 +651,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|||
if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) &&
|
||||
(F32(180_f32) == lvalue || F64(180_f64) == lvalue)
|
||||
{
|
||||
let mut proposal = format!("{}.to_degrees()", Sugg::hir(cx, mul_lhs, ".."));
|
||||
let mut proposal = format!("{}.to_degrees()", Sugg::hir(cx, mul_lhs, "..").maybe_par());
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref literal) = mul_lhs.kind;
|
||||
if let ast::LitKind::Float(ref value, float_type) = literal.node;
|
||||
|
@ -677,7 +677,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|||
(F32(180_f32) == rvalue || F64(180_f64) == rvalue) &&
|
||||
(F32(f32_consts::PI) == lvalue || F64(f64_consts::PI) == lvalue)
|
||||
{
|
||||
let mut proposal = format!("{}.to_radians()", Sugg::hir(cx, mul_lhs, ".."));
|
||||
let mut proposal = format!("{}.to_radians()", Sugg::hir(cx, mul_lhs, "..").maybe_par());
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref literal) = mul_lhs.kind;
|
||||
if let ast::LitKind::Float(ref value, float_type) = literal.node;
|
||||
|
|
|
@ -8,6 +8,11 @@ pub const fn const_context() {
|
|||
let _ = x * 180f32 / std::f32::consts::PI;
|
||||
}
|
||||
|
||||
pub fn issue9391(degrees: i64) {
|
||||
let _ = (degrees as f64).to_radians();
|
||||
let _ = (degrees as f64).to_degrees();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 3f32;
|
||||
let _ = x.to_degrees();
|
||||
|
|
|
@ -8,6 +8,11 @@ pub const fn const_context() {
|
|||
let _ = x * 180f32 / std::f32::consts::PI;
|
||||
}
|
||||
|
||||
pub fn issue9391(degrees: i64) {
|
||||
let _ = degrees as f64 * std::f64::consts::PI / 180.0;
|
||||
let _ = degrees as f64 * 180.0 / std::f64::consts::PI;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 3f32;
|
||||
let _ = x * 180f32 / std::f32::consts::PI;
|
||||
|
|
|
@ -1,40 +1,52 @@
|
|||
error: conversion to degrees can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:13:13
|
||||
error: conversion to radians can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:12:13
|
||||
|
|
||||
LL | let _ = x * 180f32 / std::f32::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()`
|
||||
LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()`
|
||||
|
|
||||
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
|
||||
|
||||
error: conversion to degrees can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:14:13
|
||||
--> $DIR/floating_point_rad.rs:13:13
|
||||
|
|
||||
LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()`
|
||||
|
||||
error: conversion to degrees can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:18:13
|
||||
|
|
||||
LL | let _ = x * 180f32 / std::f32::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()`
|
||||
|
||||
error: conversion to degrees can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:19:13
|
||||
|
|
||||
LL | let _ = 90. * 180f64 / std::f64::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()`
|
||||
|
||||
error: conversion to degrees can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:15:13
|
||||
--> $DIR/floating_point_rad.rs:20:13
|
||||
|
|
||||
LL | let _ = 90.5 * 180f64 / std::f64::consts::PI;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()`
|
||||
|
||||
error: conversion to radians can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:16:13
|
||||
--> $DIR/floating_point_rad.rs:21:13
|
||||
|
|
||||
LL | let _ = x * std::f32::consts::PI / 180f32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()`
|
||||
|
||||
error: conversion to radians can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:17:13
|
||||
--> $DIR/floating_point_rad.rs:22:13
|
||||
|
|
||||
LL | let _ = 90. * std::f32::consts::PI / 180f32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()`
|
||||
|
||||
error: conversion to radians can be done more accurately
|
||||
--> $DIR/floating_point_rad.rs:18:13
|
||||
--> $DIR/floating_point_rad.rs:23:13
|
||||
|
|
||||
LL | let _ = 90.5 * std::f32::consts::PI / 180f32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue