diag: improvements to patterns in bare fn ptr and trait decl #143469
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR addresses two diagnostic issues.
In edition 2015, trait fn declarations with function bodies can receive the "patterns aren't allowed in methods without bodies". This behaviour is correct (in edition 2015, trait functions have only a limited subset of patterns because of syntactic ambiguity wrt optional named parameters), but the diagnostic is confusing. This PR changes the message to explain that patterns are not allowed (even with function bodies) in edition 2015.
In bare function pointers (
fn(T) -> U
), patterns are not allowed (except for_
and plain argument names). Currently, this error sometimes gives the "patterns aren't allowed in methods without bodies error". This PR ensures we always get the proper error for patterns in function pointers.rust_error_codes
docs improved per Clarify that patterns may be used in trait implementations when explaining E0642 #97282.Fixes #143113 and fixes #97282.