-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Emit specific warning to clarify that #[no_mangle]
should not be applied on foreign statics or functions
#86376
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Can you say more about "may have additional undesired exporting effects"? I would naively expect that there is no additional behavior on extern statics/functions with no_mangle applied, in which case dropping that seems reasonable. I don't think we should indicate an attribute is unused if it actually has a semantic effect (which the new diagnostic implies). |
This PR has two goals.
I believe that this PR accomplishes goal 1 well with the current error message ( Attached is a file that has examples of the current behavior of
To the best of my knowledge, the behavior of I think that in attempting to clarify that the hidden effects make no sense and do not happen, I have made the help text for the lint more confusing. It definitely needs a rewording, but I would ideally like to keep something to the same effect there for the power users that understand the full implications of how |
Ah the file I referenced did not attach, github didn't like the extension, here it is: |
Hm,I believe that no_mangle does not reexport extern static/fns (which are in some sense imports, as you say), and so no_mangle has no effect whatsoever on them, right? The warning text in this PR is:
I would suggest changing the main message and the note text to something like the following, presuming that it is accurate and makes sense in your eyes as well?
|
That updated text looks good. With regards to exporting, I suppose what I was trying to do was contrast the behavior on foreign items with the behavior on everything else and explain why that is unintuitive. However since it |
This comment has been minimized.
This comment has been minimized.
remove extra commented code Deduplicate some diagnostics code add code symbols, machine applicable suggestion clarify error message
0917a8f
to
fc125a5
Compare
@bors r+ rollup Thanks! This looks good to me. I decided to skip a check in with T-lang since this seems like an obvious bug fix and we're just adding a lint here, so we can easily back this out if it shows up more often than expected or there's concerns raised at any point. |
📌 Commit fc125a5 has been approved by |
Rollup of 9 pull requests Successful merges: - rust-lang#86376 (Emit specific warning to clarify that `#[no_mangle]` should not be applied on foreign statics or functions) - rust-lang#88040 (BTree: remove Ord bound from new) - rust-lang#88053 (Fix the flock fallback implementation) - rust-lang#88350 (add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPC) - rust-lang#88410 (Remove bolding on associated constants) - rust-lang#88525 (fix(rustc_typeck): produce better errors for dyn auto trait) - rust-lang#88542 (Use the return value of readdir_r() instead of errno) - rust-lang#88548 (Stabilize `Iterator::intersperse()`) - rust-lang#88551 (Stabilize `UnsafeCell::raw_get()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Foreign statics and foreign functions should not have
#[no_mangle]
applied, as it does nothing to the name and has some extra hidden behavior that is normally unwanted. There was an existing warning for this, but it says the attribute is only allowed on "statics or functions", which to the user can be confusing.This PR adds a specific version of the unused
#[no_mangle]
warning that explains that the target is a foreign static or function and that they do not need the attribute.Fixes #78989