Skip to content

Commit 1e4d804

Browse files
committed
Don't hardcode the v1 prelude in diagnostics.
Instead of looking for `std::prelude::v1`, this changes it to look for `std::prelude::<anything>`.
1 parent 1d6b0f6 commit 1e4d804

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
324324
.lookup_import_candidates(ident, ns, &self.parent_scope, is_enum_variant)
325325
.into_iter()
326326
.map(|suggestion| import_candidate_to_enum_paths(&suggestion))
327-
.filter(|(_, enum_ty_path)| enum_ty_path != "std::prelude::v1")
327+
.filter(|(_, enum_ty_path)| !enum_ty_path.starts_with("std::prelude::"))
328328
.collect();
329329
if !enum_candidates.is_empty() {
330330
if let (PathSource::Type, Some(span)) =

compiler/rustc_typeck/src/check/demand.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
if self.can_coerce(expr_ty, sole_field_ty) {
201201
let variant_path = self.tcx.def_path_str(variant.def_id);
202202
// FIXME #56861: DRYer prelude filtering
203-
Some(variant_path.trim_start_matches("std::prelude::v1::").to_string())
203+
if let Some(path) = variant_path.strip_prefix("std::prelude::") {
204+
if let Some((_, path)) = path.split_once("::") {
205+
return Some(path.to_string());
206+
}
207+
}
208+
Some(variant_path)
204209
} else {
205210
None
206211
}

0 commit comments

Comments
 (0)