mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Move need_type_info too
This commit is contained in:
parent
5accaf3af4
commit
f49738ba6c
@ -18,8 +18,8 @@ use rustc_hir_analysis::hir_ty_lowering::{
|
||||
ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer,
|
||||
GenericPathSegment, HirTyLowerer, IsMethodCall, RegionInferReason,
|
||||
};
|
||||
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
|
||||
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
|
||||
use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
|
||||
|
@ -10,9 +10,9 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
||||
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::infer::DefineOpaqueTypes;
|
||||
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
|
||||
use rustc_infer::traits::ObligationCauseCode;
|
||||
|
@ -8,7 +8,7 @@ use rustc_errors::{ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
|
||||
|
@ -84,11 +84,11 @@ use crate::traits::{
|
||||
mod note_and_explain;
|
||||
mod suggest;
|
||||
|
||||
pub mod need_type_info;
|
||||
pub mod nice_region_error;
|
||||
pub mod region;
|
||||
pub mod sub_relations;
|
||||
|
||||
pub mod nice_region_error;
|
||||
|
||||
/// Makes a valid string literal from a string by escaping special characters (" and \),
|
||||
/// unless they are already escaped.
|
||||
fn escape_literal(s: &str) -> String {
|
||||
|
@ -13,7 +13,6 @@ use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::infer::unify_key::ConstVariableValue;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
|
||||
use rustc_middle::ty::{
|
||||
@ -183,9 +182,7 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
|
||||
warn!("resolved ty var in error message");
|
||||
}
|
||||
|
||||
let mut infcx_inner = infcx.inner.borrow_mut();
|
||||
let ty_vars = infcx_inner.type_variables();
|
||||
let var_origin = ty_vars.var_origin(ty_vid);
|
||||
let var_origin = infcx.type_var_origin(ty_vid);
|
||||
if let Some(def_id) = var_origin.param_def_id
|
||||
// The `Self` param of a trait has the def-id of the trait,
|
||||
// since it's a synthetic parameter.
|
||||
@ -206,24 +203,8 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
|
||||
}
|
||||
};
|
||||
printer.ty_infer_name_resolver = Some(Box::new(ty_getter));
|
||||
let const_getter = move |ct_vid| match infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.const_unification_table()
|
||||
.probe_value(ct_vid)
|
||||
{
|
||||
ConstVariableValue::Known { value: _ } => {
|
||||
warn!("resolved const var in error message");
|
||||
None
|
||||
}
|
||||
ConstVariableValue::Unknown { origin, universe: _ } => {
|
||||
if let Some(def_id) = origin.param_def_id {
|
||||
Some(infcx.tcx.item_name(def_id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let const_getter =
|
||||
move |ct_vid| Some(infcx.tcx.item_name(infcx.const_var_origin(ct_vid)?.param_def_id?));
|
||||
printer.const_infer_name_resolver = Some(Box::new(const_getter));
|
||||
printer
|
||||
}
|
||||
@ -300,9 +281,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
match arg.unpack() {
|
||||
GenericArgKind::Type(ty) => {
|
||||
if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let ty_vars = &inner.type_variables();
|
||||
let var_origin = ty_vars.var_origin(ty_vid);
|
||||
let var_origin = self.infcx.type_var_origin(ty_vid);
|
||||
if let Some(def_id) = var_origin.param_def_id
|
||||
// The `Self` param of a trait has the def-id of the trait,
|
||||
// since it's a synthetic parameter.
|
||||
@ -332,13 +311,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
}
|
||||
GenericArgKind::Const(ct) => {
|
||||
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
|
||||
let origin =
|
||||
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
|
||||
ConstVariableValue::Known { value } => {
|
||||
bug!("resolved infer var: {vid:?} {value}")
|
||||
}
|
||||
ConstVariableValue::Unknown { origin, universe: _ } => origin,
|
||||
};
|
||||
let origin = self.const_var_origin(vid).expect("expected unresolved const var");
|
||||
if let Some(def_id) = origin.param_def_id {
|
||||
return InferenceDiagnosticsData {
|
||||
name: self.tcx.item_name(def_id).to_string(),
|
||||
@ -885,7 +858,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
||||
use ty::InferConst::*;
|
||||
match (inner_ct.kind(), target_ct.kind()) {
|
||||
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => {
|
||||
self.tecx.inner.borrow_mut().const_unification_table().unioned(a_vid, b_vid)
|
||||
self.tecx.root_const_var(a_vid) == self.tecx.root_const_var(b_vid)
|
||||
}
|
||||
_ => false,
|
||||
}
|
@ -15,10 +15,10 @@ use rustc_span::symbol::kw;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::{symbol::Ident, BytePos, Span};
|
||||
|
||||
use crate::error_reporting::infer::need_type_info::UnderspecifiedArgKind;
|
||||
use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
|
||||
use crate::error_reporting::infer::ObligationCauseAsDiagArg;
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::infer::need_type_info::UnderspecifiedArgKind;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -65,8 +65,6 @@ pub mod relate;
|
||||
pub mod resolve;
|
||||
pub(crate) mod snapshot;
|
||||
pub mod type_variable;
|
||||
// FIXME(error_reporting): Where should we put this?
|
||||
pub mod need_type_info;
|
||||
|
||||
#[must_use]
|
||||
#[derive(Debug)]
|
||||
@ -725,6 +723,16 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
self.inner.borrow_mut().type_variables().var_origin(vid)
|
||||
}
|
||||
|
||||
/// Returns the origin of the const variable identified by `vid`
|
||||
// FIXME: We should store origins separately from the unification table
|
||||
// so this doesn't need to be optional.
|
||||
pub fn const_var_origin(&self, vid: ConstVid) -> Option<ConstVariableOrigin> {
|
||||
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
|
||||
ConstVariableValue::Known { .. } => None,
|
||||
ConstVariableValue::Unknown { origin, .. } => Some(origin),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
|
||||
freshen::TypeFreshener::new(self)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::Visitor as _;
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_infer::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::error_reporting::infer::TypeErrCtxt;
|
||||
use rustc_infer::infer::need_type_info::TypeAnnotationNeeded;
|
||||
use rustc_infer::infer::{BoundRegionConversionTime, InferCtxt};
|
||||
use rustc_infer::traits::util::elaborate;
|
||||
use rustc_infer::traits::{
|
||||
|
Loading…
Reference in New Issue
Block a user