Tweak wording of non-const traits used as const bounds
Use verbose suggestions and add additional labels/notes. Add more test cases for stable/nightly and feature enabled/disabled.
This commit is contained in:
parent
f6cb952dc1
commit
4007fc9a0f
49 changed files with 1121 additions and 194 deletions
|
@ -0,0 +1,66 @@
|
|||
error: `~const` is not allowed here
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
= 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
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &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
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^ can't be applied to `Foo`
|
||||
|
|
||||
help: enable `#![feature(const_trait_impl)]` in your crate and mark `Foo` as `#[const_trait]` to allow it to have `const` implementations
|
||||
|
|
||||
LL | #[const_trait] trait Foo {
|
||||
| ++++++++++++++
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^ can't be applied to `Bar`
|
||||
|
|
||||
help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[const_trait]` to allow it to have `const` implementations
|
||||
|
|
||||
LL | #[const_trait] trait Bar: ~const Foo {}
|
||||
| ++++++++++++++
|
||||
|
||||
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
|
||||
--> const-super-trait.rs:10:7
|
||||
|
|
||||
LL | x.a();
|
||||
| ^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0015, E0658.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,45 @@
|
|||
error: `~const` is not allowed here
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^ can't be applied to `Foo`
|
||||
|
|
||||
help: mark `Foo` as `#[const_trait]` to allow it to have `const` implementations
|
||||
|
|
||||
LL | #[const_trait] trait Foo {
|
||||
| ++++++++++++++
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^ can't be applied to `Bar`
|
||||
|
|
||||
help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations
|
||||
|
|
||||
LL | #[const_trait] trait Bar: ~const Foo {}
|
||||
| ++++++++++++++
|
||||
|
||||
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
|
||||
--> const-super-trait.rs:10:7
|
||||
|
|
||||
LL | x.a();
|
||||
| ^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,64 @@
|
|||
error: `~const` is not allowed here
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
9 | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^ can't be applied to `Foo`
|
||||
|
|
||||
note: `Foo` can't be used with `~const` because it isn't annotated with `#[const_trait]`
|
||||
--> const-super-trait.rs:3:1
|
||||
|
|
||||
3 | trait Foo {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
9 | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^ can't be applied to `Bar`
|
||||
|
|
||||
note: `Bar` can't be used with `~const` because it isn't annotated with `#[const_trait]`
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
|
||||
--> const-super-trait.rs:10:7
|
||||
|
|
||||
10 | x.a();
|
||||
| ^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0015, E0658.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,54 @@
|
|||
error: `~const` is not allowed here
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^
|
||||
|
|
||||
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0554]: `#![feature]` may not be used on the NIGHTLY release channel
|
||||
--> const-super-trait.rs:1:30
|
||||
|
|
||||
1 | #![cfg_attr(feature_enabled, feature(const_trait_impl))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:7:12
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^ can't be applied to `Foo`
|
||||
|
|
||||
note: `Foo` can't be used with `~const` because it isn't annotated with `#[const_trait]`
|
||||
--> const-super-trait.rs:3:1
|
||||
|
|
||||
3 | trait Foo {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `~const` can only be applied to `#[const_trait]` traits
|
||||
--> const-super-trait.rs:9:17
|
||||
|
|
||||
9 | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^ can't be applied to `Bar`
|
||||
|
|
||||
note: `Bar` can't be used with `~const` because it isn't annotated with `#[const_trait]`
|
||||
--> const-super-trait.rs:7:1
|
||||
|
|
||||
7 | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
|
||||
--> const-super-trait.rs:10:7
|
||||
|
|
||||
10 | x.a();
|
||||
| ^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0015, E0554.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,13 @@
|
|||
#![cfg_attr(feature_enabled, feature(const_trait_impl))]
|
||||
|
||||
trait Foo {
|
||||
fn a(&self);
|
||||
}
|
||||
|
||||
trait Bar: ~const Foo {}
|
||||
|
||||
const fn foo<T: ~const Bar>(x: &T) {
|
||||
x.a();
|
||||
}
|
||||
|
||||
fn main() {}
|
59
tests/run-make/const-trait-stable-toolchain/rmake.rs
Normal file
59
tests/run-make/const-trait-stable-toolchain/rmake.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
// Test output of const super trait errors in both stable and nightly.
|
||||
// We don't want to provide suggestions on stable that only make sense in nightly.
|
||||
|
||||
use run_make_support::{diff, rustc};
|
||||
|
||||
fn main() {
|
||||
let out = rustc()
|
||||
.input("const-super-trait.rs")
|
||||
.env("RUSTC_BOOTSTRAP", "-1")
|
||||
.cfg("feature_enabled")
|
||||
.run_fail()
|
||||
.assert_stderr_not_contains(
|
||||
"as `#[const_trait]` to allow it to have `const` implementations",
|
||||
)
|
||||
.stderr_utf8();
|
||||
diff()
|
||||
.expected_file("const-super-trait-stable-enabled.stderr")
|
||||
.normalize(
|
||||
"may not be used on the .* release channel",
|
||||
"may not be used on the NIGHTLY release channel",
|
||||
)
|
||||
.actual_text("(rustc)", &out)
|
||||
.run();
|
||||
let out = rustc()
|
||||
.input("const-super-trait.rs")
|
||||
.cfg("feature_enabled")
|
||||
.ui_testing()
|
||||
.run_fail()
|
||||
.assert_stderr_not_contains("enable `#![feature(const_trait_impl)]` in your crate and mark")
|
||||
.assert_stderr_contains("as `#[const_trait]` to allow it to have `const` implementations")
|
||||
.stderr_utf8();
|
||||
diff()
|
||||
.expected_file("const-super-trait-nightly-enabled.stderr")
|
||||
.actual_text("(rustc)", &out)
|
||||
.run();
|
||||
let out = rustc()
|
||||
.input("const-super-trait.rs")
|
||||
.env("RUSTC_BOOTSTRAP", "-1")
|
||||
.run_fail()
|
||||
.assert_stderr_not_contains("enable `#![feature(const_trait_impl)]` in your crate and mark")
|
||||
.assert_stderr_not_contains(
|
||||
"as `#[const_trait]` to allow it to have `const` implementations",
|
||||
)
|
||||
.stderr_utf8();
|
||||
diff()
|
||||
.expected_file("const-super-trait-stable-disabled.stderr")
|
||||
.actual_text("(rustc)", &out)
|
||||
.run();
|
||||
let out = rustc()
|
||||
.input("const-super-trait.rs")
|
||||
.ui_testing()
|
||||
.run_fail()
|
||||
.assert_stderr_contains("enable `#![feature(const_trait_impl)]` in your crate and mark")
|
||||
.stderr_utf8();
|
||||
diff()
|
||||
.expected_file("const-super-trait-nightly-disabled.stderr")
|
||||
.actual_text("(rustc)", &out)
|
||||
.run();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue