Skip to content

Add suggestions for must_implement_one_of - #160106

Open
joshtriplett wants to merge 3 commits into
rust-lang:mainfrom
joshtriplett:must-implement-one-of-suggestions
Open

Add suggestions for must_implement_one_of#160106
joshtriplett wants to merge 3 commits into
rust-lang:mainfrom
joshtriplett:must-implement-one-of-suggestions

Conversation

@joshtriplett

Copy link
Copy Markdown
Member

As with the suggestions for mandatory trait methods, provide suggestions for must_implement_one_of, which include the signatures of the trait methods. This makes it easy to copy-paste the signatures into the impl block.

Invoke the same logic from check_drop_xor_pin_drop, to provide suggestions with the signatures of drop and pin_drop.

Using #106643 (read/read_buf) as an example, without this change, the diagnostics look like this:

error[E0046]: not all trait items implemented, missing one of: `read`, `read_buf`
 --> src/main.rs:3:1
  |
3 | impl std::io::Read for R {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ missing one of `read`, `read_buf` in implementation

For more information about this error, try `rustc --explain E0046`.

With this change, they include suggestions:

error[E0046]: not all trait items implemented, missing one of: `read`, `read_buf`
 --> src/main.rs:3:1
  |
3 | impl std::io::Read for R {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ missing one of `read`, `read_buf` in implementation
  |
  = help: implement the missing item: `fn read(&mut self, _: &mut [u8]) -> Result<usize, std::io::Error> { todo!() }`
  = help: implement the missing item: `fn read_buf(&mut self, _: BorrowedCursor<'_, u8>) -> Result<(), std::io::Error> { todo!() }`

For more information about this error, try `rustc --explain E0046`.

…span

`missing_items_err` has logic to figure out where in the impl to insert
suggestions. Factor that logic out into a function to support reusing
it.
`missing_items_err` has logic to compute a set of suggestions regarding
the missing items. Factor that logic out into a function to support
reusing it.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2026
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 74 candidates
  • Random selection from 17 candidates

@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r? me

Thanks, great idea.

Can you also add a rustfix test?

View changes since this review

Comment thread compiler/rustc_hir_analysis/src/check/mod.rs
#[suggestion(
"implement the missing item: `{$snippet}`",
style = "hidden",
applicability = "has-placeholders",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be correct now

Suggested change
applicability = "machine-applicable"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Technically the inserted suggestions would compile, but would definitively make the code incorrect, because they include todo!() placeholders in them. So, unless I'm misunderstanding, I don't think these qualify as machine-applicable.

@rustbot rustbot assigned mejrs and unassigned chenyukang Jul 29, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2026
@joshtriplett
joshtriplett force-pushed the must-implement-one-of-suggestions branch from 2e10c49 to de1a020 Compare July 29, 2026 04:39
@rust-log-analyzer

This comment has been minimized.

As with the suggestions for mandatory trait methods, provide suggestions
for `must_implement_one_of`, which include the signatures of the trait
methods. This makes it easy to copy-paste the signatures into the impl
block.

Invoke the same logic from `check_drop_xor_pin_drop`, to provide
suggestions with the signatures of `drop` and `pin_drop`.

Without this change:
```
error[E0046]: not all trait items implemented, missing one of: `read`, `read_buf`
 --> src/main.rs:3:1
  |
3 | impl std::io::Read for R {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ missing one of `read`, `read_buf` in implementation

For more information about this error, try `rustc --explain E0046`.
```

With this change:
```
error[E0046]: not all trait items implemented, missing one of: `read`, `read_buf`
 --> src/main.rs:3:1
  |
3 | impl std::io::Read for R {
  | ^^^^^^^^^^^^^^^^^^^^^^^^ missing one of `read`, `read_buf` in implementation
  |
  = help: implement the missing item: `fn read(&mut self, _: &mut [u8]) -> Result<usize, std::io::Error> { todo!() }`
  = help: implement the missing item: `fn read_buf(&mut self, _: BorrowedCursor<'_, u8>) -> Result<(), std::io::Error> { todo!() }`

For more information about this error, try `rustc --explain E0046`.
```
@joshtriplett
joshtriplett force-pushed the must-implement-one-of-suggestions branch from de1a020 to bf8708e Compare July 29, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants