mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obk
Strengthen state tracking in const-prop Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization. Behaviour changes: - const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen. - we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry. - the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
This commit is contained in:
commit
e07c6b4899
5 changed files with 24 additions and 21 deletions
|
@ -31,9 +31,7 @@ impl core::ops::Mul<i32> for Vec1 {
|
|||
|
||||
#[allow(clippy::no_effect)]
|
||||
#[warn(clippy::erasing_op)]
|
||||
fn main() {
|
||||
let x: u8 = 0;
|
||||
|
||||
fn test(x: u8) {
|
||||
x * 0;
|
||||
0 & x;
|
||||
0 / x;
|
||||
|
@ -41,3 +39,7 @@ fn main() {
|
|||
0 * Vec1 { x: 5 };
|
||||
Vec1 { x: 5 } * 0;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(0)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/erasing_op.rs:37:5
|
||||
--> $DIR/erasing_op.rs:35:5
|
||||
|
|
||||
LL | x * 0;
|
||||
| ^^^^^
|
||||
|
@ -7,25 +7,25 @@ LL | x * 0;
|
|||
= note: `-D clippy::erasing-op` implied by `-D warnings`
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/erasing_op.rs:38:5
|
||||
--> $DIR/erasing_op.rs:36:5
|
||||
|
|
||||
LL | 0 & x;
|
||||
| ^^^^^
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/erasing_op.rs:39:5
|
||||
--> $DIR/erasing_op.rs:37:5
|
||||
|
|
||||
LL | 0 / x;
|
||||
| ^^^^^
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/erasing_op.rs:41:5
|
||||
--> $DIR/erasing_op.rs:39:5
|
||||
|
|
||||
LL | 0 * Vec1 { x: 5 };
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/erasing_op.rs:42:5
|
||||
--> $DIR/erasing_op.rs:40:5
|
||||
|
|
||||
LL | Vec1 { x: 5 } * 0;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
let mut i = 1i32;
|
||||
let mut var1 = 0i32;
|
||||
let mut var1 = 13i32;
|
||||
let mut var2 = -1i32;
|
||||
1 + i;
|
||||
i * 2;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#![warn(clippy::overflow_check_conditional)]
|
||||
|
||||
fn main() {
|
||||
let a: u32 = 1;
|
||||
let b: u32 = 2;
|
||||
let c: u32 = 3;
|
||||
fn test(a: u32, b: u32, c: u32) {
|
||||
if a + b < a {}
|
||||
if a > a + b {}
|
||||
if a + b < b {}
|
||||
|
@ -23,3 +20,7 @@ fn main() {
|
|||
if i > i + j {}
|
||||
if i - j < i {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(1, 2, 3)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: you are trying to use classic C overflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:7:8
|
||||
--> $DIR/overflow_check_conditional.rs:4:8
|
||||
|
|
||||
LL | if a + b < a {}
|
||||
| ^^^^^^^^^
|
||||
|
@ -7,43 +7,43 @@ LL | if a + b < a {}
|
|||
= note: `-D clippy::overflow-check-conditional` implied by `-D warnings`
|
||||
|
||||
error: you are trying to use classic C overflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:8:8
|
||||
--> $DIR/overflow_check_conditional.rs:5:8
|
||||
|
|
||||
LL | if a > a + b {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C overflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:9:8
|
||||
--> $DIR/overflow_check_conditional.rs:6:8
|
||||
|
|
||||
LL | if a + b < b {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C overflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:10:8
|
||||
--> $DIR/overflow_check_conditional.rs:7:8
|
||||
|
|
||||
LL | if b > a + b {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C underflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:11:8
|
||||
--> $DIR/overflow_check_conditional.rs:8:8
|
||||
|
|
||||
LL | if a - b > b {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C underflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:12:8
|
||||
--> $DIR/overflow_check_conditional.rs:9:8
|
||||
|
|
||||
LL | if b < a - b {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C underflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:13:8
|
||||
--> $DIR/overflow_check_conditional.rs:10:8
|
||||
|
|
||||
LL | if a - b > a {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: you are trying to use classic C underflow conditions that will fail in Rust
|
||||
--> $DIR/overflow_check_conditional.rs:14:8
|
||||
--> $DIR/overflow_check_conditional.rs:11:8
|
||||
|
|
||||
LL | if a < a - b {}
|
||||
| ^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue