-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of errorneous constant can be omitted on nightly and beta #67083
Comments
Oh oh. Investigating... |
Wild guess: const prop based on miri does not actually read from zst constants... and confirmed by making the constant's type i32 instead of () |
Interesting: just changing type to trait ZeroSized: Sized {
#[deny(const_err)]
const I_AM_ZERO_SIZED: i32;
fn requires_zero_size(self);
}
impl<T: Sized> ZeroSized for T {
const I_AM_ZERO_SIZED: i32 = [0][std::mem::size_of::<Self>()];
fn requires_zero_size(self) {
#![deny(const_err)]
let _unused = Self::I_AM_ZERO_SIZED;
println!("requires_zero_size called");
}
}
fn main() {
().requires_zero_size();
42_u32.requires_zero_size();
} Making a slight change:
...And this compiles again on beta and nightly. |
It's not const prop. Const prop doesn't know about this yet. If you allow all the lints on stable, you get a segfault in the running program. I think monomorphization needs to hard error on invalid constants. Trying out now |
Notice that seems quite fragile though, as this is only prevented by a deny-by-default lint. With |
Usage of a broken constant is not just a lint, it is a hard error in monomorphic code. What you are thinking about is promotion, where we never report a hard error. Using a constant whose evaluation would fail is a hard error, it's just that declaring said constant and not using it will just cause warnings. |
Ensure that we get a hard error on generic ZST constants if their bod… …y causes an error during evaluation cc rust-lang#67083 (does not fix because we still need the beta backport) r? @wesleywiser cc @RalfJung
triage: P-high, removing nomination |
Consider the following code:
The intent of code is to prevent
requires_zero_size
from being called on types with non-zero size (duh). This goal is achieved on stable: trying to compile this code with stable compiler (1.39.0) gives the following error:I expected the same with some newer unstable versiosns. However, this code compiles just fine on latest beta (2019-12-02 1463fedbddfc0ee087ec) and latest nightly (2019-12-05 710a362dc7634fce4288) at the moment.
Compiling in debug vs release gives no difference in behaviour.
The text was updated successfully, but these errors were encountered: