mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
auto merge of #6443 : cmr/rust/resolution, r=bstrie
When trying to import nonexistent items from existing modules, specify that
that is what happened, rather than just reporting "unresolved name".
Ideally the error would be reported on the span of the import... but I do not see a way to get a span there. Help appreciated 😄
This commit is contained in:
@@ -2282,17 +2282,19 @@ fn get_binding(import_resolution:
|
||||
}
|
||||
|
||||
let i = import_resolution;
|
||||
let mut resolve_fail = false;
|
||||
let mut priv_fail = false;
|
||||
match (i.value_target, i.type_target) {
|
||||
// If this name wasn't found in either namespace, it's definitely
|
||||
// unresolved.
|
||||
(None, None) => { return Failed; }
|
||||
(None, None) => { resolve_fail = true; }
|
||||
// If it's private, it's also unresolved.
|
||||
(Some(t), None) | (None, Some(t)) => {
|
||||
let bindings = &mut *t.bindings;
|
||||
match bindings.type_def {
|
||||
Some(ref type_def) => {
|
||||
if type_def.privacy == Private {
|
||||
return Failed;
|
||||
priv_fail = true;
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
@@ -2300,7 +2302,7 @@ fn get_binding(import_resolution:
|
||||
match bindings.value_def {
|
||||
Some(ref value_def) => {
|
||||
if value_def.privacy == Private {
|
||||
return Failed;
|
||||
priv_fail = true;
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
@@ -2313,13 +2315,25 @@ fn get_binding(import_resolution:
|
||||
(Some(ref value_def), Some(ref type_def)) =>
|
||||
if value_def.privacy == Private
|
||||
&& type_def.privacy == Private {
|
||||
return Failed;
|
||||
priv_fail = true;
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if resolve_fail {
|
||||
self.session.err(fmt!("unresolved import: there is no `%s` in `%s`",
|
||||
*self.session.str_of(source),
|
||||
self.module_to_str(containing_module)));
|
||||
return Failed;
|
||||
} else if priv_fail {
|
||||
self.session.err(fmt!("unresolved import: found `%s` in `%s` but it is private",
|
||||
*self.session.str_of(source),
|
||||
self.module_to_str(containing_module)));
|
||||
return Failed;
|
||||
}
|
||||
|
||||
assert!(import_resolution.outstanding_references >= 1);
|
||||
import_resolution.outstanding_references -= 1;
|
||||
|
||||
@@ -2491,7 +2505,8 @@ fn resolve_module_path_from_root(@mut self,
|
||||
*segment_name));
|
||||
return Failed;
|
||||
}
|
||||
self.session.span_err(span, ~"unresolved name");
|
||||
self.session.span_err(span, fmt!("unresolved import: could not find `%s` in \
|
||||
`%s`.", *segment_name, module_name));
|
||||
return Failed;
|
||||
}
|
||||
Indeterminate => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use baz::zed::bar; //~ ERROR unresolved name
|
||||
use baz::zed::bar; //~ ERROR unresolved import
|
||||
//~^ ERROR failed to resolve import
|
||||
|
||||
mod baz {}
|
||||
|
||||
Reference in New Issue
Block a user