about summary refs log tree commit diff
path: root/src/librustc_resolve
diff options
context:
space:
mode:
authorYI <uuuuuu@protonmail.com>2020-04-26 10:28:33 +0800
committerYI <uuuuuu@protonmail.com>2020-04-26 10:28:33 +0800
commiteb8a7031ef1ecd9b44a929f0b93f0e41c78fda25 (patch)
tree2c3342d656f4bf6a396d373465a6446c6da0a63e /src/librustc_resolve
parentbb1eedb026931853e2f37e752c45b7f3b59c5fa6 (diff)
downloadrust-eb8a7031ef1ecd9b44a929f0b93f0e41c78fda25.tar.gz
rust-eb8a7031ef1ecd9b44a929f0b93f0e41c78fda25.zip
use defkind.descr in wrong namespace resolve failure
Diffstat (limited to 'src/librustc_resolve')
-rw-r--r--src/librustc_resolve/lib.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 71fb8147793..2d53b7553a1 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -2213,25 +2213,28 @@ impl<'a> Resolver<'a> {
                     } else {
                         let mut msg =
                             format!("could not find `{}` in `{}`", ident, path[i - 1].ident);
-                        if ns == TypeNS {
-                            if let FindBindingResult::Binding(Ok(_)) =
-                                find_binding_in_ns(self, ValueNS)
+                        if ns == TypeNS || ns == ValueNS {
+                            let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
+                            if let FindBindingResult::Binding(Ok(binding)) =
+                                find_binding_in_ns(self, ns_to_try)
                             {
-                                msg = format!(
-                                    "`{}` in `{}` is a concrete value, not a module or Struct you specified",
-                                    ident,
-                                    path[i - 1].ident
-                                );
-                            };
-                        } else if ns == ValueNS {
-                            if let FindBindingResult::Binding(Ok(_)) =
-                                find_binding_in_ns(self, TypeNS)
-                            {
-                                msg = format!(
-                                    "`{}` in `{}` is a type, not a concrete value you specified",
-                                    ident,
-                                    path[i - 1].ident
-                                );
+                                let mut found = |what| {
+                                    msg = format!(
+                                        "expected {}, found {} `{}` in `{}`",
+                                        ns.descr(),
+                                        what,
+                                        ident,
+                                        path[i - 1].ident
+                                    )
+                                };
+                                if binding.module().is_some() {
+                                    found("module")
+                                } else {
+                                    match binding.res() {
+                                        def::Res::<NodeId>::Def(kind, id) => found(kind.descr(id)),
+                                        _ => found(ns_to_try.descr()),
+                                    }
+                                }
                             };
                         }
                         (msg, None)