about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-10 09:29:19 +0000
committerbors <bors@rust-lang.org>2022-08-10 09:29:19 +0000
commitd79d9e1a2e0a15f821e15c07c57046b395ddea9c (patch)
treee48b777ceb72a7d9d8d87738dce7017034880e4a
parent5366009fe47ab06e53b68811873448de52c5cd8f (diff)
parentc47914c6cfbce6e99bdeb5b8183b9655673b1110 (diff)
downloadrust-d79d9e1a2e0a15f821e15c07c57046b395ddea9c.tar.gz
rust-d79d9e1a2e0a15f821e15c07c57046b395ddea9c.zip
Auto merge of #12990 - edwin0cheng:improve-ws, r=Veykril
fix: Improve whitespace insertion in mbe

Related:  https://github.com/rust-lang/rust-analyzer/issues/12260#issuecomment-1126957162
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe.rs12
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe/regression.rs4
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs2
-rw-r--r--crates/hir-def/src/macro_expansion_tests/proc_macros.rs2
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs8
-rw-r--r--crates/hir-expand/src/fixup.rs14
-rw-r--r--crates/ide-assists/src/handlers/add_missing_impl_members.rs2
-rw-r--r--crates/mbe/src/syntax_bridge.rs11
-rw-r--r--crates/proc-macro-srv/src/tests/mod.rs6
9 files changed, 28 insertions, 33 deletions
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe.rs b/crates/hir-def/src/macro_expansion_tests/mbe.rs
index 30d39d52f38..457e43925c6 100644
--- a/crates/hir-def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mbe.rs
@@ -885,7 +885,7 @@ macro_rules! m {
     ($t:ty) => ( fn bar() -> $ t {} )
 }
 
-fn bar() -> & 'a Baz<u8> {}
+fn bar() -> &'a Baz<u8> {}
 
 fn bar() -> extern "Rust"fn() -> Ret {}
 "#]],
@@ -1578,7 +1578,7 @@ macro_rules !register_methods {
             ($$($val: expr), *) = > {
                 struct Foo;
                 impl Foo {
-                    $(fn $method()-> & 'static[u32] {
+                    $(fn $method()-> &'static[u32] {
                         &[$$($$val), *]
                     }
                     )*
@@ -1591,10 +1591,10 @@ macro_rules !implement_methods {
     ($($val: expr), *) = > {
         struct Foo;
         impl Foo {
-            fn alpha()-> & 'static[u32] {
+            fn alpha()-> &'static[u32] {
                 &[$($val), *]
             }
-            fn beta()-> & 'static[u32] {
+            fn beta()-> &'static[u32] {
                 &[$($val), *]
             }
         }
@@ -1602,10 +1602,10 @@ macro_rules !implement_methods {
 }
 struct Foo;
 impl Foo {
-    fn alpha() -> & 'static[u32] {
+    fn alpha() -> &'static[u32] {
         &[1, 2, 3]
     }
-    fn beta() -> & 'static[u32] {
+    fn beta() -> &'static[u32] {
         &[1, 2, 3]
     }
 }
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs b/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs
index 2dff4adf2ee..d2505e7cafe 100644
--- a/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs
@@ -166,7 +166,7 @@ macro_rules! int_base {
     }
 }
 #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Binary for isize {
-    fn fmt(&self , f: &mut fmt::Formatter< '_>) -> fmt::Result {
+    fn fmt(&self , f: &mut fmt::Formatter<'_>) -> fmt::Result {
         Binary.fmt_int(*self as usize, f)
     }
 }
@@ -724,7 +724,7 @@ macro_rules! delegate_impl {
         }
     }
 }
-impl <> Data for & 'amut G where G: Data {}
+impl <> Data for &'amut G where G: Data {}
 "##]],
     );
 }
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs b/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs
index 0710b1ac3d6..b8d2ca687c9 100644
--- a/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs
@@ -78,7 +78,7 @@ m!(static bar: &'static str = "hello";);
 macro_rules! m {
     ($($t:tt)*) => { $($t)*}
 }
-static bar: & 'static str = "hello";
+static bar: &'static str = "hello";
 "#]],
     );
 }
