Skip to content

Commit

Permalink
Cleanup type-checking of constants, but do not try to fix #20489.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 4, 2015
1 parent a17a7c9 commit dbfa054
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,10 @@ impl<'tcx> Generics<'tcx> {
!self.regions.is_empty_in(space)
}

pub fn is_empty(&self) -> bool {
self.types.is_empty() && self.regions.is_empty()
}

pub fn to_bounds(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>)
-> GenericBounds<'tcx> {
GenericBounds {
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
let const_did = tcx.def_map.borrow()[pat.id].clone().def_id();
let const_scheme = ty::lookup_item_type(tcx, const_did);
fcx.write_ty(pat.id, const_scheme.ty);
demand::suptype(fcx, pat.span, expected, const_scheme.ty);
assert!(const_scheme.generics.is_empty());
let const_ty = pcx.fcx.instantiate_type_scheme(pat.span,
&Substs::empty(),
&const_scheme.ty);
fcx.write_ty(pat.id, const_ty);

// FIXME(#20489) -- we should limit the types here to scalars or something!

// As with PatLit, what we really want here is that there
// exist a LUB, but for the cases that can occur, subtype
// is good enough.
demand::suptype(fcx, pat.span, expected, const_ty);
}
ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
let typ = fcx.local_ty(pat.span, pat.id);
Expand Down

0 comments on commit dbfa054

Please sign in to comment.