rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

[`unnecessary_lazy_eval`] Do not lint in external macros

Open kraktus opened this issue 3 years ago • 4 comments

fix https://github.com/rust-lang/rust-clippy/issues/9485, fix https://github.com/rust-lang/rust-clippy/issues/9439

I didn't find a way to add a test since fps occur due to an external crate.

changelog: [unnecessary_lazy_eval] Do not lint in external macros

kraktus avatar Sep 16 '22 15:09 kraktus

r? @giraffate

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

rust-highfive avatar Sep 16 '22 15:09 rust-highfive

@kraktus FYI, I've recently added a test for Derive macro FP here. Maybe we can do something similar?

dswij avatar Sep 16 '22 15:09 dswij

Thanks, I've identified the source of the false positive in rocket codebase: https://github.com/SergioBenitez/Rocket/blob/707936177a7fea6d8eca103cf0b3601ca45fe657/core/codegen/src/derive/from_form.rs#L287

Following your example I've tried to reproduce the issue with a dummy derive macro

#[proc_macro_derive(LazyEvalDerive)]
pub fn unnecessary_lazy_eval(_: TokenStream) -> TokenStream {
    quote!(
        pub fn unnecessary_then() {
            Some(1).unwrap_or_else(|| 2); // should not lint because in external macro
        }
    )
}

but it's not linting it even before my patch, so unlikely my fix is working as intended

kraktus avatar Sep 16 '22 16:09 kraktus

The fix for this needs is_from_proc_macro. You can use the with_span! macro in tests using aux-build:proc_macro_with_span.rs.

Jarcho avatar Sep 16 '22 17:09 Jarcho

:umbrella: The latest upstream changes (presumably #9551) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 29 '22 08:09 bors

@bors r+

dswij avatar Sep 30 '22 07:09 dswij

:pushpin: Commit 6ec7759c3bff136c1d39bbe0bc8a68ac8b438a55 has been approved by dswij

It is now in the queue for this repository.

bors avatar Sep 30 '22 07:09 bors

:hourglass: Testing commit 6ec7759c3bff136c1d39bbe0bc8a68ac8b438a55 with merge 68408c583e5d300e22d911b5c5a60413b5391874...

bors avatar Sep 30 '22 07:09 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: dswij Pushing 68408c583e5d300e22d911b5c5a60413b5391874 to master...

bors avatar Sep 30 '22 08:09 bors