more clippy::style fixes:

get_first
single_char_add_str
unnecessary_mut_passed
manual_map
manual_is_ascii_check
This commit is contained in:
Matthias Krüger 2023-07-23 13:11:20 +02:00
parent ed4c5fef72
commit af2b370100
8 changed files with 12 additions and 20 deletions

View File

@ -62,7 +62,7 @@ fn get_horizontal_trim(lines: &[&str], kind: CommentKind) -> Option<String> {
CommentKind::Block => {
// Whatever happens, we skip the first line.
let mut i = lines
.get(0)
.first()
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
.unwrap_or(0);
let mut j = lines.len();

View File

@ -286,7 +286,7 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
ExprKind::OffsetOf(container, fields) => hir::ExprKind::OffsetOf(
self.lower_ty(
container,
&mut ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
&ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
),
self.arena.alloc_from_iter(fields.iter().map(|&ident| self.lower_ident(ident))),
),

View File

@ -697,15 +697,15 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
write!(template, "{n}").unwrap();
if p.format_options != Default::default() || p.format_trait != FormatTrait::Display
{
template.push_str(":");
template.push(':');
}
if let Some(fill) = p.format_options.fill {
template.push(fill);
}
match p.format_options.alignment {
Some(FormatAlignment::Left) => template.push_str("<"),
Some(FormatAlignment::Right) => template.push_str(">"),
Some(FormatAlignment::Center) => template.push_str("^"),
Some(FormatAlignment::Left) => template.push('<'),
Some(FormatAlignment::Right) => template.push('>'),
Some(FormatAlignment::Center) => template.push('^'),
None => {}
}
match p.format_options.sign {

View File

@ -268,11 +268,7 @@ pub fn remove(&mut self, key: &K) -> Option<V> {
pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)> {
match self {
SsoHashMap::Array(array) => {
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
Some(array.swap_remove(index))
} else {
None
}
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index))
}
SsoHashMap::Map(map) => map.remove_entry(key),
}

View File

@ -3013,8 +3013,7 @@ pub struct FieldDef<'hir> {
impl FieldDef<'_> {
// Still necessary in couple of places
pub fn is_positional(&self) -> bool {
let first = self.ident.as_str().as_bytes()[0];
(b'0'..=b'9').contains(&first)
self.ident.as_str().as_bytes()[0].is_ascii_digit()
}
}

View File

@ -1041,10 +1041,7 @@ fn list(ns: &[usize]) -> String {
}
elem(curr, curr_count);
let mut s = "[".to_string();
s.push_str(&v.join(", "));
s.push_str("]");
s
format!("[{}]", v.join(", "))
}
};

View File

@ -400,7 +400,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
let _ = write!(s, "{}", name.len());
// Prepend a '_' if name starts with a digit or '_'
if let Some(first) = name.as_bytes().get(0) {
if let Some(first) = name.as_bytes().first() {
if first.is_ascii_digit() || *first == b'_' {
s.push('_');
}

View File

@ -194,7 +194,7 @@ fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
mapped_regions,
mapped_types,
mapped_consts,
&mut self.universes,
&self.universes,
result,
))
} else {
@ -224,7 +224,7 @@ fn try_fold_const(&mut self, ct: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Sel
mapped_regions,
mapped_types,
mapped_consts,
&mut self.universes,
&self.universes,
result,
))
} else {