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

non_upper_case_globals lint should be suppressed for #[no_mangle] items #36258

Closed
tomjakubowski opened this issue Sep 4, 2016 · 3 comments
Closed
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.

Comments

@tomjakubowski
Copy link
Contributor

tomjakubowski commented Sep 4, 2016

#[no_mangle]
pub static this_symbol_is_required_to_exist: i32 = 1;

fn main() {
}

Yields compiler warning:

warning: static constant `this_symbol_is_required_to_exist` should have an upper case name such as `THIS_SYMBOL_IS_REQUIRED_TO_EXIST`, #[warn(non_upper_case_globals)] on by default
 --> <anon>:2:1
  |
2 | pub static this_symbol_is_required_to_exist: i32 = 1;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think #[no_mangle] is a good hint that the symbol's name (incl. capitalization) is important enough that stylistic lints should be disabled for it. The lint already ignores functions in extern "C" {} blocks, for example:

extern "C" {
    pub fn This_IS_WaCkYcapitalization();
}
@nagisa
Copy link
Member

nagisa commented Sep 4, 2016

You should use export_name instead.

@joshtriplett
Copy link
Member

@nagisa That would work, but would require repetition, naming the symbol twice. And it would give the symbol a different name in Rust and in C, which could lead to user confusion. If the interface to external code requires a symbol with a given name, FFI code may wish to use that name.

@nagisa
Copy link
Member

nagisa commented Sep 5, 2016

@joshtriplett I personally feel that consistency with surrounding rust code (i.e. rust conventions) is more important than consistency with the exported symbols (remember, you cannot just wrap statics either).

Either way, I guess my case is just a stylistic preference and this bug is certainly valid.

@Mark-Simulacrum Mark-Simulacrum added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label May 13, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 26, 2017
kennytm added a commit to kennytm/rust that referenced this issue Apr 11, 2018
…r=michaelwoerister

Do not uppercase-lint #[no_mangle] statics

The reasoning being that `#[no_mangle]` expresses enough intention that there's likely a good reason for the name.

Fixes rust-lang#36258.
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.
Projects
None yet
Development

No branches or pull requests

4 participants