diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index 5bbadb0f45..ce24311115 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -31,14 +31,16 @@ fn is_format_string(string: &ast::String) -> Option<()> {
let parent = string.syntax().parent()?;
let name = parent.parent().and_then(ast::MacroCall::cast)?.path()?.segment()?.name_ref()?;
- if !matches!(name.text().as_str(), "format_args" | "format_args_nl") {
+ if !matches!(
+ name.text().as_str(),
+ "format_args" | "format_args_nl" | "const_format_args" | "panic_2015" | "panic_2021"
+ ) {
return None;
}
let first_literal = parent
.children_with_tokens()
- .filter_map(|it| it.as_token().cloned().and_then(ast::String::cast))
- .next()?;
+ .find_map(|it| it.as_token().cloned().and_then(ast::String::cast))?;
if &first_literal != string {
return None;
}
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 9c20c8ae4b..d0ad7945a7 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
@@ -51,6 +51,31 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
($fmt:expr, $($args:tt)*) => {{ }};
}
+mod panic {
+ pub macro panic_2015 {
+ () => (
+ $crate::panicking::panic("explicit panic")
+ ),
+ ($msg:literal $(,)?) => (
+ $crate::panicking::panic($msg)
+ ),
+
+ ($msg:expr $(,)?) => (
+ $crate::panicking::panic_str($msg)
+ ),
+
+ ("{}", $arg:expr $(,)?) => (
+ $crate::panicking::panic_display(&$arg)
+ ),
+ ($fmt:expr, $($arg:tt)+) => (
+ $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
+ ),
+ }
+}
+
+#[rustc_builtin_macro(std_panic)]
+macro_rules! panic {}
+
fn main() {
println!("Hello");
@@ -100,4 +125,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
println!("{ничоси}", ничоси = 92);
println!("{:x?} {} ", thingy, n2);
+ panic!("{}", 0);
+ panic!("more {}", 1);
}
\ 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 9fc730e007..91d29a96bf 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -446,6 +446,31 @@ macro_rules! format_args_nl {
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
}
+mod panic {
+ pub macro panic_2015 {
+ () => (
+ $crate::panicking::panic("explicit panic")
+ ),
+ ($msg:literal $(,)?) => (
+ $crate::panicking::panic($msg)
+ ),
+ // Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
+ ($msg:expr $(,)?) => (
+ $crate::panicking::panic_str($msg)
+ ),
+ // Special-case the single-argument case for const_panic.
+ ("{}", $arg:expr $(,)?) => (
+ $crate::panicking::panic_display(&$arg)
+ ),
+ ($fmt:expr, $($arg:tt)+) => (
+ $crate::panicking::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
+ ),
+ }
+}
+
+#[rustc_builtin_macro(std_panic)]
+macro_rules! panic {}
+
fn main() {
// from https://doc.rust-lang.org/std/fmt/index.html
println!("Hello"); // => "Hello"
@@ -495,6 +520,8 @@ fn main() {
println!("{ничоси}", ничоси = 92);
println!("{:x?} {} ", thingy, n2);
+ panic!("{}", 0);
+ panic!("more {}", 1);
}"#
.trim(),
expect_file!["./test_data/highlight_strings.html"],