Reformat using the new identifier sorting from rustfmt
This commit is contained in:
parent
1173204b36
commit
c682aa162b
1455 changed files with 7152 additions and 8384 deletions
|
@ -3,9 +3,9 @@ use rustc_ast::{
|
|||
self as ast, Fn, FnHeader, FnSig, Generics, ItemKind, Safety, Stmt, StmtKind, TyKind,
|
||||
};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::errors;
|
||||
use crate::util::check_builtin_macro_attribute;
|
||||
|
@ -68,11 +68,10 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
|
|||
|
||||
let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
|
||||
let layout_new = cx.expr_path(cx.path(span, layout_new));
|
||||
let layout = cx.expr_call(
|
||||
span,
|
||||
layout_new,
|
||||
thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)],
|
||||
);
|
||||
let layout = cx.expr_call(span, layout_new, thin_vec![
|
||||
cx.expr_ident(span, size),
|
||||
cx.expr_ident(span, align)
|
||||
]);
|
||||
|
||||
let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]);
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
use ast::token::IdentIsRaw;
|
||||
use lint::BuiltinLintDiag;
|
||||
use rustc_ast::AsmMacro;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::AsmMacro;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::*;
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_session::lint;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{ErrorGuaranteed, InnerSpan, Span};
|
||||
use rustc_target::asm::InlineAsmArch;
|
||||
use smallvec::smallvec;
|
||||
|
|
|
@ -3,13 +3,13 @@ mod context;
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::Delimiter;
|
||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
||||
use rustc_ast::{token, DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp};
|
||||
use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp, token};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::edition_panic::use_panic_2021;
|
||||
|
|
|
@ -2,15 +2,15 @@ use rustc_ast::ptr::P;
|
|||
use rustc_ast::token::{self, Delimiter, IdentIsRaw};
|
||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
||||
use rustc_ast::{
|
||||
BinOpKind, BorrowKind, DelimArgs, Expr, ExprKind, ItemKind, MacCall, MethodCall, Mutability,
|
||||
Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind, DUMMY_NODE_ID,
|
||||
BinOpKind, BorrowKind, DUMMY_NODE_ID, DelimArgs, Expr, ExprKind, ItemKind, MacCall, MethodCall,
|
||||
Mutability, Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_expand::base::ExtCtxt;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
pub(super) struct Context<'cx, 'a> {
|
||||
// An optimization.
|
||||
|
|
|
@ -4,8 +4,8 @@ use rustc_ast as ast;
|
|||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use rustc_ast as ast;
|
|||
use rustc_ast::mut_visit::MutVisitor;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{AssocCtxt, Visitor};
|
||||
use rustc_ast::{mut_visit, visit, Attribute, HasAttrs, HasTokens, NodeId};
|
||||
use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_expand::config::StripUnconfigured;
|
||||
|
@ -12,8 +12,8 @@ use rustc_expand::configure;
|
|||
use rustc_feature::Features;
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::instrument;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Attributes injected into the crate root from command line using `-Z crate-attr`.
|
||||
|
||||
use rustc_ast::attr::mk_attr;
|
||||
use rustc_ast::{self as ast, token, AttrItem, AttrStyle};
|
||||
use rustc_ast::{self as ast, AttrItem, AttrStyle, token};
|
||||
use rustc_parse::parser::ForceCollect;
|
||||
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
|
||||
use rustc_session::parse::ParseSess;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{token, ExprKind, LitIntType, LitKind, UintTy};
|
||||
use rustc_ast::{ExprKind, LitIntType, LitKind, UintTy, token};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Token};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
use rustc_ast::{AttrVec, Expr, ExprKind, Path, Ty, TyKind, DUMMY_NODE_ID};
|
||||
use rustc_ast::{AttrVec, DUMMY_NODE_ID, Expr, ExprKind, Path, Ty, TyKind};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacResult, MacroExpanderResult};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_expand::base::{
|
|||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::symbol::{Ident, sym};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
||||
use crate::cfg_eval::cfg_eval;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use rustc_ast::{self as ast, Generics, ItemKind, MetaItem, VariantData};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
@ -115,13 +115,10 @@ fn cs_clone_simple(
|
|||
// type parameters.
|
||||
} else if !field.ty.kind.is_anon_adt() {
|
||||
// let _: AssertParamIsClone<FieldTy>;
|
||||
super::assert_ty_bounds(
|
||||
cx,
|
||||
&mut stmts,
|
||||
field.ty.clone(),
|
||||
field.span,
|
||||
&[sym::clone, sym::AssertParamIsClone],
|
||||
);
|
||||
super::assert_ty_bounds(cx, &mut stmts, field.ty.clone(), field.span, &[
|
||||
sym::clone,
|
||||
sym::AssertParamIsClone,
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -130,13 +127,10 @@ fn cs_clone_simple(
|
|||
// Just a single assertion for unions, that the union impls `Copy`.
|
||||
// let _: AssertParamIsCopy<Self>;
|
||||
let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper)));
|
||||
super::assert_ty_bounds(
|
||||
cx,
|
||||
&mut stmts,
|
||||
self_ty,
|
||||
trait_span,
|
||||
&[sym::clone, sym::AssertParamIsCopy],
|
||||
);
|
||||
super::assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, &[
|
||||
sym::clone,
|
||||
sym::AssertParamIsCopy,
|
||||
]);
|
||||
} else {
|
||||
match *substr.fields {
|
||||
StaticStruct(vdata, ..) => {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use rustc_ast::{self as ast, MetaItem};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::sym;
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
@ -66,13 +66,10 @@ fn cs_total_eq_assert(
|
|||
// Already produced an assertion for this type.
|
||||
} else {
|
||||
// let _: AssertParamIsEq<FieldTy>;
|
||||
super::assert_ty_bounds(
|
||||
cx,
|
||||
&mut stmts,
|
||||
field.ty.clone(),
|
||||
field.span,
|
||||
&[sym::cmp, sym::AssertParamIsEq],
|
||||
);
|
||||
super::assert_ty_bounds(cx, &mut stmts, field.ty.clone(), field.span, &[
|
||||
sym::cmp,
|
||||
sym::AssertParamIsEq,
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_ast::MetaItem;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, sym};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{BinOpKind, BorrowKind, Expr, ExprKind, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_ast::{ExprKind, ItemKind, MetaItem, PatKind};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, sym};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use rustc_ast::{self as ast, EnumDef, MetaItem};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_session::config::FmtDebug;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, Expr, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
@ -32,10 +32,11 @@ pub(crate) fn expand_deriving_rustc_decodable(
|
|||
methods: vec![MethodDef {
|
||||
name: sym::decode,
|
||||
generics: Bounds {
|
||||
bounds: vec![(
|
||||
typaram,
|
||||
vec![Path::new_(vec![krate, sym::Decoder], vec![], PathKind::Global)],
|
||||
)],
|
||||
bounds: vec![(typaram, vec![Path::new_(
|
||||
vec![krate, sym::Decoder],
|
||||
vec![],
|
||||
PathKind::Global,
|
||||
)])],
|
||||
},
|
||||
explicit_self: false,
|
||||
nonself_args: vec![(
|
||||
|
@ -94,32 +95,24 @@ fn decodable_substructure(
|
|||
decode_static_fields(cx, trait_span, path, summary, |cx, span, name, field| {
|
||||
cx.expr_try(
|
||||
span,
|
||||
cx.expr_call_global(
|
||||
span,
|
||||
fn_read_struct_field_path.clone(),
|
||||
thin_vec![
|
||||
blkdecoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, field),
|
||||
exprdecode.clone(),
|
||||
],
|
||||
),
|
||||
cx.expr_call_global(span, fn_read_struct_field_path.clone(), thin_vec![
|
||||
blkdecoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, field),
|
||||
exprdecode.clone(),
|
||||
]),
|
||||
)
|
||||
});
|
||||
let result = cx.expr_ok(trait_span, result);
|
||||
let fn_read_struct_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_struct]);
|
||||
|
||||
cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_struct_path,
|
||||
thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, nfields),
|
||||
cx.lambda1(trait_span, result, blkarg),
|
||||
],
|
||||
)
|
||||
cx.expr_call_global(trait_span, fn_read_struct_path, thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, nfields),
|
||||
cx.lambda1(trait_span, result, blkarg),
|
||||
])
|
||||
}
|
||||
StaticEnum(_, fields) => {
|
||||
let variant = Ident::new(sym::i, trait_span);
|
||||
|
@ -160,23 +153,19 @@ fn decodable_substructure(
|
|||
let variant_array_ref = cx.expr_array_ref(trait_span, variants);
|
||||
let fn_read_enum_variant_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant]);
|
||||
let result = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_enum_variant_path,
|
||||
thin_vec![blkdecoder, variant_array_ref, lambda],
|
||||
);
|
||||
let result = cx.expr_call_global(trait_span, fn_read_enum_variant_path, thin_vec![
|
||||
blkdecoder,
|
||||
variant_array_ref,
|
||||
lambda
|
||||
]);
|
||||
let fn_read_enum_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum]);
|
||||
|
||||
cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_enum_path,
|
||||
thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.lambda1(trait_span, result, blkarg),
|
||||
],
|
||||
)
|
||||
cx.expr_call_global(trait_span, fn_read_enum_path, thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.lambda1(trait_span, result, blkarg),
|
||||
])
|
||||
}
|
||||
_ => cx.dcx().bug("expected StaticEnum or StaticStruct in derive(Decodable)"),
|
||||
};
|
||||
|
|
|
@ -2,12 +2,12 @@ use core::ops::ControlFlow;
|
|||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::visit::visit_opt;
|
||||
use rustc_ast::{attr, EnumDef, VariantData};
|
||||
use rustc_ast::{EnumDef, VariantData, attr};
|
||||
use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use smallvec::SmallVec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
@ -93,10 +93,10 @@ fn default_enum_substructure(
|
|||
} {
|
||||
Ok(default_variant) => {
|
||||
// We now know there is exactly one unit variant with exactly one `#[default]` attribute.
|
||||
cx.expr_path(cx.path(
|
||||
default_variant.span,
|
||||
vec![Ident::new(kw::SelfUpper, default_variant.span), default_variant.ident],
|
||||
))
|
||||
cx.expr_path(cx.path(default_variant.span, vec![
|
||||
Ident::new(kw::SelfUpper, default_variant.span),
|
||||
default_variant.ident,
|
||||
]))
|
||||
}
|
||||
Err(guar) => DummyResult::raw_expr(trait_span, Some(guar)),
|
||||
};
|
||||
|
|
|
@ -87,9 +87,9 @@
|
|||
|
||||
use rustc_ast::{AttrVec, ExprKind, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
|
@ -116,10 +116,11 @@ pub(crate) fn expand_deriving_rustc_encodable(
|
|||
methods: vec![MethodDef {
|
||||
name: sym::encode,
|
||||
generics: Bounds {
|
||||
bounds: vec![(
|
||||
typaram,
|
||||
vec![Path::new_(vec![krate, sym::Encoder], vec![], PathKind::Global)],
|
||||
)],
|
||||
bounds: vec![(typaram, vec![Path::new_(
|
||||
vec![krate, sym::Encoder],
|
||||
vec![],
|
||||
PathKind::Global,
|
||||
)])],
|
||||
},
|
||||
explicit_self: true,
|
||||
nonself_args: vec![(
|
||||
|
@ -157,14 +158,11 @@ fn encodable_substructure(
|
|||
// throw an underscore in front to suppress unused variable warnings
|
||||
let blkarg = Ident::new(sym::_e, trait_span);
|
||||
let blkencoder = cx.expr_ident(trait_span, blkarg);
|
||||
let fn_path = cx.expr_path(cx.path_global(
|
||||
trait_span,
|
||||
vec![
|
||||
Ident::new(krate, trait_span),
|
||||
Ident::new(sym::Encodable, trait_span),
|
||||
Ident::new(sym::encode, trait_span),
|
||||
],
|
||||
));
|
||||
let fn_path = cx.expr_path(cx.path_global(trait_span, vec![
|
||||
Ident::new(krate, trait_span),
|
||||
Ident::new(sym::Encodable, trait_span),
|
||||
Ident::new(sym::encode, trait_span),
|
||||
]));
|
||||
|
||||
match substr.fields {
|
||||
Struct(_, fields) => {
|
||||
|
@ -180,16 +178,12 @@ fn encodable_substructure(
|
|||
let enc =
|
||||
cx.expr_call(span, fn_path.clone(), thin_vec![self_ref, blkencoder.clone()]);
|
||||
let lambda = cx.lambda1(span, enc, blkarg);
|
||||
let call = cx.expr_call_global(
|
||||
span,
|
||||
fn_emit_struct_field_path.clone(),
|
||||
thin_vec![
|
||||
blkencoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, i),
|
||||
lambda,
|
||||
],
|
||||
);
|
||||
let call = cx.expr_call_global(span, fn_emit_struct_field_path.clone(), thin_vec![
|
||||
blkencoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, i),
|
||||
lambda,
|
||||
]);
|
||||
|
||||
// last call doesn't need a try!
|
||||
let last = fields.len() - 1;
|
||||
|
@ -214,16 +208,12 @@ fn encodable_substructure(
|
|||
let fn_emit_struct_path =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct]);
|
||||
|
||||
let expr = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_struct_path,
|
||||
thin_vec![
|
||||
encoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, fields.len()),
|
||||
blk,
|
||||
],
|
||||
);
|
||||
let expr = cx.expr_call_global(trait_span, fn_emit_struct_path, thin_vec![
|
||||
encoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, fields.len()),
|
||||
blk,
|
||||
]);
|
||||
BlockOrExpr::new_expr(expr)
|
||||
}
|
||||
|
||||
|
@ -243,11 +233,8 @@ fn encodable_substructure(
|
|||
let last = fields.len() - 1;
|
||||
for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() {
|
||||
let self_ref = cx.expr_addr_of(span, self_expr.clone());
|
||||
let enc = cx.expr_call(
|
||||
span,
|
||||
fn_path.clone(),
|
||||
thin_vec![self_ref, blkencoder.clone()],
|
||||
);
|
||||
let enc = cx
|
||||
.expr_call(span, fn_path.clone(), thin_vec![self_ref, blkencoder.clone()]);
|
||||
let lambda = cx.lambda1(span, enc, blkarg);
|
||||
|
||||
let call = cx.expr_call_global(
|
||||
|
@ -274,26 +261,22 @@ fn encodable_substructure(
|
|||
let fn_emit_enum_variant_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant]);
|
||||
|
||||
let call = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_enum_variant_path,
|
||||
thin_vec![
|
||||
blkencoder,
|
||||
name,
|
||||
cx.expr_usize(trait_span, *idx),
|
||||
cx.expr_usize(trait_span, fields.len()),
|
||||
blk,
|
||||
],
|
||||
);
|
||||
let call = cx.expr_call_global(trait_span, fn_emit_enum_variant_path, thin_vec![
|
||||
blkencoder,
|
||||
name,
|
||||
cx.expr_usize(trait_span, *idx),
|
||||
cx.expr_usize(trait_span, fields.len()),
|
||||
blk,
|
||||
]);
|
||||
|
||||
let blk = cx.lambda1(trait_span, call, blkarg);
|
||||
let fn_emit_enum_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum]);
|
||||
let expr = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_enum_path,
|
||||
thin_vec![encoder, cx.expr_str(trait_span, substr.type_ident.name), blk],
|
||||
);
|
||||
let expr = cx.expr_call_global(trait_span, fn_emit_enum_path, thin_vec![
|
||||
encoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
blk
|
||||
]);
|
||||
BlockOrExpr::new_mixed(thin_vec![me], Some(expr))
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,8 @@ use std::cell::RefCell;
|
|||
use std::ops::Not;
|
||||
use std::{iter, vec};
|
||||
|
||||
pub(crate) use StaticFields::*;
|
||||
pub(crate) use SubstructureFields::*;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{
|
||||
self as ast, BindingMode, ByRef, EnumDef, Expr, GenericArg, GenericParamKind, Generics,
|
||||
|
@ -185,12 +187,10 @@ use rustc_ast::{
|
|||
};
|
||||
use rustc_attr as attr;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
use ty::{Bounds, Path, Ref, Self_, Ty};
|
||||
pub(crate) use StaticFields::*;
|
||||
pub(crate) use SubstructureFields::*;
|
||||
|
||||
use crate::{deriving, errors};
|
||||
|
||||
|
@ -1228,12 +1228,10 @@ impl<'a> MethodDef<'a> {
|
|||
|
||||
let discr_let_stmts: ThinVec<_> = iter::zip(&discr_idents, &selflike_args)
|
||||
.map(|(&ident, selflike_arg)| {
|
||||
let variant_value = deriving::call_intrinsic(
|
||||
cx,
|
||||
span,
|
||||
sym::discriminant_value,
|
||||
thin_vec![selflike_arg.clone()],
|
||||
);
|
||||
let variant_value =
|
||||
deriving::call_intrinsic(cx, span, sym::discriminant_value, thin_vec![
|
||||
selflike_arg.clone()
|
||||
]);
|
||||
cx.stmt_let(span, false, ident, variant_value)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
//! 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.
|
||||
|
||||
pub(crate) use Ty::*;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind};
|
||||
use rustc_expand::base::ExtCtxt;
|
||||
use rustc_span::source_map::respan;
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use thin_vec::ThinVec;
|
||||
pub(crate) use Ty::*;
|
||||
|
||||
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
|
||||
/// for type parameters.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_ast::{MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::deriving::generic::ty::*;
|
||||
|
|
|
@ -4,9 +4,9 @@ use rustc_ast as ast;
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{GenericArg, MetaItem};
|
||||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
macro path_local($x:ident) {
|
||||
generic::ty::Path::new_local(sym::$x)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ast::ptr::P;
|
||||
use ast::HasAttrs;
|
||||
use ast::ptr::P;
|
||||
use rustc_ast::mut_visit::MutVisitor;
|
||||
use rustc_ast::visit::BoundKind;
|
||||
use rustc_ast::{
|
||||
|
@ -9,9 +9,9 @@ use rustc_ast::{
|
|||
use rustc_attr as attr;
|
||||
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::symbol::{Ident, sym};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
macro_rules! path {
|
||||
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
|
||||
|
|
|
@ -3,9 +3,9 @@ use rustc_ast::token::Delimiter;
|
|||
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
||||
use rustc_ast::*;
|
||||
use rustc_expand::base::*;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
|
||||
/// This expands to either
|
||||
/// - `$crate::panic::panic_2015!(...)` or
|
||||
|
|
|
@ -10,8 +10,8 @@ use rustc_ast::token::{self, LitKind};
|
|||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{AstDeref, ExprKind, GenericArg, Mutability};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::errors;
|
||||
|
@ -58,11 +58,11 @@ pub(crate) fn expand_option_env<'cx>(
|
|||
))],
|
||||
))
|
||||
}
|
||||
Some(value) => cx.expr_call_global(
|
||||
sp,
|
||||
cx.std_path(&[sym::option, sym::Option, sym::Some]),
|
||||
thin_vec![cx.expr_str(sp, value)],
|
||||
),
|
||||
Some(value) => {
|
||||
cx.expr_call_global(sp, cx.std_path(&[sym::option, sym::Option, sym::Some]), thin_vec![
|
||||
cx.expr_str(sp, value)
|
||||
])
|
||||
}
|
||||
};
|
||||
ExpandResult::Ready(MacEager::expr(e))
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@ use parse::Position::ArgumentNamed;
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{
|
||||
token, Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
|
||||
Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
|
||||
FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArguments, FormatCount,
|
||||
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait, Recovered, StmtKind,
|
||||
token,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
|
||||
|
|
|
@ -183,14 +183,10 @@ pub(crate) mod printf {
|
|||
s.push('{');
|
||||
|
||||
if let Some(arg) = self.parameter {
|
||||
match write!(
|
||||
s,
|
||||
"{}",
|
||||
match arg.checked_sub(1) {
|
||||
Some(a) => a,
|
||||
None => return Err(None),
|
||||
}
|
||||
) {
|
||||
match write!(s, "{}", match arg.checked_sub(1) {
|
||||
Some(a) => a,
|
||||
None => return Err(None),
|
||||
}) {
|
||||
Err(_) => return Err(None),
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{iter_subs, parse_next_substitution as pns, Format as F, Num as N, Substitution as S};
|
||||
use super::{Format as F, Num as N, Substitution as S, iter_subs, parse_next_substitution as pns};
|
||||
|
||||
macro_rules! assert_eq_pnsat {
|
||||
($lhs:expr, $rhs:expr) => {
|
||||
|
@ -99,10 +99,12 @@ fn test_parse() {
|
|||
fn test_iter() {
|
||||
let s = "The %d'th word %% is: `%.*s` %!\n";
|
||||
let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect();
|
||||
assert_eq!(
|
||||
subs.iter().map(Option::as_deref).collect::<Vec<_>>(),
|
||||
vec![Some("{}"), None, Some("{:.*}"), None]
|
||||
);
|
||||
assert_eq!(subs.iter().map(Option::as_deref).collect::<Vec<_>>(), vec![
|
||||
Some("{}"),
|
||||
None,
|
||||
Some("{:.*}"),
|
||||
None
|
||||
]);
|
||||
}
|
||||
|
||||
/// Checks that the translations are what we expect.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{parse_next_substitution as pns, Substitution as S};
|
||||
use super::{Substitution as S, parse_next_substitution as pns};
|
||||
|
||||
macro_rules! assert_eq_pnsat {
|
||||
($lhs:expr, $rhs:expr) => {
|
||||
|
@ -38,10 +38,11 @@ fn test_iter() {
|
|||
use super::iter_subs;
|
||||
let s = "The $0'th word $$ is: `$WORD` $!\n";
|
||||
let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect();
|
||||
assert_eq!(
|
||||
subs.iter().map(Option::as_deref).collect::<Vec<_>>(),
|
||||
vec![Some("{0}"), None, Some("{WORD}")]
|
||||
);
|
||||
assert_eq!(subs.iter().map(Option::as_deref).collect::<Vec<_>>(), vec![
|
||||
Some("{0}"),
|
||||
None,
|
||||
Some("{WORD}")
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use rustc_ast::expand::allocator::{
|
||||
global_fn_name, AllocatorMethod, AllocatorMethodInput, AllocatorTy, ALLOCATOR_METHODS,
|
||||
ALLOCATOR_METHODS, AllocatorMethod, AllocatorMethodInput, AllocatorTy, global_fn_name,
|
||||
};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{
|
||||
|
@ -7,9 +7,9 @@ use rustc_ast::{
|
|||
Stmt, StmtKind, Ty, TyKind,
|
||||
};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::errors;
|
||||
use crate::util::check_builtin_macro_attribute;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{ast, Pat, Ty};
|
||||
use rustc_ast::{Pat, Ty, ast};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{self, DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::{Span, sym};
|
||||
|
||||
pub(crate) fn expand<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
|
|
|
@ -2,19 +2,19 @@ use std::mem;
|
|||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{self, Visitor};
|
||||
use rustc_ast::{self as ast, attr, NodeId};
|
||||
use rustc_ast::{self as ast, NodeId, attr};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::DiagCtxtHandle;
|
||||
use rustc_expand::base::{parse_macro_name_and_helper_attrs, ExtCtxt, ResolverExpand};
|
||||
use rustc_expand::base::{ExtCtxt, ResolverExpand, parse_macro_name_and_helper_attrs};
|
||||
use rustc_expand::expand::{AstFragment, ExpansionConfig};
|
||||
use rustc_feature::Features;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::AstPass;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use smallvec::smallvec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
@ -302,29 +302,25 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
};
|
||||
let local_path = |cx: &ExtCtxt<'_>, name| cx.expr_path(cx.path(span, vec![name]));
|
||||
let proc_macro_ty_method_path = |cx: &ExtCtxt<'_>, method| {
|
||||
cx.expr_path(cx.path(
|
||||
span.with_ctxt(harness_span.ctxt()),
|
||||
vec![proc_macro, bridge, client, proc_macro_ty, method],
|
||||
))
|
||||
cx.expr_path(cx.path(span.with_ctxt(harness_span.ctxt()), vec![
|
||||
proc_macro,
|
||||
bridge,
|
||||
client,
|
||||
proc_macro_ty,
|
||||
method,
|
||||
]))
|
||||
};
|
||||
match m {
|
||||
ProcMacro::Derive(cd) => {
|
||||
cx.resolver.declare_proc_macro(cd.id);
|
||||
cx.expr_call(
|
||||
span,
|
||||
proc_macro_ty_method_path(cx, custom_derive),
|
||||
thin_vec![
|
||||
cx.expr_str(span, cd.trait_name),
|
||||
cx.expr_array_ref(
|
||||
span,
|
||||
cd.attrs
|
||||
.iter()
|
||||
.map(|&s| cx.expr_str(span, s))
|
||||
.collect::<ThinVec<_>>(),
|
||||
),
|
||||
local_path(cx, cd.function_name),
|
||||
],
|
||||
)
|
||||
cx.expr_call(span, proc_macro_ty_method_path(cx, custom_derive), thin_vec![
|
||||
cx.expr_str(span, cd.trait_name),
|
||||
cx.expr_array_ref(
|
||||
span,
|
||||
cd.attrs.iter().map(|&s| cx.expr_str(span, s)).collect::<ThinVec<_>>(),
|
||||
),
|
||||
local_path(cx, cd.function_name),
|
||||
])
|
||||
}
|
||||
ProcMacro::Attr(ca) | ProcMacro::Bang(ca) => {
|
||||
cx.resolver.declare_proc_macro(ca.id);
|
||||
|
@ -334,14 +330,10 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
ProcMacro::Derive(_) => unreachable!(),
|
||||
};
|
||||
|
||||
cx.expr_call(
|
||||
span,
|
||||
proc_macro_ty_method_path(cx, ident),
|
||||
thin_vec![
|
||||
cx.expr_str(span, ca.function_name.name),
|
||||
local_path(cx, ca.function_name),
|
||||
],
|
||||
)
|
||||
cx.expr_call(span, proc_macro_ty_method_path(cx, ident), thin_vec![
|
||||
cx.expr_str(span, ca.function_name.name),
|
||||
local_path(cx, ca.function_name),
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -355,9 +347,12 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
span,
|
||||
cx.ty(
|
||||
span,
|
||||
ast::TyKind::Slice(
|
||||
cx.ty_path(cx.path(span, vec![proc_macro, bridge, client, proc_macro_ty])),
|
||||
),
|
||||
ast::TyKind::Slice(cx.ty_path(cx.path(span, vec![
|
||||
proc_macro,
|
||||
bridge,
|
||||
client,
|
||||
proc_macro_ty,
|
||||
]))),
|
||||
),
|
||||
None,
|
||||
ast::Mutability::Not,
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_ast::tokenstream::TokenStream;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_expand::base::{
|
||||
resolve_path, DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult,
|
||||
DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult, resolve_path,
|
||||
};
|
||||
use rustc_expand::module::DirOwnership;
|
||||
use rustc_lint_defs::BuiltinLintDiag;
|
||||
|
@ -73,8 +73,8 @@ pub(crate) fn expand_file(
|
|||
let topmost = cx.expansion_cause().unwrap_or(sp);
|
||||
let loc = cx.source_map().lookup_char_pos(topmost.lo());
|
||||
|
||||
use rustc_session::config::RemapPathScopeComponents;
|
||||
use rustc_session::RemapFileNameExt;
|
||||
use rustc_session::config::RemapPathScopeComponents;
|
||||
ExpandResult::Ready(MacEager::expr(cx.expr_str(
|
||||
topmost,
|
||||
Symbol::intern(
|
||||
|
|
|
@ -3,10 +3,10 @@ use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
|||
use rustc_expand::expand::ExpansionConfig;
|
||||
use rustc_feature::Features;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_span::edition::Edition::*;
|
||||
use rustc_span::hygiene::AstPass;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn inject(
|
||||
|
|
|
@ -5,13 +5,13 @@ use std::assert_matches::assert_matches;
|
|||
use std::iter;
|
||||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, attr, GenericParamKind};
|
||||
use rustc_ast::{self as ast, GenericParamKind, attr};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{Applicability, Diag, Level};
|
||||
use rustc_expand::base::*;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::errors;
|
||||
|
@ -170,26 +170,20 @@ pub(crate) fn expand_test_or_bench(
|
|||
|
||||
// creates test::ShouldPanic::$name
|
||||
let should_panic_path = |name| {
|
||||
cx.path(
|
||||
sp,
|
||||
vec![
|
||||
test_id,
|
||||
Ident::from_str_and_span("ShouldPanic", sp),
|
||||
Ident::from_str_and_span(name, sp),
|
||||
],
|
||||
)
|
||||
cx.path(sp, vec![
|
||||
test_id,
|
||||
Ident::from_str_and_span("ShouldPanic", sp),
|
||||
Ident::from_str_and_span(name, sp),
|
||||
])
|
||||
};
|
||||
|
||||
// creates test::TestType::$name
|
||||
let test_type_path = |name| {
|
||||
cx.path(
|
||||
sp,
|
||||
vec![
|
||||
test_id,
|
||||
Ident::from_str_and_span("TestType", sp),
|
||||
Ident::from_str_and_span(name, sp),
|
||||
],
|
||||
)
|
||||
cx.path(sp, vec![
|
||||
test_id,
|
||||
Ident::from_str_and_span("TestType", sp),
|
||||
Ident::from_str_and_span(name, sp),
|
||||
])
|
||||
};
|
||||
|
||||
// creates $name: $expr
|
||||
|
@ -209,55 +203,39 @@ pub(crate) fn expand_test_or_bench(
|
|||
// A simple ident for a lambda
|
||||
let b = Ident::from_str_and_span("b", attr_sp);
|
||||
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticBenchFn")),
|
||||
thin_vec![
|
||||
// #[coverage(off)]
|
||||
// |b| self::test::assert_test_result(
|
||||
coverage_off(cx.lambda1(
|
||||
sp,
|
||||
cx.expr_call(sp, cx.expr_path(test_path("StaticBenchFn")), thin_vec![
|
||||
// #[coverage(off)]
|
||||
// |b| self::test::assert_test_result(
|
||||
coverage_off(cx.lambda1(
|
||||
sp,
|
||||
cx.expr_call(sp, cx.expr_path(test_path("assert_test_result")), thin_vec![
|
||||
// super::$test_fn(b)
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("assert_test_result")),
|
||||
thin_vec![
|
||||
// super::$test_fn(b)
|
||||
cx.expr_call(
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
thin_vec![cx.expr_ident(sp, b)],
|
||||
),
|
||||
],
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
thin_vec![cx.expr_ident(sp, b)],
|
||||
),
|
||||
b,
|
||||
)), // )
|
||||
],
|
||||
)
|
||||
],),
|
||||
b,
|
||||
)), // )
|
||||
])
|
||||
} else {
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticTestFn")),
|
||||
thin_vec![
|
||||
// #[coverage(off)]
|
||||
// || {
|
||||
coverage_off(cx.lambda0(
|
||||
sp,
|
||||
// test::assert_test_result(
|
||||
cx.expr_call(sp, cx.expr_path(test_path("StaticTestFn")), thin_vec![
|
||||
// #[coverage(off)]
|
||||
// || {
|
||||
coverage_off(cx.lambda0(
|
||||
sp,
|
||||
// test::assert_test_result(
|
||||
cx.expr_call(sp, cx.expr_path(test_path("assert_test_result")), thin_vec![
|
||||
// $test_fn()
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("assert_test_result")),
|
||||
thin_vec![
|
||||
// $test_fn()
|
||||
cx.expr_call(
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
ThinVec::new(),
|
||||
), // )
|
||||
],
|
||||
), // }
|
||||
)), // )
|
||||
],
|
||||
)
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
ThinVec::new(),
|
||||
), // )
|
||||
],), // }
|
||||
)), // )
|
||||
])
|
||||
};
|
||||
|
||||
let test_path_symbol = Symbol::intern(&item_path(
|
||||
|
@ -268,122 +246,107 @@ pub(crate) fn expand_test_or_bench(
|
|||
|
||||
let location_info = get_location_info(cx, &item);
|
||||
|
||||
let mut test_const =
|
||||
cx.item(
|
||||
sp,
|
||||
Ident::new(item.ident.name, sp),
|
||||
thin_vec![
|
||||
// #[cfg(test)]
|
||||
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
|
||||
// #[rustc_test_marker = "test_case_sort_key"]
|
||||
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
|
||||
// #[doc(hidden)]
|
||||
cx.attr_nested_word(sym::doc, sym::hidden, attr_sp),
|
||||
],
|
||||
// const $ident: test::TestDescAndFn =
|
||||
ast::ItemKind::Const(
|
||||
ast::ConstItem {
|
||||
defaultness: ast::Defaultness::Final,
|
||||
generics: ast::Generics::default(),
|
||||
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
|
||||
// test::TestDescAndFn {
|
||||
expr: Some(
|
||||
cx.expr_struct(
|
||||
sp,
|
||||
test_path("TestDescAndFn"),
|
||||
thin_vec![
|
||||
let mut test_const = cx.item(
|
||||
sp,
|
||||
Ident::new(item.ident.name, sp),
|
||||
thin_vec![
|
||||
// #[cfg(test)]
|
||||
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
|
||||
// #[rustc_test_marker = "test_case_sort_key"]
|
||||
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
|
||||
// #[doc(hidden)]
|
||||
cx.attr_nested_word(sym::doc, sym::hidden, attr_sp),
|
||||
],
|
||||
// const $ident: test::TestDescAndFn =
|
||||
ast::ItemKind::Const(
|
||||
ast::ConstItem {
|
||||
defaultness: ast::Defaultness::Final,
|
||||
generics: ast::Generics::default(),
|
||||
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
|
||||
// test::TestDescAndFn {
|
||||
expr: Some(
|
||||
cx.expr_struct(sp, test_path("TestDescAndFn"), thin_vec![
|
||||
// desc: test::TestDesc {
|
||||
field(
|
||||
"desc",
|
||||
cx.expr_struct(
|
||||
sp,
|
||||
test_path("TestDesc"),
|
||||
thin_vec![
|
||||
// name: "path::to::test"
|
||||
field(
|
||||
"name",
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticTestName")),
|
||||
thin_vec![cx.expr_str(sp, test_path_symbol)],
|
||||
),
|
||||
cx.expr_struct(sp, test_path("TestDesc"), thin_vec![
|
||||
// name: "path::to::test"
|
||||
field(
|
||||
"name",
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticTestName")),
|
||||
thin_vec![cx.expr_str(sp, test_path_symbol)],
|
||||
),
|
||||
// ignore: true | false
|
||||
field("ignore", cx.expr_bool(sp, should_ignore(&item)),),
|
||||
// ignore_message: Some("...") | None
|
||||
field(
|
||||
"ignore_message",
|
||||
if let Some(msg) = should_ignore_message(&item) {
|
||||
cx.expr_some(sp, cx.expr_str(sp, msg))
|
||||
} else {
|
||||
cx.expr_none(sp)
|
||||
},
|
||||
),
|
||||
// ignore: true | false
|
||||
field("ignore", cx.expr_bool(sp, should_ignore(&item)),),
|
||||
// ignore_message: Some("...") | None
|
||||
field(
|
||||
"ignore_message",
|
||||
if let Some(msg) = should_ignore_message(&item) {
|
||||
cx.expr_some(sp, cx.expr_str(sp, msg))
|
||||
} else {
|
||||
cx.expr_none(sp)
|
||||
},
|
||||
),
|
||||
// source_file: <relative_path_of_source_file>
|
||||
field("source_file", cx.expr_str(sp, location_info.0)),
|
||||
// start_line: start line of the test fn identifier.
|
||||
field("start_line", cx.expr_usize(sp, location_info.1)),
|
||||
// start_col: start column of the test fn identifier.
|
||||
field("start_col", cx.expr_usize(sp, location_info.2)),
|
||||
// end_line: end line of the test fn identifier.
|
||||
field("end_line", cx.expr_usize(sp, location_info.3)),
|
||||
// end_col: end column of the test fn identifier.
|
||||
field("end_col", cx.expr_usize(sp, location_info.4)),
|
||||
// compile_fail: true | false
|
||||
field("compile_fail", cx.expr_bool(sp, false)),
|
||||
// no_run: true | false
|
||||
field("no_run", cx.expr_bool(sp, false)),
|
||||
// should_panic: ...
|
||||
field("should_panic", match should_panic(cx, &item) {
|
||||
// test::ShouldPanic::No
|
||||
ShouldPanic::No => {
|
||||
cx.expr_path(should_panic_path("No"))
|
||||
}
|
||||
// test::ShouldPanic::Yes
|
||||
ShouldPanic::Yes(None) => {
|
||||
cx.expr_path(should_panic_path("Yes"))
|
||||
}
|
||||
// test::ShouldPanic::YesWithMessage("...")
|
||||
ShouldPanic::Yes(Some(sym)) => cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(should_panic_path("YesWithMessage")),
|
||||
thin_vec![cx.expr_str(sp, sym)],
|
||||
),
|
||||
// source_file: <relative_path_of_source_file>
|
||||
field("source_file", cx.expr_str(sp, location_info.0)),
|
||||
// start_line: start line of the test fn identifier.
|
||||
field("start_line", cx.expr_usize(sp, location_info.1)),
|
||||
// start_col: start column of the test fn identifier.
|
||||
field("start_col", cx.expr_usize(sp, location_info.2)),
|
||||
// end_line: end line of the test fn identifier.
|
||||
field("end_line", cx.expr_usize(sp, location_info.3)),
|
||||
// end_col: end column of the test fn identifier.
|
||||
field("end_col", cx.expr_usize(sp, location_info.4)),
|
||||
// compile_fail: true | false
|
||||
field("compile_fail", cx.expr_bool(sp, false)),
|
||||
// no_run: true | false
|
||||
field("no_run", cx.expr_bool(sp, false)),
|
||||
// should_panic: ...
|
||||
field(
|
||||
"should_panic",
|
||||
match should_panic(cx, &item) {
|
||||
// test::ShouldPanic::No
|
||||
ShouldPanic::No => {
|
||||
cx.expr_path(should_panic_path("No"))
|
||||
}
|
||||
// test::ShouldPanic::Yes
|
||||
ShouldPanic::Yes(None) => {
|
||||
cx.expr_path(should_panic_path("Yes"))
|
||||
}
|
||||
// test::ShouldPanic::YesWithMessage("...")
|
||||
ShouldPanic::Yes(Some(sym)) => cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(should_panic_path("YesWithMessage")),
|
||||
thin_vec![cx.expr_str(sp, sym)],
|
||||
),
|
||||
},
|
||||
),
|
||||
// test_type: ...
|
||||
field(
|
||||
"test_type",
|
||||
match test_type(cx) {
|
||||
// test::TestType::UnitTest
|
||||
TestType::UnitTest => {
|
||||
cx.expr_path(test_type_path("UnitTest"))
|
||||
}
|
||||
// test::TestType::IntegrationTest
|
||||
TestType::IntegrationTest => {
|
||||
cx.expr_path(test_type_path("IntegrationTest"))
|
||||
}
|
||||
// test::TestPath::Unknown
|
||||
TestType::Unknown => {
|
||||
cx.expr_path(test_type_path("Unknown"))
|
||||
}
|
||||
},
|
||||
),
|
||||
// },
|
||||
],
|
||||
),
|
||||
},),
|
||||
// test_type: ...
|
||||
field("test_type", match test_type(cx) {
|
||||
// test::TestType::UnitTest
|
||||
TestType::UnitTest => {
|
||||
cx.expr_path(test_type_path("UnitTest"))
|
||||
}
|
||||
// test::TestType::IntegrationTest
|
||||
TestType::IntegrationTest => {
|
||||
cx.expr_path(test_type_path("IntegrationTest"))
|
||||
}
|
||||
// test::TestPath::Unknown
|
||||
TestType::Unknown => {
|
||||
cx.expr_path(test_type_path("Unknown"))
|
||||
}
|
||||
},),
|
||||
// },
|
||||
],),
|
||||
),
|
||||
// testfn: test::StaticTestFn(...) | test::StaticBenchFn(...)
|
||||
field("testfn", test_fn), // }
|
||||
],
|
||||
), // }
|
||||
),
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
);
|
||||
]), // }
|
||||
),
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
);
|
||||
test_const = test_const.map(|mut tc| {
|
||||
tc.vis.kind = ast::VisibilityKind::Public;
|
||||
tc
|
||||
|
|
|
@ -6,21 +6,21 @@ use rustc_ast as ast;
|
|||
use rustc_ast::entry::EntryPointType;
|
||||
use rustc_ast::mut_visit::*;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{walk_item, Visitor};
|
||||
use rustc_ast::{attr, ModKind};
|
||||
use rustc_ast::visit::{Visitor, walk_item};
|
||||
use rustc_ast::{ModKind, attr};
|
||||
use rustc_errors::DiagCtxtHandle;
|
||||
use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
||||
use rustc_expand::expand::{AstFragment, ExpansionConfig};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
|
||||
use rustc_session::Session;
|
||||
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
|
||||
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::errors;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::kw;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{self as ast, attr, token, AttrStyle, Attribute, MetaItem};
|
||||
use rustc_ast::{self as ast, AttrStyle, Attribute, MetaItem, attr, token};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
|
||||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
|
||||
use rustc_expand::expand::AstFragment;
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
|
||||
use rustc_lint_defs::BuiltinLintDiag;
|
||||
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
|
||||
use rustc_parse::{parser, validate_attr};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue