mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add stub implementation of format_args{_nl} macros
Just enough to fix the huge amount of type mismatches they cause.
This commit is contained in:
parent
d3702c02cd
commit
c5ffb0dc81
2 changed files with 20 additions and 1 deletions
|
@ -49,7 +49,11 @@ register_builtin! {
|
|||
(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::*;
|
||||
|
|
|
@ -159,6 +159,8 @@ pub const COLUMN_MACRO: Name = Name::new_inline_ascii(6, b"column");
|
|||
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");
|
||||
|
|
Loading…
Reference in a new issue