From 4032b9ddbd9f386cc55c3d76000461a1dbb76cd9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 16 Dec 2024 15:30:03 +0000 Subject: [PATCH] Avoid wrapping a trivially defaultable type in `Option` --- .../src/diagnostics/region_name.rs | 9 +++------ .../error_reporting/infer/need_type_info.rs | 20 +++++++++---------- .../trait_impl_difference.rs | 7 ++----- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index d49dee8514457..5dfc2658d2aaf 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -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()) { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index af3b5e0d5d417..c99b120478827 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -279,7 +279,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { pub fn extract_inference_diagnostics_data( &self, arg: GenericArg<'tcx>, - highlight: Option>, + 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 diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs index b55b75aa2c14f..26334d53f4314 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs @@ -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.