]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ext/build.rs
Rollup merge of #34764 - pnkfelix:attrs-on-generic-formals, r=eddyb
[rust.git] / src / libsyntax / ext / build.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use abi::Abi;
12 use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
13 use attr;
14 use syntax_pos::{Span, DUMMY_SP, Pos};
15 use codemap::{dummy_spanned, respan, Spanned};
16 use ext::base::ExtCtxt;
17 use parse::token::{self, keywords, InternedString};
18 use ptr::P;
19
20 // Transitional reexports so qquote can find the paths it is looking for
21 mod syntax {
22     pub use ext;
23     pub use parse;
24 }
25
26 pub trait AstBuilder {
27     // paths
28     fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
29     fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path;
30     fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path;
31     fn path_all(&self, sp: Span,
32                 global: bool,
33                 idents: Vec<ast::Ident> ,
34                 lifetimes: Vec<ast::Lifetime>,
35                 types: Vec<P<ast::Ty>>,
36                 bindings: Vec<ast::TypeBinding> )
37         -> ast::Path;
38
39     fn qpath(&self, self_type: P<ast::Ty>,
40              trait_path: ast::Path,
41              ident: ast::Ident)
42              -> (ast::QSelf, ast::Path);
43     fn qpath_all(&self, self_type: P<ast::Ty>,
44                 trait_path: ast::Path,
45                 ident: ast::Ident,
46                 lifetimes: Vec<ast::Lifetime>,
47                 types: Vec<P<ast::Ty>>,
48                 bindings: Vec<ast::TypeBinding>)
49                 -> (ast::QSelf, ast::Path);
50
51     // types
52     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
53
54     fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty>;
55     fn ty_path(&self, ast::Path) -> P<ast::Ty>;
56     fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P<ast::Ty>;
57     fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
58
59     fn ty_rptr(&self, span: Span,
60                ty: P<ast::Ty>,
61                lifetime: Option<ast::Lifetime>,
62                mutbl: ast::Mutability) -> P<ast::Ty>;
63     fn ty_ptr(&self, span: Span,
64               ty: P<ast::Ty>,
65               mutbl: ast::Mutability) -> P<ast::Ty>;
66
67     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
68     fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
69
70     fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
71     fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
72
73     fn typaram(&self,
74                span: Span,
75                id: ast::Ident,
76                attrs: Vec<ast::Attribute>,
77                bounds: ast::TyParamBounds,
78                default: Option<P<ast::Ty>>) -> ast::TyParam;
79
80     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef;
81     fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef;
82     fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
83     fn lifetime(&self, span: Span, ident: ast::Name) -> ast::Lifetime;
84     fn lifetime_def(&self,
85                     span: Span,
86                     name: ast::Name,
87                     attrs: Vec<ast::Attribute>,
88                     bounds: Vec<ast::Lifetime>)
89                     -> ast::LifetimeDef;
90
91     // statements
92     fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt;
93     fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt;
94     fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P<ast::Expr>) -> ast::Stmt;
95     fn stmt_let_typed(&self,
96                       sp: Span,
97                       mutbl: bool,
98                       ident: ast::Ident,
99                       typ: P<ast::Ty>,
100                       ex: P<ast::Expr>)
101                       -> ast::Stmt;
102     fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt;
103     fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt;
104
105     // blocks
106     fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block>;
107     fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
108
109     // expressions
110     fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>;
111     fn expr_path(&self, path: ast::Path) -> P<ast::Expr>;
112     fn expr_qpath(&self, span: Span, qself: ast::QSelf, path: ast::Path) -> P<ast::Expr>;
113     fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
114
115     fn expr_self(&self, span: Span) -> P<ast::Expr>;
116     fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
117                    lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>;
118     fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
119     fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>;
120
121     fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
122     fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
123     fn expr_field_access(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr>;
124     fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>,
125                              idx: usize) -> P<ast::Expr>;
126     fn expr_call(&self, span: Span, expr: P<ast::Expr>, args: Vec<P<ast::Expr>>) -> P<ast::Expr>;
127     fn expr_call_ident(&self, span: Span, id: ast::Ident, args: Vec<P<ast::Expr>>) -> P<ast::Expr>;
128     fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident>,
129                         args: Vec<P<ast::Expr>> ) -> P<ast::Expr>;
130     fn expr_method_call(&self, span: Span,
131                         expr: P<ast::Expr>, ident: ast::Ident,
132                         args: Vec<P<ast::Expr>> ) -> P<ast::Expr>;
133     fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr>;
134     fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr>;
135
136     fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>) -> ast::Field;
137     fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr>;
138     fn expr_struct_ident(&self, span: Span, id: ast::Ident,
139                          fields: Vec<ast::Field>) -> P<ast::Expr>;
140
141     fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr>;
142
143     fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
144     fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr>;
145     fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
146     fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr>;
147     fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;
148
149     fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
150     fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr>;
151     fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
152     fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr>;
153
154     fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
155     fn expr_none(&self, sp: Span) -> P<ast::Expr>;
156
157     fn expr_break(&self, sp: Span) -> P<ast::Expr>;
158
159     fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
160
161     fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr>;
162     fn expr_unreachable(&self, span: Span) -> P<ast::Expr>;
163
164     fn expr_ok(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
165     fn expr_err(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
166     fn expr_try(&self, span: Span, head: P<ast::Expr>) -> P<ast::Expr>;
167
168     fn pat(&self, span: Span, pat: PatKind) -> P<ast::Pat>;
169     fn pat_wild(&self, span: Span) -> P<ast::Pat>;
170     fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat>;
171     fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat>;
172
173     fn pat_ident_binding_mode(&self,
174                               span: Span,
175                               ident: ast::Ident,
176                               bm: ast::BindingMode) -> P<ast::Pat>;
177     fn pat_path(&self, span: Span, path: ast::Path) -> P<ast::Pat>;
178     fn pat_tuple_struct(&self, span: Span, path: ast::Path,
179                         subpats: Vec<P<ast::Pat>>) -> P<ast::Pat>;
180     fn pat_struct(&self, span: Span, path: ast::Path,
181                   field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat>;
182     fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat>;
183
184     fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
185     fn pat_none(&self, span: Span) -> P<ast::Pat>;
186
187     fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
188     fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
189
190     fn arm(&self, span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast::Arm;
191     fn arm_unreachable(&self, span: Span) -> ast::Arm;
192
193     fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm> ) -> P<ast::Expr>;
194     fn expr_if(&self, span: Span,
195                cond: P<ast::Expr>, then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr>;
196     fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr>;
197
198     fn lambda_fn_decl(&self,
199                       span: Span,
200                       fn_decl: P<ast::FnDecl>,
201                       blk: P<ast::Block>,
202                       fn_decl_span: Span)
203                       -> P<ast::Expr>;
204
205     fn lambda(&self, span: Span, ids: Vec<ast::Ident>, blk: P<ast::Block>) -> P<ast::Expr>;
206     fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr>;
207     fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> P<ast::Expr>;
208
209     fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident> , blk: P<ast::Expr>) -> P<ast::Expr>;
210     fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr>;
211     fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr>;
212
213     fn lambda_stmts(&self, span: Span, ids: Vec<ast::Ident>,
214                     blk: Vec<ast::Stmt>) -> P<ast::Expr>;
215     fn lambda_stmts_0(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Expr>;
216     fn lambda_stmts_1(&self, span: Span, stmts: Vec<ast::Stmt>,
217                       ident: ast::Ident) -> P<ast::Expr>;
218
219     // items
220     fn item(&self, span: Span,
221             name: Ident, attrs: Vec<ast::Attribute> , node: ast::ItemKind) -> P<ast::Item>;
222
223     fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg;
224     // FIXME unused self
225     fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl>;
226
227     fn item_fn_poly(&self,
228                     span: Span,
229                     name: Ident,
230                     inputs: Vec<ast::Arg> ,
231                     output: P<ast::Ty>,
232                     generics: Generics,
233                     body: P<ast::Block>) -> P<ast::Item>;
234     fn item_fn(&self,
235                span: Span,
236                name: Ident,
237                inputs: Vec<ast::Arg> ,
238                output: P<ast::Ty>,
239                body: P<ast::Block>) -> P<ast::Item>;
240
241     fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant;
242     fn item_enum_poly(&self,
243                       span: Span,
244                       name: Ident,
245                       enum_definition: ast::EnumDef,
246                       generics: Generics) -> P<ast::Item>;
247     fn item_enum(&self, span: Span, name: Ident, enum_def: ast::EnumDef) -> P<ast::Item>;
248
249     fn item_struct_poly(&self,
250                         span: Span,
251                         name: Ident,
252                         struct_def: ast::VariantData,
253                         generics: Generics) -> P<ast::Item>;
254     fn item_struct(&self, span: Span, name: Ident, struct_def: ast::VariantData) -> P<ast::Item>;
255
256     fn item_mod(&self, span: Span, inner_span: Span,
257                 name: Ident, attrs: Vec<ast::Attribute>,
258                 items: Vec<P<ast::Item>>) -> P<ast::Item>;
259
260     fn item_static(&self,
261                    span: Span,
262                    name: Ident,
263                    ty: P<ast::Ty>,
264                    mutbl: ast::Mutability,
265                    expr: P<ast::Expr>)
266                    -> P<ast::Item>;
267
268     fn item_const(&self,
269                    span: Span,
270                    name: Ident,
271                    ty: P<ast::Ty>,
272                    expr: P<ast::Expr>)
273                    -> P<ast::Item>;
274
275     fn item_ty_poly(&self,
276                     span: Span,
277                     name: Ident,
278                     ty: P<ast::Ty>,
279                     generics: Generics) -> P<ast::Item>;
280     fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item>;
281
282     fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
283
284     fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem>;
285
286     fn meta_list_item_word(&self, sp: Span, w: InternedString) -> ast::NestedMetaItem;
287
288     fn meta_list(&self,
289                  sp: Span,
290                  name: InternedString,
291                  mis: Vec<ast::NestedMetaItem> )
292                  -> P<ast::MetaItem>;
293     fn meta_name_value(&self,
294                        sp: Span,
295                        name: InternedString,
296                        value: ast::LitKind)
297                        -> P<ast::MetaItem>;
298
299     fn item_use(&self, sp: Span,
300                 vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
301     fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>;
302     fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
303                         ident: ast::Ident, path: ast::Path) -> P<ast::Item>;
304     fn item_use_list(&self, sp: Span, vis: ast::Visibility,
305                      path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>;
306     fn item_use_glob(&self, sp: Span,
307                      vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item>;
308 }
309
310 impl<'a> AstBuilder for ExtCtxt<'a> {
311     fn path(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
312         self.path_all(span, false, strs, Vec::new(), Vec::new(), Vec::new())
313     }
314     fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
315         self.path(span, vec!(id))
316     }
317     fn path_global(&self, span: Span, strs: Vec<ast::Ident> ) -> ast::Path {
318         self.path_all(span, true, strs, Vec::new(), Vec::new(), Vec::new())
319     }
320     fn path_all(&self,
321                 sp: Span,
322                 global: bool,
323                 mut idents: Vec<ast::Ident> ,
324                 lifetimes: Vec<ast::Lifetime>,
325                 types: Vec<P<ast::Ty>>,
326                 bindings: Vec<ast::TypeBinding> )
327                 -> ast::Path {
328         let last_identifier = idents.pop().unwrap();
329         let mut segments: Vec<ast::PathSegment> = idents.into_iter()
330                                                       .map(|ident| {
331             ast::PathSegment {
332                 identifier: ident,
333                 parameters: ast::PathParameters::none(),
334             }
335         }).collect();
336         segments.push(ast::PathSegment {
337             identifier: last_identifier,
338             parameters: ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
339                 lifetimes: lifetimes,
340                 types: P::from_vec(types),
341                 bindings: P::from_vec(bindings),
342             })
343         });
344         ast::Path {
345             span: sp,
346             global: global,
347             segments: segments,
348         }
349     }
350
351     /// Constructs a qualified path.
352     ///
353     /// Constructs a path like `<self_type as trait_path>::ident`.
354     fn qpath(&self,
355              self_type: P<ast::Ty>,
356              trait_path: ast::Path,
357              ident: ast::Ident)
358              -> (ast::QSelf, ast::Path) {
359         self.qpath_all(self_type, trait_path, ident, vec![], vec![], vec![])
360     }
361
362     /// Constructs a qualified path.
363     ///
364     /// Constructs a path like `<self_type as trait_path>::ident<'a, T, A=Bar>`.
365     fn qpath_all(&self,
366                  self_type: P<ast::Ty>,
367                  trait_path: ast::Path,
368                  ident: ast::Ident,
369                  lifetimes: Vec<ast::Lifetime>,
370                  types: Vec<P<ast::Ty>>,
371                  bindings: Vec<ast::TypeBinding>)
372                  -> (ast::QSelf, ast::Path) {
373         let mut path = trait_path;
374         path.segments.push(ast::PathSegment {
375             identifier: ident,
376             parameters: ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
377                 lifetimes: lifetimes,
378                 types: P::from_vec(types),
379                 bindings: P::from_vec(bindings),
380             })
381         });
382
383         (ast::QSelf {
384             ty: self_type,
385             position: path.segments.len() - 1
386         }, path)
387     }
388
389     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
390         ast::MutTy {
391             ty: ty,
392             mutbl: mutbl
393         }
394     }
395
396     fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty> {
397         P(ast::Ty {
398             id: ast::DUMMY_NODE_ID,
399             span: span,
400             node: ty
401         })
402     }
403
404     fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
405         self.ty(path.span, ast::TyKind::Path(None, path))
406     }
407
408     fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P<ast::Ty> {
409         self.ty(path.span,
410                 ast::TyKind::ObjectSum(self.ty_path(path),
411                                  bounds))
412     }
413
414     // Might need to take bounds as an argument in the future, if you ever want
415     // to generate a bounded existential trait type.
416     fn ty_ident(&self, span: Span, ident: ast::Ident)
417         -> P<ast::Ty> {
418         self.ty_path(self.path_ident(span, ident))
419     }
420
421     fn ty_rptr(&self,
422                span: Span,
423                ty: P<ast::Ty>,
424                lifetime: Option<ast::Lifetime>,
425                mutbl: ast::Mutability)
426         -> P<ast::Ty> {
427         self.ty(span,
428                 ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl)))
429     }
430
431     fn ty_ptr(&self,
432               span: Span,
433               ty: P<ast::Ty>,
434               mutbl: ast::Mutability)
435         -> P<ast::Ty> {
436         self.ty(span,
437                 ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
438     }
439
440     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> {
441         self.ty_path(
442             self.path_all(DUMMY_SP,
443                           true,
444                           self.std_path(&["option", "Option"]),
445                           Vec::new(),
446                           vec!( ty ),
447                           Vec::new()))
448     }
449
450     fn ty_infer(&self, span: Span) -> P<ast::Ty> {
451         self.ty(span, ast::TyKind::Infer)
452     }
453
454     fn typaram(&self,
455                span: Span,
456                id: ast::Ident,
457                attrs: Vec<ast::Attribute>,
458                bounds: ast::TyParamBounds,
459                default: Option<P<ast::Ty>>) -> ast::TyParam {
460         ast::TyParam {
461             ident: id,
462             id: ast::DUMMY_NODE_ID,
463             attrs: attrs.into(),
464             bounds: bounds,
465             default: default,
466             span: span
467         }
468     }
469
470     // these are strange, and probably shouldn't be used outside of
471     // pipes. Specifically, the global version possible generates
472     // incorrect code.
473     fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
474         ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
475     }
476
477     fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
478         ty_params
479             .iter()
480             .map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident))))
481             .collect()
482     }
483
484     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
485         ast::TraitRef {
486             path: path,
487             ref_id: ast::DUMMY_NODE_ID,
488         }
489     }
490
491     fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef {
492         ast::PolyTraitRef {
493             bound_lifetimes: Vec::new(),
494             trait_ref: self.trait_ref(path),
495             span: span,
496         }
497     }
498
499     fn typarambound(&self, path: ast::Path) -> ast::TyParamBound {
500         ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None)
501     }
502
503     fn lifetime(&self, span: Span, name: ast::Name) -> ast::Lifetime {
504         ast::Lifetime { id: ast::DUMMY_NODE_ID, span: span, name: name }
505     }
506
507     fn lifetime_def(&self,
508                     span: Span,
509                     name: ast::Name,
510                     attrs: Vec<ast::Attribute>,
511                     bounds: Vec<ast::Lifetime>)
512                     -> ast::LifetimeDef {
513         ast::LifetimeDef {
514             attrs: attrs.into(),
515             lifetime: self.lifetime(span, name),
516             bounds: bounds
517         }
518     }
519
520     fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt {
521         ast::Stmt {
522             id: ast::DUMMY_NODE_ID,
523             span: expr.span,
524             node: ast::StmtKind::Expr(expr),
525         }
526     }
527
528     fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt {
529         ast::Stmt {
530             id: ast::DUMMY_NODE_ID,
531             span: expr.span,
532             node: ast::StmtKind::Semi(expr),
533         }
534     }
535
536     fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
537                 ex: P<ast::Expr>) -> ast::Stmt {
538         let pat = if mutbl {
539             let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable);
540             self.pat_ident_binding_mode(sp, ident, binding_mode)
541         } else {
542             self.pat_ident(sp, ident)
543         };
544         let local = P(ast::Local {
545             pat: pat,
546             ty: None,
547             init: Some(ex),
548             id: ast::DUMMY_NODE_ID,
549             span: sp,
550             attrs: ast::ThinVec::new(),
551         });
552         ast::Stmt {
553             id: ast::DUMMY_NODE_ID,
554             node: ast::StmtKind::Local(local),
555             span: sp,
556         }
557     }
558
559     fn stmt_let_typed(&self,
560                       sp: Span,
561                       mutbl: bool,
562                       ident: ast::Ident,
563                       typ: P<ast::Ty>,
564                       ex: P<ast::Expr>)
565                       -> ast::Stmt {
566         let pat = if mutbl {
567             let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable);
568             self.pat_ident_binding_mode(sp, ident, binding_mode)
569         } else {
570             self.pat_ident(sp, ident)
571         };
572         let local = P(ast::Local {
573             pat: pat,
574             ty: Some(typ),
575             init: Some(ex),
576             id: ast::DUMMY_NODE_ID,
577             span: sp,
578             attrs: ast::ThinVec::new(),
579         });
580         ast::Stmt {
581             id: ast::DUMMY_NODE_ID,
582             node: ast::StmtKind::Local(local),
583             span: sp,
584         }
585     }
586
587     // Generate `let _: Type;`, usually used for type assertions.
588     fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt {
589         let local = P(ast::Local {
590             pat: self.pat_wild(span),
591             ty: Some(ty),
592             init: None,
593             id: ast::DUMMY_NODE_ID,
594             span: span,
595             attrs: ast::ThinVec::new(),
596         });
597         ast::Stmt {
598             id: ast::DUMMY_NODE_ID,
599             node: ast::StmtKind::Local(local),
600             span: span,
601         }
602     }
603
604     fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {
605         ast::Stmt {
606             id: ast::DUMMY_NODE_ID,
607             node: ast::StmtKind::Item(item),
608             span: sp,
609         }
610     }
611
612     fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
613         self.block(expr.span, vec![ast::Stmt {
614             id: ast::DUMMY_NODE_ID,
615             span: expr.span,
616             node: ast::StmtKind::Expr(expr),
617         }])
618     }
619     fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
620         P(ast::Block {
621            stmts: stmts,
622            id: ast::DUMMY_NODE_ID,
623            rules: BlockCheckMode::Default,
624            span: span,
625         })
626     }
627
628     fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> {
629         P(ast::Expr {
630             id: ast::DUMMY_NODE_ID,
631             node: node,
632             span: span,
633             attrs: ast::ThinVec::new(),
634         })
635     }
636
637     fn expr_path(&self, path: ast::Path) -> P<ast::Expr> {
638         self.expr(path.span, ast::ExprKind::Path(None, path))
639     }
640
641     /// Constructs a QPath expression.
642     fn expr_qpath(&self, span: Span, qself: ast::QSelf, path: ast::Path) -> P<ast::Expr> {
643         self.expr(span, ast::ExprKind::Path(Some(qself), path))
644     }
645
646     fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr> {
647         self.expr_path(self.path_ident(span, id))
648     }
649     fn expr_self(&self, span: Span) -> P<ast::Expr> {
650         self.expr_ident(span, keywords::SelfValue.ident())
651     }
652
653     fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
654                    lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> {
655         self.expr(sp, ast::ExprKind::Binary(Spanned { node: op, span: sp }, lhs, rhs))
656     }
657
658     fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
659         self.expr_unary(sp, UnOp::Deref, e)
660     }
661     fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr> {
662         self.expr(sp, ast::ExprKind::Unary(op, e))
663     }
664
665     fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
666         let field_span = Span {
667             lo: sp.lo - Pos::from_usize(ident.name.as_str().len()),
668             hi: sp.hi,
669             expn_id: sp.expn_id,
670         };
671
672         let id = Spanned { node: ident, span: field_span };
673         self.expr(sp, ast::ExprKind::Field(expr, id))
674     }
675     fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: usize) -> P<ast::Expr> {
676         let field_span = Span {
677             lo: sp.lo - Pos::from_usize(idx.to_string().len()),
678             hi: sp.hi,
679             expn_id: sp.expn_id,
680         };
681
682         let id = Spanned { node: idx, span: field_span };
683         self.expr(sp, ast::ExprKind::TupField(expr, id))
684     }
685     fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
686         self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Immutable, e))
687     }
688     fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
689         self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Mutable, e))
690     }
691
692     fn expr_call(&self, span: Span, expr: P<ast::Expr>, args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
693         self.expr(span, ast::ExprKind::Call(expr, args))
694     }
695     fn expr_call_ident(&self, span: Span, id: ast::Ident,
696                        args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
697         self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args))
698     }
699     fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident> ,
700                       args: Vec<P<ast::Expr>> ) -> P<ast::Expr> {
701         let pathexpr = self.expr_path(self.path_global(sp, fn_path));
702         self.expr_call(sp, pathexpr, args)
703     }
704     fn expr_method_call(&self, span: Span,
705                         expr: P<ast::Expr>,
706                         ident: ast::Ident,
707                         mut args: Vec<P<ast::Expr>> ) -> P<ast::Expr> {
708         let id = Spanned { node: ident, span: span };
709         args.insert(0, expr);
710         self.expr(span, ast::ExprKind::MethodCall(id, Vec::new(), args))
711     }
712     fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> {
713         self.expr(b.span, ast::ExprKind::Block(b))
714     }
715     fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>) -> ast::Field {
716         ast::Field { ident: respan(span, name), expr: e, span: span }
717     }
718     fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr> {
719         self.expr(span, ast::ExprKind::Struct(path, fields, None))
720     }
721     fn expr_struct_ident(&self, span: Span,
722                          id: ast::Ident, fields: Vec<ast::Field>) -> P<ast::Expr> {
723         self.expr_struct(span, self.path_ident(span, id), fields)
724     }
725
726     fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> {
727         self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit))))
728     }
729     fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
730         self.expr_lit(span, ast::LitKind::Int(i as u64, ast::LitIntType::Unsigned(ast::UintTy::Us)))
731     }
732     fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
733         if i < 0 {
734             let i = (-i) as u64;
735             let lit_ty = ast::LitIntType::Signed(ast::IntTy::Is);
736             let lit = self.expr_lit(sp, ast::LitKind::Int(i, lit_ty));
737             self.expr_unary(sp, ast::UnOp::Neg, lit)
738         } else {
739             self.expr_lit(sp, ast::LitKind::Int(i as u64, ast::LitIntType::Signed(ast::IntTy::Is)))
740         }
741     }
742     fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
743         self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::LitIntType::Unsigned(ast::UintTy::U32)))
744     }
745     fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
746         self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::LitIntType::Unsigned(ast::UintTy::U8)))
747     }
748     fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
749         self.expr_lit(sp, ast::LitKind::Bool(value))
750     }
751
752     fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
753         self.expr(sp, ast::ExprKind::Vec(exprs))
754     }
755     fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
756         self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
757                               Vec::new())
758     }
759     fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
760         self.expr_addr_of(sp, self.expr_vec(sp, exprs))
761     }
762     fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> {
763         self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked))
764     }
765
766     fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
767         self.expr(sp, ast::ExprKind::Cast(expr, ty))
768     }
769
770
771     fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
772         let some = self.std_path(&["option", "Option", "Some"]);
773         self.expr_call_global(sp, some, vec!(expr))
774     }
775
776     fn expr_none(&self, sp: Span) -> P<ast::Expr> {
777         let none = self.std_path(&["option", "Option", "None"]);
778         let none = self.path_global(sp, none);
779         self.expr_path(none)
780     }
781
782
783     fn expr_break(&self, sp: Span) -> P<ast::Expr> {
784         self.expr(sp, ast::ExprKind::Break(None))
785     }
786
787
788     fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
789         self.expr(sp, ast::ExprKind::Tup(exprs))
790     }
791
792     fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr> {
793         let loc = self.codemap().lookup_char_pos(span.lo);
794         let expr_file = self.expr_str(span,
795                                       token::intern_and_get_ident(&loc.file.name));
796         let expr_line = self.expr_u32(span, loc.line as u32);
797         let expr_file_line_tuple = self.expr_tuple(span, vec!(expr_file, expr_line));
798         let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple);
799         self.expr_call_global(
800             span,
801             self.std_path(&["rt", "begin_panic"]),
802             vec!(
803                 self.expr_str(span, msg),
804                 expr_file_line_ptr))
805     }
806
807     fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
808         self.expr_fail(span,
809                        InternedString::new(
810                            "internal error: entered unreachable code"))
811     }
812
813     fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
814         let ok = self.std_path(&["result", "Result", "Ok"]);
815         self.expr_call_global(sp, ok, vec!(expr))
816     }
817
818     fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
819         let err = self.std_path(&["result", "Result", "Err"]);
820         self.expr_call_global(sp, err, vec!(expr))
821     }
822
823     fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
824         let ok = self.std_path(&["result", "Result", "Ok"]);
825         let ok_path = self.path_global(sp, ok);
826         let err = self.std_path(&["result", "Result", "Err"]);
827         let err_path = self.path_global(sp, err);
828
829         let binding_variable = self.ident_of("__try_var");
830         let binding_pat = self.pat_ident(sp, binding_variable);
831         let binding_expr = self.expr_ident(sp, binding_variable);
832
833         // Ok(__try_var) pattern
834         let ok_pat = self.pat_tuple_struct(sp, ok_path, vec![binding_pat.clone()]);
835
836         // Err(__try_var)  (pattern and expression resp.)
837         let err_pat = self.pat_tuple_struct(sp, err_path.clone(), vec![binding_pat]);
838         let err_inner_expr = self.expr_call(sp, self.expr_path(err_path),
839                                             vec!(binding_expr.clone()));
840         // return Err(__try_var)
841         let err_expr = self.expr(sp, ast::ExprKind::Ret(Some(err_inner_expr)));
842
843         // Ok(__try_var) => __try_var
844         let ok_arm = self.arm(sp, vec!(ok_pat), binding_expr);
845         // Err(__try_var) => return Err(__try_var)
846         let err_arm = self.arm(sp, vec!(err_pat), err_expr);
847
848         // match head { Ok() => ..., Err() => ... }
849         self.expr_match(sp, head, vec!(ok_arm, err_arm))
850     }
851
852
853     fn pat(&self, span: Span, pat: PatKind) -> P<ast::Pat> {
854         P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span })
855     }
856     fn pat_wild(&self, span: Span) -> P<ast::Pat> {
857         self.pat(span, PatKind::Wild)
858     }
859     fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
860         self.pat(span, PatKind::Lit(expr))
861     }
862     fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat> {
863         let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Immutable);
864         self.pat_ident_binding_mode(span, ident, binding_mode)
865     }
866
867     fn pat_ident_binding_mode(&self,
868                               span: Span,
869                               ident: ast::Ident,
870                               bm: ast::BindingMode) -> P<ast::Pat> {
871         let pat = PatKind::Ident(bm, Spanned{span: span, node: ident}, None);
872         self.pat(span, pat)
873     }
874     fn pat_path(&self, span: Span, path: ast::Path) -> P<ast::Pat> {
875         self.pat(span, PatKind::Path(None, path))
876     }
877     fn pat_tuple_struct(&self, span: Span, path: ast::Path,
878                         subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
879         self.pat(span, PatKind::TupleStruct(path, subpats, None))
880     }
881     fn pat_struct(&self, span: Span, path: ast::Path,
882                   field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat> {
883         self.pat(span, PatKind::Struct(path, field_pats, false))
884     }
885     fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
886         self.pat(span, PatKind::Tuple(pats, None))
887     }
888
889     fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
890         let some = self.std_path(&["option", "Option", "Some"]);
891         let path = self.path_global(span, some);
892         self.pat_tuple_struct(span, path, vec![pat])
893     }
894
895     fn pat_none(&self, span: Span) -> P<ast::Pat> {
896         let some = self.std_path(&["option", "Option", "None"]);
897         let path = self.path_global(span, some);
898         self.pat_path(span, path)
899     }
900
901     fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
902         let some = self.std_path(&["result", "Result", "Ok"]);
903         let path = self.path_global(span, some);
904         self.pat_tuple_struct(span, path, vec![pat])
905     }
906
907     fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
908         let some = self.std_path(&["result", "Result", "Err"]);
909         let path = self.path_global(span, some);
910         self.pat_tuple_struct(span, path, vec![pat])
911     }
912
913     fn arm(&self, _span: Span, pats: Vec<P<ast::Pat>>, expr: P<ast::Expr>) -> ast::Arm {
914         ast::Arm {
915             attrs: vec!(),
916             pats: pats,
917             guard: None,
918             body: expr
919         }
920     }
921
922     fn arm_unreachable(&self, span: Span) -> ast::Arm {
923         self.arm(span, vec!(self.pat_wild(span)), self.expr_unreachable(span))
924     }
925
926     fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
927         self.expr(span, ast::ExprKind::Match(arg, arms))
928     }
929
930     fn expr_if(&self, span: Span, cond: P<ast::Expr>,
931                then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr> {
932         let els = els.map(|x| self.expr_block(self.block_expr(x)));
933         self.expr(span, ast::ExprKind::If(cond, self.block_expr(then), els))
934     }
935
936     fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr> {
937         self.expr(span, ast::ExprKind::Loop(block, None))
938     }
939
940     fn lambda_fn_decl(&self,
941                       span: Span,
942                       fn_decl: P<ast::FnDecl>,
943                       blk: P<ast::Block>,
944                       fn_decl_span: Span) // span of the `|...|` part
945                       -> P<ast::Expr> {
946         self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref,
947                                                fn_decl,
948                                                blk,
949                                                fn_decl_span))
950     }
951
952     fn lambda(&self,
953               span: Span,
954               ids: Vec<ast::Ident>,
955               blk: P<ast::Block>)
956               -> P<ast::Expr> {
957         let fn_decl = self.fn_decl(
958             ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(),
959             self.ty_infer(span));
960
961         // FIXME -- We are using `span` as the span of the `|...|`
962         // part of the lambda, but it probably (maybe?) corresponds to
963         // the entire lambda body. Probably we should extend the API
964         // here, but that's not entirely clear.
965         self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk, span))
966     }
967
968     fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr> {
969         self.lambda(span, Vec::new(), blk)
970     }
971
972     fn lambda1(&self, span: Span, blk: P<ast::Block>, ident: ast::Ident) -> P<ast::Expr> {
973         self.lambda(span, vec!(ident), blk)
974     }
975
976     fn lambda_expr(&self, span: Span, ids: Vec<ast::Ident>,
977                    expr: P<ast::Expr>) -> P<ast::Expr> {
978         self.lambda(span, ids, self.block_expr(expr))
979     }
980     fn lambda_expr_0(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
981         self.lambda0(span, self.block_expr(expr))
982     }
983     fn lambda_expr_1(&self, span: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
984         self.lambda1(span, self.block_expr(expr), ident)
985     }
986
987     fn lambda_stmts(&self,
988                     span: Span,
989                     ids: Vec<ast::Ident>,
990                     stmts: Vec<ast::Stmt>)
991                     -> P<ast::Expr> {
992         self.lambda(span, ids, self.block(span, stmts))
993     }
994     fn lambda_stmts_0(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Expr> {
995         self.lambda0(span, self.block(span, stmts))
996     }
997     fn lambda_stmts_1(&self, span: Span, stmts: Vec<ast::Stmt>,
998                       ident: ast::Ident) -> P<ast::Expr> {
999         self.lambda1(span, self.block(span, stmts), ident)
1000     }
1001
1002     fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {
1003         let arg_pat = self.pat_ident(span, ident);
1004         ast::Arg {
1005             ty: ty,
1006             pat: arg_pat,
1007             id: ast::DUMMY_NODE_ID
1008         }
1009     }
1010
1011     // FIXME unused self
1012     fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> {
1013         P(ast::FnDecl {
1014             inputs: inputs,
1015             output: ast::FunctionRetTy::Ty(output),
1016             variadic: false
1017         })
1018     }
1019
1020     fn item(&self, span: Span, name: Ident,
1021             attrs: Vec<ast::Attribute>, node: ast::ItemKind) -> P<ast::Item> {
1022         // FIXME: Would be nice if our generated code didn't violate
1023         // Rust coding conventions
1024         P(ast::Item {
1025             ident: name,
1026             attrs: attrs,
1027             id: ast::DUMMY_NODE_ID,
1028             node: node,
1029             vis: ast::Visibility::Inherited,
1030             span: span
1031         })
1032     }
1033
1034     fn item_fn_poly(&self,
1035                     span: Span,
1036                     name: Ident,
1037                     inputs: Vec<ast::Arg> ,
1038                     output: P<ast::Ty>,
1039                     generics: Generics,
1040                     body: P<ast::Block>) -> P<ast::Item> {
1041         self.item(span,
1042                   name,
1043                   Vec::new(),
1044                   ast::ItemKind::Fn(self.fn_decl(inputs, output),
1045                               ast::Unsafety::Normal,
1046                               dummy_spanned(ast::Constness::NotConst),
1047                               Abi::Rust,
1048                               generics,
1049                               body))
1050     }
1051
1052     fn item_fn(&self,
1053                span: Span,
1054                name: Ident,
1055                inputs: Vec<ast::Arg> ,
1056                output: P<ast::Ty>,
1057                body: P<ast::Block>
1058               ) -> P<ast::Item> {
1059         self.item_fn_poly(
1060             span,
1061             name,
1062             inputs,
1063             output,
1064             Generics::default(),
1065             body)
1066     }
1067
1068     fn variant(&self, span: Span, name: Ident, tys: Vec<P<ast::Ty>> ) -> ast::Variant {
1069         let fields: Vec<_> = tys.into_iter().map(|ty| {
1070             ast::StructField {
1071                 span: ty.span,
1072                 ty: ty,
1073                 ident: None,
1074                 vis: ast::Visibility::Inherited,
1075                 attrs: Vec::new(),
1076                 id: ast::DUMMY_NODE_ID,
1077             }
1078         }).collect();
1079
1080         let vdata = if fields.is_empty() {
1081             ast::VariantData::Unit(ast::DUMMY_NODE_ID)
1082         } else {
1083             ast::VariantData::Tuple(fields, ast::DUMMY_NODE_ID)
1084         };
1085
1086         respan(span,
1087                ast::Variant_ {
1088                    name: name,
1089                    attrs: Vec::new(),
1090                    data: vdata,
1091                    disr_expr: None,
1092                })
1093     }
1094
1095     fn item_enum_poly(&self, span: Span, name: Ident,
1096                       enum_definition: ast::EnumDef,
1097                       generics: Generics) -> P<ast::Item> {
1098         self.item(span, name, Vec::new(), ast::ItemKind::Enum(enum_definition, generics))
1099     }
1100
1101     fn item_enum(&self, span: Span, name: Ident,
1102                  enum_definition: ast::EnumDef) -> P<ast::Item> {
1103         self.item_enum_poly(span, name, enum_definition,
1104                             Generics::default())
1105     }
1106
1107     fn item_struct(&self, span: Span, name: Ident,
1108                    struct_def: ast::VariantData) -> P<ast::Item> {
1109         self.item_struct_poly(
1110             span,
1111             name,
1112             struct_def,
1113             Generics::default()
1114         )
1115     }
1116
1117     fn item_struct_poly(&self, span: Span, name: Ident,
1118         struct_def: ast::VariantData, generics: Generics) -> P<ast::Item> {
1119         self.item(span, name, Vec::new(), ast::ItemKind::Struct(struct_def, generics))
1120     }
1121
1122     fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
1123                 attrs: Vec<ast::Attribute>,
1124                 items: Vec<P<ast::Item>>) -> P<ast::Item> {
1125         self.item(
1126             span,
1127             name,
1128             attrs,
1129             ast::ItemKind::Mod(ast::Mod {
1130                 inner: inner_span,
1131                 items: items,
1132             })
1133         )
1134     }
1135
1136     fn item_static(&self,
1137                    span: Span,
1138                    name: Ident,
1139                    ty: P<ast::Ty>,
1140                    mutbl: ast::Mutability,
1141                    expr: P<ast::Expr>)
1142                    -> P<ast::Item> {
1143         self.item(span, name, Vec::new(), ast::ItemKind::Static(ty, mutbl, expr))
1144     }
1145
1146     fn item_const(&self,
1147                   span: Span,
1148                   name: Ident,
1149                   ty: P<ast::Ty>,
1150                   expr: P<ast::Expr>)
1151                   -> P<ast::Item> {
1152         self.item(span, name, Vec::new(), ast::ItemKind::Const(ty, expr))
1153     }
1154
1155     fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>,
1156                     generics: Generics) -> P<ast::Item> {
1157         self.item(span, name, Vec::new(), ast::ItemKind::Ty(ty, generics))
1158     }
1159
1160     fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item> {
1161         self.item_ty_poly(span, name, ty, Generics::default())
1162     }
1163
1164     fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
1165         attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi)
1166     }
1167
1168     fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem> {
1169         attr::mk_spanned_word_item(sp, w)
1170     }
1171
1172     fn meta_list_item_word(&self, sp: Span, w: InternedString) -> ast::NestedMetaItem {
1173         respan(sp, ast::NestedMetaItemKind::MetaItem(attr::mk_spanned_word_item(sp, w)))
1174     }
1175
1176     fn meta_list(&self, sp: Span, name: InternedString, mis: Vec<ast::NestedMetaItem>)
1177                  -> P<ast::MetaItem> {
1178         attr::mk_spanned_list_item(sp, name, mis)
1179     }
1180
1181     fn meta_name_value(&self, sp: Span, name: InternedString, value: ast::LitKind)
1182                        -> P<ast::MetaItem> {
1183         attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
1184     }
1185
1186     fn item_use(&self, sp: Span,
1187                 vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
1188         P(ast::Item {
1189             id: ast::DUMMY_NODE_ID,
1190             ident: keywords::Invalid.ident(),
1191             attrs: vec![],
1192             node: ast::ItemKind::Use(vp),
1193             vis: vis,
1194             span: sp
1195         })
1196     }
1197
1198     fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> {
1199         let last = path.segments.last().unwrap().identifier;
1200         self.item_use_simple_(sp, vis, last, path)
1201     }
1202
1203     fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
1204                         ident: ast::Ident, path: ast::Path) -> P<ast::Item> {
1205         self.item_use(sp, vis,
1206                       P(respan(sp,
1207                                ast::ViewPathSimple(ident,
1208                                                    path))))
1209     }
1210
1211     fn item_use_list(&self, sp: Span, vis: ast::Visibility,
1212                      path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
1213         let imports = imports.iter().map(|id| {
1214             let item = ast::PathListItem_ {
1215                 name: *id,
1216                 rename: None,
1217                 id: ast::DUMMY_NODE_ID,
1218             };
1219             respan(sp, item)
1220         }).collect();
1221
1222         self.item_use(sp, vis,
1223                       P(respan(sp,
1224                                ast::ViewPathList(self.path(sp, path),
1225                                                  imports))))
1226     }
1227
1228     fn item_use_glob(&self, sp: Span,
1229                      vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item> {
1230         self.item_use(sp, vis,
1231                       P(respan(sp,
1232                                ast::ViewPathGlob(self.path(sp, path)))))
1233     }
1234 }