diff options
author | Florian Diebold <[email protected]> | 2019-12-06 09:57:20 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-12-06 20:25:22 +0000 |
commit | c5ffb0dc815358712a42f9358cc3538f9a7b3014 (patch) | |
tree | ae149235b0b42137cef966a141d1d23b5ccfe1c0 /crates/ra_hir_expand/src/builtin_macro.rs | |
parent | d3702c02cdff158f05d2af1bd7106cca8a3e4ba9 (diff) |
Add stub implementation of format_args{_nl} macros
Just enough to fix the huge amount of type mismatches they cause.
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_macro.rs')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 35f99b2bc..e0709704a 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -49,7 +49,11 @@ register_builtin! { | |||
49 | (COMPILE_ERROR_MACRO, CompileError) => compile_error_expand, | 49 | (COMPILE_ERROR_MACRO, CompileError) => compile_error_expand, |
50 | (FILE_MACRO, File) => file_expand, | 50 | (FILE_MACRO, File) => file_expand, |
51 | (LINE_MACRO, Line) => line_expand, | 51 | (LINE_MACRO, Line) => line_expand, |
52 | (STRINGIFY_MACRO, Stringify) => stringify_expand | 52 | (STRINGIFY_MACRO, Stringify) => stringify_expand, |
53 | (FORMAT_ARGS_MACRO, FormatArgs) => format_args_expand, | ||
54 | // format_args_nl only differs in that it adds a newline in the end, | ||
55 | // so we use the same stub expansion for now | ||
56 | (FORMAT_ARGS_NL_MACRO, FormatArgsNl) => format_args_expand | ||
53 | } | 57 | } |
54 | 58 | ||
55 | fn to_line_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { | 59 | fn to_line_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { |
@@ -200,6 +204,19 @@ fn compile_error_expand( | |||
200 | Err(mbe::ExpandError::BindingError("Must be a string".into())) | 204 | Err(mbe::ExpandError::BindingError("Must be a string".into())) |
201 | } | 205 | } |
202 | 206 | ||
207 | fn format_args_expand( | ||
208 | _db: &dyn AstDatabase, | ||
209 | _id: MacroCallId, | ||
210 | _tt: &tt::Subtree, | ||
211 | ) -> Result<tt::Subtree, mbe::ExpandError> { | ||
212 | // FIXME this is just a stub to make format macros type-check without mismatches | ||
213 | // We should make this at least insert the arguments, so that go to def etc. work within format macros | ||
214 | let expanded = quote! { | ||
215 | std::fmt::Arguments::new_v1(&[], &[]) | ||
216 | }; | ||
217 | Ok(expanded) | ||
218 | } | ||
219 | |||
203 | #[cfg(test)] | 220 | #[cfg(test)] |
204 | mod tests { | 221 | mod tests { |
205 | use super::*; | 222 | use super::*; |