Wrong error emitted with multiple traits in return position of trait function
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
pub struct Bar<T: Foo> {}
impl<T> Bar<T>
where
T: Foo,
{
pub fn dumb(&self) {}
}
pub trait Foo {
fn qux(bar: &Bar<impl Foo>) -> impl Send + Sync;
}
pub struct Baz;
impl Foo for Baz {
fn qux(bar: &Bar<impl Foo>) -> impl Send {
bar.dumb();
}
}
fn main() {}
I expected to see this happen:
error[E0392]: type parameter `T` is never used
--> src/main.rs:1:16
|
1 | pub struct Bar<T: Foo> {}
| ^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
Instead, this happened:
error[E0283]: type annotations needed
--> src/main.rs:18:13
|
18 | bar.dumb();
| ^^^^ cannot infer type for type parameter `T`
|
= note: cannot satisfy `_: Foo`
= help: the trait `Foo` is implemented for `Baz`
note: required by a bound in `Bar::<T>::dumb`
--> src/main.rs:5:8
|
5 | T: Foo,
| ^^^ required by this bound in `Bar::<T>::dumb`
6 | {
7 | pub fn dumb(&self) {}
| ---- required by a bound in this associated function
on nightly I get both errors but only the expected error (E0392) should appear. On stable I only get the latter (E0283).
E0283 is incorrect since the type of bar is annotated in the function signature.
If E0392 is fixed by adding PhantomData both errors disappear as expected.
Meta
rustc --version --verbose (stable):
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
rustc --version --verbose (nightly):
rustc 1.78.0-nightly (9c3ad802d 2024-03-07)
binary: rustc
commit-hash: 9c3ad802d9b9633d60d3a74668eb1be819212d34
commit-date: 2024-03-07
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
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 reproducing the provided example with the stable and nightly rustc versions listed in the issue, comparing the E0392 and E0283 diagnostics. Investigate the compiler paths handling unused generic parameters and multiple impl Trait return bounds; done means the example reports only the expected E0392 error, with no incorrect E0283 diagnostic.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100