Introduce const Trait (always-const trait bounds)
This commit is contained in:
parent
2fe50cd72c
commit
3eb48a35c8
69 changed files with 505 additions and 223 deletions
|
|
@ -4,13 +4,13 @@ error[E0635]: unknown feature `const_fn_trait_ref_impls`
|
|||
LL | #![feature(const_fn_trait_ref_impls)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:15:15
|
||||
|
|
||||
LL | T: ~const Fn<()> + ~const Destruct,
|
||||
| ^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:15:15
|
||||
|
|
||||
LL | T: ~const Fn<()> + ~const Destruct,
|
||||
|
|
@ -18,13 +18,13 @@ LL | T: ~const Fn<()> + ~const Destruct,
|
|||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:22:15
|
||||
|
|
||||
LL | T: ~const FnMut<()> + ~const Destruct,
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:22:15
|
||||
|
|
||||
LL | T: ~const FnMut<()> + ~const Destruct,
|
||||
|
|
@ -32,13 +32,13 @@ LL | T: ~const FnMut<()> + ~const Destruct,
|
|||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:29:15
|
||||
|
|
||||
LL | T: ~const FnOnce<()>,
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:29:15
|
||||
|
|
||||
LL | T: ~const FnOnce<()>,
|
||||
|
|
@ -46,13 +46,13 @@ LL | T: ~const FnOnce<()>,
|
|||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:36:15
|
||||
|
|
||||
LL | T: ~const Fn<()> + ~const Destruct,
|
||||
| ^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:36:15
|
||||
|
|
||||
LL | T: ~const Fn<()> + ~const Destruct,
|
||||
|
|
@ -60,13 +60,13 @@ LL | T: ~const Fn<()> + ~const Destruct,
|
|||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:50:15
|
||||
|
|
||||
LL | T: ~const FnMut<()> + ~const Destruct,
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/fn_trait_refs.rs:50:15
|
||||
|
|
||||
LL | T: ~const FnMut<()> + ~const Destruct,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/unstable-const-fn-in-libcore.rs:19:39
|
||||
|
|
||||
LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
// known-bug: #110395
|
||||
// FIXME check-pass
|
||||
// check-pass
|
||||
|
||||
// Test that we can call methods from const trait impls inside of generic const items.
|
||||
|
||||
#![feature(generic_const_items, const_trait_impl)]
|
||||
#![feature(generic_const_items, const_trait_impl, effects)]
|
||||
#![allow(incomplete_features)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// FIXME(generic_const_items, effects): Introduce `const` bounds to make this work.
|
||||
const CREATE<T: Create>: T = T::create();
|
||||
const CREATE<T: const Create>: T = T::create();
|
||||
|
||||
pub const K0: i32 = CREATE::<i32>;
|
||||
pub const K1: i32 = CREATE; // arg inferred
|
||||
|
|
@ -23,3 +21,13 @@ impl const Create for i32 {
|
|||
4096
|
||||
}
|
||||
}
|
||||
|
||||
trait Mod { // doesn't need to be a `#[const_trait]`
|
||||
const CREATE<T: const Create>: T;
|
||||
}
|
||||
|
||||
impl Mod for () {
|
||||
const CREATE<T: const Create>: T = T::create();
|
||||
}
|
||||
|
||||
pub const K2: i32 = <() as Mod>::CREATE::<i32>;
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0015]: cannot call non-const fn `<T as Create>::create` in constants
|
||||
--> $DIR/const-trait-impl.rs:11:30
|
||||
|
|
||||
LL | const CREATE<T: Create>: T = T::create();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
= help: add `#![feature(effects)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/normalize-tait-in-const.rs:25:42
|
||||
|
|
||||
LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ struct S<
|
|||
T: ~const ?Tr, // OK
|
||||
T: ~const Tr + 'a, // OK
|
||||
T: ~const 'a, //~ ERROR `~const` may only modify trait bounds, not lifetime bounds
|
||||
T: const 'a, //~ ERROR `const` may only modify trait bounds, not lifetime bounds
|
||||
>;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,11 @@ error: `~const` may only modify trait bounds, not lifetime bounds
|
|||
LL | T: ~const 'a,
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: `const` may only modify trait bounds, not lifetime bounds
|
||||
--> $DIR/bounds-type.rs:16:8
|
||||
|
|
||||
LL | T: const 'a,
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
// Check that `?Trait` matches the macro fragment specifier `ty`.
|
||||
// Syntactically trait object types can be "bare" (i.e., lack the prefix `dyn`),
|
||||
// even in newer editions like Rust 2021.
|
||||
// Therefore the arm `?$Trait:path` shouldn't get reached.
|
||||
|
||||
// edition: 2021
|
||||
// check-pass
|
||||
|
||||
macro_rules! check {
|
||||
($Ty:ty) => {};
|
||||
(?$Trait:path) => { compile_error!("non-ty"); };
|
||||
}
|
||||
|
||||
check! { ?Trait }
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -8,7 +8,7 @@ fn foo2(_: &dyn (Drop + AsRef<str>)) {} //~ ERROR incorrect parentheses around t
|
|||
fn foo2_no_space(_: &dyn(Drop + AsRef<str>)) {} //~ ERROR incorrect parentheses around trait bounds
|
||||
|
||||
fn foo3(_: &dyn {Drop + AsRef<str>}) {} //~ ERROR expected parameter name, found `{`
|
||||
//~^ ERROR expected one of `!`, `(`, `)`, `*`, `,`, `?`, `for`, `~`, lifetime, or path, found `{`
|
||||
//~^ ERROR expected one of `!`, `(`, `)`, `*`, `,`, `?`, `const`, `for`, `~`, lifetime, or path, found `{`
|
||||
//~| ERROR at least one trait is required for an object type
|
||||
|
||||
fn foo4(_: &dyn <Drop + AsRef<str>>) {} //~ ERROR expected identifier, found `<`
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ error: expected parameter name, found `{`
|
|||
LL | fn foo3(_: &dyn {Drop + AsRef<str>}) {}
|
||||
| ^ expected parameter name
|
||||
|
||||
error: expected one of `!`, `(`, `)`, `*`, `,`, `?`, `for`, `~`, lifetime, or path, found `{`
|
||||
error: expected one of `!`, `(`, `)`, `*`, `,`, `?`, `const`, `for`, `~`, lifetime, or path, found `{`
|
||||
--> $DIR/trait-object-delimiters.rs:10:17
|
||||
|
|
||||
LL | fn foo3(_: &dyn {Drop + AsRef<str>}) {}
|
||||
| -^ expected one of 10 possible tokens
|
||||
| -^ expected one of 11 possible tokens
|
||||
| |
|
||||
| help: missing `,`
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ LL | type Bar: ~const std::ops::Add;
|
|||
|
|
||||
= note: this item cannot have `~const` trait bounds
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/assoc-type.rs:17:22
|
||||
|
|
||||
LL | type Bar: ~const std::ops::Add;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
// Regression test for issue #117244.
|
||||
#![feature(const_trait_impl, effects)]
|
||||
|
||||
trait NonConst {}
|
||||
|
||||
const fn perform<T: ~const NonConst>() {}
|
||||
//~^ ERROR `~const` can only be applied to `#[const_trait]` traits
|
||||
|
||||
fn operate<T: const NonConst>() {}
|
||||
//~^ ERROR `const` can only be applied to `#[const_trait]` traits
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-bounds-non-const-trait.rs:6:28
|
||||
|
|
||||
LL | const fn perform<T: ~const NonConst>() {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-bounds-non-const-trait.rs:9:21
|
||||
|
|
||||
LL | fn operate<T: const NonConst>() {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closure-parse-not-item.rs:7:32
|
||||
|
|
||||
LL | const fn test() -> impl ~const Fn() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closure-trait-method-fail.rs:14:39
|
||||
|
|
||||
LL | const fn need_const_closure<T: ~const FnOnce(()) -> i32>(x: T) -> i32 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closure-trait-method.rs:14:39
|
||||
|
|
||||
LL | const fn need_const_closure<T: ~const FnOnce(()) -> i32>(x: T) -> i32 {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closures.rs:8:19
|
||||
|
|
||||
LL | F: ~const FnOnce() -> u8,
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closures.rs:9:19
|
||||
|
|
||||
LL | F: ~const FnMut() -> u8,
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closures.rs:10:19
|
||||
|
|
||||
LL | F: ~const Fn() -> u8,
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-closures.rs:23:27
|
||||
|
|
||||
LL | const fn answer<F: ~const Fn() -> u8>(f: &F) -> u8 {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
|
|||
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
|
||||
= note: adding a non-const method body in the future would be a breaking change
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-drop-fail-2.rs:29:26
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
|
|||
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
|
||||
= note: adding a non-const method body in the future would be a breaking change
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const-drop-fail-2.rs:29:26
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
error: `~const` is not allowed here
|
||||
--> $DIR/const-drop.rs:67:38
|
||||
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
||||
--> $DIR/const-drop.rs:19:32
|
||||
|
|
||||
LL | pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
|
||||
| ^^^^^^
|
||||
LL | const fn a<T: ~const Destruct>(_: T) {}
|
||||
| ^ the destructor for this type cannot be evaluated in constant functions
|
||||
|
||||
error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time
|
||||
--> $DIR/const-drop.rs:24:13
|
||||
|
|
||||
= note: this item cannot have `~const` trait bounds
|
||||
LL | let _ = S(&mut c);
|
||||
| ^^^^^^^^^ the destructor for this type cannot be evaluated in constant functions
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0493`.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#![feature(const_trait_impl)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(never_type)]
|
||||
// #![cfg_attr(precise, feature(const_precise_live_drops))]
|
||||
#![cfg_attr(precise, feature(const_precise_live_drops))]
|
||||
|
||||
use std::marker::Destruct;
|
||||
|
||||
|
|
@ -63,8 +63,7 @@ mod t {
|
|||
fn foo() {}
|
||||
}
|
||||
|
||||
// FIXME(effects): This should be a `const` bound instead of a `~const` one.
|
||||
pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
|
||||
pub struct ConstDropWithBound<T: const SomeTrait>(pub core::marker::PhantomData<T>);
|
||||
|
||||
impl<T: ~const SomeTrait> const Drop for ConstDropWithBound<T> {
|
||||
fn drop(&mut self) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,19 @@
|
|||
error: `~const` is not allowed here
|
||||
--> $DIR/const-drop.rs:67:38
|
||||
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
||||
--> $DIR/const-drop.rs:19:32
|
||||
|
|
||||
LL | pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
|
||||
| ^^^^^^
|
||||
LL | const fn a<T: ~const Destruct>(_: T) {}
|
||||
| ^ - value is dropped here
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constant functions
|
||||
|
||||
error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time
|
||||
--> $DIR/const-drop.rs:24:13
|
||||
|
|
||||
= note: this item cannot have `~const` trait bounds
|
||||
LL | let _ = S(&mut c);
|
||||
| ^^^^^^^^^- value is dropped here
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constant functions
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0493`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
#![feature(const_trait_impl)]
|
||||
// edition: 2021
|
||||
|
||||
#[const_trait]
|
||||
trait Trait {}
|
||||
|
||||
fn main() {
|
||||
let _: &dyn const Trait; //~ ERROR const trait bounds are not allowed in trait object types
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: const trait bounds are not allowed in trait object types
|
||||
--> $DIR/const-trait-bounds-trait-objects.rs:8:17
|
||||
|
|
||||
LL | let _: &dyn const Trait;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// check-pass
|
||||
|
||||
#![feature(const_trait_impl, effects, generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
fn main() {
|
||||
let _ = process::<()>([()]);
|
||||
let _ = Struct::<(), 4> { field: [1, 0] };
|
||||
}
|
||||
|
||||
fn process<T: const Trait>(input: [(); T::make(2)]) -> [(); T::make(2)] {
|
||||
input
|
||||
}
|
||||
|
||||
struct Struct<T: const Trait, const P: usize>
|
||||
where
|
||||
[u32; T::make(P)]:,
|
||||
{
|
||||
field: [u32; T::make(P)],
|
||||
}
|
||||
|
||||
#[const_trait]
|
||||
trait Trait {
|
||||
fn make(input: usize) -> usize;
|
||||
}
|
||||
|
||||
impl const Trait for () {
|
||||
fn make(input: usize) -> usize {
|
||||
input / 2
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(const_trait_impl, effects)]
|
||||
|
||||
const fn test() -> impl ~const Fn() { //~ ERROR ~const can only be applied to `#[const_trait]` traits
|
||||
const fn test() -> impl ~const Fn() { //~ ERROR `~const` can only be applied to `#[const_trait]` traits
|
||||
const move || { //~ ERROR const closures are experimental
|
||||
let sl: &[u8] = b"foo";
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | const move || {
|
|||
= note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
|
||||
= help: add `#![feature(const_closures)]` to the crate attributes to enable
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/ice-112822-expected-type-for-param.rs:3:32
|
||||
|
|
||||
LL | const fn test() -> impl ~const Fn() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: fatal error triggered by #[rustc_error]
|
||||
--> $DIR/feature-gate.rs:14:1
|
||||
--> $DIR/feature-gate.rs:22:1
|
||||
|
|
||||
LL | fn main() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -10,5 +10,13 @@ trait T {}
|
|||
impl const T for S {}
|
||||
//[stock]~^ ERROR const trait impls are experimental
|
||||
|
||||
const fn f<A: ~const T>() {} //[stock]~ ERROR const trait impls are experimental
|
||||
fn g<A: const T>() {} //[stock]~ ERROR const trait impls are experimental
|
||||
|
||||
macro_rules! discard { ($ty:ty) => {} }
|
||||
|
||||
discard! { impl ~const T } //[stock]~ ERROR const trait impls are experimental
|
||||
discard! { impl const T } //[stock]~ ERROR const trait impls are experimental
|
||||
|
||||
#[rustc_error]
|
||||
fn main() {} //[gated]~ ERROR fatal error triggered by #[rustc_error]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,42 @@ LL | impl const T for S {}
|
|||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:13:15
|
||||
|
|
||||
LL | const fn f<A: ~const T>() {}
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:14:9
|
||||
|
|
||||
LL | fn g<A: const T>() {}
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:18:17
|
||||
|
|
||||
LL | discard! { impl ~const T }
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:19:17
|
||||
|
|
||||
LL | discard! { impl const T }
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future.
|
||||
--> $DIR/feature-gate.rs:8:1
|
||||
|
|
||||
|
|
@ -16,6 +52,6 @@ LL | #[const_trait]
|
|||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// Ensure that we don't consider `const Trait` and `~const Trait` to
|
||||
// match the macro fragment specifier `ty` as that would be a breaking
|
||||
// change theoretically speaking. Syntactically trait object types can
|
||||
// be "bare", i.e., lack the prefix `dyn`.
|
||||
// By contrast, `?Trait` *does* match `ty` and therefore an arm like
|
||||
// `?$Trait:path` would never be reached.
|
||||
// See `parser/macro/mbe-bare-trait-object-maybe-trait-bound.rs`.
|
||||
|
||||
// check-pass
|
||||
|
||||
macro_rules! check {
|
||||
($Type:ty) => { compile_error!("ty"); };
|
||||
(const $Trait:path) => {};
|
||||
(~const $Trait:path) => {};
|
||||
}
|
||||
|
||||
check! { const Trait }
|
||||
check! { ~const Trait }
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Demonstrates and records a theoretical regressions / breaking changes caused by the
|
||||
// introduction of const trait bounds.
|
||||
|
||||
// Setting the edition to 2018 since we don't regress `demo! { dyn const }` in Rust <2018.
|
||||
// edition:2018
|
||||
|
||||
macro_rules! demo {
|
||||
($ty:ty) => { compile_error!("ty"); };
|
||||
(impl $c:ident) => {};
|
||||
(dyn $c:ident) => {};
|
||||
}
|
||||
|
||||
demo! { impl const }
|
||||
//~^ ERROR expected identifier, found `<eof>`
|
||||
|
||||
demo! { dyn const }
|
||||
//~^ ERROR const trait impls are experimental
|
||||
//~| ERROR expected identifier, found `<eof>`
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
error: expected identifier, found `<eof>`
|
||||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:13:14
|
||||
|
|
||||
LL | ($ty:ty) => { compile_error!("ty"); };
|
||||
| ------ while parsing argument for this `ty` macro fragment
|
||||
...
|
||||
LL | demo! { impl const }
|
||||
| ^^^^^ expected identifier
|
||||
|
||||
error: expected identifier, found `<eof>`
|
||||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:16:13
|
||||
|
|
||||
LL | ($ty:ty) => { compile_error!("ty"); };
|
||||
| ------ while parsing argument for this `ty` macro fragment
|
||||
...
|
||||
LL | demo! { dyn const }
|
||||
| ^^^^^ expected identifier
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:16:13
|
||||
|
|
||||
LL | demo! { dyn const }
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
// Ensure that the introduction of const trait bound didn't regress this code in Rust 2015.
|
||||
// See also `mbe-const-trait-bound-theoretical-regression.rs`.
|
||||
|
||||
// check-pass
|
||||
|
||||
macro_rules! check {
|
||||
($ty:ty) => { compile_error!("ty"); };
|
||||
(dyn $c:ident) => {};
|
||||
}
|
||||
|
||||
check! { dyn const }
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
const fn maybe_const_maybe<T: ~const ?Sized>() {}
|
||||
//~^ ERROR `~const` and `?` are mutually exclusive
|
||||
|
||||
fn const_maybe<T: const ?Sized>() {}
|
||||
//~^ ERROR `const` and `?` are mutually exclusive
|
||||
|
||||
const fn maybe_const_negative<T: ~const !Trait>() {}
|
||||
//~^ ERROR `~const` and `!` are mutually exclusive
|
||||
//~| ERROR negative bounds are not supported
|
||||
|
||||
fn const_negative<T: const !Trait>() {}
|
||||
//~^ ERROR `const` and `!` are mutually exclusive
|
||||
//~| ERROR negative bounds are not supported
|
||||
|
||||
#[const_trait]
|
||||
trait Trait {}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
error: `~const` and `?` are mutually exclusive
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:3:31
|
||||
|
|
||||
LL | const fn maybe_const_maybe<T: ~const ?Sized>() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: `const` and `?` are mutually exclusive
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:6:19
|
||||
|
|
||||
LL | fn const_maybe<T: const ?Sized>() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: `~const` and `!` are mutually exclusive
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:34
|
||||
|
|
||||
LL | const fn maybe_const_negative<T: ~const !Trait>() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: `const` and `!` are mutually exclusive
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:22
|
||||
|
|
||||
LL | fn const_negative<T: const !Trait>() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: negative bounds are not supported
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:41
|
||||
|
|
||||
LL | const fn maybe_const_negative<T: ~const !Trait>() {}
|
||||
| ^
|
||||
|
||||
error: negative bounds are not supported
|
||||
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:28
|
||||
|
|
||||
LL | fn const_negative<T: const !Trait>() {}
|
||||
| ^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/non-const-op-in-closure-in-const.rs:10:51
|
||||
|
|
||||
LL | impl<A, B> const Convert<B> for A where B: ~const From<A> {
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bou
|
|||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:10:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:10:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:10:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:10:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ trait Foo {
|
|||
|
||||
#[cfg_attr(any(yy, ny), const_trait)]
|
||||
trait Bar: ~const Foo {}
|
||||
//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~| ERROR: ~const can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~| ERROR: `~const` can only be applied to `#[const_trait]`
|
||||
//[yn,nn]~^^^ ERROR: `~const` is not allowed here
|
||||
|
||||
const fn foo<T: Bar>(x: &T) {
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bou
|
|||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
|
|
@ -24,7 +24,7 @@ LL | trait Bar: ~const Foo {}
|
|||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:17:24
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:19
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ trait Foo {
|
|||
|
||||
#[cfg_attr(any(yy, ny), const_trait)]
|
||||
trait Bar: ~const Foo {}
|
||||
//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~| ERROR: ~const can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
|
||||
//[ny,nn]~| ERROR: `~const` can only be applied to `#[const_trait]`
|
||||
//[yn,nn]~^^^ ERROR: `~const` is not allowed here
|
||||
|
||||
const fn foo<T: ~const Bar>(x: &T) {
|
||||
//[yn,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
//[yn,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
|
||||
x.a();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bou
|
|||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:17:24
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
const fn tilde_question<T: ~const ?Sized>() {}
|
||||
//~^ ERROR `~const` and `?` are mutually exclusive
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
error: `~const` and `?` are mutually exclusive
|
||||
--> $DIR/tilde-const-maybe-trait.rs:3:28
|
||||
|
|
||||
LL | const fn tilde_question<T: ~const ?Sized>() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
// compile-flags: -Z parse-only
|
||||
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
struct S<T: const Tr>;
|
||||
//~^ ERROR const bounds must start with `~`
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
error: const bounds must start with `~`
|
||||
--> $DIR/without-tilde.rs:5:13
|
||||
|
|
||||
LL | struct S<T: const Tr>;
|
||||
| -^^^^
|
||||
| |
|
||||
| help: add `~`: `~`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const_trait_impl.rs:34:16
|
||||
|
|
||||
LL | impl<T: ~const Default> const A for T {
|
||||
| ^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const_trait_impl.rs:40:16
|
||||
|
|
||||
LL | impl<T: ~const Default + ~const Sup> const A for T {
|
||||
| ^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/const_trait_impl.rs:46:16
|
||||
|
|
||||
LL | impl<T: ~const Default + ~const Sub> const A for T {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue