Skip to content

Add a HIR pass to check consts for if, loop, etc.#66170

Merged
bors merged 14 commits intorust-lang:masterfrom
ecstatic-morse:hir-const-check
Nov 13, 2019
Merged

Add a HIR pass to check consts for if, loop, etc.#66170
bors merged 14 commits intorust-lang:masterfrom
ecstatic-morse:hir-const-check

Conversation

@ecstatic-morse
Copy link
Copy Markdown
Contributor

@ecstatic-morse ecstatic-morse commented Nov 6, 2019

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., Goto and SwitchInt), and these often don't map back to the underlying statement as a whole. This PR is intended only to improve diagnostics once if and match become 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)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors for if and match in a const are not descriptive

8 participants