Permit `include!(…)` in pattern position for completeness's sake
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
At the time of writing, built-in attr include is not permitted to expand into a pattern context (its expander doesn't override make_pat):
fn main() {
match () { include!("/dev/null") => {} } //~ ERROR non-pattern macro in pattern position: include
}
For nothing but "completeness" (item, expr, pat trifecta) and for consistency with include_str and include_bytes I propose that we permit them in this position.
include's expander would then parse a PatternNoTopGuard (as defined in RFC 3637), i.e., top-level or-patterns are permitted (and guards aren't – ignoring guard_patterns for now). Meaning let include!("file"); with file containing false | true would be permitted despite let false | true; not being valid (requiring parentheses) since the macro expansion would act as invisible delimiters. Leading vert / bar would be permitted as well, naturally.
Lastly, don't strip shebang or frontmatter (meaning they'll lead to an error since the pattern parser won't accept it). Edit: Well, it depends on the outcome of https://github.com/rust-lang/rust/pull/146377.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the built-in include expander and its missing make_pat handling, then review the PatternNoTopGuard requirements from RFC 3637 and the related PR #146377. Done means include! can expand in pattern position with the specified or-pattern and leading-bar behavior, while shebang/frontmatter handling follows the outcome of that PR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100