Yeah, while it's not exactly the same as return Err(…) (because in a try block it exits the block, not the enclosing function), I have to generally agree that giving the same concept an (N+1)-th different syntax is unnecessary feature bloat.
(But most probably, this sort of discussion belongs on IRLO, not here.)
There's an experimental feature called try blocks, intended to make it easier to work with Result. The idea is that the last expression in the block gets wrapped in Ok and is the value of the block (so try { 6 } is the same as Ok(6)), return inside the block still leaves the function, ? causes the block's value to be the Err case if there is one, and yeet is bikeshed syntax for ending the block immediately and making the block's value an Err case.
The intended use is to write something like:
let file_sum = try {
if filename == "/etc/passwd" {
do yeet Errors::NotThatDumb;
}
let file = std::io::BufReader::new(std::fs::File::open(filename)?);
let mut sum = 0u64;
for line in file.lines() {
let line = line?;
sum += line.parse::<u64>()?;
}
sum
};
Where you still have access to "good" error handling, via ?, you can use the yeet syntax to throw a special error case, but you don't need to Ok-wrap your return value, and you don't have to deal with either Result combinators or with trying to not return early from the function as a whole.