Skip to content

Commit e8c4007

Browse files
committed
Fix builtin line! expansion
1 parent 57ef70c commit e8c4007

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() { column!(); }
1717
#[rustc_builtin_macro]
1818
macro_rules! column {() => {}}
1919
20-
fn main() { 0 as u32; }
20+
fn main() { 0u32; }
2121
"#]],
2222
);
2323
}
@@ -74,7 +74,7 @@ fn main() { line!() }
7474
#[rustc_builtin_macro]
7575
macro_rules! line {() => {}}
7676
77-
fn main() { 0 as u32 }
77+
fn main() { 0u32 }
7878
"#]],
7979
);
8080
}

crates/hir-def/src/macro_expansion_tests/mbe/regression.rs

+34
Original file line numberDiff line numberDiff line change
@@ -970,3 +970,37 @@ builtin #format_args ("{}", &[0 2]);
970970
"##]],
971971
);
972972
}
973+
974+
#[test]
975+
fn eager_concat_line() {
976+
check(
977+
r#"
978+
#[rustc_builtin_macro]
979+
#[macro_export]
980+
macro_rules! concat {}
981+
982+
#[rustc_builtin_macro]
983+
#[macro_export]
984+
macro_rules! line {}
985+
986+
fn main() {
987+
concat!("event ", line!());
988+
}
989+
990+
"#,
991+
expect![[r##"
992+
#[rustc_builtin_macro]
993+
#[macro_export]
994+
macro_rules! concat {}
995+
996+
#[rustc_builtin_macro]
997+
#[macro_export]
998+
macro_rules! line {}
999+
1000+
fn main() {
1001+
"event 0u32";
1002+
}
1003+
1004+
"##]],
1005+
);
1006+
}

crates/hir-expand/src/builtin_fn_macro.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn find_builtin_macro(
7878

7979
register_builtin! {
8080
LAZY:
81-
(column, Column) => column_expand,
81+
(column, Column) => line_expand,
8282
(file, File) => file_expand,
8383
(line, Line) => line_expand,
8484
(module_path, ModulePath) => module_path_expand,
@@ -127,11 +127,13 @@ fn line_expand(
127127
_tt: &tt::Subtree,
128128
) -> ExpandResult<tt::Subtree> {
129129
// dummy implementation for type-checking purposes
130-
let expanded = quote! {
131-
0 as u32
132-
};
133-
134-
ExpandResult::ok(expanded)
130+
ExpandResult::ok(tt::Subtree {
131+
delimiter: tt::Delimiter::unspecified(),
132+
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
133+
text: "0u32".into(),
134+
span: tt::Span::UNSPECIFIED,
135+
}))],
136+
})
135137
}
136138

137139
fn log_syntax_expand(
@@ -164,19 +166,6 @@ fn stringify_expand(
164166
ExpandResult::ok(expanded)
165167
}
166168

167-
fn column_expand(
168-
_db: &dyn ExpandDatabase,
169-
_id: MacroCallId,
170-
_tt: &tt::Subtree,
171-
) -> ExpandResult<tt::Subtree> {
172-
// dummy implementation for type-checking purposes
173-
let expanded = quote! {
174-
0 as u32
175-
};
176-
177-
ExpandResult::ok(expanded)
178-
}
179-
180169
fn assert_expand(
181170
_db: &dyn ExpandDatabase,
182171
_id: MacroCallId,

crates/hir-ty/src/tests/macros.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ fn infer_builtin_macros_line() {
684684
}
685685
"#,
686686
expect![[r#"
687-
!0..1 '0': i32
688-
!0..6 '0asu32': u32
687+
!0..4 '0u32': u32
689688
63..87 '{ ...!(); }': ()
690689
73..74 'x': u32
691690
"#]],
@@ -723,8 +722,7 @@ fn infer_builtin_macros_column() {
723722
}
724723
"#,
725724
expect![[r#"
726-
!0..1 '0': i32
727-
!0..6 '0asu32': u32
725+
!0..4 '0u32': u32
728726
65..91 '{ ...!(); }': ()
729727
75..76 'x': u32
730728
"#]],

crates/rust-analyzer/src/reload.rs

-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ impl GlobalState {
380380
ws
381381
})
382382
.collect::<Vec<_>>();
383-
384383
// Workspaces are the same, but we've updated build data.
385384
self.workspaces = Arc::new(workspaces);
386385
} else {

0 commit comments

Comments
 (0)