Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0379: functions in traits cannot be declared const
What it meansA trait method was declared const.
What rustc prints
error[E0379]: functions in traits cannot be declared const
--> main.rs:2:5
|
2 | const fn bar() -> u32; // error!
| ^^^^^-
| |
| functions in traits cannot be const
| help: remove the `const`Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
A trait method was declared const.
Erroneous code example:
trait Foo {
const fn bar() -> u32; // error!
}
impl Foo for () {
const fn bar() -> u32 { 0 } // error!
}
Trait methods cannot be declared const by design. For more information, see RFC 911.
From rustc --explain E0379 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0377the trait `CoerceUnsized` may only be implemented for a coercion between structures
- E0378the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else
- E0380auto traits cannot have associated items
- E0390cannot define inherent `impl` for primitive types
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?