Rollup merge of #105185 - compiler-errors:normalize_fn_sig-in-err-ctxt, r=lcnr
Move `normalize_fn_sig` to `TypeErrCtxt` r? `@lcnr`
This commit is contained in:
commit
8e0d83a70c
5 changed files with 30 additions and 67 deletions
|
@ -77,10 +77,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
err_count_on_creation: self.err_count_on_creation,
|
||||
in_snapshot: self.in_snapshot.clone(),
|
||||
universe: self.universe.clone(),
|
||||
normalize_fn_sig_for_diagnostic: self
|
||||
.normalize_fn_sig_for_diagnostic
|
||||
.as_ref()
|
||||
.map(|f| f.clone()),
|
||||
intercrate: self.intercrate,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ pub mod nice_region_error;
|
|||
pub struct TypeErrCtxt<'a, 'tcx> {
|
||||
pub infcx: &'a InferCtxt<'tcx>,
|
||||
pub typeck_results: Option<std::cell::Ref<'a, ty::TypeckResults<'tcx>>>,
|
||||
pub normalize_fn_sig: Box<dyn Fn(ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx> + 'a>,
|
||||
pub fallback_has_occurred: bool,
|
||||
}
|
||||
|
||||
|
@ -1007,22 +1008,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn normalize_fn_sig_for_diagnostic(&self, sig: ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx> {
|
||||
if let Some(normalize) = &self.normalize_fn_sig_for_diagnostic {
|
||||
normalize(self, sig)
|
||||
} else {
|
||||
sig
|
||||
}
|
||||
}
|
||||
|
||||
/// Given two `fn` signatures highlight only sub-parts that are different.
|
||||
fn cmp_fn_sig(
|
||||
&self,
|
||||
sig1: &ty::PolyFnSig<'tcx>,
|
||||
sig2: &ty::PolyFnSig<'tcx>,
|
||||
) -> (DiagnosticStyledString, DiagnosticStyledString) {
|
||||
let sig1 = &self.normalize_fn_sig_for_diagnostic(*sig1);
|
||||
let sig2 = &self.normalize_fn_sig_for_diagnostic(*sig2);
|
||||
let sig1 = &(self.normalize_fn_sig)(*sig1);
|
||||
let sig2 = &(self.normalize_fn_sig)(*sig2);
|
||||
|
||||
let get_lifetimes = |sig| {
|
||||
use rustc_hir::def::Namespace;
|
||||
|
|
|
@ -333,9 +333,6 @@ pub struct InferCtxt<'tcx> {
|
|||
/// bound.
|
||||
universe: Cell<ty::UniverseIndex>,
|
||||
|
||||
normalize_fn_sig_for_diagnostic:
|
||||
Option<Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>>,
|
||||
|
||||
/// During coherence we have to assume that other crates may add
|
||||
/// additional impls which we currently don't know about.
|
||||
///
|
||||
|
@ -572,8 +569,6 @@ pub struct InferCtxtBuilder<'tcx> {
|
|||
considering_regions: bool,
|
||||
/// Whether we are in coherence mode.
|
||||
intercrate: bool,
|
||||
normalize_fn_sig_for_diagnostic:
|
||||
Option<Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>>,
|
||||
}
|
||||
|
||||
pub trait TyCtxtInferExt<'tcx> {
|
||||
|
@ -586,7 +581,6 @@ impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
|
|||
tcx: self,
|
||||
defining_use_anchor: DefiningAnchor::Error,
|
||||
considering_regions: true,
|
||||
normalize_fn_sig_for_diagnostic: None,
|
||||
intercrate: false,
|
||||
}
|
||||
}
|
||||
|
@ -614,14 +608,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_normalize_fn_sig_for_diagnostic(
|
||||
mut self,
|
||||
fun: Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>,
|
||||
) -> Self {
|
||||
self.normalize_fn_sig_for_diagnostic = Some(fun);
|
||||
self
|
||||
}
|
||||
|
||||
/// Given a canonical value `C` as a starting point, create an
|
||||
/// inference context that contains each of the bound values
|
||||
/// within instantiated as a fresh variable. The `f` closure is
|
||||
|
@ -643,13 +629,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
|
|||
}
|
||||
|
||||
pub fn build(&mut self) -> InferCtxt<'tcx> {
|
||||
let InferCtxtBuilder {
|
||||
tcx,
|
||||
defining_use_anchor,
|
||||
considering_regions,
|
||||
ref normalize_fn_sig_for_diagnostic,
|
||||
intercrate,
|
||||
} = *self;
|
||||
let InferCtxtBuilder { tcx, defining_use_anchor, considering_regions, intercrate } = *self;
|
||||
InferCtxt {
|
||||
tcx,
|
||||
defining_use_anchor,
|
||||
|
@ -665,9 +645,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
|
|||
in_snapshot: Cell::new(false),
|
||||
skip_leak_check: Cell::new(false),
|
||||
universe: Cell::new(ty::UniverseIndex::ROOT),
|
||||
normalize_fn_sig_for_diagnostic: normalize_fn_sig_for_diagnostic
|
||||
.as_ref()
|
||||
.map(|f| f.clone()),
|
||||
intercrate,
|
||||
}
|
||||
}
|
||||
|
@ -708,7 +685,12 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
/// Creates a `TypeErrCtxt` for emitting various inference errors.
|
||||
/// During typeck, use `FnCtxt::err_ctxt` instead.
|
||||
pub fn err_ctxt(&self) -> TypeErrCtxt<'_, 'tcx> {
|
||||
TypeErrCtxt { infcx: self, typeck_results: None, fallback_has_occurred: false }
|
||||
TypeErrCtxt {
|
||||
infcx: self,
|
||||
typeck_results: None,
|
||||
fallback_has_occurred: false,
|
||||
normalize_fn_sig: Box::new(|fn_sig| fn_sig),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_in_snapshot(&self) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue