Skip to content

Commit 9dc82fa

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#82217. r? `@estebank`
2 parents 56b5393 + 1e4d804 commit 9dc82fa

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
@@ -334,7 +334,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
334334
.lookup_import_candidates(ident, ns, &self.parent_scope, is_enum_variant)
335335
.into_iter()
336336
.map(|suggestion| import_candidate_to_enum_paths(&suggestion))
337-
.filter(|(_, enum_ty_path)| enum_ty_path != "std::prelude::v1")
337+
.filter(|(_, enum_ty_path)| !enum_ty_path.starts_with("std::prelude::"))
338338
.collect();
339339
if !enum_candidates.is_empty() {
340340
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)