Skip to content

Commit a19d621

Browse files
authored
Rollup merge of rust-lang#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``
2 parents 55d4f76 + 4f3c174 commit a19d621

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
436436
// FIXME(const_trait_impl, fee1-dead) revert to const destruct once it works again
437437
#[expect(unused)]
438438
fn is_ty_const_destruct_unused<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>) -> bool {
439-
// If this doesn't need drop at all, then don't select `~const Destruct`.
439+
// If this doesn't need drop at all, then don't select `[const] Destruct`.
440440
if !ty.needs_drop(tcx, body.typing_env(tcx)) {
441441
return false;
442442
}

tests/ui/assign_ops.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod issue14871 {
9191

9292
impl<T> const NumberConstants for T
9393
where
94-
T: Number + ~const core::ops::Add,
94+
T: Number + [const] core::ops::Add,
9595
{
9696
fn constant(value: usize) -> Self {
9797
let mut res = Self::ZERO;

tests/ui/assign_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod issue14871 {
9191

9292
impl<T> const NumberConstants for T
9393
where
94-
T: Number + ~const core::ops::Add,
94+
T: Number + [const] core::ops::Add,
9595
{
9696
fn constant(value: usize) -> Self {
9797
let mut res = Self::ZERO;

tests/ui/trait_duplication_in_bounds.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ where
169169
// #13476
170170
#[const_trait]
171171
trait ConstTrait {}
172-
const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {}
172+
const fn const_trait_bounds_good<T: ConstTrait + [const] ConstTrait>() {}
173173

174-
const fn const_trait_bounds_bad<T: ~const ConstTrait>() {}
174+
const fn const_trait_bounds_bad<T: [const] ConstTrait>() {}
175175
//~^ trait_duplication_in_bounds
176176

177177
fn projections<T, U, V>()

tests/ui/trait_duplication_in_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ where
169169
// #13476
170170
#[const_trait]
171171
trait ConstTrait {}
172-
const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {}
172+
const fn const_trait_bounds_good<T: ConstTrait + [const] ConstTrait>() {}
173173

174-
const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {}
174+
const fn const_trait_bounds_bad<T: [const] ConstTrait + [const] ConstTrait>() {}
175175
//~^ trait_duplication_in_bounds
176176

177177
fn projections<T, U, V>()

tests/ui/trait_duplication_in_bounds.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
6161
error: these bounds contain repeated elements
6262
--> tests/ui/trait_duplication_in_bounds.rs:174:36
6363
|
64-
LL | const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {}
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `~const ConstTrait`
64+
LL | const fn const_trait_bounds_bad<T: [const] ConstTrait + [const] ConstTrait>() {}
65+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[const] ConstTrait`
6666

6767
error: these where clauses contain repeated elements
6868
--> tests/ui/trait_duplication_in_bounds.rs:181:8

0 commit comments

Comments
 (0)