You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitTrait{fnexists(self) -> ();fnnot_object_safe() -> Self;}implTraitfor(){fnexists(self) -> (){}fnnot_object_safe() -> Self{()}}fnmain(){// object-safe or not, this call is OKTrait::exists(());// but, in addition to nonexistence, this causes an object safety errorTrait::nonexistent(());}
Gives
error[E0599]: no function or associated item named `nonexistent` found for type `dyn Trait` in the current scope
--> src/main.rs:20:5
|
20 | Trait::nonexistent(());
| ^^^^^^^^^^^^^^^^^^ function or associated item not found in `dyn Trait`
error[E0038]: the trait `Trait` cannot be made into an object
--> src/main.rs:20:5
|
20 | Trait::nonexistent(());
| ^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
|
= note: method `not_object_safe` has no receiver
error: aborting due to 2 previous errors
As the first call shows, it is in fact possible to call a non-object-safe trait's methods in this manner, but calling a nonexistent method gives an object safety error, adding noise to the output.
Note as well the E0599 error says the receiver type is dyn Trait.
Gives
As the first call shows, it is in fact possible to call a non-object-safe trait's methods in this manner, but calling a nonexistent method gives an object safety error, adding noise to the output.
Note as well the E0599 error says the receiver type is
dyn Trait
.Playground
The text was updated successfully, but these errors were encountered: