hir-expand: fix compile_error! expansion not unquoting strings
This commit is contained in:
parent
38fa47fd79
commit
427b63b676
@ -163,7 +163,8 @@ macro_rules! compile_error {
|
||||
}
|
||||
|
||||
// This expands to nothing (since it's in item position), but emits an error.
|
||||
compile_error!("error!");
|
||||
compile_error!("error, with an escaped quote: \"");
|
||||
compile_error!(r"this is a raw string");
|
||||
"#,
|
||||
expect![[r##"
|
||||
#[rustc_builtin_macro]
|
||||
@ -172,7 +173,8 @@ macro_rules! compile_error {
|
||||
($msg:expr,) => ({ /* compiler built-in */ })
|
||||
}
|
||||
|
||||
/* error: error! */
|
||||
/* error: error, with an escaped quote: " */
|
||||
/* error: this is a raw string */
|
||||
"##]],
|
||||
);
|
||||
}
|
||||
|
@ -379,15 +379,10 @@ fn compile_error_expand(
|
||||
tt: &tt::Subtree,
|
||||
) -> ExpandResult<ExpandedEager> {
|
||||
let err = match &*tt.token_trees {
|
||||
[tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => {
|
||||
let text = it.text.as_str();
|
||||
if text.starts_with('"') && text.ends_with('"') {
|
||||
// FIXME: does not handle raw strings
|
||||
ExpandError::Other(text[1..text.len() - 1].into())
|
||||
} else {
|
||||
ExpandError::Other("`compile_error!` argument must be a string".into())
|
||||
}
|
||||
}
|
||||
[tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => match unquote_str(it) {
|
||||
Some(unquoted) => ExpandError::Other(unquoted.into()),
|
||||
None => ExpandError::Other("`compile_error!` argument must be a string".into()),
|
||||
},
|
||||
_ => ExpandError::Other("`compile_error!` argument must be a string".into()),
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user