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

Broken fix suggestion for no_mangle_with_rust_abi #13656

Closed
balt-dev opened this issue Nov 5, 2024 · 2 comments · Fixed by #13659
Closed

Broken fix suggestion for no_mangle_with_rust_abi #13656

balt-dev opened this issue Nov 5, 2024 · 2 comments · Fixed by #13659
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@balt-dev
Copy link

balt-dev commented Nov 5, 2024

Summary

The fix suggestion for this lint proposes putting a fix where it shouldn't be if there's an occurrence of the string fn anywhere before the fn keyword.

Reproducer

#![warn(clippy::no_mangle_with_rust_abi)]

mod r#fn {
    #[no_mangle]
    pub(in super::r#fn) fn breaking() {}
}

This code suggests putting extern "C" in-between r# and fn, instead of ) and fn:

warning: `#[no_mangle]` set on a function with the default (`Rust`) ABI
 --> src/lib.rs:5:5
  |
5 |     pub(in super::r#fn) fn breaking() {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::no_mangle_with_rust_abi)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: set an ABI
  |
5 |     pub(in super::r#extern "C" fn) fn breaking() {}
  |                     ++++++++++
help: or explicitly set the default
  |
5 |     pub(in super::r#extern "Rust" fn) fn breaking() {}
  |                     +++++++++++++

This is caused by it being implemented with a naive string replacement.

Version

rustc 1.84.0-nightly (b8c8287a2 2024-11-03)
binary: rustc
commit-hash: b8c8287a229cd79604aa84c25e1235fc78cd5f2e
commit-date: 2024-11-03
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Additional Labels

@rustbot label I-suggestion-causes-error

@balt-dev balt-dev added the C-bug Category: Clippy is not doing the correct thing label Nov 5, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Nov 5, 2024
@balt-dev
Copy link
Author

balt-dev commented Nov 5, 2024

@nindalf since you were the original implementor, i feel you should know about this

@balt-dev
Copy link
Author

balt-dev commented Nov 5, 2024

This is an edge case, but it's still very good to know about.

@bors bors closed this as completed in f02a020 Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants