diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index e148118348..3d63e05195 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -103,6 +103,7 @@ register_builtin! {
(assert, Assert) => assert_expand,
(stringify, Stringify) => stringify_expand,
(format_args, FormatArgs) => format_args_expand,
+ (const_format_args, ConstFormatArgs) => 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, FormatArgsNl) => format_args_expand,
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs
index 4750d65d19..9c844c6138 100644
--- a/crates/hir_expand/src/name.rs
+++ b/crates/hir_expand/src/name.rs
@@ -211,6 +211,7 @@ pub mod known {
// Builtin macros
file,
column,
+ const_format_args,
compile_error,
line,
module_path,
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index ce24311115..b755a945cd 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -38,6 +38,9 @@ fn is_format_string(string: &ast::String) -> Option<()> {
return None;
}
+ // NB: we match against `panic_2015`/`panic_2021` here because they have a special-cased arm for
+ // `"{}"`, which otherwise wouldn't get highlighted.
+
let first_literal = parent
.children_with_tokens()
.find_map(|it| it.as_token().cloned().and_then(ast::String::cast))?;
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
index 2992755ded..1f00cba25b 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
@@ -46,10 +46,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
})
}
#[rustc_builtin_macro]
-macro_rules! format_args_nl {
- ($fmt:expr) => {{ }};
- ($fmt:expr, $($args:tt)*) => {{ }};
-}
+#[macro_export]
+macro_rules! format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! const_format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! format_args_nl {}
mod panic {
pub macro panic_2015 {
@@ -79,6 +83,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
#[rustc_builtin_macro]
macro_rules! assert {}
+macro_rules! todo {
+ () => ($crate::panic!("not yet implemented"));
+ ($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
+}
+
fn main() {
println!("Hello");
@@ -104,7 +113,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
println!("Hello {:+}!", 5);
println!("{:#x}!", 27);
println!("Hello {:05}!", 5);
- println!("Hello {:05}!", -5);
+ println!("Hello {:05}!", -5);
println!("{:#010x}!", 27);
println!("Hello {0} is {1:.5}", "x", 0.01);
println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
@@ -127,9 +136,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
println!("{\x41}", A = 92);
println!("{ничоси}", ничоси = 92);
- println!("{:x?} {} ", thingy, n2);
+ println!("{:x?} {} ", thingy, n2);
panic!("{}", 0);
panic!("more {}", 1);
assert!(true, "{}", 1);
assert!(true, "{} asdasd", 1);
+ todo!("{}fmt", 0);
}
\ No newline at end of file
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index d5018f2327..21f28cc8bd 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -441,10 +441,14 @@ macro_rules! println {
})
}
#[rustc_builtin_macro]
-macro_rules! format_args_nl {
- ($fmt:expr) => {{ /* compiler built-in */ }};
- ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
-}
+#[macro_export]
+macro_rules! format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! const_format_args {}
+#[rustc_builtin_macro]
+#[macro_export]
+macro_rules! format_args_nl {}
mod panic {
pub macro panic_2015 {
@@ -474,6 +478,11 @@ macro_rules! panic {}
#[rustc_builtin_macro]
macro_rules! assert {}
+macro_rules! todo {
+ () => ($crate::panic!("not yet implemented"));
+ ($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
+}
+
fn main() {
// from https://doc.rust-lang.org/std/fmt/index.html
println!("Hello"); // => "Hello"
@@ -527,6 +536,7 @@ fn main() {
panic!("more {}", 1);
assert!(true, "{}", 1);
assert!(true, "{} asdasd", 1);
+ todo!("{}fmt", 0);
}"#
.trim(),
expect_file!["./test_data/highlight_strings.html"],