Rustfmt removes trailing `::self` unconditionally

Abierto
#7,138 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #7144 de @tayfuryldz — cerrado sin fusionar

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)

Lenguaje dominante
Rust
Estrellas
7.1k
Forks
1.2k
Merge medio
1 d 4 h
PR fusionados (30 d)
20

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rustfmt

Todos los issues de rust-lang/rustfmt

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.