Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0777: expected path to a trait, found literal
What it meansA literal value was used inside #[derive].
What rustc prints
error[E0777]: expected path to a trait, found literal --> main.rs:1:10 | 1 | #[derive("Clone")] // error! | ^^^^^^^ not a trait | = help: try using `#[derive(Clone)]`
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 literal value was used inside #[derive].
Erroneous code example:
#[derive("Clone")] // error!
struct Foo;
Only paths to traits are allowed as argument inside #[derive]. You can find more information about the #[derive] attribute in the Rust Book.
#[derive(Clone)] // ok!
struct Foo;From rustc --explain E0777 (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
- E0751found both positive and negative implementation of trait `MyTrait` for type `i32`:
- E0770the type of const parameters must not depend on other generic parameters
- E0782expected a type, found a trait
- E0785cannot define inherent `impl` for a dyn auto trait
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?