You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[`generic_assert`] Avoid constant environments
cc rust-lang#44838
This PR is a work in progress. Requesting an early perf run to evaluate possible impacts.
The `generic_assert` feature captures variables for printing purposes.
```rust
fn foo() {
let elem = 1i32;
assert!(&elem);
}
# Expansion
fn foo() {
let elem = 1i32;
{
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable};
let mut __capture0 = ::core::asserting::Capture::new();
let __local_bind0 = &elem;
if (!&*__local_bind0) {
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
{
::std::rt::panic_fmt(format_args!("Assertion failed: &elem\nWith captures:\n elem = {0:?}\n", __capture0));
}
}
};
}
```
The problem is that such a thing is complicated in constant environments. At the current time only strings are allowed and a full support parity with non-constant environments is not, as far as I can tell, visible in the foreseen future.
```rust
fn foo() {
// !!! ERROR !!!
const {
let elem = 1i32;
assert!(&elem);
}
}
```
Therefore, `generic_assert` will not be triggered in constant environment through an `is_in_const_env` variable flag created in the `rustc_parse` crate.
0 commit comments