Skip to content

Tracking issue for proc_macro::Span inspection APIs #54725

Description

@alexcrichton

View all comments

This issue is intended to track a number of unstable APIs which are used to inspect the contents of a Span for information like the file name, byte position, manufacturing new spans, combining them, etc.

This issue tracks the proc_macro_span unstable feature.

Public API

Already stabilized:

impl Span {
    // as `proc_macro_source_text`
    pub fn source_text(&self) -> Option<String>;

    // as `proc_macro_span_location`
    pub fn start(&self) -> Span;
    pub fn end(&self) -> Span;
    pub fn line(&self) -> usize;
    pub fn column(&self) -> usize;

    // as `proc_macro_span_file`
    pub fn file(&self) -> String; // Mapped file name, for display purposes.
    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on disk.
}

impl Group {
    // as `proc_macro_group_span`
    pub fn span_open(&self) -> Span;
    pub fn span_close(&self) -> Span;
}

Close to stabilization, pending some bikeshedding:

impl Span {
    pub fn byte_range(&self) -> Range<usize>;
    // Open question: Do we want to use the old or new Range type?
}

Things that require more discussion:

impl Span {
    pub fn eq(&self, other: &Span) -> bool;
    pub fn join(&self, other: Span) -> Option<Span>;
    pub fn parent(&self) -> Option<Span>;
    pub fn source(&self) -> Span;
}

impl Literal {
    pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span>;
}

History:

Unresolved questions

  • API returning ranges should use the new Range type, or impl RangeBounds

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.S-tracking-design-concernsStatus: There are blocking design concerns.T-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions