Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0371.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ trait Foo { fn foo(&self) { } }
trait Bar: Foo { }
trait Baz: Bar { }

impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
impl Baz for Bar { } // Note: This is OK
impl Bar for dyn Baz { } // error, `Baz` implements `Bar` by definition
impl Foo for dyn Baz { } // error, `Baz` implements `Bar` which implements `Foo`
impl Baz for dyn Baz { } // error, `Baz` (trivially) implements `Baz`
```

This is okay, because `Bar` does not implement `Baz` by definition:

```
# trait Foo { fn foo(&self) { } }
# trait Bar: Foo { }
# trait Baz: Bar { }
impl Baz for dyn Bar { } // Note: This is OK
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pull this last one out into a separate block that is not compile_error, we make sure it actually doesn't error.

You can render it nicely by putting # in front of the duplicated definition lines (you'll need to duplicate the trait defs into the new block)

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Mostly for future reference,) that should catch the (in this case only warnings IIRC) that were emitted as well in the success case I assume?

```

When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
Expand Down
Loading