diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2021-08-25 11:53:16 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2021-08-27 05:07:37 +0000 |
| commit | 076916fe940c07719244412e2834fdab543305d2 (patch) | |
| tree | b4b6d1f413822c9fe71c203ec1a77125f51529e3 | |
| parent | 9bc0dbeb6415b205df8336edca438a7ff4468adf (diff) | |
| download | rust-076916fe940c07719244412e2834fdab543305d2.tar.gz rust-076916fe940c07719244412e2834fdab543305d2.zip | |
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 #88155
- [ ] Do something with constness bounds in chalk
| -rw-r--r-- | src/types.rs | 4 | ||||
| -rw-r--r-- | tests/target/type.rs | 22 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/types.rs b/src/types.rs index c6f89c31065..640d127e860 100644 --- a/src/types.rs +++ b/src/types.rs @@ -537,10 +537,10 @@ impl Rewrite for ast::GenericBound { .map(|s| format!("?{}", s)), ast::TraitBoundModifier::MaybeConst => poly_trait_ref .rewrite(context, shape.offset_left(7)?) - .map(|s| format!("?const {}", s)), + .map(|s| format!("~const {}", s)), ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref .rewrite(context, shape.offset_left(8)?) - .map(|s| format!("?const ?{}", s)), + .map(|s| format!("~const ?{}", s)), }; rewrite.map(|s| if has_paren { format!("({})", s) } else { s }) } diff --git a/tests/target/type.rs b/tests/target/type.rs index e7761251688..9ab66944c8c 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -145,35 +145,33 @@ type MyFn = fn( b: SomeOtherLongComplexType, ) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>>; -// Const opt-out +// Const bound -trait T: ?const Super {} +trait T: ~const Super {} -const fn maybe_const<S: ?const T>() -> i32 { +const fn not_quite_const<S: ~const T>() -> i32 { <S as T>::CONST } -struct S<T: ?const ?Sized>(std::marker::PhantomData<T>); +struct S<T: ~const ?Sized>(std::marker::PhantomData<T>); -impl ?const T {} +impl ~const T {} -fn trait_object() -> &'static dyn ?const T { +fn trait_object() -> &'static dyn ~const T { &S } -fn i(_: impl IntoIterator<Item = Box<dyn ?const T>>) {} +fn i(_: impl IntoIterator<Item = Box<dyn ~const T>>) {} -fn apit(_: impl ?const T) {} +fn apit(_: impl ~const T) {} -fn rpit() -> impl ?const T { +fn rpit() -> impl ~const T { S } pub struct Foo<T: Trait>(T); -impl<T: ?const Trait> Foo<T> { +impl<T: ~const Trait> Foo<T> { fn new(t: T) -> Self { - // not calling methods on `t`, so we opt out of requiring - // `<T as Trait>` to have const methods via `?const` Self(t) } } |
