Hi,
First time contributor here, and a relative newcomer to Rust (I’ve been at it a couple of months now, I think?). I can understand wanting something nicer for functions that return Result<(), T>, like coercing an empty statement,
fn main() -> Result<(), io::Error> {
let content = read_file(&Path::new("test.txt"))?;
println!("{}", content);
}
though I understand there are probably difficulties with making that work generally.
However, I think introducing throws and throw would be a mistake, because people coming from other languages have expectations for what they mean, and Rust would be using them very differently. Error returns are not exceptions, they don’t propagate. Not only that, but the error you’re ‘throwing’ isn’t returned directly, it’s wrapped in an enum variant. You’re hiding the return type behind some syntactic sugar, which may be great when you know what you’re reading, but it’s a big speedbump for a minor syntax simplification.
All this is very confusing, and a source of friction. When I started to learn Rust, I started with the Book, one of the most frustrating things was existing terms being used for very different things (though I can’t think of other examples now, I guess that might be a good thing?), or new terms being introduced to explain concepts that already had widely-used names (looking at you, epochs
). Please don’t make that problem worse.