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
This commit is contained in:
Deadbeef 2021-08-25 11:53:16 +00:00
parent 9bc0dbeb64
commit 076916fe94
2 changed files with 12 additions and 14 deletions

View file

@ -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 })
}

View file

@ -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)
}
}