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

Check for invalid target_arch #7828

Open
Tracked by #79
asomers opened this issue Oct 16, 2021 · 2 comments
Open
Tracked by #79

Check for invalid target_arch #7828

asomers opened this issue Oct 16, 2021 · 2 comments
Labels
A-lint Area: New lints S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work T-macros Type: Issues with macros and macro expansion

Comments

@asomers
Copy link

asomers commented Oct 16, 2021

What it does

Checks if the value used with #[cfg(target_arch = "XXX")] is valid.

Categories (optional)

  • Kind: correctness

For example:

  • Detects dead code that almost certainly shouldn't be dead

Drawbacks

Might not be forwards-compatible with architectures added by future compilers. For example, if Rust 1.75.0 adds support for itanium and a crate cfg-gates on that, Clippy 1.74.0 would falsely warn about it.

Example

A real-world example from the Nix crate: nix-rust/nix#1566

#[cfg(target_arch = "ppc")]
pub struct Foo{}

Should be written as:

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
pub struct Foo{}
@asomers asomers added the A-lint Area: New lints label Oct 16, 2021
@asomers
Copy link
Author

asomers commented Oct 17, 2021

Also, checking for invalid target_env would be good. I just discovered some code that was wrongly checking for target_env = "newlibc" instead of target_env = "newlib".

@xFrednet
Copy link
Member

Hey, thank you for the suggestion. In general, it could be nice to check for valid targets etc.

The current API of rustc(which Clippy uses) sadly doesn't really support lints that check code before the expansion of macros. At one point, we want to have some kind of interface to also lint macros, like in this example. For now, I'll add the blocked label until we find a good way to handle macros 🙃

@xFrednet xFrednet added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work T-macros Type: Issues with macros and macro expansion labels Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

2 participants