summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-01-03 15:08:48 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-01-13 14:45:21 -0800
commit119c6141f568b8b5bca141b24d3cbd3e1aacb2c7 (patch)
treedd7f94c989ed3b4f59408e84577deab696b73930 /src/libsyntax
parentce358fca333db7bc0ac1bffa1daa13099b2561d8 (diff)
downloadrust-119c6141f568b8b5bca141b24d3cbd3e1aacb2c7.tar.gz
rust-119c6141f568b8b5bca141b24d3cbd3e1aacb2c7.zip
librustc: Remove `@` pointer patterns from the language
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs1
-rw-r--r--src/libsyntax/ast_map.rs8
-rw-r--r--src/libsyntax/ast_util.rs11
-rw-r--r--src/libsyntax/ext/base.rs7
-rw-r--r--src/libsyntax/ext/expand.rs115
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs16
-rw-r--r--src/libsyntax/fold.rs1
-rw-r--r--src/libsyntax/parse/parser.rs120
-rw-r--r--src/libsyntax/print/pprust.rs8
-rw-r--r--src/libsyntax/visit.rs1
10 files changed, 151 insertions, 137 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index ef348e52f6e..ab16ab153d9 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -369,7 +369,6 @@ pub enum Pat_ {
                                        * we don't bind the fields to names */
     PatStruct(Path, ~[FieldPat], bool),
     PatTup(~[@Pat]),
-    PatBox(@Pat),
     PatUniq(@Pat),
     PatRegion(@Pat), // reference pattern
     PatLit(@Expr),
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs
index 0f5737d775e..9cb4f14caf0 100644
--- a/src/libsyntax/ast_map.rs
+++ b/src/libsyntax/ast_map.rs
@@ -507,8 +507,12 @@ pub fn node_span(items: Map, id: ast::NodeId) -> Span {
     match items.get().find(&id) {
         Some(&NodeItem(item, _)) => item.span,
         Some(&NodeForeignItem(foreign_item, _, _, _)) => foreign_item.span,
-        Some(&NodeTraitMethod(@Required(ref type_method), _, _)) => type_method.span,
-        Some(&NodeTraitMethod(@Provided(ref method), _, _)) => method.span,
+        Some(&NodeTraitMethod(trait_method, _, _)) => {
+            match *trait_method {
+                Required(ref type_method) => type_method.span,
+                Provided(ref method) => method.span,
+            }
+        }
         Some(&NodeMethod(method, _, _)) => method.span,
         Some(&NodeVariant(variant, _, _)) => variant.span,
         Some(&NodeExpr(expr)) => expr.span,
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index c8c9cb4d247..3e0caab65c2 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -614,7 +614,7 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
         PatEnum(_, Some(ref s)) | PatTup(ref s) => {
             s.iter().advance(|&p| walk_pat(p, |p| it(p)))
         }
-        PatBox(s) | PatUniq(s) | PatRegion(s) => {
+        PatUniq(s) | PatRegion(s) => {
             walk_pat(s, it)
         }
         PatVec(ref before, ref slice, ref after) => {
@@ -945,6 +945,15 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo
     }
 }
 
+// Returns true if this literal is a string and false otherwise.
+pub fn lit_is_str(lit: @Lit) -> bool {
+    match lit.node {
+        LitStr(..) => true,
+        _ => false,
+    }
+}
+
+
 #[cfg(test)]
 mod test {
     use ast::*;
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 76135f31e31..8515c3aba50 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -324,7 +324,7 @@ impl ExtCtxt {
     pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
     pub fn call_site(&self) -> Span {
         match self.backtrace {
-            Some(@ExpnInfo {call_site: cs, ..}) => cs,
+            Some(expn_info) => expn_info.call_site,
             None => self.bug("missing top span")
         }
     }
@@ -346,10 +346,7 @@ impl ExtCtxt {
     }
     pub fn bt_pop(&mut self) {
         match self.backtrace {
-            Some(@ExpnInfo {
-                call_site: Span {expn_info: prev, ..}, ..}) => {
-                self.backtrace = prev
-            }
+            Some(expn_info) => self.backtrace = expn_info.call_site.expn_info,
             _ => self.bug("tried to pop without a push")
         }
     }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index a9cf807ff65..303277afbe8 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -471,63 +471,66 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
                          -> SmallVector<@Stmt> {
     // is it a let?
     match s.node {
-        StmtDecl(@Spanned {
-            node: DeclLocal(ref local),
-            span: stmt_span
-        },
-        node_id) => {
-
-            // take it apart:
-            let @Local {
-                ty: _,
-                pat: pat,
-                init: init,
-                id: id,
-                span: span
-            } = *local;
-            // expand the pat (it might contain exprs... #:(o)>
-            let expanded_pat = fld.fold_pat(pat);
-            // find the pat_idents in the pattern:
-            // oh dear heaven... this is going to include the enum names, as well....
-            // ... but that should be okay, as long as the new names are gensyms
-            // for the old ones.
-            let mut name_finder = new_name_finder(~[]);
-            name_finder.visit_pat(expanded_pat,());
-            // generate fresh names, push them to a new pending list
-            let mut new_pending_renames = ~[];
-            for ident in name_finder.ident_accumulator.iter() {
-                let new_name = fresh_name(ident);
-                new_pending_renames.push((*ident,new_name));
-            }
-            let rewritten_pat = {
-                let mut rename_fld =
-                    renames_to_fold(&mut new_pending_renames);
-                // rewrite the pattern using the new names (the old ones
-                // have already been applied):
-                rename_fld.fold_pat(expanded_pat)
-            };
-            // add them to the existing pending renames:
-            for pr in new_pending_renames.iter() {
-                fld.extsbox.info().pending_renames.push(*pr)
+        StmtDecl(decl, node_id) => {
+            match *decl {
+                Spanned {
+                    node: DeclLocal(ref local),
+                    span: stmt_span
+                } => {
+                    // take it apart:
+                    let Local {
+                        ty: _,
+                        pat: pat,
+                        init: init,
+                        id: id,
+                        span: span
+                    } = **local;
+                    // expand the pat (it might contain exprs... #:(o)>
+                    let expanded_pat = fld.fold_pat(pat);
+                    // find the pat_idents in the pattern:
+                    // oh dear heaven... this is going to include the enum
+                    // names, as well... but that should be okay, as long as
+                    // the new names are gensyms for the old ones.
+                    let mut name_finder = new_name_finder(~[]);
+                    name_finder.visit_pat(expanded_pat,());
+                    // generate fresh names, push them to a new pending list
+                    let mut new_pending_renames = ~[];
+                    for ident in name_finder.ident_accumulator.iter() {
+                        let new_name = fresh_name(ident);
+                        new_pending_renames.push((*ident,new_name));
+                    }
+                    let rewritten_pat = {
+                        let mut rename_fld =
+                            renames_to_fold(&mut new_pending_renames);
+                        // rewrite the pattern using the new names (the old
+                        // ones have already been applied):
+                        rename_fld.fold_pat(expanded_pat)
+                    };
+                    // add them to the existing pending renames:
+                    for pr in new_pending_renames.iter() {
+                        fld.extsbox.info().pending_renames.push(*pr)
+                    }
+                    // also, don't forget to expand the init:
+                    let new_init_opt = init.map(|e| fld.fold_expr(e));
+                    let rewritten_local =
+                        @Local {
+                            ty: local.ty,
+                            pat: rewritten_pat,
+                            init: new_init_opt,
+                            id: id,
+                            span: span,
+                        };
+                    SmallVector::one(@Spanned {
+                        node: StmtDecl(@Spanned {
+                                node: DeclLocal(rewritten_local),
+                                span: stmt_span
+                            },
+                            node_id),
+                        span: span
+                    })
+                }
+                _ => noop_fold_stmt(s, fld),
             }
-            // also, don't forget to expand the init:
-            let new_init_opt = init.map(|e| fld.fold_expr(e));
-            let rewritten_local =
-                @Local {
-                    ty: local.ty,
-                    pat: rewritten_pat,
-                    init: new_init_opt,
-                    id: id,
-                    span: span,
-                };
-            SmallVector::one(@Spanned {
-                node: StmtDecl(@Spanned {
-                        node: DeclLocal(rewritten_local),
-                        span: stmt_span
-                    },
-                    node_id),
-                span: span
-            })
         },
         _ => noop_fold_stmt(s, fld),
     }
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index dc5eb0e9537..cb7d54d7305 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -126,15 +126,15 @@ fn generic_extension(cx: &ExtCtxt,
     let s_d = cx.parse_sess().span_diagnostic;
 
     for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
-        match *lhs {
-          @MatchedNonterminal(NtMatchers(ref mtcs)) => {
+        match **lhs {
+          MatchedNonterminal(NtMatchers(ref mtcs)) => {
             // `none` is because we're not interpolating
             let arg_rdr = new_tt_reader(s_d, None, arg.to_owned()) as @Reader;
             match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) {
               Success(named_matches) => {
-                let rhs = match rhses[i] {
+                let rhs = match *rhses[i] {
                     // okay, what's your transcriber?
-                    @MatchedNonterminal(NtTT(@ref tt)) => {
+                    MatchedNonterminal(NtTT(tt)) => {
                         match (*tt) {
                             // cut off delimiters; don't parse 'em
                             TTDelim(ref tts) => {
@@ -214,13 +214,13 @@ pub fn add_new_extension(cx: &mut ExtCtxt,
                                      argument_gram);
 
     // Extract the arguments:
-    let lhses = match *argument_map.get(&lhs_nm) {
-        @MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
+    let lhses = match **argument_map.get(&lhs_nm) {
+        MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
         _ => cx.span_bug(sp, "wrong-structured lhs")
     };
 
-    let rhses = match *argument_map.get(&rhs_nm) {
-        @MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
+    let rhses = match **argument_map.get(&rhs_nm) {
+        MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
         _ => cx.span_bug(sp, "wrong-structured rhs")
     };
 
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 409368ce3df..d3862cdf1a1 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -687,7 +687,6 @@ pub fn noop_fold_pat<T: Folder>(p: @Pat, folder: &mut T) -> @Pat {
             PatStruct(pth_, fs, etc)
         }
         PatTup(ref elts) => PatTup(elts.map(|x| folder.fold_pat(*x))),
-        PatBox(inner) => PatBox(folder.fold_pat(inner)),
         PatUniq(inner) => PatUniq(folder.fold_pat(inner)),
         PatRegion(inner) => PatRegion(folder.fold_pat(inner)),
         PatRange(e1, e2) => {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a71d5bf0e9e..715ce644726 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -40,7 +40,7 @@ use ast::{LitBool, LitFloat, LitFloatUnsuffixed, LitInt, LitChar};
 use ast::{LitIntUnsuffixed, LitNil, LitStr, LitUint, Local};
 use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal};
 use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
-use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatBox, PatEnum};
+use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
 use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct};
 use ast::{PatTup, PatUniq, PatWild, PatWildMulti, Private};
 use ast::{BiRem, Required};
@@ -60,7 +60,7 @@ use ast::{ViewItem_, ViewItemExternMod, ViewItemUse};
 use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
 use ast::Visibility;
 use ast;
-use ast_util::{as_prec, operator_prec};
+use ast_util::{as_prec, lit_is_str, operator_prec};
 use ast_util;
 use codemap::{Span, BytePos, Spanned, spanned, mk_sp};
 use codemap;
@@ -2278,10 +2278,10 @@ impl Parser {
                 hi = e.span.hi;
                 // HACK: turn &[...] into a &-vec
                 ex = match e.node {
-                  ExprVec(..) | ExprLit(@codemap::Spanned {
-                    node: LitStr(..), span: _
-                  })
-                  if m == MutImmutable => {
+                  ExprVec(..) if m == MutImmutable => {
+                    ExprVstore(e, ExprVstoreSlice)
+                  }
+                  ExprLit(lit) if lit_is_str(lit) && m == MutImmutable => {
                     ExprVstore(e, ExprVstoreSlice)
                   }
                   ExprVec(..) if m == MutMutable => {
@@ -2300,8 +2300,8 @@ impl Parser {
             // HACK: turn @[...] into a @-vec
             ex = match e.node {
               ExprVec(..) |
-              ExprLit(@codemap::Spanned { node: LitStr(..), span: _}) |
               ExprRepeat(..) => ExprVstore(e, ExprVstoreBox),
+              ExprLit(lit) if lit_is_str(lit) => ExprVstore(e, ExprVstoreBox),
               _ => self.mk_unary(UnBox, e)
             };
           }
@@ -2312,9 +2312,10 @@ impl Parser {
             hi = e.span.hi;
             // HACK: turn ~[...] into a ~-vec
             ex = match e.node {
-              ExprVec(..) |
-              ExprLit(@codemap::Spanned { node: LitStr(..), span: _}) |
-              ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq),
+              ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq),
+              ExprLit(lit) if lit_is_str(lit) => {
+                  ExprVstore(e, ExprVstoreUniq)
+              }
               _ => self.mk_unary(UnUniq, e)
             };
           }
@@ -2339,12 +2340,12 @@ impl Parser {
             hi = subexpression.span.hi;
             // HACK: turn `box [...]` into a boxed-vec
             ex = match subexpression.node {
-                ExprVec(..) |
-                ExprLit(@codemap::Spanned {
-                    node: LitStr(..),
-                    span: _
-                }) |
-                ExprRepeat(..) => ExprVstore(subexpression, ExprVstoreUniq),
+                ExprVec(..) | ExprRepeat(..) => {
+                    ExprVstore(subexpression, ExprVstoreUniq)
+                }
+                ExprLit(lit) if lit_is_str(lit) => {
+                    ExprVstore(subexpression, ExprVstoreUniq)
+                }
                 _ => self.mk_unary(UnUniq, subexpression)
             };
           }
@@ -2769,8 +2770,8 @@ impl Parser {
                     })
                 } else {
                     let subpat = self.parse_pat();
-                    match subpat {
-                        @ast::Pat { id, node: PatWild, span } => {
+                    match *subpat {
+                        ast::Pat { id, node: PatWild, span } => {
                             self.obsolete(self.span, ObsoleteVecDotDotWildcard);
                             slice = Some(@ast::Pat {
                                 id: id,
@@ -2778,10 +2779,10 @@ impl Parser {
                                 span: span
                             })
                         },
-                        @ast::Pat { node: PatIdent(_, _, _), .. } => {
+                        ast::Pat { node: PatIdent(_, _, _), .. } => {
                             slice = Some(subpat);
                         }
-                        @ast::Pat { span, .. } => self.span_fatal(
+                        ast::Pat { span, .. } => self.span_fatal(
                             span, "expected an identifier or nothing"
                         )
                     }
@@ -2891,21 +2892,25 @@ impl Parser {
             hi = sub.span.hi;
             // HACK: parse @"..." as a literal of a vstore @str
             pat = match sub.node {
-              PatLit(e@@Expr {
-                node: ExprLit(@codemap::Spanned {
-                    node: LitStr(..),
-                    span: _}), ..
-              }) => {
-                let vst = @Expr {
-                    id: ast::DUMMY_NODE_ID,
-                    node: ExprVstore(e, ExprVstoreBox),
-                    span: mk_sp(lo, hi),
-                };
-                PatLit(vst)
+              PatLit(e) => {
+                  match e.node {
+                      ExprLit(lit) if lit_is_str(lit) => {
+                        let vst = @Expr {
+                            id: ast::DUMMY_NODE_ID,
+                            node: ExprVstore(e, ExprVstoreBox),
+                            span: mk_sp(lo, hi),
+                        };
+                        PatLit(vst)
+                      }
+                      _ => {
+                        self.obsolete(self.span, ObsoleteManagedPattern);
+                        PatUniq(sub)
+                      }
+                  }
               }
               _ => {
                 self.obsolete(self.span, ObsoleteManagedPattern);
-                PatBox(sub)
+                PatUniq(sub)
               }
             };
             hi = self.last_span.hi;
@@ -2922,19 +2927,20 @@ impl Parser {
             hi = sub.span.hi;
             // HACK: parse ~"..." as a literal of a vstore ~str
             pat = match sub.node {
-              PatLit(e@@Expr {
-                node: ExprLit(@codemap::Spanned {
-                    node: LitStr(..),
-                    span: _}), ..
-              }) => {
-                let vst = @Expr {
-                    id: ast::DUMMY_NODE_ID,
-                    node: ExprVstore(e, ExprVstoreUniq),
-                    span: mk_sp(lo, hi),
-                };
-                PatLit(vst)
-              }
-              _ => PatUniq(sub)
+                PatLit(e) => {
+                    match e.node {
+                        ExprLit(lit) if lit_is_str(lit) => {
+                            let vst = @Expr {
+                                id: ast::DUMMY_NODE_ID,
+                                node: ExprVstore(e, ExprVstoreUniq),
+                                span: mk_sp(lo, hi),
+                            };
+                            PatLit(vst)
+                        }
+                        _ => PatUniq(sub)
+                    }
+                }
+                _ => PatUniq(sub)
             };
             hi = self.last_span.hi;
             return @ast::Pat {
@@ -2951,18 +2957,20 @@ impl Parser {
               hi = sub.span.hi;
               // HACK: parse &"..." as a literal of a borrowed str
               pat = match sub.node {
-                  PatLit(e@@Expr {
-                      node: ExprLit(@codemap::Spanned{ node: LitStr(..), .. }),
-                      ..
-                  }) => {
-                      let vst = @Expr {
-                          id: ast::DUMMY_NODE_ID,
-                          node: ExprVstore(e, ExprVstoreSlice),
-                          span: mk_sp(lo, hi)
-                      };
-                      PatLit(vst)
+                  PatLit(e) => {
+                      match e.node {
+                        ExprLit(lit) if lit_is_str(lit) => {
+                          let vst = @Expr {
+                              id: ast::DUMMY_NODE_ID,
+                              node: ExprVstore(e, ExprVstoreSlice),
+                              span: mk_sp(lo, hi)
+                          };
+                          PatLit(vst)
+                        }
+                        _ => PatRegion(sub),
+                      }
                   }
-              _ => PatRegion(sub)
+                  _ => PatRegion(sub),
             };
             hi = self.last_span.hi;
             return @ast::Pat {
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index ea9f0907b7a..b6db827f7b8 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1709,10 +1709,6 @@ pub fn print_pat(s: &mut State, pat: &ast::Pat) {
         }
         pclose(s);
       }
-      ast::PatBox(inner) => {
-          word(&mut s.s, "@");
-          print_pat(s, inner);
-      }
       ast::PatUniq(inner) => {
           word(&mut s.s, "~");
           print_pat(s, inner);
@@ -1733,8 +1729,8 @@ pub fn print_pat(s: &mut State, pat: &ast::Pat) {
         commasep(s, Inconsistent, *before, |s, &p| print_pat(s, p));
         for &p in slice.iter() {
             if !before.is_empty() { word_space(s, ","); }
-            match p {
-                @ast::Pat { node: ast::PatWildMulti, .. } => {
+            match *p {
+                ast::Pat { node: ast::PatWildMulti, .. } => {
                     // this case is handled by print_pat
                 }
                 _ => word(&mut s.s, ".."),
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index d5fb9efe59b..ffea4b6dc75 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -397,7 +397,6 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E)
                 visitor.visit_pat(*tuple_element, env.clone())
             }
         }
-        PatBox(subpattern) |
         PatUniq(subpattern) |
         PatRegion(subpattern) => {
             visitor.visit_pat(subpattern, env)