]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0033.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0033.md
1 A trait type has been dereferenced.
2
3 Erroneous code example:
4
5 ```compile_fail,E0033
6 # trait SomeTrait { fn method_one(&self){} fn method_two(&self){} }
7 # impl<T> SomeTrait for T {}
8 let trait_obj: &SomeTrait = &"some_value";
9
10 // This tries to implicitly dereference to create an unsized local variable.
11 let &invalid = trait_obj;
12
13 // You can call methods without binding to the value being pointed at.
14 trait_obj.method_one();
15 trait_obj.method_two();
16 ```
17
18 A pointer to a trait type cannot be implicitly dereferenced by a pattern. Every
19 trait defines a type, but because the size of trait implementers isn't fixed,
20 this type has no compile-time size. Therefore, all accesses to trait types must
21 be through pointers. If you encounter this error you should try to avoid
22 dereferencing the pointer.
23
24 You can read more about trait objects in the [Trait Objects] section of the
25 Reference.
26
27 [Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects