Skip to content

Commit a69cccb

Browse files
authored
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``
2 parents fd6ceeb + 9debb8f commit a69cccb

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

tests/source/type.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ type MyFn = fn(a: SomeLongComplexType, b: SomeOtherLongComplexType,) -> Box<Futu
142142

143143
// Const bound
144144

145-
trait T: ~ const Super {}
145+
trait T: [ const ] Super {}
146146

147-
const fn not_quite_const<S: ~ const T>() -> i32 { <S as T>::CONST }
147+
const fn not_quite_const<S: [ const ] T>() -> i32 { <S as T>::CONST }
148148

149-
impl ~ const T {}
149+
impl const T for U {}
150150

151-
fn apit(_: impl ~ const T) {}
151+
fn apit(_: impl [ const ] T) {}
152152

153-
fn rpit() -> impl ~ const T { S }
153+
fn rpit() -> impl [ const] T { S }
154154

155155
pub struct Foo<T: Trait>(T);
156-
impl<T: ~ const Trait> Foo<T> {
156+
impl<T: [ const] Trait> Foo<T> {
157157
fn new(t: T) -> Self {
158158
Self(t)
159159
}

tests/target/type.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,22 @@ type MyFn = fn(
147147

148148
// Const bound
149149

150-
trait T: ~const Super {}
150+
trait T: [const] Super {}
151151

152-
const fn not_quite_const<S: ~const T>() -> i32 {
152+
const fn not_quite_const<S: [const] T>() -> i32 {
153153
<S as T>::CONST
154154
}
155155

156-
impl ~const T {}
156+
impl const T for U {}
157157

158-
fn apit(_: impl ~const T) {}
158+
fn apit(_: impl [const] T) {}
159159

160-
fn rpit() -> impl ~const T {
160+
fn rpit() -> impl [const] T {
161161
S
162162
}
163163

164164
pub struct Foo<T: Trait>(T);
165-
impl<T: ~const Trait> Foo<T> {
165+
impl<T: [const] Trait> Foo<T> {
166166
fn new(t: T) -> Self {
167167
Self(t)
168168
}

0 commit comments

Comments
 (0)