libsyntax_ext => 2018

This commit is contained in:
Taiki Endo 2019-02-04 21:49:54 +09:00
parent e858c2637f
commit 94f121ff3f
35 changed files with 269 additions and 268 deletions

View file

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"] authors = ["The Rust Project Developers"]
name = "syntax_ext" name = "syntax_ext"
version = "0.0.0" version = "0.0.0"
edition = "2018"
[lib] [lib]
name = "syntax_ext" name = "syntax_ext"

View file

@ -1,13 +1,13 @@
// Inline assembly support. // Inline assembly support.
// //
use self::State::*; use State::*;
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
use errors::DiagnosticBuilder; use crate::errors::DiagnosticBuilder;
use syntax::ast; use syntax::ast;
use syntax::ext::base; use syntax::ext::base::{self, *};
use syntax::ext::base::*;
use syntax::feature_gate; use syntax::feature_gate;
use syntax::parse::{self, token}; use syntax::parse::{self, token};
use syntax::ptr::P; use syntax::ptr::P;
@ -15,6 +15,7 @@ use syntax::symbol::Symbol;
use syntax::ast::AsmDialect; use syntax::ast::AsmDialect;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
use syntax::{span_err, struct_span_err};
enum State { enum State {
Asm, Asm,
@ -40,7 +41,7 @@ impl State {
const OPTIONS: &[&str] = &["volatile", "alignstack", "intel"]; const OPTIONS: &[&str] = &["volatile", "alignstack", "intel"];
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {

View file

@ -1,4 +1,5 @@
use errors::DiagnosticBuilder; use crate::errors::DiagnosticBuilder;
use syntax::ast::{self, *}; use syntax::ast::{self, *};
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
use syntax::ext::base::*; use syntax::ext::base::*;
@ -11,7 +12,7 @@ use syntax::tokenstream::{TokenStream, TokenTree};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
pub fn expand_assert<'cx>( pub fn expand_assert<'cx>(
cx: &'cx mut ExtCtxt, cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[TokenTree], tts: &[TokenTree],
) -> Box<dyn MacResult + 'cx> { ) -> Box<dyn MacResult + 'cx> {

View file

@ -2,17 +2,17 @@
/// a literal `true` or `false` based on whether the given cfg matches the /// a literal `true` or `false` based on whether the given cfg matches the
/// current compilation environment. /// current compilation environment.
use errors::DiagnosticBuilder; use crate::errors::DiagnosticBuilder;
use syntax::ast; use syntax::ast;
use syntax::ext::base::*; use syntax::ext::base::{self, *};
use syntax::ext::base;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::attr; use syntax::attr;
use syntax::tokenstream; use syntax::tokenstream;
use syntax::parse::token; use syntax::parse::token;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_cfg<'cx>(cx: &mut ExtCtxt, pub fn expand_cfg<'cx>(cx: &mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'static> { -> Box<dyn base::MacResult + 'static> {

View file

@ -1,11 +1,10 @@
// The compiler code necessary to support the compile_error! extension. // The compiler code necessary to support the compile_error! extension.
use syntax::ext::base::*; use syntax::ext::base::{self, *};
use syntax::ext::base;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
pub fn expand_compile_error<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_compile_error<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {

View file

@ -3,12 +3,11 @@ use syntax::ext::base;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::tokenstream; use syntax::tokenstream;
use syntax_pos;
use std::string::String; use std::string::String;
pub fn expand_syntax_ext( pub fn expand_syntax_ext(
cx: &mut base::ExtCtxt, cx: &mut base::ExtCtxt<'_>,
sp: syntax_pos::Span, sp: syntax_pos::Span,
tts: &[tokenstream::TokenTree], tts: &[tokenstream::TokenTree],
) -> Box<dyn base::MacResult + 'static> { ) -> Box<dyn base::MacResult + 'static> {

View file

@ -1,8 +1,7 @@
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
use syntax::ast; use syntax::ast;
use syntax::ext::base::*; use syntax::ext::base::{self, *};
use syntax::ext::base;
use syntax::feature_gate; use syntax::feature_gate;
use syntax::parse::token; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
@ -10,7 +9,7 @@ use syntax_pos::Span;
use syntax_pos::symbol::Symbol; use syntax_pos::symbol::Symbol;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[TokenTree]) tts: &[TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {

View file

@ -1,11 +1,12 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::MetaItem; use syntax::ast::MetaItem;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt, pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
_: &MetaItem, _: &MetaItem,
_: &Annotatable, _: &Annotatable,
@ -13,7 +14,7 @@ pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
cx.span_err(span, "this unsafe trait should be implemented explicitly"); cx.span_err(span, "this unsafe trait should be implemented explicitly");
} }
pub fn expand_deriving_copy(cx: &mut ExtCtxt, pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,

View file

@ -1,9 +1,8 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
use syntax::ast::GenericArg;
use syntax::attr; use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -11,7 +10,7 @@ use syntax::ptr::P;
use syntax::symbol::{Symbol, keywords}; use syntax::symbol::{Symbol, keywords};
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_clone(cx: &mut ExtCtxt, pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -105,12 +104,12 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
} }
fn cs_clone_shallow(name: &str, fn cs_clone_shallow(name: &str,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substr: &Substructure, substr: &Substructure<'_>,
is_union: bool) is_union: bool)
-> P<Expr> { -> P<Expr> {
fn assert_ty_bounds(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, fn assert_ty_bounds(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>,
ty: P<ast::Ty>, span: Span, helper_name: &str) { ty: P<ast::Ty>, span: Span, helper_name: &str) {
// Generate statement `let _: helper_name<ty>;`, // Generate statement `let _: helper_name<ty>;`,
// set the expn ID so we can use the unstable struct. // set the expn ID so we can use the unstable struct.
@ -120,7 +119,7 @@ fn cs_clone_shallow(name: &str,
vec![GenericArg::Type(ty)], vec![]); vec![GenericArg::Type(ty)], vec![]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); 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) { fn process_variant(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {
for field in variant.fields() { for field in variant.fields() {
// let _: AssertParamIsClone<FieldTy>; // let _: AssertParamIsClone<FieldTy>;
assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsClone"); assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsClone");
@ -151,14 +150,14 @@ fn cs_clone_shallow(name: &str,
} }
fn cs_clone(name: &str, fn cs_clone(name: &str,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substr: &Substructure) substr: &Substructure<'_>)
-> P<Expr> { -> P<Expr> {
let ctor_path; let ctor_path;
let all_fields; let all_fields;
let fn_path = cx.std_path(&["clone", "Clone", "clone"]); let fn_path = cx.std_path(&["clone", "Clone", "clone"]);
let subcall = |cx: &mut ExtCtxt, field: &FieldInfo| { let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())]; let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
cx.expr_call_global(field.span, fn_path.clone(), args) cx.expr_call_global(field.span, fn_path.clone(), args)
}; };

View file

@ -1,6 +1,6 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem, GenericArg}; use syntax::ast::{self, Expr, MetaItem, GenericArg};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -9,7 +9,7 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_eq(cx: &mut ExtCtxt, pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -44,8 +44,11 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
trait_def.expand_ext(cx, mitem, item, push, true) trait_def.expand_ext(cx, mitem, item, push, true)
} }
fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>,
fn assert_ty_bounds(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, trait_span: Span,
substr: &Substructure<'_>)
-> P<Expr> {
fn assert_ty_bounds(cx: &mut ExtCtxt<'_>, stmts: &mut Vec<ast::Stmt>,
ty: P<ast::Ty>, span: Span, helper_name: &str) { ty: P<ast::Ty>, span: Span, helper_name: &str) {
// Generate statement `let _: helper_name<ty>;`, // Generate statement `let _: helper_name<ty>;`,
// set the expn ID so we can use the unstable struct. // set the expn ID so we can use the unstable struct.
@ -55,7 +58,9 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
vec![GenericArg::Type(ty)], vec![]); vec![GenericArg::Type(ty)], vec![]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); 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: &ast::VariantData) { fn process_variant(cx: &mut ExtCtxt<'_>,
stmts: &mut Vec<ast::Stmt>,
variant: &ast::VariantData) {
for field in variant.fields() { for field in variant.fields() {
// let _: AssertParamIsEq<FieldTy>; // let _: AssertParamIsEq<FieldTy>;
assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsEq"); assert_ty_bounds(cx, stmts, field.ty.clone(), field.span, "AssertParamIsEq");

View file

@ -1,6 +1,6 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem}; use syntax::ast::{self, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -9,7 +9,7 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_ord(cx: &mut ExtCtxt, pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -44,7 +44,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
} }
pub fn ordering_collapsed(cx: &mut ExtCtxt, pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
self_arg_tags: &[ast::Ident]) self_arg_tags: &[ast::Ident])
-> P<ast::Expr> { -> P<ast::Expr> {
@ -53,7 +53,7 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt,
cx.expr_method_call(span, lft, cx.ident_of("cmp"), vec![rgt]) cx.expr_method_call(span, lft, cx.ident_of("cmp"), vec![rgt])
} }
pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
let test_id = cx.ident_of("cmp").gensym(); let test_id = cx.ident_of("cmp").gensym();
let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));

View file

@ -1,6 +1,6 @@
use deriving::{path_local, path_std}; use crate::deriving::{path_local, path_std};
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{BinOpKind, Expr, MetaItem}; use syntax::ast::{BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -9,22 +9,22 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
// structures are equal if all fields are equal, and non equal, if // structures are equal if all fields are equal, and non equal, if
// any fields are not equal or if the enum variants are different // any fields are not equal or if the enum variants are different
fn cs_op(cx: &mut ExtCtxt, fn cs_op(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
substr: &Substructure, substr: &Substructure<'_>,
op: BinOpKind, op: BinOpKind,
combiner: BinOpKind, combiner: BinOpKind,
base: bool) base: bool)
-> P<Expr> -> P<Expr>
{ {
let op = |cx: &mut ExtCtxt, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| { let op = |cx: &mut ExtCtxt<'_>, span: Span, self_f: P<Expr>, other_fs: &[P<Expr>]| {
let other_f = match (other_fs.len(), other_fs.get(0)) { let other_f = match (other_fs.len(), other_fs.get(0)) {
(1, Some(o_f)) => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`"), _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`"),
@ -53,10 +53,10 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
substr) substr)
} }
fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { fn cs_eq(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
cs_op(cx, span, substr, BinOpKind::Eq, BinOpKind::And, true) cs_op(cx, span, substr, BinOpKind::Eq, BinOpKind::And, true)
} }
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { fn cs_ne(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
cs_op(cx, span, substr, BinOpKind::Ne, BinOpKind::Or, false) cs_op(cx, span, substr, BinOpKind::Ne, BinOpKind::Or, false)
} }

View file

@ -1,8 +1,8 @@
pub use self::OrderingOp::*; pub use OrderingOp::*;
use deriving::{path_local, pathvec_std, path_std}; use crate::deriving::{path_local, pathvec_std, path_std};
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{self, BinOpKind, Expr, MetaItem}; use syntax::ast::{self, BinOpKind, Expr, MetaItem};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -11,7 +11,7 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -95,7 +95,7 @@ pub enum OrderingOp {
GeOp, GeOp,
} }
pub fn some_ordering_collapsed(cx: &mut ExtCtxt, pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
op: OrderingOp, op: OrderingOp,
self_arg_tags: &[ast::Ident]) self_arg_tags: &[ast::Ident])
@ -112,7 +112,7 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt,
cx.expr_method_call(span, lft, cx.ident_of(op_str), vec![rgt]) cx.expr_method_call(span, lft, cx.ident_of(op_str), vec![rgt])
} }
pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
let test_id = cx.ident_of("cmp").gensym(); let test_id = cx.ident_of("cmp").gensym();
let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
let ordering_expr = cx.expr_path(ordering.clone()); let ordering_expr = cx.expr_path(ordering.clone());
@ -184,14 +184,14 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
/// Strict inequality. /// Strict inequality.
fn cs_op(less: bool, fn cs_op(less: bool,
inclusive: bool, inclusive: bool,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
substr: &Substructure) -> P<Expr> { substr: &Substructure<'_>) -> P<Expr> {
let ordering_path = |cx: &mut ExtCtxt, name: &str| { let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| {
cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name]))) cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name])))
}; };
let par_cmp = |cx: &mut ExtCtxt, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| { let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
let other_f = match (other_fs.len(), other_fs.get(0)) { let other_f = match (other_fs.len(), other_fs.get(0)) {
(1, Some(o_f)) => o_f, (1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"), _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),

View file

@ -1,4 +1,7 @@
use errors::FatalError; use crate::errors::FatalError;
use crate::proc_macro_impl::EXEC_STRATEGY;
use crate::proc_macro_server;
use syntax::ast::{self, ItemKind, Attribute, Mac}; use syntax::ast::{self, ItemKind, Attribute, Mac};
use syntax::attr::{mark_used, mark_known}; use syntax::attr::{mark_used, mark_known};
use syntax::source_map::Span; use syntax::source_map::Span;
@ -9,8 +12,6 @@ use syntax::tokenstream;
use syntax::visit::Visitor; use syntax::visit::Visitor;
use syntax_pos::DUMMY_SP; use syntax_pos::DUMMY_SP;
use proc_macro_impl::EXEC_STRATEGY;
struct MarkAttrs<'a>(&'a [ast::Name]); struct MarkAttrs<'a>(&'a [ast::Name]);
impl<'a> Visitor<'a> for MarkAttrs<'a> { impl<'a> Visitor<'a> for MarkAttrs<'a> {
@ -25,15 +26,15 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
} }
pub struct ProcMacroDerive { pub struct ProcMacroDerive {
pub client: ::proc_macro::bridge::client::Client< pub client: proc_macro::bridge::client::Client<
fn(::proc_macro::TokenStream) -> ::proc_macro::TokenStream, fn(proc_macro::TokenStream) -> proc_macro::TokenStream,
>, >,
pub attrs: Vec<ast::Name>, pub attrs: Vec<ast::Name>,
} }
impl MultiItemModifier for ProcMacroDerive { impl MultiItemModifier for ProcMacroDerive {
fn expand(&self, fn expand(&self,
ecx: &mut ExtCtxt, ecx: &mut ExtCtxt<'_>,
span: Span, span: Span,
_meta_item: &ast::MetaItem, _meta_item: &ast::MetaItem,
item: Annotatable) item: Annotatable)
@ -67,7 +68,7 @@ impl MultiItemModifier for ProcMacroDerive {
let token = Token::interpolated(token::NtItem(item)); let token = Token::interpolated(token::NtItem(item));
let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into(); let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();
let server = ::proc_macro_server::Rustc::new(ecx); let server = proc_macro_server::Rustc::new(ecx);
let stream = match self.client.run(&EXEC_STRATEGY, server, input) { let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream, Ok(stream) => stream,
Err(e) => { Err(e) => {

View file

@ -1,6 +1,6 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
@ -11,7 +11,7 @@ use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
pub fn expand_deriving_debug(cx: &mut ExtCtxt, pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -47,7 +47,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
} }
/// We use the debug builders to do the heavy lifting here /// We use the debug builders to do the heavy lifting here
fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
// build fmt.debug_struct(<name>).field(<fieldname>, &<fieldval>)....build() // build fmt.debug_struct(<name>).field(<fieldname>, &<fieldval>)....build()
// or fmt.debug_tuple(<name>).field(&<fieldval>)....build() // or fmt.debug_tuple(<name>).field(&<fieldval>)....build()
// based on the "shape". // based on the "shape".
@ -124,7 +124,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<E
cx.expr_block(block) cx.expr_block(block)
} }
fn stmt_let_undescore(cx: &mut ExtCtxt, sp: Span, expr: P<ast::Expr>) -> ast::Stmt { fn stmt_let_undescore(cx: &mut ExtCtxt<'_>, sp: Span, expr: P<ast::Expr>) -> ast::Stmt {
let local = P(ast::Local { let local = P(ast::Local {
pat: cx.pat_wild(sp), pat: cx.pat_wild(sp),
ty: None, ty: None,

View file

@ -1,9 +1,9 @@
//! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more. //! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more.
use deriving::{self, pathvec_std}; use crate::deriving::{self, pathvec_std};
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use deriving::warn_if_deprecated; use crate::deriving::warn_if_deprecated;
use syntax::ast; use syntax::ast;
use syntax::ast::{Expr, MetaItem, Mutability}; use syntax::ast::{Expr, MetaItem, Mutability};
@ -13,7 +13,7 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt, pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -21,7 +21,7 @@ pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt,
expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize") expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize")
} }
pub fn expand_deriving_decodable(cx: &mut ExtCtxt, pub fn expand_deriving_decodable(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -30,7 +30,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize") expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize")
} }
fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, fn expand_deriving_decodable_imp(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -79,9 +79,9 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
trait_def.expand(cx, mitem, item, push) trait_def.expand(cx, mitem, item, push)
} }
fn decodable_substructure(cx: &mut ExtCtxt, fn decodable_substructure(cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substr: &Substructure, substr: &Substructure<'_>,
krate: &str) krate: &str)
-> P<Expr> { -> P<Expr> {
let decoder = substr.nonself_args[0].clone(); let decoder = substr.nonself_args[0].clone();
@ -168,13 +168,13 @@ fn decodable_substructure(cx: &mut ExtCtxt,
/// Create a decoder for a single enum variant/struct: /// Create a decoder for a single enum variant/struct:
/// - `outer_pat_path` is the path to this enum variant/struct /// - `outer_pat_path` is the path to this enum variant/struct
/// - `getarg` should retrieve the `usize`-th field with name `@str`. /// - `getarg` should retrieve the `usize`-th field with name `@str`.
fn decode_static_fields<F>(cx: &mut ExtCtxt, fn decode_static_fields<F>(cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
outer_pat_path: ast::Path, outer_pat_path: ast::Path,
fields: &StaticFields, fields: &StaticFields,
mut getarg: F) mut getarg: F)
-> P<Expr> -> P<Expr>
where F: FnMut(&mut ExtCtxt, Span, Symbol, usize) -> P<Expr> where F: FnMut(&mut ExtCtxt<'_>, Span, Symbol, usize) -> P<Expr>
{ {
match *fields { match *fields {
Unnamed(ref fields, is_tuple) => { Unnamed(ref fields, is_tuple) => {

View file

@ -1,15 +1,16 @@
use deriving::path_std; use crate::deriving::path_std;
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{Expr, MetaItem}; use syntax::ast::{Expr, MetaItem};
use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt}; use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::span_err;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_default(cx: &mut ExtCtxt, pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -42,7 +43,10 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
trait_def.expand(cx, mitem, item, push) trait_def.expand(cx, mitem, item, push)
} }
fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { fn default_substructure(cx: &mut ExtCtxt<'_>,
trait_span: Span,
substr: &Substructure<'_>)
-> P<Expr> {
let default_ident = cx.std_path(&["default", "Default", "default"]); let default_ident = cx.std_path(&["default", "Default", "default"]);
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new()); let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());

View file

@ -82,10 +82,10 @@
//! } //! }
//! ``` //! ```
use deriving::{self, pathvec_std}; use crate::deriving::{self, pathvec_std};
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use deriving::warn_if_deprecated; use crate::deriving::warn_if_deprecated;
use syntax::ast::{Expr, ExprKind, MetaItem, Mutability}; use syntax::ast::{Expr, ExprKind, MetaItem, Mutability};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -94,7 +94,7 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt, pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -102,7 +102,7 @@ pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,
expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize") expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize")
} }
pub fn expand_deriving_encodable(cx: &mut ExtCtxt, pub fn expand_deriving_encodable(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -111,7 +111,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize") expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize")
} }
fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, fn expand_deriving_encodable_imp(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -162,9 +162,9 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
trait_def.expand(cx, mitem, item, push) trait_def.expand(cx, mitem, item, push)
} }
fn encodable_substructure(cx: &mut ExtCtxt, fn encodable_substructure(cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substr: &Substructure, substr: &Substructure<'_>,
krate: &'static str) krate: &'static str)
-> P<Expr> { -> P<Expr> {
let encoder = substr.nonself_args[0].clone(); let encoder = substr.nonself_args[0].clone();

View file

@ -174,8 +174,8 @@
//! (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))]) //! (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))])
//! ``` //! ```
pub use self::StaticFields::*; pub use StaticFields::*;
pub use self::SubstructureFields::*; pub use SubstructureFields::*;
use std::cell::RefCell; use std::cell::RefCell;
use std::iter; use std::iter;
@ -195,9 +195,9 @@ use syntax::symbol::{Symbol, keywords};
use syntax::parse::ParseSess; use syntax::parse::ParseSess;
use syntax_pos::{DUMMY_SP, Span}; use syntax_pos::{DUMMY_SP, Span};
use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty}; use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
use deriving; use crate::deriving;
pub mod ty; pub mod ty;
@ -321,7 +321,7 @@ pub enum SubstructureFields<'a> {
/// Combine the values of all the fields together. The last argument is /// Combine the values of all the fields together. The last argument is
/// all the fields of all the structures. /// all the fields of all the structures.
pub type CombineSubstructureFunc<'a> = pub type CombineSubstructureFunc<'a> =
Box<dyn FnMut(&mut ExtCtxt, Span, &Substructure) -> P<Expr> + 'a>; Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>;
/// Deal with non-matching enum variants. The tuple is a list of /// Deal with non-matching enum variants. The tuple is a list of
/// identifiers (one for each `Self` argument, which could be any of the /// identifiers (one for each `Self` argument, which could be any of the
@ -329,7 +329,7 @@ pub type CombineSubstructureFunc<'a> =
/// holding the variant index value for each of the `Self` arguments. The /// holding the variant index value for each of the `Self` arguments. The
/// last argument is all the non-`Self` args of the method being derived. /// last argument is all the non-`Self` args of the method being derived.
pub type EnumNonMatchCollapsedFunc<'a> = pub type EnumNonMatchCollapsedFunc<'a> =
Box<dyn FnMut(&mut ExtCtxt, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>; Box<dyn FnMut(&mut ExtCtxt<'_>, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
-> RefCell<CombineSubstructureFunc<'a>> { -> RefCell<CombineSubstructureFunc<'a>> {
@ -342,7 +342,7 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
fn find_type_parameters(ty: &ast::Ty, fn find_type_parameters(ty: &ast::Ty,
ty_param_names: &[ast::Name], ty_param_names: &[ast::Name],
span: Span, span: Span,
cx: &ExtCtxt) cx: &ExtCtxt<'_>)
-> Vec<P<ast::Ty>> { -> Vec<P<ast::Ty>> {
use syntax::visit; use syntax::visit;
@ -386,7 +386,7 @@ fn find_type_parameters(ty: &ast::Ty,
impl<'a> TraitDef<'a> { impl<'a> TraitDef<'a> {
pub fn expand(self, pub fn expand(self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
mitem: &ast::MetaItem, mitem: &ast::MetaItem,
item: &'a Annotatable, item: &'a Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
@ -394,7 +394,7 @@ impl<'a> TraitDef<'a> {
} }
pub fn expand_ext(self, pub fn expand_ext(self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
mitem: &ast::MetaItem, mitem: &ast::MetaItem,
item: &'a Annotatable, item: &'a Annotatable,
push: &mut dyn FnMut(Annotatable), push: &mut dyn FnMut(Annotatable),
@ -513,7 +513,7 @@ impl<'a> TraitDef<'a> {
/// where B1, ..., BN are the bounds given by `bounds_paths`.'. Z is a phantom type, and /// where B1, ..., BN are the bounds given by `bounds_paths`.'. Z is a phantom type, and
/// therefore does not get bound by the derived trait. /// therefore does not get bound by the derived trait.
fn create_derived_impl(&self, fn create_derived_impl(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
type_ident: Ident, type_ident: Ident,
generics: &Generics, generics: &Generics,
field_tys: Vec<P<ast::Ty>>, field_tys: Vec<P<ast::Ty>>,
@ -696,7 +696,7 @@ impl<'a> TraitDef<'a> {
} }
fn expand_struct_def(&self, fn expand_struct_def(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
struct_def: &'a VariantData, struct_def: &'a VariantData,
type_ident: Ident, type_ident: Ident,
generics: &Generics, generics: &Generics,
@ -746,7 +746,7 @@ impl<'a> TraitDef<'a> {
} }
fn expand_enum_def(&self, fn expand_enum_def(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
enum_def: &'a EnumDef, enum_def: &'a EnumDef,
type_attrs: &[ast::Attribute], type_attrs: &[ast::Attribute],
type_ident: Ident, type_ident: Ident,
@ -832,12 +832,12 @@ fn find_repr_type_name(sess: &ParseSess, type_attrs: &[ast::Attribute]) -> &'sta
impl<'a> MethodDef<'a> { impl<'a> MethodDef<'a> {
fn call_substructure_method(&self, fn call_substructure_method(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
type_ident: Ident, type_ident: Ident,
self_args: &[P<Expr>], self_args: &[P<Expr>],
nonself_args: &[P<Expr>], nonself_args: &[P<Expr>],
fields: &SubstructureFields) fields: &SubstructureFields<'_>)
-> P<Expr> { -> P<Expr> {
let substructure = Substructure { let substructure = Substructure {
type_ident, type_ident,
@ -847,13 +847,13 @@ impl<'a> MethodDef<'a> {
fields, fields,
}; };
let mut f = self.combine_substructure.borrow_mut(); let mut f = self.combine_substructure.borrow_mut();
let f: &mut CombineSubstructureFunc = &mut *f; let f: &mut CombineSubstructureFunc<'_> = &mut *f;
f(cx, trait_.span, &substructure) f(cx, trait_.span, &substructure)
} }
fn get_ret_ty(&self, fn get_ret_ty(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
generics: &Generics, generics: &Generics,
type_ident: Ident) type_ident: Ident)
-> P<ast::Ty> { -> P<ast::Ty> {
@ -866,8 +866,8 @@ impl<'a> MethodDef<'a> {
fn split_self_nonself_args fn split_self_nonself_args
(&self, (&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
type_ident: Ident, type_ident: Ident,
generics: &Generics) generics: &Generics)
-> (Option<ast::ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) { -> (Option<ast::ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) {
@ -912,8 +912,8 @@ impl<'a> MethodDef<'a> {
} }
fn create_method(&self, fn create_method(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
type_ident: Ident, type_ident: Ident,
generics: &Generics, generics: &Generics,
abi: Abi, abi: Abi,
@ -1005,7 +1005,7 @@ impl<'a> MethodDef<'a> {
/// } /// }
/// ``` /// ```
fn expand_struct_method_body<'b>(&self, fn expand_struct_method_body<'b>(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>, trait_: &TraitDef<'b>,
struct_def: &'b VariantData, struct_def: &'b VariantData,
type_ident: Ident, type_ident: Ident,
@ -1077,8 +1077,8 @@ impl<'a> MethodDef<'a> {
} }
fn expand_static_struct_method_body(&self, fn expand_static_struct_method_body(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
struct_def: &VariantData, struct_def: &VariantData,
type_ident: Ident, type_ident: Ident,
self_args: &[P<Expr>], self_args: &[P<Expr>],
@ -1125,7 +1125,7 @@ impl<'a> MethodDef<'a> {
/// as their results are unused. The point of `__self_vi` and /// as their results are unused. The point of `__self_vi` and
/// `__arg_1_vi` is for `PartialOrd`; see #15503.) /// `__arg_1_vi` is for `PartialOrd`; see #15503.)
fn expand_enum_method_body<'b>(&self, fn expand_enum_method_body<'b>(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>, trait_: &TraitDef<'b>,
enum_def: &'b EnumDef, enum_def: &'b EnumDef,
type_attrs: &[ast::Attribute], type_attrs: &[ast::Attribute],
@ -1179,7 +1179,7 @@ impl<'a> MethodDef<'a> {
/// } /// }
/// ``` /// ```
fn build_enum_match_tuple<'b>(&self, fn build_enum_match_tuple<'b>(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>, trait_: &TraitDef<'b>,
enum_def: &'b EnumDef, enum_def: &'b EnumDef,
type_attrs: &[ast::Attribute], type_attrs: &[ast::Attribute],
@ -1230,7 +1230,7 @@ impl<'a> MethodDef<'a> {
.enumerate() .enumerate()
.filter(|&(_, v)| !(self.unify_fieldless_variants && v.node.data.fields().is_empty())) .filter(|&(_, v)| !(self.unify_fieldless_variants && v.node.data.fields().is_empty()))
.map(|(index, variant)| { .map(|(index, variant)| {
let mk_self_pat = |cx: &mut ExtCtxt, self_arg_name: &str| { let mk_self_pat = |cx: &mut ExtCtxt<'_>, self_arg_name: &str| {
let (p, idents) = trait_.create_enum_variant_pattern(cx, let (p, idents) = trait_.create_enum_variant_pattern(cx,
type_ident, type_ident,
variant, variant,
@ -1296,7 +1296,7 @@ impl<'a> MethodDef<'a> {
other: others, other: others,
attrs, attrs,
} }
}).collect::<Vec<FieldInfo>>(); }).collect::<Vec<FieldInfo<'_>>>();
// Now, for some given VariantK, we have built up // Now, for some given VariantK, we have built up
// expressions for referencing every field of every // expressions for referencing every field of every
@ -1501,8 +1501,8 @@ impl<'a> MethodDef<'a> {
} }
fn expand_static_enum_method_body(&self, fn expand_static_enum_method_body(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_: &TraitDef, trait_: &TraitDef<'_>,
enum_def: &EnumDef, enum_def: &EnumDef,
type_ident: Ident, type_ident: Ident,
self_args: &[P<Expr>], self_args: &[P<Expr>],
@ -1527,7 +1527,7 @@ impl<'a> MethodDef<'a> {
// general helper methods. // general helper methods.
impl<'a> TraitDef<'a> { impl<'a> TraitDef<'a> {
fn summarise_struct(&self, cx: &mut ExtCtxt, struct_def: &VariantData) -> StaticFields { fn summarise_struct(&self, cx: &mut ExtCtxt<'_>, struct_def: &VariantData) -> StaticFields {
let mut named_idents = Vec::new(); let mut named_idents = Vec::new();
let mut just_spans = Vec::new(); let mut just_spans = Vec::new();
for field in struct_def.fields() { for field in struct_def.fields() {
@ -1553,7 +1553,7 @@ impl<'a> TraitDef<'a> {
} }
fn create_subpatterns(&self, fn create_subpatterns(&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
field_paths: Vec<ast::Ident>, field_paths: Vec<ast::Ident>,
mutbl: ast::Mutability, mutbl: ast::Mutability,
use_temporaries: bool) use_temporaries: bool)
@ -1573,7 +1573,7 @@ impl<'a> TraitDef<'a> {
fn create_struct_pattern fn create_struct_pattern
(&self, (&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
struct_path: ast::Path, struct_path: ast::Path,
struct_def: &'a VariantData, struct_def: &'a VariantData,
prefix: &str, prefix: &str,
@ -1633,7 +1633,7 @@ impl<'a> TraitDef<'a> {
fn create_enum_variant_pattern fn create_enum_variant_pattern
(&self, (&self,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
enum_ident: ast::Ident, enum_ident: ast::Ident,
variant: &'a ast::Variant, variant: &'a ast::Variant,
prefix: &str, prefix: &str,
@ -1652,10 +1652,10 @@ impl<'a> TraitDef<'a> {
pub fn cs_fold_fields<'a, F>(use_foldl: bool, pub fn cs_fold_fields<'a, F>(use_foldl: bool,
mut f: F, mut f: F,
base: P<Expr>, base: P<Expr>,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
all_fields: &[FieldInfo<'a>]) all_fields: &[FieldInfo<'a>])
-> P<Expr> -> P<Expr>
where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr> where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
{ {
if use_foldl { if use_foldl {
all_fields.iter().fold(base, |old, field| { all_fields.iter().fold(base, |old, field| {
@ -1668,10 +1668,10 @@ pub fn cs_fold_fields<'a, F>(use_foldl: bool,
} }
} }
pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc, pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure<'_>)
-> P<Expr> -> P<Expr>
{ {
match *substructure.fields { match *substructure.fields {
@ -1685,7 +1685,7 @@ pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
} }
} }
pub fn cs_fold_static(cx: &mut ExtCtxt, pub fn cs_fold_static(cx: &mut ExtCtxt<'_>,
trait_span: Span) trait_span: Span)
-> P<Expr> -> P<Expr>
{ {
@ -1697,12 +1697,12 @@ pub fn cs_fold_static(cx: &mut ExtCtxt,
pub fn cs_fold<F>(use_foldl: bool, pub fn cs_fold<F>(use_foldl: bool,
f: F, f: F,
base: P<Expr>, base: P<Expr>,
enum_nonmatch_f: EnumNonMatchCollapsedFunc, enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure<'_>)
-> P<Expr> -> P<Expr>
where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr> where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
{ {
match *substructure.fields { match *substructure.fields {
EnumMatching(.., ref all_fields) | EnumMatching(.., ref all_fields) |
@ -1730,13 +1730,13 @@ pub fn cs_fold<F>(use_foldl: bool,
pub fn cs_fold1<F, B>(use_foldl: bool, pub fn cs_fold1<F, B>(use_foldl: bool,
f: F, f: F,
mut b: B, mut b: B,
enum_nonmatch_f: EnumNonMatchCollapsedFunc, enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure<'_>)
-> P<Expr> -> P<Expr>
where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>, where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>,
B: FnMut(&mut ExtCtxt, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr> B: FnMut(&mut ExtCtxt<'_>, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr>
{ {
match *substructure.fields { match *substructure.fields {
EnumMatching(.., ref all_fields) | EnumMatching(.., ref all_fields) |
@ -1776,12 +1776,12 @@ pub fn cs_fold1<F, B>(use_foldl: bool,
/// ``` /// ```
#[inline] #[inline]
pub fn cs_same_method<F>(f: F, pub fn cs_same_method<F>(f: F,
mut enum_nonmatch_f: EnumNonMatchCollapsedFunc, mut enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
trait_span: Span, trait_span: Span,
substructure: &Substructure) substructure: &Substructure<'_>)
-> P<Expr> -> P<Expr>
where F: FnOnce(&mut ExtCtxt, Span, Vec<P<Expr>>) -> P<Expr> where F: FnOnce(&mut ExtCtxt<'_>, Span, Vec<P<Expr>>) -> P<Expr>
{ {
match *substructure.fields { match *substructure.fields {
EnumMatching(.., ref all_fields) | EnumMatching(.., ref all_fields) |

View file

@ -1,11 +1,10 @@
//! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use //! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use
//! when specifying impls to be derived. //! when specifying impls to be derived.
pub use self::PtrTy::*; pub use PtrTy::*;
pub use self::Ty::*; pub use Ty::*;
use syntax::ast; use syntax::ast::{self, Expr, GenericParamKind, Generics, Ident, SelfKind, GenericArg};
use syntax::ast::{Expr, GenericParamKind, Generics, Ident, SelfKind, GenericArg};
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::source_map::{respan, DUMMY_SP}; use syntax::source_map::{respan, DUMMY_SP};
@ -60,7 +59,7 @@ impl<'a> Path<'a> {
} }
pub fn to_ty(&self, pub fn to_ty(&self,
cx: &ExtCtxt, cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ty: Ident, self_ty: Ident,
self_generics: &Generics) self_generics: &Generics)
@ -68,7 +67,7 @@ impl<'a> Path<'a> {
cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
} }
pub fn to_path(&self, pub fn to_path(&self,
cx: &ExtCtxt, cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ty: Ident, self_ty: Ident,
self_generics: &Generics) self_generics: &Generics)
@ -127,19 +126,19 @@ pub fn nil_ty<'r>() -> Ty<'r> {
Tuple(Vec::new()) Tuple(Vec::new())
} }
fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> { fn mk_lifetime(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
lt.map(|s| lt.map(|s|
cx.lifetime(span, Ident::from_str(s)) cx.lifetime(span, Ident::from_str(s))
) )
} }
fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> { fn mk_lifetimes(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
mk_lifetime(cx, span, lt).into_iter().collect() mk_lifetime(cx, span, lt).into_iter().collect()
} }
impl<'a> Ty<'a> { impl<'a> Ty<'a> {
pub fn to_ty(&self, pub fn to_ty(&self,
cx: &ExtCtxt, cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ty: Ident, self_ty: Ident,
self_generics: &Generics) self_generics: &Generics)
@ -167,7 +166,7 @@ impl<'a> Ty<'a> {
} }
pub fn to_path(&self, pub fn to_path(&self,
cx: &ExtCtxt, cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ty: Ident, self_ty: Ident,
generics: &Generics) generics: &Generics)
@ -193,11 +192,11 @@ impl<'a> Ty<'a> {
} }
fn mk_ty_param(cx: &ExtCtxt, fn mk_ty_param(cx: &ExtCtxt<'_>,
span: Span, span: Span,
name: &str, name: &str,
attrs: &[ast::Attribute], attrs: &[ast::Attribute],
bounds: &[Path], bounds: &[Path<'_>],
self_ident: Ident, self_ident: Ident,
self_generics: &Generics) self_generics: &Generics)
-> ast::GenericParam { -> ast::GenericParam {
@ -237,7 +236,7 @@ impl<'a> LifetimeBounds<'a> {
} }
} }
pub fn to_generics(&self, pub fn to_generics(&self,
cx: &ExtCtxt, cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ty: Ident, self_ty: Ident,
self_generics: &Generics) self_generics: &Generics)
@ -262,9 +261,9 @@ impl<'a> LifetimeBounds<'a> {
} }
} }
pub fn get_explicit_self(cx: &ExtCtxt, pub fn get_explicit_self(cx: &ExtCtxt<'_>,
span: Span, span: Span,
self_ptr: &Option<PtrTy>) self_ptr: &Option<PtrTy<'_>>)
-> (P<Expr>, ast::ExplicitSelf) { -> (P<Expr>, ast::ExplicitSelf) {
// this constructs a fresh `self` path // this constructs a fresh `self` path
let self_path = cx.expr_self(span); let self_path = cx.expr_self(span);

View file

@ -1,6 +1,6 @@
use deriving::{self, pathvec_std, path_std}; use crate::deriving::{self, pathvec_std, path_std};
use deriving::generic::*; use crate::deriving::generic::*;
use deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use syntax::ast::{Expr, MetaItem, Mutability}; use syntax::ast::{Expr, MetaItem, Mutability};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -8,7 +8,7 @@ use syntax::ext::build::AstBuilder;
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
pub fn expand_deriving_hash(cx: &mut ExtCtxt, pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
span: Span, span: Span,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
@ -50,7 +50,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
hash_trait_def.expand(cx, mitem, item, push); hash_trait_def.expand(cx, mitem, item, push);
} }
fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> { fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> {
let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) { let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
(1, Some(o_f)) => o_f, (1, Some(o_f)) => o_f,
_ => { _ => {

View file

@ -90,7 +90,7 @@ derive_traits! {
} }
#[inline] // because `name` is a compile-time constant #[inline] // because `name` is a compile-time constant
fn warn_if_deprecated(ecx: &mut ExtCtxt, sp: Span, name: &str) { fn warn_if_deprecated(ecx: &mut ExtCtxt<'_>, sp: Span, name: &str) {
if let Some(replacement) = match name { if let Some(replacement) = match name {
"Encodable" => Some("RustcEncodable"), "Encodable" => Some("RustcEncodable"),
"Decodable" => Some("RustcDecodable"), "Decodable" => Some("RustcDecodable"),
@ -131,7 +131,7 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String {
} }
/// Constructs an expression that calls an intrinsic /// Constructs an expression that calls an intrinsic
fn call_intrinsic(cx: &ExtCtxt, fn call_intrinsic(cx: &ExtCtxt<'_>,
mut span: Span, mut span: Span,
intrinsic: &str, intrinsic: &str,
args: Vec<P<ast::Expr>>) args: Vec<P<ast::Expr>>)

View file

@ -1,5 +1,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use syntax::{register_diagnostic, register_long_diagnostics};
// Error messages for EXXXX errors. // Error messages for EXXXX errors.
// Each message should start and end with a new line, and be wrapped to 80 characters. // Each message should start and end with a new line, and be wrapped to 80 characters.
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable. // In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.

View file

@ -4,8 +4,7 @@
// //
use syntax::ast::{self, Ident, GenericArg}; use syntax::ast::{self, Ident, GenericArg};
use syntax::ext::base::*; use syntax::ext::base::{self, *};
use syntax::ext::base;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::symbol::{keywords, Symbol}; use syntax::symbol::{keywords, Symbol};
use syntax_pos::Span; use syntax_pos::Span;
@ -13,7 +12,7 @@ use syntax::tokenstream;
use std::env; use std::env;
pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {
@ -44,7 +43,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
MacEager::expr(e) MacEager::expr(e)
} }
pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {

View file

@ -1,9 +1,11 @@
use self::ArgumentType::*; use ArgumentType::*;
use self::Position::*; use Position::*;
use fmt_macros as parse; use fmt_macros as parse;
use errors::DiagnosticBuilder; use crate::errors::DiagnosticBuilder;
use crate::errors::Applicability;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{self, *}; use syntax::ext::base::{self, *};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -13,7 +15,6 @@ use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::tokenstream; use syntax::tokenstream;
use syntax_pos::{MultiSpan, Span, DUMMY_SP}; use syntax_pos::{MultiSpan, Span, DUMMY_SP};
use errors::Applicability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use std::borrow::Cow; use std::borrow::Cow;
@ -184,7 +185,7 @@ fn parse_args<'a>(
} }
impl<'a, 'b> Context<'a, 'b> { impl<'a, 'b> Context<'a, 'b> {
fn resolve_name_inplace(&self, p: &mut parse::Piece) { fn resolve_name_inplace(&self, p: &mut parse::Piece<'_>) {
// NOTE: the `unwrap_or` branch is needed in case of invalid format // NOTE: the `unwrap_or` branch is needed in case of invalid format
// arguments, e.g., `format_args!("{foo}")`. // arguments, e.g., `format_args!("{foo}")`.
let lookup = |s| *self.names.get(s).unwrap_or(&0); let lookup = |s| *self.names.get(s).unwrap_or(&0);
@ -208,7 +209,7 @@ impl<'a, 'b> Context<'a, 'b> {
/// Verifies one piece of a parse string, and remembers it if valid. /// Verifies one piece of a parse string, and remembers it if valid.
/// All errors are not emitted as fatal so we can continue giving errors /// All errors are not emitted as fatal so we can continue giving errors
/// about this and possibly other format strings. /// about this and possibly other format strings.
fn verify_piece(&mut self, p: &parse::Piece) { fn verify_piece(&mut self, p: &parse::Piece<'_>) {
match *p { match *p {
parse::String(..) => {} parse::String(..) => {}
parse::NextArgument(ref arg) => { parse::NextArgument(ref arg) => {
@ -231,7 +232,7 @@ impl<'a, 'b> Context<'a, 'b> {
} }
} }
fn verify_count(&mut self, c: parse::Count) { fn verify_count(&mut self, c: parse::Count<'_>) {
match c { match c {
parse::CountImplied | parse::CountImplied |
parse::CountIs(..) => {} parse::CountIs(..) => {}
@ -244,7 +245,7 @@ impl<'a, 'b> Context<'a, 'b> {
} }
} }
fn describe_num_args(&self) -> Cow<str> { fn describe_num_args(&self) -> Cow<'_, str> {
match self.args.len() { match self.args.len() {
0 => "no arguments were given".into(), 0 => "no arguments were given".into(),
1 => "there is 1 argument".into(), 1 => "there is 1 argument".into(),
@ -385,11 +386,11 @@ impl<'a, 'b> Context<'a, 'b> {
self.count_args_index_offset = sofar; self.count_args_index_offset = sofar;
} }
fn rtpath(ecx: &ExtCtxt, s: &str) -> Vec<ast::Ident> { fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec<ast::Ident> {
ecx.std_path(&["fmt", "rt", "v1", s]) ecx.std_path(&["fmt", "rt", "v1", s])
} }
fn build_count(&self, c: parse::Count) -> P<ast::Expr> { fn build_count(&self, c: parse::Count<'_>) -> P<ast::Expr> {
let sp = self.macsp; let sp = self.macsp;
let count = |c, arg| { let count = |c, arg| {
let mut path = Context::rtpath(self.ecx, "Count"); let mut path = Context::rtpath(self.ecx, "Count");
@ -426,7 +427,7 @@ impl<'a, 'b> Context<'a, 'b> {
/// Build a static `rt::Argument` from a `parse::Piece` or append /// Build a static `rt::Argument` from a `parse::Piece` or append
/// to the `literal` string. /// to the `literal` string.
fn build_piece(&mut self, fn build_piece(&mut self,
piece: &parse::Piece, piece: &parse::Piece<'_>,
arg_index_consumed: &mut Vec<usize>) arg_index_consumed: &mut Vec<usize>)
-> Option<P<ast::Expr>> { -> Option<P<ast::Expr>> {
let sp = self.macsp; let sp = self.macsp;
@ -647,7 +648,7 @@ impl<'a, 'b> Context<'a, 'b> {
self.ecx.expr_call_global(self.macsp, path, fn_args) self.ecx.expr_call_global(self.macsp, path, fn_args)
} }
fn format_arg(ecx: &ExtCtxt, fn format_arg(ecx: &ExtCtxt<'_>,
macsp: Span, macsp: Span,
mut sp: Span, mut sp: Span,
ty: &ArgumentType, ty: &ArgumentType,
@ -686,7 +687,7 @@ impl<'a, 'b> Context<'a, 'b> {
} }
} }
pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt, pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt<'_>,
mut sp: Span, mut sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {
@ -703,7 +704,7 @@ pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt,
} }
pub fn expand_format_args_nl<'cx>( pub fn expand_format_args_nl<'cx>(
ecx: &'cx mut ExtCtxt, ecx: &'cx mut ExtCtxt<'_>,
mut sp: Span, mut sp: Span,
tts: &[tokenstream::TokenTree], tts: &[tokenstream::TokenTree],
) -> Box<dyn base::MacResult + 'cx> { ) -> Box<dyn base::MacResult + 'cx> {
@ -734,7 +735,7 @@ pub fn expand_format_args_nl<'cx>(
/// Take the various parts of `format_args!(efmt, args..., name=names...)` /// Take the various parts of `format_args!(efmt, args..., name=names...)`
/// and construct the appropriate formatting expression. /// and construct the appropriate formatting expression.
pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>,
sp: Span, sp: Span,
efmt: P<ast::Expr>, efmt: P<ast::Expr>,
args: Vec<P<ast::Expr>>, args: Vec<P<ast::Expr>>,
@ -952,7 +953,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
piece piece
}).collect::<Vec<_>>(); }).collect::<Vec<_>>();
let numbered_position_args = pieces.iter().any(|arg: &parse::Piece| { let numbered_position_args = pieces.iter().any(|arg: &parse::Piece<'_>| {
match *arg { match *arg {
parse::String(_) => false, parse::String(_) => false,
parse::NextArgument(arg) => { parse::NextArgument(arg) => {

View file

@ -68,7 +68,7 @@ pub mod printf {
pub position: (usize, usize), pub position: (usize, usize),
} }
impl<'a> Format<'a> { impl Format<'_> {
/// Translate this directive into an equivalent Rust formatting directive. /// Translate this directive into an equivalent Rust formatting directive.
/// ///
/// Returns `None` in cases where the `printf` directive does not have an exact Rust /// Returns `None` in cases where the `printf` directive does not have an exact Rust
@ -249,12 +249,12 @@ pub mod printf {
} }
} }
fn translate(&self, s: &mut String) -> ::std::fmt::Result { fn translate(&self, s: &mut String) -> std::fmt::Result {
use std::fmt::Write; use std::fmt::Write;
match *self { match *self {
Num::Num(n) => write!(s, "{}", n), Num::Num(n) => write!(s, "{}", n),
Num::Arg(n) => { Num::Arg(n) => {
let n = n.checked_sub(1).ok_or(::std::fmt::Error)?; let n = n.checked_sub(1).ok_or(std::fmt::Error)?;
write!(s, "{}$", n) write!(s, "{}$", n)
}, },
Num::Next => write!(s, "*"), Num::Next => write!(s, "*"),
@ -263,7 +263,7 @@ pub mod printf {
} }
/// Returns an iterator over all substitutions in a given string. /// Returns an iterator over all substitutions in a given string.
pub fn iter_subs(s: &str) -> Substitutions { pub fn iter_subs(s: &str) -> Substitutions<'_> {
Substitutions { Substitutions {
s, s,
pos: 0, pos: 0,
@ -309,7 +309,7 @@ pub mod printf {
} }
/// Parse the next substitution from the input string. /// Parse the next substitution from the input string.
pub fn parse_next_substitution(s: &str) -> Option<(Substitution, &str)> { pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
use self::State::*; use self::State::*;
let at = { let at = {
@ -389,7 +389,7 @@ pub mod printf {
let mut precision: Option<Num> = None; let mut precision: Option<Num> = None;
let mut length: Option<&str> = None; let mut length: Option<&str> = None;
let mut type_: &str = ""; let mut type_: &str = "";
let end: Cur; let end: Cur<'_>;
if let Start = state { if let Start = state {
match c { match c {
@ -575,7 +575,7 @@ pub mod printf {
Some((Substitution::Format(f), end.slice_after())) Some((Substitution::Format(f), end.slice_after()))
} }
fn at_next_cp_while<F>(mut cur: Cur, mut pred: F) -> Cur fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
where F: FnMut(char) -> bool { where F: FnMut(char) -> bool {
loop { loop {
match cur.next_cp() { match cur.next_cp() {
@ -769,7 +769,7 @@ pub mod shell {
Escape((usize, usize)), Escape((usize, usize)),
} }
impl<'a> Substitution<'a> { impl Substitution<'_> {
pub fn as_str(&self) -> String { pub fn as_str(&self) -> String {
match self { match self {
Substitution::Ordinal(n, _) => format!("${}", n), Substitution::Ordinal(n, _) => format!("${}", n),
@ -804,7 +804,7 @@ pub mod shell {
} }
/// Returns an iterator over all substitutions in a given string. /// Returns an iterator over all substitutions in a given string.
pub fn iter_subs(s: &str) -> Substitutions { pub fn iter_subs(s: &str) -> Substitutions<'_> {
Substitutions { Substitutions {
s, s,
pos: 0, pos: 0,
@ -839,7 +839,7 @@ pub mod shell {
} }
/// Parse the next substitution from the input string. /// Parse the next substitution from the input string.
pub fn parse_next_substitution(s: &str) -> Option<(Substitution, &str)> { pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
let at = { let at = {
let start = s.find('$')?; let start = s.find('$')?;
match s[start+1..].chars().next()? { match s[start+1..].chars().next()? {
@ -868,7 +868,7 @@ pub mod shell {
} }
} }
fn at_next_cp_while<F>(mut cur: Cur, mut pred: F) -> Cur fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
where F: FnMut(char) -> bool { where F: FnMut(char) -> bool {
loop { loop {
match cur.next_cp() { match cur.next_cp() {
@ -962,8 +962,6 @@ pub mod shell {
} }
mod strcursor { mod strcursor {
use std;
pub struct StrCursor<'a> { pub struct StrCursor<'a> {
s: &'a str, s: &'a str,
pub at: usize, pub at: usize,
@ -1028,7 +1026,7 @@ mod strcursor {
} }
} }
impl<'a> Copy for StrCursor<'a> {} impl Copy for StrCursor<'_> {}
impl<'a> Clone for StrCursor<'a> { impl<'a> Clone for StrCursor<'a> {
fn clone(&self) -> StrCursor<'a> { fn clone(&self) -> StrCursor<'a> {
@ -1036,8 +1034,8 @@ mod strcursor {
} }
} }
impl<'a> std::fmt::Debug for StrCursor<'a> { impl std::fmt::Debug for StrCursor<'_> {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(fmt, "StrCursor({:?} | {:?})", self.slice_before(), self.slice_after()) write!(fmt, "StrCursor({:?} | {:?})", self.slice_before(), self.slice_after())
} }
} }

View file

@ -8,21 +8,22 @@
/// LLVM's `module asm "some assembly here"`. All of LLVM's caveats /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats
/// therefore apply. /// therefore apply.
use errors::DiagnosticBuilder; use crate::errors::DiagnosticBuilder;
use syntax::ast; use syntax::ast;
use syntax::source_map::respan; use syntax::source_map::respan;
use syntax::ext::base; use syntax::ext::base::{self, *};
use syntax::ext::base::*;
use syntax::feature_gate; use syntax::feature_gate;
use syntax::parse::token; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
use smallvec::smallvec;
pub const MACRO: &str = "global_asm"; pub const MACRO: &str = "global_asm";
pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> { tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> {
if !cx.ecfg.enable_global_asm() { if !cx.ecfg.enable_global_asm() {

View file

@ -4,29 +4,21 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")] html_root_url = "https://doc.rust-lang.org/nightly/")]
#![deny(rust_2018_idioms)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(proc_macro_diagnostic)] #![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]
#![feature(proc_macro_span)] #![feature(proc_macro_span)]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(nll)]
#![feature(str_escape)] #![feature(str_escape)]
#![feature(rustc_diagnostic_macros)] #![feature(rustc_diagnostic_macros)]
#![recursion_limit="256"] #![recursion_limit="256"]
extern crate fmt_macros;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate proc_macro; extern crate proc_macro;
extern crate rustc_data_structures;
extern crate rustc_errors as errors; use rustc_errors as errors;
extern crate rustc_target;
#[macro_use]
extern crate smallvec;
#[macro_use]
extern crate log;
mod diagnostics; mod diagnostics;

View file

@ -4,7 +4,7 @@ use syntax::print;
use syntax::tokenstream; use syntax::tokenstream;
use syntax_pos; use syntax_pos;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt<'_>,
sp: syntax_pos::Span, sp: syntax_pos::Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {

View file

@ -1,6 +1,7 @@
use std::mem; use std::mem;
use errors; use crate::deriving;
use crate::errors;
use syntax::ast::{self, Ident}; use syntax::ast::{self, Ident};
use syntax::attr; use syntax::attr;
@ -18,8 +19,6 @@ use syntax::visit::{self, Visitor};
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
use deriving;
const PROC_MACRO_KINDS: [&str; 3] = ["proc_macro_derive", "proc_macro_attribute", "proc_macro"]; const PROC_MACRO_KINDS: [&str; 3] = ["proc_macro_derive", "proc_macro_attribute", "proc_macro"];
struct ProcMacroDerive { struct ProcMacroDerive {
@ -324,7 +323,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
// ]; // ];
// } // }
fn mk_decls( fn mk_decls(
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
custom_derives: &[ProcMacroDerive], custom_derives: &[ProcMacroDerive],
custom_attrs: &[ProcMacroDef], custom_attrs: &[ProcMacroDef],
custom_macros: &[ProcMacroDef], custom_macros: &[ProcMacroDef],

View file

@ -1,27 +1,27 @@
use errors::FatalError; use crate::errors::FatalError;
use crate::proc_macro_server;
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax::ext::base::*; use syntax::ext::base::{self, *};
use syntax::tokenstream::TokenStream; use syntax::tokenstream::TokenStream;
use syntax::ext::base;
pub const EXEC_STRATEGY: ::proc_macro::bridge::server::SameThread = pub const EXEC_STRATEGY: proc_macro::bridge::server::SameThread =
::proc_macro::bridge::server::SameThread; proc_macro::bridge::server::SameThread;
pub struct AttrProcMacro { pub struct AttrProcMacro {
pub client: ::proc_macro::bridge::client::Client< pub client: proc_macro::bridge::client::Client<
fn(::proc_macro::TokenStream, ::proc_macro::TokenStream) -> ::proc_macro::TokenStream, fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream,
>, >,
} }
impl base::AttrProcMacro for AttrProcMacro { impl base::AttrProcMacro for AttrProcMacro {
fn expand<'cx>(&self, fn expand<'cx>(&self,
ecx: &'cx mut ExtCtxt, ecx: &'cx mut ExtCtxt<'_>,
span: Span, span: Span,
annotation: TokenStream, annotation: TokenStream,
annotated: TokenStream) annotated: TokenStream)
-> TokenStream { -> TokenStream {
let server = ::proc_macro_server::Rustc::new(ecx); let server = proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) { match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
Ok(stream) => stream, Ok(stream) => stream,
Err(e) => { Err(e) => {
@ -39,18 +39,18 @@ impl base::AttrProcMacro for AttrProcMacro {
} }
pub struct BangProcMacro { pub struct BangProcMacro {
pub client: ::proc_macro::bridge::client::Client< pub client: proc_macro::bridge::client::Client<
fn(::proc_macro::TokenStream) -> ::proc_macro::TokenStream, fn(proc_macro::TokenStream) -> proc_macro::TokenStream,
>, >,
} }
impl base::ProcMacro for BangProcMacro { impl base::ProcMacro for BangProcMacro {
fn expand<'cx>(&self, fn expand<'cx>(&self,
ecx: &'cx mut ExtCtxt, ecx: &'cx mut ExtCtxt<'_>,
span: Span, span: Span,
input: TokenStream) input: TokenStream)
-> TokenStream { -> TokenStream {
let server = ::proc_macro_server::Rustc::new(ecx); let server = proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, input) { match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream, Ok(stream) => stream,
Err(e) => { Err(e) => {

View file

@ -1,4 +1,5 @@
use errors::{self, Diagnostic, DiagnosticBuilder}; use crate::errors::{self, Diagnostic, DiagnosticBuilder};
use std::panic; use std::panic;
use proc_macro::bridge::{server, TokenTree}; use proc_macro::bridge::{server, TokenTree};
@ -369,7 +370,7 @@ pub(crate) struct Rustc<'a> {
} }
impl<'a> Rustc<'a> { impl<'a> Rustc<'a> {
pub fn new(cx: &'a ExtCtxt) -> Self { pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
// No way to determine def location for a proc macro right now, so use call location. // No way to determine def location for a proc macro right now, so use call location.
let location = cx.current_expansion.mark.expn_info().unwrap().call_site; let location = cx.current_expansion.mark.expn_info().unwrap().call_site;
let to_span = |transparency| { let to_span = |transparency| {
@ -650,7 +651,7 @@ impl server::Literal for Rustc<'_> {
} }
} }
impl<'a> server::SourceFile for Rustc<'a> { impl server::SourceFile for Rustc<'_> {
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool { fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
Lrc::ptr_eq(file1, file2) Lrc::ptr_eq(file1, file2)
} }

View file

@ -13,7 +13,7 @@ use syntax::source_map::{ExpnInfo, MacroAttribute};
use std::iter; use std::iter;
pub fn expand_test( pub fn expand_test(
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
attr_sp: Span, attr_sp: Span,
_meta_item: &ast::MetaItem, _meta_item: &ast::MetaItem,
item: Annotatable, item: Annotatable,
@ -22,7 +22,7 @@ pub fn expand_test(
} }
pub fn expand_bench( pub fn expand_bench(
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
attr_sp: Span, attr_sp: Span,
_meta_item: &ast::MetaItem, _meta_item: &ast::MetaItem,
item: Annotatable, item: Annotatable,
@ -31,7 +31,7 @@ pub fn expand_bench(
} }
pub fn expand_test_or_bench( pub fn expand_test_or_bench(
cx: &mut ExtCtxt, cx: &mut ExtCtxt<'_>,
attr_sp: Span, attr_sp: Span,
item: Annotatable, item: Annotatable,
is_bench: bool is_bench: bool
@ -180,7 +180,7 @@ pub fn expand_test_or_bench(
ast::ItemKind::ExternCrate(Some(Symbol::intern("test"))) ast::ItemKind::ExternCrate(Some(Symbol::intern("test")))
); );
debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const)); log::debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const));
vec![ vec![
// Access to libtest under a gensymed name // Access to libtest under a gensymed name
@ -210,7 +210,7 @@ fn should_fail(i: &ast::Item) -> bool {
attr::contains_name(&i.attrs, "allow_fail") attr::contains_name(&i.attrs, "allow_fail")
} }
fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic { fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match attr::find_by_name(&i.attrs, "should_panic") { match attr::find_by_name(&i.attrs, "should_panic") {
Some(attr) => { Some(attr) => {
let ref sd = cx.parse_sess.span_diagnostic; let ref sd = cx.parse_sess.span_diagnostic;
@ -243,7 +243,7 @@ fn should_panic(cx: &ExtCtxt, i: &ast::Item) -> ShouldPanic {
} }
} }
fn has_test_signature(cx: &ExtCtxt, i: &ast::Item) -> bool { fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
let has_should_panic_attr = attr::contains_name(&i.attrs, "should_panic"); let has_should_panic_attr = attr::contains_name(&i.attrs, "should_panic");
let ref sd = cx.parse_sess.span_diagnostic; let ref sd = cx.parse_sess.span_diagnostic;
if let ast::ItemKind::Fn(ref decl, ref header, ref generics, _) = i.node { if let ast::ItemKind::Fn(ref decl, ref header, ref generics, _) = i.node {
@ -296,7 +296,7 @@ fn has_test_signature(cx: &ExtCtxt, i: &ast::Item) -> bool {
} }
} }
fn has_bench_signature(cx: &ExtCtxt, i: &ast::Item) -> bool { fn has_bench_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
let has_sig = if let ast::ItemKind::Fn(ref decl, _, _, _) = i.node { let has_sig = if let ast::ItemKind::Fn(ref decl, _, _, _) = i.node {
// N.B., inadequate check, but we're running // N.B., inadequate check, but we're running
// well before resolve, can't get too deep. // well before resolve, can't get too deep.

View file

@ -20,7 +20,7 @@ use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::feature_gate; use syntax::feature_gate;
pub fn expand( pub fn expand(
ecx: &mut ExtCtxt, ecx: &mut ExtCtxt<'_>,
attr_sp: Span, attr_sp: Span,
_meta_item: &ast::MetaItem, _meta_item: &ast::MetaItem,
anno_item: Annotatable anno_item: Annotatable

View file

@ -1,11 +1,10 @@
use syntax::ext::base::ExtCtxt; use syntax::ext::base::{self, ExtCtxt};
use syntax::ext::base;
use syntax::feature_gate; use syntax::feature_gate;
use syntax::symbol::keywords; use syntax::symbol::keywords;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
pub fn expand_trace_macros(cx: &mut ExtCtxt, pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
sp: Span, sp: Span,
tt: &[TokenTree]) tt: &[TokenTree])
-> Box<dyn base::MacResult + 'static> { -> Box<dyn base::MacResult + 'static> {