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