Unnamed repository; edit this file 'description' to name the repository.
Merge #10226
10226: minor: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
bors[bot] 2021-09-13
parent 1ef4b2c · parent a044175 · commit df34698
-rw-r--r--crates/hir_ty/src/lower.rs94
-rw-r--r--crates/hir_ty/src/method_resolution.rs4
-rw-r--r--crates/ide_assists/src/assist_context.rs2
-rw-r--r--crates/ide_assists/src/handlers/convert_bool_then.rs4
-rw-r--r--crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs4
-rw-r--r--crates/ide_assists/src/handlers/expand_glob_import.rs6
-rw-r--r--crates/ide_assists/src/handlers/extract_function.rs9
-rw-r--r--crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs8
-rw-r--r--crates/ide_assists/src/handlers/extract_variable.rs4
-rw-r--r--crates/ide_assists/src/handlers/generate_function.rs12
-rw-r--r--crates/ide_assists/src/handlers/inline_call.rs2
-rw-r--r--crates/ide_assists/src/handlers/introduce_named_lifetime.rs7
-rw-r--r--crates/ide_assists/src/handlers/raw_string.rs2
-rw-r--r--crates/ide_assists/src/handlers/remove_unused_param.rs2
-rw-r--r--crates/ide_assists/src/handlers/replace_if_let_with_match.rs8
-rw-r--r--crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs5
-rw-r--r--crates/ide_assists/src/handlers/toggle_ignore.rs2
-rw-r--r--crates/proc_macro_api/src/lib.rs2
18 files changed, 91 insertions, 86 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 13785e3a6c..28b21fc5b8 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -410,52 +410,60 @@ impl<'a> TyLoweringContext<'a> {
) -> (Ty, Option<TypeNs>) {
let ty = match resolution {
TypeNs::TraitId(trait_) => {
- let ty = if remaining_segments.len() == 1 {
- let trait_ref =
- self.lower_trait_ref_from_resolved_path(trait_, resolved_segment, None);
- let segment = remaining_segments.first().unwrap();
- let found = self
- .db
- .trait_data(trait_ref.hir_trait_id())
- .associated_type_by_name(segment.name);
- match found {
- Some(associated_ty) => {
- // FIXME handle type parameters on the segment
- TyKind::Alias(AliasTy::Projection(ProjectionTy {
- associated_ty_id: to_assoc_type_id(associated_ty),
- substitution: trait_ref.substitution,
- }))
- .intern(&Interner)
- }
- None => {
- // FIXME: report error (associated type not found)
- TyKind::Error.intern(&Interner)
+ let ty = match remaining_segments.len() {
+ 1 => {
+ let trait_ref =
+ self.lower_trait_ref_from_resolved_path(trait_, resolved_segment, None);
+ let segment = remaining_segments.first().unwrap();
+ let found = self
+ .db
+ .trait_data(trait_ref.hir_trait_id())
+ .associated_type_by_name(segment.name);
+ match found {
+ Some(associated_ty) => {
+ // FIXME handle type parameters on the segment
+ TyKind::Alias(AliasTy::Projection(ProjectionTy {
+ associated_ty_id: to_assoc_type_id(associated_ty),
+ substitution: trait_ref.substitution,
+ }))
+ .intern(&Interner)
+ }
+ None => {
+ // FIXME: report error (associated type not found)
+ TyKind::Error.intern(&Interner)
+ }
}
}
- } else if remaining_segments.len() > 1 {
- // FIXME report error (ambiguous associated type)
- TyKind::Error.intern(&Interner)
- } else {
- let self_ty = Some(
- TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
- .intern(&Interner),
- );
- let trait_ref = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
- ctx.lower_trait_ref_from_resolved_path(trait_, resolved_segment, self_ty)
- });
- let dyn_ty = DynTy {
- bounds: crate::make_only_type_binders(
- 1,
- QuantifiedWhereClauses::from_iter(
- &Interner,
- Some(crate::wrap_empty_binders(WhereClause::Implemented(
- trait_ref,
- ))),
+ 0 => {
+ let self_ty = Some(
+ TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
+ .intern(&Interner),
+ );
+ let trait_ref = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
+ ctx.lower_trait_ref_from_resolved_path(
+ trait_,
+ resolved_segment,
+ self_ty,
+ )
+ });
+ let dyn_ty = DynTy {
+ bounds: crate::make_only_type_binders(
+ 1,
+ QuantifiedWhereClauses::from_iter(
+ &Interner,
+ Some(crate::wrap_empty_binders(WhereClause::Implemented(
+ trait_ref,
+ ))),
+ ),
),
- ),
- lifetime: static_lifetime(),
- };
- TyKind::Dyn(dyn_ty).intern(&Interner)
+ lifetime: static_lifetime(),
+ };
+ TyKind::Dyn(dyn_ty).intern(&Interner)
+ }
+ _ => {
+ // FIXME report error (ambiguous associated type)
+ TyKind::Error.intern(&Interner)
+ }
};
return (ty, None);
}
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 3533d2010c..c88a8b6535 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -697,7 +697,7 @@ fn iterate_trait_method_candidates(
}
known_implemented = true;
// FIXME: we shouldn't be ignoring the binders here
- callback(&self_ty, *item)?
+ callback(self_ty, *item)?
}
}
ControlFlow::Continue(())
@@ -773,7 +773,7 @@ fn iterate_inherent_methods(
cov_mark::hit!(impl_self_type_match_without_receiver);
continue;
}
- let receiver_ty = receiver_ty.unwrap_or(&self_ty);
+ let receiver_ty = receiver_ty.unwrap_or(self_ty);
callback(receiver_ty, item)?;
}
}
diff --git a/crates/ide_assists/src/assist_context.rs b/crates/ide_assists/src/assist_context.rs
index 0244f5fb29..2b1f3d1633 100644
--- a/crates/ide_assists/src/assist_context.rs
+++ b/crates/ide_assists/src/assist_context.rs
@@ -167,7 +167,7 @@ impl Assists {
None
};
- let label = Label::new(label.into());
+ let label = Label::new(label);
let group = group.cloned();
self.buf.push(Assist { id, label, group, target, source_change });
Some(())
diff --git a/crates/ide_assists/src/handlers/convert_bool_then.rs b/crates/ide_assists/src/handlers/convert_bool_then.rs
index 5adb3f5a1b..497e7c2546 100644
--- a/crates/ide_assists/src/handlers/convert_bool_then.rs
+++ b/crates/ide_assists/src/handlers/convert_bool_then.rs
@@ -198,7 +198,7 @@ fn option_variants(
sema: &Semantics<RootDatabase>,
expr: &SyntaxNode,
) -> Option<(hir::Variant, hir::Variant)> {
- let fam = FamousDefs(&sema, sema.scope(expr).krate());
+ let fam = FamousDefs(sema, sema.scope(expr).krate());
let option_variants = fam.core_option_Option()?.variants(sema.db);
match &*option_variants {
&[variant0, variant1] => Some(if variant0.name(sema.db) == known::None {
@@ -224,7 +224,7 @@ fn is_invalid_body(
invalid
});
if !invalid {
- for_each_tail_expr(&expr, &mut |e| {
+ for_each_tail_expr(expr, &mut |e| {
if invalid {
return;
}
diff --git a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs
index fc5a17f052..bb0382e15f 100644
--- a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs
+++ b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs
@@ -110,7 +110,9 @@ fn edit_struct_def(
} else {
edit.insert(tuple_fields_text_range.start(), ast::make::tokens::single_space().text());
}
- strukt.semicolon_token().map(|t| edit.delete(t.text_range()));
+ if let Some(t) = strukt.semicolon_token() {
+ edit.delete(t.text_range());
+ }
} else {
edit.insert(tuple_fields_text_range.start(), ast::make::tokens::single_space().text());
}
diff --git a/crates/ide_assists/src/handlers/expand_glob_import.rs b/crates/ide_assists/src/handlers/expand_glob_import.rs
index aedb2f95f9..6a07136cc8 100644
--- a/crates/ide_assists/src/handlers/expand_glob_import.rs
+++ b/crates/ide_assists/src/handlers/expand_glob_import.rs
@@ -227,14 +227,12 @@ fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>
Some(
[Direction::Prev, Direction::Next]
.iter()
- .map(|dir| {
+ .flat_map(|dir| {
parent_use_item_syntax
.siblings(dir.to_owned())
.filter(|n| ast::Use::can_cast(n.kind()))
})
- .flatten()
- .filter_map(|n| Some(n.descendants().filter_map(ast::NameRef::cast)))
- .flatten()
+ .flat_map(|n| n.descendants().filter_map(ast::NameRef::cast))
.filter_map(|r| match NameRefClass::classify(&ctx.sema, &r)? {
NameRefClass::Definition(Definition::ModuleDef(def)) => Some(Def::ModuleDef(def)),
NameRefClass::Definition(Definition::Macro(def)) => Some(Def::MacroDef(def)),
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 1e21050911..c0cf3fac03 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -885,12 +885,9 @@ fn reference_is_exclusive(
/// checks if this expr requires `&mut` access, recurses on field access
fn expr_require_exclusive_access(ctx: &AssistContext, expr: &ast::Expr) -> Option<bool> {
- match expr {
- ast::Expr::MacroCall(_) => {
- // FIXME: expand macro and check output for mutable usages of the variable?
- return None;
- }
- _ => (),
+ if let ast::Expr::MacroCall(_) = expr {
+ // FIXME: expand macro and check output for mutable usages of the variable?
+ return None;
}
let parent = expr.syntax().parent()?;
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
index 9611588110..3bc347b1e2 100644
--- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -231,7 +231,7 @@ fn create_struct_def(
let variant_attrs = attrs_and_docs(variant.syntax())
.map(|tok| match tok.kind() {
WHITESPACE => make::tokens::single_newline().into(),
- _ => tok.into(),
+ _ => tok,
})
.collect();
ted::insert_all(Position::first_child_of(strukt.syntax()), variant_attrs);
@@ -251,12 +251,14 @@ fn update_variant(variant: &ast::Variant, generic: Option<ast::GenericParamList>
Some(gpl) => {
let gpl = gpl.clone_for_update();
gpl.generic_params().for_each(|gp| {
- match gp {
+ let tbl = match gp {
ast::GenericParam::LifetimeParam(it) => it.type_bound_list(),
ast::GenericParam::TypeParam(it) => it.type_bound_list(),
ast::GenericParam::ConstParam(_) => return,
+ };
+ if let Some(tbl) = tbl {
+ tbl.remove();
}
- .map(|it| it.remove());
});
make::ty(&format!("{}<{}>", name.text(), gpl.generic_params().join(", ")))
}
diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs
index c72ed32423..9398b84b3f 100644
--- a/crates/ide_assists/src/handlers/extract_variable.rs
+++ b/crates/ide_assists/src/handlers/extract_variable.rs
@@ -79,7 +79,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
if let Anchor::Replace(stmt) = anchor {
cov_mark::hit!(test_extract_var_expr_stmt);
if stmt.semicolon_token().is_none() {
- buf.push_str(";");
+ buf.push(';');
}
match ctx.config.snippet_cap {
Some(cap) => {
@@ -92,7 +92,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
return;
}
- buf.push_str(";");
+ buf.push(';');
// We want to maintain the indent level,
// but we do not want to duplicate possible
diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs
index 8feae78126..55c5c46e69 100644
--- a/crates/ide_assists/src/handlers/generate_function.rs
+++ b/crates/ide_assists/src/handlers/generate_function.rs
@@ -109,7 +109,7 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
};
let function_builder = FunctionBuilder::from_call(ctx, &call, &path, target_module, target)?;
let text_range = call.syntax().text_range();
- let label = format!("Generate {} function", function_builder.fn_name.clone());
+ let label = format!("Generate {} function", function_builder.fn_name);
add_func_to_accumulator(
acc,
ctx,
@@ -139,7 +139,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
FunctionBuilder::from_method_call(ctx, &call, &fn_name, target_module, target)?;
let text_range = call.syntax().text_range();
let adt_name = if impl_.is_none() { Some(adt.name(ctx.sema.db)) } else { None };
- let label = format!("Generate {} method", function_builder.fn_name.clone());
+ let label = format!("Generate {} method", function_builder.fn_name);
add_func_to_accumulator(
acc,
ctx,
@@ -369,7 +369,7 @@ fn make_return_type(
}
}
};
- let ret_type = ret_ty.map(|rt| make::ret_type(rt));
+ let ret_type = ret_ty.map(make::ret_type);
(ret_type, should_focus_return_type)
}
@@ -386,7 +386,7 @@ fn get_fn_target(
file = in_file;
target
}
- None => next_space_for_fn_after_call_site(FuncExpr::Func(call.clone()))?,
+ None => next_space_for_fn_after_call_site(FuncExpr::Func(call))?,
};
Some((target.clone(), file, get_insert_offset(&target)))
}
@@ -397,7 +397,7 @@ fn get_method_target(
impl_: &Option<ast::Impl>,
) -> Option<(GeneratedFunctionTarget, TextSize)> {
let target = match impl_ {
- Some(impl_) => next_space_for_fn_in_impl(&impl_)?,
+ Some(impl_) => next_space_for_fn_in_impl(impl_)?,
None => {
next_space_for_fn_in_module(ctx.sema.db, &target_module.definition_source(ctx.sema.db))?
.1
@@ -448,7 +448,7 @@ fn fn_args(
});
arg_types.push(match fn_arg_type(ctx, target_module, &arg) {
Some(ty) => {
- if ty.len() > 0 && ty.starts_with('&') {
+ if !ty.is_empty() && ty.starts_with('&') {
if let Some((new_ty, _)) = useless_type_special_case("", &ty[1..].to_owned()) {
new_ty
} else {
diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs
index 9cab0487e1..33e029c236 100644
--- a/crates/ide_assists/src/handlers/inline_call.rs
+++ b/crates/ide_assists/src/handlers/inline_call.rs
@@ -199,7 +199,7 @@ pub(crate) fn inline_(
.sema
.type_of_expr(&expr)
.filter(TypeInfo::has_adjustment)
- .and_then(|_| param_ty);
+ .and(param_ty);
body.push_front(
make::let_stmt(pat, ty, Some(expr)).clone_for_update().into(),
)
diff --git a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
index aa32c698a2..8077f73d1e 100644
--- a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
+++ b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs
@@ -77,7 +77,7 @@ fn generate_fn_def_assist(
})
.collect();
match fn_params_without_lifetime.len() {
- 1 => Some(fn_params_without_lifetime.into_iter().nth(0)?),
+ 1 => Some(fn_params_without_lifetime.into_iter().next()?),
0 => None,
// multiple unnnamed is invalid. assist is not applicable
_ => return None,
@@ -93,8 +93,9 @@ fn generate_fn_def_assist(
make::lifetime_param(new_lifetime_param.clone()).clone_for_update().into(),
);
ted::replace(lifetime.syntax(), new_lifetime_param.clone_for_update().syntax());
- loc_needing_lifetime
- .map(|position| ted::insert(position, new_lifetime_param.clone_for_update().syntax()));
+ if let Some(position) = loc_needing_lifetime {
+ ted::insert(position, new_lifetime_param.clone_for_update().syntax());
+ }
})
}
diff --git a/crates/ide_assists/src/handlers/raw_string.rs b/crates/ide_assists/src/handlers/raw_string.rs
index d98a55ae4a..acd0829570 100644
--- a/crates/ide_assists/src/handlers/raw_string.rs
+++ b/crates/ide_assists/src/handlers/raw_string.rs
@@ -35,7 +35,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option<
if matches!(value, Cow::Borrowed(_)) {
// Avoid replacing the whole string to better position the cursor.
edit.insert(token.syntax().text_range().start(), format!("r{}", hashes));
- edit.insert(token.syntax().text_range().end(), format!("{}", hashes));
+ edit.insert(token.syntax().text_range().end(), hashes);
} else {
edit.replace(
token.syntax().text_range(),
diff --git a/crates/ide_assists/src/handlers/remove_unused_param.rs b/crates/ide_assists/src/handlers/remove_unused_param.rs
index 9aa33e39ba..75b9f827d7 100644
--- a/crates/ide_assists/src/handlers/remove_unused_param.rs
+++ b/crates/ide_assists/src/handlers/remove_unused_param.rs
@@ -137,7 +137,7 @@ fn process_usage(
return Some(range_to_remove(arg.syntax()));
}
- return None;
+ None
}
fn range_to_remove(node: &SyntaxNode) -> TextRange {
diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
index 5ce2ad3193..96a8c78392 100644
--- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs
@@ -126,7 +126,7 @@ fn make_else_arm(
if let Some(else_block) = else_block {
let pattern = if let [(Either::Left(pat), _)] = conditionals {
ctx.sema
- .type_of_pat(&pat)
+ .type_of_pat(pat)
.and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty.adjusted()))
.zip(Some(pat))
} else {
@@ -134,7 +134,7 @@ fn make_else_arm(
};
let pattern = match pattern {
Some((it, pat)) => {
- if does_pat_match_variant(&pat, &it.sad_pattern()) {
+ if does_pat_match_variant(pat, &it.sad_pattern()) {
it.happy_pattern()
} else {
it.sad_pattern()
@@ -144,7 +144,7 @@ fn make_else_arm(
};
make::match_arm(iter::once(pattern), None, unwrap_trivial_block(else_block))
} else {
- make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit().into())
+ make::match_arm(iter::once(make::wildcard_pat().into()), None, make::expr_unit())
}
}
@@ -257,7 +257,7 @@ fn is_empty_expr(expr: &ast::Expr) -> bool {
}
fn binds_name(sema: &hir::Semantics<RootDatabase>, pat: &ast::Pat) -> bool {
- let binds_name_v = |pat| binds_name(&sema, &pat);
+ let binds_name_v = |pat| binds_name(sema, &pat);
match pat {
ast::Pat::IdentPat(pat) => !matches!(
pat.name().and_then(|name| NameClass::classify(sema, &name)),
diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
index 13367df807..47600be763 100644
--- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
@@ -141,10 +141,7 @@ fn path_eq_no_generics(lhs: ast::Path, rhs: ast::Path) -> bool {
&& lhs
.name_ref()
.zip(rhs.name_ref())
- .map_or(false, |(lhs, rhs)| lhs.text() == rhs.text()) =>
- {
- ()
- }
+ .map_or(false, |(lhs, rhs)| lhs.text() == rhs.text()) => {}
_ => return false,
}
diff --git a/crates/ide_assists/src/handlers/toggle_ignore.rs b/crates/ide_assists/src/handlers/toggle_ignore.rs
index 33e12a7d0c..4da6089cac 100644
--- a/crates/ide_assists/src/handlers/toggle_ignore.rs
+++ b/crates/ide_assists/src/handlers/toggle_ignore.rs
@@ -33,7 +33,7 @@ pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()
AssistId("toggle_ignore", AssistKind::None),
"Ignore this test",
attr.syntax().text_range(),
- |builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")),
+ |builder| builder.insert(attr.syntax().text_range().end(), "\n#[ignore]"),
),
Some(ignore_attr) => acc.add(
AssistId("toggle_ignore", AssistKind::None),
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs
index 20c5ffaebd..b03a029f8a 100644
--- a/crates/proc_macro_api/src/lib.rs
+++ b/crates/proc_macro_api/src/lib.rs
@@ -130,7 +130,7 @@ impl ProcMacroServer {
.into_iter()
.map(|(name, kind)| ProcMacro {
process: self.process.clone(),
- name: name.into(),
+ name,
kind,
dylib_path: dylib.path.clone(),
})