Skip to content

Commit f51da1e

Browse files
committed
Remove span from hir::Pat.
1 parent 3cf2fba commit f51da1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+309
-241
lines changed

compiler/rustc_ast_lowering/src/item.rs

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

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

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26562656
self.arena.alloc(hir::Pat {
26572657
hir_id,
26582658
kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
2659-
span,
26602659
default_binding_modes: true,
26612660
}),
26622661
hir_id,
@@ -2668,19 +2667,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26682667
}
26692668

26702669
fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2671-
self.arena.alloc(hir::Pat {
2672-
hir_id: self.next_id(span),
2673-
kind,
2674-
span,
2675-
default_binding_modes: true,
2676-
})
2670+
self.arena.alloc(hir::Pat { hir_id: self.next_id(span), kind, default_binding_modes: true })
26772671
}
26782672

26792673
fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
26802674
self.arena.alloc(hir::Pat {
26812675
hir_id: self.next_id(span),
26822676
kind,
2683-
span,
26842677
default_binding_modes: false,
26852678
})
26862679
}

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
275275
self.arena.alloc(hir::Pat {
276276
hir_id: self.lower_node_id(p.id, p.span),
277277
kind,
278-
span: p.span,
279278
default_binding_modes: true,
280279
})
281280
}

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,6 @@ pub struct Pat<'hir> {
798798
#[stable_hasher(ignore)]
799799
pub hir_id: HirId,
800800
pub kind: PatKind<'hir>,
801-
pub span: Span,
802801
// Whether to use default binding modes.
803802
// At present, this is false only for destructuring assignment.
804803
pub default_binding_modes: bool,
@@ -3056,7 +3055,7 @@ impl<'hir> Node<'hir> {
30563055
mod size_asserts {
30573056
rustc_data_structures::static_assert_size!(super::Block<'static>, 40);
30583057
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
3059-
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
3058+
rustc_data_structures::static_assert_size!(super::Pat<'static>, 80);
30603059
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
30613060
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
30623061

compiler/rustc_hir/src/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

@@ -60,10 +59,10 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
6059
impl hir::Pat<'_> {
6160
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
6261
/// `match foo() { Some(a) => (), None => () }`
63-
pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Span, Ident)) {
62+
pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Ident)) {
6463
self.walk_always(|p| {
6564
if let PatKind::Binding(binding_mode, _, ident, _) = p.kind {
66-
f(binding_mode, p.hir_id, p.span, ident);
65+
f(binding_mode, p.hir_id, ident);
6766
}
6867
});
6968
}
@@ -72,17 +71,14 @@ impl hir::Pat<'_> {
7271
/// `match foo() { Some(a) => (), None => () }`.
7372
///
7473
/// When encountering an or-pattern `p_0 | ... | p_n` only `p_0` will be visited.
75-
pub fn each_binding_or_first(
76-
&self,
77-
f: &mut impl FnMut(hir::BindingAnnotation, HirId, Span, Ident),
78-
) {
74+
pub fn each_binding_or_first(&self, f: &mut impl FnMut(hir::BindingAnnotation, HirId, Ident)) {
7975
self.walk(|p| match &p.kind {
8076
PatKind::Or(ps) => {
8177
ps[0].each_binding_or_first(f);
8278
false
8379
}
8480
PatKind::Binding(bm, _, ident, _) => {
85-
f(*bm, p.hir_id, p.span, *ident);
81+
f(*bm, p.hir_id, *ident);
8682
true
8783
}
8884
_ => true,
@@ -150,7 +146,7 @@ impl hir::Pat<'_> {
150146
// ref bindings are be implicit after #42640 (default match binding modes). See issue #44848.
151147
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
152148
let mut result = None;
153-
self.each_binding(|annotation, _, _, _| match annotation {
149+
self.each_binding(|annotation, _, _| match annotation {
154150
hir::BindingAnnotation::Ref => match result {
155151
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
156152
_ => {}

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,29 @@ impl<'a> State<'a> {
341341
pub fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
342342
where
343343
F: FnMut(&mut State<'_>, &T),
344-
G: FnMut(&T) -> rustc_span::Span,
344+
G: FnMut(&State<'_>, &T) -> rustc_span::Span,
345345
{
346346
self.rbox(0, b);
347347
let len = elts.len();
348348
let mut i = 0;
349349
for elt in elts {
350-
self.maybe_print_comment(get_span(elt).hi());
350+
self.maybe_print_comment(get_span(self, elt).hi());
351351
op(self, elt);
352352
i += 1;
353353
if i < len {
354354
self.s.word(",");
355-
self.maybe_print_trailing_comment(get_span(elt), Some(get_span(&elts[i]).hi()));
355+
self.maybe_print_trailing_comment(
356+
get_span(self, elt),
357+
Some(get_span(self, &elts[i]).hi()),
358+
);
356359
self.space_if_not_bol();
357360
}
358361
}
359362
self.end();
360363
}
361364

362365
pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[hir::Expr<'_>]) {
363-
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
366+
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |_, e| e.span)
364367
}
365368

366369
pub fn print_mod(&mut self, _mod: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
@@ -1237,7 +1240,7 @@ impl<'a> State<'a> {
12371240
s.print_expr(&field.expr);
12381241
s.end()
12391242
},
1240-
|f| f.span,
1243+
|_, f| f.span,
12411244
);
12421245
match *wth {
12431246
Some(ref expr) => {
@@ -1887,7 +1890,8 @@ impl<'a> State<'a> {
18871890
}
18881891

18891892
pub fn print_pat(&mut self, pat: &hir::Pat<'_>) {
1890-
self.maybe_print_comment(pat.span.lo());
1893+
let span = self.span(pat.hir_id);
1894+
self.maybe_print_comment(span.lo());
18911895
self.ann.pre(self, AnnNode::Pat(pat));
18921896
// Pat isn't normalized, but the beauty of it
18931897
// is that it doesn't matter
@@ -1951,7 +1955,7 @@ impl<'a> State<'a> {
19511955
s.print_pat(&f.pat);
19521956
s.end()
19531957
},
1954-
|f| f.pat.span,
1958+
|s, f| s.span(f.pat.hir_id),
19551959
);
19561960
if etc {
19571961
if !fields.is_empty() {

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
464464
local_visitor.visit_expr(expr);
465465
}
466466
let err_span = if let Some(pattern) = local_visitor.found_arg_pattern {
467-
pattern.span
467+
self.tcx.hir().span(pattern.hir_id)
468468
} else if let Some(span) = arg_data.span {
469469
// `span` here lets us point at `sum` instead of the entire right hand side expr:
470470
// error[E0282]: type annotations needed
@@ -637,12 +637,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
637637
// with the type parameter `_` specified
638638
// ```
639639
err.span_label(
640-
pattern.span,
640+
self.tcx.hir().span(pattern.hir_id),
641641
format!("consider giving this closure parameter {}", suffix),
642642
);
643643
} else if let Some(pattern) = local_visitor.found_local_pattern {
644+
let pattern_span = self.tcx.hir().span(pattern.hir_id);
644645
let msg = if let Some(simple_ident) = pattern.simple_ident() {
645-
match pattern.span.desugaring_kind() {
646+
match pattern_span.desugaring_kind() {
646647
None => format!("consider giving `{}` {}", simple_ident, suffix),
647648
Some(DesugaringKind::ForLoop(_)) => {
648649
"the element type for this iterator is not specified".to_string()
@@ -652,7 +653,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
652653
} else {
653654
format!("consider giving this pattern {}", suffix)
654655
};
655-
err.span_label(pattern.span, msg);
656+
err.span_label(pattern_span, msg);
656657
} else if let Some(e) = local_visitor.found_method_call {
657658
if let ExprKind::MethodCall(segment, _, exprs, _) = &e.kind {
658659
// Suggest impl candidates:

compiler/rustc_mir_build/src/build/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
858858
argument_scope: region::Scope,
859859
expr: &Expr<'_, 'tcx>,
860860
) -> BlockAnd<()> {
861+
let tcx = self.tcx;
862+
let tcx_hir = tcx.hir();
863+
let hir_typeck_results = self.typeck_results;
864+
861865
// Allocate locals for the function arguments
862866
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
863-
let source_info =
864-
SourceInfo::outermost(arg_opt.map_or(self.fn_span, |arg| arg.pat.span));
867+
let source_info = SourceInfo::outermost(
868+
arg_opt.map_or(self.fn_span, |arg| tcx_hir.span(arg.pat.hir_id)),
869+
);
865870
let arg_local = self.local_decls.push(LocalDecl::with_source_info(ty, source_info));
866871

867872
// If this is a simple binding pattern, give debuginfo a nice name.
@@ -876,10 +881,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
876881
}
877882
}
878883

879-
let tcx = self.tcx;
880-
let tcx_hir = tcx.hir();
881-
let hir_typeck_results = self.typeck_results;
882-
883884
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
884885
// indexed closure and we stored in a map called closure_captures in TypeckResults
885886
// with the closure's DefId. Here, we run through that vec of UpvarIds for
@@ -954,7 +955,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
954955

955956
// Make sure we drop (parts of) the argument even when not matched on.
956957
self.schedule_drop(
957-
arg_opt.as_ref().map_or(expr.span, |arg| arg.pat.span),
958+
arg_opt.as_ref().map_or(expr.span, |arg| tcx_hir.span(arg.pat.hir_id)),
958959
argument_scope,
959960
local,
960961
DropKind::Value,

0 commit comments

Comments
 (0)