Skip to content

Commit 5089e11

Browse files
authored
Rollup merge of #69713 - matthiaskrgr:more_cleanup, r=cramertj
more clippy cleanups * Don't use .ok() before unwrapping via .expect() on a Result. * Use .map() to modify data inside Options instead of using .and_then(|x| Some(y)) * Use .as_deref() instead of .as_ref().map(Deref::deref) * Don't use "if let" bindings to only check a value and not actually bind anything. * Use single-char patter on {ends,starts}_with and remove clone on copy type.
2 parents e15d393 + 80ed505 commit 5089e11

File tree

17 files changed

+32
-38
lines changed

17 files changed

+32
-38
lines changed

src/librustc/traits/structural_impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
415415
super::ReferenceOutlivesReferent(ty) => {
416416
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
417417
}
418-
super::ObjectTypeBound(ty, r) => tcx
419-
.lift(&ty)
420-
.and_then(|ty| tcx.lift(&r).and_then(|r| Some(super::ObjectTypeBound(ty, r)))),
418+
super::ObjectTypeBound(ty, r) => {
419+
tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
420+
}
421421
super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
422422
super::Coercion { source, target } => {
423423
Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })

src/librustc_codegen_llvm/back/write.rs

Lines changed: 1 addition & 1 deletion
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_llvm/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pub unsafe fn create_module(
174174

175175
let llvm_data_layout = llvm::LLVMGetDataLayout(llmod);
176176
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
177-
.ok()
178177
.expect("got a non-UTF8 data-layout from LLVM");
179178

180179
// Unfortunately LLVM target specs change over time, and right now we

src/librustc_codegen_ssa/back/write.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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_errors/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ impl Registry {
2727
if !self.long_descriptions.contains_key(code) {
2828
return Err(InvalidErrorCode);
2929
}
30-
Ok(self.long_descriptions.get(code).unwrap().clone())
30+
Ok(*self.long_descriptions.get(code).unwrap())
3131
}
3232
}

src/librustc_interface/util.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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 {

0 commit comments

Comments
 (0)