Build wildcard witnesses instead of panicking

This commit is contained in:
Dawer 2021-04-30 13:33:07 +05:00
parent 678d85ca7e
commit b4f4197332

View File

@ -496,6 +496,8 @@ pub(crate) fn wildcards(pcx: PatCtxt<'_>, constructor: &Constructor) -> Self {
pub(super) fn apply(self, pcx: PatCtxt<'_>, ctor: &Constructor) -> Pat {
let subpatterns_and_indices = self.patterns_and_indices();
let mut subpatterns = subpatterns_and_indices.iter().map(|&(_, p)| p);
// TODO witnesses are not yet used
const TODO: Pat = Pat::Wild;
match ctor {
Single | Variant(_) => match pcx.ty.kind(&Interner) {
@ -509,7 +511,7 @@ pub(super) fn apply(self, pcx: PatCtxt<'_>, ctor: &Constructor) -> Pat {
let path = find_path(pcx.cx.db.upcast(), item, pcx.cx.module)
.map(|mpath| Path::from_known_path(mpath, Vec::new()).into());
match adt {
hir_def::AdtId::EnumId(_) => todo!(),
hir_def::AdtId::EnumId(id) => TODO,
hir_def::AdtId::StructId(id) => {
let variant_data = &pcx.cx.db.struct_data(id).variant_data;
let args = subpatterns_and_indices
@ -522,7 +524,7 @@ pub(super) fn apply(self, pcx: PatCtxt<'_>, ctor: &Constructor) -> Pat {
.collect();
Pat::Record { path, args, ellipsis: false }
}
hir_def::AdtId::UnionId(_) => todo!(),
hir_def::AdtId::UnionId(_) => Pat::Wild,
}
} else {
Pat::Tuple { args: subpatterns, ellipsis: None }
@ -540,12 +542,10 @@ pub(super) fn apply(self, pcx: PatCtxt<'_>, ctor: &Constructor) -> Pat {
}
_ => Pat::Wild,
},
Constructor::Slice(slice) => {
todo!()
}
Str(_) => todo!(),
FloatRange(..) => todo!(),
Constructor::IntRange(_) => todo!(),
Constructor::Slice(slice) => TODO,
Str(_) => TODO,
FloatRange(..) => TODO,
Constructor::IntRange(_) => TODO,
NonExhaustive => Pat::Wild,
Wildcard => Pat::Wild,
Opaque => panic!("bug: we should not try to apply an opaque constructor"),