Skip to content

Commit 6e8fabb

Browse files
authored
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.
2 parents 19d6178 + a618271 commit 6e8fabb

File tree

39 files changed

+156
-172
lines changed

39 files changed

+156
-172
lines changed

src/librustc/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
136136
}
137137

138138
PatKind::Struct(_, ref subpats, _) => {
139-
let pats_exit = self.pats_all(subpats.iter().map(|f| &f.node.pat), pred);
139+
let pats_exit = self.pats_all(subpats.iter().map(|f| &f.pat), pred);
140140
self.add_ast_node(pat.hir_id.local_id, &[pats_exit])
141141
}
142142

src/librustc/hir/intravisit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
704704
PatKind::Struct(ref qpath, ref fields, _) => {
705705
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
706706
for field in fields {
707-
visitor.visit_id(field.node.hir_id);
708-
visitor.visit_ident(field.node.ident);
709-
visitor.visit_pat(&field.node.pat)
707+
visitor.visit_id(field.hir_id);
708+
visitor.visit_ident(field.ident);
709+
visitor.visit_pat(&field.pat)
710710
}
711711
}
712712
PatKind::Tuple(ref tuple_elements, _) => {

src/librustc/hir/lowering.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -2691,16 +2691,12 @@ impl<'a> LoweringContext<'a> {
26912691

26922692
let fs = fields
26932693
.iter()
2694-
.map(|f| {
2695-
Spanned {
2696-
span: f.span,
2697-
node: hir::FieldPat {
2698-
hir_id: self.next_id(),
2699-
ident: f.node.ident,
2700-
pat: self.lower_pat(&f.node.pat),
2701-
is_shorthand: f.node.is_shorthand,
2702-
},
2703-
}
2694+
.map(|f| hir::FieldPat {
2695+
hir_id: self.next_id(),
2696+
ident: f.ident,
2697+
pat: self.lower_pat(&f.pat),
2698+
is_shorthand: f.is_shorthand,
2699+
span: f.span,
27042700
})
27052701
.collect();
27062702
hir::PatKind::Struct(qpath, fs, etc)

src/librustc/hir/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ impl Pat {
877877
match self.node {
878878
PatKind::Binding(.., Some(ref p)) => p.walk_(it),
879879
PatKind::Struct(_, ref fields, _) => {
880-
fields.iter().all(|field| field.node.pat.walk_(it))
880+
fields.iter().all(|field| field.pat.walk_(it))
881881
}
882882
PatKind::TupleStruct(_, ref s, _) | PatKind::Tuple(ref s, _) => {
883883
s.iter().all(|p| p.walk_(it))
@@ -923,6 +923,7 @@ pub struct FieldPat {
923923
/// The pattern the field is destructured to.
924924
pub pat: P<Pat>,
925925
pub is_shorthand: bool,
926+
pub span: Span,
926927
}
927928

928929
/// Explicit binding annotations given in the HIR for a binding. Note
@@ -968,7 +969,7 @@ pub enum PatKind {
968969

969970
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
970971
/// The `bool` is `true` in the presence of a `..`.
971-
Struct(QPath, HirVec<Spanned<FieldPat>>, bool),
972+
Struct(QPath, HirVec<FieldPat>, bool),
972973

973974
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
974975
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.

src/librustc/hir/print.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1670,14 +1670,14 @@ impl<'a> State<'a> {
16701670
&fields[..],
16711671
|s, f| {
16721672
s.cbox(INDENT_UNIT);
1673-
if !f.node.is_shorthand {
1674-
s.print_ident(f.node.ident);
1673+
if !f.is_shorthand {
1674+
s.print_ident(f.ident);
16751675
s.word_nbsp(":");
16761676
}
1677-
s.print_pat(&f.node.pat);
1677+
s.print_pat(&f.pat);
16781678
s.end()
16791679
},
1680-
|f| f.node.pat.span);
1680+
|f| f.pat.span);
16811681
if etc {
16821682
if !fields.is_empty() {
16831683
self.word_space(",");

src/librustc/ich/impls_hir.rs

-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
153153
}
154154
}
155155

156-
impl_stable_hash_for_spanned!(hir::FieldPat);
157-
158156
impl_stable_hash_for_spanned!(hir::BinOpKind);
159157

160158
impl_stable_hash_for!(struct hir::Stmt {
@@ -187,8 +185,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
187185

188186
impl_stable_hash_for_spanned!(usize);
189187

190-
impl_stable_hash_for_spanned!(ast::Ident);
191-
192188
impl_stable_hash_for!(struct ast::Ident {
193189
name,
194190
span,

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
13451345
// part of `walk_mac`, and (b) we should be calling
13461346
// `visit_path`, *but* that would require a `NodeId`, and I
13471347
// want to get #53686 fixed quickly. -nmatsakis
1348-
ast_visit::walk_path(self, &mac.node.path);
1348+
ast_visit::walk_path(self, &mac.path);
13491349

13501350
run_early_pass!(self, check_mac, mac);
13511351
}

src/librustc/middle/dead.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use crate::util::nodemap::FxHashSet;
1717

1818
use rustc_data_structures::fx::FxHashMap;
1919

20-
use syntax::{ast, source_map};
21-
use syntax::attr;
20+
use syntax::{ast, attr};
2221
use syntax::symbol::sym;
2322
use syntax_pos;
2423

@@ -119,17 +118,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
119118
}
120119
}
121120

122-
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res,
123-
pats: &[source_map::Spanned<hir::FieldPat>]) {
121+
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res, pats: &[hir::FieldPat]) {
124122
let variant = match self.tables.node_type(lhs.hir_id).sty {
125123
ty::Adt(adt, _) => adt.variant_of_res(res),
126124
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
127125
};
128126
for pat in pats {
129-
if let PatKind::Wild = pat.node.pat.node {
127+
if let PatKind::Wild = pat.pat.node {
130128
continue;
131129
}
132-
let index = self.tcx.field_index(pat.node.hir_id, self.tables);
130+
let index = self.tcx.field_index(pat.hir_id, self.tables);
133131
self.insert_def_id(variant.fields[index].did);
134132
}
135133
}

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ fn add_from_pat<'tcx>(ir: &mut IrMaps<'tcx>, pat: &P<hir::Pat>) {
418418
}
419419
Struct(_, ref fields, _) => {
420420
for field in fields {
421-
if field.node.is_shorthand {
422-
shorthand_field_ids.insert(field.node.pat.hir_id);
421+
if field.is_shorthand {
422+
shorthand_field_ids.insert(field.pat.hir_id);
423423
}
424424
}
425425
}

src/librustc/middle/mem_categorization.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
12821282
};
12831283

12841284
for fp in field_pats {
1285-
let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2)
1286-
let f_index = self.tcx.field_index(fp.node.hir_id, self.tables);
1285+
let field_ty = self.pat_ty_adjusted(&fp.pat)?; // see (*2)
1286+
let f_index = self.tcx.field_index(fp.hir_id, self.tables);
12871287
let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index,
1288-
fp.node.ident, field_ty));
1289-
self.cat_pattern_(cmt_field, &fp.node.pat, op)?;
1288+
fp.ident, field_ty));
1289+
self.cat_pattern_(cmt_field, &fp.pat, op)?;
12901290
}
12911291
}
12921292

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ fn resolve_local<'tcx>(
12071207
PatKind::Binding(hir::BindingAnnotation::RefMut, ..) => true,
12081208

12091209
PatKind::Struct(_, ref field_pats, _) => {
1210-
field_pats.iter().any(|fp| is_binding_pat(&fp.node.pat))
1210+
field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
12111211
}
12121212

12131213
PatKind::Slice(ref pats1, ref pats2, ref pats3) => {

src/librustc_lint/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
164164
.expect("struct pattern type is not an ADT")
165165
.variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id));
166166
for fieldpat in field_pats {
167-
if fieldpat.node.is_shorthand {
167+
if fieldpat.is_shorthand {
168168
continue;
169169
}
170170
if fieldpat.span.ctxt().outer_expn_info().is_some() {
@@ -173,9 +173,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
173173
// (Issue #49588)
174174
continue;
175175
}
176-
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
176+
if let PatKind::Binding(_, _, ident, None) = fieldpat.pat.node {
177177
if cx.tcx.find_field_index(ident, &variant) ==
178-
Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) {
178+
Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables)) {
179179
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
180180
fieldpat.span,
181181
&format!("the `{}:` in this pattern is redundant", ident));
@@ -1493,7 +1493,7 @@ impl EarlyLintPass for KeywordIdents {
14931493
self.check_tokens(cx, mac_def.stream());
14941494
}
14951495
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
1496-
self.check_tokens(cx, mac.node.tts.clone().into());
1496+
self.check_tokens(cx, mac.tts.clone().into());
14971497
}
14981498
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
14991499
self.check_ident_token(cx, UnderMacro(false), ident);

src/librustc_mir/hair/pattern/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
645645
fields.iter()
646646
.map(|field| {
647647
FieldPattern {
648-
field: Field::new(self.tcx.field_index(field.node.hir_id,
648+
field: Field::new(self.tcx.field_index(field.hir_id,
649649
self.tables)),
650-
pattern: self.lower_pattern(&field.node.pat),
650+
pattern: self.lower_pattern(&field.pat),
651651
}
652652
})
653653
.collect();

src/librustc_passes/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
824824
|this| visit::walk_enum_def(this, enum_definition, generics, item_id))
825825
}
826826

827-
fn visit_mac(&mut self, mac: &Spanned<Mac_>) {
827+
fn visit_mac(&mut self, mac: &Mac) {
828828
// when a new macro kind is added but the author forgets to set it up for expansion
829829
// because that's the only part that won't cause a compiler error
830830
self.session.diagnostic()

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
10751075
let adt = self.tables.pat_ty(pat).ty_adt_def().unwrap();
10761076
let variant = adt.variant_of_res(res);
10771077
for field in fields {
1078-
let use_ctxt = field.node.ident.span;
1079-
let index = self.tcx.field_index(field.node.hir_id, self.tables);
1078+
let use_ctxt = field.ident.span;
1079+
let index = self.tcx.field_index(field.hir_id, self.tables);
10801080
self.check_field(use_ctxt, field.span, adt, &variant.fields[index]);
10811081
}
10821082
}

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> base::Resolver for Resolver<'a> {
186186
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
187187
(&attr.path, MacroKind::Attr, derives.clone(), after_derive),
188188
InvocationKind::Bang { ref mac, .. } =>
189-
(&mac.node.path, MacroKind::Bang, Vec::new(), false),
189+
(&mac.path, MacroKind::Bang, Vec::new(), false),
190190
InvocationKind::Derive { ref path, .. } =>
191191
(path, MacroKind::Derive, Vec::new(), false),
192192
InvocationKind::DeriveContainer { ref derives, .. } => {

src/librustc_save_analysis/dump_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::print::pprust::{
3232
ty_to_string
3333
};
3434
use syntax::ptr::P;
35-
use syntax::source_map::{Spanned, DUMMY_SP, respan};
35+
use syntax::source_map::{DUMMY_SP, respan};
3636
use syntax::walk_list;
3737
use syntax_pos::*;
3838

@@ -879,7 +879,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
879879
};
880880
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
881881

882-
for &Spanned { node: ref field, .. } in fields {
882+
for field in fields {
883883
if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
884884
if !self.span.filter_generated(field.ident.span) {
885885
let span = self.span_from_span(field.ident.span);

src/librustc_typeck/check/_match.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::traits::{ObligationCause, ObligationCauseCode};
1212
use rustc::ty::{self, Ty, TypeFoldable};
1313
use rustc::ty::subst::Kind;
1414
use syntax::ast;
15-
use syntax::source_map::Spanned;
1615
use syntax::util::lev_distance::find_best_match_for_name;
1716
use syntax_pos::Span;
1817
use syntax_pos::hygiene::DesugaringKind;
@@ -1036,7 +1035,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10361035
&self,
10371036
pat: &'tcx hir::Pat,
10381037
qpath: &hir::QPath,
1039-
fields: &'tcx [Spanned<hir::FieldPat>],
1038+
fields: &'tcx [hir::FieldPat],
10401039
etc: bool,
10411040
expected: Ty<'tcx>,
10421041
def_bm: ty::BindingMode,
@@ -1048,7 +1047,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10481047
variant_ty
10491048
} else {
10501049
for field in fields {
1051-
self.check_pat_walk(&field.node.pat, self.tcx.types.err, def_bm, discrim_span);
1050+
self.check_pat_walk(&field.pat, self.tcx.types.err, def_bm, discrim_span);
10521051
}
10531052
return self.tcx.types.err;
10541053
};
@@ -1206,7 +1205,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
12061205
pat_id: hir::HirId,
12071206
span: Span,
12081207
variant: &'tcx ty::VariantDef,
1209-
fields: &'tcx [Spanned<hir::FieldPat>],
1208+
fields: &'tcx [hir::FieldPat],
12101209
etc: bool,
12111210
def_bm: ty::BindingMode,
12121211
) -> bool {
@@ -1231,7 +1230,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
12311230

12321231
let mut inexistent_fields = vec![];
12331232
// Typecheck each field.
1234-
for &Spanned { node: ref field, span } in fields {
1233+
for field in fields {
1234+
let span = field.span;
12351235
let ident = tcx.adjust_ident(field.ident, variant.def_id);
12361236
let field_ty = match used_fields.entry(ident) {
12371237
Occupied(occupied) => {

src/librustc_typeck/check/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
283283
}
284284
hir::PatKind::Struct(_, ref fields, _) => {
285285
for field in fields {
286-
self.visit_field_id(field.node.hir_id);
286+
self.visit_field_id(field.hir_id);
287287
}
288288
}
289289
_ => {}

src/librustdoc/clean/cfg/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::*;
33
use syntax_pos::DUMMY_SP;
44
use syntax::ast::*;
55
use syntax::attr;
6-
use syntax::source_map::dummy_spanned;
76
use syntax::symbol::Symbol;
87
use syntax::with_default_globals;
98

@@ -181,7 +180,8 @@ fn test_parse_ok() {
181180

182181
let mi = attr::mk_name_value_item_str(
183182
Ident::from_str("all"),
184-
dummy_spanned(Symbol::intern("done"))
183+
Symbol::intern("done"),
184+
DUMMY_SP,
185185
);
186186
assert_eq!(Cfg::parse(&mi), Ok(name_value_cfg("all", "done")));
187187

src/librustdoc/clean/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
2929
use syntax::ast::{self, AttrStyle, Ident};
3030
use syntax::attr;
3131
use syntax::ext::base::MacroKind;
32-
use syntax::source_map::{dummy_spanned, Spanned};
32+
use syntax::source_map::DUMMY_SP;
3333
use syntax::symbol::{Symbol, kw, sym};
3434
use syntax::symbol::InternedString;
3535
use syntax_pos::{self, Pos, FileName};
@@ -930,8 +930,8 @@ impl Attributes {
930930
if attr.check_name(sym::enable) {
931931
if let Some(feat) = attr.value_str() {
932932
let meta = attr::mk_name_value_item_str(
933-
Ident::with_empty_ctxt(sym::target_feature),
934-
dummy_spanned(feat));
933+
Ident::with_empty_ctxt(sym::target_feature), feat, DUMMY_SP
934+
);
935935
if let Ok(feat_cfg) = Cfg::parse(&meta) {
936936
cfg &= feat_cfg;
937937
}
@@ -4102,8 +4102,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
41024102
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
41034103
PatKind::Struct(ref name, ref fields, etc) => {
41044104
format!("{} {{ {}{} }}", qpath_to_string(name),
4105-
fields.iter().map(|&Spanned { node: ref fp, .. }|
4106-
format!("{}: {}", fp.ident, name_from_pat(&*fp.pat)))
4105+
fields.iter().map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
41074106
.collect::<Vec<String>>().join(", "),
41084107
if etc { ", .." } else { "" }
41094108
)

0 commit comments

Comments
 (0)