rust-lang / rust-lang/rust

[proc-macro] Add possibility to generate a `Span` from a path representation

Open
#140,943 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-proc-macros C-feature-request T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently, we cannot handle Span when using the proc-macro crate, which is problematic in many cases, like askama when the generated code triggers an error and we can't show the users where in their templates the error originates from.

So an idea I had was to provide a method looking like this:

struct FileLocation {
    line: u32,
    column: u32,
}

fn span_from_representation(file: &Path, beginning: FileLocation, end: Option<FileLocation>) -> Option<Span>;

It would allow to get the span we need without having to manipulate the Span content (which is not possible outside of the compiler anyway).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing proc-macro Span handling and the proposed span_from_representation signature in the issue. Done means providing a way to derive an Option from a path and beginning/end file locations so generated errors can point to their source templates; no files or tests are identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.