Skip to content

Commit 61504ae

Browse files
committed
Remove span from hir::Pat.
1 parent 1f05c3d commit 61504ae

File tree

38 files changed

+241
-202
lines changed

38 files changed

+241
-202
lines changed

src/librustc_ast_lowering/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10701070
// parameters (c.f. rust-lang/rust#64512).
10711071
for (index, parameter) in decl.inputs.iter().enumerate() {
10721072
let parameter = this.lower_param(parameter);
1073-
let span = parameter.pat.span;
1073+
let span = this.spans[parameter.pat.hir_id];
10741074

10751075
// Check if this is a binding pattern, if so, we can optimize and avoid adding a
10761076
// `let <pat> = __argN;` statement. In this case, we do not rename the parameter.

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25322532
self.arena.alloc(hir::Pat {
25332533
hir_id,
25342534
kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
2535-
span,
25362535
}),
25372536
hir_id,
25382537
)
@@ -2543,7 +2542,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25432542
}
25442543

25452544
fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2546-
self.arena.alloc(hir::Pat { hir_id: self.next_id(span), kind, span })
2545+
self.arena.alloc(hir::Pat { hir_id: self.next_id(span), kind })
25472546
}
25482547

25492548
/// Given a suffix `["b", "c", "d"]`, returns path `::std::b::c::d` when

src/librustc_ast_lowering/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
266266

267267
/// Construct a `Pat` with the `HirId` of `p.id` lowered.
268268
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
269-
self.arena.alloc(hir::Pat { hir_id: self.lower_node_id(p.id, p.span), kind, span: p.span })
269+
self.arena.alloc(hir::Pat { hir_id: self.lower_node_id(p.id, p.span), kind })
270270
}
271271

272272
/// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern.

src/librustc_hir/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ pub struct Pat<'hir> {
744744
#[stable_hasher(ignore)]
745745
pub hir_id: HirId,
746746
pub kind: PatKind<'hir>,
747-
pub span: Span,
748747
}
749748

750749
impl Pat<'_> {

src/librustc_hir/pat_util.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::def::{CtorOf, DefKind, Res};
22
use crate::def_id::DefId;
33
use crate::hir::{self, HirId, PatKind};
44
use rustc_span::symbol::Ident;
5-
use rustc_span::Span;
65

76
use std::iter::{Enumerate, ExactSizeIterator};
87

@@ -79,10 +78,10 @@ impl hir::Pat<'_> {
7978

