Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add message for resolution failure because wrong namespace #71419

Merged
merged 2 commits into from
Apr 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-71406.rs
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@ use std::sync::mpsc;

fn main() {
let (tx, rx) = mpsc::channel::new(1);
//~^ ERROR `channel` in `mpsc` is a concrete value, not a module or Struct you specified
//~^ ERROR expected type, found function `channel` in `mpsc`
}
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-71406.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0433]: failed to resolve: `channel` in `mpsc` is a concrete value, not a module or Struct you specified
error[E0433]: failed to resolve: expected type, found function `channel` in `mpsc`
--> $DIR/issue-71406.rs:4:26
|
LL | let (tx, rx) = mpsc::channel::new(1);
| ^^^^^^^ `channel` in `mpsc` is a concrete value, not a module or Struct you specified
| ^^^^^^^ expected type, found function `channel` in `mpsc`

error: aborting due to previous error