Rollup merge of #63586 - petrochenkov:nospanned, r=eddyb
cleanup: Remove `Spanned` where possible It generally only makes sense on enums, otherwise it's more convenient to "flatten" it by adding a span field to the struct it wraps.
This commit is contained in:
commit
6e8fabb4ac
39 changed files with 156 additions and 172 deletions
|
@ -136,7 +136,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
PatKind::Struct(_, ref subpats, _) => {
|
||||
let pats_exit = self.pats_all(subpats.iter().map(|f| &f.node.pat), pred);
|
||||
let pats_exit = self.pats_all(subpats.iter().map(|f| &f.pat), pred);
|
||||
self.add_ast_node(pat.hir_id.local_id, &[pats_exit])
|
||||
}
|
||||
|
||||
|
|
|
@ -704,9 +704,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
|||
PatKind::Struct(ref qpath, ref fields, _) => {
|
||||
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
|
||||
for field in fields {
|
||||
visitor.visit_id(field.node.hir_id);
|
||||
visitor.visit_ident(field.node.ident);
|
||||
visitor.visit_pat(&field.node.pat)
|
||||
visitor.visit_id(field.hir_id);
|
||||
visitor.visit_ident(field.ident);
|
||||
visitor.visit_pat(&field.pat)
|
||||
}
|
||||
}
|
||||
PatKind::Tuple(ref tuple_elements, _) => {
|
||||
|
|
|
@ -2691,16 +2691,12 @@ impl<'a> LoweringContext<'a> {
|
|||
|
||||
let fs = fields
|
||||
.iter()
|
||||
.map(|f| {
|
||||
Spanned {
|
||||
span: f.span,
|
||||
node: hir::FieldPat {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.node.ident,
|
||||
pat: self.lower_pat(&f.node.pat),
|
||||
is_shorthand: f.node.is_shorthand,
|
||||
},
|
||||
}
|
||||
.map(|f| hir::FieldPat {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
pat: self.lower_pat(&f.pat),
|
||||
is_shorthand: f.is_shorthand,
|
||||
span: f.span,
|
||||
})
|
||||
.collect();
|
||||
hir::PatKind::Struct(qpath, fs, etc)
|
||||
|
|
|
@ -877,7 +877,7 @@ impl Pat {
|
|||
match self.node {
|
||||
PatKind::Binding(.., Some(ref p)) => p.walk_(it),
|
||||
PatKind::Struct(_, ref fields, _) => {
|
||||
fields.iter().all(|field| field.node.pat.walk_(it))
|
||||
fields.iter().all(|field| field.pat.walk_(it))
|
||||
}
|
||||
PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
|
||||
s.iter().all(|p| p.walk_(it))
|
||||
|
@ -923,6 +923,7 @@ pub struct FieldPat {
|
|||
/// The pattern the field is destructured to.
|
||||
pub pat: P<Pat>,
|
||||
pub is_shorthand: bool,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Explicit binding annotations given in the HIR for a binding. Note
|
||||
|
@ -968,7 +969,7 @@ pub enum PatKind {
|
|||
|
||||
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
|
||||
/// The `bool` is `true` in the presence of a `..`.
|
||||
Struct(QPath, HirVec<Spanned<FieldPat>>, bool),
|
||||
Struct(QPath, HirVec<FieldPat>, bool),
|
||||
|
||||
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
|
||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||
|
|
|
@ -1670,14 +1670,14 @@ impl<'a> State<'a> {
|
|||
&fields[..],
|
||||
|s, f| {
|
||||
s.cbox(INDENT_UNIT);
|
||||
if !f.node.is_shorthand {
|
||||
s.print_ident(f.node.ident);
|
||||
if !f.is_shorthand {
|
||||
s.print_ident(f.ident);
|
||||
s.word_nbsp(":");
|
||||
}
|
||||
s.print_pat(&f.node.pat);
|
||||
s.print_pat(&f.pat);
|
||||
s.end()
|
||||
},
|
||||
|f| f.node.pat.span);
|
||||
|f| f.pat.span);
|
||||
if etc {
|
||||
if !fields.is_empty() {
|
||||
self.word_space(",");
|
||||
|
|
|
@ -153,8 +153,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
|
|||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for_spanned!(hir::FieldPat);
|
||||
|
||||
impl_stable_hash_for_spanned!(hir::BinOpKind);
|
||||
|
||||
impl_stable_hash_for!(struct hir::Stmt {
|
||||
|
@ -187,8 +185,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
|
|||
|
||||
impl_stable_hash_for_spanned!(usize);
|
||||
|
||||
impl_stable_hash_for_spanned!(ast::Ident);
|
||||
|
||||
impl_stable_hash_for!(struct ast::Ident {
|
||||
name,
|
||||
span,
|
||||
|
|
|
@ -1345,7 +1345,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
|||
// part of `walk_mac`, and (b) we should be calling
|
||||
// `visit_path`, *but* that would require a `NodeId`, and I
|
||||
// want to get #53686 fixed quickly. -nmatsakis
|
||||
ast_visit::walk_path(self, &mac.node.path);
|
||||
ast_visit::walk_path(self, &mac.path);
|
||||
|
||||
run_early_pass!(self, check_mac, mac);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ use crate::util::nodemap::FxHashSet;
|
|||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
||||
use syntax::{ast, source_map};
|
||||
use syntax::attr;
|
||||
use syntax::{ast, attr};
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos;
|
||||
|
||||
|
@ -119,17 +118,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res,
|
||||
pats: &[source_map::Spanned<hir::FieldPat>]) {
|
||||
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res, pats: &[hir::FieldPat]) {
|
||||
let variant = match self.tables.node_type(lhs.hir_id).sty {
|
||||
ty::Adt(adt, _) => adt.variant_of_res(res),
|
||||
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
|
||||
};
|
||||
for pat in pats {
|
||||
if let PatKind::Wild = pat.node.pat.node {
|
||||
if let PatKind::Wild = pat.pat.node {
|
||||
continue;
|
||||
}
|
||||
let index = self.tcx.field_index(pat.node.hir_id, self.tables);
|
||||
let index = self.tcx.field_index(pat.hir_id, self.tables);
|
||||
self.insert_def_id(variant.fields[index].did);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -418,8 +418,8 @@ fn add_from_pat<'tcx>(ir: &mut IrMaps<'tcx>, pat: &P<hir::Pat>) {
|
|||
}
|
||||
Struct(_, ref fields, _) => {
|
||||
for field in fields {
|
||||
if field.node.is_shorthand {
|
||||
shorthand_field_ids.insert(field.node.pat.hir_id);
|
||||
if field.is_shorthand {
|
||||
shorthand_field_ids.insert(field.pat.hir_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1282,11 +1282,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||
};
|
||||
|
||||
for fp in field_pats {
|
||||
let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2)
|
||||
let f_index = self.tcx.field_index(fp.node.hir_id, self.tables);
|
||||
let field_ty = self.pat_ty_adjusted(&fp.pat)?; // see (*2)
|
||||
let f_index = self.tcx.field_index(fp.hir_id, self.tables);
|
||||
let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index,
|
||||
fp.node.ident, field_ty));
|
||||
self.cat_pattern_(cmt_field, &fp.node.pat, op)?;
|
||||
fp.ident, field_ty));
|
||||
self.cat_pattern_(cmt_field, &fp.pat, op)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1207,7 +1207,7 @@ fn resolve_local<'tcx>(
|
|||
PatKind::Binding(hir::BindingAnnotation::RefMut, ..) => true,
|
||||
|
||||
PatKind::Struct(_, ref field_pats, _) => {
|
||||
field_pats.iter().any(|fp| is_binding_pat(&fp.node.pat))
|
||||
field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
|
||||
}
|
||||
|
||||
PatKind::Slice(ref pats1, ref pats2, ref pats3) => {
|
||||
|
|
|
@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
|
|||
.expect("struct pattern type is not an ADT")
|
||||
.variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id));
|
||||
for fieldpat in field_pats {
|
||||
if fieldpat.node.is_shorthand {
|
||||
if fieldpat.is_shorthand {
|
||||
continue;
|
||||
}
|
||||
if fieldpat.span.ctxt().outer_expn_info().is_some() {
|
||||
|
@ -173,9 +173,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
|
|||
// (Issue #49588)
|
||||
continue;
|
||||
}
|
||||
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
|
||||
if let PatKind::Binding(_, _, ident, None) = fieldpat.pat.node {
|
||||
if cx.tcx.find_field_index(ident, &variant) ==
|
||||
Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) {
|
||||
Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables)) {
|
||||
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
|
||||
fieldpat.span,
|
||||
&format!("the `{}:` in this pattern is redundant", ident));
|
||||
|
@ -1493,7 +1493,7 @@ impl EarlyLintPass for KeywordIdents {
|
|||
self.check_tokens(cx, mac_def.stream());
|
||||
}
|
||||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
|
||||
self.check_tokens(cx, mac.node.tts.clone().into());
|
||||
self.check_tokens(cx, mac.tts.clone().into());
|
||||
}
|
||||
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
|
||||
self.check_ident_token(cx, UnderMacro(false), ident);
|
||||
|
|
|
@ -645,9 +645,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
|||
fields.iter()
|
||||
.map(|field| {
|
||||
FieldPattern {
|
||||
field: Field::new(self.tcx.field_index(field.node.hir_id,
|
||||
field: Field::new(self.tcx.field_index(field.hir_id,
|
||||
self.tables)),
|
||||
pattern: self.lower_pattern(&field.node.pat),
|
||||
pattern: self.lower_pattern(&field.pat),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -824,7 +824,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
|this| visit::walk_enum_def(this, enum_definition, generics, item_id))
|
||||
}
|
||||
|
||||
fn visit_mac(&mut self, mac: &Spanned<Mac_>) {
|
||||
fn visit_mac(&mut self, mac: &Mac) {
|
||||
// when a new macro kind is added but the author forgets to set it up for expansion
|
||||
// because that's the only part that won't cause a compiler error
|
||||
self.session.diagnostic()
|
||||
|
|
|
@ -1075,8 +1075,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
|
|||
let adt = self.tables.pat_ty(pat).ty_adt_def().unwrap();
|
||||
let variant = adt.variant_of_res(res);
|
||||
for field in fields {
|
||||
let use_ctxt = field.node.ident.span;
|
||||
let index = self.tcx.field_index(field.node.hir_id, self.tables);
|
||||
let use_ctxt = field.ident.span;
|
||||
let index = self.tcx.field_index(field.hir_id, self.tables);
|
||||
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
|
||||
(&attr.path, MacroKind::Attr, derives.clone(), after_derive),
|
||||
InvocationKind::Bang { ref mac, .. } =>
|
||||
(&mac.node.path, MacroKind::Bang, Vec::new(), false),
|
||||
(&mac.path, MacroKind::Bang, Vec::new(), false),
|
||||
InvocationKind::Derive { ref path, .. } =>
|
||||
(path, MacroKind::Derive, Vec::new(), false),
|
||||
InvocationKind::DeriveContainer { ref derives, .. } => {
|
||||
|
|
|
@ -32,7 +32,7 @@ use syntax::print::pprust::{
|
|||
ty_to_string
|
||||
};
|
||||
use syntax::ptr::P;
|
||||
use syntax::source_map::{Spanned, DUMMY_SP, respan};
|
||||
use syntax::source_map::{DUMMY_SP, respan};
|
||||
use syntax::walk_list;
|
||||
use syntax_pos::*;
|
||||
|
||||
|
@ -879,7 +879,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
|||
};
|
||||
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
|
||||
|
||||
for &Spanned { node: ref field, .. } in fields {
|
||||
for field in fields {
|
||||
if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
|
||||
if !self.span.filter_generated(field.ident.span) {
|
||||
let span = self.span_from_span(field.ident.span);
|
||||
|
|
|
@ -12,7 +12,6 @@ use rustc::traits::{ObligationCause, ObligationCauseCode};
|
|||
use rustc::ty::{self, Ty, TypeFoldable};
|
||||
use rustc::ty::subst::Kind;
|
||||
use syntax::ast;
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::util::lev_distance::find_best_match_for_name;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::hygiene::DesugaringKind;
|
||||
|
@ -1036,7 +1035,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
|||
&self,
|
||||
pat: &'tcx hir::Pat,
|
||||
qpath: &hir::QPath,
|
||||
fields: &'tcx [Spanned<hir::FieldPat>],
|
||||
fields: &'tcx [hir::FieldPat],
|
||||
etc: bool,
|
||||
expected: Ty<'tcx>,
|
||||
def_bm: ty::BindingMode,
|
||||
|
@ -1048,7 +1047,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
|||
variant_ty
|
||||
} else {
|
||||
for field in fields {
|
||||
self.check_pat_walk(&field.node.pat, self.tcx.types.err, def_bm, discrim_span);
|
||||
self.check_pat_walk(&field.pat, self.tcx.types.err, def_bm, discrim_span);
|
||||
}
|
||||
return self.tcx.types.err;
|
||||
};
|
||||
|
@ -1206,7 +1205,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
|||
pat_id: hir::HirId,
|
||||
span: Span,
|
||||
variant: &'tcx ty::VariantDef,
|
||||
fields: &'tcx [Spanned<hir::FieldPat>],
|
||||
fields: &'tcx [hir::FieldPat],
|
||||
etc: bool,
|
||||
def_bm: ty::BindingMode,
|
||||
) -> bool {
|
||||
|
@ -1231,7 +1230,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
|
|||
|
||||
let mut inexistent_fields = vec![];
|
||||
// Typecheck each field.
|
||||
for &Spanned { node: ref field, span } in fields {
|
||||
for field in fields {
|
||||
let span = field.span;
|
||||
let ident = tcx.adjust_ident(field.ident, variant.def_id);
|
||||
let field_ty = match used_fields.entry(ident) {
|
||||
Occupied(occupied) => {
|
||||
|
|
|
@ -283,7 +283,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
|
|||
}
|
||||
hir::PatKind::Struct(_, ref fields, _) => {
|
||||
for field in fields {
|
||||
self.visit_field_id(field.node.hir_id);
|
||||
self.visit_field_id(field.hir_id);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -3,7 +3,6 @@ use super::*;
|
|||
use syntax_pos::DUMMY_SP;
|
||||
use syntax::ast::*;
|
||||
use syntax::attr;
|
||||
use syntax::source_map::dummy_spanned;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::with_default_globals;
|
||||
|
||||
|
@ -181,7 +180,8 @@ fn test_parse_ok() {
|
|||
|
||||
let mi = attr::mk_name_value_item_str(
|
||||
Ident::from_str("all"),
|
||||
dummy_spanned(Symbol::intern("done"))
|
||||
Symbol::intern("done"),
|
||||
DUMMY_SP,
|
||||
);
|
||||
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
|||
use syntax::ast::{self, AttrStyle, Ident};
|
||||
use syntax::attr;
|
||||
use syntax::ext::base::MacroKind;
|
||||
use syntax::source_map::{dummy_spanned, Spanned};
|
||||
use syntax::source_map::DUMMY_SP;
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
use syntax::symbol::InternedString;
|
||||
use syntax_pos::{self, Pos, FileName};
|
||||
|
@ -930,8 +930,8 @@ impl Attributes {
|
|||
if attr.check_name(sym::enable) {
|
||||
if let Some(feat) = attr.value_str() {
|
||||
let meta = attr::mk_name_value_item_str(
|
||||
Ident::with_empty_ctxt(sym::target_feature),
|
||||
dummy_spanned(feat));
|
||||
Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP
|
||||
);
|
||||
if let Ok(feat_cfg) = Cfg::parse(&meta) {
|
||||
cfg &= feat_cfg;
|
||||
}
|
||||
|
@ -4102,8 +4102,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
|
|||
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
|
||||
PatKind::Struct(ref name, ref fields, etc) => {
|
||||
format!("{} {{ {}{} }}", qpath_to_string(name),
|
||||
fields.iter().map(|&Spanned { node: ref fp, .. }|
|
||||
format!("{}: {}", fp.ident, name_from_pat(&*fp.pat)))
|
||||
fields.iter().map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
|
||||
.collect::<Vec<String>>().join(", "),
|
||||
if etc { ", .." } else { "" }
|
||||
)
|
||||
|
|
|
@ -571,7 +571,7 @@ impl Pat {
|
|||
|
||||
match &self.node {
|
||||
PatKind::Ident(_, _, Some(p)) => p.walk(it),
|
||||
PatKind::Struct(_, fields, _) => fields.iter().all(|field| field.node.pat.walk(it)),
|
||||
PatKind::Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk(it)),
|
||||
PatKind::TupleStruct(_, s) | PatKind::Tuple(s) | PatKind::Slice(s) => {
|
||||
s.iter().all(|p| p.walk(it))
|
||||
}
|
||||
|
@ -609,6 +609,7 @@ pub struct FieldPat {
|
|||
pub is_shorthand: bool,
|
||||
pub attrs: ThinVec<Attribute>,
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||
|
@ -642,7 +643,7 @@ pub enum PatKind {
|
|||
|
||||
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
|
||||
/// The `bool` is `true` in the presence of a `..`.
|
||||
Struct(Path, Vec<Spanned<FieldPat>>, /* recovered */ bool),
|
||||
Struct(Path, Vec<FieldPat>, /* recovered */ bool),
|
||||
|
||||
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
|
||||
TupleStruct(Path, Vec<P<Pat>>),
|
||||
|
@ -939,8 +940,6 @@ pub struct Field {
|
|||
pub id: NodeId,
|
||||
}
|
||||
|
||||
pub type SpannedIdent = Spanned<Ident>;
|
||||
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
|
||||
pub enum BlockCheckMode {
|
||||
Default,
|
||||
|
@ -1287,8 +1286,6 @@ pub enum Movability {
|
|||
Movable,
|
||||
}
|
||||
|
||||
pub type Mac = Spanned<Mac_>;
|
||||
|
||||
/// Represents a macro invocation. The `Path` indicates which macro
|
||||
/// is being invoked, and the vector of token-trees contains the source
|
||||
/// of the macro invocation.
|
||||
|
@ -1296,10 +1293,11 @@ pub type Mac = Spanned<Mac_>;
|
|||
/// N.B., the additional ident for a `macro_rules`-style macro is actually
|
||||
/// stored in the enclosing item.
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
||||
pub struct Mac_ {
|
||||
pub struct Mac {
|
||||
pub path: Path,
|
||||
pub delim: MacDelimiter,
|
||||
pub tts: TokenStream,
|
||||
pub span: Span,
|
||||
pub prior_type_ascription: Option<(Span, bool)>,
|
||||
}
|
||||
|
||||
|
@ -1310,7 +1308,7 @@ pub enum MacDelimiter {
|
|||
Brace,
|
||||
}
|
||||
|
||||
impl Mac_ {
|
||||
impl Mac {
|
||||
pub fn stream(&self) -> TokenStream {
|
||||
self.tts.clone()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::ast::{AttrId, AttrStyle, Name, Ident, Path, PathSegment};
|
|||
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
|
||||
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
|
||||
use crate::mut_visit::visit_clobber;
|
||||
use crate::source_map::{BytePos, Spanned, dummy_spanned};
|
||||
use crate::source_map::{BytePos, Spanned, DUMMY_SP};
|
||||
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||
use crate::parse::parser::Parser;
|
||||
use crate::parse::{self, ParseSess, PResult};
|
||||
|
@ -328,7 +328,9 @@ impl Attribute {
|
|||
let comment = self.value_str().unwrap();
|
||||
let meta = mk_name_value_item_str(
|
||||
Ident::with_empty_ctxt(sym::doc),
|
||||
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
|
||||
Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())),
|
||||
DUMMY_SP,
|
||||
);
|
||||
f(&Attribute {
|
||||
id: self.id,
|
||||
style: self.style,
|
||||
|
@ -345,9 +347,9 @@ impl Attribute {
|
|||
|
||||
/* Constructors */
|
||||
|
||||
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
|
||||
let lit_kind = LitKind::Str(value.node, ast::StrStyle::Cooked);
|
||||
mk_name_value_item(ident, lit_kind, value.span)
|
||||
pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem {
|
||||
let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked);
|
||||
mk_name_value_item(ident, lit_kind, str_span)
|
||||
}
|
||||
|
||||
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::ast::{self, Attribute, Name, PatKind};
|
||||
use crate::attr::{HasAttrs, Stability, Deprecation};
|
||||
use crate::source_map::{SourceMap, Spanned, respan};
|
||||
use crate::source_map::SourceMap;
|
||||
use crate::edition::Edition;
|
||||
use crate::ext::expand::{self, AstFragment, Invocation};
|
||||
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
|
||||
|
@ -916,7 +916,7 @@ pub fn expr_to_spanned_string<'a>(
|
|||
cx: &'a mut ExtCtxt<'_>,
|
||||
mut expr: P<ast::Expr>,
|
||||
err_msg: &str,
|
||||
) -> Result<Spanned<(Symbol, ast::StrStyle)>, Option<DiagnosticBuilder<'a>>> {
|
||||
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
|
||||
// Update `expr.span`'s ctxt now in case expr is an `include!` macro invocation.
|
||||
expr.span = expr.span.apply_mark(cx.current_expansion.id);
|
||||
|
||||
|
@ -926,7 +926,7 @@ pub fn expr_to_spanned_string<'a>(
|
|||
|
||||
Err(match expr.node {
|
||||
ast::ExprKind::Lit(ref l) => match l.node {
|
||||
ast::LitKind::Str(s, style) => return Ok(respan(expr.span, (s, style))),
|
||||
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
|
||||
ast::LitKind::Err(_) => None,
|
||||
_ => Some(cx.struct_span_err(l.span, err_msg))
|
||||
},
|
||||
|
@ -940,7 +940,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
|
|||
expr_to_spanned_string(cx, expr, err_msg)
|
||||
.map_err(|err| err.map(|mut err| err.emit()))
|
||||
.ok()
|
||||
.map(|s| s.node)
|
||||
.map(|(symbol, style, _)| (symbol, style))
|
||||
}
|
||||
|
||||
/// Non-fatally assert that `tts` is empty. Note that this function
|
||||
|
|
|
@ -575,7 +575,7 @@ impl<'a> ExtCtxt<'a> {
|
|||
self.pat(span, PatKind::TupleStruct(path, subpats))
|
||||
}
|
||||
pub fn pat_struct(&self, span: Span, path: ast::Path,
|
||||
field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat> {
|
||||
field_pats: Vec<ast::FieldPat>) -> P<ast::Pat> {
|
||||
self.pat(span, PatKind::Struct(path, field_pats, false))
|
||||
}
|
||||
pub fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::ast::{self, Block, Ident, LitKind, NodeId, PatKind, Path};
|
||||
use crate::ast::{MacStmtStyle, StmtKind, ItemKind};
|
||||
use crate::attr::{self, HasAttrs};
|
||||
use crate::source_map::{dummy_spanned, respan};
|
||||
use crate::source_map::respan;
|
||||
use crate::config::StripUnconfigured;
|
||||
use crate::ext::base::*;
|
||||
use crate::ext::proc_macro::collect_derives;
|
||||
|
@ -492,22 +492,21 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
InvocationKind::Bang { mac, .. } => match ext {
|
||||
SyntaxExtensionKind::Bang(expander) => {
|
||||
self.gate_proc_macro_expansion_kind(span, fragment_kind);
|
||||
let tok_result = expander.expand(self.cx, span, mac.node.stream());
|
||||
let tok_result = expander.expand(self.cx, span, mac.stream());
|
||||
let result =
|
||||
self.parse_ast_fragment(tok_result, fragment_kind, &mac.node.path, span);
|
||||
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span);
|
||||
self.gate_proc_macro_expansion(span, &result);
|
||||
result
|
||||
}
|
||||
SyntaxExtensionKind::LegacyBang(expander) => {
|
||||
let prev = self.cx.current_expansion.prior_type_ascription;
|
||||
self.cx.current_expansion.prior_type_ascription =
|
||||
mac.node.prior_type_ascription;
|
||||
let tok_result = expander.expand(self.cx, span, mac.node.stream());
|
||||
self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription;
|
||||
let tok_result = expander.expand(self.cx, span, mac.stream());
|
||||
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
|
||||
result
|
||||
} else {
|
||||
let msg = format!("non-{kind} macro in {kind} position: {path}",
|
||||
kind = fragment_kind.name(), path = mac.node.path);
|
||||
kind = fragment_kind.name(), path = mac.path);
|
||||
self.cx.span_err(span, &msg);
|
||||
self.cx.trace_macros_diag();
|
||||
fragment_kind.dummy(span)
|
||||
|
@ -1251,13 +1250,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||
ast::NestedMetaItem::MetaItem(
|
||||
attr::mk_name_value_item_str(
|
||||
Ident::with_empty_ctxt(sym::file),
|
||||
dummy_spanned(file),
|
||||
file,
|
||||
DUMMY_SP,
|
||||
),
|
||||
),
|
||||
ast::NestedMetaItem::MetaItem(
|
||||
attr::mk_name_value_item_str(
|
||||
Ident::with_empty_ctxt(sym::contents),
|
||||
dummy_spanned(src_interned),
|
||||
src_interned,
|
||||
DUMMY_SP,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
|
|
@ -14,12 +14,13 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
|
||||
pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
|
||||
fn mac_placeholder() -> ast::Mac {
|
||||
dummy_spanned(ast::Mac_ {
|
||||
ast::Mac {
|
||||
path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
|
||||
tts: TokenStream::empty().into(),
|
||||
delim: ast::MacDelimiter::Brace,
|
||||
span: DUMMY_SP,
|
||||
prior_type_ascription: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let ident = ast::Ident::invalid();
|
||||
|
|
|
@ -533,8 +533,8 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
|
|||
vis.visit_span(span);
|
||||
}
|
||||
|
||||
pub fn noop_visit_mac<T: MutVisitor>(Spanned { node, span }: &mut Mac, vis: &mut T) {
|
||||
let Mac_ { path, delim: _, tts, .. } = node;
|
||||
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut Mac, vis: &mut T) {
|
||||
let Mac { path, delim: _, tts, span, prior_type_ascription: _ } = mac;
|
||||
vis.visit_path(path);
|
||||
vis.visit_tts(tts);
|
||||
vis.visit_span(span);
|
||||
|
@ -1042,10 +1042,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
|||
}
|
||||
PatKind::Struct(path, fields, _etc) => {
|
||||
vis.visit_path(path);
|
||||
for Spanned {
|
||||
node: FieldPat { ident, pat, is_shorthand: _, attrs, id },
|
||||
span
|
||||
} in fields {
|
||||
for FieldPat { ident, pat, is_shorthand: _, attrs, id, span } in fields {
|
||||
vis.visit_ident(ident);
|
||||
vis.visit_id(id);
|
||||
vis.visit_pat(pat);
|
||||
|
|
|
@ -8,13 +8,13 @@ use crate::ast::{self, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode};
|
|||
use crate::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm};
|
||||
use crate::ast::{Ty, TyKind, FunctionRetTy, Arg, FnDecl};
|
||||
use crate::ast::{BinOpKind, BinOp, UnOp};
|
||||
use crate::ast::{Mac_, AnonConst, Field};
|
||||
use crate::ast::{Mac, AnonConst, Field};
|
||||
|
||||
use crate::parse::classify;
|
||||
use crate::parse::token::{self, Token};
|
||||
use crate::parse::diagnostics::{Error};
|
||||
use crate::print::pprust;
|
||||
use crate::source_map::{self, respan, Span};
|
||||
use crate::source_map::{self, Span};
|
||||
use crate::symbol::{kw, sym};
|
||||
use crate::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par};
|
||||
|
||||
|
@ -1011,12 +1011,13 @@ impl<'a> Parser<'a> {
|
|||
// MACRO INVOCATION expression
|
||||
let (delim, tts) = self.expect_delimited_token_tree()?;
|
||||
hi = self.prev_span;
|
||||
ex = ExprKind::Mac(respan(lo.to(hi), Mac_ {
|
||||
ex = ExprKind::Mac(Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: lo.to(hi),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
}));
|
||||
});
|
||||
} else if self.check(&token::OpenDelim(token::Brace)) {
|
||||
if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) {
|
||||
return expr;
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::ast::{Visibility, VisibilityKind, Mutability, FnDecl, FnHeader};
|
|||
use crate::ast::{ForeignItem, ForeignItemKind};
|
||||
use crate::ast::{Ty, TyKind, GenericBounds, TraitRef};
|
||||
use crate::ast::{EnumDef, VariantData, StructField, AnonConst};
|
||||
use crate::ast::{Mac, Mac_, MacDelimiter};
|
||||
use crate::ast::{Mac, MacDelimiter};
|
||||
use crate::ext::base::DummyResult;
|
||||
use crate::parse::token;
|
||||
use crate::parse::parser::maybe_append;
|
||||
|
@ -530,12 +530,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
let hi = self.prev_span;
|
||||
let mac = respan(mac_lo.to(hi), Mac_ {
|
||||
let mac = Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: mac_lo.to(hi),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
});
|
||||
};
|
||||
let item =
|
||||
self.mk_item(lo.to(hi), Ident::invalid(), ItemKind::Mac(mac), visibility, attrs);
|
||||
return Ok(Some(item));
|
||||
|
@ -604,12 +605,13 @@ impl<'a> Parser<'a> {
|
|||
self.expect(&token::Semi)?;
|
||||
}
|
||||
|
||||
Ok(Some(respan(lo.to(self.prev_span), Mac_ {
|
||||
Ok(Some(Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: lo.to(self.prev_span),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
})))
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::{Parser, PResult, PathStyle};
|
|||
|
||||
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||
use crate::ptr::P;
|
||||
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac_};
|
||||
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
|
||||
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
|
||||
use crate::parse::token::{self};
|
||||
use crate::print::pprust;
|
||||
|
@ -275,12 +275,13 @@ impl<'a> Parser<'a> {
|
|||
fn parse_pat_mac_invoc(&mut self, lo: Span, path: Path) -> PResult<'a, PatKind> {
|
||||
self.bump();
|
||||
let (delim, tts) = self.expect_delimited_token_tree()?;
|
||||
let mac = respan(lo.to(self.prev_span), Mac_ {
|
||||
let mac = Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: lo.to(self.prev_span),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
});
|
||||
};
|
||||
Ok(PatKind::Mac(mac))
|
||||
}
|
||||
|
||||
|
@ -487,7 +488,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses the fields of a struct-like pattern.
|
||||
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<Spanned<FieldPat>>, bool)> {
|
||||
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<FieldPat>, bool)> {
|
||||
let mut fields = Vec::new();
|
||||
let mut etc = false;
|
||||
let mut ate_comma = true;
|
||||
|
@ -619,11 +620,7 @@ impl<'a> Parser<'a> {
|
|||
.emit();
|
||||
}
|
||||
|
||||
fn parse_pat_field(
|
||||
&mut self,
|
||||
lo: Span,
|
||||
attrs: Vec<Attribute>
|
||||
) -> PResult<'a, Spanned<FieldPat>> {
|
||||
fn parse_pat_field(&mut self, lo: Span, attrs: Vec<Attribute>) -> PResult<'a, FieldPat> {
|
||||
// Check if a colon exists one ahead. This means we're parsing a fieldname.
|
||||
let hi;
|
||||
let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
|
||||
|
@ -658,15 +655,13 @@ impl<'a> Parser<'a> {
|
|||
(subpat, fieldname, true)
|
||||
};
|
||||
|
||||
Ok(Spanned {
|
||||
Ok(FieldPat {
|
||||
ident: fieldname,
|
||||
pat: subpat,
|
||||
is_shorthand,
|
||||
attrs: attrs.into(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: lo.to(hi),
|
||||
node: FieldPat {
|
||||
ident: fieldname,
|
||||
pat: subpat,
|
||||
is_shorthand,
|
||||
attrs: attrs.into(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::path::PathStyle;
|
|||
use crate::ptr::P;
|
||||
use crate::{maybe_whole, ThinVec};
|
||||
use crate::ast::{self, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind};
|
||||
use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac_, MacDelimiter};
|
||||
use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac, MacDelimiter};
|
||||
use crate::ext::base::DummyResult;
|
||||
use crate::parse::{classify, DirectoryOwnership};
|
||||
use crate::parse::diagnostics::Error;
|
||||
|
@ -99,12 +99,13 @@ impl<'a> Parser<'a> {
|
|||
MacStmtStyle::NoBraces
|
||||
};
|
||||
|
||||
let mac = respan(lo.to(hi), Mac_ {
|
||||
let mac = Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: lo.to(hi),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
});
|
||||
};
|
||||
let node = if delim == MacDelimiter::Brace ||
|
||||
self.token == token::Semi || self.token == token::Eof {
|
||||
StmtKind::Mac(P((mac, style, attrs.into())))
|
||||
|
|
|
@ -4,9 +4,9 @@ use crate::{maybe_whole, maybe_recover_from_interpolated_ty_qpath};
|
|||
use crate::ptr::P;
|
||||
use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident};
|
||||
use crate::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef};
|
||||
use crate::ast::{Mutability, AnonConst, FnDecl, Mac_};
|
||||
use crate::ast::{Mutability, AnonConst, FnDecl, Mac};
|
||||
use crate::parse::token::{self, Token};
|
||||
use crate::source_map::{respan, Span};
|
||||
use crate::source_map::Span;
|
||||
use crate::symbol::{kw};
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -175,13 +175,14 @@ impl<'a> Parser<'a> {
|
|||
if self.eat(&token::Not) {
|
||||
// Macro invocation in type position
|
||||
let (delim, tts) = self.expect_delimited_token_tree()?;
|
||||
let node = Mac_ {
|
||||
let mac = Mac {
|
||||
path,
|
||||
tts,
|
||||
delim,
|
||||
span: lo.to(self.prev_span),
|
||||
prior_type_ascription: self.last_type_ascription,
|
||||
};
|
||||
TyKind::Mac(respan(lo.to(self.prev_span), node))
|
||||
TyKind::Mac(mac)
|
||||
} else {
|
||||
// Just a type path or bound list (trait object type) starting with a trait.
|
||||
// `Type`
|
||||
|
|
|
@ -172,8 +172,8 @@ fn get_spans_of_pat_idents(src: &str) -> Vec<Span> {
|
|||
impl<'a> crate::visit::Visitor<'a> for PatIdentVisitor {
|
||||
fn visit_pat(&mut self, p: &'a ast::Pat) {
|
||||
match p.node {
|
||||
PatKind::Ident(_ , ref spannedident, _) => {
|
||||
self.spans.push(spannedident.span.clone());
|
||||
PatKind::Ident(_ , ref ident, _) => {
|
||||
self.spans.push(ident.span.clone());
|
||||
}
|
||||
_ => {
|
||||
crate::visit::walk_pat(self, p);
|
||||
|
@ -273,7 +273,7 @@ fn ttdelim_span() {
|
|||
"foo!( fn main() { body } )".to_string(), &sess).unwrap();
|
||||
|
||||
let tts: Vec<_> = match expr.node {
|
||||
ast::ExprKind::Mac(ref mac) => mac.node.stream().trees().collect(),
|
||||
ast::ExprKind::Mac(ref mac) => mac.stream().trees().collect(),
|
||||
_ => panic!("not a macro"),
|
||||
};
|
||||
|
||||
|
|
|
@ -1067,7 +1067,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
ast::ForeignItemKind::Macro(ref m) => {
|
||||
self.print_mac(m);
|
||||
match m.node.delim {
|
||||
match m.delim {
|
||||
MacDelimiter::Brace => {},
|
||||
_ => self.s.word(";")
|
||||
}
|
||||
|
@ -1341,7 +1341,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
ast::ItemKind::Mac(ref mac) => {
|
||||
self.print_mac(mac);
|
||||
match mac.node.delim {
|
||||
match mac.delim {
|
||||
MacDelimiter::Brace => {}
|
||||
_ => self.s.word(";"),
|
||||
}
|
||||
|
@ -1554,7 +1554,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
ast::TraitItemKind::Macro(ref mac) => {
|
||||
self.print_mac(mac);
|
||||
match mac.node.delim {
|
||||
match mac.delim {
|
||||
MacDelimiter::Brace => {}
|
||||
_ => self.s.word(";"),
|
||||
}
|
||||
|
@ -1591,7 +1591,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
ast::ImplItemKind::Macro(ref mac) => {
|
||||
self.print_mac(mac);
|
||||
match mac.node.delim {
|
||||
match mac.delim {
|
||||
MacDelimiter::Brace => {}
|
||||
_ => self.s.word(";"),
|
||||
}
|
||||
|
@ -1749,11 +1749,11 @@ impl<'a> State<'a> {
|
|||
|
||||
crate fn print_mac(&mut self, m: &ast::Mac) {
|
||||
self.print_mac_common(
|
||||
Some(MacHeader::Path(&m.node.path)),
|
||||
Some(MacHeader::Path(&m.path)),
|
||||
true,
|
||||
None,
|
||||
m.node.delim.to_token(),
|
||||
m.node.stream(),
|
||||
m.delim.to_token(),
|
||||
m.stream(),
|
||||
true,
|
||||
m.span,
|
||||
);
|
||||
|
@ -2367,14 +2367,14 @@ impl<'a> State<'a> {
|
|||
Consistent, &fields[..],
|
||||
|s, f| {
|
||||
s.cbox(INDENT_UNIT);
|
||||
if !f.node.is_shorthand {
|
||||
s.print_ident(f.node.ident);
|
||||
if !f.is_shorthand {
|
||||
s.print_ident(f.ident);
|
||||
s.word_nbsp(":");
|
||||
}
|
||||
s.print_pat(&f.node.pat);
|
||||
s.print_pat(&f.pat);
|
||||
s.end();
|
||||
},
|
||||
|f| f.node.pat.span);
|
||||
|f| f.pat.span);
|
||||
if etc {
|
||||
if !fields.is_empty() { self.word_space(","); }
|
||||
self.s.word("..");
|
||||
|
|
|
@ -442,9 +442,9 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
|
|||
PatKind::Struct(ref path, ref fields, _) => {
|
||||
visitor.visit_path(path, pattern.id);
|
||||
for field in fields {
|
||||
walk_list!(visitor, visit_attribute, field.node.attrs.iter());
|
||||
visitor.visit_ident(field.node.ident);
|
||||
visitor.visit_pat(&field.node.pat)
|
||||
walk_list!(visitor, visit_attribute, field.attrs.iter());
|
||||
visitor.visit_ident(field.ident);
|
||||
visitor.visit_pat(&field.pat)
|
||||
}
|
||||
}
|
||||
PatKind::Tuple(ref elems) => {
|
||||
|
@ -663,7 +663,7 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
|
|||
}
|
||||
|
||||
pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a Mac) {
|
||||
visitor.visit_path(&mac.node.path, DUMMY_NODE_ID);
|
||||
visitor.visit_path(&mac.path, DUMMY_NODE_ID);
|
||||
}
|
||||
|
||||
pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use errors::{Applicability, DiagnosticBuilder};
|
||||
|
||||
use syntax::ast::{self, *};
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::ext::base::*;
|
||||
use syntax::parse::token::{self, TokenKind};
|
||||
use syntax::parse::parser::Parser;
|
||||
|
@ -25,7 +24,7 @@ pub fn expand_assert<'cx>(
|
|||
};
|
||||
|
||||
let sp = sp.apply_mark(cx.current_expansion.id);
|
||||
let panic_call = Mac_ {
|
||||
let panic_call = Mac {
|
||||
path: Path::from_ident(Ident::new(sym::panic, sp)),
|
||||
tts: custom_message.unwrap_or_else(|| {
|
||||
TokenStream::from(TokenTree::token(
|
||||
|
@ -37,6 +36,7 @@ pub fn expand_assert<'cx>(
|
|||
))
|
||||
}).into(),
|
||||
delim: MacDelimiter::Parenthesis,
|
||||
span: sp,
|
||||
prior_type_ascription: None,
|
||||
};
|
||||
let if_expr = cx.expr_if(
|
||||
|
@ -44,10 +44,7 @@ pub fn expand_assert<'cx>(
|
|||
cx.expr(sp, ExprKind::Unary(UnOp::Not, cond_expr)),
|
||||
cx.expr(
|
||||
sp,
|
||||
ExprKind::Mac(Spanned {
|
||||
span: sp,
|
||||
node: panic_call,
|
||||
}),
|
||||
ExprKind::Mac(panic_call),
|
||||
),
|
||||
None,
|
||||
);
|
||||
|
|
|
@ -187,7 +187,7 @@ use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
|
|||
use syntax::ast::{VariantData, GenericParamKind, GenericArg};
|
||||
use syntax::attr;
|
||||
use syntax::ext::base::{Annotatable, ExtCtxt, SpecialDerives};
|
||||
use syntax::source_map::{self, respan};
|
||||
use syntax::source_map::respan;
|
||||
use syntax::util::map_in_place::MapInPlace;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
|
@ -1610,15 +1610,13 @@ impl<'a> TraitDef<'a> {
|
|||
if ident.is_none() {
|
||||
cx.span_bug(sp, "a braced struct with unnamed fields in `derive`");
|
||||
}
|
||||
source_map::Spanned {
|
||||
ast::FieldPat {
|
||||
ident: ident.unwrap(),
|
||||
is_shorthand: false,
|
||||
attrs: ThinVec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: pat.span.with_ctxt(self.span.ctxt()),
|
||||
node: ast::FieldPat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: ident.unwrap(),
|
||||
pat,
|
||||
is_shorthand: false,
|
||||
attrs: ThinVec::new(),
|
||||
},
|
||||
pat,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -846,9 +846,9 @@ pub fn expand_preparsed_format_args(
|
|||
|
||||
let msg = "format argument must be a string literal";
|
||||
let fmt_sp = efmt.span;
|
||||
let fmt = match expr_to_spanned_string(ecx, efmt, msg) {
|
||||
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
|
||||
Ok(mut fmt) if append_newline => {
|
||||
fmt.node.0 = Symbol::intern(&format!("{}\n", fmt.node.0));
|
||||
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
|
||||
fmt
|
||||
}
|
||||
Ok(fmt) => fmt,
|
||||
|
@ -875,7 +875,7 @@ pub fn expand_preparsed_format_args(
|
|||
_ => (false, None),
|
||||
};
|
||||
|
||||
let str_style = match fmt.node.1 {
|
||||
let str_style = match fmt_style {
|
||||
ast::StrStyle::Cooked => None,
|
||||
ast::StrStyle::Raw(raw) => {
|
||||
Some(raw as usize)
|
||||
|
@ -981,7 +981,7 @@ pub fn expand_preparsed_format_args(
|
|||
vec![]
|
||||
};
|
||||
|
||||
let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below
|
||||
let fmt_str = &*fmt_str.as_str(); // for the suggestions below
|
||||
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
|
||||
|
||||
let mut unverified_pieces = Vec::new();
|
||||
|
@ -995,7 +995,7 @@ pub fn expand_preparsed_format_args(
|
|||
|
||||
if !parser.errors.is_empty() {
|
||||
let err = parser.errors.remove(0);
|
||||
let sp = fmt.span.from_inner(err.span);
|
||||
let sp = fmt_span.from_inner(err.span);
|
||||
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}",
|
||||
err.description));
|
||||
e.span_label(sp, err.label + " in format string");
|
||||
|
@ -1003,7 +1003,7 @@ pub fn expand_preparsed_format_args(
|
|||
e.note(¬e);
|
||||
}
|
||||
if let Some((label, span)) = err.secondary_label {
|
||||
let sp = fmt.span.from_inner(span);
|
||||
let sp = fmt_span.from_inner(span);
|
||||
e.span_label(sp, label);
|
||||
}
|
||||
e.emit();
|
||||
|
@ -1011,7 +1011,7 @@ pub fn expand_preparsed_format_args(
|
|||
}
|
||||
|
||||
let arg_spans = parser.arg_places.iter()
|
||||
.map(|span| fmt.span.from_inner(*span))
|
||||
.map(|span| fmt_span.from_inner(*span))
|
||||
.collect();
|
||||
|
||||
let named_pos: FxHashSet<usize> = names.values().cloned().collect();
|
||||
|
@ -1034,7 +1034,7 @@ pub fn expand_preparsed_format_args(
|
|||
str_pieces: Vec::with_capacity(unverified_pieces.len()),
|
||||
all_pieces_simple: true,
|
||||
macsp,
|
||||
fmtsp: fmt.span,
|
||||
fmtsp: fmt_span,
|
||||
invalid_refs: Vec::new(),
|
||||
arg_spans,
|
||||
arg_with_formatting: Vec::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue