Take &Pat
This commit is contained in:
parent
cd7a9b7234
commit
eb5cbfebfd
@ -20,7 +20,7 @@ pub type PatIdMap = HashMap<Ident, NodeId>;
|
||||
|
||||
// This is used because same-named variables in alternative patterns need to
|
||||
// use the NodeId of their namesake in the first pattern.
|
||||
pub fn pat_id_map(dm: resolve::DefMap, pat: @Pat) -> PatIdMap {
|
||||
pub fn pat_id_map(dm: resolve::DefMap, pat: &Pat) -> PatIdMap {
|
||||
let mut map = HashMap::new();
|
||||
do pat_bindings(dm, pat) |_bm, p_id, _s, n| {
|
||||
map.insert(path_to_ident(n), p_id);
|
||||
@ -52,7 +52,7 @@ pub fn pat_is_const(dm: resolve::DefMap, pat: &Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding(dm: resolve::DefMap, pat: @Pat) -> bool {
|
||||
pub fn pat_is_binding(dm: resolve::DefMap, pat: &Pat) -> bool {
|
||||
match pat.node {
|
||||
PatIdent(*) => {
|
||||
!pat_is_variant_or_struct(dm, pat) &&
|
||||
@ -62,7 +62,7 @@ pub fn pat_is_binding(dm: resolve::DefMap, pat: @Pat) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @Pat) -> bool {
|
||||
pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: &Pat) -> bool {
|
||||
match pat.node {
|
||||
PatIdent(*) => pat_is_binding(dm, pat),
|
||||
PatWild | PatWildMulti => true,
|
||||
@ -73,7 +73,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @Pat) -> bool {
|
||||
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
|
||||
/// `match foo() { Some(a) => (), None => () }`
|
||||
pub fn pat_bindings(dm: resolve::DefMap,
|
||||
pat: @Pat,
|
||||
pat: &Pat,
|
||||
it: |BindingMode, NodeId, Span, &Path|) {
|
||||
do walk_pat(pat) |p| {
|
||||
match p.node {
|
||||
@ -86,7 +86,7 @@ pub fn pat_bindings(dm: resolve::DefMap,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pat_binding_ids(dm: resolve::DefMap, pat: @Pat) -> ~[NodeId] {
|
||||
pub fn pat_binding_ids(dm: resolve::DefMap, pat: &Pat) -> ~[NodeId] {
|
||||
let mut found = ~[];
|
||||
pat_bindings(dm, pat, |_bm, b_id, _sp, _pt| found.push(b_id) );
|
||||
return found;
|
||||
@ -94,7 +94,7 @@ pub fn pat_binding_ids(dm: resolve::DefMap, pat: @Pat) -> ~[NodeId] {
|
||||
|
||||
/// 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: resolve::DefMap, pat: @Pat) -> bool {
|
||||
pub fn pat_contains_bindings(dm: resolve::DefMap, pat: &Pat) -> bool {
|
||||
let mut contains_bindings = false;
|
||||
do walk_pat(pat) |p| {
|
||||
if pat_is_binding(dm, p) {
|
||||
|
@ -636,7 +636,7 @@ pub fn is_item_impl(item: @ast::item) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_pat(pat: @Pat, it: |@Pat| -> bool) -> bool {
|
||||
pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
|
||||
if !it(pat) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user