libsyntax/librustc: Allow specifying mut on ~self.

This commit is contained in:
Luqman Aden 2013-10-20 02:34:01 -04:00
parent 5754848f8c
commit af163579ed
11 changed files with 23 additions and 11 deletions

View File

@ -977,7 +977,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
'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]));

View 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);
}
}

View 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_));
}

View File

@ -3801,7 +3801,7 @@ impl Resolver {
}
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));

View File

@ -689,7 +689,7 @@ fn ty_of_method_or_bare_fn<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}))

View File

@ -1236,7 +1236,7 @@ impl<'self> LookupContext<'self> {
}
}
sty_uniq => {
sty_uniq(_) => {
debug!("(is relevant?) explicit self is a unique pointer");
match ty::get(rcvr_ty).sty {
ty::ty_uniq(mt) => {

View File

@ -389,7 +389,7 @@ impl Clean<SelfTy> for ast::explicit_self {
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()),
}

View 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_>;

View 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)));

View File

@ -3520,7 +3520,7 @@ impl Parser {
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 @@ impl Parser {
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
}

View 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);