Skip to content

Commit e14eae6

Browse files
committed
Remove subst_spanned
1 parent f9b2e3c commit e14eae6

File tree

3 files changed

+14
-53
lines changed

3 files changed

+14
-53
lines changed

compiler/rustc_middle/src/ty/subst.rs

+10-38
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::intern::{Interned, WithStableHash};
1010
use rustc_hir::def_id::DefId;
1111
use rustc_macros::HashStable;
1212
use rustc_serialize::{self, Decodable, Encodable};
13-
use rustc_span::{Span, DUMMY_SP};
13+
use rustc_span::DUMMY_SP;
1414
use smallvec::SmallVec;
1515

1616
use core::intrinsics;
@@ -498,34 +498,14 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
498498
}
499499
}
500500

501-
///////////////////////////////////////////////////////////////////////////
502-
// Public trait `Subst`
503-
//
504-
// Just call `foo.subst(tcx, substs)` to perform a substitution across
505-
// `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when
506-
// there is more information available (for better errors).
507-
501+
// Just call `foo.subst(tcx, substs)` to perform a substitution across `foo`.
508502
pub trait Subst<'tcx>: Sized {
509-
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self {
510-
self.subst_spanned(tcx, substs, None)
511-
}
512-
513-
fn subst_spanned(
514-
self,
515-
tcx: TyCtxt<'tcx>,
516-
substs: &[GenericArg<'tcx>],
517-
span: Option<Span>,
518-
) -> Self;
503+
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self;
519504
}
520505

521506
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
522-
fn subst_spanned(
523-
self,
524-
tcx: TyCtxt<'tcx>,
525-
substs: &[GenericArg<'tcx>],
526-
span: Option<Span>,
527-
) -> T {
528-
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
507+
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> T {
508+
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
529509
self.fold_with(&mut folder)
530510
}
531511
}
@@ -537,9 +517,6 @@ struct SubstFolder<'a, 'tcx> {
537517
tcx: TyCtxt<'tcx>,
538518
substs: &'a [GenericArg<'tcx>],
539519

540-
/// The location for which the substitution is performed, if available.
541-
span: Option<Span>,
542-
543520
/// Number of region binders we have passed through while doing the substitution
544521
binders_passed: u32,
545522
}
@@ -571,13 +548,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
571548
match rk {
572549
Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
573550
_ => {
574-
let span = self.span.unwrap_or(DUMMY_SP);
575551
let msg = format!(
576552
"Region parameter out of range \
577553
when substituting in region {} (index={})",
578554
data.name, data.index
579555
);
580-
span_bug!(span, "{}", msg);
556+
span_bug!(DUMMY_SP, "{}", msg);
581557
}
582558
}
583559
}
@@ -617,9 +593,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
617593
let ty = match opt_ty {
618594
Some(GenericArgKind::Type(ty)) => ty,
619595
Some(kind) => {
620-
let span = self.span.unwrap_or(DUMMY_SP);
621596
span_bug!(
622-
span,
597+
DUMMY_SP,
623598
"expected type for `{:?}` ({:?}/{}) but found {:?} \
624599
when substituting, substs={:?}",
625600
p,
@@ -630,9 +605,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
630605
);
631606
}
632607
None => {
633-
let span = self.span.unwrap_or(DUMMY_SP);
634608
span_bug!(
635-
span,
609+
DUMMY_SP,
636610
"type parameter `{:?}` ({:?}/{}) out of range \
637611
when substituting, substs={:?}",
638612
p,
@@ -652,9 +626,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
652626
let ct = match opt_ct {
653627
Some(GenericArgKind::Const(ct)) => ct,
654628
Some(kind) => {
655-
let span = self.span.unwrap_or(DUMMY_SP);
656629
span_bug!(
657-
span,
630+
DUMMY_SP,
658631
"expected const for `{:?}` ({:?}/{}) but found {:?} \
659632
when substituting substs={:?}",
660633
p,
@@ -665,9 +638,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
665638
);
666639
}
667640
None => {
668-
let span = self.span.unwrap_or(DUMMY_SP);
669641
span_bug!(
670-
span,
642+
DUMMY_SP,
671643
"const parameter `{:?}` ({:?}/{}) out of range \
672644
when substituting substs={:?}",
673645
p,

compiler/rustc_typeck/src/astconv/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
523523
self.astconv
524524
.normalize_ty(
525525
self.span,
526-
tcx.at(self.span).type_of(param.def_id).subst_spanned(
527-
tcx,
528-
substs,
529-
Some(self.span),
530-
),
526+
tcx.at(self.span).type_of(param.def_id).subst(tcx, substs),
531527
)
532528
.into()
533529
}
@@ -547,9 +543,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
547543
GenericParamDefKind::Const { has_default } => {
548544
let ty = tcx.at(self.span).type_of(param.def_id);
549545
if !infer_args && has_default {
550-
tcx.const_param_default(param.def_id)
551-
.subst_spanned(tcx, substs.unwrap(), Some(self.span))
552-
.into()
546+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
553547
} else {
554548
if infer_args {
555549
self.astconv.ct_infer(ty, Some(param), self.span).into()

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031403
// is missing.
14041404
let default = tcx.type_of(param.def_id);
14051405
self.fcx
1406-
.normalize_ty(
1407-
self.span,
1408-
default.subst_spanned(tcx, substs.unwrap(), Some(self.span)),
1409-
)
1406+
.normalize_ty(self.span, default.subst(tcx, substs.unwrap()))
14101407
.into()
14111408
} else {
14121409
// If no type arguments were provided, we have to infer them.
@@ -1418,9 +1415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14181415
}
14191416
GenericParamDefKind::Const { has_default } => {
14201417
if !infer_args && has_default {
1421-
tcx.const_param_default(param.def_id)
1422-
.subst_spanned(tcx, substs.unwrap(), Some(self.span))
1423-
.into()
1418+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
14241419
} else {
14251420
self.fcx.var_for_def(self.span, param)
14261421
}

0 commit comments

Comments
 (0)