about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-21 04:19:03 +0000
committerbors <bors@rust-lang.org>2023-01-21 04:19:03 +0000
commite098eb17e1514bcd604ac4bd57cec362944687af (patch)
tree5ed9ca15b097af81778b76c4e6167b633ead064d /compiler/rustc_resolve/src
parent0726909f6d219951ba15ac2f65656eff96bb1867 (diff)
parent34d4df5bd5e6efccbcf7b191ac5c7ed2e8ae67cd (diff)
downloadrust-e098eb17e1514bcd604ac4bd57cec362944687af.tar.gz
rust-e098eb17e1514bcd604ac4bd57cec362944687af.zip
Auto merge of #107143 - compiler-errors:rollup-zabvmo5, r=compiler-errors
Rollup of 9 pull requests

Successful merges:

 - #104154 (Change `bindings_with_variant_name` to deny-by-default)
 - #104347 (diagnostics: suggest changing `s@self::{macro}`@::macro`` for exported)
 - #104672 (Unify stable and unstable sort implementations in same core module)
 - #107048 (check for x version updates)
 - #107061 (Implement some more new solver candidates and fix some bugs)
 - #107095 (rustdoc: remove redundant CSS selector `.sidebar .current`)
 - #107112 (Fix typo in opaque_types.rs)
 - #107124 (fix check macro expansion)
 - #107131 (rustdoc: use CSS inline layout for radio line instead of flexbox)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index f24e405018b..8d104aa5cc5 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -2125,9 +2125,15 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
 
                 let source_map = self.r.session.source_map();
 
+                // Make sure this is actually crate-relative.
+                let is_definitely_crate = import
+                    .module_path
+                    .first()
+                    .map_or(false, |f| f.ident.name != kw::SelfLower && f.ident.name != kw::Super);
+
                 // Add the import to the start, with a `{` if required.
                 let start_point = source_map.start_point(after_crate_name);
-                if let Ok(start_snippet) = source_map.span_to_snippet(start_point) {
+                if is_definitely_crate && let Ok(start_snippet) = source_map.span_to_snippet(start_point) {
                     corrections.push((
                         start_point,
                         if has_nested {
@@ -2139,11 +2145,17 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
                             format!("{{{}, {}", import_snippet, start_snippet)
                         },
                     ));
-                }
 
-                // Add a `};` to the end if nested, matching the `{` added at the start.
-                if !has_nested {
-                    corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
+                    // Add a `};` to the end if nested, matching the `{` added at the start.
+                    if !has_nested {
+                        corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
+                    }
+                } else {
+                    // If the root import is module-relative, add the import separately
+                    corrections.push((
+                        import.use_span.shrink_to_lo(),
+                        format!("use {module_name}::{import_snippet};\n"),
+                    ));
                 }
             }