mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Move some stuff to TypeErrCtxt
This commit is contained in:
parent
0f8534e79e
commit
fc1e7ceb4b
@ -457,8 +457,11 @@ 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.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
|
||||
let type_name = self
|
||||
.infcx
|
||||
.err_ctxt()
|
||||
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
|
||||
.name;
|
||||
|
||||
debug!(
|
||||
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
|
||||
@ -872,8 +875,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
|
||||
let mut highlight = RegionHighlightMode::default();
|
||||
highlight.highlighting_region_vid(tcx, fr, *self.next_region_name.try_borrow().unwrap());
|
||||
let type_name =
|
||||
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
|
||||
let type_name = self
|
||||
.infcx
|
||||
.err_ctxt()
|
||||
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
|
||||
.name;
|
||||
|
||||
let yield_span = match tcx.hir_node(self.mir_hir_id()) {
|
||||
hir::Node::Expr(hir::Expr {
|
||||
|
@ -2574,7 +2574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
base: &'tcx hir::Expr<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) {
|
||||
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
|
||||
let Some(output_ty) = self.err_ctxt().get_impl_future_output_ty(ty) else {
|
||||
err.span_label(field_ident.span, "unknown field");
|
||||
return;
|
||||
};
|
||||
|
@ -1107,12 +1107,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.tcx
|
||||
.instantiate_bound_regions_with_erased(Binder::bind_with_vars(ty, bound_vars));
|
||||
let ty = match self.tcx.asyncness(fn_id) {
|
||||
ty::Asyncness::Yes => self.get_impl_future_output_ty(ty).unwrap_or_else(|| {
|
||||
span_bug!(
|
||||
fn_decl.output.span(),
|
||||
"failed to get output type of async function"
|
||||
)
|
||||
}),
|
||||
ty::Asyncness::Yes => {
|
||||
self.err_ctxt().get_impl_future_output_ty(ty).unwrap_or_else(|| {
|
||||
span_bug!(
|
||||
fn_decl.output.span(),
|
||||
"failed to get output type of async function"
|
||||
)
|
||||
})
|
||||
}
|
||||
ty::Asyncness::No => ty,
|
||||
};
|
||||
let ty = self.normalize(expr.span, ty);
|
||||
|
@ -3276,7 +3276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
span: Span,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
) {
|
||||
let output_ty = match self.get_impl_future_output_ty(ty) {
|
||||
let output_ty = match self.err_ctxt().get_impl_future_output_ty(ty) {
|
||||
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
|
||||
_ => return,
|
||||
};
|
||||
|
@ -152,7 +152,7 @@ impl<'tcx> Deref for TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let (def_id, args) = match *ty.kind() {
|
||||
ty::Alias(_, ty::AliasTy { def_id, args, .. })
|
||||
@ -189,9 +189,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
.flatten()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
/// Adds a note if the types come from similarly named crates
|
||||
fn check_and_note_conflicting_crates(&self, err: &mut Diag<'_>, terr: TypeError<'tcx>) {
|
||||
use hir::def_id::CrateNum;
|
||||
|
@ -445,7 +445,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
})
|
||||
}
|
||||
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
|
||||
let mut err = self.infcx.report_extra_impl_obligation(
|
||||
let mut err = self.report_extra_impl_obligation(
|
||||
span,
|
||||
impl_item_def_id,
|
||||
trait_item_def_id,
|
||||
@ -645,7 +645,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
trait_item_def_id,
|
||||
}) = origin
|
||||
{
|
||||
return self.infcx.report_extra_impl_obligation(
|
||||
return self.report_extra_impl_obligation(
|
||||
span,
|
||||
impl_item_def_id,
|
||||
trait_item_def_id,
|
||||
|
@ -289,7 +289,7 @@ fn closure_as_fn_str<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
|
||||
format!("fn({args}){ret}")
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
/// Extracts data used by diagnostic for either types or constants
|
||||
/// which were stuck during inference.
|
||||
pub fn extract_inference_diagnostics_data(
|
||||
@ -391,7 +391,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
span: Span,
|
||||
arg_data: InferenceDiagnosticsData,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
) -> Diag<'_> {
|
||||
) -> Diag<'a> {
|
||||
let source_kind = "other";
|
||||
let source_name = "";
|
||||
let failure_span = None;
|
||||
@ -434,9 +434,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
#[instrument(level = "debug", skip(self, error_code))]
|
||||
pub fn emit_inference_failure_err(
|
||||
&self,
|
||||
@ -453,7 +451,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
// If we don't have any typeck results we're outside
|
||||
// of a body, so we won't be able to get better info
|
||||
// here.
|
||||
return self.infcx.bad_inference_failure_err(failure_span, arg_data, error_code);
|
||||
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
|
||||
};
|
||||
|
||||
let mut local_visitor = FindInferSourceVisitor::new(self, typeck_results, arg);
|
||||
@ -465,7 +463,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
let Some(InferSource { span, kind }) = local_visitor.infer_source else {
|
||||
return self.infcx.bad_inference_failure_err(failure_span, arg_data, error_code);
|
||||
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
|
||||
};
|
||||
|
||||
let (source_kind, name, path) = kind.ty_localized_msg(self);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::ObjectSafetyViolation;
|
||||
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::error_reporting::infer::TypeErrCtxt;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
@ -11,9 +11,9 @@ use rustc_span::Span;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
pub fn report_extra_impl_obligation<'a>(
|
||||
&'a self,
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
pub fn report_extra_impl_obligation(
|
||||
&self,
|
||||
error_span: Span,
|
||||
impl_item_def_id: LocalDefId,
|
||||
trait_item_def_id: DefId,
|
||||
|
Loading…
Reference in New Issue
Block a user