Skip to content

Naming of proc_macro::Span::local_file() #139903

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
m-ou-se opened this issue Apr 16, 2025 · 5 comments
Closed

Naming of proc_macro::Span::local_file() #139903

m-ou-se opened this issue Apr 16, 2025 · 5 comments
Assignees
Labels
A-proc-macros Area: Procedural macros C-discussion Category: Discussion or questions that doesn't represent real issues. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Apr 16, 2025

This is about #54725's open question on the name of local_file:

The unstable API is now:

impl Span {
    /// The path to the source file in which this span occurs, for display purposes.
    ///
    /// This might not correspond to a valid file system path.
    /// 
    /// It might be remapped (e.g. `/src/lib.rs`) , or might be an artificial path (e.g. `"<command line>"`).
    pub fn file(&self) -> String;

    /// The path to the source file in which this span occurs on the local file system.
    ///
    /// This is unaffected by path remapping.
    ///
    /// This path should not be embedded in the output of the macro; prefer `file()` instead.
    pub fn local_file(&self) -> Option<PathBuf>;
}

The question is: What should we name local_file?

Keeping it as local_file is an option, but maybe we can think of something better.

@m-ou-se m-ou-se added A-proc-macros Area: Procedural macros C-discussion Category: Discussion or questions that doesn't represent real issues. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 16, 2025
@m-ou-se m-ou-se self-assigned this Apr 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Apr 16, 2025

FWIW, rustc internally uses "LocalPath" for this:

local_path: Option<PathBuf>,

@m-ou-se m-ou-se removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Apr 16, 2025

I personally think local_file is good enough.

@m-ou-se
Copy link
Member Author

m-ou-se commented Apr 17, 2025

@rust-lang/libs-api If you have an opinion/ideas, please speak up!

@BurntSushi
Copy link
Member

I weakly prefer path/local_path, but I don't feel strongly.

@m-ou-se m-ou-se added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Apr 22, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented Apr 30, 2025

We discussed this last week in the libs-api meeting. We didn't have any better ideas than local_file.

I'll make a PR to stabilize it under that name and propose an FCP.

@m-ou-se m-ou-se closed this as completed Apr 30, 2025
bors added a commit to rust-lang-ci/rust that referenced this issue May 6, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang#139903
bors added a commit to rust-lang-ci/rust that referenced this issue May 6, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang#139903
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue May 8, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang/rust#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang/rust#139903
Syndelis added a commit to Syndelis/list-files-macro-rs that referenced this issue May 10, 2025
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 10, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang/rust#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang/rust#139903
github-actions bot pushed a commit to carolynzech/rust that referenced this issue May 16, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang#139903
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue May 20, 2025
Stabilize proc_macro::Span::{file, local_file}.

Stabilizes this part of rust-lang/rust#54725:

```rust
impl Span {
    pub fn file(&self) -> String; // Mapped/artificial file name, for display purposes.

    pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on the local file system.
}
```

See also the naming discussion in rust-lang/rust#139903
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-proc-macros Area: Procedural macros C-discussion Category: Discussion or questions that doesn't represent real issues. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants