Skip to content

Commit

Permalink
resolve: Reduce some clutter in import ambiguity errors
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 8, 2018
1 parent 4a45578 commit 2010b4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
42 changes: 23 additions & 19 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
self.current_module = directive.parent_scope.module;

let orig_vis = directive.vis.replace(ty::Visibility::Invisible);
let prev_ambiguity_errors_len = self.ambiguity_errors.len();
let path_res = self.resolve_path(&directive.module_path, None, &directive.parent_scope,
true, directive.span, directive.crate_lint());
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
directive.vis.set(orig_vis);
let module = match path_res {
PathResult::Module(module) => {
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
if let Some(initial_module) = directive.imported_module.get() {
if module != initial_module && self.ambiguity_errors.is_empty() {
if module != initial_module && no_ambiguity {
span_bug!(directive.span, "inconsistent resolution for an import");
}
} else {
Expand All @@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
module
}
PathResult::Failed(span, msg, false) => {
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
}
return None;
}
PathResult::Failed(span, msg, true) => {
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
return if let Some((suggested_path, note)) = self.make_path_suggestion(
span, directive.module_path.clone(), &directive.parent_scope
) {
Some((
span,
format!("did you mean `{}`?", Segment::names_to_string(&suggested_path)),
note,
))
} else {
Some((span, msg, None))
};
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
return Some(match self.make_path_suggestion(span, directive.module_path.clone(),
&directive.parent_scope) {
Some((suggestion, note)) => (
span,
format!("did you mean `{}`?", Segment::names_to_string(&suggestion)),
note,
),
None => (span, msg, None),
});
}
return None;
}
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
}
// The error was already reported earlier.
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
return None;
}
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/imports/issue-56125.rs
Expand Up @@ -7,13 +7,11 @@
mod m1 {
use issue_56125::last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR unresolved import `issue_56125::last_segment`
}

mod m2 {
use issue_56125::non_last_segment::non_last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
}

mod m3 {
Expand Down
26 changes: 7 additions & 19 deletions src/test/ui/imports/issue-56125.stderr
@@ -1,17 +1,5 @@
error[E0433]: failed to resolve: could not find `non_last_segment` in `issue_56125`
--> $DIR/issue-56125.rs:14:22
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`

error[E0432]: unresolved import `issue_56125::last_segment`
--> $DIR/issue-56125.rs:8:22
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`

error[E0432]: unresolved import `empty::issue_56125`
--> $DIR/issue-56125.rs:21:9
--> $DIR/issue-56125.rs:19:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
Expand All @@ -32,36 +20,36 @@ LL | use issue_56125::last_segment::*;
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:14:9
--> $DIR/issue-56125.rs:13:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:14:9
--> $DIR/issue-56125.rs:13:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:22:9
--> $DIR/issue-56125.rs:20:9
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the unresolved item imported here
--> $DIR/issue-56125.rs:21:9
--> $DIR/issue-56125.rs:19:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this unresolved item unambiguously

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

Some errors occurred: E0432, E0433, E0659.
Some errors occurred: E0432, E0659.
For more information about an error, try `rustc --explain E0432`.

0 comments on commit 2010b4f

Please sign in to comment.