Closed
Description
struct MyError;
impl From<i32> for Result<(), MyError> {
fn from(x: i32) -> Self {
if x == 0 { Ok(()) } else { Err(MyError) }
}
}
fn main() {}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> src/main.rs:3:1
|
3 | impl From<i32> for Result<(), MyError> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
|
= note: the impl does not reference any types defined in this crate
= note: define and implement a trait or new type instead
error: aborting due to previous error
For more information about this error, try `rustc --explain E0117`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
This is incorrect because the error message states:
the impl does not reference any types defined in this crate
but the impl
does reference one type defined in this crate: MyError
.