-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Printing function address is confusing due to per-function ZST "singleton type" #75239
Comments
This creates a reference-to-function-pointer (type
The error could possibly be improved, and the entire situation documented better, but I think getting an error is expected here. Printing function pointers is easy (well, if they are not polymorphic via |
It might also be worth linting against |
#75477 helps with the docs. But to close this issue, it would probably make sense to write a lint against That should be a matter of adding a new At least I hope that makes sense, someone stop me if this is all wrong. ;) |
Expand function pointer docs Be more explicit in the ABI section, and add a section on how to obtain a function pointer, which can be somewhat confusing. Cc rust-lang#75239
I'd like to help write this lint. The default level for the lint should be |
Yeah, |
Nominated for lang team discussion. It seems we usually ask for lints to be approved before shipping them, so let's get that process started. @ayrtonm sorry for this, I wasn't aware of this part of the process. You can still go ahead and implement this if you want, but depending on what the lang team decides, we should submit this lint to clippy instead of the compiler itself. That might require minor adjustments, but the main work you are putting in and the testcases will be useful either way. :) |
As a point of interest, this would have been extremely useful in helping debug a segfault in https://gitlab.com/YottaDB/Lang/YDBRust/-/blob/447c641fcf6945d81d6947fcd9a6a8b34b40537f/src/simple_api/mod.rs#L1891. The original code used |
Without the |
Unfortunately I never committed the broken code so I'm not sure what I had originally ... the closest thing is https://gitlab.com/YottaDB/Lang/YDBRust/-/commit/223b86ac99117672ec8ae8d5a70b4e4da691becf#c03d74036e9573cf34d6119f0c039f06492d3997_1581_1587 which doesn't compile. Sorry for the noise. |
no worries. I already have the lint implemented, but in that case I'll wait until they discuss to write the tests |
I think |
@rfcbot poll T-lang Should we add a lint for taking a reference to a fn? |
Team member @joshtriplett has asked teams: T-lang, for consensus on:
|
I think I agree here, but to confirm: this isn't actually about linting the taking of a reference to a place of |
Yes. |
Discussed in a (rather small) @rust-lang/lang meeting today: Those present felt a lint would make sense. If somebody wanted to go ahead and try to author one, please feel free and nominate the resulting PR for discussion. |
@ayrtonm all right, so if you want to open a PR, everything is settled for that. :) |
I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=61fe688172759b7756e84751557e39ea
I expected to see this happen:
The compilation succeed or guide me to
fn
to*const ()
withas
.fn
:&size_of::<Left>
. But in this case the addresses printed are the same (what?).Instead, this happened:
Cryptic error message:
There is
impl<usize> Pointer for fn() -> usize
: https://doc.rust-lang.org/nightly/std/fmt/trait.Pointer.html#impl-Pointer-3 .It took me minutes before I found the workaround. But it still surprised me.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: