Account for #![feature(const_trait_impl)] state

This commit is contained in:
Esteban Küber 2025-07-19 21:42:15 +00:00
parent 9bc814cc8d
commit bf45da7e51
8 changed files with 62 additions and 5 deletions

View file

@ -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 {

View file

@ -55,10 +55,24 @@ LL | #[const_trait] trait Bar: [const] Foo {}
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | const fn foo<T: ~const Bar>(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

View file

@ -35,10 +35,23 @@ LL | #[const_trait] trait Bar: [const] Foo {}
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | const fn foo<T: ~const Bar>(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

View file

@ -53,10 +53,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const`
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
9 | const fn foo<T: ~const Bar>(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

View file

@ -43,10 +43,19 @@ note: `Bar` can't be used with `[const]` because it isn't `const`
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
9 | const fn foo<T: ~const Bar>(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

View file

@ -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]

View file

@ -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]

View file

@ -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]