Skip to content

Commit 1185d8b

Browse files
authored
Rollup merge of #69802 - matthiaskrgr:cl1ppy, r=Dylan-DPC
fix more clippy findings * reduce references on match patterns (clippy::match_ref_pats) * Use writeln!(fmt, "word") instead of write!(fmt, "word\n") (clippy::write_with_newline) * libtest: remove redundant argument to writeln!() (clippy::writeln_empty_string) * remove unneeded mutable references (cippy::unnecessary_mut_passed) * libtest: declare variables as floats instead of casting them (clippy::unnecessary_cast) * rustdoc: remove redundant static lifetimes (clippy::redundant_static_lifetimes) * call .as_deref() instead of .as_ref().map(Deref::deref) (clippy::option_as_ref_deref) * iterate over a maps values directly. (clippy::for_kv_map) * rustdoc: simplify boolean condition (clippy::nonminimal_bool) * Use ?-operator in more places (clippy::question_mark, had some false negatives fixed recently) * rustdoc: Use .any(p) instead of find(p).is_some(). (clippy::search_is_some) * rustdoc: don't call into_iter() on iterator. (clippy::identity_conversion)
2 parents 5831003 + 8351138 commit 1185d8b

File tree

23 files changed

+78
-118
lines changed

23 files changed

+78
-118
lines changed

src/libcore/str/pattern.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
365365
let haystack = self.haystack.as_bytes();
366366
loop {
367367
// get the haystack up to but not including the last character searched
368-
let bytes = if let Some(slice) = haystack.get(self.finger..self.finger_back) {
369-
slice
370-
} else {
371-
return None;
372-
};
368+
let bytes = haystack.get(self.finger..self.finger_back)?;
373369
// the last byte of the utf8 encoded needle
374370
// SAFETY: we have an invariant that `utf8_size < 5`
375371
let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
@@ -575,11 +571,12 @@ macro_rules! pattern_methods {
575571

576572
#[inline]
577573
fn is_suffix_of(self, haystack: &'a str) -> bool
578-
where $t: ReverseSearcher<'a>
574+
where
575+
$t: ReverseSearcher<'a>,
579576
{
580577
($pmap)(self).is_suffix_of(haystack)
581578
}
582-
}
579+
};
583580
}
584581

585582
macro_rules! searcher_methods {
@@ -614,7 +611,7 @@ macro_rules! searcher_methods {
614611
fn next_reject_back(&mut self) -> Option<(usize, usize)> {
615612
self.0.next_reject_back()
616613
}
617-
}
614+
};
618615
}
619616

620617
/////////////////////////////////////////////////////////////////////////////

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'hir> Map<'hir> {
298298
}
299299

300300
pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
301-
let node = if let Some(node) = self.find(hir_id) { node } else { return None };
301+
let node = self.find(hir_id)?;
302302

