]> git.lizzy.rs Git - rust.git/commitdiff
Add stub implementation of format_args{_nl} macros
authorFlorian Diebold <flodiebold@gmail.com>
Fri, 6 Dec 2019 09:57:20 +0000 (10:57 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Fri, 6 Dec 2019 20:25:22 +0000 (21:25 +0100)
Just enough to fix the huge amount of type mismatches they cause.

crates/ra_hir_expand/src/builtin_macro.rs
crates/ra_hir_expand/src/name.rs

index 35f99b2bc4cfca408ed3dbb006c89128ed90d4c3..e0709704a03914cd76a5edc64d27b2f5e2f7607f 100644 (file)
@@ -49,7 +49,11 @@ pub fn find_builtin_macro(
     (COMPILE_ERROR_MACRO, CompileError) => compile_error_expand,
     (FILE_MACRO, File) => file_expand,
     (LINE_MACRO, Line) => line_expand,
-    (STRINGIFY_MACRO, Stringify) => stringify_expand
+    (STRINGIFY_MACRO, Stringify) => stringify_expand,
+    (FORMAT_ARGS_MACRO, FormatArgs) => format_args_expand,
+    // format_args_nl only differs in that it adds a newline in the end,
+    // so we use the same stub expansion for now
+    (FORMAT_ARGS_NL_MACRO, FormatArgsNl) => format_args_expand
 }
 
 fn to_line_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize {
@@ -200,6 +204,19 @@ fn compile_error_expand(
     Err(mbe::ExpandError::BindingError("Must be a string".into()))
 }
 
+fn format_args_expand(
+    _db: &dyn AstDatabase,
+    _id: MacroCallId,
+    _tt: &tt::Subtree,
+) -> Result<tt::Subtree, mbe::ExpandError> {
+    // FIXME this is just a stub to make format macros type-check without mismatches
+    // We should make this at least insert the arguments, so that go to def etc. work within format macros
+    let expanded = quote! {
+        std::fmt::Arguments::new_v1(&[], &[])
+    };
+    Ok(expanded)
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
index c5a19116093ba7d9b520b756a8230c7f3807a5b0..34edf2003a48198de041b80cf983b05c77d9b66d 100644 (file)
@@ -159,6 +159,8 @@ fn as_name(&self) -> Name {
 pub const COMPILE_ERROR_MACRO: Name = Name::new_inline_ascii(13, b"compile_error");
 pub const LINE_MACRO: Name = Name::new_inline_ascii(4, b"line");
 pub const STRINGIFY_MACRO: Name = Name::new_inline_ascii(9, b"stringify");
+pub const FORMAT_ARGS_MACRO: Name = Name::new_inline_ascii(11, b"format_args");
+pub const FORMAT_ARGS_NL_MACRO: Name = Name::new_inline_ascii(14, b"format_args_nl");
 
 // Builtin derives
 pub const COPY_TRAIT: Name = Name::new_inline_ascii(4, b"Copy");