-
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 don't work on blocks when the target is sized #57749
Comments
Background: I found this issue while playing with let body = document.body().unwrap();
body.append_child(&{
let button = document.create_element("button")?.dyn_into::<HtmlButtonElement>().unwrap();
button.append_child(&document.create_text_node("Click me"))?;
button
})?;
|
From reading https://github.com/rust-lang/rust/pull/31651/files I get the impression that |
Linked issue: #23014 |
Another use case came up on URLO: the desugared // `bar: fn(&B)`, `a: Result<A, E>`, `A: Sized + Deref<Target=B>`
// This fails but `&*a?` or `&&a?` or `a?.deref()` work
bar(&a?); More code contextuse std::ops::Deref;
struct A;
struct B;
impl Deref for A {
type Target = B;
fn deref(&self) -> &B {
&B
}
}
// Replace the above with these and it will work:
//type A = String;
//type B = str;
struct E;
fn foo(a: Result<A, E>) -> Result<(), E> {
// &*a? or &&a? or a?.deref() also work
bar(&a?);
Ok(())
}
fn bar(_: &B) {} |
I found a workaround that works on stable for this:
not sure if there is a safer way to do this, trying to make |
Update: It turns out that my above solution could technically turn into UB because it wasn't
|
As seen on StackOverflow.
Consider the following code:
The following expressions do compile:
reset(&Homura)
reset(&&{ Homura })
reset({ &Homura })
But this doesn't:
reset(&{ Homura })
Is there are particular reason for this discrepancy?
I found two similar issues #26978 and #32122 but they don't seem to cover this particular case.
The text was updated successfully, but these errors were encountered: