about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2018-12-08 08:43:49 +0100
committerGitHub <noreply@github.com>2018-12-08 08:43:49 +0100
commit9f7f9496000eb2e1e49eaab075233f0f44e7bdac (patch)
treee701e316cda063d1e224ffe53e927fedc7e45b1c /src
parent7f076fa521e0a94781846585b60914fbd6ec0984 (diff)
parent2010b4f60b6fd2d3b54e7aeef329bcb7f92aec76 (diff)
downloadrust-9f7f9496000eb2e1e49eaab075233f0f44e7bdac.tar.gz
rust-9f7f9496000eb2e1e49eaab075233f0f44e7bdac.zip
Rollup merge of #56620 - petrochenkov:noclutter, r=estebank
resolve: Reduce some clutter in import ambiguity errors

Noticed in https://www.reddit.com/r/rust/comments/a3pyrw/announcing_rust_131_and_rust_2018/eb8alhi/.
The first error is distracting, but unnecessary, it's a *consequence* of the ambiguity error and appears because one of the ambiguous `actix` modules (unsurprisingly) doesn't have the expected name in it.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/resolve_imports.rs42
-rw-r--r--src/test/ui/imports/issue-56125.rs2
-rw-r--r--src/test/ui/imports/issue-56125.stderr26
3 files changed, 30 insertions, 40 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index f130895e236..015cd31ac1d 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -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 {
@@ -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!(),
diff --git a/src/test/ui/imports/issue-56125.rs b/src/test/ui/imports/issue-56125.rs
index 843b52f1843..0327522e4b8 100644
--- a/src/test/ui/imports/issue-56125.rs
+++ b/src/test/ui/imports/issue-56125.rs
@@ -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 {
diff --git a/src/test/ui/imports/issue-56125.stderr b/src/test/ui/imports/issue-56125.stderr
index b1292ef8f78..559979e5d51 100644
--- a/src/test/ui/imports/issue-56125.stderr
+++ b/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`
@@ -32,7 +20,7 @@ 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
@@ -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`
    = 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
@@ -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`
    = 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`.