Add a HIR pass to check consts for if, loop, etc.#66170
Merged
bors merged 14 commits intorust-lang:masterfrom Nov 13, 2019
Merged
Add a HIR pass to check consts for if, loop, etc.#66170bors merged 14 commits intorust-lang:masterfrom
if, loop, etc.#66170bors merged 14 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #66125.
This PR adds a HIR pass to check for high-level control flow constructs that are forbidden in a const-context. The MIR const-checker is unable to provide good spans for these since they are lowered to control flow primitives (e.g.,
GotoandSwitchInt), and these often don't map back to the underlying statement as a whole. This PR is intended only to improve diagnostics onceifandmatchbecome commonplace in constants (behind a feature flag). The MIR const-checker will continue to operate unchanged, and will catch anything this check might miss.In this implementation, the HIR const-checking pass is run much earlier than the MIR one, so it will supersede any errors from the latter. I will need some mentoring if we wish to change this, since I'm not familiar with the diagnostics system. Moving this pass into the same phase as the MIR const-checker could also help keep backwards compatibility for items like
const _: () = loop { break; };, which are currently (erroneously?) accepted by the MIR const-checker (see #62272).r? @Centril
cc @eddyb (since they filed #62272)