Skip to content

Permit include!(…) in pattern position for completeness's sake #146372

@fmease

Description

@fmease

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 #146377.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-patternsRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-lang-nominatedNominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.P-lang-drag-1Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-langP-lowLow priorityT-langRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions