Skip to content

Commit 0b7d4cc

Browse files
committed
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.
2 parents 518cfe8 + 76b86b2 commit 0b7d4cc

File tree

5 files changed

+52
-64
lines changed

5 files changed

+52
-64
lines changed

crates/ide-assists/src/handlers/inline_call.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -418,24 +418,15 @@ fn inline(
418418
let expr: &ast::Expr = expr;
419419

420420
let mut insert_let_stmt = || {
421-
let param_ty = match param_ty {
422-
None => None,
423-
Some(param_ty) => {
424-
if sema.hir_file_for(param_ty.syntax()).is_macro() {
425-
if let Some(param_ty) =
426-
ast::Type::cast(insert_ws_into(param_ty.syntax().clone()))
427-
{
428-
Some(param_ty)
429-
} else {
430-
Some(param_ty.clone_for_update())
431-
}
432-
} else {
433-
Some(param_ty.clone_for_update())
434-
}
421+
let param_ty = param_ty.clone().map(|param_ty| {
422+
if sema.hir_file_for(param_ty.syntax()).is_macro() {
423+
ast::Type::cast(insert_ws_into(param_ty.syntax().clone())).unwrap_or(param_ty)
424+
} else {
425+
param_ty
435426
}
436-
};
437-
let ty: Option<syntax::ast::Type> =
438-
sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
427+
});
428+
429+
let ty = sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);
439430

440431
let is_self = param
441432
.name(sema.db)
@@ -1359,8 +1350,8 @@ macro_rules! define_foo {
13591350
define_foo!();
13601351
fn bar() -> u32 {
13611352
{
1362-
let x = 0;
1363-
x
1353+
let x = 0;
1354+
x
13641355
}
13651356
}
13661357
"#,
@@ -1673,7 +1664,7 @@ fn main() {
16731664
let a: A = A{};
16741665
let b = {
16751666
let a = a;
1676-
a as A
1667+
a as A
16771668
};
16781669
}
16791670
"#,
@@ -1792,7 +1783,7 @@ fn _hash2(self_: &u64, state: &mut u64) {
17921783
{
17931784
let inner_self_: &u64 = &self_;
17941785
let state: &mut u64 = state;
1795-
_write_u64(state, *inner_self_)
1786+
_write_u64(state, *inner_self_)
17961787
};
17971788
}
17981789
"#,

crates/ide-assists/src/handlers/inline_macro.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ macro_rules! foo {
288288
}
289289
fn main() {
290290
cfg_if!{
291-
if #[cfg(test)]{
292-
1;
293-
}else {
294-
1;
295-
}
291+
if #[cfg(test)]{
292+
1;
293+
}else {
294+
1;
295+
}
296296
};
297297
}
298298
"#,

crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
2020
let after = Position::after;
2121

2222
let do_indent = |pos: fn(_) -> Position, token: &SyntaxToken, indent| {
23-
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(2 * indent)))
23+
(pos(token.clone()), make::tokens::whitespace(&" ".repeat(4 * indent)))
2424
};
2525
let do_ws = |pos: fn(_) -> Position, token: &SyntaxToken| {
2626
(pos(token.clone()), make::tokens::single_space())
@@ -41,7 +41,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
4141
if indent > 0 {
4242
mods.push((
4343
Position::after(node.clone()),
44-
make::tokens::whitespace(&" ".repeat(2 * indent)),
44+
make::tokens::whitespace(&" ".repeat(4 * indent)),
4545
));
4646
}
4747
if node.parent().is_some() {
@@ -91,10 +91,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
9191
LIFETIME_IDENT if is_next(is_text, true) => {
9292
mods.push(do_ws(after, tok));
9393
}
94-
MUT_KW if is_next(|it| it == SELF_KW, false) => {
95-
mods.push(do_ws(after, tok));
96-
}
97-
AS_KW | DYN_KW | IMPL_KW | CONST_KW => {
94+
AS_KW | DYN_KW | IMPL_KW | CONST_KW | MUT_KW => {
9895
mods.push(do_ws(after, tok));
9996
}
10097
T![;] if is_next(|it| it != R_CURLY, true) => {

crates/ide/src/expand_macro.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ f$0oo!();
308308
expect![[r#"
309309
foo!
310310
fn some_thing() -> u32 {
311-
let a = 0;
312-
a+10
311+
let a = 0;
312+
a+10
313313
}"#]],
314314
);
315315
}
@@ -342,13 +342,13 @@ fn main() {
342342
expect![[r#"
343343
match_ast!
344344
{
345-
if let Some(it) = ast::TraitDef::cast(container.clone()){}
346-
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
347-
else {
348-
{
349-
continue
345+
if let Some(it) = ast::TraitDef::cast(container.clone()){}
346+
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
347+
else {
348+
{
349+
continue
350+
}
350351
}
351-
}
352352
}"#]],
353353
);
354354
}
@@ -397,12 +397,12 @@ fn main() {
397397
expect![[r#"
398398
foo!
399399
{
400-
macro_rules! bar {
401-
() => {
402-
42
400+
macro_rules! bar {
401+
() => {
402+
42
403+
}
403404
}
404-
}
405-
42
405+
42
406406
}"#]],
407407
);
408408
}
@@ -482,16 +482,16 @@ struct Foo {}
482482
expect![[r#"
483483
Clone
484484
impl < >$crate::clone::Clone for Foo< >where {
485-
fn clone(&self) -> Self {
486-
match self {
487-
Foo{}
488-
=> Foo{}
489-
,
485+
fn clone(&self) -> Self {
486+
match self {
487+
Foo{}
488+
=> Foo{}
489+
,
490490
491-
}
492-
}
491+
}
492+
}
493493
494-
}"#]],
494+
}"#]],
495495
);
496496
}
497497

@@ -534,16 +534,16 @@ struct Foo {}
534534
expect![[r#"
535535
Clone
536536
impl < >$crate::clone::Clone for Foo< >where {
537-
fn clone(&self) -> Self {
538-
match self {
539-
Foo{}
540-
=> Foo{}
541-
,
537+
fn clone(&self) -> Self {
538+
match self {
539+
Foo{}
540+
=> Foo{}
541+
,
542542
543-
}
544-
}
543+
}
544+
}
545545
546-
}"#]],
546+
}"#]],
547547
);
548548
}
549549
}

crates/ide/src/hover/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,8 +6366,8 @@ fn main() { $0V; }
63666366
63676367
```rust
63686368
pub const V: i8 = {
6369-
let e = 123;
6370-
f(e)
6369+
let e = 123;
6370+
f(e)
63716371
}
63726372
```
63736373
"#]],
@@ -6393,7 +6393,7 @@ fn main() { $0V; }
63936393
63946394
```rust
63956395
pub static V: i8 = {
6396-
let e = 123;
6396+
let e = 123;
63976397
}
63986398
```
63996399
"#]],

0 commit comments

Comments
 (0)