Skip to content

Commit 415ad17

Browse files
committed
Remove GenericArg::span.
1 parent 44a58d4 commit 415ad17

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

src/librustc_ast_lowering/path.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
});
269269
let first_generic_span = generic_args
270270
.args
271-
.iter()
272-
.map(|a| a.span())
273-
.chain(generic_args.bindings.iter().map(|b| b.span))
274-
.next();
271+
.first()
272+
.map(|a| self.spans[a.id()])
273+
.or_else(|| generic_args.bindings.first().map(|b| b.span));
275274
if !generic_args.parenthesized && !has_lifetimes {
276275
generic_args.args = self
277276
.elided_path_lifetimes(

src/librustc_hir/hir.rs

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

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

src/librustc_mir/borrow_check/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
581581
// doesn't happen, even in erroneous
582582
// programs. Else we should use delay-span-bug.
583583
span_bug!(
584-
hir_arg.span(),
584+
self.infcx.tcx.hir().span(hir_arg.id()),
585585
"unmatched subst and hir arg: found {:?} vs {:?}",
586586
kind,
587587
hir_arg,

src/librustc_typeck/astconv.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_middle::ty::{
2626
use rustc_middle::ty::{GenericParamDef, GenericParamDefKind};
2727
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, LATE_BOUND_LIFETIME_ARGUMENTS};
2828
use rustc_session::parse::feature_err;
29-
use rustc_session::Session;
3029
use rustc_span::symbol::{sym, Ident, Symbol};
3130
use rustc_span::{MultiSpan, Span, DUMMY_SP};
3231
use rustc_target::spec::abi;
@@ -260,12 +259,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
260259
});
261260

262261
if explicit && impl_trait {
262+
let hir = tcx.hir();
263263
let spans = seg
264264
.generic_args()
265265
.args
266266
.iter()
267267
.filter_map(|arg| match arg {
268-
GenericArg::Type(_) => Some(arg.span()),
268+
GenericArg::Type(_) => Some(hir.span(arg.id())),
269269
_ => None,
270270
})
271271
.collect::<Vec<_>>();
@@ -388,7 +388,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
388388
// we want to point to the unexpected arguments.
389389
let spans: Vec<Span> = args.args[offset + permitted..offset + provided]
390390
.iter()
391-
.map(|arg| arg.span())
391+
.map(|arg| tcx.hir().span(arg.id()))
392392
.collect();
393393
unexpected_spans.extend(spans.clone());
394394
(spans, format!("unexpected {} argument", kind))
@@ -475,10 +475,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
475475

476476
/// Report an error that a generic argument did not match the generic parameter that was
477477
/// expected.
478-
fn generic_arg_mismatch_err(sess: &Session, arg: &GenericArg<'_>, kind: &'static str) {
478+
fn generic_arg_mismatch_err(tcx: TyCtxt<'_>, arg: &GenericArg<'_>, kind: &'static str) {
479479
let mut err = struct_span_err!(
480-
sess,
481-
arg.span(),
480+
tcx.sess,
481+
tcx.hir().span(arg.id()),
482482
E0747,
483483
"{} provided when a {} was expected",
484484
arg.descr(),
@@ -648,7 +648,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
648648
if arg_count.correct.is_ok()
649649
&& arg_count.explicit_late_bound == ExplicitLateBound::No
650650
{
651-
Self::generic_arg_mismatch_err(tcx.sess, arg, kind.descr());
651+
Self::generic_arg_mismatch_err(tcx, arg, kind.descr());
652652
}
653653

654654
// We've reported the error, but we want to make sure that this
@@ -680,7 +680,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
680680
assert_eq!(kind, "lifetime");
681681
let provided =
682682
force_infer_lt.expect("lifetimes ought to have been inferred");
683-
Self::generic_arg_mismatch_err(tcx.sess, provided, kind);
683+
Self::generic_arg_mismatch_err(tcx, provided, kind);
684684
}
685685

686686
break;
@@ -2539,7 +2539,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25392539
let msg = "cannot specify lifetime arguments explicitly \
25402540
if late bound lifetime parameters are present";
25412541
let note = "the late bound lifetime parameter is introduced here";
2542-
let span = args.args[0].span();
2542+
let span = tcx.hir().span(args.args[0].id());
25432543
if position == GenericArgPosition::Value
25442544
&& arg_counts.lifetimes != param_counts.lifetimes
25452545
{

src/librustc_typeck/check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,9 +3943,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
39433943
// Account for `foo.bar::<T>()`.
39443944
.map(|arg| {
39453945
// Skip the closing `>`.
3946-
tcx.sess
3947-
.source_map()
3948-
.next_point(tcx.sess.source_map().next_point(arg.span()))
3946+
tcx.sess.source_map().next_point(
3947+
tcx.sess.source_map().next_point(tcx.hir().span(arg.id())),
3948+
)
39493949
})
39503950
.unwrap_or(*span),
39513951
&args[1..], // Skip the receiver.

0 commit comments

Comments
 (0)