Skip to content

Commit 4032b9d

Browse files
committed
Avoid wrapping a trivially defaultable type in Option
1 parent f387b9d commit 4032b9d

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
459459
) -> RegionNameHighlight {
460460
let mut highlight = RegionHighlightMode::default();
461461
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
462-
let type_name = self
463-
.infcx
464-
.err_ctxt()
465-
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
466-
.name;
462+
let type_name =
463+
self.infcx.err_ctxt().extract_inference_diagnostics_data(ty.into(), highlight).name;
467464

468465
debug!(
469466
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
@@ -874,7 +871,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
874871
let type_name = self
875872
.infcx
876873
.err_ctxt()
877-
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
874+
.extract_inference_diagnostics_data(yield_ty.into(), highlight)
878875
.name;
879876

880877
let yield_span = match tcx.hir_node(self.mir_hir_id()) {

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
279279
pub fn extract_inference_diagnostics_data(
280280
&self,
281281
arg: GenericArg<'tcx>,
282-
highlight: Option<ty::print::RegionHighlightMode<'tcx>>,
282+
highlight: ty::print::RegionHighlightMode<'tcx>,
283283
) -> InferenceDiagnosticsData {
284284
match arg.unpack() {
285285
GenericArgKind::Type(ty) => {
@@ -301,9 +301,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
301301
}
302302

303303
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS);
304-
if let Some(highlight) = highlight {
305-
printer.region_highlight_mode = highlight;
306-
}
304+
printer.region_highlight_mode = highlight;
305+
307306
ty.print(&mut printer).unwrap();
308307
InferenceDiagnosticsData {
309308
name: printer.into_buffer(),
@@ -326,9 +325,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
326325

327326
debug_assert!(!origin.span.is_dummy());
328327
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS);
329-
if let Some(highlight) = highlight {
330-
printer.region_highlight_mode = highlight;
331-
}
328+
printer.region_highlight_mode = highlight;
329+
332330
ct.print(&mut printer).unwrap();
333331
InferenceDiagnosticsData {
334332
name: printer.into_buffer(),
@@ -344,9 +342,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
344342
// to figure out which inference var is actually unresolved so that
345343
// this path is unreachable.
346344
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS);
347-
if let Some(highlight) = highlight {
348-
printer.region_highlight_mode = highlight;
349-
}
345+
printer.region_highlight_mode = highlight;
346+
350347
ct.print(&mut printer).unwrap();
351348
InferenceDiagnosticsData {
352349
name: printer.into_buffer(),
@@ -422,7 +419,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
422419
should_label_span: bool,
423420
) -> Diag<'a> {
424421
let arg = self.resolve_vars_if_possible(arg);
425-
let arg_data = self.extract_inference_diagnostics_data(arg, None);
422+
let arg_data =
423+
self.extract_inference_diagnostics_data(arg, ty::print::RegionHighlightMode::default());
426424

427425
let Some(typeck_results) = &self.typeck_results else {
428426
// If we don't have any typeck results we're outside

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8585
.cx
8686
.extract_inference_diagnostics_data(
8787
Ty::new_fn_ptr(tcx, expected).into(),
88-
Some(expected_highlight),
88+
expected_highlight,
8989
)
9090
.name;
9191
let found_highlight = HighlightBuilder::build(found);
9292
let found = self
9393
.cx
94-
.extract_inference_diagnostics_data(
95-
Ty::new_fn_ptr(tcx, found).into(),
96-
Some(found_highlight),
97-
)
94+
.extract_inference_diagnostics_data(Ty::new_fn_ptr(tcx, found).into(), found_highlight)
9895
.name;
9996

10097
// Get the span of all the used type parameters in the method.

0 commit comments

Comments
 (0)