-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(zero_repeat_side_effects): better identify exprs with side effects #15814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,136 @@ | ||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:18:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:16:5 | ||
| | ||
LL | let a = [f(); 0]; | ||
| ^^^^^^^^^^^^^^^^^ help: consider using: `f(); let a: [i32; 0] = [];` | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::zero-repeat-side-effects` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::zero_repeat_side_effects)]` | ||
help: consider performing the side effect separately | ||
| | ||
LL - let a = [f(); 0]; | ||
LL + f(); let a: [i32; 0] = []; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:21:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:19:5 | ||
| | ||
LL | b = [f(); 0]; | ||
| ^^^^^^^^^^^^ help: consider using: `f(); b = [] as [i32; 0]` | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - b = [f(); 0]; | ||
LL + f(); b = [] as [i32; 0]; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:26:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:24:5 | ||
| | ||
LL | let c = vec![f(); 0]; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let c: std::vec::Vec<i32> = vec![];` | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - let c = vec![f(); 0]; | ||
LL + f(); let c: std::vec::Vec<i32> = vec![]; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:29:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:27:5 | ||
| | ||
LL | d = vec![f(); 0]; | ||
| ^^^^^^^^^^^^^^^^ help: consider using: `f(); d = vec![] as std::vec::Vec<i32>` | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - d = vec![f(); 0]; | ||
LL + f(); d = vec![] as std::vec::Vec<i32>; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:33:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:31:5 | ||
| | ||
LL | let e = [println!("side effect"); 0]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `println!("side effect"); let e: [(); 0] = [];` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - let e = [println!("side effect"); 0]; | ||
LL + println!("side effect"); let e: [(); 0] = []; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:37:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:35:5 | ||
| | ||
LL | let g = [{ f() }; 0]; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `{ f() }; let g: [i32; 0] = [];` | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - let g = [{ f() }; 0]; | ||
LL + { f() }; let g: [i32; 0] = []; | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:41:10 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:39:10 | ||
| | ||
LL | drop(vec![f(); 0]); | ||
| ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec<i32> }` | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - drop(vec![f(); 0]); | ||
LL + drop({ f(); vec![] as std::vec::Vec<i32> }); | ||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:45:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:43:5 | ||
| | ||
LL | vec![f(); 0]; | ||
| ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec<i32> }` | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - vec![f(); 0]; | ||
LL + { f(); vec![] as std::vec::Vec<i32> }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such an ugly suggestion… Never mind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I can improve it just a bit -- since the original expression is in a statement, I can safely remove the block around the suggestion. Should I do it in this PR, or in a separate one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to say in the same PR, but doing it in another PR looks better as it has nothing to do with the current PR. Assign it to me if you take on it. |
||
| | ||
|
||
error: function or method calls as the initial value in zero-sized array initializers may cause side effects | ||
--> tests/ui/zero_repeat_side_effects.rs:47:5 | ||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:45:5 | ||
| | ||
LL | [f(); 0]; | ||
| ^^^^^^^^ help: consider using: `{ f(); [] as [i32; 0] }` | ||
| ^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - [f(); 0]; | ||
LL + { f(); [] as [i32; 0] }; | ||
| | ||
|
||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:99:10 | ||
| | ||
LL | foo(&[Some(f()); 0]); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - foo(&[Some(f()); 0]); | ||
LL + foo(&{ Some(f()); [] as [std::option::Option<i32>; 0] }); | ||
| | ||
|
||
error: expression with side effects as the initial value in a zero-sized array initializer | ||
--> tests/ui/zero_repeat_side_effects.rs:101:10 | ||
| | ||
LL | foo(&[Some(Some(S::new())); 0]); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider performing the side effect separately | ||
| | ||
LL - foo(&[Some(Some(S::new())); 0]); | ||
LL + foo(&{ Some(Some(S::new())); [] as [std::option::Option<std::option::Option<S>>; 0] }); | ||
| | ||
|
||
error: aborting due to 9 previous errors | ||
error: aborting due to 11 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.