Skip to content

Commit d792210

Browse files
committed
Auto merge of #6682 - camsteffen:let-underscore-ref, r=llogiq
Fix let_underscore_drop FP changelog: Fix let_underscore_drop false positives and negatives Fixes #6633
2 parents dfb34c0 + 40ce056 commit d792210

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

clippy_dev/src/serve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn run(port: u16, lint: Option<&str>) -> ! {
3434
// Give some time for python to start
3535
thread::sleep(Duration::from_millis(500));
3636
// Launch browser after first export.py has completed and http.server is up
37-
let _ = opener::open(url);
37+
let _result = opener::open(url);
3838
});
3939
}
4040
thread::sleep(Duration::from_millis(1000));

clippy_lints/src/let_underscore.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::lint::in_external_macro;
55
use rustc_middle::ty::subst::GenericArgKind;
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77

8-
use crate::utils::{implements_trait, is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};
8+
use crate::utils::{is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};
99

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

126126
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
127127
});
128-
let implements_drop = cx.tcx.lang_items().drop_trait().map_or(false, |drop_trait|
129-
init_ty.walk().any(|inner| match inner.unpack() {
130-
GenericArgKind::Type(inner_ty) => {
131-
implements_trait(cx, inner_ty, drop_trait, &[])
132-
},
133-
134-
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
135-
})
136-
);
137128
if contains_sync_guard {
138129
span_lint_and_help(
139130
cx,
@@ -144,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
144135
"consider using an underscore-prefixed named \
145136
binding or dropping explicitly with `std::mem::drop`"
146137
)
147-
} else if implements_drop {
138+
} else if init_ty.needs_drop(cx.tcx, cx.param_env) {
148139
span_lint_and_help(
149140
cx,
150141
LET_UNDERSCORE_DROP,

clippy_lints/src/macro_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
160160
let found_idx = self.mac_refs.iter().position(|mac| import.ends_with(&mac.name));
161161

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

166166
match seg.as_slice() {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod tests {
195195
#[should_panic]
196196
fn fix_without_unstable() {
197197
let args = "cargo clippy --fix".split_whitespace().map(ToString::to_string);
198-
let _ = ClippyCmd::new(args);
198+
ClippyCmd::new(args);
199199
}
200200

201201
#[test]

tests/ui/let_underscore_drop.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ fn main() {
1616
let _ = Box::new(());
1717
let _ = Droppable;
1818
let _ = Some(Droppable);
19+
20+
// no lint for reference
21+
let _ = droppable_ref();
22+
}
23+
24+
#[must_use]
25+
fn droppable_ref() -> &'static mut Droppable {
26+
unimplemented!()
1927
}

0 commit comments

Comments
 (0)