Remove use of RefCell<DefMap> in the simpler parts of pat_util
This commit is contained in:
parent
1ca1874986
commit
b1788ef8e1
@ -472,7 +472,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||
let guard_exit = self.expr(&**guard, guard_start);
|
||||
|
||||
let this_has_bindings = pat_util::pat_contains_bindings_or_wild(
|
||||
&self.tcx.def_map, &**pat);
|
||||
&self.tcx.def_map.borrow(), &**pat);
|
||||
|
||||
// If both this pattern and the previous pattern
|
||||
// were free of bindings, they must consist only
|
||||
|
@ -702,7 +702,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||
|
||||
Some(constructor) => {
|
||||
let matrix = rows.iter().filter_map(|r| {
|
||||
if pat_is_binding_or_wild(&cx.tcx.def_map, raw_pat(r[0])) {
|
||||
if pat_is_binding_or_wild(&cx.tcx.def_map.borrow(), raw_pat(r[0])) {
|
||||
Some(r[1..].to_vec())
|
||||
} else {
|
||||
None
|
||||
@ -1073,7 +1073,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
|
||||
// check legality of moving out of the enum
|
||||
|
||||
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
|
||||
if sub.map_or(false, |p| pat_contains_bindings(def_map, &*p)) {
|
||||
if sub.map_or(false, |p| pat_contains_bindings(&def_map.borrow(), &*p)) {
|
||||
span_err!(cx.tcx.sess, p.span, E0007, "cannot bind by-move with sub-bindings");
|
||||
} else if has_guard {
|
||||
span_err!(cx.tcx.sess, p.span, E0008, "cannot bind by-move into a pattern guard");
|
||||
@ -1086,7 +1086,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
|
||||
|
||||
for pat in pats {
|
||||
front_util::walk_pat(&**pat, |p| {
|
||||
if pat_is_binding(def_map, &*p) {
|
||||
if pat_is_binding(&def_map.borrow(), &*p) {
|
||||
match p.node {
|
||||
hir::PatIdent(hir::BindByValue(_), _, ref sub) => {
|
||||
let pat_ty = tcx.node_id_to_type(p.id);
|
||||
@ -1181,7 +1181,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> {
|
||||
|
||||
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
|
||||
fn visit_pat(&mut self, pat: &Pat) {
|
||||
if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) {
|
||||
if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map.borrow(), pat) {
|
||||
span_err!(self.cx.tcx.sess, pat.span, E0303,
|
||||
"pattern bindings are not allowed \
|
||||
after an `@`");
|
||||
|
@ -250,7 +250,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
fn visit_arm(&mut self, arm: &hir::Arm) {
|
||||
if arm.pats.len() == 1 {
|
||||
let pat = &*arm.pats[0];
|
||||
let variants = pat_util::necessary_variants(&self.tcx.def_map, pat);
|
||||
let variants = pat_util::necessary_variants(&self.tcx.def_map.borrow(), pat);
|
||||
|
||||
// Inside the body, ignore constructions of variants
|
||||
// necessary for the pattern to match. Those construction sites
|
||||
@ -270,7 +270,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
hir::PatStruct(_, ref fields, _) => {
|
||||
self.handle_field_pattern_match(pat, fields);
|
||||
}
|
||||
_ if pat_util::pat_is_const(def_map, pat) => {
|
||||
_ if pat_util::pat_is_const(&def_map.borrow(), pat) => {
|
||||
// it might be the only use of a const
|
||||
self.lookup_and_handle_definition(&pat.id)
|
||||
}
|
||||
|
@ -934,7 +934,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| {
|
||||
let tcx = self.tcx();
|
||||
let def_map = &self.tcx().def_map;
|
||||
if pat_util::pat_is_binding(def_map, pat) {
|
||||
if pat_util::pat_is_binding(&def_map.borrow(), pat) {
|
||||
match pat.node {
|
||||
hir::PatIdent(hir::BindByRef(_), _, _) =>
|
||||
mode.lub(BorrowingMatch),
|
||||
@ -969,7 +969,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
let def_map = &self.tcx().def_map;
|
||||
let delegate = &mut self.delegate;
|
||||
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
|
||||
if pat_util::pat_is_binding(def_map, pat) {
|
||||
if pat_util::pat_is_binding(&def_map.borrow(), pat) {
|
||||
let tcx = typer.tcx;
|
||||
|
||||
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}",
|
||||
|
@ -32,13 +32,13 @@ pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
|
||||
map
|
||||
}
|
||||
|
||||
pub fn pat_is_refutable(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatLit(_) | hir::PatRange(_, _) | hir::PatQPath(..) => true,
|
||||
hir::PatEnum(_, _) |
|
||||
hir::PatIdent(_, _, None) |
|
||||
hir::PatStruct(..) => {
|
||||
match dm.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(DefVariant(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
@ -48,12 +48,12 @@ pub fn pat_is_refutable(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_variant_or_struct(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatEnum(_, _) |
|
||||
hir::PatIdent(_, _, None) |
|
||||
hir::PatStruct(..) => {
|
||||
match dm.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(DefVariant(..)) | Some(DefStruct(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
@ -62,10 +62,10 @@ pub fn pat_is_variant_or_struct(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
|
||||
match dm.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
@ -76,10 +76,10 @@ pub fn pat_is_const(dm: &RefCell<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: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
|
||||
match dm.borrow().get(&pat.id)
|
||||
match dm.get(&pat.id)
|
||||
.and_then(|d| if d.depth == 0 { Some(d.base_def) }
|
||||
else { None } ) {
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) => true,
|
||||
@ -90,7 +90,7 @@ pub fn pat_is_resolved_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(..) => {
|
||||
!pat_is_variant_or_struct(dm, pat) &&
|
||||
@ -100,7 +100,7 @@ pub fn pat_is_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(..) => pat_is_binding(dm, pat),
|
||||
hir::PatWild => true,
|
||||
@ -115,7 +115,7 @@ pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
|
||||
{
|
||||
walk_pat(pat, |p| {
|
||||
match p.node {
|
||||
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
|
||||
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
|
||||
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
|
||||
}
|
||||
_ => {}
|
||||
@ -129,7 +129,7 @@ pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I)
|
||||
{
|
||||
walk_pat(pat, |p| {
|
||||
match p.node {
|
||||
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
|
||||
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
|
||||
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
|
||||
}
|
||||
_ => {}
|
||||
@ -140,7 +140,7 @@ pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I)
|
||||
|
||||
/// Checks if the pattern contains any patterns that bind something to
|
||||
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
|
||||
pub fn pat_contains_bindings(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
let mut contains_bindings = false;
|
||||
walk_pat(pat, |p| {
|
||||
if pat_is_binding(dm, p) {
|
||||
@ -185,7 +185,7 @@ pub fn arm_contains_ref_binding(dm: &RefCell<DefMap>, arm: &hir::Arm) -> Option<
|
||||
|
||||
/// Checks if the pattern contains any patterns that bind something to
|
||||
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
|
||||
pub fn pat_contains_bindings_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
let mut contains_bindings = false;
|
||||
walk_pat(pat, |p| {
|
||||
if pat_is_binding_or_wild(dm, p) {
|
||||
@ -221,14 +221,14 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
|
||||
}
|
||||
|
||||
/// Return variants that are necessary to exist for the pattern to match.
|
||||
pub fn necessary_variants(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Vec<DefId> {
|
||||
pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
|
||||
let mut variants = vec![];
|
||||
walk_pat(pat, |p| {
|
||||
match p.node {
|
||||
hir::PatEnum(_, _) |
|
||||
hir::PatIdent(_, _, None) |
|
||||
hir::PatStruct(..) => {
|
||||
match dm.borrow().get(&p.id) {
|
||||
match dm.get(&p.id) {
|
||||
Some(&PathResolution { base_def: DefVariant(_, id, _), .. }) => {
|
||||
variants.push(id);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ impl<'tcx> Mirror<'tcx> for PatNode<'tcx> {
|
||||
},
|
||||
|
||||
hir::PatEnum(..) | hir::PatIdent(..) | hir::PatQPath(..)
|
||||
if pat_is_resolved_const(&cx.tcx.def_map, self.pat) =>
|
||||
if pat_is_resolved_const(&cx.tcx.def_map.borrow(), self.pat) =>
|
||||
{
|
||||
let def = cx.tcx.def_map.borrow().get(&self.pat.id).unwrap().full_def();
|
||||
match def {
|
||||
@ -231,7 +231,7 @@ impl<'tcx> Mirror<'tcx> for PatNode<'tcx> {
|
||||
}
|
||||
|
||||
hir::PatIdent(bm, ref ident, ref sub)
|
||||
if pat_is_binding(&cx.tcx.def_map, self.pat) =>
|
||||
if pat_is_binding(&cx.tcx.def_map.borrow(), self.pat) =>
|
||||
{
|
||||
let id = match self.binding_map {
|
||||
None => self.pat.id,
|
||||
|
@ -517,7 +517,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
|
||||
let mut bound_ptrs = br.bound_ptrs.clone();
|
||||
match this.node {
|
||||
hir::PatIdent(_, ref path, None) => {
|
||||
if pat_is_binding(dm, &*this) {
|
||||
if pat_is_binding(&dm.borrow(), &*this) {
|
||||
bound_ptrs.push((path.node.name, val.val));
|
||||
}
|
||||
}
|
||||
@ -556,7 +556,7 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
|
||||
// Collect all of the matches that can match against anything.
|
||||
enter_match(bcx, dm, m, col, val, |pats| {
|
||||
if pat_is_binding_or_wild(dm, &*pats[col]) {
|
||||
if pat_is_binding_or_wild(&dm.borrow(), &*pats[col]) {
|
||||
let mut r = pats[..col].to_vec();
|
||||
r.push_all(&pats[col + 1..]);
|
||||
Some(r)
|
||||
@ -847,7 +847,7 @@ fn pick_column_to_specialize(def_map: &RefCell<DefMap>, m: &[Match]) -> Option<u
|
||||
fn pat_score(def_map: &RefCell<DefMap>, pat: &hir::Pat) -> usize {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, Some(ref inner)) => pat_score(def_map, &**inner),
|
||||
_ if pat_is_refutable(def_map, pat) => 1,
|
||||
_ if pat_is_refutable(&def_map.borrow(), pat) => 1,
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
@ -1801,7 +1801,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
let ccx = bcx.ccx();
|
||||
match pat.node {
|
||||
hir::PatIdent(pat_binding_mode, ref path1, ref inner) => {
|
||||
if pat_is_binding(&tcx.def_map, &*pat) {
|
||||
if pat_is_binding(&tcx.def_map.borrow(), &*pat) {
|
||||
// Allocate the stack slot where the value of this
|
||||
// binding will live and place it into the appropriate
|
||||
// map.
|
||||
|
@ -167,7 +167,7 @@ fn walk_pattern(cx: &CrateContext,
|
||||
|
||||
// Check if this is a binding. If so we need to put it on the
|
||||
// scope stack and maybe introduce an artificial scope
|
||||
if pat_util::pat_is_binding(def_map, &*pat) {
|
||||
if pat_util::pat_is_binding(&def_map.borrow(), &*pat) {
|
||||
|
||||
let name = path1.node.name;
|
||||
|
||||
|
@ -133,7 +133,8 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
// subtyping doesn't matter here, as the value is some kind of scalar
|
||||
demand::eqtype(fcx, pat.span, expected, lhs_ty);
|
||||
}
|
||||
hir::PatEnum(..) | hir::PatIdent(..) if pat_is_resolved_const(&tcx.def_map, pat) => {
|
||||
hir::PatEnum(..) | hir::PatIdent(..)
|
||||
if pat_is_resolved_const(&tcx.def_map.borrow(), pat) => {
|
||||
let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id();
|
||||
let const_scheme = tcx.lookup_item_type(const_did);
|
||||
assert!(const_scheme.generics.is_empty());
|
||||
@ -149,7 +150,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
// is good enough.
|
||||
demand::suptype(fcx, pat.span, expected, const_ty);
|
||||
}
|
||||
hir::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
|
||||
hir::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map.borrow(), pat) => {
|
||||
let typ = fcx.local_ty(pat.span, pat.id);
|
||||
match bm {
|
||||
hir::BindByRef(mutbl) => {
|
||||
@ -410,7 +411,7 @@ pub fn check_dereferencable<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
inner: &hir::Pat) -> bool {
|
||||
let fcx = pcx.fcx;
|
||||
let tcx = pcx.fcx.ccx.tcx;
|
||||
if pat_is_binding(&tcx.def_map, inner) {
|
||||
if pat_is_binding(&tcx.def_map.borrow(), inner) {
|
||||
let expected = fcx.infcx().shallow_resolve(expected);
|
||||
expected.builtin_deref(true, ty::NoPreference).map_or(true, |mt| match mt.ty.sty {
|
||||
ty::TyTrait(_) => {
|
||||
|
@ -529,7 +529,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
|
||||
// Add pattern bindings.
|
||||
fn visit_pat(&mut self, p: &'tcx hir::Pat) {
|
||||
if let hir::PatIdent(_, ref path1, _) = p.node {
|
||||
if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map, p) {
|
||||
if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map.borrow(), p) {
|
||||
let var_ty = self.assign(p.span, p.id, None);
|
||||
|
||||
self.fcx.require_type_is_sized(var_ty, p.span,
|
||||
|
@ -57,7 +57,7 @@ pub fn resolve_type_vars_in_fn(fcx: &FnCtxt,
|
||||
wbcx.visit_pat(&*arg.pat);
|
||||
|
||||
// Privacy needs the type for the whole pattern, not just each binding
|
||||
if !pat_util::pat_is_binding(&fcx.tcx().def_map, &*arg.pat) {
|
||||
if !pat_util::pat_is_binding(&fcx.tcx().def_map.borrow(), &*arg.pat) {
|
||||
wbcx.visit_node_id(ResolvingPattern(arg.pat.span),
|
||||
arg.pat.id);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user