Skip to content

Commit 5fcf979

Browse files
Merge #11692
11692: round of clippy fixes. r=Veykril a=matthiaskrgr Split these up into smaller chunks so I can easily revert parts of it if needed. Co-authored-by: Matthias Krüger <[email protected]>
2 parents ff7e057 + f39cac1 commit 5fcf979

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+215
-271
lines changed

crates/base_db/src/fixture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ struct FileMeta {
394394
}
395395

396396
fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
397-
if let Some((a, b)) = crate_str.split_once("@") {
398-
let (version, origin) = match b.split_once(":") {
399-
Some(("CratesIo", data)) => match data.split_once(",") {
397+
if let Some((a, b)) = crate_str.split_once('@') {
398+
let (version, origin) = match b.split_once(':') {
399+
Some(("CratesIo", data)) => match data.split_once(',') {
400400
Some((version, url)) => {
401401
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()) })
402402
}

crates/hir/src/from_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl From<GenericParam> for GenericParamId {
8282
fn from(id: GenericParam) -> Self {
8383
match id {
8484
GenericParam::LifetimeParam(it) => GenericParamId::LifetimeParamId(it.id),
85-
GenericParam::ConstParam(it) => GenericParamId::ConstParamId(it.id.into()),
86-
GenericParam::TypeParam(it) => GenericParamId::TypeParamId(it.id.into()),
85+
GenericParam::ConstParam(it) => GenericParamId::ConstParamId(it.id),
86+
GenericParam::TypeParam(it) => GenericParamId::TypeParamId(it.id),
8787
}
8888
}
8989
}

crates/hir/src/lib.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Crate {
231231
return None;
232232
}
233233

234-
let doc_url = doc_attr_q.tt_values().map(|tt| {
234+
let doc_url = doc_attr_q.tt_values().filter_map(|tt| {
235235
let name = tt.token_trees.iter()
236236
.skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident { text, ..} )) if text == "html_root_url"))
237237
.nth(2);
@@ -240,7 +240,7 @@ impl Crate {
240240
Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
241241
_ => None
242242
}
243-
}).flatten().next();
243+
}).next();
244244

245245
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
246246
}
@@ -1530,11 +1530,7 @@ impl SelfParam {
15301530
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
15311531
let environment = db.trait_environment(self.func.into());
15321532

1533-
Type {
1534-
krate,
1535-
env: environment.clone(),
1536-
ty: ctx.lower_ty(&db.function_data(self.func).params[0].1),
1537-
}
1533+
Type { krate, env: environment, ty: ctx.lower_ty(&db.function_data(self.func).params[0].1) }
15381534
}
15391535
}
15401536

@@ -1816,14 +1812,12 @@ impl Macro {
18161812

18171813
pub fn is_builtin_derive(&self, db: &dyn HirDatabase) -> bool {
18181814
match self.id {
1819-
MacroId::Macro2Id(it) => match it.lookup(db.upcast()).expander {
1820-
MacroExpander::BuiltInDerive(_) => true,
1821-
_ => false,
1822-
},
1823-
MacroId::MacroRulesId(it) => match it.lookup(db.upcast()).expander {
1824-
MacroExpander::BuiltInDerive(_) => true,
1825-
_ => false,
1826-
},
1815+
MacroId::Macro2Id(it) => {
1816+
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInDerive(_))
1817+
}
1818+
MacroId::MacroRulesId(it) => {
1819+
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInDerive(_))
1820+
}
18271821
MacroId::ProcMacroId(_) => false,
18281822
}
18291823
}

crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
398398
}
399399

400400
pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
401-
self.imp.scope_at_offset(&node, offset)
401+
self.imp.scope_at_offset(node, offset)
402402
}
403403

