diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 55d29f9c2146..c958a91f754b 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -390,7 +390,13 @@ fn build_error_for_const_call<'tcx>( `{trait_name}` is not const", ), ); - if parent.is_local() { + if parent.is_local() && ccx.tcx.sess.is_nightly_build() { + if !ccx.tcx.features().const_trait_impl() { + err.help( + "add `#![feature(const_trait_impl)]` to the crate attributes to \ + enable `#[const_trait]`", + ); + } let indentation = ccx .tcx .sess @@ -403,6 +409,8 @@ fn build_error_for_const_call<'tcx>( format!("#[const_trait]\n{indentation}"), Applicability::MachineApplicable, ); + } else if !ccx.tcx.sess.is_nightly_build() { + err.help("const traits are not yet supported on stable Rust"); } } } else if ccx.tcx.constness(callee) != hir::Constness::Const { diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr index 895558f3b0fc..47f6817b9b64 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr @@ -55,10 +55,24 @@ LL | #[const_trait] trait Bar: [const] Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +LL | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 6 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr index 821ab6fa57cd..49e2f98c371f 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr @@ -35,10 +35,23 @@ LL | #[const_trait] trait Bar: [const] Foo {} error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +LL | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants LL | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +LL | trait Foo { + | ^^^^^^^^^ this trait is not const +LL | fn a(&self); + | ------------ this method is not const +help: consider making trait `Foo` const + | +LL + #[const_trait] +LL | trait Foo { + | error: aborting due to 4 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr index b39be78e4384..62fd9a38b759 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr @@ -53,10 +53,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const` error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +9 | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants 10 | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ this trait is not const +4 | fn a(&self); + | ------------ this method is not const + = help: const traits are not yet supported on stable Rust error: aborting due to 6 previous errors diff --git a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr index 30ee5cf6f4b0..fc1adbe441ce 100644 --- a/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr +++ b/tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr @@ -43,10 +43,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const` error[E0015]: cannot call non-const method `::a` in constant functions --> const-super-trait.rs:10:7 | +9 | const fn foo(x: &T) { + | ---------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants 10 | x.a(); | ^^^ | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants +note: method `a` is not const because trait `Foo` is not const + --> const-super-trait.rs:3:1 + | +3 | trait Foo { + | ^^^^^^^^^ this trait is not const +4 | fn a(&self); + | ------------ this method is not const + = help: const traits are not yet supported on stable Rust error: aborting due to 5 previous errors diff --git a/tests/ui/resolve/issue-39559-2.stderr b/tests/ui/resolve/issue-39559-2.stderr index 8c19fb23d8e9..fbbcaa663ae0 100644 --- a/tests/ui/resolve/issue-39559-2.stderr +++ b/tests/ui/resolve/issue-39559-2.stderr @@ -11,6 +11,7 @@ LL | trait Dim { | ^^^^^^^^^ this trait is not const LL | fn dim() -> usize; | ------------------ this associated function is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` help: consider making trait `Dim` const | LL + #[const_trait] @@ -30,6 +31,7 @@ LL | trait Dim { | ^^^^^^^^^ this trait is not const LL | fn dim() -> usize; | ------------------ this associated function is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` help: consider making trait `Dim` const | LL + #[const_trait] diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr index 8a35dd966425..2625f9446061 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr @@ -104,6 +104,7 @@ LL | trait Foo { | ^^^^^^^^^ this trait is not const LL | fn a(&self); | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` help: consider making trait `Foo` const | LL + #[const_trait] diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr index 8a35dd966425..2625f9446061 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr @@ -104,6 +104,7 @@ LL | trait Foo { | ^^^^^^^^^ this trait is not const LL | fn a(&self); | ------------ this method is not const + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable `#[const_trait]` help: consider making trait `Foo` const | LL + #[const_trait]