-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Deref coercions do not work with blocks #26978
Comments
CC @nrc |
As some users have discovered, |
I suspect this is something specific to deref coercions. I think it is 'just a bug', but I don't know how easy it is to fix. |
This blocks usage of
|
@tbu- Yup, actually this issue was found by a Stack Overflow question that tried the same thing. |
There is also this rust-users thread with a very similar problem. |
triage: I-nominated |
triaged because it is such an annoying bug. Recommend p-medium. |
cc @eddyb |
triage: P-medium |
It would be very helpful to point out the error, which is: <anon>:8:9: 8:10 error: mismatched types:
expected `str`,
found `collections::string::String`
(expected str,
found struct `collections::string::String`) [E0308]
<anon>:8 f(&{x}); // Error
^ So the problem could be that |
Update: That was dumb of me: I did not realize this only ever happens with |
Uncomment issue4 power_assert! now that rust-lang/rust#26978 is fixed
This issue should be reopened: fn f(_: &i32) {}
fn main() {
let x = Box::new(1i32);
f(&x); // OK
f(&(x)); // OK
f(&{x}); // Error
} |
I should've renamed the title of this issue, I believe (based on my comments in this thread) that this issue was specifically about I doubt your example ever worked, because the block gets |
It seems that the compiler handles a block differently when coercing a value.
RFC 401 says that a block with type
U
is also a target for coercion, so I think this behavior is a bug.Also, the compiler seems to be able to coerce blocks using some "trivial" rules (e.g.
&mut T
->&T
).So I guess this is more likely a problem of auto-deref.
The text was updated successfully, but these errors were encountered: