@@ -99,6 +99,7 @@ register_builtin! {
99
99
EAGER :
100
100
( concat, Concat ) => concat_expand,
101
101
( include, Include ) => include_expand,
102
+ ( include_bytes, IncludeBytes ) => include_bytes_expand,
102
103
( include_str, IncludeStr ) => include_str_expand,
103
104
( env, Env ) => env_expand,
104
105
( option_env, OptionEnv ) => option_env_expand
@@ -337,6 +338,24 @@ fn include_expand(
337
338
Ok ( ( res, FragmentKind :: Items ) )
338
339
}
339
340
341
+ fn include_bytes_expand (
342
+ _db : & dyn AstDatabase ,
343
+ _arg_id : EagerMacroId ,
344
+ tt : & tt:: Subtree ,
345
+ ) -> Result < ( tt:: Subtree , FragmentKind ) , mbe:: ExpandError > {
346
+ let _path = parse_string ( tt) ?;
347
+
348
+ // FIXME: actually read the file here if the user asked for macro expansion
349
+ let res = tt:: Subtree {
350
+ delimiter : None ,
351
+ token_trees : vec ! [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( tt:: Literal {
352
+ text: r#"b"""# . into( ) ,
353
+ id: tt:: TokenId :: unspecified( ) ,
354
+ } ) ) ] ,
355
+ } ;
356
+ Ok ( ( res, FragmentKind :: Expr ) )
357
+ }
358
+
340
359
fn include_str_expand (
341
360
db : & dyn AstDatabase ,
342
361
arg_id : EagerMacroId ,
@@ -611,4 +630,20 @@ mod tests {
611
630
r#"std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(arg1(a,b,c)),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(arg2),std::fmt::Display::fmt),])"#
612
631
) ;
613
632
}
633
+
634
+ #[ test]
635
+ fn test_include_bytes_expand ( ) {
636
+ let expanded = expand_builtin_macro (
637
+ r#"
638
+ #[rustc_builtin_macro]
639
+ macro_rules! include_bytes {
640
+ ($file:expr) => {{ /* compiler built-in */ }};
641
+ ($file:expr,) => {{ /* compiler built-in */ }};
642
+ }
643
+ include_bytes("foo");
644
+ "# ,
645
+ ) ;
646
+
647
+ assert_eq ! ( expanded, r#"b"""# ) ;
648
+ }
614
649
}
0 commit comments