Skip to content

Commit

Permalink
Auto merge of #6682 - camsteffen:let-underscore-ref, r=llogiq
Browse files Browse the repository at this point in the history
Fix let_underscore_drop FP

changelog: Fix let_underscore_drop false positives and negatives

Fixes #6633
  • Loading branch information
bors committed Feb 7, 2021
2 parents dfb34c0 + 40ce056 commit d792210
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion clippy_dev/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn run(port: u16, lint: Option<&str>) -> ! {
// Give some time for python to start
thread::sleep(Duration::from_millis(500));
// Launch browser after first export.py has completed and http.server is up
let _ = opener::open(url);
let _result = opener::open(url);
});
}
thread::sleep(Duration::from_millis(1000));
Expand Down
13 changes: 2 additions & 11 deletions clippy_lints/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_session::{declare_lint_pass, declare_tool_lint};

use crate::utils::{implements_trait, is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};
use crate::utils::{is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};

declare_clippy_lint! {
/// **What it does:** Checks for `let _ = <expr>`
Expand Down Expand Up @@ -125,15 +125,6 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {

GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
});
let implements_drop = cx.tcx.lang_items().drop_trait().map_or(false, |drop_trait|
init_ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => {
implements_trait(cx, inner_ty, drop_trait, &[])
},

GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
})
);
if contains_sync_guard {
span_lint_and_help(
cx,
Expand All @@ -144,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
"consider using an underscore-prefixed named \
binding or dropping explicitly with `std::mem::drop`"
)
} else if implements_drop {
} else if init_ty.needs_drop(cx.tcx, cx.param_env) {
span_lint_and_help(
cx,
LET_UNDERSCORE_DROP,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/macro_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
let found_idx = self.mac_refs.iter().position(|mac| import.ends_with(&mac.name));

if let Some(idx) = found_idx {
let _ = self.mac_refs.remove(idx);
self.mac_refs.remove(idx);
let seg = import.split("::").collect::<Vec<_>>();

match seg.as_slice() {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod tests {
#[should_panic]
fn fix_without_unstable() {
let args = "cargo clippy --fix".split_whitespace().map(ToString::to_string);
let _ = ClippyCmd::new(args);
ClippyCmd::new(args);
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/let_underscore_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ fn main() {
let _ = Box::new(());
let _ = Droppable;
let _ = Some(Droppable);

// no lint for reference
let _ = droppable_ref();
}

#[must_use]
fn droppable_ref() -> &'static mut Droppable {
unimplemented!()
}

0 comments on commit d792210

Please sign in to comment.