diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2018-12-08 08:43:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-08 08:43:49 +0100 |
| commit | 9f7f9496000eb2e1e49eaab075233f0f44e7bdac (patch) | |
| tree | e701e316cda063d1e224ffe53e927fedc7e45b1c /src/librustc_resolve | |
| parent | 7f076fa521e0a94781846585b60914fbd6ec0984 (diff) | |
| parent | 2010b4f60b6fd2d3b54e7aeef329bcb7f92aec76 (diff) | |
| download | rust-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/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 42 |
1 files changed, 23 insertions, 19 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!(), |
