From 34a912933323aa343ffa016b19c6e73155a26431 Mon Sep 17 00:00:00 2001 From: Ryo Yoshida Date: Thu, 11 May 2023 18:15:28 +0900 Subject: [PATCH] fix: `column!()` and `line!()` built-in macros return u32 --- .../macro_expansion_tests/builtin_fn_macro.rs | 12 +++++------ .../hir-def/src/macro_expansion_tests/mbe.rs | 4 ++-- .../src/macro_expansion_tests/mbe/matching.rs | 2 +- .../macro_expansion_tests/mbe/regression.rs | 20 +++++++++---------- .../hir-def/src/macro_expansion_tests/mod.rs | 1 + crates/hir-expand/src/builtin_fn_macro.rs | 6 ++---- crates/hir-ty/src/tests/macros.rs | 6 ++++-- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs index 0b72ca1eec1..6cb741dac71 100644 --- a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs +++ b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs @@ -13,12 +13,12 @@ macro_rules! column {() => {}} fn main() { column!(); } "#, - expect![[r##" + expect![[r#" #[rustc_builtin_macro] macro_rules! column {() => {}} -fn main() { 0; } -"##]], +fn main() { 0 as u32; } +"#]], ); } @@ -31,12 +31,12 @@ macro_rules! line {() => {}} fn main() { line!() } "#, - expect![[r##" + expect![[r#" #[rustc_builtin_macro] macro_rules! line {() => {}} -fn main() { 0 } -"##]], +fn main() { 0 as u32 } +"#]], ); } diff --git a/crates/hir-def/src/macro_expansion_tests/mbe.rs b/crates/hir-def/src/macro_expansion_tests/mbe.rs index 99c405fb917..c056c077a56 100644 --- a/crates/hir-def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir-def/src/macro_expansion_tests/mbe.rs @@ -922,7 +922,7 @@ macro_rules! m { fn bar() -> &'a Baz {} -fn bar() -> extern "Rust"fn() -> Ret {} +fn bar() -> extern "Rust" fn() -> Ret {} "#]], ); } @@ -1333,7 +1333,7 @@ macro_rules! matches { } fn main() { match 0 { - 0|1if true =>true , _=>false + 0|1 if true =>true , _=>false }; } "#]], diff --git a/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs index e5fb15b6be4..0909d8c8354 100644 --- a/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs +++ b/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs @@ -73,7 +73,7 @@ fn main() { macro_rules! asi { ($($stmt:stmt)*) => ($($stmt)*); } fn main() { - let a = 2let b = 5drop(b-a)println!("{}", a+b) + let a = 2 let b = 5 drop(b-a)println!("{}", a+b) } "#]], ) 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 b663a291789..d8e4a4dcc7c 100644 --- a/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs +++ b/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs @@ -297,55 +297,55 @@ extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $Return #[derive(Clone)] struct CharEscapeDebugContinue; impl Fn<(char, )> for CharEscapeDebugContinue { - #[inline] extern "rust-call"fn call(&self , (c, ): (char, )) -> char::EscapeDebug { { + #[inline] extern "rust-call" fn call(&self , (c, ): (char, )) -> char::EscapeDebug { { c.escape_debug_ext(false ) } } } impl FnMut<(char, )> for CharEscapeDebugContinue { - #[inline] extern "rust-call"fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeDebug { + #[inline] extern "rust-call" fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeDebug { Fn::call(&*self , (c, )) } } impl FnOnce<(char, )> for CharEscapeDebugContinue { type Output = char::EscapeDebug; - #[inline] extern "rust-call"fn call_once(self , (c, ): (char, )) -> char::EscapeDebug { + #[inline] extern "rust-call" fn call_once(self , (c, ): (char, )) -> char::EscapeDebug { Fn::call(&self , (c, )) } } #[derive(Clone)] struct CharEscapeUnicode; impl Fn<(char, )> for CharEscapeUnicode { - #[inline] extern "rust-call"fn call(&self , (c, ): (char, )) -> char::EscapeUnicode { { + #[inline] extern "rust-call" fn call(&self , (c, ): (char, )) -> char::EscapeUnicode { { c.escape_unicode() } } } impl FnMut<(char, )> for CharEscapeUnicode { - #[inline] extern "rust-call"fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeUnicode { + #[inline] extern "rust-call" fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeUnicode { Fn::call(&*self , (c, )) } } impl FnOnce<(char, )> for CharEscapeUnicode { type Output = char::EscapeUnicode; - #[inline] extern "rust-call"fn call_once(self , (c, ): (char, )) -> char::EscapeUnicode { + #[inline] extern "rust-call" fn call_once(self , (c, ): (char, )) -> char::EscapeUnicode { Fn::call(&self , (c, )) } } #[derive(Clone)] struct CharEscapeDefault; impl Fn<(char, )> for CharEscapeDefault { - #[inline] extern "rust-call"fn call(&self , (c, ): (char, )) -> char::EscapeDefault { { + #[inline] extern "rust-call" fn call(&self , (c, ): (char, )) -> char::EscapeDefault { { c.escape_default() } } } impl FnMut<(char, )> for CharEscapeDefault { - #[inline] extern "rust-call"fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeDefault { + #[inline] extern "rust-call" fn call_mut(&mut self , (c, ): (char, )) -> char::EscapeDefault { Fn::call(&*self , (c, )) } } impl FnOnce<(char, )> for CharEscapeDefault { type Output = char::EscapeDefault; - #[inline] extern "rust-call"fn call_once(self , (c, ): (char, )) -> char::EscapeDefault { + #[inline] extern "rust-call" fn call_once(self , (c, ): (char, )) -> char::EscapeDefault { Fn::call(&self , (c, )) } } @@ -833,7 +833,7 @@ pub fn new() { /* parse error: expected SEMICOLON */ /* parse error: expected expression, item or let statement */ pub fn new() { - let _ = 0as u32<<(8+8); + let _ = 0 as u32<<(8+8); } // MACRO_ITEMS@0..31 // FN@0..31 diff --git a/crates/hir-def/src/macro_expansion_tests/mod.rs b/crates/hir-def/src/macro_expansion_tests/mod.rs index c48c0c1aee5..a59a3dc81ef 100644 --- a/crates/hir-def/src/macro_expansion_tests/mod.rs +++ b/crates/hir-def/src/macro_expansion_tests/mod.rs @@ -280,6 +280,7 @@ fn pretty_print_macro_expansion(expn: SyntaxNode, map: Option<&TokenMap>) -> Str let curr_kind = token.kind(); let space = match (prev_kind, curr_kind) { _ if prev_kind.is_trivia() || curr_kind.is_trivia() => "", + _ if prev_kind.is_literal() && !curr_kind.is_punct() => " ", (T!['{'], T!['}']) => "", (T![=], _) | (_, T![=]) => " ", (_, T!['{']) => " ", diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs index 9a25141d8f1..9c8dc4ed1fc 100644 --- a/crates/hir-expand/src/builtin_fn_macro.rs +++ b/crates/hir-expand/src/builtin_fn_macro.rs @@ -135,9 +135,8 @@ fn line_expand( _tt: &tt::Subtree, ) -> ExpandResult { // dummy implementation for type-checking purposes - let line_num = 0; let expanded = quote! { - #line_num + 0 as u32 }; ExpandResult::ok(expanded) @@ -179,9 +178,8 @@ fn column_expand( _tt: &tt::Subtree, ) -> ExpandResult { // dummy implementation for type-checking purposes - let col_num = 0; let expanded = quote! { - #col_num + 0 as u32 }; ExpandResult::ok(expanded) diff --git a/crates/hir-ty/src/tests/macros.rs b/crates/hir-ty/src/tests/macros.rs index d45edf730ad..9377a3a5f26 100644 --- a/crates/hir-ty/src/tests/macros.rs +++ b/crates/hir-ty/src/tests/macros.rs @@ -661,8 +661,9 @@ fn main() { "#, expect![[r#" !0..1 '0': i32 + !0..6 '0asu32': u32 63..87 '{ ...!(); }': () - 73..74 'x': i32 + 73..74 'x': u32 "#]], ); } @@ -699,8 +700,9 @@ fn main() { "#, expect![[r#" !0..1 '0': i32 + !0..6 '0asu32': u32 65..91 '{ ...!(); }': () - 75..76 'x': i32 + 75..76 'x': u32 "#]], ); }