Skip to content

Commit fc1e7ce

Browse files
Move some stuff to TypeErrCtxt
1 parent 0f8534e commit fc1e7ce

File tree

8 files changed

+31
-27
lines changed

8 files changed

+31
-27
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
457457
) -> RegionNameHighlight {
458458
let mut highlight = RegionHighlightMode::default();
459459
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
460-
let type_name =
461-
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
460+
let type_name = self
461+
.infcx
462+
.err_ctxt()
463+
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
464+
.name;
462465

463466
debug!(
464467
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
@@ -872,8 +875,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
872875

873876
let mut highlight = RegionHighlightMode::default();
874877
highlight.highlighting_region_vid(tcx, fr, *self.next_region_name.try_borrow().unwrap());
875-
let type_name =
876-
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
878+
let type_name = self
879+
.infcx
880+
.err_ctxt()
881+
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
882+
.name;
877883

878884
let yield_span = match tcx.hir_node(self.mir_hir_id()) {
879885
hir::Node::Expr(hir::Expr {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25742574
base: &'tcx hir::Expr<'tcx>,
25752575
ty: Ty<'tcx>,
25762576
) {
2577-
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
2577+
let Some(output_ty) = self.err_ctxt().get_impl_future_output_ty(ty) else {
25782578
err.span_label(field_ident.span, "unknown field");
25792579
return;
25802580
};

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11071107
.tcx
11081108
.instantiate_bound_regions_with_erased(Binder::bind_with_vars(ty, bound_vars));
11091109
let ty = match self.tcx.asyncness(fn_id) {
1110-
ty::Asyncness::Yes => self.get_impl_future_output_ty(ty).unwrap_or_else(|| {
1111-
span_bug!(
1112-
fn_decl.output.span(),
1113-
"failed to get output type of async function"
1114-
)
1115-
}),
1110+
ty::Asyncness::Yes => {
1111+
self.err_ctxt().get_impl_future_output_ty(ty).unwrap_or_else(|| {
1112+
span_bug!(
1113+
fn_decl.output.span(),
1114+
"failed to get output type of async function"
1115+
)
1116+
})
1117+
}
11161118
ty::Asyncness::No => ty,
11171119
};
11181120
let ty = self.normalize(expr.span, ty);

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32763276
span: Span,
32773277
return_type: Option<Ty<'tcx>>,
32783278
) {
3279-
let output_ty = match self.get_impl_future_output_ty(ty) {
3279+
let output_ty = match self.err_ctxt().get_impl_future_output_ty(ty) {
32803280
Some(output_ty) => self.resolve_vars_if_possible(output_ty),
32813281
_ => return,
32823282
};

compiler/rustc_infer/src/error_reporting/infer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'tcx> Deref for TypeErrCtxt<'_, 'tcx> {
152152
}
153153
}
154154

155-
impl<'tcx> InferCtxt<'tcx> {
155+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
156156
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
157157
let (def_id, args) = match *ty.kind() {
158158
ty::Alias(_, ty::AliasTy { def_id, args, .. })
@@ -189,9 +189,7 @@ impl<'tcx> InferCtxt<'tcx> {
189189
.flatten()
190190
})
191191
}
192-
}
193192

194-
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
195193
/// Adds a note if the types come from similarly named crates
196194
fn check_and_note_conflicting_crates(&self, err: &mut Diag<'_>, terr: TypeError<'tcx>) {
197195
use hir::def_id::CrateNum;

compiler/rustc_infer/src/error_reporting/infer/region.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
445445
})
446446
}
447447
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
448-
let mut err = self.infcx.report_extra_impl_obligation(
448+
let mut err = self.report_extra_impl_obligation(
449449
span,
450450
impl_item_def_id,
451451
trait_item_def_id,
@@ -645,7 +645,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
645645
trait_item_def_id,
646646
}) = origin
647647
{
648-
return self.infcx.report_extra_impl_obligation(
648+
return self.report_extra_impl_obligation(
649649
span,
650650
impl_item_def_id,
651651
trait_item_def_id,

compiler/rustc_infer/src/infer/need_type_info.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn closure_as_fn_str<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
289289
format!("fn({args}){ret}")
290290
}
291291

292-
impl<'tcx> InferCtxt<'tcx> {
292+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
293293
/// Extracts data used by diagnostic for either types or constants
294294
/// which were stuck during inference.
295295
pub fn extract_inference_diagnostics_data(
@@ -391,7 +391,7 @@ impl<'tcx> InferCtxt<'tcx> {
391391
span: Span,
392392
arg_data: InferenceDiagnosticsData,
393393
error_code: TypeAnnotationNeeded,
394-
) -> Diag<'_> {
394+
) -> Diag<'a> {
395395
let source_kind = "other";
396396
let source_name = "";
397397
let failure_span = None;
@@ -434,9 +434,7 @@ impl<'tcx> InferCtxt<'tcx> {
434434
}),
435435
}
436436
}
437-
}
438437

439-
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
440438
#[instrument(level = "debug", skip(self, error_code))]
441439
pub fn emit_inference_failure_err(
442440
&self,
@@ -453,7 +451,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
453451
// If we don't have any typeck results we're outside
454452
// of a body, so we won't be able to get better info
455453
// here.
456-
return self.infcx.bad_inference_failure_err(failure_span, arg_data, error_code);
454+
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
457455
};
458456

459457
let mut local_visitor = FindInferSourceVisitor::new(self, typeck_results, arg);
@@ -465,7 +463,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
465463
}
466464

467465
let Some(InferSource { span, kind }) = local_visitor.infer_source else {
468-
return self.infcx.bad_inference_failure_err(failure_span, arg_data, error_code);
466+
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
469467
};
470468

471469
let (source_kind, name, path) = kind.ty_localized_msg(self);

compiler/rustc_infer/src/traits/error_reporting/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::ObjectSafetyViolation;
22

3-
use crate::infer::InferCtxt;
3+
use crate::error_reporting::infer::TypeErrCtxt;
44
use rustc_data_structures::fx::FxIndexSet;
55
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
66
use rustc_hir as hir;
@@ -11,9 +11,9 @@ use rustc_span::Span;
1111
use std::fmt;
1212
use std::iter;
1313

14-
impl<'tcx> InferCtxt<'tcx> {
15-
pub fn report_extra_impl_obligation<'a>(
16-
&'a self,
14+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15+
pub fn report_extra_impl_obligation(
16+
&self,
1717
error_span: Span,
1818
impl_item_def_id: LocalDefId,
1919
trait_item_def_id: DefId,

0 commit comments

Comments
 (0)