8079
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
8180
/// `match foo() { Some(a) => (), None => () }`
82-
pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Span, Ident)) {
81+
pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Ident)) {
8382
self.walk_always(|p| {
8483
if let PatKind::Binding(binding_mode, _, ident, _) = p.kind {
85-
f(binding_mode, p.hir_id, p.span, ident);
84+
f(binding_mode, p.hir_id, ident);
8685
}
8786
});
8887
}
@@ -91,17 +90,14 @@ impl hir::Pat<'_> {
9190
/// `match foo() { Some(a) => (), None => () }`.
9291
///
9392
/// When encountering an or-pattern `p_0 | ... | p_n` only `p_0` will be visited.
94-
pub fn each_binding_or_first(
95-
&self,
96-
f: &mut impl FnMut(hir::BindingAnnotation, HirId, Span, Ident),
97-
) {
93+
pub fn each_binding_or_first(&self, f: &mut impl FnMut(hir::BindingAnnotation, HirId, Ident)) {
9894
self.walk(|p| match &p.kind {
9995
PatKind::Or(ps) => {
10096
ps[0].each_binding_or_first(f);
10197
false
10298
}
10399
PatKind::Binding(bm, _, ident, _) => {
104-
f(*bm, p.hir_id, p.span, *ident);
100+
f(*bm, p.hir_id, *ident);
105101
true
106102
}
107103
_ => true,
@@ -181,7 +177,7 @@ impl hir::Pat<'_> {
181177
// ref bindings are be implicit after #42640 (default match binding modes). See issue #44848.
182178
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
183179
let mut result = None;
184-
self.each_binding(|annotation, _, _, _| match annotation {
180+
self.each_binding(|annotation, _, _| match annotation {
185181
hir::BindingAnnotation::Ref => match result {
186182
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
187183
_ => {}

src/librustc_hir_pretty/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,26 +337,29 @@ impl<'a> State<'a> {
337337
pub fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
338338
where
339339
F: FnMut(&mut State<'_>, &T),
340-
G: FnMut(&T) -> rustc_span::Span,
340+
G: FnMut(&State<'_>, &T) -> rustc_span::Span,
341341
{
342342
self.rbox(0, b);
343343
let len = elts.len();
344344
let mut i = 0;
345345
for elt in elts {
346-
self.maybe_print_comment(get_span(elt).hi());
346+
self.maybe_print_comment(get_span(self, elt).hi());
347347
op(self, elt);
348348
i += 1;
349349
if i < len {
350350
self.s.word(",");
351-
self.maybe_print_trailing_comment(get_span(elt), Some(get_span(&elts[i]).hi()));
351+
self.maybe_print_trailing_comment(
352+
get_span(self, elt),
353+
Some(get_span(self, &elts[i]).hi()),
354+
);
352355
self.space_if_not_bol();
353356
}
354357
}
355358
self.end();
356359
}
357360

358361
pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[hir::Expr<'_>]) {
359-
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
362+
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |_, e| e.span)
360363
}
361364

362365
pub fn print_mod(&mut self, _mod: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
@@ -1185,7 +1188,7 @@ impl<'a> State<'a> {
11851188
s.print_expr(&field.expr);
11861189
s.end()
11871190
},
1188-
|f| f.span,
1191+
|_, f| f.span,
11891192
);
11901193
match *wth {
11911194
Some(ref expr) => {
@@ -1827,7 +1830,8 @@ impl<'a> State<'a> {
18271830
}
18281831

18291832
pub fn print_pat(&mut self, pat: &hir::Pat<'_>) {
1830-
self.maybe_print_comment(pat.span.lo());
1833+
let span = self.span(pat.hir_id);
1834+
self.maybe_print_comment(span.lo());
18311835
self.ann.pre(self, AnnNode::Pat(pat));
18321836
// Pat isn't normalized, but the beauty of it
18331837
// is that it doesn't matter
@@ -1891,7 +1895,7 @@ impl<'a> State<'a> {
18911895
s.print_pat(&f.pat);
18921896
s.end()
18931897
},
1894-
|f| f.pat.span,
1898+
|s, f| s.span(f.pat.hir_id),
18951899
);
18961900
if etc {
18971901
if !fields.is_empty() {

src/librustc_infer/infer/error_reporting/need_type_info.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
110110
if let (None, Some(ty)) =
111111
(self.found_arg_pattern, self.node_ty_contains_target(param.hir_id))
112112
{
113-
if self.target_span.contains(param.pat.span) {
113+
if self.target_span.contains(self.infcx.tcx.hir().span(param.pat.hir_id)) {
114114
self.found_arg_pattern = Some(&*param.pat);
115115
self.found_node_ty = Some(ty);
116116
}
@@ -298,7 +298,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
298298
local_visitor.visit_expr(expr);
299299
}
300300
let err_span = if let Some(pattern) = local_visitor.found_arg_pattern {
301-
pattern.span
301+
self.tcx.hir().span(pattern.hir_id)
302302
} else if let Some(span) = name_sp {
303303
// `span` here lets us point at `sum` instead of the entire right hand side expr:
304304
// error[E0282]: type annotations needed
@@ -461,12 +461,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
461461
// with the type parameter `_` specified
462462
// ```
463463
err.span_label(
464-
pattern.span,
464+
self.tcx.hir().span(pattern.hir_id),
465465
format!("consider giving this closure parameter {}", suffix),
466466
);
467467
} else if let Some(pattern) = local_visitor.found_local_pattern {
468+
let pattern_span = self.tcx.hir().span(pattern.hir_id);
468469
let msg = if let Some(simple_ident) = pattern.simple_ident() {
469-
match pattern.span.desugaring_kind() {
470+
match pattern_span.desugaring_kind() {
470471
None => format!("consider giving `{}` {}", simple_ident, suffix),
471472
Some(DesugaringKind::ForLoop) => {
472473
"the element type for this iterator is not specified".to_string()
@@ -476,7 +477,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
476477
} else {
477478
format!("consider giving this pattern {}", suffix)
478479
};
479-
err.span_label(pattern.span, msg);
480+
err.span_label(pattern_span, msg);
480481
} else if let Some(e) = local_visitor.found_method_call {
481482
if let ExprKind::MethodCall(segment, ..) = &e.kind {
482483
// Suggest specifying type params or point out the return type of the call:

src/librustc_middle/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
406406
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
407407
let node =
408408
if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) };
409-
self.insert(pat.span, pat.hir_id, node);
409+
self.insert(DUMMY_SP, pat.hir_id, node);
410410

411411
self.with_parent(pat.hir_id, |this| {
412412
intravisit::walk_pat(this, pat);

src/librustc_mir_build/build/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
792792
argument_scope: region::Scope,
793793
ast_body: &'tcx hir::Expr<'tcx>,
794794
) -> BlockAnd<()> {
795+
let tcx = self.hir.tcx();
796+
let tcx_hir = tcx.hir();
797+
795798
// Allocate locals for the function arguments
796799
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
797800
let source_info =
798-
SourceInfo::outermost(arg_opt.map_or(self.fn_span, |arg| arg.pat.span));
801+
SourceInfo::outermost(arg_opt.map_or(self.fn_span, |arg| tcx.hir().span(arg.pat.hir_id)));
799802
let arg_local = self.local_decls.push(LocalDecl::with_source_info(ty, source_info));
800803

801804
// If this is a simple binding pattern, give debuginfo a nice name.
@@ -810,8 +813,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
810813
}
811814
}
812815

813-
let tcx = self.hir.tcx();
814-
let tcx_hir = tcx.hir();
815816
let hir_tables = self.hir.tables();
816817

817818
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
@@ -844,7 +845,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
844845
if let Some(Node::Binding(pat)) = tcx_hir.find(var_id) {
845846
if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
846847
name = ident.name;
847-
match hir_tables.extract_binding_mode(tcx.sess, pat.hir_id, pat.span) {
848+
let pat_span = tcx_hir.span(pat.hir_id);
849+
match hir_tables.extract_binding_mode(tcx.sess, pat.hir_id, pat_span) {
848850
Some(ty::BindByValue(hir::Mutability::Mut)) => {
849851
mutability = Mutability::Mut;
850852
}
@@ -887,7 +889,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
887889

888890
// Make sure we drop (parts of) the argument even when not matched on.
889891
self.schedule_drop(
890-
arg_opt.as_ref().map_or(ast_body.span, |arg| arg.pat.span),
892+
arg_opt.as_ref().map_or(ast_body.span, |arg| tcx_hir.span(arg.pat.hir_id)),
891893
argument_scope,
892894
local,
893895
DropKind::Value,

0 commit comments

Comments
 (0)