Skip to content

Commit 427b63b

Browse files
committed
hir-expand: fix compile_error! expansion not unquoting strings
1 parent 38fa47f commit 427b63b

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ macro_rules! compile_error {
163163
}
164164
165165
// This expands to nothing (since it's in item position), but emits an error.
166-
compile_error!("error!");
166+
compile_error!("error, with an escaped quote: \"");
167+
compile_error!(r"this is a raw string");
167168
"#,
168169
expect![[r##"
169170
#[rustc_builtin_macro]
@@ -172,7 +173,8 @@ macro_rules! compile_error {
172173
($msg:expr,) => ({ /* compiler built-in */ })
173174
}
174175
175-
/* error: error! */
176+
/* error: error, with an escaped quote: " */
177+
/* error: this is a raw string */
176178
"##]],
177179
);
178180
}

crates/hir-expand/src/builtin_fn_macro.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,10 @@ fn compile_error_expand(
379379
tt: &tt::Subtree,
380380
) -> ExpandResult<ExpandedEager> {
381381
let err = match &*tt.token_trees {
382-
[tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => {
383-
let text = it.text.as_str();
384-
if text.starts_with('"') && text.ends_with('"') {
385-
// FIXME: does not handle raw strings
386-
ExpandError::Other(text[1..text.len() - 1].into())
387-
} else {
388-
ExpandError::Other("`compile_error!` argument must be a string".into())
389-
}
390-
}
382+
[tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => match unquote_str(it) {
383+
Some(unquoted) => ExpandError::Other(unquoted.into()),
384+
None => ExpandError::Other("`compile_error!` argument must be a string".into()),
385+
},
391386
_ => ExpandError::Other("`compile_error!` argument must be a string".into()),
392387
};
393388

0 commit comments

Comments
 (0)