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 used_underscore_binding #947

Closed
mcarton opened this issue May 23, 2016 · 11 comments · Fixed by #11523
Closed

Fix used_underscore_binding #947

mcarton opened this issue May 23, 2016 · 11 comments · Fixed by #11523
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@mcarton
Copy link
Member

mcarton commented May 23, 2016

In #944, used_underscore_binding was made allow and to ignore _result as a ugly hack. This should be fixed.

@llogiq
Copy link
Contributor

llogiq commented May 24, 2016

How? Does a macro check work here?

@Manishearth
Copy link
Member

We could just have rustc emit __result instead

@bluss
Copy link
Member

bluss commented May 25, 2016

using an underscored binding is useful in macros to avoid having the "unused variable" default rustc lint fire for the macro case where it's not needed, while still allowing it to be used for the > 0 argument cases.

@Manishearth
Copy link
Member

rustc uses double underscores for "maybe used idk" bindings in macros, clippy doesn't warn on those

@oli-obk
Copy link
Contributor

oli-obk commented May 25, 2016

clippy doesn't warn on used underscore bindings in macros if the binding was declared inside the macro

@oli-obk
Copy link
Contributor

oli-obk commented May 25, 2016

I'm currently evaluating if it's possible to insert the hir-lowerings into the expansion-database, so we can treat them just as we treat macros.

@bluss
Copy link
Member

bluss commented May 25, 2016

@oli-obk That must be a recent change

@oli-obk
Copy link
Contributor

oli-obk commented May 25, 2016

@oli-obk That must be a recent change

no, you're right, it isn't checked. I wonder why...

@mcarton mcarton added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Aug 30, 2016
@oli-obk
Copy link
Contributor

oli-obk commented Jan 10, 2020

cc @ThibsG this is the lint we were talking about, but I'm not sure at all whether we do now know that the _result from rustc is unused

@camsteffen camsteffen added C-bug Category: Clippy is not doing the correct thing and removed C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Oct 26, 2021
@hellow554
Copy link
Contributor

I came across this today, which is a valid reason to use an underscore variable IMHO:

let _unused = get_option();
debug_assert!(_unused.is_some());

@kraktus
Copy link
Contributor

kraktus commented Nov 25, 2022

In the above case debug_assert!(get_option().is_some()); would resolve it though

I triggered it with features flag (pseudo-code):

pub fn foo(x: usize) -> usize { internal_foo(x, None) }
#[cfg(feature = "cached")]
pub fn foo_cached(x: usize, cache_key: u64) -> usize { internal_foo(x, Some(cache_key)) } 
fn internal_foo(x: usize, cache_key: Option<u64>) -> usize { ... }

This can probably be avoided if I used internal_foo as a macro rather than a function, but maybe would be worth adding to the output that if intentional could use __variable instead?

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants