Skip to content

Tracking Issue for proc_macro_expand #90765

Open
@mystor

Description

@mystor

Feature gate: #![feature(proc_macro_expand)]

This is a tracking issue for the TokenStream::expand_expr function for use in proc-macros. This function allows eagerly expanding TokenStreams containing expressions from within a proc-macro, such that they can be modified, giving proc-macros similar functionality to built-in macros like format_args!, concat! and include!.

Public API

impl TokenStream {
    pub fn expand_expr(&self) -> Result<TokenStream, ExpandError>;
}

#[non_exhaustive]
pub struct ExpandError;

impl Debug for ExpandError { ... }
impl Display for ExpandError { ... }
impl Error for ExpandError {}
impl !Send for ExpandError {}
impl !Sync for ExpandError {}

Steps / History

Unresolved Questions

  • What types of expressions beyond literals should be supported?
  • Should expanding non-expression macros (e.g. types, items, etc.) be supported?
  • Should certain macros (e.g. those with #[allow_internal_unstable]) be expandable or left unexpanded?
  • How can we evolve which macros are expanded or not within the rustc stability model? Can downstream crates opt-in to additional macro expansion on nightly channels? Should an additional argument be provided to customize what should be expanded?
  • Should compilation be allowed to proceed after an expand method errors?
  • Are there concerns about stabilizing the span information generated by internal macros like include!?
  • How can we properly preserve span information when expanding expression macros?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-proc-macrosArea: Procedural macrosC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.WG-macrosWorking group: Macros

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions