Skip to content
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

Warn when using link_name in exported items ? #55313

Closed
gnzlbg opened this issue Oct 24, 2018 · 4 comments
Closed

Warn when using link_name in exported items ? #55313

gnzlbg opened this issue Oct 24, 2018 · 4 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 24, 2018

In this context:

#[link_name = "foo"]
pub static mut FOO: i32 = 4;

what does link_name do? Chances are that the user actually meant to export FOO and that

#[export_name = "foo"]
pub static mut FOO: i32 = 4;

was intended instead.

Should we warn/error about this?

cc @alexcrichton

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 25, 2018
@Centril
Copy link
Contributor

Centril commented Oct 25, 2018

cc @japaric

@Centril Centril added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Oct 25, 2018
@alexcrichton
Copy link
Member

Yes here #[link_name] has no effect, so it should ideally provide an unused attribute warning

@Enselic
Copy link
Member

Enselic commented Jul 23, 2023

Since a while (I think since #73461 which added bunch of tests for this) this is now fixed.

$ rustc src/lib.rs --crate-type lib
warning: attribute should be applied to a foreign function or static
 --> src/lib.rs:1:1
  |
1 | #[link_name = "foo"]
  | ^^^^^^^^^^^^^^^^^^^^
2 | pub static mut FOO: i32 = 4;
  | ---------------------------- not a foreign function or static
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: `#[warn(unused_attributes)]` on by default

warning: 1 warning emitted

@Enselic
Copy link
Member

Enselic commented Aug 17, 2023

Closing since this has been fixed and tests have been added.

@Enselic Enselic closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants