-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
(edition 2015) "patterns aren't allowed in methods without bodies" even though the method has a body #143113
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-edition-2015Area: The 2015 edition (the first edition)Area: The 2015 edition (the first edition)D-editionDiagnostics: An error or lint that should account for edition differences.Diagnostics: An error or lint that should account for edition differences.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-edition-2015Area: The 2015 edition (the first edition)Area: The 2015 edition (the first edition)D-editionDiagnostics: An error or lint that should account for edition differences.Diagnostics: An error or lint that should account for edition differences.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Code
Current output
Desired output
Rationale and extra context
this error only exists because, in edition 2015, trait functions can be like
fn f(());without even giving a pattern. to account for the syntactic ambiguity of a "pattern or a type in this position", the patterns are very restricted. but, even if a body is provided, the pattern is still optional.fn f(u32) {}is perfectly fine in this edition, even though you can't name that parameter in the function body.the error message incorrectly assumes that this ambiguity can only exist if there is no method body, when in fact it exists in both cases.
additionally, the same error message is printed in a function pointer type like
fn((): ()), where it is ALSO wrong. however,fn(&_: ())(or with any pattern that is allowed in an edition-2015-trait-body) will print a much better error message (patterns aren't allowed in function pointer types); so thefn((): ())case should be changed to match thefn(&_: ())case.Rust Version