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