1
Fork 0

Handle ty::Opaque correctly

This commit is contained in:
Nadrieril 2023-10-27 05:10:58 +02:00
parent d5070e32ea
commit 3fa2e71ce1
2 changed files with 33 additions and 11 deletions

View file

@ -883,7 +883,22 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
self.patterns.is_empty() self.patterns.is_empty()
} }
fn head_ty(&self) -> Option<Ty<'tcx>> { fn head_ty(&self) -> Option<Ty<'tcx>> {
self.patterns.get(0).map(|p| p.ty()) if self.patterns.len() == 0 {
return None;
}
// If the type is opaque and it is revealed anywhere in the column, we take the revealed
// version. Otherwise we could encounter constructors for the revealed type and crash.
let is_opaque = |ty: Ty<'tcx>| matches!(ty.kind(), ty::Alias(ty::Opaque, ..));
let first_ty = self.patterns[0].ty();
if is_opaque(first_ty) {
for pat in &self.patterns {
let ty = pat.ty();
if !is_opaque(ty) {
return Some(ty);
}
}
}
Some(first_ty)
} }
fn analyze_ctors(&self, pcx: &PatCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'tcx> { fn analyze_ctors(&self, pcx: &PatCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'tcx> {

View file

@ -26,11 +26,9 @@ fn upvar() {
fn enum_upvar() { fn enum_upvar() {
type T = impl Copy; type T = impl Copy;
let foo: T = Some((1u32, 2u32)); let foo: T = Some((1u32, 2u32));
let x = move || { let x = move || match foo {
match foo { None => (),
None => (), Some((a, b)) => (),
Some((a, b)) => (),
}
}; };
} }
@ -63,6 +61,19 @@ mod only_pattern {
None => {} None => {}
} }
} }
type V = impl Copy;
fn baz(baz: Option<V>) {
match baz {
_ => {}
Some((mut x, mut y)) => {
x = 42;
y = "foo";
}
None => {}
}
}
} }
mod only_pattern_rpit { mod only_pattern_rpit {
@ -71,11 +82,7 @@ mod only_pattern_rpit {
let (mut x, mut y) = foo(false); let (mut x, mut y) = foo(false);
x = 42; x = 42;
y = "foo"; y = "foo";
if b { if b { panic!() } else { foo(true) }
panic!()
} else {
foo(true)
}
} }
fn bar(b: bool) -> Option<impl Copy> { fn bar(b: bool) -> Option<impl Copy> {