Skip to content

Commit 7584102

Browse files
committed
Remove span from hir::GenericParam.
1 parent deec340 commit 7584102

File tree

16 files changed

+92
-64
lines changed

16 files changed

+92
-64
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
839839
name: hir_name,
840840
attrs: &[],
841841
bounds: &[],
842-
span,
843842
pure_wrt_drop: false,
844843
kind: hir::GenericParamKind::Lifetime { kind },
845844
}
@@ -1379,7 +1378,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13791378
pure_wrt_drop: false,
13801379
attrs: &[],
13811380
bounds: hir_bounds,
1382-
span,
13831381
kind: hir::GenericParamKind::Type {
13841382
default: None,
13851383
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
@@ -1671,7 +1669,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16711669
self.output_lifetime_params.push(hir::GenericParam {
16721670
hir_id,
16731671
name,
1674-
span: lifetime.span,
16751672
pure_wrt_drop: false,
16761673
attrs: &[],
16771674
bounds: &[],
@@ -2248,7 +2245,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22482245
hir::GenericParam {
22492246
hir_id: self.lower_node_id(param.id, param.ident.span),
22502247
name,
2251-
span: param.ident.span,
22522248
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
22532249
attrs: self.lower_attrs(&param.attrs),
22542250
bounds: self.arena.alloc_from_iter(bounds),

src/librustc_hir/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::def_id::LocalDefId;
1717
use rustc_span::source_map::{SourceMap, Spanned};
1818
use rustc_span::symbol::{kw, sym, Ident, Symbol};
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

@@ -425,7 +425,6 @@ pub struct GenericParam<'hir> {
425425
pub name: ParamName,
426426
pub attrs: &'hir [Attribute],
427427
pub bounds: GenericBounds<'hir>,
428-
pub span: Span,
429428
pub pure_wrt_drop: bool,
430429
pub kind: GenericParamKind<'hir>,
431430
}
@@ -490,14 +489,6 @@ impl Generics<'hir> {
490489
}
491490
None
492491
}
493-
494-
pub fn spans(&self) -> MultiSpan {
495-
if self.params.is_empty() {
496-
self.span.into()
497-
} else {
498-
self.params.iter().map(|p| p.span).collect::<Vec<Span>>().into()
499-
}
500-
}
501492
}
502493

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

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn msg_span_from_early_bound_and_free_regions(
158158
if let Some(param) =
159159
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
160160
{
161-
sp = param.span;
161+
sp = tcx.hir().span(param.hir_id);
162162
}
163163
(format!("the lifetime `{}` as defined on", br.name), sp)
164164
}
@@ -167,7 +167,7 @@ fn msg_span_from_early_bound_and_free_regions(
167167
if let Some(param) =
168168
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
169169
{
170-
sp = param.span;
170+
sp = tcx.hir().span(param.hir_id);
171171
}
172172
(format!("the lifetime `{}` as defined on", name), sp)
173173
}

src/librustc_lint/builtin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11441144
let suggestion = spans
11451145
.iter()
11461146
.map(|sp| {
1147-
let start = param.span.between(*sp); // Include the `:` in `T: Bound`.
1147+
let param_span = cx.tcx.hir().span(param.hir_id);
1148+
let start = param_span.between(*sp); // Include the `:` in `T: Bound`.
11481149
(start.to(*sp), String::new())
11491150
})
11501151
.collect();
@@ -1684,8 +1685,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
16841685
infer_static,
16851686
);
16861687
bound_count += bound_spans.len();
1688+
let param_span = cx.tcx.hir().span(param.hir_id);
16871689
lint_spans.extend(self.consolidate_outlives_bound_spans(
1688-
param.span.shrink_to_hi(),
1690+
param_span.shrink_to_hi(),
16891691
&param.bounds,
16901692
bound_spans,
16911693
));

src/librustc_middle/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
371371
}
372372

373373
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
374-
self.insert(param.span, param.hir_id, Node::GenericParam(param));
374+
self.insert(DUMMY_SP, param.hir_id, Node::GenericParam(param));
375375
intravisit::walk_generic_param(self, param);
376376
}
377377

src/librustc_middle/ty/diagnostics.rs

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

9797
if def_id == tcx.lang_items().sized_trait() {
9898
// Type parameters are already `Sized` by default.
99-
err.span_label(param.span, &format!("this type parameter needs to be `{}`", constraint));
99+
err.span_label(
100+
tcx.hir().span(param.hir_id),
101+
&format!("this type parameter needs to be `{}`", constraint),
102+
);
100103
return true;
101104
}
102105
let mut suggest_restrict = |span| {
@@ -124,7 +127,7 @@ pub fn suggest_constraining_type_param(
124127
// |
125128
// replace with: `impl Foo + Bar`
126129

127-
suggest_restrict(param.span.shrink_to_hi());
130+
suggest_restrict(tcx.hir().span(param.hir_id).shrink_to_hi());
128131
return true;
129132
}
130133

@@ -154,7 +157,7 @@ pub fn suggest_constraining_type_param(
154157
// fn foo<T>(t: T) { ... }
155158
// - help: consider restricting this type parameter with `T: Foo`
156159
err.span_suggestion_verbose(
157-
param.span.shrink_to_hi(),
160+
tcx.hir().span(param.hir_id).shrink_to_hi(),
158161
&msg_restrict_type,
159162
format!(": {}", constraint),
160163
Applicability::MachineApplicable,

src/librustc_resolve/late/diagnostics.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10291029
} => false,
10301030
_ => true,
10311031
}) {
1032-
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
1032+
let span = self.tcx.hir().span(param.hir_id);
1033+
(span.shrink_to_lo(), format!("{}, ", lifetime_ref))
10331034
} else {
10341035
(generics.span, format!("<{}>", lifetime_ref))
10351036
};
@@ -1072,7 +1073,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10721073
{
10731074
let (span, span_type) = match &trait_ref.bound_generic_params {
10741075
[] => (trait_ref.span.shrink_to_lo(), ForLifetimeSpanType::BoundEmpty),
1075-
[.., bound] => (bound.span.shrink_to_hi(), ForLifetimeSpanType::BoundTail),
1076+
[.., bound] => (
1077+
self.tcx.hir().span(bound.hir_id).shrink_to_hi(),
1078+
ForLifetimeSpanType::BoundTail,
1079+
),
10761080
};
10771081
self.missing_named_lifetime_spots
10781082
.push(MissingLifetimeSpot::HigherRanked { span, span_type });
@@ -1125,7 +1129,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11251129
} => false,
11261130
_ => true,
11271131
}) {
1128-
(param.span.shrink_to_lo(), "'a, ".to_string())
1132+
let span = self.tcx.hir().span(param.hir_id);
1133+
(span.shrink_to_lo(), "'a, ".to_string())
11291134
} else {
11301135
(generics.span, "<'a>".to_string())
11311136
}

src/librustc_resolve/late/lifetimes.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
481481
self.is_in_fn_syntax = true;
482482
let lifetime_span: Option<Span> =
483483
c.generic_params.iter().rev().find_map(|param| match param.kind {
484-
GenericParamKind::Lifetime { .. } => Some(param.span),
484+
GenericParamKind::Lifetime { .. } => {
485+
Some(self.tcx.hir().span(param.hir_id))
486+
}
485487
_ => None,
486488
});
487489
let (span, span_type) = if let Some(span) = lifetime_span {
@@ -1004,8 +1006,9 @@ fn shadower_label(span: Span) -> Shadower {
10041006
fn original_lifetime(span: Span) -> Original {
10051007
Original { kind: ShadowKind::Lifetime, span }
10061008
}
1007-
fn shadower_lifetime(param: &hir::GenericParam<'_>) -> Shadower {
1008-
Shadower { kind: ShadowKind::Lifetime, span: param.span }
1009+
fn shadower_lifetime(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Shadower {
1010+
let span = tcx.hir().span(param.hir_id);
1011+
Shadower { kind: ShadowKind::Lifetime, span }
10091012
}
10101013

10111014
impl ShadowKind {
@@ -1021,7 +1024,7 @@ fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &[hir::Generic
10211024
let lifetime_params: Vec<_> = params
10221025
.iter()
10231026
.filter_map(|param| match param.kind {
1024-
GenericParamKind::Lifetime { kind, .. } => Some((kind, param.span)),
1027+
GenericParamKind::Lifetime { kind, .. } => Some((kind, tcx.hir().span(param.hir_id))),
10251028
_ => None,
10261029
})
10271030
.collect();
@@ -1342,8 +1345,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13421345
in_band = true;
13431346
}
13441347
}
1348+
let param_span = self.tcx.hir().span(param.hir_id);
13451349
if in_band {
1346-
Some(param.span)
1350+
Some(param_span)
13471351
} else {
13481352
if generics.params.len() == 1 {
13491353
// if sole lifetime, remove the entire `<>` brackets
@@ -1352,9 +1356,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13521356
// if removing within `<>` brackets, we also want to
13531357
// delete a leading or trailing comma as appropriate
13541358
if i >= generics.params.len() - 1 {
1355-
Some(generics.params[i - 1].span.shrink_to_hi().to(param.span))
1359+
let other_span = self.tcx.hir().span(generics.params[i - 1].hir_id);
1360+
Some(other_span.shrink_to_hi().to(param_span))
13561361
} else {
1357-
Some(param.span.to(generics.params[i + 1].span.shrink_to_lo()))
1362+
let other_span = self.tcx.hir().span(generics.params[i + 1].hir_id);
1363+
Some(param_span.to(other_span.shrink_to_lo()))
13581364
}
13591365
}
13601366
}
@@ -1513,7 +1519,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15131519
hir_lifetime.name.ident(),
15141520
)),
15151521
Node::GenericParam(param) => {
1516-
Some((param.hir_id, param.span, param.name.ident()))
1522+
let span = self.tcx.hir().span(param.hir_id);
1523+
Some((param.hir_id, span, param.name.ident()))
15171524
}
15181525
_ => None,
15191526
} {
@@ -1574,7 +1581,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15741581
hir_lifetime.name.ident(),
15751582
)),
15761583
Node::GenericParam(param) => {
1577-
Some((param.hir_id, param.span, param.name.ident()))
1584+
let span = self.tcx.hir().span(param.hir_id);
1585+
Some((param.hir_id, span, param.name.ident()))
15781586
}
15791587
_ => None,
15801588
} {
@@ -2494,33 +2502,33 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
24942502
if let hir::ParamName::Plain(_) = lifetime_i_name {
24952503
let name = lifetime_i_name.ident().name;
24962504
if name == kw::UnderscoreLifetime || name == kw::StaticLifetime {
2505+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
24972506
let mut err = struct_span_err!(
24982507
self.tcx.sess,
2499-
lifetime_i.span,
2508+
span_i,
25002509
E0262,
25012510
"invalid lifetime parameter name: `{}`",
25022511
lifetime_i.name.ident(),
25032512
);
2504-
err.span_label(
2505-
lifetime_i.span,
2506-
format!("{} is a reserved lifetime name", name),
2507-
);
2513+
err.span_label(span_i, format!("{} is a reserved lifetime name", name));
25082514
err.emit();
25092515
}
25102516
}
25112517

25122518
// It is a hard error to shadow a lifetime within the same scope.
25132519
for (lifetime_j, lifetime_j_name) in lifetimes.iter().skip(i + 1) {
25142520
if lifetime_i_name == lifetime_j_name {
2521+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
2522+
let span_j = self.tcx.hir().span(lifetime_j.hir_id);
25152523
struct_span_err!(
25162524
self.tcx.sess,
2517-
lifetime_j.span,
2525+
span_j,
25182526
E0263,
25192527
"lifetime name `{}` declared twice in the same scope",
25202528
lifetime_j.name.ident()
25212529
)
2522-
.span_label(lifetime_j.span, "declared twice")
2523-
.span_label(lifetime_i.span, "previous declaration here")
2530+
.span_label(span_j, "declared twice")
2531+
.span_label(span_i, "previous declaration here")
25242532
.emit();
25252533
}
25262534
}
@@ -2537,10 +2545,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25372545
),
25382546
hir::LifetimeName::Static => {
25392547
self.insert_lifetime(lt, Region::Static);
2548+
let span_i = self.tcx.hir().span(lifetime_i.hir_id);
25402549
self.tcx
25412550
.sess
25422551
.struct_span_warn(
2543-
lifetime_i.span.to(lt.span),
2552+
span_i.to(lt.span),
25442553
&format!(
25452554
"unnecessary lifetime parameter `{}`",
25462555
lifetime_i.name.ident(),
@@ -2584,7 +2593,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25842593
self.tcx,
25852594
label.name,
25862595
original_label(label.span),
2587-
shadower_lifetime(&param),
2596+
shadower_lifetime(self.tcx, &param),
25882597
);
25892598
return;
25902599
}
@@ -2611,7 +2620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26112620
self.tcx,
26122621
param.name.ident().name,
26132622
original_lifetime(self.tcx.hir().span(hir_id)),
2614-
shadower_lifetime(&param),
2623+
shadower_lifetime(self.tcx, &param),
26152624
);
26162625
return;
26172626
}

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17181718
None => return,
17191719
};
17201720
for param in generics.params {
1721-
if param.span != *span
1721+
let param_span = self.tcx.hir().span(param.hir_id);
1722+
if param_span != *span
17221723
|| param.bounds.iter().any(|bound| {
17231724
bound.trait_ref().and_then(|trait_ref| trait_ref.trait_def_id())
17241725
== self.tcx.lang_items().sized_trait()
@@ -1748,9 +1749,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17481749
};
17491750
visitor.visit_item(item);
17501751
if !visitor.invalid_spans.is_empty() {
1751-
let mut multispan: MultiSpan = param.span.into();
1752+
let mut multispan: MultiSpan = param_span.into();
17521753
multispan.push_span_label(
1753-
param.span,
1754+
param_span,
17541755
format!("this could be changed to `{}: ?Sized`...", param.name.ident()),
17551756
);
17561757
for sp in visitor.invalid_spans {

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn suggest_restriction(
274274
// `fn foo<A>(t: impl Trait)`
275275
// ^^^ suggest `<A, T: Trait>` here
276276
Some(param) => (
277-
param.bounds_span().unwrap_or(param.span).shrink_to_hi(),
277+
param.bounds_span().unwrap_or(tcx.hir().span(param.hir_id)).shrink_to_hi(),
278278
format!(", {}", type_param),
279279
),
280280
},

0 commit comments

Comments
 (0)