about summary refs log tree commit diff
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
commita19d621975bf7aa18931aa55339ae767b8935d95 (patch)
tree7e723a31e908131035074fbe564d6421eacdc892
parent55d4f76c73ae517905df61674667463e65e90b47 (diff)
parent4f3c17486eafadd4ccebdf5230b27a285c9a110d (diff)
downloadrust-a19d621975bf7aa18931aa55339ae767b8935d95.tar.gz
rust-a19d621975bf7aa18931aa55339ae767b8935d95.zip
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``
-rw-r--r--clippy_utils/src/qualify_min_const_fn.rs2
-rw-r--r--tests/ui/assign_ops.fixed2
-rw-r--r--tests/ui/assign_ops.rs2
-rw-r--r--tests/ui/trait_duplication_in_bounds.fixed4
-rw-r--r--tests/ui/trait_duplication_in_bounds.rs4
-rw-r--r--tests/ui/trait_duplication_in_bounds.stderr4
6 files changed, 9 insertions, 9 deletions
diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs
index e629012b187..328fe3d428b 100644
--- a/clippy_utils/src/qualify_min_const_fn.rs
+++ b/clippy_utils/src/qualify_min_const_fn.rs
@@ -436,7 +436,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
     // FIXME(const_trait_impl, fee1-dead) revert to const destruct once it works again
     #[expect(unused)]
     fn is_ty_const_destruct_unused<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool {
-        // If this doesn't need drop at all, then don't select `~const Destruct`.
+        // If this doesn't need drop at all, then don't select `[const] Destruct`.
         if !ty.needs_drop(tcx, body.typing_env(tcx)) {
             return false;
         }
diff --git a/tests/ui/assign_ops.fixed b/tests/ui/assign_ops.fixed
index 3bc6885d7c3..99beea850a2 100644
--- a/tests/ui/assign_ops.fixed
+++ b/tests/ui/assign_ops.fixed
@@ -91,7 +91,7 @@ mod issue14871 {
 
     impl<T> const NumberConstants for T
     where
-        T: Number + ~const core::ops::Add,
+        T: Number + [const] core::ops::Add,
     {
         fn constant(value: usize) -> Self {
             let mut res = Self::ZERO;
diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs
index f1f8f9daff9..900d5ad38e0 100644
--- a/tests/ui/assign_ops.rs
+++ b/tests/ui/assign_ops.rs
@@ -91,7 +91,7 @@ mod issue14871 {
 
     impl<T> const NumberConstants for T
     where
-        T: Number + ~const core::ops::Add,
+        T: Number + [const] core::ops::Add,
     {
         fn constant(value: usize) -> Self {
             let mut res = Self::ZERO;
diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed
index 666ff78b218..cf52ecf2f03 100644
--- a/tests/ui/trait_duplication_in_bounds.fixed
+++ b/tests/ui/trait_duplication_in_bounds.fixed
@@ -169,9 +169,9 @@ where
 // #13476
 #[const_trait]
 trait ConstTrait {}
-const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {}
+const fn const_trait_bounds_good<T: ConstTrait + [const] ConstTrait>() {}
 
-const fn const_trait_bounds_bad<T: ~const ConstTrait>() {}
+const fn const_trait_bounds_bad<T: [const] ConstTrait>() {}
 //~^ trait_duplication_in_bounds
 
 fn projections<T, U, V>()
diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs
index a1a86fe058e..955562f08dc 100644
--- a/tests/ui/trait_duplication_in_bounds.rs
+++ b/tests/ui/trait_duplication_in_bounds.rs
@@ -169,9 +169,9 @@ where
 // #13476
 #[const_trait]
 trait ConstTrait {}
-const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {}
+const fn const_trait_bounds_good<T: ConstTrait + [const] ConstTrait>() {}
 
-const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {}
+const fn const_trait_bounds_bad<T: [const] ConstTrait + [const] ConstTrait>() {}
 //~^ trait_duplication_in_bounds
 
 fn projections<T, U, V>()
diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr
index d76b4e45848..ab31721ef51 100644
--- a/tests/ui/trait_duplication_in_bounds.stderr
+++ b/tests/ui/trait_duplication_in_bounds.stderr
@@ -61,8 +61,8 @@ LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
 error: these bounds contain repeated elements
   --> tests/ui/trait_duplication_in_bounds.rs:174:36
    |
-LL | const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {}
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `~const ConstTrait`
+LL | const fn const_trait_bounds_bad<T: [const] ConstTrait + [const] ConstTrait>() {}
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[const] ConstTrait`
 
 error: these where clauses contain repeated elements
   --> tests/ui/trait_duplication_in_bounds.rs:181:8