Skip to content

Commit 6ec2356

Browse files
committed
Remove span from hir::GenericParam.
1 parent 32716ae commit 6ec2356

File tree

16 files changed

+97
-67
lines changed

16 files changed

+97
-67
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
874874
hir_id: self.lower_node_id(node_id, span),
875875
name: hir_name,
876876
bounds: &[],
877-
span,
878877
pure_wrt_drop: false,
879878
kind: hir::GenericParamKind::Lifetime { kind },
880879
}
@@ -1497,7 +1496,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14971496
name: ParamName::Plain(ident),
14981497
pure_wrt_drop: false,
14991498
bounds: hir_bounds,
1500-
span,
15011499
kind: hir::GenericParamKind::Type {
15021500
default: None,
15031501
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
@@ -1785,7 +1783,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17851783
self.output_lifetime_params.push(hir::GenericParam {
17861784
hir_id,
17871785
name,
1788-
span: lifetime.span,
17891786
pure_wrt_drop: false,
17901787
bounds: &[],
17911788
kind: hir::GenericParamKind::Lifetime { kind },
@@ -2359,7 +2356,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23592356
hir::GenericParam {
23602357
hir_id,
23612358
name,
2362-
span: param.ident.span,
23632359
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
23642360
bounds: self.arena.alloc_from_iter(bounds),
23652361
kind,

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_macros::HashStable_Generic;
1616
use rustc_span::source_map::{SourceMap, Spanned};
1717
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1818
use rustc_span::{def_id::LocalDefId, BytePos};
19-
use rustc_span::{MultiSpan, Span, DUMMY_SP};
19+
use rustc_span::{Span, DUMMY_SP};
2020
use rustc_target::asm::InlineAsmRegOrRegClass;
2121
use rustc_target::spec::abi::Abi;
2222

@@ -471,7 +471,6 @@ pub struct GenericParam<'hir> {
471471
pub hir_id: HirId,
472472
pub name: ParamName,
473473
pub bounds: GenericBounds<'hir>,
474-
pub span: Span,
475474
pub pure_wrt_drop: bool,
476475
pub kind: GenericParamKind<'hir>,
477476
}
@@ -519,14 +518,6 @@ impl Generics<'hir> {
519518
}
520519
None
521520
}
522-
523-
pub fn spans(&self) -> MultiSpan {
524-
if self.params.is_empty() {
525-
self.span.into()
526-
} else {
527-
self.params.iter().map(|p| p.span).collect::<Vec<Span>>().into()
528-
}
529-
}
530521
}
531522

