]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_resolve/lib.rs
resolve: Suggest `crate::` for resolving ambiguities when appropriate
[rust.git] / src / librustc_resolve / lib.rs
index 0be9881f910b78f0fede1bfcbefe59583ebed486..cbf82a80266678f72d33557103e7ab90de619c92 100644 (file)
@@ -1292,6 +1292,7 @@ fn descr(self) -> &'static str {
 /// Miscellaneous bits of metadata for better ambiguity error reporting.
 #[derive(Clone, Copy, PartialEq)]
 enum AmbiguityErrorMisc {
+    SuggestCrate,
     SuggestSelf,
     FromPrelude,
     None,
@@ -4870,12 +4871,21 @@ fn report_ambiguity_error(&self, ambiguity_error: &AmbiguityError) {
                                         `{ident}` to disambiguate", ident = ident))
             }
             if b.is_extern_crate() && ident.span.rust_2018() {
-                help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously",
-                                       ident = ident, thing = b.descr()))
-            }
-            if misc == AmbiguityErrorMisc::SuggestSelf {
-                help_msgs.push(format!("use `self::{ident}` to refer to this {thing} unambiguously",
-                                       ident = ident, thing = b.descr()))
+                help_msgs.push(format!(
+                    "use `::{ident}` to refer to this {thing} unambiguously",
+                    ident = ident, thing = b.descr(),
+                ))
+            }
+            if misc == AmbiguityErrorMisc::SuggestCrate {
+                help_msgs.push(format!(
+                    "use `crate::{ident}` to refer to this {thing} unambiguously",
+                    ident = ident, thing = b.descr(),
+                ))
+            } else if misc == AmbiguityErrorMisc::SuggestSelf {
+                help_msgs.push(format!(
+                    "use `self::{ident}` to refer to this {thing} unambiguously",
+                    ident = ident, thing = b.descr(),
+                ))
             }
 
             if b.span.is_dummy() {