]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #66170 - ecstatic-morse:hir-const-check, r=Centril,oli-obk
authorbors <bors@rust-lang.org>
Wed, 13 Nov 2019 20:10:54 +0000 (20:10 +0000)
committerbors <bors@rust-lang.org>
Wed, 13 Nov 2019 20:10:54 +0000 (20:10 +0000)
Add a HIR pass to check consts for `if`, `loop`, etc.

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)


Trivial merge