mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 17:33:07 +00:00
![Esteban Küber](/assets/img/avatar_default.png)
``` error: unconstrained generic constant --> $DIR/const-argument-if-length.rs:18:10 | LL | pad: [u8; is_zst::<T>()], | ^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: { | ++++++++++++++++++++++++++ ``` Detect when the constant expression isn't `usize` and suggest casting: ``` error: unconstrained generic constant --> f300.rs:6:10 | 6 | bb::<{!N}>(); | ^^^^ -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36 | help: try adding a `where` bound | 5 | fn b<const N: bool>() where [(); {!N} as usize]: { | ++++++++++++++++++++++++++ ``` Fix #122395.
93 lines
2.9 KiB
Plaintext
93 lines
2.9 KiB
Plaintext
error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
|
--> $DIR/unify-op-with-fn-call.rs:18:29
|
|
|
|
|
LL | struct Evaluatable<const N: Foo>;
|
|
| ^^^
|
|
|
|
|
help: add `#[derive(ConstParamTy)]` to the struct
|
|
|
|
|
LL + #[derive(ConstParamTy)]
|
|
LL | struct Foo(u8);
|
|
|
|
|
|
|
error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
|
--> $DIR/unify-op-with-fn-call.rs:20:17
|
|
|
|
|
LL | fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
|
|
| ^^^
|
|
|
|
|
help: add `#[derive(ConstParamTy)]` to the struct
|
|
|
|
|
LL + #[derive(ConstParamTy)]
|
|
LL | struct Foo(u8);
|
|
|
|
|
|
|
error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
|
--> $DIR/unify-op-with-fn-call.rs:24:17
|
|
|
|
|
LL | fn bar<const N: Foo>() {}
|
|
| ^^^
|
|
|
|
|
help: add `#[derive(ConstParamTy)]` to the struct
|
|
|
|
|
LL + #[derive(ConstParamTy)]
|
|
LL | struct Foo(u8);
|
|
|
|
|
|
|
error: unconstrained generic constant
|
|
--> $DIR/unify-op-with-fn-call.rs:30:12
|
|
|
|
|
LL | bar2::<{ std::ops::Add::add(N, N) }>();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try adding a `where` bound
|
|
|
|
|
LL | fn foo2<const N: usize>(a: Evaluatable2<{ N + N }>) where [(); { std::ops::Add::add(N, N) }]: {
|
|
| +++++++++++++++++++++++++++++++++++++++++
|
|
|
|
error[E0015]: cannot call non-const operator in constants
|
|
--> $DIR/unify-op-with-fn-call.rs:20:39
|
|
|
|
|
LL | fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
|
|
| ^^^^^
|
|
|
|
|
note: impl defined here, but it is not `const`
|
|
--> $DIR/unify-op-with-fn-call.rs:10:1
|
|
|
|
|
LL | impl const std::ops::Add for Foo {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
|
|
|
LL + #![feature(effects)]
|
|
|
|
|
|
|
error[E0015]: cannot call non-const fn `<Foo as Add>::add` in constants
|
|
--> $DIR/unify-op-with-fn-call.rs:21:13
|
|
|
|
|
LL | bar::<{ std::ops::Add::add(N, N) }>();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
|
|
|
LL + #![feature(effects)]
|
|
|
|
|
|
|
error[E0015]: cannot call non-const fn `<usize as Add>::add` in constants
|
|
--> $DIR/unify-op-with-fn-call.rs:30:14
|
|
|
|
|
LL | bar2::<{ std::ops::Add::add(N, N) }>();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
|
help: add `#![feature(effects)]` to the crate attributes to enable
|
|
|
|
|
LL + #![feature(effects)]
|
|
|
|
|
|
|
error: aborting due to 7 previous errors
|
|
|
|
Some errors have detailed explanations: E0015, E0741.
|
|
For more information about an error, try `rustc --explain E0015`.
|