mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
single_match
This commit is contained in:
parent
9dd07f0bc4
commit
b1a0c9ac40
14 changed files with 89 additions and 130 deletions
|
@ -178,7 +178,6 @@ new_without_default = "allow"
|
|||
non_canonical_clone_impl = "allow"
|
||||
non_canonical_partial_ord_impl = "allow"
|
||||
self_named_constructors = "allow"
|
||||
single_match = "allow"
|
||||
skip_while_next = "allow"
|
||||
too_many_arguments = "allow"
|
||||
toplevel_ref_arg = "allow"
|
||||
|
|
|
@ -114,34 +114,26 @@ impl ExprValidator {
|
|||
) {
|
||||
// Check that the number of arguments matches the number of parameters.
|
||||
|
||||
// FIXME: Due to shortcomings in the current type system implementation, only emit this
|
||||
// diagnostic if there are no type mismatches in the containing function.
|
||||
if self.infer.expr_type_mismatches().next().is_some() {
|
||||
return;
|
||||
}
|
||||
// FIXME: Due to shortcomings in the current type system implementation, only emit
|
||||
// this diagnostic if there are no type mismatches in the containing function.
|
||||
} else if let Expr::MethodCall { receiver, .. } = expr {
|
||||
let (callee, _) = match self.infer.method_resolution(call_id) {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
|
||||
match expr {
|
||||
Expr::MethodCall { receiver, .. } => {
|
||||
let (callee, _) = match self.infer.method_resolution(call_id) {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
|
||||
if filter_map_next_checker
|
||||
.get_or_insert_with(|| {
|
||||
FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db)
|
||||
})
|
||||
.check(call_id, receiver, &callee)
|
||||
.is_some()
|
||||
{
|
||||
self.diagnostics.push(
|
||||
BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap {
|
||||
method_call_expr: call_id,
|
||||
},
|
||||
);
|
||||
}
|
||||
if filter_map_next_checker
|
||||
.get_or_insert_with(|| {
|
||||
FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db)
|
||||
})
|
||||
.check(call_id, receiver, &callee)
|
||||
.is_some()
|
||||
{
|
||||
self.diagnostics.push(BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap {
|
||||
method_call_expr: call_id,
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,13 +142,10 @@ impl HirPlace {
|
|||
mut current_capture: CaptureKind,
|
||||
len: usize,
|
||||
) -> CaptureKind {
|
||||
match current_capture {
|
||||
CaptureKind::ByRef(BorrowKind::Mut { .. }) => {
|
||||
if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
|
||||
current_capture = CaptureKind::ByRef(BorrowKind::Unique);
|
||||
}
|
||||
if let CaptureKind::ByRef(BorrowKind::Mut { .. }) = current_capture {
|
||||
if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
|
||||
current_capture = CaptureKind::ByRef(BorrowKind::Unique);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
current_capture
|
||||
}
|
||||
|
|
|
@ -339,11 +339,8 @@ fn push_mut_span(local: LocalId, span: MirSpan, result: &mut ArenaMap<LocalId, M
|
|||
}
|
||||
|
||||
fn record_usage(local: LocalId, result: &mut ArenaMap<LocalId, MutabilityReason>) {
|
||||
match &mut result[local] {
|
||||
it @ MutabilityReason::Unused => {
|
||||
*it = MutabilityReason::Not;
|
||||
}
|
||||
_ => (),
|
||||
if let it @ MutabilityReason::Unused = &mut result[local] {
|
||||
*it = MutabilityReason::Not;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -288,12 +288,9 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
current: BasicBlockId,
|
||||
) -> Result<Option<(Operand, BasicBlockId)>> {
|
||||
if !self.has_adjustments(expr_id) {
|
||||
match &self.body.exprs[expr_id] {
|
||||
Expr::Literal(l) => {
|
||||
let ty = self.expr_ty_without_adjust(expr_id);
|
||||
return Ok(Some((self.lower_literal_to_operand(ty, l)?, current)));
|
||||
}
|
||||
_ => (),
|
||||
if let Expr::Literal(l) = &self.body.exprs[expr_id] {
|
||||
let ty = self.expr_ty_without_adjust(expr_id);
|
||||
return Ok(Some((self.lower_literal_to_operand(ty, l)?, current)));
|
||||
}
|
||||
}
|
||||
let Some((p, current)) = self.lower_expr_as_place(current, expr_id, true)? else {
|
||||
|
|
|
@ -689,27 +689,22 @@ fn does_source_exists_outside_sel_in_same_mod(
|
|||
match def {
|
||||
Definition::Module(x) => {
|
||||
let source = x.definition_source(ctx.db());
|
||||
let have_same_parent;
|
||||
if let Some(ast_module) = &curr_parent_module {
|
||||
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
|
||||
if let Some(hir_module) = x.parent(ctx.db()) {
|
||||
have_same_parent =
|
||||
compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some();
|
||||
compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some()
|
||||
} else {
|
||||
let source_file_id = source.file_id.original_file(ctx.db());
|
||||
have_same_parent = source_file_id == curr_file_id;
|
||||
source_file_id == curr_file_id
|
||||
}
|
||||
} else {
|
||||
let source_file_id = source.file_id.original_file(ctx.db());
|
||||
have_same_parent = source_file_id == curr_file_id;
|
||||
}
|
||||
source_file_id == curr_file_id
|
||||
};
|
||||
|
||||
if have_same_parent {
|
||||
match source.value {
|
||||
ModuleSource::Module(module_) => {
|
||||
source_exists_outside_sel_in_same_mod =
|
||||
!selection_range.contains_range(module_.syntax().text_range());
|
||||
}
|
||||
_ => {}
|
||||
if let ModuleSource::Module(module_) = source.value {
|
||||
source_exists_outside_sel_in_same_mod =
|
||||
!selection_range.contains_range(module_.syntax().text_range());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,19 +270,16 @@ fn generate_impl(
|
|||
make::path_from_text(&format!("<{} as {}>", field_ty, delegate.trait_()?));
|
||||
|
||||
let delegate_assoc_items = delegate.get_or_create_assoc_item_list();
|
||||
match bound_def.assoc_item_list() {
|
||||
Some(ai) => {
|
||||
ai.assoc_items()
|
||||
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
|
||||
.for_each(|item| {
|
||||
let assoc =
|
||||
process_assoc_item(item, qualified_path_type.clone(), field_name);
|
||||
if let Some(assoc) = assoc {
|
||||
delegate_assoc_items.add_item(assoc);
|
||||
}
|
||||
});
|
||||
}
|
||||
None => {}
|
||||
if let Some(ai) = bound_def.assoc_item_list() {
|
||||
ai.assoc_items()
|
||||
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
|
||||
.for_each(|item| {
|
||||
let assoc =
|
||||
process_assoc_item(item, qualified_path_type.clone(), field_name);
|
||||
if let Some(assoc) = assoc {
|
||||
delegate_assoc_items.add_item(assoc);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let target_scope = ctx.sema.scope(strukt.strukt.syntax())?;
|
||||
|
@ -512,17 +509,14 @@ fn generate_args_for_impl(
|
|||
// form the substitution list
|
||||
let mut arg_substs = FxHashMap::default();
|
||||
|
||||
match field_ty {
|
||||
field_ty @ ast::Type::PathType(_) => {
|
||||
let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args());
|
||||
let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args());
|
||||
if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) {
|
||||
self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| {
|
||||
arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg);
|
||||
})
|
||||
}
|
||||
if let field_ty @ ast::Type::PathType(_) = field_ty {
|
||||
let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args());
|
||||
let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args());
|
||||
if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) {
|
||||
self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| {
|
||||
arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg);
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let args = old_impl_args
|
||||
|
|
|
@ -181,21 +181,18 @@ fn remove_items_visibility(item: &ast::AssocItem) {
|
|||
}
|
||||
|
||||
fn strip_body(item: &ast::AssocItem) {
|
||||
match item {
|
||||
ast::AssocItem::Fn(f) => {
|
||||
if let Some(body) = f.body() {
|
||||
// In constrast to function bodies, we want to see no ws before a semicolon.
|
||||
// So let's remove them if we see any.
|
||||
if let Some(prev) = body.syntax().prev_sibling_or_token() {
|
||||
if prev.kind() == SyntaxKind::WHITESPACE {
|
||||
ted::remove(prev);
|
||||
}
|
||||
if let ast::AssocItem::Fn(f) = item {
|
||||
if let Some(body) = f.body() {
|
||||
// In constrast to function bodies, we want to see no ws before a semicolon.
|
||||
// So let's remove them if we see any.
|
||||
if let Some(prev) = body.syntax().prev_sibling_or_token() {
|
||||
if prev.kind() == SyntaxKind::WHITESPACE {
|
||||
ted::remove(prev);
|
||||
}
|
||||
|
||||
ted::replace(body.syntax(), make::tokens::semicolon());
|
||||
}
|
||||
|
||||
ted::replace(body.syntax(), make::tokens::semicolon());
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -425,8 +425,8 @@ fn inline(
|
|||
if is_self {
|
||||
let mut this_pat = make::ident_pat(false, false, make::name("this"));
|
||||
let mut expr = expr.clone();
|
||||
match pat {
|
||||
Pat::IdentPat(pat) => match (pat.ref_token(), pat.mut_token()) {
|
||||
if let Pat::IdentPat(pat) = pat {
|
||||
match (pat.ref_token(), pat.mut_token()) {
|
||||
// self => let this = obj
|
||||
(None, None) => {}
|
||||
// mut self => let mut this = obj
|
||||
|
@ -449,8 +449,7 @@ fn inline(
|
|||
make::expr_ref(expr, true)
|
||||
};
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
let_stmts
|
||||
.push(make::let_stmt(this_pat.into(), ty, Some(expr)).clone_for_update().into())
|
||||
|
|
|
@ -11,22 +11,18 @@ pub(crate) fn complete_field_list_tuple_variant(
|
|||
path_ctx: &PathCompletionCtx,
|
||||
) {
|
||||
if ctx.qualifier_ctx.vis_node.is_some() {
|
||||
return;
|
||||
}
|
||||
match path_ctx {
|
||||
PathCompletionCtx {
|
||||
has_macro_bang: false,
|
||||
qualified: Qualified::No,
|
||||
parent: None,
|
||||
has_type_args: false,
|
||||
..
|
||||
} => {
|
||||
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
|
||||
add_keyword("pub(crate)", "pub(crate)");
|
||||
add_keyword("pub(super)", "pub(super)");
|
||||
add_keyword("pub", "pub");
|
||||
}
|
||||
_ => (),
|
||||
} else if let PathCompletionCtx {
|
||||
has_macro_bang: false,
|
||||
qualified: Qualified::No,
|
||||
parent: None,
|
||||
has_type_args: false,
|
||||
..
|
||||
} = path_ctx
|
||||
{
|
||||
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
|
||||
add_keyword("pub(crate)", "pub(crate)");
|
||||
add_keyword("pub(super)", "pub(super)");
|
||||
add_keyword("pub", "pub");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -369,11 +369,10 @@ fn import_on_the_fly_method(
|
|||
};
|
||||
key(&a.import_path).cmp(&key(&b.import_path))
|
||||
})
|
||||
.for_each(|import| match import.original_item {
|
||||
ItemInNs::Values(hir::ModuleDef::Function(f)) => {
|
||||
.for_each(|import| {
|
||||
if let ItemInNs::Values(hir::ModuleDef::Function(f)) = import.original_item {
|
||||
acc.add_method_with_import(ctx, dot_access, f, import);
|
||||
}
|
||||
_ => (),
|
||||
});
|
||||
Some(())
|
||||
}
|
||||
|
|
|
@ -295,15 +295,12 @@ fn render_resolution_pat(
|
|||
let _p = profile::span("render_resolution");
|
||||
use hir::ModuleDef::*;
|
||||
|
||||
match resolution {
|
||||
ScopeDef::ModuleDef(Macro(mac)) => {
|
||||
let ctx = ctx.import_to_add(import_to_add);
|
||||
return render_macro_pat(ctx, pattern_ctx, local_name, mac);
|
||||
}
|
||||
_ => (),
|
||||
if let ScopeDef::ModuleDef(Macro(mac)) = resolution {
|
||||
let ctx = ctx.import_to_add(import_to_add);
|
||||
render_macro_pat(ctx, pattern_ctx, local_name, mac)
|
||||
} else {
|
||||
render_resolution_simple_(ctx, &local_name, import_to_add, resolution)
|
||||
}
|
||||
|
||||
render_resolution_simple_(ctx, &local_name, import_to_add, resolution)
|
||||
}
|
||||
|
||||
fn render_resolution_path(
|
||||
|
|
|
@ -282,8 +282,8 @@ fn traverse(
|
|||
inside_attribute = false
|
||||
}
|
||||
|
||||
Enter(NodeOrToken::Node(node)) => match ast::Item::cast(node.clone()) {
|
||||
Some(item) => {
|
||||
Enter(NodeOrToken::Node(node)) => {
|
||||
if let Some(item) = ast::Item::cast(node.clone()) {
|
||||
match item {
|
||||
ast::Item::MacroRules(mac) => {
|
||||
macro_highlighter.init();
|
||||
|
@ -324,8 +324,7 @@ fn traverse(
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
}
|
||||
Leave(NodeOrToken::Node(node)) if ast::Item::can_cast(node.kind()) => {
|
||||
match ast::Item::cast(node.clone()) {
|
||||
Some(ast::Item::MacroRules(mac)) => {
|
||||
|
|
|
@ -567,10 +567,11 @@ impl GlobalState {
|
|||
|
||||
for ws in &self.fetch_build_data_queue.last_op_result().1 {
|
||||
match ws {
|
||||
Ok(data) => match data.error() {
|
||||
Some(stderr) => stdx::format_to!(buf, "{:#}\n", stderr),
|
||||
_ => (),
|
||||
},
|
||||
Ok(data) => {
|
||||
if let Some(stderr) = data.error() {
|
||||
stdx::format_to!(buf, "{:#}\n", stderr)
|
||||
}
|
||||
}
|
||||
// io errors
|
||||
Err(err) => stdx::format_to!(buf, "{:#}\n", err),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue