Skip to content

Commit 155a5c2

Browse files
committed
Auto merge of #113978 - matthiaskrgr:clippy_072023_style, r=fee1-dead
couple of clippy::style changes comparison_to_empty iter_nth_zero for_kv_map manual_next_back redundant_pattern get_first single_char_add_str unnecessary_mut_passed manual_map manual_is_ascii_check
2 parents bccefd2 + af2b370 commit 155a5c2

File tree

13 files changed

+27
-32
lines changed

13 files changed

+27
-32
lines changed

compiler/rustc_ast/src/util/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
6262
CommentKind::Block => {
6363
// Whatever happens, we skip the first line.
6464
let mut i = lines
65-
.get(0)
65+
.first()
6666
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
6767
.unwrap_or(0);
6868
let mut j = lines.len();

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
286286
ExprKind::OffsetOf(container, fields) => hir::ExprKind::OffsetOf(
287287
self.lower_ty(
288288
container,
289-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
289+
&ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
290290
),
291291
self.arena.alloc_from_iter(fields.iter().map(|&ident| self.lower_ident(ident))),
292292
),

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -697,15 +697,15 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
697697
write!(template, "{n}").unwrap();
698698
if p.format_options != Default::default() || p.format_trait != FormatTrait::Display
699699
{
700-
template.push_str(":");
700+
template.push(':');
701701
}
702702
if let Some(fill) = p.format_options.fill {
703703
template.push(fill);
704704
}
705705
match p.format_options.alignment {
706-
Some(FormatAlignment::Left) => template.push_str("<"),
707-
Some(FormatAlignment::Right) => template.push_str(">"),
708-
Some(FormatAlignment::Center) => template.push_str("^"),
706+
Some(FormatAlignment::Left) => template.push('<'),
707+
Some(FormatAlignment::Right) => template.push('>'),
708+
Some(FormatAlignment::Center) => template.push('^'),
709709
None => {}
710710
}
711711
match p.format_options.sign {

compiler/rustc_data_structures/src/sso/map.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
268268
pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)> {
269269
match self {
270270
SsoHashMap::Array(array) => {
271-
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
272-
Some(array.swap_remove(index))
273-
} else {
274-
None
275-
}
271+
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index))
276272
}
277273
SsoHashMap::Map(map) => map.remove_entry(key),
278274
}

compiler/rustc_hir/src/hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3013,8 +3013,7 @@ pub struct FieldDef<'hir> {
30133013
impl FieldDef<'_> {
30143014
// Still necessary in couple of places
30153015
pub fn is_positional(&self) -> bool {
3016-
let first = self.ident.as_str().as_bytes()[0];
3017-
(b'0'..=b'9').contains(&first)
3016+
self.ident.as_str().as_bytes()[0].is_ascii_digit()
30183017
}
30193018
}
30203019

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
621621
// is in a different line, so we point at both.
622622
err.span_label(secondary_span, "expected due to the type of this binding");
623623
err.span_label(primary_span, format!("expected due to this{post_message}"));
624-
} else if post_message == "" {
624+
} else if post_message.is_empty() {
625625
// We are pointing at either the assignment lhs or the binding def pattern.
626626
err.span_label(primary_span, "expected due to the type of this binding");
627627
} else {

compiler/rustc_infer/src/infer/region_constraints/leak_check.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,11 @@ impl<'tcx> MiniGraph<'tcx> {
425425
}
426426
}
427427
} else {
428-
for (constraint, _origin) in &region_constraints.data().constraints {
429-
each_constraint(constraint)
430-
}
428+
region_constraints
429+
.data()
430+
.constraints
431+
.keys()
432+
.for_each(|constraint| each_constraint(constraint));
431433
}
432434
}
433435

compiler/rustc_lexer/src/unescape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ where
372372
callback(start..end, EscapeError::MultipleSkippedLinesWarning);
373373
}
374374
let tail = &tail[first_non_space..];
375-
if let Some(c) = tail.chars().nth(0) {
375+
if let Some(c) = tail.chars().next() {
376376
if c.is_whitespace() {
377377
// For error reporting, we would like the span to contain the character that was not
378378
// skipped. The +1 is necessary to account for the leading \ that started the escape.

compiler/rustc_monomorphize/src/partitioning.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,7 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
10411041
}
10421042
elem(curr, curr_count);
10431043

1044-
let mut s = "[".to_string();
1045-
s.push_str(&v.join(", "));
1046-
s.push_str("]");
1047-
s
1044+
format!("[{}]", v.join(", "))
10481045
}
10491046
};
10501047

@@ -1229,12 +1226,13 @@ fn dump_mono_items_stats<'tcx>(
12291226
// Gather instantiated mono items grouped by def_id
12301227
let mut items_per_def_id: FxHashMap<_, Vec<_>> = Default::default();
12311228
for cgu in codegen_units {
1232-
for (&mono_item, _) in cgu.items() {
1229+
cgu.items()
1230+
.keys()
12331231
// Avoid variable-sized compiler-generated shims
1234-
if mono_item.is_user_defined() {
1232+
.filter(|mono_item| mono_item.is_user_defined())
1233+
.for_each(|mono_item| {
12351234
items_per_def_id.entry(mono_item.def_id()).or_default().push(mono_item);
1236-
}
1237-
}
1235+
});
12381236
}
12391237

12401238
#[derive(serde::Serialize)]
@@ -1287,7 +1285,7 @@ fn codegened_and_inlined_items(tcx: TyCtxt<'_>, (): ()) -> &DefIdSet {
12871285
let mut result = items.clone();
12881286

12891287
for cgu in cgus {
1290-
for (item, _) in cgu.items() {
1288+
for item in cgu.items().keys() {
12911289
if let MonoItem::Fn(ref instance) = item {
12921290
let did = instance.def_id();
12931291
if !visited.insert(did) {

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn emit_unescape_error(
2727
lit, span_with_quotes, mode, range, error
2828
);
2929
let last_char = || {
30-
let c = lit[range.clone()].chars().rev().next().unwrap();
30+
let c = lit[range.clone()].chars().next_back().unwrap();
3131
let span = span.with_lo(span.hi() - BytePos(c.len_utf8() as u32));
3232
(c, span)
3333
};

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
400400
let _ = write!(s, "{}", name.len());
401401

402402
// Prepend a '_' if name starts with a digit or '_'
403-
if let Some(first) = name.as_bytes().get(0) {
403+
if let Some(first) = name.as_bytes().first() {
404404
if first.is_ascii_digit() || *first == b'_' {
405405
s.push('_');
406406
}

compiler/rustc_trait_selection/src/solve/normalize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
194194
mapped_regions,
195195
mapped_types,
196196
mapped_consts,
197-
&mut self.universes,
197+
&self.universes,
198198
result,
199199
))
200200
} else {
@@ -224,7 +224,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
224224
mapped_regions,
225225
mapped_types,
226226
mapped_consts,
227-
&mut self.universes,
227+
&self.universes,
228228
result,
229229
))
230230
} else {

compiler/rustc_ty_utils/src/implied_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
5151
// assumed_wf_types should include those of `Opaque<T>`, `Opaque<T>` itself
5252
// and `&'static T`.
5353
DefKind::OpaqueTy => bug!("unimplemented implied bounds for nested opaque types"),
54-
def_kind @ _ => {
54+
def_kind => {
5555
bug!("unimplemented implied bounds for opaque types with parent {def_kind:?}")
5656
}
5757
},

0 commit comments

Comments
 (0)