Skip to content

Commit fdd11fb

Browse files
committed
Do not allow const refinement of (const) methods in impls
1 parent e18f475 commit fdd11fb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

text/0000-const-trait-impls.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const trait Default {
2020
}
2121

2222
impl const Default for () {
23-
const fn default() {}
23+
(const) fn default() {}
2424
}
2525

2626
struct Thing<T>(T);
@@ -180,11 +180,11 @@ Free functions are unaffected and will stay as `const fn`.
180180

181181
### Impls for conditionally const methods
182182

183-
Methods that are declared as `(const)` on a trait can now be made `const` in an impl, if that impl is marked as `impl cosnt Trait`:
183+
Methods that are declared as `(const)` on a trait can now also be made `(const)` in an impl, if that impl is marked as `impl const Trait`:
184184

185185
```rust
186186
impl const Trait for Type {
187-
const fn thing() {}
187+
(const) fn thing() {}
188188
}
189189
```
190190

@@ -202,7 +202,7 @@ const trait Foo {
202202
}
203203

204204
impl const Foo for () {
205-
const fn foo(&self) {}
205+
(const) fn foo(&self) {}
206206
fn bar(&self) {
207207
println!("writing to terminal is not possible in const eval");
208208
}
@@ -221,11 +221,11 @@ const trait Default {
221221
}
222222

223223
impl const Default for () {
224-
const fn default() {}
224+
(const) fn default() {}
225225
}
226226

227227
impl<T: Default> const Default for Box<T> {
228-
fn default() -> Self { Box::new(T::default()) }
228+
(const) fn default() -> Self { Box::new(T::default()) }
229229
}
230230

231231
// This function requires a `const` impl for the type passed for T,
@@ -304,7 +304,7 @@ struct MyStruct<T>(T);
304304

305305
impl<T: (const) Add<Output = T>> const Add for MyStruct<T> {
306306
type Output = MyStruct<T>;
307-
const fn add(self, other: MyStruct<T>) -> MyStruct<T> {
307+
(const) fn add(self, other: MyStruct<T>) -> MyStruct<T> {
308308
MyStruct(self.0 + other.0)
309309
}
310310
}
@@ -314,7 +314,7 @@ where
314314
for<'a> &'a T: (const) Add<Output = T>,
315315
{
316316
type Output = MyStruct<T>;
317-
const fn add(self, other: &MyStruct<T>) -> MyStruct<T> {
317+
(const) fn add(self, other: &MyStruct<T>) -> MyStruct<T> {
318318
MyStruct(&self.0 + &other.0)
319319
}
320320
}
@@ -605,7 +605,7 @@ struct NewType<T>(T);
605605

606606
impl<T: (const) Add<Output = T>> const Add for NewType<T> {
607607
type Output = Self;
608-
fn add(self, other: Self) -> Self::Output {
608+
(const) fn add(self, other: Self) -> Self::Output {
609609
NewType(self.0 + other.0)
610610
}
611611
}
@@ -620,7 +620,7 @@ struct Error;
620620

621621
impl<T: (const) Add<Output = T>> const Add for NewType<T> {
622622
type Output = Result<Self, Error>;
623-
fn add(self, other: Self) -> Self::Output {
623+
(const) fn add(self, other: Self) -> Self::Output {
624624
if self.1 {
625625
Ok(NewType(self.0 + other.0, other.1))
626626
} else {
@@ -670,7 +670,7 @@ const trait Bar {
670670
struct Foo<T: Bar>(T);
671671

672672
impl<T: (const) Bar> const Drop for Foo<T> {
673-
const fn drop(&mut self) {
673+
(const) fn drop(&mut self) {
674674
self.0.thing();
675675
}
676676
}
@@ -689,7 +689,7 @@ Extraneous `(const) Trait` bounds where `Trait` isn't a bound on the type at all
689689

690690
```rust
691691
impl<T: (const) Bar + (const) Baz> const Drop for Foo<T> {
692-
const fn drop(&mut self) {
692+
(const) fn drop(&mut self) {
693693
self.0.thing();
694694
}
695695
}

0 commit comments

Comments
 (0)