Skip to content

Commit

Permalink
Introduce ~const
Browse files Browse the repository at this point in the history
 - [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
  • Loading branch information
fee1-dead committed Aug 27, 2021
1 parent 9bc0dbe commit 076916f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
22 changes: 10 additions & 12 deletions tests/target/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 076916f

Please sign in to comment.