diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-25 14:33:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-25 14:33:56 +0100 |
| commit | 568ae3aee7be10d4439486686cad186b3df2446e (patch) | |
| tree | d1588d12ef0c774a8bb0e0d0aacc5e3a2c505443 /compiler/rustc_resolve | |
| parent | f891af9de529f7df8d094e130dd6f35fe07b4d78 (diff) | |
| parent | 04c2454b1ecdf8e8611f291708ef38937288a250 (diff) | |
Rollup merge of #82087 - estebank:abolish-ice, r=oli-obk
Fix ICE caused by suggestion with no code substitutions Change suggestion logic to filter and checking _before_ creating specific resolution suggestion. Assert earlier that suggestions contain code substitions to make it easier in the future to debug invalid uses. If we find this becomes too noisy in the wild, we can always make the emitter resilient to these cases and remove the assertions. Fix #78651.
Diffstat (limited to 'compiler/rustc_resolve')
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 6457c6cee57..d60f929cb8f 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -319,9 +319,13 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { .collect::<Vec<_>>(); let crate_def_id = DefId::local(CRATE_DEF_INDEX); if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) { - let enum_candidates = - self.r.lookup_import_candidates(ident, ns, &self.parent_scope, is_enum_variant); - + let mut enum_candidates: Vec<_> = self + .r + .lookup_import_candidates(ident, ns, &self.parent_scope, is_enum_variant) + .into_iter() + .map(|suggestion| import_candidate_to_enum_paths(&suggestion)) + .filter(|(_, enum_ty_path)| enum_ty_path != "std::prelude::v1") + .collect(); if !enum_candidates.is_empty() { if let (PathSource::Type, Some(span)) = (source, self.diagnostic_metadata.current_type_ascription.last()) @@ -340,10 +344,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } } - let mut enum_candidates = enum_candidates - .iter() - .map(|suggestion| import_candidate_to_enum_paths(&suggestion)) - .collect::<Vec<_>>(); enum_candidates.sort(); // Contextualize for E0412 "cannot find type", but don't belabor the point @@ -363,19 +363,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { err.span_suggestions( span, &msg, - enum_candidates - .into_iter() - .map(|(_variant_path, enum_ty_path)| enum_ty_path) - // Variants re-exported in prelude doesn't mean `prelude::v1` is the - // type name! - // FIXME: is there a more principled way to do this that - // would work for other re-exports? - .filter(|enum_ty_path| enum_ty_path != "std::prelude::v1") - // Also write `Option` rather than `std::prelude::v1::Option`. - .map(|enum_ty_path| { - // FIXME #56861: DRY-er prelude filtering. - enum_ty_path.trim_start_matches("std::prelude::v1::").to_owned() - }), + enum_candidates.into_iter().map(|(_variant_path, enum_ty_path)| enum_ty_path), Applicability::MachineApplicable, ); } |
