refining_impl_trait: The suggested fix does not yet take precise capturing into account.
Open
Nobody has claimed this yet.
A-diagnostics
A-impl-trait
A-lints
D-invalid-suggestion
L-refining_impl_trait
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
pub trait Trait {
fn precise_capturing(&self) -> impl use<Self> + Send;
}
impl Trait for () {
fn precise_capturing(&self) -> () {}
}
Current output
warning: impl trait in impl method signature does not match trait method signature
--> src\lib.rs:6:36
|
2 | fn precise_capturing(&self) -> impl use<Self> + Send;
| --------------------- return type from trait method defined here
...
6 | fn precise_capturing(&self) -> () {}
| ^^
|
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
= note: `#[warn(refining_impl_trait_reachable)]` on by default
help: replace the return type so that it matches the trait
|
6 - fn precise_capturing(&self) -> () {}
6 + fn precise_capturing(&self) -> impl Send {}
|
Desired output
warning: impl trait in impl method signature does not match trait method signature
--> src\lib.rs:6:36
|
2 | fn precise_capturing(&self) -> impl use<Self> + Send;
| --------------------- return type from trait method defined here
...
6 | fn precise_capturing(&self) -> () {}
| ^^
|
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
= note: `#[warn(refining_impl_trait_reachable)]` on by default
help: replace the return type so that it matches the trait
|
6 - fn precise_capturing(&self) -> () {}
6 + fn precise_capturing(&self) -> impl use<> + Send {}
|
Rationale and extra context
It's a slight inconvenience since the code won't compile after the current quick-fix is applied:
error: return type captures more lifetimes than trait definition
--> src\lib.rs:6:36
|
2 | fn precise_capturing(&self) -> impl use<Self> + Send;
| - this lifetime was captured
...
6 | fn precise_capturing(&self) -> impl Send {}
| ^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> src\lib.rs:2:36
|
2 | fn precise_capturing(&self) -> impl use<Self> + Send;
| ^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Send`
Copying it from the trait works, but requires removing Self from the use<> and occasionally more type parameters to be added.
Other cases
Rust Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-msvc
release: 1.87.0
LLVM version: 20.1.1
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the supplied src/lib.rs reproduction with the reported Rust version and compare the current and desired diagnostics. Trace the refining_impl_trait warning’s suggested replacement, then add or update coverage so the help text preserves the trait’s precise use<> captures and the suggestion compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100