Skip to content

Commit bdb88c9

Browse files
committed
Avoid creating a fn sig type just to unwrap it again to get at its signature
1 parent 83ab648 commit bdb88c9

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::hir::nested_filter;
99
use rustc_middle::traits::ObligationCauseCode;
1010
use rustc_middle::ty::error::ExpectedFound;
1111
use rustc_middle::ty::print::RegionHighlightMode;
12-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
12+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
1313
use rustc_span::Span;
1414
use tracing::debug;
1515

@@ -39,12 +39,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3939
{
4040
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
4141
// all of the region highlighting machinery only deals with those.
42-
let guar = self.emit_err(
43-
var_origin.span(),
44-
Ty::new_fn_ptr(self.cx.tcx, expected),
45-
Ty::new_fn_ptr(self.cx.tcx, found),
46-
*trait_item_def_id,
47-
);
42+
let guar = self.emit_err(var_origin.span(), expected, found, trait_item_def_id);
4843
return Some(guar);
4944
}
5045
None
@@ -53,8 +48,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5348
fn emit_err(
5449
&self,
5550
sp: Span,
56-
expected: Ty<'tcx>,
57-
found: Ty<'tcx>,
51+
expected: ty::PolyFnSig<'tcx>,
52+
found: ty::PolyFnSig<'tcx>,
5853
trait_def_id: DefId,
5954
) -> ErrorGuaranteed {
6055
let trait_sp = self.tcx().def_span(trait_def_id);
@@ -67,10 +62,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6762
}
6863

6964
impl<'tcx> HighlightBuilder<'tcx> {
70-
fn build(ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
65+
fn build(sig: ty::PolyFnSig<'tcx>) -> RegionHighlightMode<'tcx> {
7166
let mut builder =
7267
HighlightBuilder { highlight: RegionHighlightMode::default(), counter: 1 };
73-
builder.visit_ty(ty);
68+
sig.visit_with(&mut builder);
7469
builder.highlight
7570
}
7671
}
@@ -85,13 +80,22 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8580
}
8681

8782
let expected_highlight = HighlightBuilder::build(expected);
83+
let tcx = self.cx.tcx;
8884
let expected = self
8985
.cx
90-
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
86+
.extract_inference_diagnostics_data(
87+
Ty::new_fn_ptr(tcx, expected).into(),
88+
Some(expected_highlight),
89+
)
9190
.name;
9291
let found_highlight = HighlightBuilder::build(found);
93-
let found =
94-
self.cx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
92+
let found = self
93+
.cx
94+
.extract_inference_diagnostics_data(
95+
Ty::new_fn_ptr(tcx, found).into(),
96+
Some(found_highlight),
97+
)
98+
.name;
9599

96100
// Get the span of all the used type parameters in the method.
97101
let assoc_item = self.tcx().associated_item(trait_def_id);

0 commit comments

Comments
 (0)