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
Howevery this unexpectedly fails, requiring the type to be specified in the closure definition. (|a| a + a)(42) on the other hand works just fine.
Digging a little deeper I discovered this related problem. It seems that the unary operator doesn't add an implicit trait bound to the closure, and instead just gives an error immediately.
This seems to be the behaviour for all unary operators, not just the unary minus.
OleStrohm
changed the title
Unary minus does not add bounds to closure, instead just errors
Unary operators do not add bounds to closure, instead just errors
Mar 3, 2022
…rain, r=petrochenkov
Suggest constraining param for unary ops when missing trait impl
This PR adds a suggestion of constraining param for unary ops `-` and `!` when the corresponding trait implementation
is missing.
Fixs rust-lang#94543.
BTW, this is my first time to touch rustc, please correct me if I did anything wrong.
Uh oh!
There was an error while loading. Please reload this page.
I tried this code:
Howevery this unexpectedly fails, requiring the type to be specified in the closure definition.
(|a| a + a)(42)
on the other hand works just fine.Digging a little deeper I discovered this related problem. It seems that the unary operator doesn't add an implicit trait bound to the closure, and instead just gives an error immediately.
This seems to be the behaviour for all unary operators, not just the unary minus.
I expected to see this happen:
I expected both of these to have errors like closure_binary:
Instead, this happened:
Only closure_binary has such an error. Instead closure_unary has:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: