about summary refs log tree commit diff
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:00 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:00 +0200
commit36c2b011cb4bb9bd34647486551e85a969773c8d (patch)
treee3b6cf9615355244e05cb699f6d3896217179a0c /src/tools/rustfmt
parentfe5f3dedf7b4d6bea2cadb17343f747d70b4c66b (diff)
parent512ff9520666a952850d0a360a4310c5995f6991 (diff)
Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-dead
New const traits syntax

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error

r? ``@fee1-dead``

cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
Diffstat (limited to 'src/tools/rustfmt')
-rw-r--r--src/tools/rustfmt/tests/source/type.rs12
-rw-r--r--src/tools/rustfmt/tests/target/type.rs12
2 files changed, 12 insertions, 12 deletions
diff --git a/src/tools/rustfmt/tests/source/type.rs b/src/tools/rustfmt/tests/source/type.rs
index 7a232f85198..213fad7cb16 100644
--- a/src/tools/rustfmt/tests/source/type.rs
+++ b/src/tools/rustfmt/tests/source/type.rs
@@ -142,18 +142,18 @@ type MyFn = fn(a: SomeLongComplexType, b: SomeOtherLongComplexType,) -> Box<Futu
 
 // Const bound
 
-trait T: ~   const  Super {}
+trait T: [   const ] Super {}
 
-const fn not_quite_const<S: ~  const    T>() -> i32 { <S as T>::CONST }
+const fn not_quite_const<S: [  const  ]  T>() -> i32 { <S as T>::CONST }
 
-impl ~    const T {}
+impl     const T for U {}
 
-fn apit(_: impl ~   const T) {}
+fn apit(_: impl [   const ] T) {}
 
-fn rpit() -> impl ~  const T { S }
+fn rpit() -> impl [  const] T { S }
 
 pub struct Foo<T: Trait>(T);
-impl<T:   ~  const Trait> Foo<T> {
+impl<T:   [  const] Trait> Foo<T> {
     fn new(t: T) -> Self {
         Self(t)
     }
diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs
index 325adb52f3f..93479f8b484 100644
--- a/src/tools/rustfmt/tests/target/type.rs
+++ b/src/tools/rustfmt/tests/target/type.rs
@@ -147,22 +147,22 @@ type MyFn = fn(
 
 // Const bound
 
-trait T: ~const Super {}
+trait T: [const] Super {}
 
-const fn not_quite_const<S: ~const T>() -> i32 {
+const fn not_quite_const<S: [const] T>() -> i32 {
     <S as T>::CONST
 }
 
-impl ~const T {}
+impl const T for U {}
 
-fn apit(_: impl ~const T) {}
+fn apit(_: impl [const] T) {}
 
-fn rpit() -> impl ~const T {
+fn rpit() -> impl [const] T {
     S
 }
 
 pub struct Foo<T: Trait>(T);
-impl<T: ~const Trait> Foo<T> {
+impl<T: [const] Trait> Foo<T> {
     fn new(t: T) -> Self {
         Self(t)
     }