Skip to content

Commit 55f6739

Browse files
authored
const impl -> impl const
1 parent ae05ba2 commit 55f6739

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

const-generic-const-fn-bounds.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Summary
77
[summary]: #summary
88

9-
Allow `const impl`s for trait impls where all method impls are checked as const fn.
9+
Allow `impl const Trait` for trait impls where all method impls are checked as const fn.
1010

1111
Make it legal to declare trait bounds on generic parameters of const functions and allow
1212
the body of the const fn to call methods on the generic parameters that have a `const` modifier
@@ -39,7 +39,7 @@ The obligation is passed to the caller of your `triple_add` function to supply a
3939

4040
```rust
4141
struct MyInt(i8);
42-
const impl Add for MyInt {
42+
impl const Add for MyInt {
4343
fn add(self, other: Self) -> Self {
4444
MyInt(self.0 + other.0)
4545
}
@@ -51,7 +51,7 @@ so in the following `H` is required to have a const impl of `Hasher`, so that
5151
methods on `state` are callable.
5252

5353
```rust
54-
const impl Hash for MyInt {
54+
impl const Hash for MyInt {
5555
fn hash<H>(
5656
&self,
5757
state: &mut H,
@@ -65,11 +65,11 @@ const impl Hash for MyInt {
6565

6666
## Drop
6767

68-
A notable use case of `const impl` is defining `Drop` impls. If you write
68+
A notable use case of `impl const` is defining `Drop` impls. If you write
6969

7070
```rust
7171
struct SomeDropType<'a>(&'a Cell<u32>);
72-
const impl Drop for SomeDropType {
72+
impl const Drop for SomeDropType {
7373
fn drop(&mut self) {
7474
self.0.set(self.0.get() - 1);
7575
}
@@ -89,7 +89,7 @@ and ensuring that lowering to HIR and MIR keeps track of that.
8989
The miri engine already fully supports calling methods on generic
9090
bounds, there's just no way of declaring them. Checking methods for constness is already implemented
9191
for inherent methods. The implementation will have to extend those checks to also run on methods
92-
of `const impl` items.
92+
of `impl const` items.
9393

9494
# Drawbacks
9595
[drawbacks]: #drawbacks
@@ -150,21 +150,21 @@ It might also be desirable to make the automatic `Fn*` impls on function types a
150150
This change should probably go in hand with allowing `const fn` pointers on const functions
151151
that support being called (in contrast to regular function pointers).
152152

153-
## Deriving `const impl`s
153+
## Deriving `impl const`
154154

155155
```rust
156156
#[derive(Clone)]
157157
pub struct Foo(Bar);
158158

159159
struct Bar;
160160

161-
const impl Clone for Bar {
161+
impl const Clone for Bar {
162162
fn clone(&self) -> Self { Bar }
163163
}
164164
```
165165

166166
could theoretically have a scheme inferring `Foo`'s `Clone` impl to be `const`. If some time
167-
later the `const impl Clone for Bar` (a private type) is changed to just `impl`, `Foo`'s `Clone`
167+
later the `impl const Clone for Bar` (a private type) is changed to just `impl`, `Foo`'s `Clone`
168168
impl would suddenly stop being `const`, without any visible change to the API. This should not
169169
be allowed for the same reason as why we're not inferring `const` on functions: changes to private
170170
things should not affect the constness of public things, because that is not compatible with semver.
@@ -177,13 +177,13 @@ pub struct Foo(Bar);
177177

178178
struct Bar;
179179

180-
const impl Clone for Bar {
180+
impl const Clone for Bar {
181181
fn clone(&self) -> Self { Bar }
182182
}
183183
```
184184

185-
which would generate a `const impl Clone for Foo` block which would fail to compile if any of `Foo`'s
186-
fields (so just `Bar` in this example) are not implementing `Clone` via `const impl`. The obligation is
185+
which would generate a `impl const Clone for Foo` block which would fail to compile if any of `Foo`'s
186+
fields (so just `Bar` in this example) are not implementing `Clone` via `impl const`. The obligation is
187187
now on the crate author to keep the public API semver compatible, but they can't accidentally fail to
188188
uphold that obligation by changing private things.
189189

@@ -200,7 +200,7 @@ const context. It seems like a natural extension to this RFC to allow
200200
const fn foo() -> impl const Bar { /* code here */ }
201201
```
202202

203-
which requires that the function only returns types with `const impl Bar` blocks.
203+
which requires that the function only returns types with `impl const Bar` blocks.
204204

205205
## Specialization
206206

@@ -211,13 +211,13 @@ and `const` modifiers on `impl` blocks.
211211
# Unresolved questions
212212
[unresolved-questions]: #unresolved-questions
213213

214-
Should `const impl` blocks additionally generate impls that are not const if any generic
214+
Should `impl const` blocks additionally generate impls that are not const if any generic
215215
parameters are not const?
216216

217217
E.g.
218218

219219
```rust
220-
const impl<T: Add> Add for Foo<T> {
220+
impl<T: Add> const Add for Foo<T> {
221221
fn add(self, other: Self) -> Self {
222222
Foo(self.0 + other.0)
223223
}
@@ -226,21 +226,21 @@ const impl<T: Add> Add for Foo<T> {
226226

227227
would allow calling `Foo(String::new()) + Foo(String::new())` even though that is (at the time
228228
of writing this RFC) most definitely not const, because `String` only has an `impl Add for String`
229-
and not a `const impl Add for String`.
229+
and not an `impl const Add for String`.
230230

231231
This would go in hand with the current scheme for const functions, which may also be called
232232
at runtime with runtime arguments, but are checked for soundness as if they were called in
233233
a const context.
234234

235-
## Require `const` bounds on everything inside a `const impl` block?
235+
## Require `const` bounds on everything inside an `impl const` block?
236236

237-
Instead of inferring `const`ness on all bounds and functions inside a `const impl` block,
237+
Instead of inferring `const`ness on all bounds and functions inside a `impl const` block,
238238
we force the user to supply these bounds. This is more consistent with not inferring `const`
239239
on `const` function argument types and generic bounds. The `Hash` example from above would
240240
then look like
241241

242242
```rust
243-
const impl Hash for MyInt {
243+
impl const Hash for MyInt {
244244
const fn hash<H>(
245245
&self,
246246
state: &mut H,

0 commit comments

Comments
 (0)