about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2024-12-16 15:30:03 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2024-12-16 16:02:05 +0000
commit4032b9ddbd9f386cc55c3d76000461a1dbb76cd9 (patch)
treea4e46aa2868cd30507659ac00e4f963aed41632c
parentf387b9d9092829c036684242f20b773549c90237 (diff)
Avoid wrapping a trivially defaultable type in `Option`
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_name.rs9
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs20
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs7
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 d49dee85144..5dfc2658d2a 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 af3b5e0d5d4..c99b1204788 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<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
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 b55b75aa2c1..26334d53f43 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.