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

Add lint for inline assembly syntax style preference #6092

Merged
merged 2 commits into from
Sep 30, 2020

Conversation

jethrogb
Copy link

changelog: Add lint for inline assembly syntax style preference

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthiaskrgr (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 28, 2020
@jethrogb jethrogb force-pushed the jb/inline-asm-syntax-lint branch 5 times, most recently from 26150a9 to dace477 Compare September 28, 2020 14:06
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution and welcome to Clippy!

Currently Clippy is reluctant to accept new pre-expansion lints, as it's not clear if support for them will be removed at some point in rustc. Moreover, with a pre-expansion lint we would not be able to catch cases like the following:

#![feature(asm)]

macro_rules! nested {
    () => {
        asm!("");
    }
}

fn main() {
    unsafe {
        nested!();   
    }
}

Luckily, we don't need a pre-expansion pass. We can move the lints to an early pass, check for expressions whose kind is ExprKind::InlineAsm, and then check the syntax with

if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
   // ...
}

tests/ui/asm_syntax.rs Show resolved Hide resolved
@ebroto
Copy link
Member

ebroto commented Sep 29, 2020

r? @ebroto

@rust-highfive rust-highfive assigned ebroto and unassigned matthiaskrgr Sep 29, 2020
@ebroto ebroto added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 29, 2020
@jethrogb jethrogb force-pushed the jb/inline-asm-syntax-lint branch from dace477 to 040c320 Compare September 30, 2020 07:05
@jethrogb
Copy link
Author

Neat! That would've saved me a bunch of work 😃 Only downside is rustc_ast::ast::InlineAsm doesn't contain span information for the options.

@jethrogb jethrogb requested a review from ebroto September 30, 2020 07:07
@jethrogb jethrogb force-pushed the jb/inline-asm-syntax-lint branch from 040c320 to 0690f9c Compare September 30, 2020 07:43
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo the change I've added. If the tests pass I will merge it.

Thanks!

tests/ui/asm_syntax.rs Outdated Show resolved Hide resolved
Use a single `only` header command in asm_syntax test
@ebroto
Copy link
Member

ebroto commented Sep 30, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Sep 30, 2020

📌 Commit 507561e has been approved by ebroto

@bors
Copy link
Contributor

bors commented Sep 30, 2020

⌛ Testing commit 507561e with merge abce9e7...

@bors
Copy link
Contributor

bors commented Sep 30, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: ebroto
Pushing abce9e7 to master...

@bors bors merged commit abce9e7 into rust-lang:master Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants