Skip to content

Commit 20f23ab

Browse files
committed
Auto merge of #128041 - compiler-errors:uplift-errors-into-trait-sel, r=lcnr
Uplift most type-system related error reporting from `rustc_infer` to `rustc_trait_selection` Completes the major part of #127492. The only cleanup that's needed afterwards is to actually use normalization in favor of the callback where needed, and deleting `can_eq_shallow`. r? lcnr Sorry for the large diff! Would prefer if comments can be handled in a follow-up (unless they're absolutely dealbreakers) because it seems bitrotty to let this sit.
2 parents aee3dc4 + e9e9495 commit 20f23ab

File tree

81 files changed

+2599
-2605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2599
-2605
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_errors::Diag;
22
use rustc_hir::def_id::LocalDefId;
3-
use rustc_infer::error_reporting::infer::nice_region_error::NiceRegionError;
43
use rustc_infer::infer::canonical::Canonical;
54
use rustc_infer::infer::region_constraints::Constraint;
65
use rustc_infer::infer::region_constraints::RegionConstraintData;
@@ -14,6 +13,8 @@ use rustc_middle::ty::RegionVid;
1413
use rustc_middle::ty::UniverseIndex;
1514
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1615
use rustc_span::Span;
16+
use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError;
17+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1718
use rustc_trait_selection::traits::query::type_op;
1819
use rustc_trait_selection::traits::ObligationCtxt;
1920
use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause};

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use rustc_span::def_id::LocalDefId;
3535
use rustc_span::hygiene::DesugaringKind;
3636
use rustc_span::symbol::{kw, sym, Ident};
3737
use rustc_span::{BytePos, Span, Symbol};
38-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt;
3938
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
39+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4040
use rustc_trait_selection::infer::InferCtxtExt;
4141
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
4242
use std::iter;

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::def_id::LocalDefId;
2727
use rustc_span::source_map::Spanned;
2828
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
2929
use rustc_target::abi::{FieldIdx, VariantIdx};
30-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt as _;
30+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3131
use rustc_trait_selection::infer::InferCtxtExt;
3232
use rustc_trait_selection::traits::{
3333
type_known_to_meet_bound_modulo_regions, FulfillmentErrorCode,

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::{
1616
use rustc_span::symbol::{kw, Symbol};
1717
use rustc_span::{sym, BytePos, DesugaringKind, Span};
1818
use rustc_target::abi::FieldIdx;
19-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt;
19+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2020
use rustc_trait_selection::infer::InferCtxtExt;
2121
use rustc_trait_selection::traits;
2222

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ use rustc_hir::GenericBound::Trait;
1010
use rustc_hir::QPath::Resolved;
1111
use rustc_hir::WherePredicate::BoundPredicate;
1212
use rustc_hir::{PolyTraitRef, TyKind, WhereBoundPredicate};
13-
use rustc_infer::error_reporting::infer::nice_region_error::{
14-
self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
15-
HirTraitObjectVisitor, NiceRegionError, TraitObjectVisitor,
16-
};
17-
use rustc_infer::error_reporting::infer::region::unexpected_hidden_region_diagnostic;
1813
use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
1914
use rustc_middle::bug;
2015
use rustc_middle::hir::place::PlaceBase;
@@ -25,6 +20,12 @@ use rustc_middle::ty::{self, RegionVid, Ty};
2520
use rustc_middle::ty::{Region, TyCtxt};
2621
use rustc_span::symbol::{kw, Ident};
2722
use rustc_span::Span;
23+
use rustc_trait_selection::error_reporting::infer::nice_region_error::{
24+
self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
25+
HirTraitObjectVisitor, NiceRegionError, TraitObjectVisitor,
26+
};
27+
use rustc_trait_selection::error_reporting::infer::region::unexpected_hidden_region_diagnostic;
28+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2829
use rustc_trait_selection::infer::InferCtxtExt;
2930
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
3031

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
1414
use rustc_middle::{bug, span_bug};
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616
use rustc_span::{Span, DUMMY_SP};
17+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1718

1819
use crate::{universal_regions::DefiningTy, MirBorrowckCtxt};
1920

@@ -457,8 +458,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
457458
) -> RegionNameHighlight {
458459
let mut highlight = RegionHighlightMode::default();
459460
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;
461+
let type_name = self
462+
.infcx
463+
.err_ctxt()
464+
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
465+
.name;
462466

463467
debug!(
464468
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
@@ -872,8 +876,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
872876

873877
let mut highlight = RegionHighlightMode::default();
874878
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;
879+
let type_name = self
880+
.infcx
881+
.err_ctxt()
882+
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
883+
.name;
877884

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

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
1111
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
1212
use rustc_middle::ty::{GenericArgKind, GenericArgs};
1313
use rustc_span::Span;
14-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
14+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1515
use rustc_trait_selection::traits::ObligationCtxt;
1616

1717
use crate::session_diagnostics::LifetimeMismatchOpaqueParam;

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::traits::query::OutlivesBound;
1111
use rustc_middle::traits::ObligationCause;
1212
use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
1313
use rustc_span::{ErrorGuaranteed, Span};
14-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
14+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1515
use rustc_trait_selection::solve::deeply_normalize;
1616
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1717
use std::rc::Rc;

compiler/rustc_const_eval/src/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
1313
use rustc_middle::ty::{Instance, InstanceKind, TypeVisitableExt};
1414
use rustc_mir_dataflow::Analysis;
1515
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
16-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
16+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1717
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt};
1818
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitor};
1919

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::{
2626
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
2727
use rustc_target::abi::FieldIdx;
2828
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
29-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
29+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3030
use rustc_trait_selection::traits;
3131
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
3232
use rustc_type_ir::fold::TypeFoldable;

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{
2121
use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_span::Span;
24-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
24+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2525
use rustc_trait_selection::infer::InferCtxtExt;
2626
use rustc_trait_selection::regions::InferCtxtRegionExt;
2727
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;

compiler/rustc_hir_analysis/src/check/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_session::config::EntryFnType;
77
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
88
use rustc_span::{symbol::sym, Span};
99
use rustc_target::spec::abi::Abi;
10-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
10+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1111
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
1212

1313
use std::ops::Not;

compiler/rustc_hir_analysis/src/check/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ use rustc_errors::{pluralize, struct_span_code_err, Diag};
8282
use rustc_hir::def_id::{DefId, LocalDefId};
8383
use rustc_hir::intravisit::Visitor;
8484
use rustc_index::bit_set::BitSet;
85-
use rustc_infer::error_reporting::infer::ObligationCauseExt as _;
8685
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
8786
use rustc_infer::infer::{self, TyCtxtInferExt as _};
8887
use rustc_infer::traits::ObligationCause;
@@ -96,10 +95,9 @@ use rustc_span::symbol::{kw, sym, Ident};
9695
use rustc_span::{def_id::CRATE_DEF_ID, BytePos, Span, Symbol, DUMMY_SP};
9796
use rustc_target::abi::VariantIdx;
9897
use rustc_target::spec::abi::Abi;
99-
use rustc_trait_selection::error_reporting::traits::suggestions::{
100-
ReturnsVisitor, TypeErrCtxtExt as _,
101-
};
102-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
98+
use rustc_trait_selection::error_reporting::infer::ObligationCauseExt as _;
99+
use rustc_trait_selection::error_reporting::traits::suggestions::ReturnsVisitor;
100+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
103101
use rustc_trait_selection::traits::ObligationCtxt;
104102

105103
use crate::errors;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_session::parse::feature_err;
2929
use rustc_span::symbol::{sym, Ident};
3030
use rustc_span::{Span, DUMMY_SP};
3131
use rustc_target::spec::abi::Abi;
32-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
32+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3333
use rustc_trait_selection::regions::InferCtxtRegionExt;
3434
use rustc_trait_selection::traits::misc::{
3535
type_allowed_to_implement_const_param_ty, ConstParamTyImplementationError,

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
1717
use rustc_middle::ty::print::PrintTraitRefExt as _;
1818
use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt};
1919
use rustc_span::{Span, DUMMY_SP};
20-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
20+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2121
use rustc_trait_selection::traits::misc::{
2222
type_allowed_to_implement_const_param_ty, type_allowed_to_implement_copy,
2323
ConstParamTyImplementationError, CopyImplementationError, InfringingFieldsReason,

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UncoveredTyParamCollector<'_, 'tcx> {
517517
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
518518
return;
519519
}
520-
let Some(origin) = self.infcx.type_var_origin(ty) else {
520+
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
521521
return ty.super_visit_with(self);
522522
};
523+
let origin = self.infcx.type_var_origin(vid);
523524
if let Some(def_id) = origin.param_def_id {
524525
self.uncovered_params.insert(def_id);
525526
}
@@ -546,9 +547,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarReplacer<'cx, 'tcx> {
546547
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
547548
return ty;
548549
}
549-
let Some(origin) = self.infcx.type_var_origin(ty) else {
550+
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
550551
return ty.super_fold_with(self);
551552
};
553+
let origin = self.infcx.type_var_origin(vid);
552554
if let Some(def_id) = origin.param_def_id {
553555
// The generics of an `impl` don't have a parent, we can index directly.
554556
let index = self.generics.param_def_id_to_index[&def_id];

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use rustc_middle::ty::trait_def::TraitSpecializationKind;
7878
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
7979
use rustc_middle::ty::{GenericArg, GenericArgs, GenericArgsRef};
8080
use rustc_span::{ErrorGuaranteed, Span};
81-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
81+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
8282
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
8383
use rustc_trait_selection::traits::{self, translate_args_with_cause, wf, ObligationCtxt};
8484

compiler/rustc_hir_typeck/src/coercion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ use rustc_session::parse::feature_err;
5858
use rustc_span::symbol::sym;
5959
use rustc_span::{BytePos, DesugaringKind, Span, DUMMY_SP};
6060
use rustc_target::spec::abi::Abi;
61-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt;
62-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtSelectionErrExt as _;
6361
use rustc_trait_selection::infer::InferCtxtExt as _;
6462
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
6563
use rustc_trait_selection::traits::{

compiler/rustc_hir_typeck/src/expr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ use rustc_span::source_map::Spanned;
5353
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5454
use rustc_span::Span;
5555
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
56-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt as _;
57-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt;
5856
use rustc_trait_selection::infer::InferCtxtExt;
5957
use rustc_trait_selection::traits::ObligationCtxt;
6058
use rustc_trait_selection::traits::{self, ObligationCauseCode};
@@ -2574,7 +2572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25742572
base: &'tcx hir::Expr<'tcx>,
25752573
ty: Ty<'tcx>,
25762574
) {
2577-
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
2575+
let Some(output_ty) = self.err_ctxt().get_impl_future_output_ty(ty) else {
25782576
err.span_label(field_ident.span, "unknown field");
25792577
return;
25802578
};

compiler/rustc_hir_typeck/src/fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
175175
};
176176
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
177177

178-
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
178+
let span = ty.ty_vid().map_or(DUMMY_SP, |vid| self.infcx.type_var_origin(vid).span);
179179
self.demand_eqtype(span, ty, fallback);
180180
self.fallback_has_occurred.set(true);
181181
true

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_hir_analysis::hir_ty_lowering::{
1919
GenericPathSegment, HirTyLowerer, IsMethodCall, RegionInferReason,
2020
};
2121
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
22-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
2322
use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
2423
use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
2524
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
@@ -37,7 +36,7 @@ use rustc_span::hygiene::DesugaringKind;
3736
use rustc_span::symbol::{kw, sym};
3837
use rustc_span::Span;
3938
use rustc_target::abi::FieldIdx;
40-
use rustc_trait_selection::error_reporting::traits::TypeErrCtxtExt as _;
39+
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
4140
use rustc_trait_selection::traits::{
4241
self, NormalizeExt, ObligationCauseCode, ObligationCtxt, StructurallyNormalizeExt,
4342
};

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338338
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindAmbiguousParameter<'_, 'tcx> {
339339
type Result = ControlFlow<ty::GenericArg<'tcx>>;
340340
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
341-
if let Some(origin) = self.0.type_var_origin(ty)
342-
&& let Some(def_id) = origin.param_def_id
341+
if let ty::Infer(ty::TyVar(vid)) = *ty.kind()
342+
&& let Some(def_id) = self.0.type_var_origin(vid).param_def_id
343343
&& let generics = self.0.tcx.generics_of(self.1)
344344
&& let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id)
345345
&& let Some(arg) =

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
2929
use rustc_hir_analysis::check::potentially_plural_count;
3030
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
3131
use rustc_index::IndexVec;
32-
use rustc_infer::error_reporting::infer::{FailureCode, ObligationCauseExt};
3332
use rustc_infer::infer::TypeTrace;
3433
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
3534
use rustc_middle::ty::adjustment::AllowTwoPhase;
@@ -39,6 +38,7 @@ use rustc_middle::{bug, span_bug};
3938
use rustc_session::Session;
4039
use rustc_span::symbol::{kw, Ident};
4140
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
41+
use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt};
4242
use rustc_trait_selection::infer::InferCtxtExt;
4343
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
4444

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use hir::def_id::CRATE_DEF_ID;
1515
use rustc_hir as hir;
1616
use rustc_hir::def_id::{DefId, LocalDefId};
1717
use rustc_hir_analysis::hir_ty_lowering::{HirTyLowerer, RegionInferReason};
18-
use rustc_infer::error_reporting::infer::sub_relations::SubRelations;
19-
use rustc_infer::error_reporting::infer::TypeErrCtxt;
2018
use rustc_infer::infer;
2119
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
2220
use rustc_session::Session;
2321
use rustc_span::symbol::Ident;
2422
use rustc_span::{self, sym, Span, DUMMY_SP};
23+
use rustc_trait_selection::error_reporting::infer::sub_relations::SubRelations;
24+
use rustc_trait_selection::error_reporting::TypeErrCtxt;
2525
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
2626

2727
use std::cell::{Cell, RefCell};
@@ -162,9 +162,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
162162

163163
/// Creates an `TypeErrCtxt` with a reference to the in-progress
164164
/// `TypeckResults` which is used for diagnostics.
165-
/// Use [`InferCtxt::err_ctxt`] to start one without a `TypeckResults`.
165+
/// Use [`InferCtxtErrorExt::err_ctxt`] to start one without a `TypeckResults`.
166166
///
167-
/// [`InferCtxt::err_ctxt`]: infer::InferCtxt::err_ctxt
167+
/// [`InferCtxtErrorExt::err_ctxt`]: rustc_trait_selection::error_reporting::InferCtxtErrorExt::err_ctxt
168168
pub fn err_ctxt(&'a self) -> TypeErrCtxt<'a, 'tcx> {
169169
let mut sub_relations = SubRelations::default();
170170
sub_relations.add_constraints(

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use rustc_session::errors::ExprParenthesesNeeded;
3232
use rustc_span::source_map::Spanned;
3333
use rustc_span::symbol::{sym, Ident};
3434
use rustc_span::{Span, Symbol};
35-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt;
3635
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
36+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3737
use rustc_trait_selection::infer::InferCtxtExt;
3838
use rustc_trait_selection::traits;
3939
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -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/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_hir::HirId;
1212
use rustc_hir_analysis::autoderef::{self, Autoderef};
1313
use rustc_infer::infer::canonical::OriginalQueryValues;
1414
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
15-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
1615
use rustc_infer::infer::DefineOpaqueTypes;
1716
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
1817
use rustc_infer::traits::ObligationCauseCode;
@@ -34,6 +33,7 @@ use rustc_span::edit_distance::{
3433
};
3534
use rustc_span::symbol::sym;
3635
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
36+
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
3737
use rustc_trait_selection::infer::InferCtxtExt as _;
3838
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3939
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;

0 commit comments

Comments
 (0)