Skip to content

Commit 4d4c7be

Browse files
committed
Better support for associated types in struct patterns
1 parent ba419a7 commit 4d4c7be

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
7676
PatKind::Path(..) |
7777
PatKind::Struct(..) => {
7878
match dm.get(&pat.id).map(|d| d.full_def()) {
79-
Some(Def::Variant(..)) | Some(Def::Struct(..)) | Some(Def::TyAlias(..)) => true,
79+
Some(Def::Variant(..)) | Some(Def::Struct(..)) |
80+
Some(Def::TyAlias(..)) | Some(Def::AssociatedTy(..)) => true,
8081
_ => false
8182
}
8283
}

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
17151715
pub fn variant_of_def(&self, def: Def) -> &VariantDefData<'gcx, 'container> {
17161716
match def {
17171717
Def::Variant(_, vid) => self.variant_with_id(vid),
1718-
Def::Struct(..) | Def::TyAlias(..) => self.struct_variant(),
1718+
Def::Struct(..) | Def::TyAlias(..) | Def::AssociatedTy(..) => self.struct_variant(),
17191719
_ => bug!("unexpected def {:?} in variant_of_def", def)
17201720
}
17211721
}

src/librustc_trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ fn any_irrefutable_adt_pat(tcx: TyCtxt, m: &[Match], col: usize) -> bool {
796796
PatKind::Tuple(..) => true,
797797
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) => {
798798
match tcx.expect_def(pat.id) {
799-
Def::Struct(..) | Def::TyAlias(..) => true,
799+
Def::Struct(..) | Def::TyAlias(..) | Def::AssociatedTy(..) => true,
800800
_ => false,
801801
}
802802
}

0 commit comments

Comments
 (0)