diff --git a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
index 72c44a0fbcb..029821e5e87 100644
--- a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
+++ b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
@@ -87,7 +87,7 @@ fn foo() { bar.; blub }
 fn foo() { bar.; blub }
 
 fn foo() {
-    bar. ;
+    bar.;
     blub
 }"##]],
     );
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index c21b35cdc09..8befa7f7da7 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -251,9 +251,13 @@ fn format_args_expand(
     }
     for arg in &mut args {
         // Remove `key =`.
-        if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' && p.spacing != tt::Spacing::Joint)
+        if matches!(arg.token_trees.get(1), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=')
         {
-            arg.token_trees.drain(..2);
+            // but not with `==`
+            if !matches!(arg.token_trees.get(2), Some(tt::TokenTree::Leaf(tt::Leaf::Punct(p))) if p.char == '=' )
+            {
+                arg.token_trees.drain(..2);
+            }
         }
     }
     let _format_string = args.remove(0);
diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs
index 46257b6bc4d..893e6fe4b82 100644
--- a/crates/hir-expand/src/fixup.rs
+++ b/crates/hir-expand/src/fixup.rs
@@ -468,7 +468,7 @@ fn foo() {
 }
 "#,
             expect![[r#"
-fn foo () {a . __ra_fixup}
+fn foo () {a .__ra_fixup}
 "#]],
         )
     }
@@ -478,11 +478,11 @@ fn foo () {a . __ra_fixup}
         check(
             r#"
 fn foo() {
-    a. ;
+    a.;
 }
 "#,
             expect![[r#"
-fn foo () {a . __ra_fixup ;}
+fn foo () {a .__ra_fixup ;}
 "#]],
         )
     }
@@ -492,12 +492,12 @@ fn foo () {a . __ra_fixup ;}
         check(
             r#"
 fn foo() {
-    a. ;
+    a.;
     bar();
 }
 "#,
             expect![[r#"
-fn foo () {a . __ra_fixup ; bar () ;}
+fn foo () {a .__ra_fixup ; bar () ;}
 "#]],
         )
     }
@@ -525,7 +525,7 @@ fn foo() {
 }
 "#,
             expect![[r#"
-fn foo () {let x = a . __ra_fixup ;}
+fn foo () {let x = a .__ra_fixup ;}
 "#]],
         )
     }
@@ -541,7 +541,7 @@ fn foo() {
 }
 "#,
             expect![[r#"
-fn foo () {a . b ; bar () ;}
+fn foo () {a .b ; bar () ;}
 "#]],
         )
     }
diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
index c808c010c67..62cf5ab4f37 100644
--- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
@@ -944,7 +944,7 @@ foo!();
 struct Foo(usize);
 
 impl FooB for Foo {
-    $0fn foo< 'lt>(& 'lt self){}
+    $0fn foo<'lt>(&'lt self){}
 }
 "#,
         )
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index aca6ecd424e..e4c56565b92 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -228,16 +228,7 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
             }
 
             let spacing = match conv.peek().map(|next| next.kind(conv)) {
-                Some(kind)
-                    if !kind.is_trivia()
-                        && kind.is_punct()
-                        && kind != T!['[']
-                        && kind != T!['{']
-                        && kind != T!['(']
-                        && kind != UNDERSCORE =>
-                {
-                    tt::Spacing::Joint
-                }
+                Some(kind) if !kind.is_trivia() => tt::Spacing::Joint,
                 _ => tt::Spacing::Alone,
             };
             let char = match token.to_char(conv) {
diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs
index 07222907f08..6339d56d017 100644
--- a/crates/proc-macro-srv/src/tests/mod.rs
+++ b/crates/proc-macro-srv/src/tests/mod.rs
@@ -19,7 +19,7 @@ fn test_derive_error() {
         expect![[r##"
             SUBTREE $
               IDENT   compile_error 4294967295
-              PUNCH   ! [alone] 4294967295
+              PUNCH   ! [joint] 4294967295
               SUBTREE () 4294967295
                 LITERAL "#[derive(DeriveError)] struct S ;" 4294967295
               PUNCH   ; [alone] 4294967295"##]],
@@ -109,7 +109,7 @@ fn test_fn_like_macro_clone_literals() {
               PUNCH   , [alone] 4294967295
               LITERAL 2_u32 4294967295
               PUNCH   , [alone] 4294967295
-              PUNCH   - [alone] 4294967295
+              PUNCH   - [joint] 4294967295
               LITERAL 4i64 4294967295
               PUNCH   , [alone] 4294967295
               LITERAL 3.14f32 4294967295
@@ -130,7 +130,7 @@ fn test_attr_macro() {
         expect![[r##"
             SUBTREE $
               IDENT   compile_error 4294967295
-              PUNCH   ! [alone] 4294967295
+              PUNCH   ! [joint] 4294967295
               SUBTREE () 4294967295
                 LITERAL "#[attr_error(some arguments)] mod m {}" 4294967295
               PUNCH   ; [alone] 4294967295"##]],