Skip to content

Commit 076916f

Browse files
committed
Introduce ~const
- [x] Removed `?const` and change uses of `?const` - [x] Added `~const` to the AST. It is gated behind const_trait_impl. - [x] Validate `~const` in ast_validation. - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and `ConstIfConst` allowing future extensions) - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`. - [ ] Optional steps (*for this PR, obviously*) - [ ] Fix rust-lang#88155 - [ ] Do something with constness bounds in chalk
1 parent 9bc0dbe commit 076916f

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,10 @@ impl Rewrite for ast::GenericBound {
537537
.map(|s| format!("?{}", s)),
538538
ast::TraitBoundModifier::MaybeConst => poly_trait_ref
539539
.rewrite(context, shape.offset_left(7)?)
540-
.map(|s| format!("?const {}", s)),
540+
.map(|s| format!("~const {}", s)),
541541
ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
542542
.rewrite(context, shape.offset_left(8)?)
543-
.map(|s| format!("?const ?{}", s)),
543+
.map(|s| format!("~const ?{}", s)),
544544
};
545545
rewrite.map(|s| if has_paren { format!("({})", s) } else { s })
546546
}

tests/target/type.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -145,35 +145,33 @@ type MyFn = fn(
145145
b: SomeOtherLongComplexType,
146146
) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>>;
147147

148-
// Const opt-out
148+
// Const bound
149149

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

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

156-
struct S<T: ?const ?Sized>(std::marker::PhantomData<T>);
156+
struct S<T: ~const ?Sized>(std::marker::PhantomData<T>);
157157

158-
impl ?const T {}
158+
impl ~const T {}
159159

160-
fn trait_object() -> &'static dyn ?const T {
160+
fn trait_object() -> &'static dyn ~const T {
161161
&S
162162
}
163163

164-
fn i(_: impl IntoIterator<Item = Box<dyn ?const T>>) {}
164+
fn i(_: impl IntoIterator<Item = Box<dyn ~const T>>) {}
165165

166-
fn apit(_: impl ?const T) {}
166+
fn apit(_: impl ~const T) {}
167167

168-
fn rpit() -> impl ?const T {
168+
fn rpit() -> impl ~const T {
169169
S
170170
}
171171

172172
pub struct Foo<T: Trait>(T);
173-
impl<T: ?const Trait> Foo<T> {
173+
impl<T: ~const Trait> Foo<T> {
174174
fn new(t: T) -> Self {
175-
// not calling methods on `t`, so we opt out of requiring
176-
// `<T as Trait>` to have const methods via `?const`
177175
Self(t)
178176
}
179177
}

0 commit comments

Comments
 (0)