Skip to content

Incorrect coherence diagnostic #55752

Closed
Closed
@gnzlbg

Description

@gnzlbg
struct MyError;

impl From<i32> for Result<(), MyError> {
    fn from(x: i32) -> Self {
        if x == 0 { Ok(()) } else { Err(MyError) }
    }
}

fn main() {}

(Playground)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions