]> git.lizzy.rs Git - rust.git/commitdiff
libsyntax/librustc: Allow specifying mut on ~self.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Sun, 20 Oct 2013 06:34:01 +0000 (02:34 -0400)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Wed, 23 Oct 2013 01:22:19 +0000 (21:22 -0400)
src/librustc/metadata/decoder.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/liveness.rs
src/librustc/middle/resolve.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/method.rs
src/librustdoc/clean.rs
src/libsyntax/ast.rs
src/libsyntax/ext/deriving/ty.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs

index ca1912c834769f5e6b8911c65367a7ac1df083ad..10232730329427165e7221a768cc2228ea6727f0 100644 (file)
@@ -977,7 +977,7 @@ fn get_mutability(ch: u8) -> ast::Mutability {
         's' => { return ast::sty_static; }
         'v' => { return ast::sty_value(get_mutability(string[1])); }
         '@' => { return ast::sty_box(get_mutability(string[1])); }
-        '~' => { return ast::sty_uniq; }
+        '~' => { return ast::sty_uniq(get_mutability(string[1])); }
         '&' => {
             // FIXME(#4846) expl. region
             return ast::sty_region(None, get_mutability(string[1]));
index 0f5ce06a7daaa62f97bf7d3a339c715d726d5fbf..bae0dcc2a5203e576c8a1f7cdfa9085749d0f3cb 100644 (file)
@@ -675,8 +675,9 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explic
             ebml_w.writer.write(&[ '@' as u8 ]);
             encode_mutability(ebml_w, m);
         }
-        sty_uniq => {
+        sty_uniq(m) => {
             ebml_w.writer.write(&[ '~' as u8 ]);
+            encode_mutability(ebml_w, m);
         }
     }
 
index a235d7395a6db9ff296f62c730030c95acfb356c..71934c9f2a7ed93db87d3a2cd125009c32d4f400 100644 (file)
@@ -392,7 +392,7 @@ fn visit_fn(v: &mut LivenessVisitor,
     match *fk {
         visit::fk_method(_, _, method) => {
             match method.explicit_self.node {
-                sty_value(_) | sty_region(*) | sty_box(_) | sty_uniq => {
+                sty_value(_) | sty_region(*) | sty_box(_) | sty_uniq(_) => {
                     fn_maps.add_variable(Arg(method.self_id,
                                              special_idents::self_));
                 }
index 4c5d2f86a1b202ab8c0cf0a69126348c5fc88724..ee36b807ac79c358311f26e9524d3efc4ca0853b 100644 (file)
@@ -3801,7 +3801,7 @@ fn resolve_function(&mut self,
                 }
                 HasSelfBinding(self_node_id, explicit_self) => {
                     let mutable = match explicit_self.node {
-                        sty_value(m) if m == MutMutable => true,
+                        sty_uniq(m) | sty_value(m) if m == MutMutable => true,
                         _ => false
                     };
                     let def_like = DlDef(DefSelf(self_node_id, mutable));
index e703f6da4168e9e1b0763fa1eb3415b634ddef0e..dd0c6c12a69aacf3077fdf7f683562ef7ab956ae 100644 (file)
@@ -689,7 +689,7 @@ fn transform_self_ty<AC:AstConv,RS:RegionScope + Clone + 'static>(
                                 ty::mt {ty: self_info.untransformed_self_ty,
                                         mutbl: mutability}))
             }
-            ast::sty_uniq => {
+            ast::sty_uniq(_) => {
                 Some(ty::mk_uniq(this.tcx(),
                                  ty::mt {ty: self_info.untransformed_self_ty,
                                          mutbl: ast::MutImmutable}))
index b48e1f7fcf1577b867c249ca4bf9ad737fcd9b8e..af1d5ce3cc608afc5b62ea8944b027566d468921 100644 (file)
@@ -1236,7 +1236,7 @@ fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool {
                 }
             }
 
-            sty_uniq => {
+            sty_uniq(_) => {
                 debug!("(is relevant?) explicit self is a unique pointer");
                 match ty::get(rcvr_ty).sty {
                     ty::ty_uniq(mt) => {
index 90fc71aa863542a40247aa78ad14ffd9d8f8e1b5..dd1ad8263da860c2d1eb6d9864f6ffc2a8244855 100644 (file)
@@ -389,7 +389,7 @@ fn clean(&self) -> SelfTy {
         match self.node {
             ast::sty_static => SelfStatic,
             ast::sty_value(_) => SelfValue,
-            ast::sty_uniq => SelfOwned,
+            ast::sty_uniq(_) => SelfOwned,
             ast::sty_region(lt, mt) => SelfBorrowed(lt.clean(), mt.clean()),
             ast::sty_box(mt) => SelfManaged(mt.clean()),
         }
index 6631924239d3b10779fe8c9359db075628959ddc..372f1950c1de0047979beff35f0f4eb80999cb83 100644 (file)
@@ -924,7 +924,7 @@ pub enum explicit_self_ {
     sty_value(Mutability),                     // `self`
     sty_region(Option<Lifetime>, Mutability),  // `&'lt self`
     sty_box(Mutability),                       // `@self`
-    sty_uniq                                   // `~self`
+    sty_uniq(Mutability)                       // `~self`
 }
 
 pub type explicit_self = Spanned<explicit_self_>;
index a9fdafc80141662efbd17aa4f3465208bc3d6868..c60259304aef23cac3baea73919089ceff543ee4 100644 (file)
@@ -246,7 +246,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: Span, self_ptr: &Option<PtrTy>)
             let self_ty = respan(
                 span,
                 match *ptr {
-                    Send => ast::sty_uniq,
+                    Send => ast::sty_uniq(ast::MutImmutable),
                     Managed(mutbl) => ast::sty_box(mutbl),
                     Borrowed(ref lt, mutbl) => {
                         let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s)));
index 133934a746a1123e5d58d6ded6a903bba0173355..605e259cf0c2b2e89e18cada2eecd75b9b436296 100644 (file)
@@ -3520,7 +3520,7 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
                     self.span_err(*self.last_span,
                                   "mutability declaration not allowed here");
                 }
-                sty_uniq
+                sty_uniq(MutImmutable)
             }, self)
           }
           token::IDENT(*) if self.is_self_ident() => {
@@ -3546,6 +3546,14 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
             self.expect_self_ident();
             sty_value(mutability)
           }
+          _ if self.token_is_mutability(self.token) &&
+               self.look_ahead(1, |t| *t == token::TILDE) &&
+               self.look_ahead(2, |t| token::is_keyword(keywords::Self, t)) => {
+            let mutability = self.parse_mutability();
+            self.bump();
+            self.expect_self_ident();
+            sty_uniq(mutability)
+          }
           _ => {
             sty_static
           }
index 9ce28e4d55a8ae998e23553dd7f6aa52140a9a92..0e330da31e6235915279d8a1b062ea05d9709c9d 100644 (file)
@@ -1690,7 +1690,10 @@ pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
             print_mutability(s, m);
             word(s.s, "self");
         }
-        ast::sty_uniq => { word(s.s, "~self"); }
+        ast::sty_uniq(m) => {
+            print_mutability(s, m);
+            word(s.s, "~self");
+        }
         ast::sty_region(ref lt, m) => {
             word(s.s, "&");
             print_opt_lifetime(s, lt);