diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-02 10:27:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-02 10:27:21 +0200 |
| commit | 74a272d3d74d55d024532dd62941d09fb5f9317c (patch) | |
| tree | 2eef8bf28f49356602d9a95293712e9a261e66e0 /tests | |
| parent | 37c50653fe6ee416dbdc864f619f25ff31581cfd (diff) | |
| parent | 908574b5e761fca6e0b03ef4e2c8640fcff1218a (diff) | |
| download | rust-74a272d3d74d55d024532dd62941d09fb5f9317c.tar.gz rust-74a272d3d74d55d024532dd62941d09fb5f9317c.zip | |
Rollup merge of #113231 - Urgau:fix_false_positive_drop_copy, r=Nilstrieb
Fix `dropping_copy_types` lint from linting in match-arm with side-effects This PR fixes an issue with the `dropping_copy_types` and `dropping_references` lints when not all patterns that can have side-effects were detected and ignored. Nearly _fixes_ https://github.com/rust-lang/rust/issues/112653 (will need beta-backport to completely fix the issue) r? ``@Nilstrieb``
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/lint/dropping_copy_types.rs | 19 | ||||
| -rw-r--r-- | tests/ui/lint/dropping_references.rs | 19 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/lint/dropping_copy_types.rs b/tests/ui/lint/dropping_copy_types.rs index 2937320e5d8..2412222d6d1 100644 --- a/tests/ui/lint/dropping_copy_types.rs +++ b/tests/ui/lint/dropping_copy_types.rs @@ -77,3 +77,22 @@ fn issue9482(x: u8) { _ => (), } } + +fn issue112653() { + fn foo() -> Result<u8, ()> { + println!("doing foo"); + Ok(0) // result is not always useful, the side-effect matters + } + fn bar() { + println!("doing bar"); + } + + fn stuff() -> Result<(), ()> { + match 42 { + 0 => drop(foo()?), // drop is needed because we only care about side-effects + 1 => bar(), + _ => (), // doing nothing (no side-effects needed here) + } + Ok(()) + } +} diff --git a/tests/ui/lint/dropping_references.rs b/tests/ui/lint/dropping_references.rs index 0d5d484f451..bb02cb75a90 100644 --- a/tests/ui/lint/dropping_references.rs +++ b/tests/ui/lint/dropping_references.rs @@ -97,3 +97,22 @@ fn issue10122(x: u8) { _ => (), } } + +fn issue112653() { + fn foo() -> Result<&'static u8, ()> { + println!("doing foo"); + Ok(&0) // result is not always useful, the side-effect matters + } + fn bar() { + println!("doing bar"); + } + + fn stuff() -> Result<(), ()> { + match 42 { + 0 => drop(foo()?), // drop is needed because we only care about side-effects + 1 => bar(), + _ => (), // doing nothing (no side-effects needed here) + } + Ok(()) + } +} |
