This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed
hir-def/src/macro_expansion_tests Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments