Skip to content

Commit 1281d43

Browse files
committed
Remove RegionHighlightMode::tcx.
It's easier to pass it in to the one method that needs it (`highlighting_region_vid`) than to store it in the type. This means `RegionHighlightMode` can impl `Default`.
1 parent 203c57d commit 1281d43

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
442442
span: Span,
443443
counter: usize,
444444
) -> RegionNameHighlight {
445-
let mut highlight = RegionHighlightMode::new(self.infcx.tcx);
446-
highlight.highlighting_region_vid(needle_fr, counter);
445+
let mut highlight = RegionHighlightMode::default();
446+
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
447447
let type_name =
448448
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
449449

@@ -804,8 +804,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
804804
return None;
805805
}
806806

807-
let mut highlight = RegionHighlightMode::new(tcx);
808-
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
807+
let mut highlight = RegionHighlightMode::default();
808+
highlight.highlighting_region_vid(tcx, fr, *self.next_region_name.try_borrow().unwrap());
809809
let type_name =
810810
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
811811

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
385385

386386
let highlight_trait_ref = |trait_ref| Highlighted {
387387
tcx: self.tcx(),
388-
highlight: RegionHighlightMode::new(self.tcx()),
388+
highlight: RegionHighlightMode::default(),
389389
value: trait_ref,
390390
};
391391

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6767
}
6868

6969
impl<'tcx> HighlightBuilder<'tcx> {
70-
fn build(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
70+
fn build(ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
7171
let mut builder =
72-
HighlightBuilder { highlight: RegionHighlightMode::new(tcx), counter: 1 };
72+
HighlightBuilder { highlight: RegionHighlightMode::default(), counter: 1 };
7373
builder.visit_ty(ty);
7474
builder.highlight
7575
}
@@ -85,12 +85,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8585
}
8686
}
8787

88-
let expected_highlight = HighlightBuilder::build(self.tcx(), expected);
88+
let expected_highlight = HighlightBuilder::build(expected);
8989
let expected = self
9090
.cx
9191
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
9292
.name;
93-
let found_highlight = HighlightBuilder::build(self.tcx(), found);
93+
let found_highlight = HighlightBuilder::build(found);
9494
let found =
9595
self.cx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
9696

compiler/rustc_middle/src/ty/print/pretty.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ define_helper!(
136136
///
137137
/// Regions not selected by the region highlight mode are presently
138138
/// unaffected.
139-
#[derive(Copy, Clone)]
139+
#[derive(Copy, Clone, Default)]
140140
pub struct RegionHighlightMode<'tcx> {
141-
tcx: TyCtxt<'tcx>,
142-
143141
/// If enabled, when we see the selected region, use "`'N`"
144142
/// instead of the ordinary behavior.
145143
highlight_regions: [Option<(ty::Region<'tcx>, usize)>; 3],
@@ -155,14 +153,6 @@ pub struct RegionHighlightMode<'tcx> {
155153
}
156154

157155
impl<'tcx> RegionHighlightMode<'tcx> {
158-
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
159-
Self {
160-
tcx,
161-
highlight_regions: Default::default(),
162-
highlight_bound_region: Default::default(),
163-
}
164-
}
165-
166156
/// If `region` and `number` are both `Some`, invokes
167157
/// `highlighting_region`.
168158
pub fn maybe_highlighting_region(
@@ -188,8 +178,13 @@ impl<'tcx> RegionHighlightMode<'tcx> {
188178
}
189179

190180
/// Convenience wrapper for `highlighting_region`.
191-
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
192-
self.highlighting_region(ty::Region::new_var(self.tcx, vid), number)
181+
pub fn highlighting_region_vid(
182+
&mut self,
183+
tcx: TyCtxt<'tcx>,
184+
vid: ty::RegionVid,
185+
number: usize,
186+
) {
187+
self.highlighting_region(ty::Region::new_var(tcx, vid), number)
193188
}
194189

195190
/// Returns `Some(n)` with the number to use for the given region, if any.
@@ -1778,7 +1773,7 @@ impl<'a, 'tcx> FmtPrinter<'a, 'tcx> {
17781773
printed_type_count: 0,
17791774
type_length_limit,
17801775
truncated: false,
1781-
region_highlight_mode: RegionHighlightMode::new(tcx),
1776+
region_highlight_mode: RegionHighlightMode::default(),
17821777
ty_infer_name_resolver: None,
17831778
const_infer_name_resolver: None,
17841779
}))

0 commit comments

Comments
 (0)