]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_expand/src/build.rs
Rollup merge of #100434 - compiler-errors:issue-100373, r=cjgillot
[rust.git] / compiler / rustc_expand / src / build.rs
1 use crate::base::ExtCtxt;
2
3 use rustc_ast::attr;
4 use rustc_ast::ptr::P;
5 use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp};
6 use rustc_span::source_map::Spanned;
7 use rustc_span::symbol::{kw, sym, Ident, Symbol};
8
9 use rustc_span::Span;
10
11 impl<'a> ExtCtxt<'a> {
12     pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path {
13         self.path_all(span, false, strs, vec![])
14     }
15     pub fn path_ident(&self, span: Span, id: Ident) -> ast::Path {
16         self.path(span, vec![id])
17     }
18     pub fn path_global(&self, span: Span, strs: Vec<Ident>) -> ast::Path {
19         self.path_all(span, true, strs, vec![])
20     }
21     pub fn path_all(
22         &self,
23         span: Span,
24         global: bool,
25         mut idents: Vec<Ident>,
26         args: Vec<ast::GenericArg>,
27     ) -> ast::Path {
28         assert!(!idents.is_empty());
29         let add_root = global && !idents[0].is_path_segment_keyword();
30         let mut segments = Vec::with_capacity(idents.len() + add_root as usize);
31         if add_root {
32             segments.push(ast::PathSegment::path_root(span));
33         }
34         let last_ident = idents.pop().unwrap();
35         segments.extend(
36             idents.into_iter().map(|ident| ast::PathSegment::from_ident(ident.with_span_pos(span))),
37         );
38         let args = if !args.is_empty() {
39             let args = args.into_iter().map(ast::AngleBracketedArg::Arg).collect();
40             ast::AngleBracketedArgs { args, span }.into()
41         } else {
42             None
43         };
44         segments.push(ast::PathSegment {
45             ident: last_ident.with_span_pos(span),
46             id: ast::DUMMY_NODE_ID,
47             args,
48         });
49         ast::Path { span, segments, tokens: None }
50     }
51
52     pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
53         ast::MutTy { ty, mutbl }
54     }
55
56     pub fn ty(&self, span: Span, kind: ast::TyKind) -> P<ast::Ty> {
57         P(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None })
58     }
59
60     pub fn ty_infer(&self, span: Span) -> P<ast::Ty> {
61         self.ty(span, ast::TyKind::Infer)
62     }
63
64     pub fn ty_path(&self, path: ast::Path) -> P<ast::Ty> {
65         self.ty(path.span, ast::TyKind::Path(None, path))
66     }
67
68     // Might need to take bounds as an argument in the future, if you ever want
69     // to generate a bounded existential trait type.
70     pub fn ty_ident(&self, span: Span, ident: Ident) -> P<ast::Ty> {
71         self.ty_path(self.path_ident(span, ident))
72     }
73
74     pub fn anon_const(&self, span: Span, kind: ast::ExprKind) -> ast::AnonConst {
75         ast::AnonConst {
76             id: ast::DUMMY_NODE_ID,
77             value: P(ast::Expr {
78                 id: ast::DUMMY_NODE_ID,
79                 kind,
80                 span,
81                 attrs: AttrVec::new(),
82                 tokens: None,
83             }),
84         }
85     }
86
87     pub fn const_ident(&self, span: Span, ident: Ident) -> ast::AnonConst {
88         self.anon_const(span, ast::ExprKind::Path(None, self.path_ident(span, ident)))
89     }
90
91     pub fn ty_rptr(
92         &self,
93         span: Span,
94         ty: P<ast::Ty>,
95         lifetime: Option<ast::Lifetime>,
96         mutbl: ast::Mutability,
97     ) -> P<ast::Ty> {
98         self.ty(span, ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl)))
99     }
100
101     pub fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {
102         self.ty(span, ast::TyKind::Ptr(self.ty_mt(ty, mutbl)))
103     }
104
105     pub fn typaram(
106         &self,
107         span: Span,
108         ident: Ident,
109         attrs: Vec<ast::Attribute>,
110         bounds: ast::GenericBounds,
111         default: Option<P<ast::Ty>>,
112     ) -> ast::GenericParam {
113         ast::GenericParam {
114             ident: ident.with_span_pos(span),
115             id: ast::DUMMY_NODE_ID,
116             attrs: attrs.into(),
117             bounds,
118             kind: ast::GenericParamKind::Type { default },
119             is_placeholder: false,
120             colon_span: None,
121         }
122     }
123
124     pub fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
125         ast::TraitRef { path, ref_id: ast::DUMMY_NODE_ID }
126     }
127
128     pub fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef {
129         ast::PolyTraitRef {
130             bound_generic_params: Vec::new(),
131             trait_ref: self.trait_ref(path),
132             span,
133         }
134     }
135
136     pub fn trait_bound(&self, path: ast::Path) -> ast::GenericBound {
137         ast::GenericBound::Trait(
138             self.poly_trait_ref(path.span, path),
139             ast::TraitBoundModifier::None,
140         )
141     }
142
143     pub fn lifetime(&self, span: Span, ident: Ident) -> ast::Lifetime {
144         ast::Lifetime { id: ast::DUMMY_NODE_ID, ident: ident.with_span_pos(span) }
145     }
146
147     pub fn lifetime_static(&self, span: Span) -> ast::Lifetime {
148         self.lifetime(span, Ident::new(kw::StaticLifetime, span))
149     }
150
151     pub fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt {
152         ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Expr(expr) }
153     }
154
155     pub fn stmt_let_pat(&self, sp: Span, pat: P<ast::Pat>, ex: P<ast::Expr>) -> ast::Stmt {
156         let local = P(ast::Local {
157             pat,
158             ty: None,
159             id: ast::DUMMY_NODE_ID,
160             kind: LocalKind::Init(ex),
161             span: sp,
162             attrs: AttrVec::new(),
163             tokens: None,
164         });
165         self.stmt_local(local, sp)
166     }
167
168     pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<ast::Expr>) -> ast::Stmt {
169         self.stmt_let_ty(sp, mutbl, ident, None, ex)
170     }
171
172     pub fn stmt_let_ty(
173         &self,
174         sp: Span,
175         mutbl: bool,
176         ident: Ident,
177         ty: Option<P<ast::Ty>>,
178         ex: P<ast::Expr>,
179     ) -> ast::Stmt {
180         let pat = if mutbl {
181             let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mut);
182             self.pat_ident_binding_mode(sp, ident, binding_mode)
183         } else {
184             self.pat_ident(sp, ident)
185         };
186         let local = P(ast::Local {
187             pat,
188             ty,
189             id: ast::DUMMY_NODE_ID,
190             kind: LocalKind::Init(ex),
191             span: sp,
192             attrs: AttrVec::new(),
193             tokens: None,
194         });
195         self.stmt_local(local, sp)
196     }
197
198     // Generates `let _: Type;`, which is usually used for type assertions.
199     pub fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt {
200         let local = P(ast::Local {
201             pat: self.pat_wild(span),
202             ty: Some(ty),
203             id: ast::DUMMY_NODE_ID,
204             kind: LocalKind::Decl,
205             span,
206             attrs: AttrVec::new(),
207             tokens: None,
208         });
209         self.stmt_local(local, span)
210     }
211
212     pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt {
213         ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Local(local), span }
214     }
215
216     pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {
217         ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Item(item), span: sp }
218     }
219
220     pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
221         self.block(
222             expr.span,
223             vec![ast::Stmt {
224                 id: ast::DUMMY_NODE_ID,
225                 span: expr.span,
226                 kind: ast::StmtKind::Expr(expr),
227             }],
228         )
229     }
230     pub fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
231         P(ast::Block {
232             stmts,
233             id: ast::DUMMY_NODE_ID,
234             rules: BlockCheckMode::Default,
235             span,
236             tokens: None,
237             could_be_bare_literal: false,
238         })
239     }
240
241     pub fn expr(&self, span: Span, kind: ast::ExprKind) -> P<ast::Expr> {
242         P(ast::Expr { id: ast::DUMMY_NODE_ID, kind, span, attrs: AttrVec::new(), tokens: None })
243     }
244
245     pub fn expr_path(&self, path: ast::Path) -> P<ast::Expr> {
246         self.expr(path.span, ast::ExprKind::Path(None, path))
247     }
248
249     pub fn expr_ident(&self, span: Span, id: Ident) -> P<ast::Expr> {
250         self.expr_path(self.path_ident(span, id))
251     }
252     pub fn expr_self(&self, span: Span) -> P<ast::Expr> {
253         self.expr_ident(span, Ident::with_dummy_span(kw::SelfLower))
254     }
255
256     pub fn expr_binary(
257         &self,
258         sp: Span,
259         op: ast::BinOpKind,
260         lhs: P<ast::Expr>,
261         rhs: P<ast::Expr>,
262     ) -> P<ast::Expr> {
263         self.expr(sp, ast::ExprKind::Binary(Spanned { node: op, span: sp }, lhs, rhs))
264     }
265
266     pub fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
267         self.expr(sp, ast::ExprKind::Unary(UnOp::Deref, e))
268     }
269
270     pub fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
271         self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e))
272     }
273
274     pub fn expr_call(
275         &self,
276         span: Span,
277         expr: P<ast::Expr>,
278         args: Vec<P<ast::Expr>>,
279     ) -> P<ast::Expr> {
280         self.expr(span, ast::ExprKind::Call(expr, args))
281     }
282     pub fn expr_call_ident(&self, span: Span, id: Ident, args: Vec<P<ast::Expr>>) -> P<ast::Expr> {
283         self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args))
284     }
285     pub fn expr_call_global(
286         &self,
287         sp: Span,
288         fn_path: Vec<Ident>,
289         args: Vec<P<ast::Expr>>,
290     ) -> P<ast::Expr> {
291         let pathexpr = self.expr_path(self.path_global(sp, fn_path));
292         self.expr_call(sp, pathexpr, args)
293     }
294     pub fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> {
295         self.expr(b.span, ast::ExprKind::Block(b, None))
296     }
297     pub fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::ExprField {
298         ast::ExprField {
299             ident: ident.with_span_pos(span),
300             expr: e,
301             span,
302             is_shorthand: false,
303             attrs: AttrVec::new(),
304             id: ast::DUMMY_NODE_ID,
305             is_placeholder: false,
306         }
307     }
308     pub fn expr_struct(
309         &self,
310         span: Span,
311         path: ast::Path,
312         fields: Vec<ast::ExprField>,
313     ) -> P<ast::Expr> {
314         self.expr(
315             span,
316             ast::ExprKind::Struct(P(ast::StructExpr {
317                 qself: None,
318                 path,
319                 fields,
320                 rest: ast::StructRest::None,
321             })),
322         )
323     }
324     pub fn expr_struct_ident(
325         &self,
326         span: Span,
327         id: Ident,
328         fields: Vec<ast::ExprField>,
329     ) -> P<ast::Expr> {
330         self.expr_struct(span, self.path_ident(span, id), fields)
331     }
332
333     pub fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
334         let lit = ast::Lit::from_lit_kind(lit_kind, span);
335         self.expr(span, ast::ExprKind::Lit(lit))
336     }
337     pub fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
338         self.expr_lit(
339             span,
340             ast::LitKind::Int(i as u128, ast::LitIntType::Unsigned(ast::UintTy::Usize)),
341         )
342     }
343     pub fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
344         self.expr_lit(sp, ast::LitKind::Int(u as u128, ast::LitIntType::Unsigned(ast::UintTy::U32)))
345     }
346     pub fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
347         self.expr_lit(sp, ast::LitKind::Bool(value))
348     }
349
350     /// `[expr1, expr2, ...]`
351     pub fn expr_array(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
352         self.expr(sp, ast::ExprKind::Array(exprs))
353     }
354
355     /// `&[expr1, expr2, ...]`
356     pub fn expr_array_ref(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
357         self.expr_addr_of(sp, self.expr_array(sp, exprs))
358     }
359
360     pub fn expr_str(&self, sp: Span, s: Symbol) -> P<ast::Expr> {
361         self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked))
362     }
363
364     pub fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
365         self.expr(sp, ast::ExprKind::Cast(expr, ty))
366     }
367
368     pub fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
369         let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
370         self.expr_call_global(sp, some, vec![expr])
371     }
372
373     pub fn expr_none(&self, sp: Span) -> P<ast::Expr> {
374         let none = self.std_path(&[sym::option, sym::Option, sym::None]);
375         self.expr_path(self.path_global(sp, none))
376     }
377     pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
378         self.expr(sp, ast::ExprKind::Tup(exprs))
379     }
380
381     pub fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> {
382         self.expr_call_global(
383             span,
384             [sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(),
385             vec![self.expr_str(span, msg)],
386         )
387     }
388
389     pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
390         self.expr_fail(span, Symbol::intern("internal error: entered unreachable code"))
391     }
392
393     pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
394         let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
395         self.expr_call_global(sp, ok, vec![expr])
396     }
397
398     pub fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
399         let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
400         let ok_path = self.path_global(sp, ok);
401         let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
402         let err_path = self.path_global(sp, err);
403
404         let binding_variable = Ident::new(sym::__try_var, sp);
405         let binding_pat = self.pat_ident(sp, binding_variable);
406         let binding_expr = self.expr_ident(sp, binding_variable);
407
408         // `Ok(__try_var)` pattern
409         let ok_pat = self.pat_tuple_struct(sp, ok_path, vec![binding_pat.clone()]);
410
411         // `Err(__try_var)` (pattern and expression respectively)
412         let err_pat = self.pat_tuple_struct(sp, err_path.clone(), vec![binding_pat]);
413         let err_inner_expr =
414             self.expr_call(sp, self.expr_path(err_path), vec![binding_expr.clone()]);
415         // `return Err(__try_var)`
416         let err_expr = self.expr(sp, ast::ExprKind::Ret(Some(err_inner_expr)));
417
418         // `Ok(__try_var) => __try_var`
419         let ok_arm = self.arm(sp, ok_pat, binding_expr);
420         // `Err(__try_var) => return Err(__try_var)`
421         let err_arm = self.arm(sp, err_pat, err_expr);
422
423         // `match head { Ok() => ..., Err() => ... }`
424         self.expr_match(sp, head, vec![ok_arm, err_arm])
425     }
426
427     pub fn pat(&self, span: Span, kind: PatKind) -> P<ast::Pat> {
428         P(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None })
429     }
430     pub fn pat_wild(&self, span: Span) -> P<ast::Pat> {
431         self.pat(span, PatKind::Wild)
432     }
433     pub fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
434         self.pat(span, PatKind::Lit(expr))
435     }
436     pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> {
437         let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Not);
438         self.pat_ident_binding_mode(span, ident, binding_mode)
439     }
440
441     pub fn pat_ident_binding_mode(
442         &self,
443         span: Span,
444         ident: Ident,
445         bm: ast::BindingMode,
446     ) -> P<ast::Pat> {
447         let pat = PatKind::Ident(bm, ident.with_span_pos(span), None);
448         self.pat(span, pat)
449     }
450     pub fn pat_path(&self, span: Span, path: ast::Path) -> P<ast::Pat> {
451         self.pat(span, PatKind::Path(None, path))
452     }
453     pub fn pat_tuple_struct(
454         &self,
455         span: Span,
456         path: ast::Path,
457         subpats: Vec<P<ast::Pat>>,
458     ) -> P<ast::Pat> {
459         self.pat(span, PatKind::TupleStruct(None, path, subpats))
460     }
461     pub fn pat_struct(
462         &self,
463         span: Span,
464         path: ast::Path,
465         field_pats: Vec<ast::PatField>,
466     ) -> P<ast::Pat> {
467         self.pat(span, PatKind::Struct(None, path, field_pats, false))
468     }
469     pub fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
470         self.pat(span, PatKind::Tuple(pats))
471     }
472
473     pub fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
474         let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
475         let path = self.path_global(span, some);
476         self.pat_tuple_struct(span, path, vec![pat])
477     }
478
479     pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm {
480         ast::Arm {
481             attrs: AttrVec::new(),
482             pat,
483             guard: None,
484             body: expr,
485             span,
486             id: ast::DUMMY_NODE_ID,
487             is_placeholder: false,
488         }
489     }
490
491     pub fn arm_unreachable(&self, span: Span) -> ast::Arm {
492         self.arm(span, self.pat_wild(span), self.expr_unreachable(span))
493     }
494
495     pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
496         self.expr(span, ast::ExprKind::Match(arg, arms))
497     }
498
499     pub fn expr_if(
500         &self,
501         span: Span,
502         cond: P<ast::Expr>,
503         then: P<ast::Expr>,
504         els: Option<P<ast::Expr>>,
505     ) -> P<ast::Expr> {
506         let els = els.map(|x| self.expr_block(self.block_expr(x)));
507         self.expr(span, ast::ExprKind::If(cond, self.block_expr(then), els))
508     }
509
510     pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: P<ast::Expr>) -> P<ast::Expr> {
511         let fn_decl = self.fn_decl(
512             ids.iter().map(|id| self.param(span, *id, self.ty(span, ast::TyKind::Infer))).collect(),
513             ast::FnRetTy::Default(span),
514         );
515
516         // FIXME -- We are using `span` as the span of the `|...|`
517         // part of the lambda, but it probably (maybe?) corresponds to
518         // the entire lambda body. Probably we should extend the API
519         // here, but that's not entirely clear.
520         self.expr(
521             span,
522             ast::ExprKind::Closure(
523                 ast::ClosureBinder::NotPresent,
524                 ast::CaptureBy::Ref,
525                 ast::Async::No,
526                 ast::Movability::Movable,
527                 fn_decl,
528                 body,
529                 span,
530             ),
531         )
532     }
533
534     pub fn lambda0(&self, span: Span, body: P<ast::Expr>) -> P<ast::Expr> {
535         self.lambda(span, Vec::new(), body)
536     }
537
538     pub fn lambda1(&self, span: Span, body: P<ast::Expr>, ident: Ident) -> P<ast::Expr> {
539         self.lambda(span, vec![ident], body)
540     }
541
542     pub fn lambda_stmts_1(&self, span: Span, stmts: Vec<ast::Stmt>, ident: Ident) -> P<ast::Expr> {
543         self.lambda1(span, self.expr_block(self.block(span, stmts)), ident)
544     }
545
546     pub fn param(&self, span: Span, ident: Ident, ty: P<ast::Ty>) -> ast::Param {
547         let arg_pat = self.pat_ident(span, ident);
548         ast::Param {
549             attrs: AttrVec::default(),
550             id: ast::DUMMY_NODE_ID,
551             pat: arg_pat,
552             span,
553             ty,
554             is_placeholder: false,
555         }
556     }
557
558     // `self` is unused but keep it as method for the convenience use.
559     pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> {
560         P(ast::FnDecl { inputs, output })
561     }
562
563     pub fn item(
564         &self,
565         span: Span,
566         name: Ident,
567         attrs: Vec<ast::Attribute>,
568         kind: ast::ItemKind,
569     ) -> P<ast::Item> {
570         // FIXME: Would be nice if our generated code didn't violate
571         // Rust coding conventions
572         P(ast::Item {
573             ident: name,
574             attrs,
575             id: ast::DUMMY_NODE_ID,
576             kind,
577             vis: ast::Visibility {
578                 span: span.shrink_to_lo(),
579                 kind: ast::VisibilityKind::Inherited,
580                 tokens: None,
581             },
582             span,
583             tokens: None,
584         })
585     }
586
587     pub fn item_static(
588         &self,
589         span: Span,
590         name: Ident,
591         ty: P<ast::Ty>,
592         mutbl: ast::Mutability,
593         expr: P<ast::Expr>,
594     ) -> P<ast::Item> {
595         self.item(span, name, Vec::new(), ast::ItemKind::Static(ty, mutbl, Some(expr)))
596     }
597
598     pub fn item_const(
599         &self,
600         span: Span,
601         name: Ident,
602         ty: P<ast::Ty>,
603         expr: P<ast::Expr>,
604     ) -> P<ast::Item> {
605         let def = ast::Defaultness::Final;
606         self.item(span, name, Vec::new(), ast::ItemKind::Const(def, ty, Some(expr)))
607     }
608
609     pub fn attribute(&self, mi: ast::MetaItem) -> ast::Attribute {
610         attr::mk_attr_outer(mi)
611     }
612
613     pub fn meta_word(&self, sp: Span, w: Symbol) -> ast::MetaItem {
614         attr::mk_word_item(Ident::new(w, sp))
615     }
616 }