File tree Expand file tree Collapse file tree 2 files changed +38
-19
lines changed Expand file tree Collapse file tree 2 files changed +38
-19
lines changed Original file line number Diff line number Diff line change @@ -4895,3 +4895,26 @@ fn main() {
4895
4895
"###
4896
4896
) ;
4897
4897
}
4898
+
4899
+ #[ test]
4900
+ fn infer_builtin_macros_compile_error ( ) {
4901
+ assert_snapshot ! (
4902
+ infer( r#"
4903
+ #[rustc_builtin_macro]
4904
+ macro_rules! compile_error {
4905
+ ($msg:expr) => ({ /* compiler built-in */ });
4906
+ ($msg:expr,) => ({ /* compiler built-in */ })
4907
+ }
4908
+
4909
+ fn main() {
4910
+ compile_error!("error!");
4911
+ }
4912
+ "# ) ,
4913
+ @r###"
4914
+ ![0; 14) 'loop{"error!"}': !
4915
+ ![4; 14) '{"error!"}': &str
4916
+ ![5; 13) '"error!"': &str
4917
+ [166; 199) '{ ...!"); }': !
4918
+ "###
4919
+ ) ;
4920
+ }
Original file line number Diff line number Diff line change @@ -177,25 +177,21 @@ fn file_expand(
177
177
}
178
178
179
179
fn compile_error_expand (
180
- db : & dyn AstDatabase ,
181
- id : MacroCallId ,
182
- _tt : & tt:: Subtree ,
180
+ _db : & dyn AstDatabase ,
181
+ _id : MacroCallId ,
182
+ tt : & tt:: Subtree ,
183
183
) -> Result < tt:: Subtree , mbe:: ExpandError > {
184
- let loc = db. lookup_intern_macro ( id) ;
185
- let macro_call = loc. ast_id . to_node ( db) ;
186
-
187
- let macro_content = {
188
- // FIXME: verify that this is an ast::Literatal with kind() == LiteralKind.String, else error.
189
- let arg = macro_call. token_tree ( ) . ok_or_else ( || mbe:: ExpandError :: UnexpectedToken ) ?;
190
- let macro_args = arg. syntax ( ) . clone ( ) ;
191
- let text = macro_args. text ( ) ;
192
- let without_parens = TextUnit :: of_char ( '(' ) ..text. len ( ) - TextUnit :: of_char ( ')' ) ;
193
- text. slice ( without_parens) . to_string ( )
194
- } ;
195
-
196
- let expanded = quote ! {
197
- loop { #macro_content }
198
- } ;
184
+ if tt. count ( ) == 1 {
185
+ match & tt. token_trees [ 0 ] {
186
+ tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( it) ) => {
187
+ let s = it. text . as_str ( ) ;
188
+ if s. starts_with ( r#"""# ) && s. ends_with ( r#"""# ) {
189
+ return Ok ( quote ! { loop { #it } } ) ;
190
+ }
191
+ } ,
192
+ _ => { } ,
193
+ } ;
194
+ }
199
195
200
- Ok ( expanded )
196
+ Err ( mbe :: ExpandError :: BindingError ( "Must be a string" . into ( ) ) )
201
197
}
You can’t perform that action at this time.
0 commit comments