Closed
Description
I tried this code playground
struct MyValue;
struct MyError(u32);
impl MyError {
#[allow(dead_code)]
fn new(n: u32) -> Self {
Self(n)
}
}
impl std::str::FromStr for MyValue {
type Err = MyError;
fn from_str(_s: &str) -> Result<Self, Self::Err> {
// -------- THIS DOES NOT COMPILE --------
Err(Self::Err(42))
// --------- THESE COMPILE FINE ----------
// Err(Self::Err { 0: 42 })
// Err(Self::Err::new(42))
// Err(MyError(42))
}
}
fn main() {
assert!("x".parse::<MyValue>().is_err());
}
I expected to see this happen: it should compile
Instead, this happened:
error[E0599]: no associated item named `Err` found for struct `MyValue` in the current scope
--> src/main.rs:15:19
|
1 | struct MyValue;
| -------------- associated item `Err` not found for this struct
...
15 | Err(Self::Err(42))
| ^^^ associated item not found in `MyValue`
Meta
rustc --version --verbose
:
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
This might be related to #71054