mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 02:54:00 +00:00
resolve: Reduce some clutter in import ambiguity errors
This commit is contained in:
parent
4a45578bc5
commit
2010b4f60b
@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||||||
self.current_module = directive.parent_scope.module;
|
self.current_module = directive.parent_scope.module;
|
||||||
|
|
||||||
let orig_vis = directive.vis.replace(ty::Visibility::Invisible);
|
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,
|
let path_res = self.resolve_path(&directive.module_path, None, &directive.parent_scope,
|
||||||
true, directive.span, directive.crate_lint());
|
true, directive.span, directive.crate_lint());
|
||||||
|
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
|
||||||
directive.vis.set(orig_vis);
|
directive.vis.set(orig_vis);
|
||||||
let module = match path_res {
|
let module = match path_res {
|
||||||
PathResult::Module(module) => {
|
PathResult::Module(module) => {
|
||||||
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
|
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
|
||||||
if let Some(initial_module) = directive.imported_module.get() {
|
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");
|
span_bug!(directive.span, "inconsistent resolution for an import");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||||||
module
|
module
|
||||||
}
|
}
|
||||||
PathResult::Failed(span, msg, false) => {
|
PathResult::Failed(span, msg, false) => {
|
||||||
assert!(!self.ambiguity_errors.is_empty() ||
|
if no_ambiguity {
|
||||||
directive.imported_module.get().is_none());
|
assert!(directive.imported_module.get().is_none());
|
||||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||||
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
PathResult::Failed(span, msg, true) => {
|
PathResult::Failed(span, msg, true) => {
|
||||||
assert!(!self.ambiguity_errors.is_empty() ||
|
if no_ambiguity {
|
||||||
directive.imported_module.get().is_none());
|
assert!(directive.imported_module.get().is_none());
|
||||||
return if let Some((suggested_path, note)) = self.make_path_suggestion(
|
return Some(match self.make_path_suggestion(span, directive.module_path.clone(),
|
||||||
span, directive.module_path.clone(), &directive.parent_scope
|
&directive.parent_scope) {
|
||||||
) {
|
Some((suggestion, note)) => (
|
||||||
Some((
|
span,
|
||||||
span,
|
format!("did you mean `{}`?", Segment::names_to_string(&suggestion)),
|
||||||
format!("did you mean `{}`?", Segment::names_to_string(&suggested_path)),
|
note,
|
||||||
note,
|
),
|
||||||
))
|
None => (span, msg, None),
|
||||||
} else {
|
});
|
||||||
Some((span, msg, None))
|
}
|
||||||
};
|
return None;
|
||||||
}
|
}
|
||||||
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
|
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.
|
// The error was already reported earlier.
|
||||||
assert!(!self.ambiguity_errors.is_empty() ||
|
|
||||||
directive.imported_module.get().is_none());
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
|
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
|
||||||
|
@ -7,13 +7,11 @@
|
|||||||
mod m1 {
|
mod m1 {
|
||||||
use issue_56125::last_segment::*;
|
use issue_56125::last_segment::*;
|
||||||
//~^ ERROR `issue_56125` is ambiguous
|
//~^ ERROR `issue_56125` is ambiguous
|
||||||
//~| ERROR unresolved import `issue_56125::last_segment`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod m2 {
|
mod m2 {
|
||||||
use issue_56125::non_last_segment::non_last_segment::*;
|
use issue_56125::non_last_segment::non_last_segment::*;
|
||||||
//~^ ERROR `issue_56125` is ambiguous
|
//~^ ERROR `issue_56125` is ambiguous
|
||||||
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod m3 {
|
mod m3 {
|
||||||
|
@ -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`
|
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`
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
|
||||||
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
|
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
|
||||||
@ -32,7 +20,7 @@ LL | use issue_56125::last_segment::*;
|
|||||||
= help: use `self::issue_56125` to refer to this module unambiguously
|
= 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)
|
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::*;
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
|
||||||
| ^^^^^^^^^^^ ambiguous name
|
| ^^^^^^^^^^^ ambiguous name
|
||||||
@ -40,14 +28,14 @@ LL | use issue_56125::non_last_segment::non_last_segment::*;
|
|||||||
= note: `issue_56125` could refer to an extern crate passed with `--extern`
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
|
||||||
= help: use `::issue_56125` to refer to this extern crate unambiguously
|
= help: use `::issue_56125` to refer to this extern crate unambiguously
|
||||||
note: `issue_56125` could also refer to the module imported here
|
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::*;
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= help: use `self::issue_56125` to refer to this module unambiguously
|
= 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)
|
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
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
|
||||||
| ^^^^^^^^^^^ ambiguous name
|
| ^^^^^^^^^^^ ambiguous name
|
||||||
@ -55,13 +43,13 @@ LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
|
|||||||
= note: `issue_56125` could refer to an extern crate passed with `--extern`
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
|
||||||
= help: use `::issue_56125` to refer to this extern crate unambiguously
|
= help: use `::issue_56125` to refer to this extern crate unambiguously
|
||||||
note: `issue_56125` could also refer to the unresolved item imported here
|
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`
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
= help: use `self::issue_56125` to refer to this unresolved item unambiguously
|
= 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`.
|
For more information about an error, try `rustc --explain E0432`.
|
||||||
|
Loading…
Reference in New Issue
Block a user