Skip to content

Commit d08eb98

Browse files
committed
Auto merge of #75133 - nnethercote:rm-SubstFolder-fields, r=matthewjasper
Remove two fields from `SubstFolder`. They're only used in error messages printed if there's an internal compiler error, and the cost of maintaining them is high enough to show up in profiles. r? @matthewjasper
2 parents 5f6bd6e + eeb4b83 commit d08eb98

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

src/librustc_middle/ty/subst.rs

+6-31
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
425425
substs: &[GenericArg<'tcx>],
426426
span: Option<Span>,
427427
) -> T {
428-
let mut folder =
429-
SubstFolder { tcx, substs, span, root_ty: None, ty_stack_depth: 0, binders_passed: 0 };
428+
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
430429
(*self).fold_with(&mut folder)
431430
}
432431
}
@@ -441,12 +440,6 @@ struct SubstFolder<'a, 'tcx> {
441440
/// The location for which the substitution is performed, if available.
442441
span: Option<Span>,
443442

444-
/// The root type that is being substituted, if available.
445-
root_ty: Option<Ty<'tcx>>,
446-
447-
/// Depth of type stack
448-
ty_stack_depth: usize,
449-
450443
/// Number of region binders we have passed through while doing the substitution
451444
binders_passed: u32,
452445
}
@@ -478,9 +471,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
478471
let span = self.span.unwrap_or(DUMMY_SP);
479472
let msg = format!(
480473
"Region parameter out of range \
481-
when substituting in region {} (root type={:?}) \
482-
(index={})",
483-
data.name, self.root_ty, data.index
474+
when substituting in region {} (index={})",
475+
data.name, data.index
484476
);
485477
span_bug!(span, "{}", msg);
486478
}
@@ -495,25 +487,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
495487
return t;
496488
}
497489

498-
// track the root type we were asked to substitute
499-
let depth = self.ty_stack_depth;
500-
if depth == 0 {
501-
self.root_ty = Some(t);
502-
}
503-
self.ty_stack_depth += 1;
504-
505-
let t1 = match t.kind {
490+
match t.kind {
506491
ty::Param(p) => self.ty_for_param(p, t),
507492
_ => t.super_fold_with(self),
508-
};
509-
510-
assert_eq!(depth + 1, self.ty_stack_depth);
511-
self.ty_stack_depth -= 1;
512-
if depth == 0 {
513-
self.root_ty = None;
514493
}
515-
516-
t1
517494
}
518495

519496
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
@@ -540,12 +517,11 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
540517
span_bug!(
541518
span,
542519
"expected type for `{:?}` ({:?}/{}) but found {:?} \
543-
when substituting (root type={:?}) substs={:?}",
520+
when substituting, substs={:?}",
544521
p,
545522
source_ty,
546523
p.index,
547524
kind,
548-
self.root_ty,
549525
self.substs,
550526
);
551527
}
@@ -554,11 +530,10 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
554530
span_bug!(
555531
span,
556532
"type parameter `{:?}` ({:?}/{}) out of range \
557-
when substituting (root type={:?}) substs={:?}",
533+
when substituting, substs={:?}",
558534
p,
559535
source_ty,
560536
p.index,
561-
self.root_ty,
562537
self.substs,
563538
);
564539
}

0 commit comments

Comments
 (0)