Remove match_ast! macro call

Add node about uncommenting tuple in macro call
This commit is contained in:
BooksBaum 2021-08-19 14:09:52 +02:00
parent b1ebb82f32
commit 2c27adc0a3
No known key found for this signature in database
GPG Key ID: 8C831753B888F65A

View File

@ -227,6 +227,11 @@ fn edit_tuple_usage(
// no index access -> make invalid -> requires handling by user
// -> put usage in block comment
//
// Note: For macro invocations this might result in still valid code:
// When a macro accepts the tuple as argument, as well as no arguments at all,
// uncommenting the tuple still leaves the macro call working (see `tests::in_macro_call::empty_macro`).
// But this is an unlikely case. Usually the resulting macro call will become erroneous.
builder.insert(usage.range.start(), "/*");
builder.insert(usage.range.end(), "*/");
}
@ -322,14 +327,17 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat
let mut ref_data =
RefData { range: s.text_range(), needs_deref: true, needs_parentheses: true };
let parent = match s.parent() {
Some(parent) => parent,
let parent = match s.parent().map(ast::Expr::cast) {
Some(Some(parent)) => parent,
Some(None) => {
ref_data.needs_parentheses = false;
return ref_data;
}
None => return ref_data,
};
match_ast! {
match parent {
ast::ParenExpr(it) => {
ast::Expr::ParenExpr(it) => {
// already parens in place -> don't replace
ref_data.needs_parentheses = false;
// there might be a ref outside: `&(t.0)` -> can be removed
@ -337,8 +345,8 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat
ref_data.needs_deref = false;
ref_data.range = it.syntax().text_range();
}
},
ast::RefExpr(it) => {
}
ast::Expr::RefExpr(it) => {
// `&*` -> cancel each other out
ref_data.needs_deref = false;
ref_data.needs_parentheses = false;
@ -347,12 +355,12 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat
Some(parent) => ref_data.range = parent.syntax().text_range(),
None => ref_data.range = it.syntax().text_range(),
};
},
}
// higher precedence than deref `*`
// https://doc.rust-lang.org/reference/expressions.html#expression-precedence
// -> requires parentheses
ast::PathExpr(_it) => {},
ast::MethodCallExpr(it) => {
ast::Expr::PathExpr(_it) => {}
ast::Expr::MethodCallExpr(it) => {
// `field_expr` is `self_param` (otherwise it would be in `ArgList`)
// test if there's already auto-ref in place (`value` -> `&value`)
@ -386,25 +394,24 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat
ref_data.needs_deref = false;
ref_data.needs_parentheses = false;
}
},
ast::FieldExpr(_it) => {
}
ast::Expr::FieldExpr(_it) => {
// `t.0.my_field`
ref_data.needs_deref = false;
ref_data.needs_parentheses = false;
},
ast::IndexExpr(_it) => {
}
ast::Expr::IndexExpr(_it) => {
// `t.0[1]`
ref_data.needs_deref = false;
ref_data.needs_parentheses = false;
},
ast::TryExpr(_it) => {
}
ast::Expr::TryExpr(_it) => {
// `t.0?`
// requires deref and parens: `(*_0)`
},
}
// lower precedence than deref `*` -> no parens
_ => {
ref_data.needs_parentheses = false;
},
}
};