Skip to content

Commit 935b7ba

Browse files
committed
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 😄
2 parents 1bf2f68 + 2210d2d commit 935b7ba

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/librustc/middle/resolve.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -2282,25 +2282,27 @@ pub impl Resolver {
22822282
}
22832283
22842284
let i = import_resolution;
2285+
let mut resolve_fail = false;
2286+
let mut priv_fail = false;
22852287
match (i.value_target, i.type_target) {
22862288
// If this name wasn't found in either namespace, it's definitely
22872289
// unresolved.
2288-
(None, None) => { return Failed; }
2290+
(None, None) => { resolve_fail = true; }
22892291
// If it's private, it's also unresolved.
22902292
(Some(t), None) | (None, Some(t)) => {
22912293
let bindings = &mut *t.bindings;
22922294
match bindings.type_def {
22932295
Some(ref type_def) => {
22942296
if type_def.privacy == Private {
2295-
return Failed;
2297+
priv_fail = true;
22962298
}
22972299
}
22982300
_ => ()
22992301
}
23002302
match bindings.value_def {
23012303
Some(ref value_def) => {
23022304
if value_def.privacy == Private {
2303-
return Failed;
2305+
priv_fail = true;
23042306
}
23052307
}
23062308
_ => ()
@@ -2313,13 +2315,25 @@ pub impl Resolver {
23132315
(Some(ref value_def), Some(ref type_def)) =>
23142316
if value_def.privacy == Private
23152317
&& type_def.privacy == Private {
2316-
return Failed;
2318+
priv_fail = true;
23172319
},
23182320
_ => ()
23192321
}
23202322
}
23212323
}
23222324
2325+
if resolve_fail {
2326+
self.session.err(fmt!("unresolved import: there is no `%s` in `%s`",
2327+
*self.session.str_of(source),
2328+
self.module_to_str(containing_module)));
2329+
return Failed;
2330+
} else if priv_fail {
2331+
self.session.err(fmt!("unresolved import: found `%s` in `%s` but it is private",
2332+
*self.session.str_of(source),
2333+
self.module_to_str(containing_module)));
2334+
return Failed;
2335+
}
2336+
23232337
assert!(import_resolution.outstanding_references >= 1);
23242338
import_resolution.outstanding_references -= 1;
23252339

@@ -2491,7 +2505,8 @@ pub impl Resolver {
24912505
*segment_name));
24922506
return Failed;
24932507
}
2494-
self.session.span_err(span, ~"unresolved name");
2508+
self.session.span_err(span, fmt!("unresolved import: could not find `%s` in \
2509+
`%s`.", *segment_name, module_name));
24952510
return Failed;
24962511
}
24972512
Indeterminate => {

src/test/compile-fail/import2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use baz::zed::bar; //~ ERROR unresolved name
11+
use baz::zed::bar; //~ ERROR unresolved import
1212
//~^ ERROR failed to resolve import
1313

1414
mod baz {}

0 commit comments

Comments
 (0)