mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Add support for include_bytes
This commit is contained in:
parent
446fd3f515
commit
f8d37ff0b2
2 changed files with 36 additions and 0 deletions
|
@ -99,6 +99,7 @@ register_builtin! {
|
||||||
EAGER:
|
EAGER:
|
||||||
(concat, Concat) => concat_expand,
|
(concat, Concat) => concat_expand,
|
||||||
(include, Include) => include_expand,
|
(include, Include) => include_expand,
|
||||||
|
(include_bytes, IncludeBytes) => include_bytes_expand,
|
||||||
(include_str, IncludeStr) => include_str_expand,
|
(include_str, IncludeStr) => include_str_expand,
|
||||||
(env, Env) => env_expand,
|
(env, Env) => env_expand,
|
||||||
(option_env, OptionEnv) => option_env_expand
|
(option_env, OptionEnv) => option_env_expand
|
||||||
|
@ -337,6 +338,24 @@ fn include_expand(
|
||||||
Ok((res, FragmentKind::Items))
|
Ok((res, FragmentKind::Items))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn include_bytes_expand(
|
||||||
|
_db: &dyn AstDatabase,
|
||||||
|
_arg_id: EagerMacroId,
|
||||||
|
tt: &tt::Subtree,
|
||||||
|
) -> Result<(tt::Subtree, FragmentKind), mbe::ExpandError> {
|
||||||
|
let _path = parse_string(tt)?;
|
||||||
|
|
||||||
|
// FIXME: actually read the file here if the user asked for macro expansion
|
||||||
|
let res = tt::Subtree {
|
||||||
|
delimiter: None,
|
||||||
|
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
|
||||||
|
text: r#"b"""#.into(),
|
||||||
|
id: tt::TokenId::unspecified(),
|
||||||
|
}))],
|
||||||
|
};
|
||||||
|
Ok((res, FragmentKind::Expr))
|
||||||
|
}
|
||||||
|
|
||||||
fn include_str_expand(
|
fn include_str_expand(
|
||||||
db: &dyn AstDatabase,
|
db: &dyn AstDatabase,
|
||||||
arg_id: EagerMacroId,
|
arg_id: EagerMacroId,
|
||||||
|
@ -611,4 +630,20 @@ mod tests {
|
||||||
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),])"#
|
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),])"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_include_bytes_expand() {
|
||||||
|
let expanded = expand_builtin_macro(
|
||||||
|
r#"
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! include_bytes {
|
||||||
|
($file:expr) => {{ /* compiler built-in */ }};
|
||||||
|
($file:expr,) => {{ /* compiler built-in */ }};
|
||||||
|
}
|
||||||
|
include_bytes("foo");
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(expanded, r#"b"""#);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,7 @@ pub mod known {
|
||||||
stringify,
|
stringify,
|
||||||
concat,
|
concat,
|
||||||
include,
|
include,
|
||||||
|
include_bytes,
|
||||||
include_str,
|
include_str,
|
||||||
format_args,
|
format_args,
|
||||||
format_args_nl,
|
format_args_nl,
|
||||||
|
|
Loading…
Reference in a new issue