rust/tests
bors 7bb4f0889e Auto merge of #104087 - nbdd0121:const, r=scottmcm
Stabilise inline_const

# Stabilisation Report

## Summary

This PR will stabilise `inline_const` feature in expression position. `inline_const_pat` is still unstable and will *not* be stabilised.

The feature will allow code like this:
```rust
foo(const { 1 + 1 })
```
which is roughly desugared into
```rust
struct Foo;
impl Foo {
    const FOO: i32 = 1 + 1;
}
foo(Foo::FOO)
```

This feature is from https://github.com/rust-lang/rfcs/pull/2920 and is tracked in #76001 (the tracking issue should *not* be closed as it needs to track inline const in pattern position). The initial implementation is done in #77124.

## Difference from RFC

There are two major differences (enhancements) as implemented from the RFC. First thing is that the RFC says that the type of an inline const block inferred from the content *within* it, but we currently can infer the type using the information from outside the const block as well. This is a frequently requested feature to the initial implementation (e.g. #89964). The inference is implemented in #89561 and is done by treating inline const similar to a closure and therefore share inference context with its parent body.

This allows code like:
```rust
let v: Vec<i32> = const { Vec::new() };
```

Another enhancement that differs from the RFC is that we currently allow inline consts to reference generic parameters. This is implemented in #96557.

This allows code like:
```rust
fn create_none_array<T, const N: usize>() -> [Option<T>; N] {
    [const { None::<T> }; N]
}
```

This enhancement also makes inline const usable as static asserts:

```rust
fn require_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) }
}
```

## Documentation

Reference: rust-lang/reference#1295

## Unresolved issues

We still have a few issues that are not resolved, but I don't think it necessarily has to block stabilisation:
* expr fragment specifier issue: #86730
* ~~`const {}` behaves similar to `async {}` but not to `{}` and `unsafe {}` (they are treated as `ExpressionWithoutBlock` rather than `ExpressionWithBlock`): https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/const.20blocks.20differ.20from.20normal.20and.20from.20unsafe.20blocks/near/290229453~~

## Tests

There are a few tests in https://github.com/rust-lang/rust/tree/master/src/test/ui/inline-const
2024-04-24 17:23:03 +00:00
..
assembly also update windows slack-protector tests 2024-04-22 23:45:04 -04:00
auxiliary
codegen Fix tests and bless 2024-04-24 13:12:33 +01:00
codegen-units
coverage Error on using yield without also using #[coroutine] on the closure 2024-04-24 08:05:29 +00:00
coverage-run-rustdoc
crashes Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnr 2024-04-23 17:25:16 +02:00
debuginfo Error on using yield without also using #[coroutine] on the closure 2024-04-24 08:05:29 +00:00
incremental Add missing -Zquery-dep-graph to the spike-neg incr comp tests 2024-04-06 13:36:16 +00:00
mir-opt Fix tests and bless 2024-04-24 13:12:33 +01:00
pretty Fix tests and bless 2024-04-24 13:12:33 +01:00
run-make Auto merge of #124112 - beetrees:incremental-os-str, r=Nadrieril 2024-04-22 04:00:58 +00:00
run-make-fulldeps
run-pass-valgrind
rustdoc Auto merge of #118441 - GuillaumeGomez:display-stability-version, r=rustdoc 2024-04-19 14:17:29 +00:00
rustdoc-gui Rollup merge of #124197 - GuillaumeGomez:move-duplicated-code, r=notriddle 2024-04-23 06:24:56 +02:00
rustdoc-js rustdoc-search: single result for items with multiple paths 2024-04-08 17:07:14 -07:00
rustdoc-js-std rustdoc-search: fix description on aliases in results 2024-04-18 22:21:29 -07:00
rustdoc-json
rustdoc-ui Rollup merge of #122591 - gurry:122162-impl-type-binding-suggestion, r=fmease 2024-04-23 17:25:14 +02:00
ui Auto merge of #104087 - nbdd0121:const, r=scottmcm 2024-04-24 17:23:03 +00:00
ui-fulldeps Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwco 2024-04-23 17:25:17 +02:00
COMPILER_TESTS.md