-
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
Be a little nicer with casts when formatting fn
pointers
#97420
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
} | ||
} | ||
f.flags |= 1 << (FlagV1::Alternate as u32); | ||
pointer_fmt_inner((*self as *const ()).addr(), f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this as *const ()
does anything.
@jam1garner do you have an idea how this might affect anything/how to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say more about why it's here? I would expect this code to be self.addr(), I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left it here from the previous version in which it was used to erase the type. But since this gets the addr, I guess it's useless now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it is there is in order to erase the type to avoid monomorphizing the impl, since the debug/pointer formatting doesn't care about the type, just the address.
The reason this matters is that if you derive(Debug) for bindgen'd bindings involving lots of pointer fields it generates an obscene amount of code, and severely hurts compile times.
I agree that it should be entirely useless now in the presence of .addr()! (I also do not know why T: Sized is needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the T: Sized
bound on addr
exists to make discarding the metadata explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wander is it makes sense then to have a .discard_meta(): *const ()
? it would play nicely with other methods like said addr
. Though I don't really see a value in making discarding metadata explicit (at least for addr
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addr()
already discards other information so I don't disagree -- however, map_addr
should then probably also be made to support ?Sized
.
@Gankra designed those APIs so she might better be able to explain why addr
requires Sized
.
r=me with the seemingly useless cast to a unit raw ptr removed. |
This comment has been minimized.
This comment has been minimized.
What, why does |
Ok, let's leave the cast in for now and leave a comment on why. |
fd6ed87
to
25e7b92
Compare
This comment has been minimized.
This comment has been minimized.
25e7b92
to
7103f45
Compare
7103f45
to
ac5c15d
Compare
Done 😅 |
@bors r+ |
📌 Commit ac5c15d has been approved by |
…=Mark-Simulacrum Be a little nicer with casts when formatting `fn` pointers This removes a `fn(...) -> ...` -> `usize` -> `*const ()` -> `usize` cast. cc rust-lang#95489.
Rollup of 5 pull requests Successful merges: - rust-lang#97420 (Be a little nicer with casts when formatting `fn` pointers) - rust-lang#97450 ([RFC 2011] Basic compiler infrastructure) - rust-lang#97599 (Fix JSON reexport ICE) - rust-lang#97617 (Rustdoc anonymous reexports) - rust-lang#97636 (Revert rust-lang#96682.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This removes a
fn(...) -> ...
->usize
->*const ()
->usize
cast. cc #95489.