Skip to content

Commit

Permalink
Remove Spanned from {ast,hir}::FieldPat
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Aug 15, 2019
1 parent 433b1e3 commit a618271
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) => {
Expand Down
16 changes: 6 additions & 10 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(",");
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
};
Expand Down Expand Up @@ -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 {
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {}
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_SP, Spanned};
use syntax::source_map::DUMMY_SP;
use syntax::symbol::{Symbol, kw, sym};
use syntax::symbol::InternedString;
use syntax_pos::{self, Pos, FileName};
Expand Down Expand Up @@ -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 { "" }
)
Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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>>),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
5 changes: 1 addition & 4 deletions src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit a618271

Please sign in to comment.