aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-06-27 19:02:47 +0100
committerLaurenČ›iu Nicola <[email protected]>2020-06-27 19:02:47 +0100
commitf8d37ff0b23aa84f001b728b8905fd6c3427f889 (patch)
tree9599dd143bea8ff04e683d6679182d1cee5e8dda /crates/ra_hir_expand
parent446fd3f515177d044344580c4002c7647e728119 (diff)
Add support for include_bytes
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs35
-rw-r--r--crates/ra_hir_expand/src/name.rs1
2 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 631358f41..626f9efd0 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -99,6 +99,7 @@ register_builtin! {
99 EAGER: 99 EAGER:
100 (concat, Concat) => concat_expand, 100 (concat, Concat) => concat_expand,
101 (include, Include) => include_expand, 101 (include, Include) => include_expand,
102 (include_bytes, IncludeBytes) => include_bytes_expand,
102 (include_str, IncludeStr) => include_str_expand, 103 (include_str, IncludeStr) => include_str_expand,
103 (env, Env) => env_expand, 104 (env, Env) => env_expand,
104 (option_env, OptionEnv) => option_env_expand 105 (option_env, OptionEnv) => option_env_expand
@@ -337,6 +338,24 @@ fn include_expand(
337 Ok((res, FragmentKind::Items)) 338 Ok((res, FragmentKind::Items))
338} 339}
339 340
341fn 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
340fn include_str_expand( 359fn include_str_expand(
341 db: &dyn AstDatabase, 360 db: &dyn AstDatabase,
342 arg_id: EagerMacroId, 361 arg_id: EagerMacroId,
@@ -611,4 +630,20 @@ mod tests {
611 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),])"# 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}
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs
index b475c8cc7..1b0303685 100644
--- a/crates/ra_hir_expand/src/name.rs
+++ b/crates/ra_hir_expand/src/name.rs
@@ -191,6 +191,7 @@ pub mod known {
191 stringify, 191 stringify,
192 concat, 192 concat,
193 include, 193 include,
194 include_bytes,
194 include_str, 195 include_str,
195 format_args, 196 format_args,
196 format_args_nl, 197 format_args_nl,