forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#125433 - surechen:fix_125189, r=Urgau
A small diagnostic improvement for dropping_copy_types For a value `m` which implements `Copy` trait, `drop(m);` does nothing. We now suggest user to ignore it by a abstract and general note: `let _ = ...`. I think we can give a clearer note here: `let _ = m;` fixes rust-lang#125189 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
- Loading branch information
Showing
11 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/lint/dropping_copy_types-issue-125189-can-not-fixed.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ check-fail | ||
|
||
#![deny(dropping_copy_types)] | ||
|
||
fn main() { | ||
let y = 1; | ||
let z = 2; | ||
match y { | ||
0 => drop(y), //~ ERROR calls to `std::mem::drop` | ||
1 => drop(z), //~ ERROR calls to `std::mem::drop` | ||
2 => drop(3), //~ ERROR calls to `std::mem::drop` | ||
_ => {}, | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/ui/lint/dropping_copy_types-issue-125189-can-not-fixed.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing | ||
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:9:14 | ||
| | ||
LL | 0 => drop(y), | ||
| ^^^^^-^ | ||
| | | ||
| argument has type `i32` | ||
| | ||
= note: use `let _ = ...` to ignore the expression or result | ||
note: the lint level is defined here | ||
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:3:9 | ||
| | ||
LL | #![deny(dropping_copy_types)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing | ||
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:10:14 | ||
| | ||
LL | 1 => drop(z), | ||
| ^^^^^-^ | ||
| | | ||
| argument has type `i32` | ||
| | ||
= note: use `let _ = ...` to ignore the expression or result | ||
|
||
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing | ||
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:11:14 | ||
| | ||
LL | 2 => drop(3), | ||
| ^^^^^-^ | ||
| | | ||
| argument has type `i32` | ||
| | ||
= note: use `let _ = ...` to ignore the expression or result | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//@ check-fail | ||
//@ run-rustfix | ||
|
||
#![deny(dropping_copy_types)] | ||
|
||
fn main() { | ||
let y = 1; | ||
let _ = 3.2; //~ ERROR calls to `std::mem::drop` | ||
let _ = y; //~ ERROR calls to `std::mem::drop` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//@ check-fail | ||
//@ run-rustfix | ||
|
||
#![deny(dropping_copy_types)] | ||
|
||
fn main() { | ||
let y = 1; | ||
drop(3.2); //~ ERROR calls to `std::mem::drop` | ||
drop(y); //~ ERROR calls to `std::mem::drop` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing | ||
--> $DIR/dropping_copy_types-issue-125189.rs:8:5 | ||
| | ||
LL | drop(3.2); | ||
| ^^^^^---^ | ||
| | | ||
| argument has type `f64` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/dropping_copy_types-issue-125189.rs:4:9 | ||
| | ||
LL | #![deny(dropping_copy_types)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - drop(3.2); | ||
LL + let _ = 3.2; | ||
| | ||
|
||
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing | ||
--> $DIR/dropping_copy_types-issue-125189.rs:9:5 | ||
| | ||
LL | drop(y); | ||
| ^^^^^-^ | ||
| | | ||
| argument has type `i32` | ||
| | ||
help: use `let _ = ...` to ignore the expression or result | ||
| | ||
LL - drop(y); | ||
LL + let _ = y; | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters