Skip to content

Commit 3219fdd

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 61b68f1 + 80ed505 commit 3219fdd

File tree

17 files changed

+32
-38
lines changed

17 files changed

+32
-38
lines changed

src/librustc/traits/structural_impls.rs

+3-3
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

+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_llvm/context.rs

-1
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

+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_errors/registry.rs

+1-1
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

+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_parse/parser/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> Parser<'a> {
3737
let inner_parse_policy = InnerAttributeParsePolicy::NotPermitted {
3838
reason: inner_error_reason,
3939
saw_doc_comment: just_parsed_doc_comment,
40-
prev_attr_sp: attrs.last().and_then(|a| Some(a.span)),
40+
prev_attr_sp: attrs.last().map(|a| a.span),
4141
};
4242
let attr = self.parse_attribute_with_inner_parse_policy(inner_parse_policy)?;
4343
attrs.push(attr);

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 {

src/librustc_resolve/late/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10861086
for param in params {
10871087
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span)
10881088
{
1089-
if snippet.starts_with("&") && !snippet.starts_with("&'") {
1089+
if snippet.starts_with('&') && !snippet.starts_with("&'") {
10901090
introduce_suggestion
10911091
.push((param.span, format!("&'a {}", &snippet[1..])));
10921092
} else if snippet.starts_with("&'_ ") {
@@ -1118,7 +1118,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11181118
(1, Some(name), Some("'_")) => {
11191119
suggest_existing(err, name.to_string());
11201120
}
1121-
(1, Some(name), Some(snippet)) if !snippet.ends_with(">") => {
1121+
(1, Some(name), Some(snippet)) if !snippet.ends_with('>') => {
11221122
suggest_existing(err, format!("{}<{}>", snippet, name));
11231123
}
11241124
(0, _, Some("&")) => {
@@ -1127,7 +1127,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11271127
(0, _, Some("'_")) => {
11281128
suggest_new(err, "'a");
11291129
}
1130-
(0, _, Some(snippet)) if !snippet.ends_with(">") => {
1130+
(0, _, Some(snippet)) if !snippet.ends_with('>') => {
11311131
suggest_new(err, &format!("{}<'a>", snippet));
11321132
}
11331133
_ => {

src/librustc_typeck/check/method/probe.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -1550,21 +1550,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15501550

15511551
let method_names = pcx.candidate_method_names();
15521552
pcx.allow_similar_names = false;
1553-
let applicable_close_candidates: Vec<ty::AssocItem> =
1554-
method_names
1555-
.iter()
1556-
.filter_map(|&method_name| {
1557-
pcx.reset();
1558-
pcx.method_name = Some(method_name);
1559-
pcx.assemble_inherent_candidates();
1560-
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
1561-
.map_or(None, |_| {
1562-
pcx.pick_core()
1563-
.and_then(|pick| pick.ok())
1564-
.and_then(|pick| Some(pick.item))
1565-
})
1566-
})
1567-
.collect();
1553+
let applicable_close_candidates: Vec<ty::AssocItem> = method_names
1554+
.iter()
1555+
.filter_map(|&method_name| {
1556+
pcx.reset();
1557+
pcx.method_name = Some(method_name);
1558+
pcx.assemble_inherent_candidates();
1559+
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
1560+
.map_or(None, |_| {
1561+
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
1562+
})
1563+
})
1564+
.collect();
15681565

15691566
if applicable_close_candidates.is_empty() {
15701567
Ok(None)

src/librustdoc/clean/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ pub fn external_generic_args(
121121
let args: Vec<_> = substs
122122
.iter()
123123
.filter_map(|kind| match kind.unpack() {
124-
GenericArgKind::Lifetime(lt) => {
125-
lt.clean(cx).and_then(|lt| Some(GenericArg::Lifetime(lt)))
126-
}
124+
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
127125
GenericArgKind::Type(_) if skip_self => {
128126
skip_self = false;
129127
None

src/librustdoc/html/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
296296
""
297297
}
298298
)),
299-
playground_button.as_ref().map(String::as_str),
299+
playground_button.as_deref(),
300300
Some((s1.as_str(), s2)),
301301
));
302302
Some(Event::Html(s.into()))
@@ -315,7 +315,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
315315
""
316316
}
317317
)),
318-
playground_button.as_ref().map(String::as_str),
318+
playground_button.as_deref(),
319319
None,
320320
));
321321
Some(Event::Html(s.into()))

0 commit comments

Comments
 (0)