-
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 #5506 - ebroto:mismatched_target_os, r=flip1995
Implement mismatched_target_os lint I've extended the check suggested in the issue to all the currently supported operating systems instead of limiting it to `linux` and `macos`, let me know if we want to do this. Also, I've restored the text `There are over XXX lints ...` in the README as it was matched against by `cargo dev new_lint`. changelog: Added `mismatched_target_os` lint to warn when an operating system is used in target family position in a #[cfg] attribute Closes #3949
- Loading branch information
Showing
10 changed files
with
582 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::mismatched_target_os)] | ||
#![allow(unused)] | ||
|
||
#[cfg(target_os = "cloudabi")] | ||
fn cloudabi() {} | ||
|
||
#[cfg(target_os = "hermit")] | ||
fn hermit() {} | ||
|
||
#[cfg(target_os = "wasi")] | ||
fn wasi() {} | ||
|
||
#[cfg(target_os = "none")] | ||
fn none() {} | ||
|
||
// list with conditions | ||
#[cfg(all(not(any(windows, target_os = "cloudabi")), target_os = "wasi"))] | ||
fn list() {} | ||
|
||
// windows is a valid target family, should be ignored | ||
#[cfg(windows)] | ||
fn windows() {} | ||
|
||
// correct use, should be ignored | ||
#[cfg(target_os = "hermit")] | ||
fn correct() {} | ||
|
||
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,30 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::mismatched_target_os)] | ||
#![allow(unused)] | ||
|
||
#[cfg(cloudabi)] | ||
fn cloudabi() {} | ||
|
||
#[cfg(hermit)] | ||
fn hermit() {} | ||
|
||
#[cfg(wasi)] | ||
fn wasi() {} | ||
|
||
#[cfg(none)] | ||
fn none() {} | ||
|
||
// list with conditions | ||
#[cfg(all(not(any(windows, cloudabi)), wasi))] | ||
fn list() {} | ||
|
||
// windows is a valid target family, should be ignored | ||
#[cfg(windows)] | ||
fn windows() {} | ||
|
||
// correct use, should be ignored | ||
#[cfg(target_os = "hermit")] | ||
fn correct() {} | ||
|
||
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,51 @@ | ||
error: operating system used in target family position | ||
--> $DIR/mismatched_target_os_non_unix.rs:6:1 | ||
| | ||
LL | #[cfg(cloudabi)] | ||
| ^^^^^^--------^^ | ||
| | | ||
| help: try: `target_os = "cloudabi"` | ||
| | ||
= note: `-D clippy::mismatched-target-os` implied by `-D warnings` | ||
|
||
error: operating system used in target family position | ||
--> $DIR/mismatched_target_os_non_unix.rs:9:1 | ||
| | ||
LL | #[cfg(hermit)] | ||
| ^^^^^^------^^ | ||
| | | ||
| help: try: `target_os = "hermit"` | ||
|
||
error: operating system used in target family position | ||
--> $DIR/mismatched_target_os_non_unix.rs:12:1 | ||
| | ||
LL | #[cfg(wasi)] | ||
| ^^^^^^----^^ | ||
| | | ||
| help: try: `target_os = "wasi"` | ||
|
||
error: operating system used in target family position | ||
--> $DIR/mismatched_target_os_non_unix.rs:15:1 | ||
| | ||
LL | #[cfg(none)] | ||
| ^^^^^^----^^ | ||
| | | ||
| help: try: `target_os = "none"` | ||
|
||
error: operating system used in target family position | ||
--> $DIR/mismatched_target_os_non_unix.rs:19:1 | ||
| | ||
LL | #[cfg(all(not(any(windows, cloudabi)), wasi))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: try | ||
| | ||
LL | #[cfg(all(not(any(windows, target_os = "cloudabi")), wasi))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
help: try | ||
| | ||
LL | #[cfg(all(not(any(windows, cloudabi)), target_os = "wasi"))] | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
Oops, something went wrong.