Closed
Description
Nightly-only ICEs are exposed on stable because array lengths are evaluated even when they are invalid:
struct Bug([u8; panic!(1)]);
This first emits an error that a feature flag is missing, but then const-evaluates the array length anyway and later leads to an ICE. This is not a stability hole (there's an error, the code will not compile), but it's an ICE on stable, so it's a bug.
While the ICE should also be fixed, the underlying problem is that we should not const-evaluate code that failed stability checking (and there are possibly other kinds of checks to which this applies as well)
@oli-obk proposed some solutions:
- poison the mir Body if const checks fail (by adding a field like https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#structfield.tainted_by_errors or by just nuking the body by replacing it with
_0 = ConstKind::Error; return;
) and thus make allow const evaluation to check if the mir Body failed the checks and bail out before doing anything- make the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.ConstQualifs.html have an
error
field similar to https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#structfield.tainted_by_errors
Cc @rust-lang/wg-const-eval