rust-lang / rust-lang/rustfmt

Feature request: path prefix remapping

Open
#4,341 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

rustfmt can emit diagnostics (eg syntax errors), but has no way to normalize the source filenames.

rustc has a --remap-path-prefix option so that all places where source file names are emitted (diagnostics, debug info, etc) can be normalized by, for example, removing an absolute path of a build directory.

It would be nice if rustfmt also implemented this option so the same kinds of remapping can be performed on its diagnostics.

To Reproduce

$ cat t.rs
fn main() {{}
$ rustfmt t.rs
error: this file contains an unclosed delimiter
 --> /home/jsgf/t.rs:1:15
  |
1 | fn main() {{}
  |           -   ^
  |           |
  |           unclosed delimiter

rustfmt shows the full path - not the path passed to it, and has no option for remapping this.

Expected behavior

rustfmt --remap-path-prefix /home/jsgf/= t.rs would show just t.rs:1:15 as the error path.

Meta

  • rustfmt version: rustfmt 1.4.15-stable (530eadf 2020-06-02)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: rustfmt

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 at the rustfmt command-line entry point and trace how diagnostic source filenames are produced for the t.rs reproducer. Determine where a --remap-path-prefix option would be parsed and applied, then verify that the example reports t.rs:1:15 instead of the absolute path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.