-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for RFC 2342, "Allow if
and match
in constants"
#49146
Comments
|
@eddyb A good starting point would probably be to take my |
This comment has been minimized.
This comment has been minimized.
@mark-i-m Alas no. I think @eddyb has been very busy indeed, because I've not even been able to ping him on IRC for the last few weeks hah. Sadly my const-qualif branch doesn't even compile since I last rebased it over master. (I don't believe I've pushed yet though.)
|
Okay, funnily enough, I rebased again just today and it seems to be building all fine now! Looks like there was a regression, and it just got fixed. All over to @eddyb now. |
@alexreg Sorry, I've switched to a local sleep schedule and I see you've pinged me when I wake up but then you're offline all day when I'm awake (ugh timezones). |
@eddyb That's alright heh. You must be off to bed early, since I'm usually on from 8:00PM GMT, but it's all good! :-) |
Make `Vec::new` a `const fn` `RawVec::empty/_in` are a hack. They're there because `if size_of::<T> == 0 { !0 } else { 0 }` is not allowed in `const` yet. However, because `RawVec` is unstable, the `empty/empty_in` constructors can be removed when rust-lang#49146 is done...
I'm really sorry, took me a while to realize that the series of patches in question requires removing #![feature(const_fn)]
const fn read<T: Copy>(x: &T) -> T { *x }
static FOO: u32 = read(&BAR);
static BAR: u32 = 5;
fn main() {
println!("{}", FOO);
} This is not detected statically, instead So I think reading I think then we can keep statically denying mentioning Do we need an RFC for this? |
Sounds fair w.r.t. reading from statics. Doubt it needs an RFC, maybe just a crater run, but then I’m probably not the best one to say. |
Note that we wouldn't be restricting anything, we'd be relaxing a restriction that's already broken. |
Oh, I misread. So const evaluation would still be sound, just not referentially transparent? |
The last paragraph describes a referentially transparent approach (but we lose that property if we start allowing mentioning |
Well, "dangling pointer" sure sounds like a soundness issue, but I'll trust you on this! |
"dangling pointer" is a bad error message, that's just miri forbidding reading from (from IRC) To summarize, referentially transparent |
I do like preserving referential transparency so @eddyb's idea sounds fantastic! |
Yeah I’m pro making const fns pure as well. |
Please note that certain seemingly harmless plans could ruin referential transparency, e.g.: let x = 0;
let non_deterministic = &x as *const _ as usize;
if non_deterministic.count_ones() % 2 == 0 {
// do one thing
} else {
// do a completely different thing
} This would fail with a miri error at compile-time, but would be non-deterministic at runtime (because we can't mark that memory address as "abstract" like miri can). EDIT: @Centril had the idea of making certain raw pointer operations (such as comparisons and casts to integers) |
Depends what you mean by "harmless"... I can certainly see reason we'd want to ban such non-deterministic behaviour. |
lint: deny incoherent_fundamental_impls by default Warn the ecosystem of the pending intent-to-disallow in #49799. There are 4 ICEs on my machine, look unrelated (having happened before in #49146 (comment)) ```rust thread 'main' panicked at 'assertion failed: position <= slice.len()', libserialize/leb128.rs:97:1 ``` ``` [run-pass] run-pass/allocator/xcrate-use2.rs [run-pass] run-pass/issue-12133-3.rs [run-pass] run-pass/issue-32518.rs [run-pass] run-pass/trait-default-method-xc-2.rs ``` r? @nikomatsakis
It would be fantastic if work were continued on this. |
async-std started failing to compile on 1.45 due to a new indirect dependency 'socket2' which in version 0.4.0 fails with the following error: Compiling socket2 v0.4.0 error[E0658]: `match` is not allowed in a `const fn` --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.0/src/lib.rs:156:9 | 156 | / match address { 157 | | SocketAddr::V4(_) => Domain::IPV4, 158 | | SocketAddr::V6(_) => Domain::IPV6, 159 | | } | |_________^ | = note: see issue #49146 <rust-lang/rust#49146> for more information Compiling signal-hook-registry v1.3.0 error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. error: could not compile `socket2`.
async-std started failing to compile on 1.45 due to a new indirect dependency 'socket2' which in version 0.4.0 fails with the following error: Compiling socket2 v0.4.0 error[E0658]: `match` is not allowed in a `const fn` --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.0/src/lib.rs:156:9 | 156 | / match address { 157 | | SocketAddr::V4(_) => Domain::IPV4, 158 | | SocketAddr::V6(_) => Domain::IPV6, 159 | | } | |_________^ | = note: see issue #49146 <rust-lang/rust#49146> for more information Compiling signal-hook-registry v1.3.0 error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. error: could not compile `socket2`.
socket crate became incompatible with Alpine 3.12 toolchain (rust 1.44) error[E0658]: `match` is not allowed in a `const fn` --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.0/src/lib.rs:156:9 | 156 | / match address { 157 | | SocketAddr::V4(_) => Domain::IPV4, 158 | | SocketAddr::V6(_) => Domain::IPV6, 159 | | } | |_________^ | = note: see issue #49146 <rust-lang/rust#49146> for more information
I need it to enable some attributes that are otherwise not available, this all is to avoid error[E0658]: `if` is not allowed in a `const` --> /home/mjost/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.43/src/int/specialized_div_rem/mod.rs:84:12 | 84 | } else if cfg!(any(target_arch = "sparc", target_arch = "sparc64")) { | ____^ 85 | | // LZD or LZCNT on SPARC only exists for the VIS 3 extension and later. 86 | | cfg!(target_feature = "vis3") 87 | | } else if cfg!(any(target_arch = "riscv32", target_arch = "riscv64")) { ... | 92 | | true 93 | | } | |___^ | = note: see issue #49146 <rust-lang/rust#49146> for more information = help: add `#![feature(const_if_match)]` to the crate attributes to enable
I was able to fix this error by running |
For some reason ran into rust-lang/rust#65721 and rust-lang/rust#49146 along with some other misc compiler errors and lints Feels like every time I come back to this project the rust versions get out of wack
This is a tracking issue for the RFC "Allow
if
andmatch
in constants" (rust-lang/rfcs#2342).Please redirect constification of specific functions or issues you want to report to fresh issues and label them appropriately with
F-const_if_match
so that this issues doesn't get flooded with ephemeral comments obscuring important developments.Steps:
#![feature(const_if_match)]
and#![feature(const_loop)]
#72437let
bindings in constants that use&&
and||
short circuiting operations. These are treated as&
and|
insideconst
andstatic
items right now.Unresolved questions:
None
The text was updated successfully, but these errors were encountered: