Auto merge of #16690 - roife:fix-issue-16471, r=Veykril

fix: use 4 spaces for indentation in macro expansion

Partial fix for #16471.

In the previous code, the indentation produced by macro expansion was set to 2 spaces. This PR modifies it to 4 spaces for the sake of consistency.
This commit is contained in:
bors 2024-03-04 08:49:51 +00:00
commit 0b7d4cc6ff
5 changed files with 52 additions and 64 deletions

View file

@ -418,24 +418,15 @@ fn inline(
let expr: &ast::Expr = expr;
let mut insert_let_stmt = || {
let param_ty = match param_ty {
None => None,
Some(param_ty) => {
let param_ty = param_ty.clone().map(|param_ty| {
if sema.hir_file_for(param_ty.syntax()).is_macro() {
if let Some(param_ty) =
ast::Type::cast(insert_ws_into(param_ty.syntax().clone()))
{
Some(param_ty)
ast::Type::cast(insert_ws_into(param_ty.syntax().clone())).unwrap_or(param_ty)
} else {
Some(param_ty.clone_for_update())
param_ty
}
} else {
Some(param_ty.clone_for_update())
}
}
};
let ty: Option<syntax::ast::Type> =
sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
});
let ty = sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
let is_self = param
.name(sema.db)

View file

@ -20,7 +20,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
let after = Position::after;
let do_indent = |pos: fn(_) -> Position, token: &SyntaxToken, indent| {
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(2 * indent)))
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(4 * indent)))
};
let do_ws = |pos: fn(_) -> Position, token: &SyntaxToken| {
(pos(token.clone()), make::tokens::single_space())
@ -41,7 +41,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
if indent > 0 {
mods.push((
Position::after(node.clone()),
make::tokens::whitespace(&" ".repeat(2 * indent)),
make::tokens::whitespace(&" ".repeat(4 * indent)),
));
}
if node.parent().is_some() {
@ -91,10 +91,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
LIFETIME_IDENT if is_next(is_text, true) => {
mods.push(do_ws(after, tok));
}
MUT_KW if is_next(|it| it == SELF_KW, false) => {
mods.push(do_ws(after, tok));
}
AS_KW | DYN_KW | IMPL_KW | CONST_KW => {
AS_KW | DYN_KW | IMPL_KW | CONST_KW | MUT_KW => {
mods.push(do_ws(after, tok));
}
T![;] if is_next(|it| it != R_CURLY, true) => {