Skip to content

Commit e6c0698

Browse files
committed
Remove GenericArg::span.
1 parent 96b8564 commit e6c0698

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
266266
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
267267
let first_generic_span = generic_args
268268
.args
269-
.iter()
270-
.map(|a| a.span())
271-
.chain(generic_args.bindings.iter().map(|b| b.span))
272-
.next();
269+
.first()
270+
.map(|a| self.spans[a.id()])
271+
.or_else(|| generic_args.bindings.first().map(|b| b.span));
273272
if !generic_args.parenthesized && !has_lifetimes {
274273
generic_args.args = self
275274
.elided_path_lifetimes(

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,6 @@ pub enum GenericArg<'hir> {
256256
}
257257

258258
impl GenericArg<'_> {
259-
pub fn span(&self) -> Span {
260-
match self {
261-
GenericArg::Lifetime(l) => l.span,
262-
GenericArg::Type(t) => t.span,
263-
GenericArg::Const(c) => c.span,
264-
}
265-
}
266-
267259
pub fn id(&self) -> HirId {
268260
match self {
269261
GenericArg::Lifetime(l) => l.hir_id,

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
638638
// doesn't happen, even in erroneous
639639
// programs. Else we should use delay-span-bug.
640640
span_bug!(
641-
hir_arg.span(),
641+
self.infcx.tcx.hir().span(hir_arg.id()),
642642
"unmatched subst and hir arg: found {:?} vs {:?}",
643643
kind,
644644
hir_arg,

compiler/rustc_typeck/src/astconv/generics.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2727
help: Option<&str>,
2828
) {
2929
let sess = tcx.sess;
30+
let arg_span = tcx.hir().span(arg.id());
3031
let mut err = struct_span_err!(
3132
sess,
32-
arg.span(),
33+
arg_span,
3334
E0747,
3435
"{} provided when a {} was expected",
3536
arg.descr(),
@@ -49,8 +50,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
4950
GenericParamDefKind::Const { .. },
5051
) => {
5152
let suggestions = vec![
52-
(arg.span().shrink_to_lo(), String::from("{ ")),
53-
(arg.span().shrink_to_hi(), String::from(" }")),
53+
(arg_span.shrink_to_lo(), String::from("{ ")),
54+
(arg_span.shrink_to_hi(), String::from(" }")),
5455
];
5556
err.multipart_suggestion(
5657
"if this generic argument was intended as a const parameter, \
@@ -66,7 +67,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
6667
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
6768
if let Ok(snippet) = snippet {
6869
err.span_suggestion(
69-
arg.span(),
70+
arg_span,
7071
"array type provided where a `usize` was expected, try",
7172
format!("{{ {} }}", snippet),
7273
Applicability::MaybeIncorrect,
@@ -450,7 +451,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
450451
let (spans, labels): (Vec<Span>, Vec<String>) = args.args
451452
[offset + permitted..offset + provided]
452453
.iter()
453-
.map(|arg| (arg.span(), format!("unexpected {} argument", arg.short_descr())))
454+
.map(|arg| {
455+
(
456+
tcx.hir().span(arg.id()),
457+
format!("unexpected {} argument", arg.short_descr()),
458+
)
459+
})
454460
.unzip();
455461
unexpected_spans.extend(spans.clone());
456462
(spans, labels)
@@ -553,7 +559,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
553559
.args
554560
.iter()
555561
.filter_map(|arg| match arg {
556-
GenericArg::Type(_) | GenericArg::Const(_) => Some(arg.span()),
562+
GenericArg::Type(_) | GenericArg::Const(_) => Some(tcx.hir().span(arg.id())),
557563
_ => None,
558564
})
559565
.collect::<Vec<_>>();
@@ -599,7 +605,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
599605
let msg = "cannot specify lifetime arguments explicitly \
600606
if late bound lifetime parameters are present";
601607
let note = "the late bound lifetime parameter is introduced here";
602-
let span = args.args[0].span();
608+
let span = tcx.hir().span(args.args[0].id());
603609
if position == GenericArgPosition::Value
604610
&& arg_counts.lifetimes != param_counts.lifetimes
605611
{

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
401401
}
402402
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
403403
if has_default {
404+
let arg_id = arg.id();
404405
tcx.check_optional_stability(
405406
param.def_id,
406-
Some(arg.id()),
407-
arg.span(),
407+
Some(arg_id),
408+
tcx.hir().span(arg_id),
408409
|_, _| {
409410
// Default generic parameters may not be marked
410411
// with stability attributes, i.e. when the

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
129129
.and_then(|args| args.args.iter().last())
130130
// Account for `foo.bar::<T>()`.
131131
.map(|arg| {
132+
let arg_span = tcx.hir().span(arg.id());
132133
// Skip the closing `>`.
133134
tcx.sess
134135
.source_map()
135-
.next_point(tcx.sess.source_map().next_point(arg.span()))
136+
.next_point(tcx.sess.source_map().next_point(arg_span))
136137
})
137138
.unwrap_or(*span),
138139
&args[1..], // Skip the receiver.

0 commit comments

Comments
 (0)