Repository navigation
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
.
Lint Name
no_mangle_with_rust_abi
Reproducer
I tried this code:
// compile-flags: -C no-prepopulate-passes -Copt-level=0
#![crate_type = "lib"]
#![feature(const_eval_select)]
#![feature(core_intrinsics)]
use std::intrinsics::const_eval_select;
const fn foo(_: i32) -> i32 { 1 }
#[no_mangle]
pub fn hi(n: i32) -> i32 { n }
#[no_mangle]
pub unsafe fn hey() {
// CHECK: call i32 @hi(i32
const_eval_select((42,), foo, hi);
}
pub fn main() {}I saw this happen:
cargo clippy --fix --allow-dirty -- -Aclippy::all -Wclippy::no-mangle-with-rust-abi
The suggestion does not compile when applied:
warning: failed to automatically apply fixes suggested by rustc to crate `clippyfix`
after fixes were automatically applied the compiler reported errors within these files:
* src/main.rs
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error[E0277]: expected a `std::ops::FnOnce<(i32,)>` closure, found `extern "C" fn(i32) -> i32 {hi}`
--> src/main.rs:17:35
|
17 | const_eval_select((42,), foo, hi);
| ----------------- ^^ expected an `FnOnce<(i32,)>` closure, found `extern "C" fn(i32) -> i32 {hi}`
| |
| required by a bound introduced by this call
|
= help: the trait `std::ops::FnOnce<(i32,)>` is not implemented for fn item `extern "C" fn(i32) -> i32 {hi}`
note: required by a bound in `std::intrinsics::const_eval_select`
--> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/intrinsics.rs:2182:12
|
2182 | G: FnOnce<ARG, Output = RET>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
Original diagnostics will follow.
warning: attribute #[no_mangle] set on a Rust ABI function
--> src/main.rs:12:1
|
12 | pub fn hi(n: i32) -> i32 { n }
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `pub extern "C" fn hi(n: i32) -> i32`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
= note: requested on the command line with `-W clippy::no-mangle-with-rust-abi`
warning: attribute #[no_mangle] set on a Rust ABI function
--> src/main.rs:15:1
|
15 | pub unsafe fn hey() {
| ^^^^^^^^^^^^^^^^^^^ help: try: `pub unsafe extern "C" fn hey()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
Version
rustc 1.69.0-nightly (d962ea578 2023-02-26)
binary: rustc
commit-hash: d962ea57899d64dc8a57040142c6b498a57c8064
commit-date: 2023-02-26
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Activity
matthiaskrgr commentedon Feb 26, 2023
no_mangleonmain()also introduces some interesting suggestion which does not compile 😅matthiaskrgr commentedon Feb 26, 2023
^
cc @nindalf
Auto merge of #10420 - Jarcho:no_mangle_diag, r=dswij