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

redundant_closure triggers for macro #3791

Closed
matthiaskrgr opened this issue Feb 20, 2019 · 5 comments · Fixed by #3816
Closed

redundant_closure triggers for macro #3791

matthiaskrgr opened this issue Feb 20, 2019 · 5 comments · Fixed by #3816
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion

Comments

@matthiaskrgr
Copy link
Member

I was using the get_version_info!() macro and got warnings that the imported code contains redundant closures on places where I used it.

https://github.com/rust-lang/rust-clippy/blob/master/rustc_tools_util/src/lib.rs

Can we disable the lint for code imported via macros?

@flip1995
Copy link
Member

flip1995 commented Feb 21, 2019

Huh? Can you provide an example? The get_version_info!() macro doesn't contain closures, so the lint shouldn't trigger at all. Or am I missing something?

macro_rules! get_version_info {
() => {{
let major = env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
let crate_name = String::from(env!("CARGO_PKG_NAME"));
let host_compiler = $crate::get_channel();
let commit_hash = option_env!("GIT_HASH").map(str::to_string);
let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
VersionInfo {
major,
minor,
patch,
host_compiler,
commit_hash,
commit_date,
crate_name,
}
}};
}

@matthiaskrgr
Copy link
Member Author

matthiaskrgr/cargo-cache@81ffeeb

Yeah it was updated to not contain closures but the crates.io version still contains closures.

@matthiaskrgr
Copy link
Member Author

Anyway, what I mean is, if we report code imported by macros, these macros could also come from third party crates and issuing a lint warning looks like a false positive since the warning cannot be fixed by modifying the root crate.

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Feb 21, 2019
@flip1995
Copy link
Member

Ah that makes sense. We once had an in_external_macro function in utils, but I think it isn't possible anymore to get this information from rustc.

@phansch
Copy link
Member

phansch commented Feb 22, 2019

rustc now has a in_external_macro function: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/fn.in_external_macro.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants