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

Fix nonstandard_macro_braces FP and docs of disallowed_types #7478

Merged
merged 5 commits into from
Aug 10, 2021

Conversation

DevinR528
Copy link
Contributor

changelog: Fix FP in [nonstandard_macro_braces] lint

@rust-highfive
Copy link

r? @llogiq

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 20, 2021
@DevinR528
Copy link
Contributor Author

DevinR528 commented Jul 20, 2021

I could make this 2 PRs I just wasn't sure if it would be worth it for how small the change is?

Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

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

Can you add tests?

@@ -44,7 +44,7 @@ fn main() {
let _ = format!["ugh {} stop being such a good compiler", "hello"];
let _ = quote!(let x = 1;);
let _ = quote::quote!(match match match);
let _ = test!();
let _ = test!(); // don't trigger for macro calls inside macros
Copy link
Contributor

Choose a reason for hiding this comment

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

You know if the macro is defined within the same crate..... I would argue it makes sense to still emit the lint, but maybe it's not worth complicating the logic further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got something that works, that was a bit of a rabbit hole, Span is a complicated thing...

@DevinR528
Copy link
Contributor Author

With #7488 I'm going to remove the commit to fix the docs of disallowed_type and move it to the other PR.

Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

This looks good in general, I only have one small suggestion for readability.

@@ -93,13 +93,21 @@ impl EarlyLintPass for MacroBraces {
}

fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a MacroBraces) -> Option<MacroInfo<'a>> {
let unnested_or_local = || {
let nested = in_macro(span.ctxt().outer_expn_data().call_site);
let in_local_macro = nested
Copy link
Contributor

Choose a reason for hiding this comment

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

Having nested && here and returning !nested || .. might befuddle at cursory reading. I'd suggest using a guard if instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this what you mean?

let unnested_or_local = || {
    let nested = in_macro(span.ctxt().outer_expn_data().call_site);
    let in_local_macro = matches!(
        span.macro_backtrace().last().and_then(|e| e.macro_def_id),
        Some(defid) if nested && defid.is_local() // adding `nested` to the if guard?
    );
    
    !nested || in_local_macro
};

Copy link
Contributor

@llogiq llogiq Aug 2, 2021

Choose a reason for hiding this comment

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

I was more thinking of

let unnested_or_local = || {
    let nested = in_macro(span.ctxt().outer_expn_data().call_site);
    !nested || span.macro_backtrace().last().map_or(false, |e| 
        e.macro_def_id.map_or(false, |defid| defid.is_local()))
    )
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right duh 🤦 I was asking the same question two times in a row (!nested then nested && ..)

@DevinR528
Copy link
Contributor Author

Should I squash, or is there anything else, thanks again!

@llogiq
Copy link
Contributor

llogiq commented Aug 8, 2021

No, that should be fine.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2021

📌 Commit bc7fac9 has been approved by llogiq

@bors
Copy link
Contributor

bors commented Aug 8, 2021

⌛ Testing commit bc7fac9 with merge 722c7bb...

bors added a commit that referenced this pull request Aug 8, 2021
Fix nonstandard_macro_braces FP and docs of disallowed_types

changelog: Fix FP in [`nonstandard_macro_braces`] lint
@bors
Copy link
Contributor

bors commented Aug 8, 2021

💔 Test failed - checks-action_test

@giraffate
Copy link
Contributor

@bors retry

@bors
Copy link
Contributor

bors commented Aug 10, 2021

⌛ Testing commit bc7fac9 with merge f998e89...

@bors
Copy link
Contributor

bors commented Aug 10, 2021

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

@bors bors merged commit f998e89 into rust-lang:master Aug 10, 2021
@DevinR528 DevinR528 deleted the preemtive branch August 12, 2021 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants