You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #134776 - estebank:vanilla-ice, r=lcnr
Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern
When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.
Slight tweak to output to remove unnecessary context as a drive-by.
Fix#134764.
#[allow(rustc::potential_query_instability)] // Span labels will be sorted by the rendering
429
445
for span in v.adts_with_manual_partialeq {
430
446
err.span_note(span, "the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details");
"must be annotated with `#[derive(PartialEq)]` to be usable in patterns",
437
453
);
438
454
}
439
-
for ty in v.manual {
455
+
#[allow(rustc::potential_query_instability)]
456
+
let mut manual: Vec<_> = v.manual.into_iter().map(|t| t.to_string()).collect();
457
+
manual.sort();
458
+
for ty in manual {
440
459
err.note(format!(
441
460
"`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details"
442
461
));
443
462
}
444
-
for ty in v.without {
463
+
#[allow(rustc::potential_query_instability)]
464
+
let mut without: Vec<_> = v.without.into_iter().map(|t| t.to_string()).collect();
465
+
without.sort();
466
+
for ty in without {
445
467
err.note(format!(
446
468
"`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns"
447
469
));
448
470
}
449
471
}
450
472
473
+
#[derive(Debug)]
474
+
struct PartialEqImplStatus {
475
+
has_impl: bool,
476
+
is_derived: bool,
477
+
structural_partial_eq: bool,
478
+
non_blanket_impl: Option<DefId>,
479
+
}
480
+
451
481
#[instrument(level = "trace", skip(tcx), ret)]
452
482
fn type_has_partial_eq_impl<'tcx>(
453
483
tcx: TyCtxt<'tcx>,
454
484
typing_env: ty::TypingEnv<'tcx>,
455
485
ty: Ty<'tcx>,
456
-
) -> (
457
-
/* has impl */ bool,
458
-
/* is derived */ bool,
459
-
/* structural partial eq */ bool,
460
-
/* non-blanket impl */ Option<DefId>,
461
-
) {
486
+
) -> PartialEqImplStatus {
462
487
let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
463
488
// double-check there even *is* a semantic `PartialEq` to dispatch to.
0 commit comments