Confusing 'unreachable code' error message when macro is involved #64590
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This code:
Gives the following warning:
This warning is misleading - it suggests that the entire
return
statement, 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.return
statements. 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')The text was updated successfully, but these errors were encountered: