Rewrite check_pat_enum, split it into check_pat_tuple_struct and check_pat_path
Update definitions in def_map for associated types written in unqualified form (like `Self::Output`) Cleanup finish_resolving_def_to_ty/resolve_ty_and_def_ufcs Make VariantDef's available through constructor IDs
This commit is contained in:
parent
eb32440d45
commit
2cdd9f1c97
17 changed files with 229 additions and 327 deletions
|
|
@ -137,15 +137,6 @@ impl Def {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn variant_def_ids(&self) -> Option<(DefId, DefId)> {
|
||||
match *self {
|
||||
Def::Variant(enum_id, var_id) => {
|
||||
Some((enum_id, var_id))
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind_name(&self) -> &'static str {
|
||||
match *self {
|
||||
Def::Fn(..) => "function",
|
||||
|
|
|
|||
|
|
@ -12,15 +12,12 @@ use hir::def::*;
|
|||
use hir::def_id::DefId;
|
||||
use hir::{self, PatKind};
|
||||
use ty::TyCtxt;
|
||||
use util::nodemap::FnvHashMap;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
use std::iter::{Enumerate, ExactSizeIterator};
|
||||
|
||||
pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
|
||||
|
||||
pub struct EnumerateAndAdjust<I> {
|
||||
enumerate: Enumerate<I>,
|
||||
gap_pos: usize,
|
||||
|
|
@ -97,22 +94,6 @@ pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
// Same as above, except that partially-resolved defs cause `false` to be
|
||||
// returned instead of a panic.
|
||||
pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
PatKind::Path(..) | PatKind::QPath(..) => {
|
||||
match dm.get(&pat.id)
|
||||
.and_then(|d| if d.depth == 0 { Some(d.base_def) }
|
||||
else { None } ) {
|
||||
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
|
||||
/// `match foo() { Some(a) => (), None => () }`
|
||||
pub fn pat_bindings<F>(pat: &hir::Pat, mut f: F)
|
||||
|
|
|
|||
|
|
@ -591,6 +591,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.global_interners.arenas.trait_defs.alloc(def)
|
||||
}
|
||||
|
||||
pub fn insert_adt_def(self, did: DefId, adt_def: ty::AdtDefMaster<'gcx>) {
|
||||
// this will need a transmute when reverse-variance is removed
|
||||
if let Some(prev) = self.adt_defs.borrow_mut().insert(did, adt_def) {
|
||||
bug!("Tried to overwrite interned AdtDef: {:?}", prev)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn intern_adt_def(self,
|
||||
did: DefId,
|
||||
kind: ty::AdtKind,
|
||||
|
|
@ -598,10 +605,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
-> ty::AdtDefMaster<'gcx> {
|
||||
let def = ty::AdtDefData::new(self, did, kind, variants);
|
||||
let interned = self.global_interners.arenas.adt_defs.alloc(def);
|
||||
// this will need a transmute when reverse-variance is removed
|
||||
if let Some(prev) = self.adt_defs.borrow_mut().insert(did, interned) {
|
||||
bug!("Tried to overwrite interned AdtDef: {:?}", prev)
|
||||
}
|
||||
self.insert_adt_def(did, interned);
|
||||
interned
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2454,6 +2454,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
self.def_map.borrow().get(&id).map(|resolution| resolution.full_def())
|
||||
}
|
||||
|
||||
// Returns `ty::VariantDef` if `def` refers to a struct,
|
||||
// or variant or their constructors, panics otherwise.
|
||||
pub fn expect_variant_def(self, def: Def) -> VariantDef<'tcx> {
|
||||
match def {
|
||||
Def::Variant(enum_did, did) => {
|
||||
self.lookup_adt_def(enum_did).variant_with_id(did)
|
||||
}
|
||||
Def::Struct(did) => {
|
||||
self.lookup_adt_def(did).struct_variant()
|
||||
}
|
||||
_ => bug!("expect_variant_def used with unexpected def {:?}", def)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn def_key(self, id: DefId) -> ast_map::DefKey {
|
||||
if id.is_local() {
|
||||
self.map.def_key(id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue