Auto merge of #15903 - Veykril:inner-diag, r=Veykril

Fix builtin line! expansion

`concat` expects only literals, not whole syntax nodes, so we need to expand as such
This commit is contained in:
bors 2023-11-15 13:21:17 +00:00
commit b8b4b22c1b
5 changed files with 46 additions and 26 deletions

View file

@ -17,7 +17,7 @@ fn main() { column!(); }
#[rustc_builtin_macro]
macro_rules! column {() => {}}
fn main() { 0 as u32; }
fn main() { 0u32; }
"#]],
);
}
@ -74,7 +74,7 @@ fn main() { line!() }
#[rustc_builtin_macro]
macro_rules! line {() => {}}
fn main() { 0 as u32 }
fn main() { 0u32 }
"#]],
);
}

View file

@ -970,3 +970,37 @@ builtin #format_args ("{}", &[0 2]);
"##]],
);
}
#[test]
fn eager_concat_line() {
check(
r#"
#[rustc_builtin_macro]
#[macro_export]
macro_rules! concat {}
#[rustc_builtin_macro]
#[macro_export]
macro_rules! line {}
fn main() {
concat!("event ", line!());
}
"#,
expect![[r##"
#[rustc_builtin_macro]
#[macro_export]
macro_rules! concat {}
#[rustc_builtin_macro]
#[macro_export]
macro_rules! line {}
fn main() {
"event 0u32";
}
"##]],
);
}

View file

@ -78,7 +78,7 @@ pub fn find_builtin_macro(
register_builtin! {
LAZY:
(column, Column) => column_expand,
(column, Column) => line_expand,
(file, File) => file_expand,
(line, Line) => line_expand,
(module_path, ModulePath) => module_path_expand,
@ -127,11 +127,13 @@ fn line_expand(
_tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> {
// dummy implementation for type-checking purposes
let expanded = quote! {
0 as u32
};
ExpandResult::ok(expanded)
ExpandResult::ok(tt::Subtree {
delimiter: tt::Delimiter::unspecified(),
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
text: "0u32".into(),
span: tt::Span::UNSPECIFIED,
}))],
})
}
fn log_syntax_expand(
@ -164,19 +166,6 @@ fn stringify_expand(
ExpandResult::ok(expanded)
}
fn column_expand(
_db: &dyn ExpandDatabase,
_id: MacroCallId,
_tt: &tt::Subtree,
) -> ExpandResult<tt::Subtree> {
// dummy implementation for type-checking purposes
let expanded = quote! {
0 as u32
};
ExpandResult::ok(expanded)
}
fn assert_expand(
_db: &dyn ExpandDatabase,
_id: MacroCallId,

View file

@ -684,8 +684,7 @@ fn infer_builtin_macros_line() {
}
"#,
expect![[r#"
!0..1 '0': i32
!0..6 '0asu32': u32
!0..4 '0u32': u32
63..87 '{ ...!(); }': ()
73..74 'x': u32
"#]],
@ -723,8 +722,7 @@ fn infer_builtin_macros_column() {
}
"#,
expect![[r#"
!0..1 '0': i32
!0..6 '0asu32': u32
!0..4 '0u32': u32
65..91 '{ ...!(); }': ()
75..76 'x': u32
"#]],

View file

@ -380,7 +380,6 @@ impl GlobalState {
ws
})
.collect::<Vec<_>>();
// Workspaces are the same, but we've updated build data.
self.workspaces = Arc::new(workspaces);
} else {