Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a2bfc02

Browse files
committed
keep leading double-colon to respect the 2018 edition of rust's paths
1 parent 78d4fca commit a2bfc02

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/imports.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ impl UseTree {
324324
attrs,
325325
};
326326

327-
let leading_modsep = context.config.edition() == Edition::Edition2018
328-
&& a.prefix.to_string().len() > 2
329-
&& a.prefix.to_string().starts_with("::");
327+
let leading_modsep =
328+
context.config.edition() == Edition::Edition2018 && a.prefix.is_global();
330329

331330
let mut modsep = leading_modsep;
332331

@@ -367,7 +366,15 @@ impl UseTree {
367366
));
368367
}
369368
UseTreeKind::Simple(ref rename, ..) => {
370-
let name = rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned();
369+
// If the path has leading double colons and is composed of only 2 segments, then we
370+
// bypass the call to path_to_imported_ident which would get only the ident and
371+
// lose the path root, e.g., `that` in `::that`.
372+
// The span of `a.prefix` contains the leading colons.
373+
let name = if a.prefix.segments.len() == 2 && leading_modsep {
374+
context.snippet(a.prefix.span).to_owned()
375+
} else {
376+
rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned()
377+
};
371378
let alias = rename.and_then(|ident| {
372379
if ident.name == "_" {
373380
// for impl-only-use

0 commit comments

Comments
 (0)