forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#131558 - sassman:feat/warnin-for-no-mangle-together-with-export-name, r=Urgau Lint on combining `#[no_mangle]` and `#[export_name]` This is my very first contribution to the compiler, even though I read the [chapter about lints](https://rustc-dev-guide.rust-lang.org/diagnostics.html) I'm not very certain that this ~~new lint is done right as a builtin lint~~ PR is right. I appreciate any guidance on how to improve the code. - Add test for issue rust-lang#47446 - ~~Implement the new lint `mixed_export_name_and_no_mangle` as a builtin lint (not sure if that is the right way to go)~~ Extend `unused_attributes` lint - Add suggestion how to fix it <details> <summary>Old proposed new lint</summary> > The `mixed_export_name_and_no_mangle` lint detects usage of both `#[export_name]` and `#[no_mangle]` on the same item which results on `#[no_mangle]` being ignored. > > *warn-by-default* > > ### Example > > ```rust > #[no_mangle] // ignored > #[export_name = "foo"] // takes precedences > pub fn bar() {} > ``` > > ### Explanation > > The compiler will not respect the `#[no_mangle]` attribute when generating the symbol name for the function, as the `#[export_name]` attribute takes precedence. This can lead to confusion and is unnecessary. </details>
- Loading branch information
Showing
9 changed files
with
143 additions
and
5 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
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,14 @@ | ||
// issue: rust-lang/rust#47446 | ||
//@ run-rustfix | ||
//@ check-pass | ||
|
||
#![warn(unused_attributes)] | ||
//~^ WARN `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes] | ||
#[export_name = "foo"] | ||
pub fn bar() {} | ||
|
||
//~^ WARN `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes] | ||
#[export_name = "baz"] | ||
pub fn bak() {} | ||
|
||
fn main() {} |
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,16 @@ | ||
// issue: rust-lang/rust#47446 | ||
//@ run-rustfix | ||
//@ check-pass | ||
|
||
#![warn(unused_attributes)] | ||
#[no_mangle] | ||
//~^ WARN `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes] | ||
#[export_name = "foo"] | ||
pub fn bar() {} | ||
|
||
#[unsafe(no_mangle)] | ||
//~^ WARN `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes] | ||
#[export_name = "baz"] | ||
pub fn bak() {} | ||
|
||
fn main() {} |
39 changes: 39 additions & 0 deletions
39
tests/ui/attributes/mixed_export_name_and_no_mangle.stderr
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,39 @@ | ||
warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` | ||
--> $DIR/mixed_export_name_and_no_mangle.rs:6:1 | ||
| | ||
LL | #[no_mangle] | ||
| ^^^^^^^^^^^^ `#[no_mangle]` is ignored | ||
| | ||
note: `#[export_name]` takes precedence | ||
--> $DIR/mixed_export_name_and_no_mangle.rs:8:1 | ||
| | ||
LL | #[export_name = "foo"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
note: the lint level is defined here | ||
--> $DIR/mixed_export_name_and_no_mangle.rs:5:9 | ||
| | ||
LL | #![warn(unused_attributes)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
help: remove the `#[no_mangle]` attribute | ||
| | ||
LL - #[no_mangle] | ||
| | ||
|
||
warning: `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` | ||
--> $DIR/mixed_export_name_and_no_mangle.rs:11:1 | ||
| | ||
LL | #[unsafe(no_mangle)] | ||
| ^^^^^^^^^^^^^^^^^^^^ `#[unsafe(no_mangle)]` is ignored | ||
| | ||
note: `#[export_name]` takes precedence | ||
--> $DIR/mixed_export_name_and_no_mangle.rs:13:1 | ||
| | ||
LL | #[export_name = "baz"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
help: remove the `#[unsafe(no_mangle)]` attribute | ||
| | ||
LL - #[unsafe(no_mangle)] | ||
| | ||
|
||
warning: 2 warnings emitted | ||
|