Skip to content

Force explicit abi #13372

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
maijun-sec opened this issue Sep 9, 2024 · 2 comments
Closed

Force explicit abi #13372

maijun-sec opened this issue Sep 9, 2024 · 2 comments
Assignees
Labels
A-lint Area: New lints

Comments

@maijun-sec
Copy link

maijun-sec commented Sep 9, 2024

What it does

This is from a configuration of rustfmt force_explicit_abi.

When using extern to specify an external function, it's advised to explicitly specify C-ABI.

Although the default is C-ABI if extern is not specified, it is a convention for Rust to specify it explicitly.

Advantage

  • It is a convention for Rust to specify it explicitly when using extern to specify an external function;
  • Clippy can support to check such scenario that rustfmt can automatically format.

Drawbacks

No response

Example

bad case:

// Noncompliant
extern {
    pub static lorem: c_int;
}

good case:

// Compliant
extern "C" {
    pub static lorem: c_int;
}

extern "Rust" {
    type MyType;
    fn f(&self) -> usize;
}
@maijun-sec maijun-sec added the A-lint Area: New lints label Sep 9, 2024
@CBSpeir
Copy link
Contributor

CBSpeir commented Sep 14, 2024

@rustbot claim

@maijun-sec
Copy link
Author

already have a rustc lint, rust-lang/rust#76219

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants