Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0033: A trait type has been dereferenced
What it meansA trait type has been dereferenced.
The compiler team's explanation
A trait type has been dereferenced.
Erroneous code example:
let trait_obj: &SomeTrait = &"some_value";
// This tries to implicitly dereference to create an unsized local variable.
let &invalid = trait_obj;
// You can call methods without binding to the value being pointed at.
trait_obj.method_one();
trait_obj.method_two();
A pointer to a trait type cannot be implicitly dereferenced by a pattern. Every trait defines a type, but because the size of trait implementers isn't fixed, this type has no compile-time size. Therefore, all accesses to trait types must be through pointers. If you encounter this error you should try to avoid dereferencing the pointer.
You can read more about trait objects in the Trait Objects section of the Reference.
From rustc --explain E0033 (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
- E0029only `char` and numeric types are allowed in range patterns
- E0030lower bound for range pattern must be less than or equal to upper bound
- E0038For any given trait `Trait` there may be a related _type_ called the _trait object type_ which is typically written as `dyn Trait`. In earlier editions of Rust, trait object types were written as plain `Trait` (just the name of the trait, written in type positions) but this was a bit too confusing, so we now write `dyn Trait`
- E0044foreign items may not have type parameters
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?