about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-27 19:24:31 +0000
committerbors <bors@rust-lang.org>2023-12-27 19:24:31 +0000
commit88d69b72b4ccfd4e4b64451a7a5d9fd23d2249a3 (patch)
treeee06621ba34b79cf6fb813a928424d9450fc8ed9 /src
parenta861c8965eaff66901710cc384a59f6b0b1a7700 (diff)
parent3eb48a35c8ae8335da66dc2bdb4f60e6ae22e1dd (diff)
downloadrust-88d69b72b4ccfd4e4b64451a7a5d9fd23d2249a3.tar.gz
rust-88d69b72b4ccfd4e4b64451a7a5d9fd23d2249a3.zip
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)
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/format.rs4
-rw-r--r--src/librustdoc/json/conversions.rs3
2 files changed, 5 insertions, 2 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index a9c0ab557cb..1923fc15119 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -449,8 +449,8 @@ impl clean::GenericBound {
                     hir::TraitBoundModifier::None => "",
                     hir::TraitBoundModifier::Maybe => "?",
                     hir::TraitBoundModifier::Negative => "!",
-                    // ~const is experimental; do not display those bounds in rustdoc
-                    hir::TraitBoundModifier::MaybeConst => "",
+                    // `const` and `~const` trait bounds are experimental; don't render them.
+                    hir::TraitBoundModifier::Const | hir::TraitBoundModifier::MaybeConst => "",
                 };
                 if f.alternate() {
                     write!(f, "{modifier_str}{ty:#}", ty = ty.print(cx))
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index 513e94afe29..32d7a80863d 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -547,6 +547,9 @@ pub(crate) fn from_trait_bound_modifier(
         None => TraitBoundModifier::None,
         Maybe => TraitBoundModifier::Maybe,
         MaybeConst => TraitBoundModifier::MaybeConst,
+        // FIXME(const_trait_impl): Create rjt::TBM::Const and map to it once always-const bounds
+        // are less experimental.
+        Const => TraitBoundModifier::None,
         // FIXME(negative-bounds): This bound should be rendered negative, but
         // since that's experimental, maybe let's not add it to the rustdoc json
         // API just now...