Rustfmt removes trailing `::self` unconditionally

Đang mở
#7,138 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #7144 của @tayfuryldz — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
tooling

Hướng nghiên cứu

Start by running the supplied Rust example through rustfmt and compare the parsed use tree before and after formatting. Investigate the handling of trailing ::self in imports and add a regression test for this reproduction. Done means formatting preserves the import's behavior and the example still fails to compile as it did before formatting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A-imports A-resolve C-bug I-invalid-code S-has-mcve X-impacts-stable-default-format

Related: https://github.com/rust-lang/rustfmt/issues/3568

For the following

mod a {
    pub mod b {}

    pub fn b() {}
}

fn b() {}

use a::b::self;

which compiles successfully.

Rustfmt will format it into

mod a {
    pub mod b {}

    pub fn b() {}
}

fn b() {}

use a::b;

which compiles with fail

error[E0255]: the name `b` is defined multiple times
 --> src/lib.rs:9:5
  |
7 | fn b() {}
  | ------ previous definition of the value `b` here
8 |
9 | use a::b;
  |     ^^^^ `b` reimported here
  |
  = note: `b` must be defined only once in the value namespace of this module
help: you can use `as` to change the binding name of the import
  |
9 | use a::b as other_b;
  |          ++++++++++

Version: rustfmt 1.10.0-nightly (d453bdd8f0 2026-08-14)

Ngôn ngữ chính
Rust
Star
7.1k
Fork
1.2k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rustfmt

Tất cả issue của rust-lang/rustfmt

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.