-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Confusing 'unreachable code' error message when macro is involved #64590
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.
This code:
Gives the following warning:
This warning is misleading - it suggests that the entire
returnstatement, including the call toearly_return!()is unreachable.This also occurs in the more 'obviously wrong' case of:
In general, it could be hard to decide what kind of warning message to generate. I think there are two things we could do to improve error messages in most cases:
!) was generated by a macro, explicitly indicate this in the warning. This should help make it clear to the user that there is hidden control flow going on.returnstatements. If possible, try to detect that the cause of the unreachability was 'inside' of thereturn, and add a note pointing directly at it (e.g. 'the expression ' unconditionally diverges')