1
Fork 0
This commit is contained in:
Michael Goulet 2024-04-05 12:07:59 -04:00
parent ba6c166ee4
commit 25c0cf0a66
6 changed files with 15 additions and 25 deletions

View file

@ -100,11 +100,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Create a type variable (for now) to represent the closure kind. // Create a type variable (for now) to represent the closure kind.
// It will be unified during the upvar inference phase (`upvar.rs`) // It will be unified during the upvar inference phase (`upvar.rs`)
None => self.next_ty_var(TypeVariableOrigin { None => {
// FIXME(eddyb) distinguish closure kind inference variables from the rest. self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
param_def_id: None, }
span: expr_span,
}),
}; };
let closure_args = ty::ClosureArgs::new( let closure_args = ty::ClosureArgs::new(

View file

@ -1365,13 +1365,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let max_len = cmp::max(expected_len, elements.len()); let max_len = cmp::max(expected_len, elements.len());
let element_tys_iter = (0..max_len).map(|_| { let element_tys_iter =
self.next_ty_var( (0..max_len).map(|_| self.next_ty_var(TypeVariableOrigin { param_def_id: None, span }));
// FIXME: `MiscVariable` for now -- obtaining the span and name information
// from all tuple elements isn't trivial.
TypeVariableOrigin { param_def_id: None, span },
)
});
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter); let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
let pat_ty = Ty::new_tup(tcx, element_tys); let pat_ty = Ty::new_tup(tcx, element_tys);
if let Some(err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, pat_info.top_info) { if let Some(err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, pat_info.top_info) {

View file

@ -65,9 +65,6 @@ impl<'tcx> InferCtxt<'tcx> {
let span = if span.contains(def_span) { def_span } else { span }; let span = if span.contains(def_span) { def_span } else { span };
let code = traits::ObligationCauseCode::OpaqueReturnType(None); let code = traits::ObligationCauseCode::OpaqueReturnType(None);
let cause = ObligationCause::new(span, body_id, code); let cause = ObligationCause::new(span, body_id, code);
// FIXME(compiler-errors): We probably should add a new TypeVariableOriginKind
// for opaque types, and then use that kind to fix the spans for type errors
// that we see later on.
let ty_var = self.next_ty_var(TypeVariableOrigin { param_def_id: None, span }); let ty_var = self.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
obligations.extend( obligations.extend(
self.handle_opaque_type(ty, ty_var, &cause, param_env).unwrap().obligations, self.handle_opaque_type(ty, ty_var, &cause, param_env).unwrap().obligations,

View file

@ -37,7 +37,9 @@ pub struct TypeVariableTable<'a, 'tcx> {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct TypeVariableOrigin { pub struct TypeVariableOrigin {
pub span: Span, pub span: Span,
// `DefId` of the type parameter this was instantiated for, if any. /// `DefId` of the type parameter this was instantiated for, if any.
///
/// This should only be used for diagnostics.
pub param_def_id: Option<DefId>, pub param_def_id: Option<DefId>,
} }

View file

@ -1,9 +1,8 @@
use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, TyKind}; use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, TyKind};
use rustc_hir::{Path, QPath}; use rustc_hir::{Path, QPath};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_infer::traits::{Obligation, ObligationCause};
use rustc_middle::query::Key;
use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable, TypeFolder}; use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable, TypeFolder};
use rustc_middle::ty::{EarlyBinder, TraitRef, TypeSuperFoldable}; use rustc_middle::ty::{EarlyBinder, TraitRef, TypeSuperFoldable};
use rustc_span::def_id::{DefId, LOCAL_CRATE}; use rustc_span::def_id::{DefId, LOCAL_CRATE};
@ -313,13 +312,10 @@ impl<'a, 'tcx, F: FnMut(DefId) -> bool> TypeFolder<TyCtxt<'tcx>>
} }
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if let Some(ty_did) = t.ty_def_id() if let Some(def) = t.ty_adt_def()
&& (self.did_has_local_parent)(ty_did) && (self.did_has_local_parent)(def.did())
{ {
self.infcx.next_ty_var(TypeVariableOrigin { self.infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.infer_span })
kind: TypeVariableOriginKind::TypeInference,
span: self.infer_span,
})
} else { } else {
t.super_fold_with(self) t.super_fold_with(self)
} }

View file

@ -106,7 +106,9 @@ impl ToType for ty::FloatVarValue {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct ConstVariableOrigin { pub struct ConstVariableOrigin {
pub span: Span, pub span: Span,
// `DefId` of the const parameter this was instantiated for, if any. /// `DefId` of the const parameter this was instantiated for, if any.
///
/// This should only be used for diagnostics.
pub param_def_id: Option<DefId>, pub param_def_id: Option<DefId>,
} }