diff options
| author | David Wood <david@davidtw.co> | 2019-02-11 19:29:10 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2019-02-11 19:29:10 +0100 |
| commit | 48b0c9da69965cd40d037cee42cf3093ed09c6ee (patch) | |
| tree | 0344c160bbf7495809ad76c96bf38a5f27caf25c /src/librustc_resolve/error_reporting.rs | |
| parent | de111e6367b065fd5f8cee59b64eefefd8272f44 (diff) | |
Only suggest imports if not imported.
This commit modifies name resolution error reporting so that if a name is in scope and has been imported then we do not suggest importing it. This can occur when we add a label about constructors not being visible due to private fields. In these cases, we know that the struct/variant has been imported and we should silence any suggestions to import the struct/variant.
Diffstat (limited to 'src/librustc_resolve/error_reporting.rs')
| -rw-r--r-- | src/librustc_resolve/error_reporting.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs index 8300e691bbe..a6e27c0a1ae 100644 --- a/src/librustc_resolve/error_reporting.rs +++ b/src/librustc_resolve/error_reporting.rs @@ -106,7 +106,15 @@ impl<'a> Resolver<'a> { // Try to lookup name in more relaxed fashion for better error reporting. let ident = path.last().unwrap().ident; - let candidates = self.lookup_import_candidates(ident, ns, is_expected); + let candidates = self.lookup_import_candidates(ident, ns, is_expected) + .drain(..) + .filter(|ImportSuggestion { did, .. }| { + match (did, def.and_then(|def| def.opt_def_id())) { + (Some(suggestion_did), Some(actual_did)) => *suggestion_did != actual_did, + _ => true, + } + }) + .collect::<Vec<_>>(); if candidates.is_empty() && is_expected(Def::Enum(DefId::local(CRATE_DEF_INDEX))) { let enum_candidates = self.lookup_import_candidates(ident, ns, is_enum_variant); |
