auto merge of #10657 : sanxiyn/rust/pat, r=cmr
This commit is contained in:
commit
6fe6a6f9df
|
@ -51,7 +51,7 @@ impl<'self> Visitor<()> for CheckLoanCtxt<'self> {
|
|||
fn visit_block(&mut self, b:&ast::Block, _:()) {
|
||||
check_loans_in_block(self, b);
|
||||
}
|
||||
fn visit_pat(&mut self, p:@ast::Pat, _:()) {
|
||||
fn visit_pat(&mut self, p:&ast::Pat, _:()) {
|
||||
check_loans_in_pat(self, p);
|
||||
}
|
||||
fn visit_fn(&mut self, fk:&visit::fn_kind, fd:&ast::fn_decl,
|
||||
|
@ -847,7 +847,7 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
|
|||
}
|
||||
|
||||
fn check_loans_in_pat<'a>(this: &mut CheckLoanCtxt<'a>,
|
||||
pat: @ast::Pat)
|
||||
pat: &ast::Pat)
|
||||
{
|
||||
this.check_for_conflicting_loans(pat.id);
|
||||
this.check_move_out_from_id(pat.id, pat.span);
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'self> visit::Visitor<()> for GatherLoanCtxt<'self> {
|
|||
fn visit_stmt(&mut self, s:@Stmt, _:()) {
|
||||
add_stmt_to_map(self, s);
|
||||
}
|
||||
fn visit_pat(&mut self, p:@Pat, _:()) {
|
||||
fn visit_pat(&mut self, p:&Pat, _:()) {
|
||||
add_pat_to_id_range(self, p);
|
||||
}
|
||||
fn visit_local(&mut self, l:@Local, _:()) {
|
||||
|
@ -119,7 +119,7 @@ pub fn gather_loans(bccx: &BorrowckCtxt,
|
|||
}
|
||||
|
||||
fn add_pat_to_id_range(this: &mut GatherLoanCtxt,
|
||||
p: @ast::Pat) {
|
||||
p: &ast::Pat) {
|
||||
// NB: This visitor function just adds the pat ids into the id
|
||||
// range. We gather loans that occur in patterns using the
|
||||
// `gather_pat()` method below. Eventually these two should be
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Visitor<bool> for CheckCrateVisitor {
|
|||
fn visit_item(&mut self, i:@item, env:bool) {
|
||||
check_item(self, self.sess, self.ast_map, self.def_map, i, env);
|
||||
}
|
||||
fn visit_pat(&mut self, p:@Pat, env:bool) {
|
||||
fn visit_pat(&mut self, p:&Pat, env:bool) {
|
||||
check_pat(self, p, env);
|
||||
}
|
||||
fn visit_expr(&mut self, ex:@Expr, env:bool) {
|
||||
|
@ -81,7 +81,7 @@ pub fn check_item(v: &mut CheckCrateVisitor,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_pat(v: &mut CheckCrateVisitor, p: @Pat, _is_const: bool) {
|
||||
pub fn check_pat(v: &mut CheckCrateVisitor, p: &Pat, _is_const: bool) {
|
||||
fn is_str(e: @Expr) -> bool {
|
||||
match e.node {
|
||||
ExprVstore(
|
||||
|
|
|
@ -900,7 +900,7 @@ fn check_unsafe_block(cx: &Context, e: &ast::Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_unused_mut_pat(cx: &Context, p: @ast::Pat) {
|
||||
fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) {
|
||||
match p.node {
|
||||
ast::PatIdent(ast::BindByValue(ast::MutMutable),
|
||||
ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> {
|
||||
|
@ -1119,7 +1119,7 @@ impl<'self> Visitor<()> for Context<'self> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, p: @ast::Pat, _: ()) {
|
||||
fn visit_pat(&mut self, p: &ast::Pat, _: ()) {
|
||||
check_pat_non_uppercase_statics(self, p);
|
||||
check_unused_mut_pat(self, p);
|
||||
|
||||
|
|
|
@ -459,8 +459,6 @@ impl VisitContext {
|
|||
}
|
||||
|
||||
ExprMatch(discr, ref arms) => {
|
||||
// We must do this first so that `arms_have_by_move_bindings`
|
||||
// below knows which bindings are moves.
|
||||
for arm in arms.iter() {
|
||||
self.consume_arm(arm);
|
||||
}
|
||||
|
@ -657,27 +655,6 @@ impl VisitContext {
|
|||
self.consume_expr(arg_expr)
|
||||
}
|
||||
|
||||
pub fn arms_have_by_move_bindings(&mut self,
|
||||
moves_map: MovesMap,
|
||||
arms: &[Arm])
|
||||
-> Option<@Pat> {
|
||||
let mut ret = None;
|
||||
for arm in arms.iter() {
|
||||
for &pat in arm.pats.iter() {
|
||||
let cont = do ast_util::walk_pat(pat) |p| {
|
||||
if moves_map.contains(&p.id) {
|
||||
ret = Some(p);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
};
|
||||
if !cont { return ret }
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn compute_captures(&mut self, fn_expr_id: NodeId) -> @[CaptureVar] {
|
||||
debug!("compute_capture_vars(fn_expr_id={:?})", fn_expr_id);
|
||||
let _indenter = indenter();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -739,7 +739,7 @@ impl<'self> Visitor<()> for PrivacyVisitor<'self> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pattern: @ast::Pat, _: ()) {
|
||||
fn visit_pat(&mut self, pattern: &ast::Pat, _: ()) {
|
||||
match pattern.node {
|
||||
ast::PatStruct(_, ref fields, _) => {
|
||||
match ty::get(ty::pat_ty(self.tcx, pattern)).sty {
|
||||
|
|
|
@ -340,7 +340,7 @@ fn resolve_arm(visitor: &mut RegionResolutionVisitor,
|
|||
}
|
||||
|
||||
fn resolve_pat(visitor: &mut RegionResolutionVisitor,
|
||||
pat: @ast::Pat,
|
||||
pat: &ast::Pat,
|
||||
cx: Context) {
|
||||
assert_eq!(cx.var_parent, cx.parent);
|
||||
parent_to_expr(visitor, cx, pat.id, pat.span);
|
||||
|
@ -480,7 +480,7 @@ impl Visitor<Context> for RegionResolutionVisitor {
|
|||
fn visit_arm(&mut self, a:&Arm, cx:Context) {
|
||||
resolve_arm(self, a, cx);
|
||||
}
|
||||
fn visit_pat(&mut self, p:@Pat, cx:Context) {
|
||||
fn visit_pat(&mut self, p:&Pat, cx:Context) {
|
||||
resolve_pat(self, p, cx);
|
||||
}
|
||||
fn visit_stmt(&mut self, s:@Stmt, cx:Context) {
|
||||
|
|
|
@ -375,7 +375,7 @@ impl Visitor<()> for GatherLocalsVisitor {
|
|||
|
||||
}
|
||||
// Add pattern bindings.
|
||||
fn visit_pat(&mut self, p:@ast::Pat, _:()) {
|
||||
fn visit_pat(&mut self, p:&ast::Pat, _:()) {
|
||||
match p.node {
|
||||
ast::PatIdent(_, ref path, _)
|
||||
if pat_util::pat_is_binding(self.fcx.ccx.tcx.def_map, p) => {
|
||||
|
|
|
@ -278,7 +278,7 @@ fn visit_block(b: &ast::Block, wbcx: &mut WbCtxt) {
|
|||
visit::walk_block(wbcx, b, ());
|
||||
}
|
||||
|
||||
fn visit_pat(p: @ast::Pat, wbcx: &mut WbCtxt) {
|
||||
fn visit_pat(p: &ast::Pat, wbcx: &mut WbCtxt) {
|
||||
if !wbcx.success {
|
||||
return;
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ impl Visitor<()> for WbCtxt {
|
|||
fn visit_stmt(&mut self, s:@ast::Stmt, _:()) { visit_stmt(s, self); }
|
||||
fn visit_expr(&mut self, ex:@ast::Expr, _:()) { visit_expr(ex, self); }
|
||||
fn visit_block(&mut self, b:&ast::Block, _:()) { visit_block(b, self); }
|
||||
fn visit_pat(&mut self, p:@ast::Pat, _:()) { visit_pat(p, self); }
|
||||
fn visit_pat(&mut self, p:&ast::Pat, _:()) { visit_pat(p, self); }
|
||||
fn visit_local(&mut self, l:@ast::Local, _:()) { visit_local(l, self); }
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ impl Ctx {
|
|||
visit::walk_block(self, b, ());
|
||||
}
|
||||
|
||||
fn map_pat(&mut self, pat: @Pat) {
|
||||
fn map_pat(&mut self, pat: &Pat) {
|
||||
match pat.node {
|
||||
PatIdent(_, ref path, _) => {
|
||||
// Note: this is at least *potentially* a pattern...
|
||||
|
@ -345,7 +345,7 @@ impl Visitor<()> for Ctx {
|
|||
self.path.pop();
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: @Pat, _: ()) {
|
||||
fn visit_pat(&mut self, pat: &Pat, _: ()) {
|
||||
self.map_pat(pat);
|
||||
visit::walk_pat(self, pat, ())
|
||||
}
|
||||
|
|
|
@ -497,7 +497,7 @@ impl<'self, O: IdVisitingOperation> Visitor<()> for IdVisitor<'self, O> {
|
|||
visit::walk_stmt(self, statement, env)
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pattern: @Pat, env: ()) {
|
||||
fn visit_pat(&mut self, pattern: &Pat, env: ()) {
|
||||
self.operation.visit_id(pattern.id);
|
||||
visit::walk_pat(self, pattern, env)
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -612,7 +612,7 @@ struct NewNameFinderContext {
|
|||
}
|
||||
|
||||
impl Visitor<()> for NewNameFinderContext {
|
||||
fn visit_pat(&mut self, pattern: @ast::Pat, _: ()) {
|
||||
fn visit_pat(&mut self, pattern: &ast::Pat, _: ()) {
|
||||
match *pattern {
|
||||
// we found a pat_ident!
|
||||
ast::Pat {
|
||||
|
|
|
@ -78,7 +78,7 @@ pub trait Visitor<E:Clone> {
|
|||
fn visit_block(&mut self, b:&Block, e:E) { walk_block(self, b, e) }
|
||||
fn visit_stmt(&mut self, s:@Stmt, e:E) { walk_stmt(self, s, e) }
|
||||
fn visit_arm(&mut self, a:&Arm, e:E) { walk_arm(self, a, e) }
|
||||
fn visit_pat(&mut self, p:@Pat, e:E) { walk_pat(self, p, e) }
|
||||
fn visit_pat(&mut self, p:&Pat, e:E) { walk_pat(self, p, e) }
|
||||
fn visit_decl(&mut self, d:@Decl, e:E) { walk_decl(self, d, e) }
|
||||
fn visit_expr(&mut self, ex:@Expr, e:E) { walk_expr(self, ex, e) }
|
||||
fn visit_expr_post(&mut self, _ex:@Expr, _e:E) { }
|
||||
|
|
Loading…
Reference in New Issue