Skip to content

Commit

Permalink
Avoid wrapping a trivially defaultable type in Option
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 16, 2024
1 parent f387b9d commit 4032b9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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={:?}",
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4032b9d

Please sign in to comment.