-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I noticed some weird behavior today and couldn't find any documentation on how it works. It seems that format_args!
and include_str!
can actually work together to do compile-time validation of file inputs. Like so:
let html = format_args!(include_str!("./index.html"), title="test");
Both of these are compiler builtins so their sources aren't easily accessible. However, in neither of their documentation did I see any mention of this behavior. Contrast this with a proc/decl macro that tries to parse the inners as a LitStr/literal:
macro_rules! parse_args {
($a:literal) => {};
}
fn test() {
let nodes = parse_args!(include_str!("./htmlexample.html"));
}
with error:
|
12 | macro_rules! parse_args {
| ----------------------- when calling this macro
...
17 | let nodes = parse_args!(include_str!("./htmlexample.html"));
| ^^^^^^^^^^^ no rules expected this token in macro call
Is there any documentation for this behavior? Is there any way for macro developers to also leverage this mechanic for parse a str literal returned by include_str!
?
property-x
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.