The "this function takes ownership of the receiver self
" diagnostic hint not shown inside closures
#94056
Labels
A-closures
Area: Closures (`|…| { … }`)
A-diagnostics
Area: Messages for errors, warnings, and lints
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=bfca5a5df52348cba46546d72a36ccb6
The current output is:
This diagnostic was confusing to me, since:
update()
takes ownershipCopy
trait, which whilst true, isn't really the correct way to fix thisIdeally the output should look like:
ie: Have a
note
that explains the root issue - which is that themut self
takes ownership - and thus hopefully allow users to realise it should be&mut self
in the definition ofupdate()
, rather than the problem being intestcase()
.Notably, if I change the implementation to use a for loop (rather than a closure with
.forEach()
):(see https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=eb04a60d4d60c15c1911d14c64e2a692)
...then the output already includes the above suggestion:
The text was updated successfully, but these errors were encountered: