Skip to content

Commit af2b370

Browse files
committed
more clippy::style fixes:
get_first single_char_add_str unnecessary_mut_passed manual_map manual_is_ascii_check
1 parent ed4c5fe commit af2b370

File tree

8 files changed

+12
-20
lines changed

8 files changed

+12
-20
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_monomorphize/src/partitioning.rs

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

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 {

0 commit comments

Comments
 (0)