Rollup merge of #120318 - Nadrieril:share-debug-impl, r=compiler-errors

pattern_analysis: Reuse most of the `DeconstructedPat` `Debug` impl

The `DeconstructedPat: Debug` is best-effort because we'd need `tcx` to get things like field names etc. Since rust-analyzer has a similar constraint, this PR moves most the impl to be shared between the two. While I was at it I also fixed a nit in the `IntRange: Debug` impl.

r? `@compiler-errors`
This commit is contained in:
Matthias Krüger 2024-01-25 08:39:45 +01:00 committed by GitHub
commit a1ecced532
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 97 additions and 107 deletions

View file

@ -112,8 +112,12 @@ pub trait TypeCx: Sized + fmt::Debug {
/// This must follow the invariants of `ConstructorSet`
fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error>;
/// Best-effort `Debug` implementation.
fn debug_pat(f: &mut fmt::Formatter<'_>, pat: &DeconstructedPat<'_, Self>) -> fmt::Result;
/// Write the name of the variant represented by `pat`. Used for the best-effort `Debug` impl of
/// `DeconstructedPat`. Only invoqued when `pat.ctor()` is `Struct | Variant(_) | UnionField`.
fn write_variant_name(
f: &mut fmt::Formatter<'_>,
pat: &crate::pat::DeconstructedPat<'_, Self>,
) -> fmt::Result;
/// Raise a bug.
fn bug(&self, fmt: fmt::Arguments<'_>) -> !;