-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
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
Ownership error masks missing implementation of trait #27009
Comments
This compiles because Maybe a lint which warns when this impl/method is invoked could help? |
(I have to point out that i've only just started with Rust.) So if i get you right i should have dereferenced Maybe like so? |
Well, yes, if you do that you will get the desired compiler error, but I don't think the error message is worth the additional verbosity in general. <anon>:23:41: 23:48 error: no method named `clone` found for type `Test` in the current scope
<anon>:23 let test = (*tests.last().unwrap()).clone();
^~~~~~~
<anon>:23:41: 23:48 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `clone`, perhaps you need to implement it:
<anon>:23:41: 23:48 help: candidate #1: `core::clone::Clone` |
So to wrap it up it was my bad, because i didn't know that references can be cloned by default... kinda hard to put my finger on the actual problem here 📦 |
Thanks for reporting! Always better to have too many reports than not enough. Since this isn't a bug, I'm closing it. |
I would expect the main function to not compile because clone() has not been implemented for struct Test. However this error is masked by:
src/main.rs:26:2: 26:7 error: cannot borrow
testsas mutable because it is also borrowed as immutable
The error here is the missing implementation though, because it solves the ownership issue. rustc doesn't complain about the missing implementation at all.
The text was updated successfully, but these errors were encountered: