1
Fork 0

Implement "&<pat> everywhere"

The original proposal allows reference patterns
with "compatible" mutability, however it's not clear
what that means so for now we require an exact match.

I don't know the type system code well, so if something
seems to not make sense it's probably because I made a
mistake
This commit is contained in:
Jules Bertholet 2024-03-30 12:57:54 -05:00
parent 877d36b192
commit f37a4d55ee
No known key found for this signature in database
GPG key ID: 32034DAFC38C1BFC
11 changed files with 257 additions and 29 deletions

View file

@ -65,9 +65,16 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
// we wrap the unadjusted pattern in `PatKind::Deref` repeatedly, consuming the
// adjustments in *reverse order* (last-in-first-out, so that the last `Deref` inserted
// gets the least-dereferenced type).
let unadjusted_pat = self.lower_pattern_unadjusted(pat);
let unadjusted = if self.typeck_results.ref_pats_that_dont_deref().contains(pat.hir_id) {
match pat.kind {
hir::PatKind::Ref(inner, _) => self.lower_pattern_unadjusted(inner),
_ => span_bug!(pat.span, "non ref pattern marked as non-deref ref pattern"),
}
} else {
self.lower_pattern_unadjusted(pat)
};
self.typeck_results.pat_adjustments().get(pat.hir_id).unwrap_or(&vec![]).iter().rev().fold(
unadjusted_pat,
unadjusted,
|pat: Box<_>, ref_ty| {
debug!("{:?}: wrapping pattern with type {:?}", pat, ref_ty);
Box::new(Pat {