Closed
Description
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0aed05fe97333e35dc688bc76eabd8ad
use std::path::Path;
fn path_starts_with<'a>(path: &'a Path) -> Option<&'a Path> {
if false {
return None;
}
return Path::new("/");
}
The current output is:
// ... standard error about type mismatch
= note: to return `impl Trait`, all returned values must be of the same type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
The error message should not message impl Trait
, because it has nothing to do with this code (from user PoV)
If I change the code to the following:
use std::path::Path;
fn path_starts_with<'a>(/*no parameter here anymore*/) -> Option<&'a Path> {
if false {
return None;
}
return Path::new("/");
}
Confusing message goes away