Skip to content

Commit ccd8498

Browse files
committed
syntax: fix fallout from using ptr::P.
1 parent d6fb338 commit ccd8498

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1529
-1688
lines changed

src/libsyntax/ast_map/blocks.rs

+41-41
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! for the `Code` associated with a particular NodeId.
2323
2424
use abi;
25-
use ast::{P, Block, FnDecl, NodeId};
25+
use ast::{Block, FnDecl, NodeId};
2626
use ast;
2727
use ast_map::{Node};
2828
use ast_map;
@@ -39,16 +39,16 @@ use visit;
3939
/// - The default implementation for a trait method.
4040
///
4141
/// To construct one, use the `Code::from_node` function.
42-
pub struct FnLikeNode { node: ast_map::Node }
42+
pub struct FnLikeNode<'a> { node: ast_map::Node<'a> }
4343

4444
/// MaybeFnLike wraps a method that indicates if an object
4545
/// corresponds to some FnLikeNode.
4646
pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
4747

4848
/// Components shared by fn-like things (fn items, methods, closures).
4949
pub struct FnParts<'a> {
50-
pub decl: P<FnDecl>,
51-
pub body: P<Block>,
50+
pub decl: &'a FnDecl,
51+
pub body: &'a Block,
5252
pub kind: visit::FnKind<'a>,
5353
pub span: Span,
5454
pub id: NodeId,
@@ -78,12 +78,12 @@ impl MaybeFnLike for ast::Expr {
7878
/// Carries either an FnLikeNode or a Block, as these are the two
7979
/// constructs that correspond to "code" (as in, something from which
8080
/// we can construct a control-flow graph).
81-
pub enum Code {
82-
FnLikeCode(FnLikeNode),
83-
BlockCode(P<Block>),
81+
pub enum Code<'a> {
82+
FnLikeCode(FnLikeNode<'a>),
83+
BlockCode(&'a Block),
8484
}
8585

86-
impl Code {
86+
impl<'a> Code<'a> {
8787
pub fn id(&self) -> ast::NodeId {
8888
match *self {
8989
FnLikeCode(node) => node.id(),
@@ -115,32 +115,32 @@ impl Code {
115115
/// use when implementing FnLikeNode operations.
116116
struct ItemFnParts<'a> {
117117
ident: ast::Ident,
118-
decl: P<ast::FnDecl>,
118+
decl: &'a ast::FnDecl,
119119
style: ast::FnStyle,
120120
abi: abi::Abi,
121121
generics: &'a ast::Generics,
122-
body: P<Block>,
122+
body: &'a Block,
123123
id: ast::NodeId,
124124
span: Span
125125
}
126126

127127
/// These are all the components one can extract from a closure expr
128128
/// for use when implementing FnLikeNode operations.
129-
struct ClosureParts {
130-
decl: P<FnDecl>,
131-
body: P<Block>,
129+
struct ClosureParts<'a> {
130+
decl: &'a FnDecl,
131+
body: &'a Block,
132132
id: NodeId,
133133
span: Span
134134
}
135135

136-
impl ClosureParts {
137-
fn new(d: P<FnDecl>, b: P<Block>, id: NodeId, s: Span) -> ClosureParts {
136+
impl<'a> ClosureParts<'a> {
137+
fn new(d: &'a FnDecl, b: &'a Block, id: NodeId, s: Span) -> ClosureParts<'a> {
138138
ClosureParts { decl: d, body: b, id: id, span: s }
139139
}
140140
}
141141

142-
impl FnLikeNode {
143-
pub fn to_fn_parts<'a>(&'a self) -> FnParts<'a> {
142+
impl<'a> FnLikeNode<'a> {
143+
pub fn to_fn_parts(self) -> FnParts<'a> {
144144
FnParts {
145145
decl: self.decl(),
146146
body: self.body(),
@@ -150,31 +150,31 @@ impl FnLikeNode {
150150
}
151151
}
152152

153-
pub fn body<'a>(&'a self) -> P<Block> {
154-
self.handle(|i: ItemFnParts| i.body,
155-
|m: &'a ast::Method| m.pe_body(),
156-
|c: ClosureParts| c.body)
153+
pub fn body(self) -> &'a Block {
154+
self.handle(|i: ItemFnParts<'a>| &*i.body,
155+
|m: &'a ast::Method| m.pe_body(),
156+
|c: ClosureParts<'a>| c.body)
157157
}
158158

159-
pub fn decl<'a>(&'a self) -> P<FnDecl> {
160-
self.handle(|i: ItemFnParts| i.decl,
161-
|m: &'a ast::Method| m.pe_fn_decl(),
162-
|c: ClosureParts| c.decl)
159+
pub fn decl(self) -> &'a FnDecl {
160+
self.handle(|i: ItemFnParts<'a>| &*i.decl,
161+
|m: &'a ast::Method| m.pe_fn_decl(),
162+
|c: ClosureParts<'a>| c.decl)
163163
}
164164

165-
pub fn span<'a>(&'a self) -> Span {
165+
pub fn span(self) -> Span {
166166
self.handle(|i: ItemFnParts| i.span,
167167
|m: &'a ast::Method| m.span,
168168
|c: ClosureParts| c.span)
169169
}
170170

171-
pub fn id<'a>(&'a self) -> NodeId {
171+
pub fn id(self) -> NodeId {
172172
self.handle(|i: ItemFnParts| i.id,
173173
|m: &'a ast::Method| m.id,
174174
|c: ClosureParts| c.id)
175175
}
176176

177-
pub fn kind<'a>(&'a self) -> visit::FnKind<'a> {
177+
pub fn kind(self) -> visit::FnKind<'a> {
178178
let item = |p: ItemFnParts<'a>| -> visit::FnKind<'a> {
179179
visit::FkItemFn(p.ident, p.generics, p.style, p.abi)
180180
};
@@ -187,33 +187,33 @@ impl FnLikeNode {
187187
self.handle(item, method, closure)
188188
}
189189

190-
fn handle<'a, A>(&'a self,
191-
item_fn: |ItemFnParts<'a>| -> A,
192-
method: |&'a ast::Method| -> A,
193-
closure: |ClosureParts| -> A) -> A {
190+
fn handle<A>(self,
191+
item_fn: |ItemFnParts<'a>| -> A,
192+
method: |&'a ast::Method| -> A,
193+
closure: |ClosureParts<'a>| -> A) -> A {
194194
match self.node {
195-
ast_map::NodeItem(ref i) => match i.node {
196-
ast::ItemFn(decl, style, abi, ref generics, block) =>
195+
ast_map::NodeItem(i) => match i.node {
196+
ast::ItemFn(ref decl, style, abi, ref generics, ref block) =>
197197
item_fn(ItemFnParts{
198-
ident: i.ident, decl: decl, style: style, body: block,
198+
ident: i.ident, decl: &**decl, style: style, body: &**block,
199199
generics: generics, abi: abi, id: i.id, span: i.span
200200
}),
201201
_ => fail!("item FnLikeNode that is not fn-like"),
202202
},
203-
ast_map::NodeTraitItem(ref t) => match **t {
203+
ast_map::NodeTraitItem(t) => match *t {
204204
ast::ProvidedMethod(ref m) => method(&**m),
205205
_ => fail!("trait method FnLikeNode that is not fn-like"),
206206
},
207-
ast_map::NodeImplItem(ref ii) => {
208-
match **ii {
207+
ast_map::NodeImplItem(ii) => {
208+
match *ii {
209209
ast::MethodImplItem(ref m) => method(&**m),
210210
}
211211
}
212-
ast_map::NodeExpr(ref e) => match e.node {
212+
ast_map::NodeExpr(e) => match e.node {
213213
ast::ExprFnBlock(_, ref decl, ref block) =>
214-
closure(ClosureParts::new(*decl, *block, e.id, e.span)),
214+
closure(ClosureParts::new(&**decl, &**block, e.id, e.span)),
215215
ast::ExprProc(ref decl, ref block) =>
216-
closure(ClosureParts::new(*decl, *block, e.id, e.span)),
216+
closure(ClosureParts::new(&**decl, &**block, e.id, e.span)),
217217
_ => fail!("expr FnLikeNode that is not fn-like"),
218218
},
219219
_ => fail!("other FnLikeNode that is not fn-like"),

src/libsyntax/ast_util.rs

+15-101
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use codemap::Span;
1919
use owned_slice::OwnedSlice;
2020
use parse::token;
2121
use print::pprust;
22+
use ptr::P;
2223
use visit::Visitor;
2324
use visit;
2425

2526
use std::cell::Cell;
2627
use std::cmp;
27-
use std::gc::{Gc, GC};
2828
use std::u32;
2929

3030
pub fn path_name_i(idents: &[Ident]) -> String {
@@ -98,7 +98,7 @@ pub fn unop_to_string(op: UnOp) -> &'static str {
9898
}
9999
}
100100

101-
pub fn is_path(e: Gc<Expr>) -> bool {
101+
pub fn is_path(e: P<Expr>) -> bool {
102102
return match e.node { ExprPath(_) => true, _ => false };
103103
}
104104

@@ -166,21 +166,6 @@ pub fn float_ty_to_string(t: FloatTy) -> String {
166166
}
167167
}
168168

169-
pub fn is_call_expr(e: Gc<Expr>) -> bool {
170-
match e.node { ExprCall(..) => true, _ => false }
171-
}
172-
173-
pub fn block_from_expr(e: Gc<Expr>) -> P<Block> {
174-
P(Block {
175-
view_items: Vec::new(),
176-
stmts: Vec::new(),
177-
expr: Some(e),
178-
id: e.id,
179-
rules: DefaultBlock,
180-
span: e.span
181-
})
182-
}
183-
184169
// convert a span and an identifier to the corresponding
185170
// 1-segment path
186171
pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
@@ -197,10 +182,12 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
197182
}
198183
}
199184

200-
pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> Gc<Pat> {
201-
box(GC) ast::Pat { id: id,
202-
node: PatIdent(BindByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None),
203-
span: s }
185+
pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> {
186+
P(Pat {
187+
id: id,
188+
node: PatIdent(BindByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None),
189+
span: s
190+
})
204191
}
205192

206193
pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
@@ -226,57 +213,6 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident {
226213
token::gensym_ident(pretty.as_slice())
227214
}
228215

229-
pub fn trait_method_to_ty_method(method: &Method) -> TypeMethod {
230-
match method.node {
231-
MethDecl(ident,
232-
ref generics,
233-
abi,
234-
explicit_self,
235-
fn_style,
236-
decl,
237-
_,
238-
vis) => {
239-
TypeMethod {
240-
ident: ident,
241-
attrs: method.attrs.clone(),
242-
fn_style: fn_style,
243-
decl: decl,
244-
generics: generics.clone(),
245-
explicit_self: explicit_self,
246-
id: method.id,
247-
span: method.span,
248-
vis: vis,
249-
abi: abi,
250-
}
251-
},
252-
MethMac(_) => fail!("expected non-macro method declaration")
253-
}
254-
}
255-
256-
/// extract a TypeMethod from a TraitItem. if the TraitItem is
257-
/// a default, pull out the useful fields to make a TypeMethod
258-
//
259-
// NB: to be used only after expansion is complete, and macros are gone.
260-
pub fn trait_item_to_ty_method(method: &TraitItem) -> TypeMethod {
261-
match *method {
262-
RequiredMethod(ref m) => (*m).clone(),
263-
ProvidedMethod(ref m) => trait_method_to_ty_method(&**m),
264-
}
265-
}
266-
267-
pub fn split_trait_methods(trait_methods: &[TraitItem])
268-
-> (Vec<TypeMethod> , Vec<Gc<Method>> ) {
269-
let mut reqd = Vec::new();
270-
let mut provd = Vec::new();
271-
for trt_method in trait_methods.iter() {
272-
match *trt_method {
273-
RequiredMethod(ref tm) => reqd.push((*tm).clone()),
274-
ProvidedMethod(m) => provd.push(m)
275-
}
276-
};
277-
(reqd, provd)
278-
}
279-
280216
pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
281217
match field.node.kind {
282218
ast::NamedField(_, v) | ast::UnnamedField(v) => v
@@ -603,13 +539,6 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
603539
visitor.result.get()
604540
}
605541

606-
pub fn is_item_impl(item: Gc<ast::Item>) -> bool {
607-
match item.node {
608-
ItemImpl(..) => true,
609-
_ => false
610-
}
611-
}
612-
613542
pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
614543
if !it(pat) {
615544
return false;
@@ -678,7 +607,7 @@ pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
678607

679608
/// Returns true if the given pattern consists solely of an identifier
680609
/// and false otherwise.
681-
pub fn pat_is_ident(pat: Gc<ast::Pat>) -> bool {
610+
pub fn pat_is_ident(pat: P<ast::Pat>) -> bool {
682611
match pat.node {
683612
ast::PatIdent(..) => true,
684613
_ => false,
@@ -713,28 +642,13 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo
713642
}
714643

715644
/// Returns true if this literal is a string and false otherwise.
716-
pub fn lit_is_str(lit: Gc<Lit>) -> bool {
645+
pub fn lit_is_str(lit: &Lit) -> bool {
717646
match lit.node {
718647
LitStr(..) => true,
719648
_ => false,
720649
}
721650
}
722651

723-
pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> {
724-
match ty.node {
725-
ast::TyRptr(_, mut_ty) | ast::TyPtr(mut_ty) => {
726-
vec!(mut_ty.ty)
727-
}
728-
ast::TyBox(ty)
729-
| ast::TyVec(ty)
730-
| ast::TyUniq(ty)
731-
| ast::TyFixedLengthVec(ty, _) => vec!(ty),
732-
ast::TyTup(ref tys) => tys.clone(),
733-
ast::TyParen(ty) => get_inner_tys(ty),
734-
_ => Vec::new()
735-
}
736-
}
737-
738652
/// Returns true if the static with the given mutability and attributes
739653
/// has a significant address and false otherwise.
740654
pub fn static_has_significant_address(mutbl: ast::Mutability,
@@ -757,13 +671,13 @@ pub trait PostExpansionMethod {
757671
fn pe_abi(&self) -> Abi;
758672
fn pe_explicit_self<'a>(&'a self) -> &'a ast::ExplicitSelf;
759673
fn pe_fn_style(&self) -> ast::FnStyle;
760-
fn pe_fn_decl(&self) -> P<ast::FnDecl>;
761-
fn pe_body(&self) -> P<ast::Block>;
674+
fn pe_fn_decl<'a>(&'a self) -> &'a ast::FnDecl;
675+
fn pe_body<'a>(&'a self) -> &'a ast::Block;
762676
fn pe_vis(&self) -> ast::Visibility;
763677
}
764678

765679
macro_rules! mf_method{
766-
($meth_name:ident, $field_ty:ty, $field_pat:pat, $result:ident) => {
680+
($meth_name:ident, $field_ty:ty, $field_pat:pat, $result:expr) => {
767681
fn $meth_name<'a>(&'a self) -> $field_ty {
768682
match self.node {
769683
$field_pat => $result,
@@ -784,8 +698,8 @@ impl PostExpansionMethod for Method {
784698
mf_method!(pe_explicit_self,&'a ast::ExplicitSelf,
785699
MethDecl(_,_,_,ref explicit_self,_,_,_,_),explicit_self)
786700
mf_method!(pe_fn_style,ast::FnStyle,MethDecl(_,_,_,_,fn_style,_,_,_),fn_style)
787-
mf_method!(pe_fn_decl,P<ast::FnDecl>,MethDecl(_,_,_,_,_,decl,_,_),decl)
788-
mf_method!(pe_body,P<ast::Block>,MethDecl(_,_,_,_,_,_,body,_),body)
701+
mf_method!(pe_fn_decl,&'a ast::FnDecl,MethDecl(_,_,_,_,_,ref decl,_,_),&**decl)
702+
mf_method!(pe_body,&'a ast::Block,MethDecl(_,_,_,_,_,_,ref body,_),&**body)
789703
mf_method!(pe_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,_,vis),vis)
790704
}
791705

0 commit comments

Comments
 (0)