diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-03-10 08:01:37 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-10 08:01:37 +0900 |
| commit | 9dc82face341121e3464a59665bc7c5b394cacc0 (patch) | |
| tree | fd570f707b6a801d7f1e7fd6b72fc983184daa04 | |
| parent | 56b5393cc2cc0ac5769b00dbccbd34dc9202dd67 (diff) | |
| parent | 1e4d8042fc98dd07546a0eb201517983e82f4235 (diff) | |
Rollup merge of #82942 - m-ou-se:diagnostics-hardcoded-prelude-v1, r=estebank
Don't hardcode the `v1` prelude in diagnostics, to allow for new preludes. Instead of looking for `std::prelude::v1`, this changes the two places where that was hardcoded to look for `std::prelude::<anything>` instead. This is needed for https://github.com/rust-lang/rust/pull/82217. r? `@estebank`
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/demand.rs | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 2ee7f53ffa8..e7b3d459766 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -334,7 +334,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { .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") + .filter(|(_, enum_ty_path)| !enum_ty_path.starts_with("std::prelude::")) .collect(); if !enum_candidates.is_empty() { if let (PathSource::Type, Some(span)) = diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 39b973ed371..f9f67769e96 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -200,7 +200,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.can_coerce(expr_ty, sole_field_ty) { let variant_path = self.tcx.def_path_str(variant.def_id); // FIXME #56861: DRYer prelude filtering - Some(variant_path.trim_start_matches("std::prelude::v1::").to_string()) + if let Some(path) = variant_path.strip_prefix("std::prelude::") { + if let Some((_, path)) = path.split_once("::") { + return Some(path.to_string()); + } + } + Some(variant_path) } else { None } |
