Avoid wrapping a trivially defaultable type in Option

This commit is contained in:
Oli Scherer 2024-12-16 15:30:03 +00:00
parent f387b9d909
commit 4032b9ddbd
3 changed files with 14 additions and 22 deletions

View File

@ -459,11 +459,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
) -> RegionNameHighlight {
let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
let type_name = self
.infcx
.err_ctxt()
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
.name;
let type_name =
self.infcx.err_ctxt().extract_inference_diagnostics_data(ty.into(), highlight).name;
debug!(
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
@ -874,7 +871,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let type_name = self
.infcx
.err_ctxt()
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
.extract_inference_diagnostics_data(yield_ty.into(), highlight)
.name;
let yield_span = match tcx.hir_node(self.mir_hir_id()) {

View File

@ -279,7 +279,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
pub fn extract_inference_diagnostics_data(
&self,
arg: GenericArg<'tcx>,
highlight: Option<ty::print::RegionHighlightMode<'tcx>>,
highlight: ty::print::RegionHighlightMode<'tcx>,
) -> InferenceDiagnosticsData {
match arg.unpack() {
GenericArgKind::Type(ty) => {
@ -301,9 +301,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS);
if let Some(highlight) = highlight {
printer.region_highlight_mode = highlight;
}
printer.region_highlight_mode = highlight;
ty.print(&mut printer).unwrap();
InferenceDiagnosticsData {
name: printer.into_buffer(),
@ -326,9 +325,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
debug_assert!(!origin.span.is_dummy());
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS);
if let Some(highlight) = highlight {
printer.region_highlight_mode = highlight;
}
printer.region_highlight_mode = highlight;
ct.print(&mut printer).unwrap();
InferenceDiagnosticsData {
name: printer.into_buffer(),
@ -344,9 +342,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// to figure out which inference var is actually unresolved so that
// this path is unreachable.
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS);
if let Some(highlight) = highlight {
printer.region_highlight_mode = highlight;
}
printer.region_highlight_mode = highlight;
ct.print(&mut printer).unwrap();
InferenceDiagnosticsData {
name: printer.into_buffer(),
@ -422,7 +419,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
should_label_span: bool,
) -> Diag<'a> {
let arg = self.resolve_vars_if_possible(arg);
let arg_data = self.extract_inference_diagnostics_data(arg, None);
let arg_data =
self.extract_inference_diagnostics_data(arg, ty::print::RegionHighlightMode::default());
let Some(typeck_results) = &self.typeck_results else {
// If we don't have any typeck results we're outside

View File

@ -85,16 +85,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
.cx
.extract_inference_diagnostics_data(
Ty::new_fn_ptr(tcx, expected).into(),
Some(expected_highlight),
expected_highlight,
)
.name;
let found_highlight = HighlightBuilder::build(found);
let found = self
.cx
.extract_inference_diagnostics_data(
Ty::new_fn_ptr(tcx, found).into(),
Some(found_highlight),
)
.extract_inference_diagnostics_data(Ty::new_fn_ptr(tcx, found).into(), found_highlight)
.name;
// Get the span of all the used type parameters in the method.