Skip to content

Commit dbfa054

Browse files
committed
Cleanup type-checking of constants, but do not try to fix #20489.
1 parent a17a7c9 commit dbfa054

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/librustc/middle/ty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,10 @@ impl<'tcx> Generics<'tcx> {
17791779
!self.regions.is_empty_in(space)
17801780
}
17811781

1782+
pub fn is_empty(&self) -> bool {
1783+
self.types.is_empty() && self.regions.is_empty()
1784+
}
1785+
17821786
pub fn to_bounds(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>)
17831787
-> GenericBounds<'tcx> {
17841788
GenericBounds {

src/librustc_typeck/check/_match.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,18 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
103103
ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
104104
let const_did = tcx.def_map.borrow()[pat.id].clone().def_id();
105105
let const_scheme = ty::lookup_item_type(tcx, const_did);
106-
fcx.write_ty(pat.id, const_scheme.ty);
107-
demand::suptype(fcx, pat.span, expected, const_scheme.ty);
106+
assert!(const_scheme.generics.is_empty());
107+
let const_ty = pcx.fcx.instantiate_type_scheme(pat.span,
108+
&Substs::empty(),
109+
&const_scheme.ty);
110+
fcx.write_ty(pat.id, const_ty);
111+
112+
// FIXME(#20489) -- we should limit the types here to scalars or something!
113+
114+
// As with PatLit, what we really want here is that there
115+
// exist a LUB, but for the cases that can occur, subtype
116+
// is good enough.
117+
demand::suptype(fcx, pat.span, expected, const_ty);
108118
}
109119
ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
110120
let typ = fcx.local_ty(pat.span, pat.id);

0 commit comments

Comments
 (0)