Skip to content

Commit f49738b

Browse files
Move need_type_info too
1 parent 5accaf3 commit f49738b

File tree

8 files changed

+23
-42
lines changed

8 files changed

+23
-42
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use rustc_hir_analysis::hir_ty_lowering::{
1818
ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer,
1919
GenericPathSegment, HirTyLowerer, IsMethodCall, RegionInferReason,
2020
};
21+
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
2122
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
22-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
2323
use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
2424
use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
2525
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use rustc_hir as hir;
1010
use rustc_hir::def::DefKind;
1111
use rustc_hir::HirId;
1212
use rustc_hir_analysis::autoderef::{self, Autoderef};
13+
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
1314
use rustc_infer::infer::canonical::OriginalQueryValues;
1415
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
15-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
1616
use rustc_infer::infer::DefineOpaqueTypes;
1717
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
1818
use rustc_infer::traits::ObligationCauseCode;

compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{ErrorGuaranteed, StashKey};
88
use rustc_hir as hir;
99
use rustc_hir::intravisit::{self, Visitor};
1010
use rustc_hir::HirId;
11-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
11+
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::traits::ObligationCause;
1414
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ use crate::traits::{
8484
mod note_and_explain;
8585
mod suggest;
8686

87+
pub mod need_type_info;
88+
pub mod nice_region_error;
8789
pub mod region;
8890
pub mod sub_relations;
8991

90-
pub mod nice_region_error;
91-
9292
/// Makes a valid string literal from a string by escaping special characters (" and \),
9393
/// unless they are already escaped.
9494
fn escape_literal(s: &str) -> String {

compiler/rustc_infer/src/infer/need_type_info.rs renamed to compiler/rustc_infer/src/error_reporting/infer/need_type_info.rs

+6-33
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::intravisit::{self, Visitor};
1313
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
1414
use rustc_middle::bug;
1515
use rustc_middle::hir::nested_filter;
16-
use rustc_middle::infer::unify_key::ConstVariableValue;
1716
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
1817
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
1918
use rustc_middle::ty::{
@@ -183,9 +182,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
183182
warn!("resolved ty var in error message");
184183
}
185184

186-
let mut infcx_inner = infcx.inner.borrow_mut();
187-
let ty_vars = infcx_inner.type_variables();
188-
let var_origin = ty_vars.var_origin(ty_vid);
185+
let var_origin = infcx.type_var_origin(ty_vid);
189186
if let Some(def_id) = var_origin.param_def_id
190187
// The `Self` param of a trait has the def-id of the trait,
191188
// since it's a synthetic parameter.
@@ -206,24 +203,8 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
206203
}
207204
};
208205
printer.ty_infer_name_resolver = Some(Box::new(ty_getter));
209-
let const_getter = move |ct_vid| match infcx
210-
.inner
211-
.borrow_mut()
212-
.const_unification_table()
213-
.probe_value(ct_vid)
214-
{
215-
ConstVariableValue::Known { value: _ } => {
216-
warn!("resolved const var in error message");
217-
None
218-
}
219-
ConstVariableValue::Unknown { origin, universe: _ } => {
220-
if let Some(def_id) = origin.param_def_id {
221-
Some(infcx.tcx.item_name(def_id))
222-
} else {
223-
None
224-
}
225-
}
226-
};
206+
let const_getter =
207+
move |ct_vid| Some(infcx.tcx.item_name(infcx.const_var_origin(ct_vid)?.param_def_id?));
227208
printer.const_infer_name_resolver = Some(Box::new(const_getter));
228209
printer
229210
}
@@ -300,9 +281,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
300281
match arg.unpack() {
301282
GenericArgKind::Type(ty) => {
302283
if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() {
303-
let mut inner = self.inner.borrow_mut();
304-
let ty_vars = &inner.type_variables();
305-
let var_origin = ty_vars.var_origin(ty_vid);
284+
let var_origin = self.infcx.type_var_origin(ty_vid);
306285
if let Some(def_id) = var_origin.param_def_id
307286
// The `Self` param of a trait has the def-id of the trait,
308287
// since it's a synthetic parameter.
@@ -332,13 +311,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
332311
}
333312
GenericArgKind::Const(ct) => {
334313
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
335-
let origin =
336-
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
337-
ConstVariableValue::Known { value } => {
338-
bug!("resolved infer var: {vid:?} {value}")
339-
}
340-
ConstVariableValue::Unknown { origin, universe: _ } => origin,
341-
};
314+
let origin = self.const_var_origin(vid).expect("expected unresolved const var");
342315
if let Some(def_id) = origin.param_def_id {
343316
return InferenceDiagnosticsData {
344317
name: self.tcx.item_name(def_id).to_string(),
@@ -885,7 +858,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
885858
use ty::InferConst::*;
886859
match (inner_ct.kind(), target_ct.kind()) {
887860
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => {
888-
self.tecx.inner.borrow_mut().const_unification_table().unioned(a_vid, b_vid)
861+
self.tecx.root_const_var(a_vid) == self.tecx.root_const_var(b_vid)
889862
}
890863
_ => false,
891864
}

compiler/rustc_infer/src/errors/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use rustc_span::symbol::kw;
1515
use rustc_span::Symbol;
1616
use rustc_span::{symbol::Ident, BytePos, Span};
1717

18+
use crate::error_reporting::infer::need_type_info::UnderspecifiedArgKind;
1819
use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
1920
use crate::error_reporting::infer::ObligationCauseAsDiagArg;
2021
use crate::fluent_generated as fluent;
21-
use crate::infer::need_type_info::UnderspecifiedArgKind;
2222

2323
use std::path::PathBuf;
2424

compiler/rustc_infer/src/infer/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ pub mod relate;
6565
pub mod resolve;
6666
pub(crate) mod snapshot;
6767
pub mod type_variable;
68-
// FIXME(error_reporting): Where should we put this?
69-
pub mod need_type_info;
7068

7169
#[must_use]
7270
#[derive(Debug)]
@@ -725,6 +723,16 @@ impl<'tcx> InferCtxt<'tcx> {
725723
self.inner.borrow_mut().type_variables().var_origin(vid)
726724
}
727725

726+
/// Returns the origin of the const variable identified by `vid`
727+
// FIXME: We should store origins separately from the unification table
728+
// so this doesn't need to be optional.
729+
pub fn const_var_origin(&self, vid: ConstVid) -> Option<ConstVariableOrigin> {
730+
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
731+
ConstVariableValue::Known { .. } => None,
732+
ConstVariableValue::Unknown { origin, .. } => Some(origin),
733+
}
734+
}
735+
728736
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
729737
freshen::TypeFreshener::new(self)
730738
}

compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::def_id::DefId;
99
use rustc_hir::intravisit::Visitor as _;
1010
use rustc_hir::LangItem;
11+
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
1112
use rustc_infer::error_reporting::infer::TypeErrCtxt;
12-
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
1313
use rustc_infer::infer::{BoundRegionConversionTime, InferCtxt};
1414
use rustc_infer::traits::util::elaborate;
1515
use rustc_infer::traits::{

0 commit comments

Comments
 (0)