From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_error_codes/src/error_codes/E0033.md | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0033.md (limited to 'compiler/rustc_error_codes/src/error_codes/E0033.md') diff --git a/compiler/rustc_error_codes/src/error_codes/E0033.md b/compiler/rustc_error_codes/src/error_codes/E0033.md new file mode 100644 index 000000000..735a2d1f3 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0033.md @@ -0,0 +1,27 @@ +A trait type has been dereferenced. + +Erroneous code example: + +```compile_fail,E0033 +# trait SomeTrait { fn method_one(&self){} fn method_two(&self){} } +# impl SomeTrait for T {} +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. + +[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects -- cgit v1.2.3