E0562 should mention impl Trait in argument position #80476
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-impl-trait
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
C-bug
Category: This is a bug.
D-incorrect
Diagnostics: A diagnostic that is giving misleading or incorrect information.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
impl Trait
as a type is permitted in function parameter lists. However, the error message E0562 incorrectly states that it is only permitted in function or inherent method return positions.Being precise in this message will assist beginners (such as myself a few months ago) in understanding the boundaries of the language. Particularly, one might reasonably imagine equivalence between a function's parameter list and a single parameter whose type is a
struct
bundling several parameters, butimpl Trait
is available in the former and not the latter — whereas the error message implies that it is allowed in neither of those places.Tangentially, it would be neat if the compiler gave suggestions to rewrite disallowed
impl Trait
as either an explicit parameter,struct C<S: impl Into<String>> { x: S }
, or (especially in the case ofimpl Into
) a constructor function, but that's much more work and more dependent on the context and perhaps even the specific trait.Meta
This occurs on both stable
1.48.0
and nightly1.50.0-nightly (2020-12-22 bb1fbbf84455fbad9afd)
, and the message is present in the same form in the current source code.The text was updated successfully, but these errors were encountered: