diff options
| author | bors <bors@rust-lang.org> | 2019-11-13 20:10:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-13 20:10:54 +0000 |
| commit | ded5ee0013f6126f885baf5e072c20ba8b86ee6a (patch) | |
| tree | 01bfb70673480a89165ef0063a47fc5a3d37be8c /src/librustc/query/mod.rs | |
| parent | 695fe965173795f9242dfcad6d1c07d7a17b106a (diff) | |
| parent | 7552bd662f89c67c54e61e2f7c1c1979f6b510e2 (diff) | |
| download | rust-ded5ee0013f6126f885baf5e072c20ba8b86ee6a.tar.gz rust-ded5ee0013f6126f885baf5e072c20ba8b86ee6a.zip | |
Auto merge of #66170 - ecstatic-morse:hir-const-check, r=Centril,oli-obk
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)
Diffstat (limited to 'src/librustc/query/mod.rs')
| -rw-r--r-- | src/librustc/query/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index bd7b77b0abb..9bd2a933c1c 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -329,6 +329,11 @@ rustc_queries! { desc { |tcx| "checking for unstable API usage in {}", key.describe_as_module(tcx) } } + /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`). + query check_mod_const_bodies(key: DefId) -> () { + desc { |tcx| "checking consts in {}", key.describe_as_module(tcx) } + } + /// Checks the loops in the module. query check_mod_loops(key: DefId) -> () { desc { |tcx| "checking loops in {}", key.describe_as_module(tcx) } |