532523
/// Synthetic type parameters are converted to another form during lowering; this allows

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn msg_span_from_early_bound_and_free_regions(
163163
if let Some(param) =
164164
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
165165
{
166-
sp = param.span;
166+
sp = tcx.hir().span(param.hir_id);
167167
}
168168
(format!("the lifetime `{}` as defined on", br.name), sp)
169169
}
@@ -174,7 +174,7 @@ fn msg_span_from_early_bound_and_free_regions(
174174
if let Some(param) =
175175
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
176176
{
177-
sp = param.span;
177+
sp = tcx.hir().span(param.hir_id);
178178
}
179179
(format!("the lifetime `{}` as defined on", name), sp)
180180
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,8 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14871487
let suggestion = spans
14881488
.iter()
14891489
.map(|sp| {
1490-
let start = param.span.between(*sp); // Include the `:` in `T: Bound`.
1490+
let param_span = cx.tcx.hir().span(param.hir_id);
1491+
let start = param_span.between(*sp); // Include the `:` in `T: Bound`.
14911492
(start.to(*sp), String::new())
14921493
})
14931494
.collect();
@@ -2142,8 +2143,9 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21422143
infer_static,
21432144
);
21442145
bound_count += bound_spans.len();
2146+
let param_span = cx.tcx.hir().span(param.hir_id);
21452147
lint_spans.extend(self.consolidate_outlives_bound_spans(
2146-
param.span.shrink_to_hi(),
2148+
param_span.shrink_to_hi(),
21472149
&param.bounds,
21482150
bound_spans,
21492151
));

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ pub fn suggest_constraining_type_param(
129129

130130
if def_id == tcx.lang_items().sized_trait() {
131131
// Type parameters are already `Sized` by default.
132-
err.span_label(param.span, &format!("this type parameter needs to be `{}`", constraint));
132+
err.span_label(
133+
tcx.hir().span(param.hir_id),
134+
&format!("this type parameter needs to be `{}`", constraint),
135+
);
133136
return true;
134137
}
135138
let mut suggest_restrict = |span| {
@@ -157,7 +160,7 @@ pub fn suggest_constraining_type_param(
157160
// |
158161
// replace with: `impl Foo + Bar`
159162

160-
suggest_restrict(param.span.shrink_to_hi());
163+
suggest_restrict(tcx.hir().span(param.hir_id).shrink_to_hi());
161164
return true;
162165
}
163166

@@ -187,7 +190,7 @@ pub fn suggest_constraining_type_param(
187190
// fn foo<T>(t: T) { ... }
188191
// - help: consider restricting this type parameter with `T: Foo`
189192
err.span_suggestion_verbose(
190-
param.span.shrink_to_hi(),
193+
tcx.hir().span(param.hir_id).shrink_to_hi(),
191194
&msg_restrict_type,
192195
format!(": {}", constraint),
193196
Applicability::MachineApplicable,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,14 +843,15 @@ impl CheckAttrVisitor<'tcx> {
843843
match param.kind {
844844
hir::GenericParamKind::Const { .. } => {}
845845
_ => {
846+
let param_span = self.tcx.hir().span(param.hir_id);
846847
self.tcx
847848
.sess
848849
.struct_span_err(
849850
attr.span,
850851
"#[rustc_legacy_const_generics] functions must \
851852
only have const generics",
852853
)
853-
.span_label(param.span, "non-const generic parameter")
854+
.span_label(param_span, "non-const generic parameter")
854855
.emit();
855856
return false;
856857
}
@@ -1219,7 +1220,8 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
12191220

12201221
fn visit_generic_param(&mut self, generic_param: &'tcx hir::GenericParam<'tcx>) {
12211222
let target = Target::from_generic_param(generic_param);
1222-
self.check_attributes(generic_param.hir_id, &generic_param.span, target, None);
1223+
let span = self.tcx.hir().span(generic_param.hir_id);
1224+
self.check_attributes(generic_param.hir_id, &span, target, None);
12231225
intravisit::walk_generic_param(self, generic_param)
12241226
}
12251227

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
517517
_ => AnnotationKind::Prohibited,
518518
};
519519

520+
let span = self.tcx.hir().span(p.hir_id);
520521
self.annotate(
521522
p.hir_id,
522-
p.span,
523+
span,
523524
kind,
524525
InheritDeprecation::No,
525526
InheritConstStability::No,

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
16701670
}
16711671
)
16721672
}) {
1673-
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
1673+
let span = self.tcx.hir().span(param.hir_id);
1674+
(span.shrink_to_lo(), format!("{}, ", lifetime_ref))
16741675
} else {
16751676
suggests_in_band = true;
16761677
(generics.span, format!("<{}>", lifetime_ref))
@@ -1754,7 +1755,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
17541755
{
17551756
let (span, span_type) = match &trait_ref.bound_generic_params {
17561757
[] => (trait_ref.span.shrink_to_lo(), ForLifetimeSpanType::BoundEmpty),
1757-
[.., bound] => (bound.span.shrink_to_hi(), ForLifetimeSpanType::BoundTail),
1758+
[.., bound] => (
1759+
self.tcx.hir().span(bound.hir_id).shrink_to_hi(),
1760+
ForLifetimeSpanType::BoundTail,
1761+
),
17581762
};
17591763
self.missing_named_lifetime_spots
17601764
.push(MissingLifetimeSpot::HigherRanked { span, span_type });
@@ -1868,7 +1872,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
18681872
}
18691873
)
18701874
}) {
1871-
(param.span.shrink_to_lo(), "'a, ".to_string())
1875+
let span = self.tcx.hir().span(param.hir_id);
1876+
(span.shrink_to_lo(), "'a, ".to_string())
18721877
} else {
18731878
(generics.span, "<'a>".to_string())
18741879
}

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
505505
self.is_in_fn_syntax = true;
506506
let lifetime_span: Option<Span> =
507507
c.generic_params.iter().rev().find_map(|param| match param.kind {
508-
GenericParamKind::Lifetime { .. } => Some(param.span),
508+
GenericParamKind::Lifetime { .. } => {
509+
Some(self.tcx.hir().span(param.hir_id))
510+
}
509511
_ => None,
510512
});
511513
let (span, span_type) = if let Some(span) = lifetime_span {
@@ -1073,8 +1075,9 @@ fn shadower_label(span: Span) -> Shadower {
10731075
fn original_lifetime(span: Span) -> Original {
10741076
Original { kind: ShadowKind::Lifetime, span }
10751077
}
1076-
fn shadower_lifetime(param: &hir::GenericParam<'_>) -> Shadower {
1077-
Shadower { kind: ShadowKind::Lifetime, span: param.span }
1078+
fn shadower_lifetime(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Shadower {
1079+
let span = tcx.hir().span(param.hir_id);
1080+
Shadower { kind: ShadowKind::Lifetime, span }
10781081
}
10791082

10801083
impl ShadowKind {
@@ -1090,7 +1093,7 @@ fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &[hir::Generic
10901093
let lifetime_params: Vec<_> = params
10911094
.iter()
10921095
.filter_map(|param| match param.kind {
1093-
GenericParamKind::Lifetime { kind, .. } => Some((kind, param.span)),
1096+
GenericParamKind::Lifetime { kind, .. } => Some((kind, tcx.hir().span(param.hir_id))),
10941097
_ => None,
10951098
})
10961099
.collect();
@@ -1415,18 +1418,21 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14151418
param.kind,
14161419
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand }
14171420
);
1421+
let param_span = self.tcx.hir().span(param.hir_id);
14181422
if in_band {
1419-
Some(param.span)
1423+
Some(param_span)
14201424
} else if generics.params.len() == 1 {
14211425
// if sole lifetime, remove the entire `<>` brackets
14221426
Some(generics.span)
14231427
} else {
14241428
// if removing within `<>` brackets, we also want to
14251429
// delete a leading or trailing comma as appropriate
14261430
if i >= generics.params.len() - 1 {
1427-
Some(generics.params[i - 1].span.shrink_to_hi().to(param.span))
1431+
let generic_span = self.tcx.hir().span(generics.params[i - 1].hir_id);
1432+
Some(generic_span.shrink_to_hi().to(param_span))
14281433
} else {
1429-
Some(param.span.to(generics.params[i + 1].span.shrink_to_lo()))
1434+
let generic_span = self.tcx.hir().span(generics.params[i + 1].hir_id);
1435+
Some(param_span.to(generic_span.shrink_to_lo()))
14301436
}
14311437
}
14321438
} else {
@@ -1583,7 +1589,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15831589
hir_lifetime.name.ident(),
15841590
)),
15851591
Node::GenericParam(param) => {
1586-
Some((param.hir_id, param.span, param.name.ident()))
1592+
let span = self.tcx.hir().span(param.hir_id);
1593+
Some((param.hir_id, span, param.name.ident()))
15871594
}
15881595
_ => None,
15891596
} {
@@ -1640,7 +1647,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16401647
hir_lifetime.name.ident(),
16411648
)),
16421649
Node::GenericParam(param) => {
1643-
Some((param.hir_id, param.span, param.name.ident()))
1650+
let span = self.tcx.hir().span(param.hir_id);
1651+
Some((param.hir_id, span, param.name.ident()))
16441652
}
16451653
_ => None,
16461654
} {
@@ -2580,33 +2588,33 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25802588
if let hir::ParamName::Plain(_) = lifetime_i_name {
25812589
let name = lifetime_i_name.ident().name;
25822590
if name == kw::UnderscoreLifetime || name == kw::StaticLifetime {
2591+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
25832592
let mut err = struct_span_err!(
25842593
self.tcx.sess,
2585-
lifetime_i.span,
2594+
span_i,
25862595
E0262,
25872596
"invalid lifetime parameter name: `{}`",
25882597
lifetime_i.name.ident(),
25892598
);
2590-
err.span_label(
2591-
lifetime_i.span,
2592-
format!("{} is a reserved lifetime name", name),
2593-
);
2599+
err.span_label(span_i, format!("{} is a reserved lifetime name", name));
25942600
err.emit();
25952601
}
25962602
}
25972603

25982604
// It is a hard error to shadow a lifetime within the same scope.
25992605
for (lifetime_j, lifetime_j_name) in lifetimes.iter().skip(i + 1) {
26002606
if lifetime_i_name == lifetime_j_name {
2607+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
2608+
let span_j = self.tcx.hir().span(lifetime_j.hir_id);
26012609
struct_span_err!(
26022610
self.tcx.sess,
2603-
lifetime_j.span,
2611+
span_j,
26042612
E0263,
26052613
"lifetime name `{}` declared twice in the same scope",
26062614
lifetime_j.name.ident()
26072615
)
2608-
.span_label(lifetime_j.span, "declared twice")
2609-
.span_label(lifetime_i.span, "previous declaration here")
2616+
.span_label(span_j, "declared twice")
2617+
.span_label(span_i, "previous declaration here")
26102618
.emit();
26112619
}
26122620
}
@@ -2623,10 +2631,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26232631
),
26242632
hir::LifetimeName::Static => {
26252633
self.insert_lifetime(lt, Region::Static);
2634+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
26262635
self.tcx
26272636
.sess
26282637
.struct_span_warn(
2629-
lifetime_i.span.to(lt.span),
2638+
span_i.to(lt.span),
26302639
&format!(
26312640
"unnecessary lifetime parameter `{}`",
26322641
lifetime_i.name.ident(),
@@ -2670,7 +2679,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26702679
self.tcx,
26712680
label.name,
26722681
original_label(label.span),
2673-
shadower_lifetime(&param),
2682+
shadower_lifetime(self.tcx, &param),
26742683
);
26752684
return;
26762685
}
@@ -2697,7 +2706,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26972706
self.tcx,
26982707
param.name.ident().name,
26992708
original_lifetime(self.tcx.hir().span(hir_id)),
2700-
shadower_lifetime(&param),
2709+
shadower_lifetime(self.tcx, &param),
27012710
);
27022711
return;
27032712
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17391739
None => return,
17401740
};
17411741
for param in generics.params {
1742-
if param.span != span
1742+
let param_span = self.tcx.hir().span(param.hir_id);
1743+
if param_span != span
17431744
|| param.bounds.iter().any(|bound| {
17441745
bound.trait_ref().and_then(|trait_ref| trait_ref.trait_def_id())
17451746
== self.tcx.lang_items().sized_trait()
@@ -1769,9 +1770,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17691770
};
17701771
visitor.visit_item(item);
17711772
if !visitor.invalid_spans.is_empty() {
1772-
let mut multispan: MultiSpan = param.span.into();
1773+
let mut multispan: MultiSpan = param_span.into();
17731774
multispan.push_span_label(
1774-
param.span,
1775+
param_span,
17751776
format!("this could be changed to `{}: ?Sized`...", param.name.ident()),
17761777
);
17771778
for sp in visitor.invalid_spans {

0 commit comments

Comments
 (0)