1
Fork 0

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 { ) -> RegionNameHighlight {
let mut highlight = RegionHighlightMode::default(); let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter); highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
let type_name = self let type_name =
.infcx self.infcx.err_ctxt().extract_inference_diagnostics_data(ty.into(), highlight).name;
.err_ctxt()
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
.name;
debug!( debug!(
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}", "highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
@ -874,7 +871,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let type_name = self let type_name = self
.infcx .infcx
.err_ctxt() .err_ctxt()
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)) .extract_inference_diagnostics_data(yield_ty.into(), highlight)
.name; .name;
let yield_span = match tcx.hir_node(self.mir_hir_id()) { 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( pub fn extract_inference_diagnostics_data(
&self, &self,
arg: GenericArg<'tcx>, arg: GenericArg<'tcx>,
highlight: Option<ty::print::RegionHighlightMode<'tcx>>, highlight: ty::print::RegionHighlightMode<'tcx>,
) -> InferenceDiagnosticsData { ) -> InferenceDiagnosticsData {
match arg.unpack() { match arg.unpack() {
GenericArgKind::Type(ty) => { GenericArgKind::Type(ty) => {
@ -301,9 +301,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
} }
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS); 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(); ty.print(&mut printer).unwrap();
InferenceDiagnosticsData { InferenceDiagnosticsData {
name: printer.into_buffer(), name: printer.into_buffer(),
@ -326,9 +325,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
debug_assert!(!origin.span.is_dummy()); debug_assert!(!origin.span.is_dummy());
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS); 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(); ct.print(&mut printer).unwrap();
InferenceDiagnosticsData { InferenceDiagnosticsData {
name: printer.into_buffer(), 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 // to figure out which inference var is actually unresolved so that
// this path is unreachable. // this path is unreachable.
let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::ValueNS); 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(); ct.print(&mut printer).unwrap();
InferenceDiagnosticsData { InferenceDiagnosticsData {
name: printer.into_buffer(), name: printer.into_buffer(),
@ -422,7 +419,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
should_label_span: bool, should_label_span: bool,
) -> Diag<'a> { ) -> Diag<'a> {
let arg = self.resolve_vars_if_possible(arg); 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 { let Some(typeck_results) = &self.typeck_results else {
// If we don't have any typeck results we're outside // If we don't have any typeck results we're outside

View file

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