-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
pub trait Test {
fn into_iter(&self) -> impl Iterator<Item = Self> {
todo!() // A proper implementation will also fail
}
}
I expected to see this happen: an error message stating that impl Trait
is not allowed as part of trait declarations.
Instead, this happened: the following misleading error
error[E0562]: `impl Trait` not allowed outside of function and method return types
--> src/main.rs:3:28
|
3 | fn into_iter(&self) -> impl Iterator<Item = Self> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0562`.
This error is misleading because it states that the problem is that the keyword impl
is not being used as part of a return type, even though it is.
Meta
rustc --version --verbose
:
rustc 1.59.0-nightly (efec54529 2021-12-04)
binary: rustc
commit-hash: efec545293b9263be9edfb283a7aa66350b3acbf
commit-date: 2021-12-04
host: x86_64-pc-windows-msvc
release: 1.59.0-nightly
LLVM version: 13.0.0
Backtrace
Produces the exact same error
fmease and compiler-errors
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.