303303
Some(match node {
304304
Node::Item(item) => match item.kind {

src/librustc/ty/util.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,7 @@ impl<'tcx> TyCtxt<'tcx> {
346346
adt_did: DefId,
347347
validate: &mut dyn FnMut(Self, DefId) -> Result<(), ErrorReported>,
348348
) -> Option<ty::Destructor> {
349-
let drop_trait = if let Some(def_id) = self.lang_items().drop_trait() {
350-
def_id
351-
} else {
352-
return None;
353-
};
354-
349+
let drop_trait = self.lang_items().drop_trait()?;
355350
self.ensure().coherent_trait(drop_trait);
356351

357352
let mut dtor_did = None;

src/librustc_driver/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,12 +1124,7 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
11241124
return None;
11251125
}
11261126

1127-
let matches = if let Some(matches) = handle_options(&args) {
1128-
matches
1129-
} else {
1130-
return None;
1131-
};
1132-
1127+
let matches = handle_options(&args)?;
11331128
let mut result = Vec::new();
11341129
let mut excluded_cargo_defaults = false;
11351130
for flag in ICE_REPORT_COMPILER_FLAGS {

src/librustc_infer/traits/auto_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
113113
return AutoTraitResult::ExplicitImpl;
114114
}
115115

116-
return tcx.infer_ctxt().enter(|mut infcx| {
116+
return tcx.infer_ctxt().enter(|infcx| {
117117
let mut fresh_preds = FxHashSet::default();
118118

119119
// Due to the way projections are handled by SelectionContext, we need to run
@@ -164,7 +164,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
164164

165165
let (full_env, full_user_env) = self
166166
.evaluate_predicates(
167-
&mut infcx,
167+
&infcx,
168168
trait_did,
169169
ty,
170170
new_env,

src/librustc_infer/traits/specialize/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,7 @@ pub(super) fn specialization_graph_provider(
413413
fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
414414
use std::fmt::Write;
415415

416-
let trait_ref = if let Some(tr) = tcx.impl_trait_ref(impl_def_id) {
417-
tr
418-
} else {
419-
return None;
420-
};
421-
416+
let trait_ref = tcx.impl_trait_ref(impl_def_id)?;
422417
let mut w = "impl".to_owned();
423418

424419
let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);

src/librustc_mir/transform/generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ fn create_generator_drop_shim<'tcx>(
944944
// unrelated code from the resume part of the function
945945
simplify::remove_dead_blocks(&mut body);
946946

947-
dump_mir(tcx, None, "generator_drop", &0, source, &mut body, |_, _| Ok(()));
947+
dump_mir(tcx, None, "generator_drop", &0, source, &body, |_, _| Ok(()));
948948

949949
body
950950
}

src/librustc_mir/util/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn dump_matched_mir_node<'tcx>(
293293
writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?;
294294
writeln!(file, "// source = {:?}", source)?;
295295
writeln!(file, "// pass_name = {}", pass_name)?;
296-
writeln!(file, "")?;
296+
writeln!(file)?;
297297
write_mir_fn(tcx, source, body, &mut file, result)?;
298298
Ok(())
299299
});
@@ -316,7 +316,7 @@ pub fn write_mir_fn<'tcx>(
316316
write_basic_block(tcx, block, body, &mut |_, _| Ok(()), w)?;
317317
print(w, " ", &result.outs)?;
318318
if block.index() + 1 != body.basic_blocks().len() {
319-
writeln!(w, "")?;
319+
writeln!(w)?;
320320
}
321321
}
322322

src/librustc_mir/util/pretty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn dump_matched_mir_node<'tcx, F>(
134134
if let Some(ref layout) = body.generator_layout {
135135
writeln!(file, "// generator_layout = {:?}", layout)?;
136136
}
137-
writeln!(file, "")?;
137+
writeln!(file)?;
138138
extra_data(PassWhere::BeforeCFG, &mut file)?;
139139
write_user_type_annotations(body, &mut file)?;
140140
write_mir_fn(tcx, source, body, &mut extra_data, &mut file)?;
@@ -242,13 +242,13 @@ pub fn write_mir_pretty<'tcx>(
242242
first = false;
243243
} else {
244244
// Put empty lines between all items
245-
writeln!(w, "")?;
245+
writeln!(w)?;
246246
}
247247

248248
write_mir_fn(tcx, MirSource::item(def_id), body, &mut |_, _| Ok(()), w)?;
249249

250250
for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
251-
writeln!(w, "")?;
251+
writeln!(w)?;
252252
let src = MirSource { instance: ty::InstanceDef::Item(def_id), promoted: Some(i) };
253253
write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?;
254254
}
@@ -271,7 +271,7 @@ where
271271
extra_data(PassWhere::BeforeBlock(block), w)?;
272272
write_basic_block(tcx, block, body, extra_data, w)?;
273273
if block.index() + 1 != body.basic_blocks().len() {
274-
writeln!(w, "")?;
274+
writeln!(w)?;
275275
}
276276
}
277277

@@ -529,7 +529,7 @@ pub fn write_mir_intro<'tcx>(
529529
write_scope_tree(tcx, body, &scope_tree, w, OUTERMOST_SOURCE_SCOPE, 1)?;
530530

531531
// Add an empty line before the first block is printed.
532-
writeln!(w, "")?;
532+
writeln!(w)?;
533533

534534
Ok(())
535535
}

src/librustc_resolve/late/diagnostics.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11071107
}
11081108
};
11091109

1110-
match (
1111-
lifetime_names.len(),
1112-
lifetime_names.iter().next(),
1113-
snippet.as_ref().map(|s| s.as_str()),
1114-
) {
1110+
match (lifetime_names.len(), lifetime_names.iter().next(), snippet.as_deref()) {
11151111
(1, Some(name), Some("&")) => {
11161112
suggest_existing(err, format!("&{} ", name));
11171113
}

0 commit comments

Comments
 (0)