-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #13631 - samueltardieu:push-uoowutzkvsrk, r=Centri3
no_mangle attribute requires unsafe in Rust 2024 Tests without unsafe must not run in edition 2024. Also, error messages have been modified to include the full attribute, so that a use of `#[unsafe(no_mangle)]` does not produce an error message containing `#[no_mangle]`. changelog: [`no_mangle_attribute`]: handle `#[unsafe(no_mangle)]` as well
- Loading branch information
Showing
5 changed files
with
164 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//@edition:2021 | ||
// | ||
// Edition 2024 requires the use of #[unsafe(no_mangle)] | ||
|
||
//@no-rustfix: overlapping suggestions | ||
#![allow(unused)] | ||
#![warn(clippy::no_mangle_with_rust_abi)] | ||
|
||
#[no_mangle] | ||
fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ||
//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
//~| NOTE: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` | ||
|
||
#[no_mangle] | ||
pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ||
//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
|
||
/// # Safety | ||
/// This function shouldn't be called unless the horsemen are ready | ||
#[no_mangle] | ||
pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ||
//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
|
||
/// # Safety | ||
/// This function shouldn't be called unless the horsemen are ready | ||
#[no_mangle] | ||
unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ||
//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
|
||
#[no_mangle] | ||
fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( | ||
//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
arg_one: u32, | ||
arg_two: usize, | ||
) -> u32 { | ||
0 | ||
} | ||
|
||
// Must not run on functions that explicitly opt in to using the Rust ABI with `extern "Rust"` | ||
#[no_mangle] | ||
#[rustfmt::skip] | ||
extern "Rust" fn rust_abi_fn_explicit_opt_in(arg_one: u32, arg_two: usize) {} | ||
|
||
fn rust_abi_fn_again(arg_one: u32, arg_two: usize) {} | ||
|
||
#[no_mangle] | ||
extern "C" fn c_abi_fn(arg_one: u32, arg_two: usize) {} | ||
|
||
extern "C" fn c_abi_fn_again(arg_one: u32, arg_two: usize) {} | ||
|
||
extern "C" { | ||
fn c_abi_in_block(arg_one: u32, arg_two: usize); | ||
} | ||
|
||
fn main() { | ||
// test code goes here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
error: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
--> tests/ui/no_mangle_with_rust_abi_2021.rs:10:1 | ||
| | ||
LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::no_mangle_with_rust_abi)]` | ||
help: set an ABI | ||
| | ||
LL | extern "C" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ||
| ++++++++++ | ||
help: or explicitly set the default | ||
| | ||
LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ||
| +++++++++++++ | ||
|
||
error: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
--> tests/ui/no_mangle_with_rust_abi_2021.rs:15:1 | ||
| | ||
LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: set an ABI | ||
| | ||
LL | pub extern "C" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ||
| ++++++++++ | ||
help: or explicitly set the default | ||
| | ||
LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ||
| +++++++++++++ | ||
|
||
error: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
--> tests/ui/no_mangle_with_rust_abi_2021.rs:21:1 | ||
| | ||
LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: set an ABI | ||
| | ||
LL | pub unsafe extern "C" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ||
| ++++++++++ | ||
help: or explicitly set the default | ||
| | ||
LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ||
| +++++++++++++ | ||
|
||
error: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
--> tests/ui/no_mangle_with_rust_abi_2021.rs:27:1 | ||
| | ||
LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: set an ABI | ||
| | ||
LL | unsafe extern "C" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ||
| ++++++++++ | ||
help: or explicitly set the default | ||
| | ||
LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ||
| +++++++++++++ | ||
|
||
error: `#[no_mangle]` set on a function with the default (`Rust`) ABI | ||
--> tests/ui/no_mangle_with_rust_abi_2021.rs:31:1 | ||
| | ||
LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( | ||
LL | | | ||
LL | | arg_one: u32, | ||
LL | | arg_two: usize, | ||
LL | | ) -> u32 { | ||
| |________^ | ||
| | ||
help: set an ABI | ||
| | ||
LL | extern "C" fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( | ||
| ++++++++++ | ||
help: or explicitly set the default | ||
| | ||
LL | extern "Rust" fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( | ||
| +++++++++++++ | ||
|
||
error: aborting due to 5 previous errors | ||
|