Rollup merge of #64670 - Mark-Simulacrum:ext-build-simplify, r=petrochenkov

Cleanup syntax::ext::build

I suspect most of this code could be inlined but I only removed the bits where the inlining didn't really hurt readability (i.e., method call -> function call) or the completely unused code.
This commit is contained in:
Mazdak Farrokhzad
2019-09-23 00:36:34 +02:00
committed by GitHub
7 changed files with 27 additions and 331 deletions

View File

@@ -115,7 +115,7 @@ fn cs_clone_shallow(name: &str,
let span = cx.with_def_site_ctxt(span);
let assert_path = cx.path_all(span, true,
cx.std_path(&[sym::clone, Symbol::intern(helper_name)]),
vec![GenericArg::Type(ty)], vec![]);
vec![GenericArg::Type(ty)]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
}
fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {

View File

@@ -2,7 +2,7 @@ use crate::deriving::path_std;
use crate::deriving::generic::*;
use crate::deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem, GenericArg};
use syntax::ast::{self, Ident, Expr, MetaItem, GenericArg};
use syntax::ext::base::{Annotatable, ExtCtxt, SpecialDerives};
use syntax::ptr::P;
use syntax::symbol::{sym, Symbol};
@@ -16,8 +16,8 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::EQ);
let inline = cx.meta_word(span, sym::inline);
let hidden = cx.meta_list_item_word(span, sym::hidden);
let doc = cx.meta_list(span, sym::doc, vec![hidden]);
let hidden = syntax::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
let doc = syntax::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
let attrs = vec![cx.attribute(inline), cx.attribute(doc)];
let trait_def = TraitDef {
span,
@@ -56,7 +56,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>,
let span = cx.with_def_site_ctxt(span);
let assert_path = cx.path_all(span, true,
cx.std_path(&[sym::cmp, Symbol::intern(helper_name)]),
vec![GenericArg::Type(ty)], vec![]);
vec![GenericArg::Type(ty)]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
}
fn process_variant(cx: &mut ExtCtxt<'_>,

View File

@@ -664,7 +664,7 @@ impl<'a> TraitDef<'a> {
}).collect();
// Create the type of `self`.
let path = cx.path_all(self.span, false, vec![type_ident], self_params, vec![]);
let path = cx.path_all(self.span, false, vec![type_ident], self_params);
let self_type = cx.ty_path(path);
let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
@@ -672,8 +672,11 @@ impl<'a> TraitDef<'a> {
attr::mark_used(&attr);
let opt_trait_ref = Some(trait_ref);
let unused_qual = {
let word = cx.meta_list_item_word(self.span, Symbol::intern("unused_qualifications"));
cx.attribute(cx.meta_list(self.span, sym::allow, vec![word]))
let word = syntax::attr::mk_nested_word_item(
Ident::new(Symbol::intern("unused_qualifications"), self.span));
let list = syntax::attr::mk_list_item(
Ident::new(sym::allow, self.span), vec![word]);
cx.attribute(list)
};
let mut a = vec![attr, unused_qual];

View File

@@ -82,12 +82,12 @@ impl<'a> Path<'a> {
.collect();
match self.kind {
PathKind::Global => cx.path_all(span, true, idents, params, Vec::new()),
PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()),
PathKind::Global => cx.path_all(span, true, idents, params),
PathKind::Local => cx.path_all(span, false, idents, params),
PathKind::Std => {
let def_site = cx.with_def_site_ctxt(DUMMY_SP);
idents.insert(0, Ident::new(kw::DollarCrate, def_site));
cx.path_all(span, false, idents, params, Vec::new())
cx.path_all(span, false, idents, params)
}
}
@@ -183,7 +183,7 @@ impl<'a> Ty<'a> {
}
}).collect();
cx.path_all(span, false, vec![self_ty], params, vec![])
cx.path_all(span, false, vec![self_ty], params)
}
Literal(ref p) => p.to_path(cx, span, self_ty, generics),
Ptr(..) => cx.span_bug(span, "pointer in a path in generic `derive`"),

View File

@@ -32,7 +32,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
Ident::new(sym::str, sp)),
Some(lt),
ast::Mutability::Immutable))],
vec![]))
))
}
Ok(s) => {
cx.expr_call_global(sp,

View File

@@ -145,8 +145,8 @@ pub fn expand_test_or_bench(
let mut test_const = cx.item(sp, ast::Ident::new(item.ident.name, sp),
vec![
// #[cfg(test)]
cx.attribute(cx.meta_list(attr_sp, sym::cfg, vec![
cx.meta_list_item_word(attr_sp, sym::test)
cx.attribute(attr::mk_list_item(ast::Ident::new(sym::cfg, attr_sp), vec![
attr::mk_nested_word_item(ast::Ident::new(sym::test, attr_sp))
])),
// #[rustc_test_marker]
cx.attribute(cx.meta_word(attr_sp, sym::rustc_test_marker)),