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`.
This commit is contained in:
parent
203c57dbe2
commit
1281d43942
4 changed files with 18 additions and 23 deletions
|
@ -442,8 +442,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
counter: usize,
|
counter: usize,
|
||||||
) -> RegionNameHighlight {
|
) -> RegionNameHighlight {
|
||||||
let mut highlight = RegionHighlightMode::new(self.infcx.tcx);
|
let mut highlight = RegionHighlightMode::default();
|
||||||
highlight.highlighting_region_vid(needle_fr, counter);
|
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
|
||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
||||||
|
|
||||||
|
@ -804,8 +804,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut highlight = RegionHighlightMode::new(tcx);
|
let mut highlight = RegionHighlightMode::default();
|
||||||
highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
|
highlight.highlighting_region_vid(tcx, fr, *self.next_region_name.try_borrow().unwrap());
|
||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
|
|
||||||
let highlight_trait_ref = |trait_ref| Highlighted {
|
let highlight_trait_ref = |trait_ref| Highlighted {
|
||||||
tcx: self.tcx(),
|
tcx: self.tcx(),
|
||||||
highlight: RegionHighlightMode::new(self.tcx()),
|
highlight: RegionHighlightMode::default(),
|
||||||
value: trait_ref,
|
value: trait_ref,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> HighlightBuilder<'tcx> {
|
impl<'tcx> HighlightBuilder<'tcx> {
|
||||||
fn build(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
|
fn build(ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
HighlightBuilder { highlight: RegionHighlightMode::new(tcx), counter: 1 };
|
HighlightBuilder { highlight: RegionHighlightMode::default(), counter: 1 };
|
||||||
builder.visit_ty(ty);
|
builder.visit_ty(ty);
|
||||||
builder.highlight
|
builder.highlight
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_highlight = HighlightBuilder::build(self.tcx(), expected);
|
let expected_highlight = HighlightBuilder::build(expected);
|
||||||
let expected = self
|
let expected = self
|
||||||
.cx
|
.cx
|
||||||
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
|
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
|
||||||
.name;
|
.name;
|
||||||
let found_highlight = HighlightBuilder::build(self.tcx(), found);
|
let found_highlight = HighlightBuilder::build(found);
|
||||||
let found =
|
let found =
|
||||||
self.cx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
|
self.cx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
|
||||||
|
|
||||||
|
|
|
@ -136,10 +136,8 @@ define_helper!(
|
||||||
///
|
///
|
||||||
/// Regions not selected by the region highlight mode are presently
|
/// Regions not selected by the region highlight mode are presently
|
||||||
/// unaffected.
|
/// unaffected.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone, Default)]
|
||||||
pub struct RegionHighlightMode<'tcx> {
|
pub struct RegionHighlightMode<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
|
|
||||||
/// If enabled, when we see the selected region, use "`'N`"
|
/// If enabled, when we see the selected region, use "`'N`"
|
||||||
/// instead of the ordinary behavior.
|
/// instead of the ordinary behavior.
|
||||||
highlight_regions: [Option<(ty::Region<'tcx>, usize)>; 3],
|
highlight_regions: [Option<(ty::Region<'tcx>, usize)>; 3],
|
||||||
|
@ -155,14 +153,6 @@ pub struct RegionHighlightMode<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> RegionHighlightMode<'tcx> {
|
impl<'tcx> RegionHighlightMode<'tcx> {
|
||||||
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
|
|
||||||
Self {
|
|
||||||
tcx,
|
|
||||||
highlight_regions: Default::default(),
|
|
||||||
highlight_bound_region: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If `region` and `number` are both `Some`, invokes
|
/// If `region` and `number` are both `Some`, invokes
|
||||||
/// `highlighting_region`.
|
/// `highlighting_region`.
|
||||||
pub fn maybe_highlighting_region(
|
pub fn maybe_highlighting_region(
|
||||||
|
@ -188,8 +178,13 @@ impl<'tcx> RegionHighlightMode<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience wrapper for `highlighting_region`.
|
/// Convenience wrapper for `highlighting_region`.
|
||||||
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
|
pub fn highlighting_region_vid(
|
||||||
self.highlighting_region(ty::Region::new_var(self.tcx, vid), number)
|
&mut self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
vid: ty::RegionVid,
|
||||||
|
number: usize,
|
||||||
|
) {
|
||||||
|
self.highlighting_region(ty::Region::new_var(tcx, vid), number)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `Some(n)` with the number to use for the given region, if any.
|
/// Returns `Some(n)` with the number to use for the given region, if any.
|
||||||
|
@ -1778,7 +1773,7 @@ impl<'a, 'tcx> FmtPrinter<'a, 'tcx> {
|
||||||
printed_type_count: 0,
|
printed_type_count: 0,
|
||||||
type_length_limit,
|
type_length_limit,
|
||||||
truncated: false,
|
truncated: false,
|
||||||
region_highlight_mode: RegionHighlightMode::new(tcx),
|
region_highlight_mode: RegionHighlightMode::default(),
|
||||||
ty_infer_name_resolver: None,
|
ty_infer_name_resolver: None,
|
||||||
const_infer_name_resolver: None,
|
const_infer_name_resolver: None,
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue