summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_expand/src/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_expand/src/build.rs')
-rw-r--r--compiler/rustc_expand/src/build.rs50
1 files changed, 31 insertions, 19 deletions
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs
index 0952e65cf..4812bdd9d 100644
--- a/compiler/rustc_expand/src/build.rs
+++ b/compiler/rustc_expand/src/build.rs
@@ -1,13 +1,12 @@
use crate::base::ExtCtxt;
-
use rustc_ast::attr;
use rustc_ast::ptr::P;
use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp};
use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
-
use rustc_span::Span;
+use thin_vec::ThinVec;
impl<'a> ExtCtxt<'a> {
pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path {
@@ -28,7 +27,7 @@ impl<'a> ExtCtxt<'a> {
) -> ast::Path {
assert!(!idents.is_empty());
let add_root = global && !idents[0].is_path_segment_keyword();
- let mut segments = Vec::with_capacity(idents.len() + add_root as usize);
+ let mut segments = ThinVec::with_capacity(idents.len() + add_root as usize);
if add_root {
segments.push(ast::PathSegment::path_root(span));
}
@@ -194,7 +193,7 @@ impl<'a> ExtCtxt<'a> {
self.stmt_local(local, sp)
}
- // Generates `let _: Type;`, which is usually used for type assertions.
+ /// Generates `let _: Type;`, which is usually used for type assertions.
pub fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt {
let local = P(ast::Local {
pat: self.pat_wild(span),
@@ -334,8 +333,8 @@ impl<'a> ExtCtxt<'a> {
}
fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
- let lit = ast::Lit::from_lit_kind(lit_kind, span);
- self.expr(span, ast::ExprKind::Lit(lit))
+ let token_lit = lit_kind.to_token_lit();
+ self.expr(span, ast::ExprKind::Lit(token_lit))
}
pub fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
@@ -532,15 +531,18 @@ impl<'a> ExtCtxt<'a> {
// here, but that's not entirely clear.
self.expr(
span,
- ast::ExprKind::Closure(
- ast::ClosureBinder::NotPresent,
- ast::CaptureBy::Ref,
- ast::Async::No,
- ast::Movability::Movable,
+ ast::ExprKind::Closure(Box::new(ast::Closure {
+ binder: ast::ClosureBinder::NotPresent,
+ capture_clause: ast::CaptureBy::Ref,
+ asyncness: ast::Async::No,
+ movability: ast::Movability::Movable,
fn_decl,
body,
- span,
- ),
+ fn_decl_span: span,
+ // FIXME(SarthakSingh31): This points to the start of the declaration block and
+ // not the span of the argument block.
+ fn_arg_span: span,
+ })),
)
}
@@ -580,8 +582,6 @@ impl<'a> ExtCtxt<'a> {
attrs: ast::AttrVec,
kind: ast::ItemKind,
) -> P<ast::Item> {
- // FIXME: Would be nice if our generated code didn't violate
- // Rust coding conventions
P(ast::Item {
ident: name,
attrs,
@@ -619,11 +619,23 @@ impl<'a> ExtCtxt<'a> {
self.item(span, name, AttrVec::new(), ast::ItemKind::Const(def, ty, Some(expr)))
}
- pub fn attribute(&self, mi: ast::MetaItem) -> ast::Attribute {
- attr::mk_attr_outer(&self.sess.parse_sess.attr_id_generator, mi)
+ // Builds `#[name]`.
+ pub fn attr_word(&self, name: Symbol, span: Span) -> ast::Attribute {
+ let g = &self.sess.parse_sess.attr_id_generator;
+ attr::mk_attr_word(g, ast::AttrStyle::Outer, name, span)
+ }
+
+ // Builds `#[name = val]`.
+ //
+ // Note: `span` is used for both the identifer and the value.
+ pub fn attr_name_value_str(&self, name: Symbol, val: Symbol, span: Span) -> ast::Attribute {
+ let g = &self.sess.parse_sess.attr_id_generator;
+ attr::mk_attr_name_value_str(g, ast::AttrStyle::Outer, name, val, span)
}
- pub fn meta_word(&self, sp: Span, w: Symbol) -> ast::MetaItem {
- attr::mk_word_item(Ident::new(w, sp))
+ // Builds `#[outer(inner)]`.
+ pub fn attr_nested_word(&self, outer: Symbol, inner: Symbol, span: Span) -> ast::Attribute {
+ let g = &self.sess.parse_sess.attr_id_generator;
+ attr::mk_attr_nested_word(g, ast::AttrStyle::Outer, outer, inner, span)
}
}