rust/compiler/rustc_middle/src
bors 88d69b72b4 Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-dead
Introduce `const Trait` (always-const trait bounds)

Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone.

Not sure if this needs t-lang sign-off though.

(\*):

```rs
#![feature(const_trait_impl, effects, generic_const_exprs)]

fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ }

struct Store<T: const Trait>
where
    Type<{ T::generate() }>:,
{
    field: Type<{ T::generate() }>,
}
```

Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`.

```rs
#![feature(const_trait_impl, effects, generic_const_items)]

const DEFAULT<T: const Default>: T = T::default();
```

Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable.
Supersedes #117530.

---

cc `@oli-obk`

As discussed
r? fee1-dead (or compiler)
2023-12-27 19:24:31 +00:00
..
dep_graph Reduce exposure of things. 2023-11-16 16:49:22 +11:00
hir Unify SourceFile::name_hash and StableSourceFileId 2023-12-19 22:34:26 +01:00
hooks Rename hook. 2023-11-01 16:49:18 +00:00
infer NFC: do not clone types that are copy 2023-12-15 23:19:51 +01:00
middle Auto merge of #119258 - compiler-errors:closure-kind, r=eholk 2023-12-26 04:25:53 +00:00
mir Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank 2023-12-26 12:27:29 +00:00
query Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
thir thir::Visitor only needs to visit &'thir data 2023-12-26 03:15:18 +00:00
traits Auto merge of #118431 - sjwang05:issue-44695, r=estebank 2023-12-26 21:34:24 +00:00
ty Introduce const Trait (always-const trait bounds) 2023-12-27 12:51:32 +01:00
util Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
arena.rs Make ConstKind and TyKind Copy 2023-12-12 01:09:12 +00:00
error.rs don't point at const usage site for resolution-time errors 2023-09-14 22:34:05 +02:00
lib.rs update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
lint.rs Streamline struct_lint_level. 2023-12-23 13:18:50 +11:00
macros.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
metadata.rs rustc_metadata: Remove Span from ModChild 2023-04-18 17:25:04 +03:00
tests.rs
thir.rs Don't include destruction scopes in THIR 2023-12-04 16:31:13 +00:00
values.rs Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00