Skip to content

Commit

Permalink
parse regions on unsafe pointers (rust-lang#7694)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Jul 23, 2013
1 parent 4f206cf commit a972633
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,9 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
_ => ()
}
}
ast::ty_ptr(ref mt) => { check_ty(cx, mt.ty) }
ast::ty_ptr(_, ref mt) => {
check_ty(cx, mt.ty)
}
_ => ()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ fn determine_rp_in_ty(ty: &ast::Ty,

match ty.node {
ast::ty_box(ref mt) | ast::ty_uniq(ref mt) | ast::ty_vec(ref mt) |
ast::ty_rptr(_, ref mt) | ast::ty_ptr(ref mt) => {
ast::ty_rptr(_, ref mt) | ast::ty_ptr(_, ref mt) => {
visit_mt(mt, (cx, visitor));
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Clone + 'static>(
// return /something/ so they can at least get more errors
ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, mt), ty::vstore_uniq)
}
ast::ty_ptr(ref mt) => {
ast::ty_ptr(_, ref mt) => {
ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt))
}
ast::ty_rptr(ref region, ref mt) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ pub enum ty_ {
ty_uniq(mt),
ty_vec(mt),
ty_fixed_length_vec(mt, @expr),
ty_ptr(mt),
ty_ptr(Option<Lifetime>, mt),
ty_rptr(Option<Lifetime>, mt),
ty_closure(@TyClosure),
ty_bare_fn(@TyBareFn),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
ty_box(ref mt) => ty_box(fold_mt(mt, fld)),
ty_uniq(ref mt) => ty_uniq(fold_mt(mt, fld)),
ty_vec(ref mt) => ty_vec(fold_mt(mt, fld)),
ty_ptr(ref mt) => ty_ptr(fold_mt(mt, fld)),
ty_ptr(region, ref mt) => ty_ptr(region, fold_mt(mt, fld)),
ty_rptr(region, ref mt) => ty_rptr(region, fold_mt(mt, fld)),
ty_closure(ref f) => {
ty_closure(@TyClosure {
Expand Down
15 changes: 10 additions & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ impl Parser {
} else if *self.token == token::BINOP(token::STAR) {
// STAR POINTER (bare pointer?)
self.bump();
ty_ptr(self.parse_mt())
self.parse_star_pointee()
} else if *self.token == token::LBRACE {
// STRUCTURAL RECORD (remove?)
let elems = self.parse_unspanned_seq(
Expand Down Expand Up @@ -1084,16 +1084,21 @@ impl Parser {
ctor(mt)
}

pub fn parse_star_pointee(&self) -> ty_ {
// look for `*'lt` or `*'foo ` and interpret `foo` as the region name:
let opt_lifetime = self.parse_opt_lifetime();
ty_ptr(opt_lifetime, self.parse_mt())
}

pub fn parse_borrowed_pointee(&self) -> ty_ {
// look for `&'lt` or `&'foo ` and interpret `foo` as the region name:
let opt_lifetime = self.parse_opt_lifetime();

if self.token_is_closure_keyword(self.token) {
return self.parse_ty_closure(BorrowedSigil, opt_lifetime);
self.parse_ty_closure(BorrowedSigil, opt_lifetime)
} else {
ty_rptr(opt_lifetime, self.parse_mt())
}

let mt = self.parse_mt();
return ty_rptr(opt_lifetime, mt);
}

// parse an optional, obsolete argument mode.
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ pub fn print_type(s: @ps, ty: &ast::Ty) {
print_type(s, mt.ty);
word(s.s, "]");
}
ast::ty_ptr(ref mt) => { word(s.s, "*"); print_mt(s, mt); }
ast::ty_ptr(ref lifetime, ref mt) => {
word(s.s, "*");
print_opt_lifetime(s, lifetime);
print_mt(s, mt);
}
ast::ty_rptr(ref lifetime, ref mt) => {
word(s.s, "&");
print_opt_lifetime(s, lifetime);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub fn skip_ty<E>(_t: &Ty, (_e,_v): (E, vt<E>)) {}
pub fn visit_ty<E:Clone>(t: &Ty, (e, v): (E, vt<E>)) {
match t.node {
ty_box(ref mt) | ty_uniq(ref mt) |
ty_vec(ref mt) | ty_ptr(ref mt) | ty_rptr(_, ref mt) => {
ty_vec(ref mt) | ty_ptr(_, ref mt) | ty_rptr(_, ref mt) => {
(v.visit_ty)(mt.ty, (e, v));
},
ty_tup(ref ts) => {
Expand Down

0 comments on commit a972633

Please sign in to comment.