Paths to extension trait functions in diagnostics can be confusing
Open
Nobody has claimed this yet.
A-diagnostics
C-bug
D-confusing
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following code compiles with a warning (on take function):
use std::ops::Deref;
pub trait MutexGuard<T>: Deref<Target = T> /*+ DerefMut<Target = T>*/ {
fn set(&mut self, value: T);
fn take(&self) -> Option<T>;
}
impl<T> MutexGuard<T> for tokio::sync::MutexGuard<'_, T> {
fn set(&mut self, value: T) {
*self.deref_mut() = value;
}
fn take(&self) -> Option<T> {
tokio::sync::MutexGuard::take(self)
}
}
warning: function cannot return without recursing
--> src/lib.rs:13:5
|
13 | fn take(&self) -> Option<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
14 | tokio::sync::MutexGuard::take(self)
| ----------------------------------- recursive call site
|
= help: a `loop` may express intention better if this is on purpose
= note: `#[warn(unconditional_recursion)]` on by default
I specified a "full path" (tokio::sync::MutexGuard::take) to take function and it should use that path rather than using a trait.
$ rustc --version
rustc 1.78.0 (9b00956e5 2024-04-29)
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 with the provided src/lib.rs reproduction and the rustc 1.78.0 behavior. Trace how the fully qualified tokio::sync::MutexGuard::take path is resolved in this context, then verify that the warning no longer treats the call as recursive while preserving the unconditional-recursion diagnostic for genuinely recursive calls.
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
- 42/100