Do not pretend that return is not significant

A `return` in an expression makes it divergent and cannot be removed
blindly. While this stripping might have been introduced as a way to
catch more cases, it was improperly used, and no tests exhibit a
failure when this special handling is removed.
This commit is contained in:
Samuel Tardieu 2025-05-08 15:55:02 +02:00
parent f88f9a9dc5
commit 82f8b1ccd0
4 changed files with 42 additions and 15 deletions

View file

@ -301,4 +301,16 @@ pub fn issue13574() -> Option<()> {
None
}
fn issue14754(t: Result<i32, &'static str>) -> Result<i32, &'static str> {
let _ = match t {
Ok(v) => Ok::<_, &'static str>(v),
err @ Err(_) => return err,
};
println!("Still here");
let x = t;
//~^^^^ needless_match
println!("Still here");
x
}
fn main() {}

View file

@ -364,4 +364,19 @@ pub fn issue13574() -> Option<()> {
None
}
fn issue14754(t: Result<i32, &'static str>) -> Result<i32, &'static str> {
let _ = match t {
Ok(v) => Ok::<_, &'static str>(v),
err @ Err(_) => return err,
};
println!("Still here");
let x = match t {
Ok(v) => Ok::<_, &'static str>(v),
err @ Err(_) => err,
};
//~^^^^ needless_match
println!("Still here");
x
}
fn main() {}

View file

@ -151,5 +151,15 @@ LL | | None
LL | | }
| |_________^ help: replace it with: `A`
error: aborting due to 14 previous errors
error: this match expression is unnecessary
--> tests/ui/needless_match.rs:373:13
|
LL | let x = match t {
| _____________^
LL | | Ok(v) => Ok::<_, &'static str>(v),
LL | | err @ Err(_) => err,
LL | | };
| |_____^ help: replace it with: `t`
error: aborting due to 15 previous errors