Skip to content

Commit d8d2004

Browse files
committed
Don't use "if let" bindings to only check a value and not actually bind anything.
For example: `if let Some(_) = foo() {}` can be reduced to `if foo().is_some() {}` (clippy::redundant_pattern_matching)
1 parent 38f5db7 commit d8d2004

File tree

9 files changed

+9
-9
lines changed

9 files changed

+9
-9
lines changed

src/librustc_codegen_llvm/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pub(crate) unsafe fn codegen(
725725
Err(_) => return 0,
726726
};
727727

728-
if let Err(_) = write!(cursor, "{:#}", demangled) {
728+
if write!(cursor, "{:#}", demangled).is_err() {
729729
// Possible only if provided buffer is not big enough
730730
return 0;
731731
}

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
12571257
if main_thread_worker_state == MainThreadWorkerState::Idle {
12581258
if !queue_full_enough(work_items.len(), running, max_workers) {
12591259
// The queue is not full enough, codegen more items:
1260-
if let Err(_) = codegen_worker_send.send(Message::CodegenItem) {
1260+
if codegen_worker_send.send(Message::CodegenItem).is_err() {
12611261
panic!("Could not send Message::CodegenItem to main thread")
12621262
}
12631263
main_thread_worker_state = MainThreadWorkerState::Codegenning;

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl CodeSuggestion {
163163
None => buf.push_str(&line[lo..]),
164164
}
165165
}
166-
if let None = hi_opt {
166+
if hi_opt.is_none() {
167167
buf.push('\n');
168168
}
169169
}

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut
426426
for a in attrs.iter() {
427427
if a.check_name(sym::crate_type) {
428428
if let Some(n) = a.value_str() {
429-
if let Some(_) = categorize_crate_type(n) {
429+
if categorize_crate_type(n).is_some() {
430430
return;
431431
}
432432

src/librustc_lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl LintStore {
335335
lint_name.to_string()
336336
};
337337
// If the lint was scoped with `tool::` check if the tool lint exists
338-
if let Some(_) = tool_name {
338+
if tool_name.is_some() {
339339
match self.by_name.get(&complete_name) {
340340
None => match self.lint_groups.get(&*complete_name) {
341341
None => return CheckLintNameResult::Tool(Err((None, String::new()))),

src/librustc_mir/borrow_check/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19051905
// expressions evaluate through `as_temp` or `into` a return
19061906
// slot or local, so to find all unsized rvalues it is enough
19071907
// to check all temps, return slots and locals.
1908-
if let None = self.reported_errors.replace((ty, span)) {
1908+
if self.reported_errors.replace((ty, span)).is_none() {
19091909
let mut diag = struct_span_err!(
19101910
self.tcx().sess,
19111911
span,

src/librustc_mir/borrow_check/type_check/relate_tys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
6464
}
6565

6666
fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> {
67-
if let Some(_) = &mut self.borrowck_context {
67+
if self.borrowck_context.is_some() {
6868
let origin = NLLRegionVariableOrigin::Existential { from_forall };
6969
self.infcx.next_nll_region_var(origin)
7070
} else {

src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
565565

566566
// # Function pointers
567567
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
568-
if let Some(_) = self.get_fn_alloc(id) {
568+
if self.get_fn_alloc(id).is_some() {
569569
return if let AllocCheck::Dereferenceable = liveness {
570570
// The caller requested no function pointers.
571571
throw_unsup!(DerefFunctionPointer)

src/librustc_passes/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
196196
// The file may be empty, which leads to the diagnostic machinery not emitting this
197197
// note. This is a relatively simple way to detect that case and emit a span-less
198198
// note instead.
199-
if let Ok(_) = tcx.sess.source_map().lookup_line(sp.lo()) {
199+
if tcx.sess.source_map().lookup_line(sp.lo()).is_ok() {
200200
err.set_span(sp);
201201
err.span_label(sp, &note);
202202
} else {

0 commit comments

Comments
 (0)