We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The warning text in the doc says:
'Warning: For trait objects, if there is an inherent method of the same name as a trait method, it will give a compiler error when trying to call the method in a method call expression.' https://doc.rust-lang.org/reference/expressions/method-call-expr.html
However, the following Playground code compiles and calls the trait object method: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ee3edd82619f479bdc9980c03b2f201f
This suggests that the warning is incorrect, and should be deleted.
The text was updated successfully, but these errors were encountered:
I think there may be a misunderstanding of what the text is saying. It is referring to methods on the trait, and one on the trait object. For example:
trait Bar { fn method(&self); } struct Foo; impl Bar for Foo { fn method(&self) { println!("Bar::method"); } } impl dyn Bar { fn method(&self) { println!("dyn Bar"); } } fn main() { let x: &dyn Bar = &Foo; x.method(); }
impl dyn adds methods to the trait object which is different from the trait itself.
impl dyn
Sorry, something went wrong.
Ah, I see.
The issue with the text is that 'inherent method' of a 'trait object' is ambiguous. It could mean, in the context of the example:
impl Foo
impl dyn Bar
Given that (1) is a far more common usage in Rust than (2), I suspect most will read it that way.
Placing your example, @ehuss, in the text, would certainly aid understanding, and perhaps rewording the text somehow to further clarify.
No branches or pull requests
The warning text in the doc says:
'Warning: For trait objects, if there is an inherent method of the same name as a trait method, it will give a compiler error when trying to call the method in a method call expression.'
https://doc.rust-lang.org/reference/expressions/method-call-expr.html
However, the following Playground code compiles and calls the trait object method: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ee3edd82619f479bdc9980c03b2f201f
This suggests that the warning is incorrect, and should be deleted.
The text was updated successfully, but these errors were encountered: