mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
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:
commit
0b7d4cc6ff
5 changed files with 52 additions and 64 deletions
|
@ -418,24 +418,15 @@ fn inline(
|
||||||
let expr: &ast::Expr = expr;
|
let expr: &ast::Expr = expr;
|
||||||
|
|
||||||
let mut insert_let_stmt = || {
|
let mut insert_let_stmt = || {
|
||||||
let param_ty = match param_ty {
|
let param_ty = param_ty.clone().map(|param_ty| {
|
||||||
None => None,
|
if sema.hir_file_for(param_ty.syntax()).is_macro() {
|
||||||
Some(param_ty) => {
|
ast::Type::cast(insert_ws_into(param_ty.syntax().clone())).unwrap_or(param_ty)
|
||||||
if sema.hir_file_for(param_ty.syntax()).is_macro() {
|
} else {
|
||||||
if let Some(param_ty) =
|
param_ty
|
||||||
ast::Type::cast(insert_ws_into(param_ty.syntax().clone()))
|
|
||||||
{
|
|
||||||
Some(param_ty)
|
|
||||||
} else {
|
|
||||||
Some(param_ty.clone_for_update())
|
|
||||||
}
|
|
||||||
} 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
|
let is_self = param
|
||||||
.name(sema.db)
|
.name(sema.db)
|
||||||
|
@ -1359,8 +1350,8 @@ macro_rules! define_foo {
|
||||||
define_foo!();
|
define_foo!();
|
||||||
fn bar() -> u32 {
|
fn bar() -> u32 {
|
||||||
{
|
{
|
||||||
let x = 0;
|
let x = 0;
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -1673,7 +1664,7 @@ fn main() {
|
||||||
let a: A = A{};
|
let a: A = A{};
|
||||||
let b = {
|
let b = {
|
||||||
let a = a;
|
let a = a;
|
||||||
a as A
|
a as A
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -1792,7 +1783,7 @@ fn _hash2(self_: &u64, state: &mut u64) {
|
||||||
{
|
{
|
||||||
let inner_self_: &u64 = &self_;
|
let inner_self_: &u64 = &self_;
|
||||||
let state: &mut u64 = state;
|
let state: &mut u64 = state;
|
||||||
_write_u64(state, *inner_self_)
|
_write_u64(state, *inner_self_)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
|
@ -288,11 +288,11 @@ macro_rules! foo {
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
cfg_if!{
|
cfg_if!{
|
||||||
if #[cfg(test)]{
|
if #[cfg(test)]{
|
||||||
1;
|
1;
|
||||||
}else {
|
}else {
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
|
||||||
let after = Position::after;
|
let after = Position::after;
|
||||||
|
|
||||||
let do_indent = |pos: fn(_) -> Position, token: &SyntaxToken, indent| {
|
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| {
|
let do_ws = |pos: fn(_) -> Position, token: &SyntaxToken| {
|
||||||
(pos(token.clone()), make::tokens::single_space())
|
(pos(token.clone()), make::tokens::single_space())
|
||||||
|
@ -41,7 +41,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
|
||||||
if indent > 0 {
|
if indent > 0 {
|
||||||
mods.push((
|
mods.push((
|
||||||
Position::after(node.clone()),
|
Position::after(node.clone()),
|
||||||
make::tokens::whitespace(&" ".repeat(2 * indent)),
|
make::tokens::whitespace(&" ".repeat(4 * indent)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if node.parent().is_some() {
|
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) => {
|
LIFETIME_IDENT if is_next(is_text, true) => {
|
||||||
mods.push(do_ws(after, tok));
|
mods.push(do_ws(after, tok));
|
||||||
}
|
}
|
||||||
MUT_KW if is_next(|it| it == SELF_KW, false) => {
|
AS_KW | DYN_KW | IMPL_KW | CONST_KW | MUT_KW => {
|
||||||
mods.push(do_ws(after, tok));
|
|
||||||
}
|
|
||||||
AS_KW | DYN_KW | IMPL_KW | CONST_KW => {
|
|
||||||
mods.push(do_ws(after, tok));
|
mods.push(do_ws(after, tok));
|
||||||
}
|
}
|
||||||
T![;] if is_next(|it| it != R_CURLY, true) => {
|
T![;] if is_next(|it| it != R_CURLY, true) => {
|
||||||
|
|
|
@ -308,8 +308,8 @@ f$0oo!();
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
foo!
|
foo!
|
||||||
fn some_thing() -> u32 {
|
fn some_thing() -> u32 {
|
||||||
let a = 0;
|
let a = 0;
|
||||||
a+10
|
a+10
|
||||||
}"#]],
|
}"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -342,13 +342,13 @@ fn main() {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
match_ast!
|
match_ast!
|
||||||
{
|
{
|
||||||
if let Some(it) = ast::TraitDef::cast(container.clone()){}
|
if let Some(it) = ast::TraitDef::cast(container.clone()){}
|
||||||
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
|
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
|
||||||
else {
|
else {
|
||||||
{
|
{
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}"#]],
|
}"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -397,12 +397,12 @@ fn main() {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
foo!
|
foo!
|
||||||
{
|
{
|
||||||
macro_rules! bar {
|
macro_rules! bar {
|
||||||
() => {
|
() => {
|
||||||
42
|
42
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
42
|
||||||
42
|
|
||||||
}"#]],
|
}"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -482,16 +482,16 @@ struct Foo {}
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
Clone
|
Clone
|
||||||
impl < >$crate::clone::Clone for Foo< >where {
|
impl < >$crate::clone::Clone for Foo< >where {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Foo{}
|
Foo{}
|
||||||
=> Foo{}
|
=> Foo{}
|
||||||
,
|
,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}"#]],
|
}"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,16 +534,16 @@ struct Foo {}
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
Clone
|
Clone
|
||||||
impl < >$crate::clone::Clone for Foo< >where {
|
impl < >$crate::clone::Clone for Foo< >where {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Foo{}
|
Foo{}
|
||||||
=> Foo{}
|
=> Foo{}
|
||||||
,
|
,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}"#]],
|
}"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6366,8 +6366,8 @@ fn main() { $0V; }
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub const V: i8 = {
|
pub const V: i8 = {
|
||||||
let e = 123;
|
let e = 123;
|
||||||
f(e)
|
f(e)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -6393,7 +6393,7 @@ fn main() { $0V; }
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
pub static V: i8 = {
|
pub static V: i8 = {
|
||||||
let e = 123;
|
let e = 123;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue