Skip to content

Add suggestions for must_implement_one_of - #160106

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
joshtriplett:must-implement-one-of-suggestions
Jul 30, 2026
Merged

Add suggestions for must_implement_one_of#160106
rust-bors[bot] merged 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
Comment thread compiler/rustc_hir_analysis/src/diagnostics.rs
@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

@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.

@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bf8708e has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 29, 2026
@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

⚠️ A new commit 84087a82ef87ed82b82271359ea46cc1d4ccbaa1 was pushed.

This pull request was unapproved.

@joshtriplett
joshtriplett force-pushed the must-implement-one-of-suggestions branch from 84087a8 to bf8708e Compare July 29, 2026 15:44
@joshtriplett

Copy link
Copy Markdown
Member Author

(Sorry, pushed to the wrong branch.)

@joshtriplett

Copy link
Copy Markdown
Member Author

@bors r=mejrs

@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bf8708e has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 29, 2026
…-suggestions, r=mejrs

Add suggestions for `must_implement_one_of`

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 rust-lang#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`.
```
rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
Rollup of 17 pull requests

Successful merges:

 - #159014 ([rustdoc] Do not take `doc(cfg())` into account when filtering doctests)
 - #159130 (a bit optimize four-digit chunks in integer formatting)
 - #159592 (core: implement bounded random sampling)
 - #159898 (Add intrinsic-test alias and set  sample rate)
 - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`)
 - #158649 (Hermit: fix `readdir()` )
 - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs)
 - #160053 (test: add test suite for the 85681 issue)
 - #160087 (Add regression test for nested associated-type projection ICE)
 - #160090 (rustc_resolve: Further reduce mutability in resolver)
 - #160099 (Resolver: split module resolutions into local and external resolutions)
 - #160106 (Add suggestions for `must_implement_one_of`)
 - #160117 (Remove unnecessary format usage)
 - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once)
 - #160142 (bootstrap: remove use-lld config alias)
 - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N))
 - #160151 (Mark a doctest as requiring unwinding)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 29, 2026
…-suggestions, r=mejrs

Add suggestions for `must_implement_one_of`

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 rust-lang#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`.
```
rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
Rollup of 18 pull requests

Successful merges:

 - #159130 (a bit optimize four-digit chunks in integer formatting)
 - #159592 (core: implement bounded random sampling)
 - #159898 (Add intrinsic-test alias and set  sample rate)
 - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`)
 - #158649 (Hermit: fix `readdir()` )
 - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs)
 - #160053 (test: add test suite for the 85681 issue)
 - #160087 (Add regression test for nested associated-type projection ICE)
 - #160090 (rustc_resolve: Further reduce mutability in resolver)
 - #160099 (Resolver: split module resolutions into local and external resolutions)
 - #160106 (Add suggestions for `must_implement_one_of`)
 - #160117 (Remove unnecessary format usage)
 - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once)
 - #160139 (iter: specialize Take::count using advance_by)
 - #160142 (bootstrap: remove use-lld config alias)
 - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N))
 - #160151 (Mark a doctest as requiring unwinding)
 - #160166 (Use correct feature gates for `f16`/`f128` `From` impls)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 29, 2026
…-suggestions, r=mejrs

Add suggestions for `must_implement_one_of`

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 rust-lang#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`.
```
rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #159898 (Add intrinsic-test alias and set  sample rate)
 - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`)
 - #158649 (Hermit: fix `readdir()` )
 - #158693 (Add type-check to offload intrinisc calls)
 - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #160053 (test: add test suite for the 85681 issue)
 - #160087 (Add regression test for nested associated-type projection ICE)
 - #160090 (rustc_resolve: Further reduce mutability in resolver)
 - #160099 (Resolver: split module resolutions into local and external resolutions)
 - #160106 (Add suggestions for `must_implement_one_of`)
 - #160117 (Remove unnecessary format usage)
 - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once)
 - #160139 (iter: specialize Take::count using advance_by)
 - #160142 (bootstrap: remove use-lld config alias)
 - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N))
 - #160151 (Mark a doctest as requiring unwinding)
 - #160166 (Use correct feature gates for `f16`/`f128` `From` impls)
rust-bors Bot pushed a commit that referenced this pull request Jul 30, 2026
Rollup of 20 pull requests

Successful merges:

 - #157669 (cfi: add diag mode support)
 - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`)
 - #158649 (Hermit: fix `readdir()` )
 - #158693 (Add type-check to offload intrinisc calls)
 - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #160053 (test: add test suite for the 85681 issue)
 - #160087 (Add regression test for nested associated-type projection ICE)
 - #160090 (rustc_resolve: Further reduce mutability in resolver)
 - #160099 (Resolver: split module resolutions into local and external resolutions)
 - #160101 (Add missing `needs-unwind` annotation to `add-spawn-hook-reentrancy-159923` test)
 - #160106 (Add suggestions for `must_implement_one_of`)
 - #160117 (Remove unnecessary format usage)
 - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once)
 - #160139 (iter: specialize Take::count using advance_by)
 - #160142 (bootstrap: remove use-lld config alias)
 - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N))
 - #160151 (Mark a doctest as requiring unwinding)
 - #160166 (Use correct feature gates for `f16`/`f128` `From` impls)
 - #160178 (Remove unused `va_start` intrinsic)
rust-bors Bot pushed a commit that referenced this pull request Jul 30, 2026
Rollup of 20 pull requests

Successful merges:

 - #157669 (cfi: add diag mode support)
 - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`)
 - #158649 (Hermit: fix `readdir()` )
 - #158693 (Add type-check to offload intrinisc calls)
 - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #160053 (test: add test suite for the 85681 issue)
 - #160087 (Add regression test for nested associated-type projection ICE)
 - #160090 (rustc_resolve: Further reduce mutability in resolver)
 - #160099 (Resolver: split module resolutions into local and external resolutions)
 - #160101 (Add missing `needs-unwind` annotation to `add-spawn-hook-reentrancy-159923` test)
 - #160106 (Add suggestions for `must_implement_one_of`)
 - #160117 (Remove unnecessary format usage)
 - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once)
 - #160139 (iter: specialize Take::count using advance_by)
 - #160142 (bootstrap: remove use-lld config alias)
 - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N))
 - #160151 (Mark a doctest as requiring unwinding)
 - #160166 (Use correct feature gates for `f16`/`f128` `From` impls)
 - #160178 (Remove unused `va_start` intrinsic)
@rust-bors
rust-bors Bot merged commit e56dd19 into rust-lang:main Jul 30, 2026
26 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 30, 2026
rust-timer added a commit that referenced this pull request Jul 30, 2026
Rollup merge of #160106 - joshtriplett:must-implement-one-of-suggestions, r=mejrs

Add suggestions for `must_implement_one_of`

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`.
```
@joshtriplett
joshtriplett deleted the must-implement-one-of-suggestions branch July 30, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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