404404
pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {

crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ fn resolve_hir_path_(
603603
// within the trait's associated types.
604604
if let (Some(unresolved), &TypeNs::TraitId(trait_id)) = (&unresolved, &ty) {
605605
if let Some(type_alias_id) =
606-
db.trait_data(trait_id).associated_type_by_name(&unresolved.name)
606+
db.trait_data(trait_id).associated_type_by_name(unresolved.name)
607607
{
608608
return Some(PathResolution::Def(ModuleDefId::from(type_alias_id).into()));
609609
}

crates/hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl DocsRangeMap {
667667
let InFile { file_id, value: source } = self.source_map.source_of_id(idx);
668668
match source {
669669
Either::Left(attr) => {
670-
let string = get_doc_string_in_attr(&attr)?;
670+
let string = get_doc_string_in_attr(attr)?;
671671
let text_range = string.open_quote_text_range()?;
672672
let range = TextRange::at(
673673
text_range.end() + original_line_src_range.start() + relative_range.start(),

crates/hir_def/src/body.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@ impl BodySourceMap {
421421
}
422422

423423
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
424-
let src = node.map(|it| AstPtr::new(it));
424+
let src = node.map(AstPtr::new);
425425
self.expr_map.get(&src).cloned()
426426
}
427427

428428
pub fn node_macro_file(&self, node: InFile<&ast::MacroCall>) -> Option<HirFileId> {
429-
let src = node.map(|it| AstPtr::new(it));
429+
let src = node.map(AstPtr::new);
430430
self.expansions.get(&src).cloned()
431431
}
432432

@@ -449,15 +449,15 @@ impl BodySourceMap {
449449
}
450450

451451
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
452-
let src = node.map(|it| AstPtr::new(it));
452+
let src = node.map(AstPtr::new);
453453
self.label_map.get(&src).cloned()
454454
}
455455

456456
pub fn field_syntax(&self, expr: ExprId) -> InFile<AstPtr<ast::RecordExprField>> {
457457
self.field_map_back[&expr].clone()
458458
}
459459
pub fn node_field(&self, node: InFile<&ast::RecordExprField>) -> Option<ExprId> {
460-
let src = node.map(|it| AstPtr::new(it));
460+
let src = node.map(AstPtr::new);
461461
self.field_map.get(&src).cloned()
462462
}
463463

crates/hir_def/src/body/lower.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,17 +941,15 @@ impl From<ast::LiteralKind> for Literal {
941941
LiteralKind::IntNumber(lit) => {
942942
if let builtin @ Some(_) = lit.suffix().and_then(BuiltinFloat::from_suffix) {
943943
Literal::Float(Default::default(), builtin)
944-
} else if let builtin @ Some(_) =
945-
lit.suffix().and_then(|it| BuiltinInt::from_suffix(it))
946-
{
944+
} else if let builtin @ Some(_) = lit.suffix().and_then(BuiltinInt::from_suffix) {
947945
Literal::Int(lit.value().unwrap_or(0) as i128, builtin)
948946
} else {
949-
let builtin = lit.suffix().and_then(|it| BuiltinUint::from_suffix(it));
947+
let builtin = lit.suffix().and_then(BuiltinUint::from_suffix);
950948
Literal::Uint(lit.value().unwrap_or(0), builtin)
951949
}
952950
}
953951
LiteralKind::FloatNumber(lit) => {
954-
let ty = lit.suffix().and_then(|it| BuiltinFloat::from_suffix(it));
952+
let ty = lit.suffix().and_then(BuiltinFloat::from_suffix);
955953
Literal::Float(Default::default(), ty)
956954
}
957955
LiteralKind::ByteString(bs) => {

crates/hir_def/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl FunctionData {
6666
.by_key("rustc_legacy_const_generics")
6767
.tt_values()
6868
.next()
69-
.map(|arg| parse_rustc_legacy_const_generics(arg))
69+
.map(parse_rustc_legacy_const_generics)
7070
.unwrap_or_default();
7171

7272
Arc::new(FunctionData {

crates/hir_def/src/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl TypeOrConstParamData {
7272

7373
pub fn type_param(&self) -> Option<&TypeParamData> {
7474
match self {
75-
TypeOrConstParamData::TypeParamData(x) => Some(&x),
75+
TypeOrConstParamData::TypeParamData(x) => Some(x),
7676
TypeOrConstParamData::ConstParamData(_) => None,
7777
}
7878
}

0 commit comments

Comments
 (0)