mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #124955 - nnethercote:next_ty_var, r=lcnr
Use fewer origins when creating type variables. To reduce lots of repetitive boilerplate code. Details in the individual commit messages. r? ``@lcnr``
This commit is contained in:
commit
0ee258009c
@ -11,7 +11,6 @@ use std::assert_matches::assert_matches;
|
|||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
|
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
@ -74,9 +73,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let next_ty_var = || {
|
let next_ty_var = || self.infcx.next_ty_var(body.span);
|
||||||
self.infcx.next_ty_var(TypeVariableOrigin { span: body.span, param_def_id: None })
|
|
||||||
};
|
|
||||||
let output_ty = Ty::new_coroutine(
|
let output_ty = Ty::new_coroutine(
|
||||||
self.tcx(),
|
self.tcx(),
|
||||||
self.tcx().coroutine_for_closure(mir_def_id),
|
self.tcx().coroutine_for_closure(mir_def_id),
|
||||||
|
@ -16,7 +16,6 @@ use rustc_index::{IndexSlice, IndexVec};
|
|||||||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||||
use rustc_infer::infer::outlives::env::RegionBoundPairs;
|
use rustc_infer::infer::outlives::env::RegionBoundPairs;
|
||||||
use rustc_infer::infer::region_constraints::RegionConstraintData;
|
use rustc_infer::infer::region_constraints::RegionConstraintData;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{
|
use rustc_infer::infer::{
|
||||||
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
|
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
|
||||||
};
|
};
|
||||||
@ -2356,10 +2355,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// Types with regions are comparable if they have a common super-type.
|
// Types with regions are comparable if they have a common super-type.
|
||||||
ty::RawPtr(_, _) | ty::FnPtr(_) => {
|
ty::RawPtr(_, _) | ty::FnPtr(_) => {
|
||||||
let ty_right = right.ty(body, tcx);
|
let ty_right = right.ty(body, tcx);
|
||||||
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
|
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
|
||||||
param_def_id: None,
|
|
||||||
span: body.source_info(location).span,
|
|
||||||
});
|
|
||||||
self.sub_types(
|
self.sub_types(
|
||||||
ty_left,
|
ty_left,
|
||||||
common_ty,
|
common_ty,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||||
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
|
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
|
||||||
use rustc_infer::traits::{Obligation, PredicateObligations};
|
use rustc_infer::traits::{Obligation, PredicateObligations};
|
||||||
@ -129,10 +128,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
|||||||
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
|
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
|
||||||
// the opaque.
|
// the opaque.
|
||||||
let mut enable_subtyping = |ty, opaque_is_expected| {
|
let mut enable_subtyping = |ty, opaque_is_expected| {
|
||||||
let ty_vid = infcx.next_ty_var_id_in_universe(
|
let ty_vid = infcx.next_ty_var_id_in_universe(self.span(), ty::UniverseIndex::ROOT);
|
||||||
TypeVariableOrigin { param_def_id: None, span: self.span() },
|
|
||||||
ty::UniverseIndex::ROOT,
|
|
||||||
);
|
|
||||||
|
|
||||||
let variance = if opaque_is_expected {
|
let variance = if opaque_is_expected {
|
||||||
self.ambient_variance
|
self.ambient_variance
|
||||||
|
@ -9,7 +9,6 @@ use rustc_hir::def::{DefKind, Res};
|
|||||||
use rustc_hir::intravisit;
|
use rustc_hir::intravisit;
|
||||||
use rustc_hir::{GenericParamKind, ImplItemKind};
|
use rustc_hir::{GenericParamKind, ImplItemKind};
|
||||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
|
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
|
||||||
use rustc_infer::traits::{util, FulfillmentError};
|
use rustc_infer::traits::{util, FulfillmentError};
|
||||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||||
@ -800,10 +799,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
|
|||||||
bug!("FIXME(RPITIT): error here");
|
bug!("FIXME(RPITIT): error here");
|
||||||
}
|
}
|
||||||
// Replace with infer var
|
// Replace with infer var
|
||||||
let infer_ty = self
|
let infer_ty = self.ocx.infcx.next_ty_var(self.span);
|
||||||
.ocx
|
|
||||||
.infcx
|
|
||||||
.next_ty_var(TypeVariableOrigin { span: self.span, param_def_id: None });
|
|
||||||
self.types.insert(proj.def_id, (infer_ty, proj.args));
|
self.types.insert(proj.def_id, (infer_ty, proj.args));
|
||||||
// Recurse into bounds
|
// Recurse into bounds
|
||||||
for (pred, pred_span) in self
|
for (pred, pred_span) in self
|
||||||
|
@ -5,7 +5,6 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
|
|||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::{self as hir, ExprKind, PatKind};
|
use rustc_hir::{self as hir, ExprKind, PatKind};
|
||||||
use rustc_hir_pretty::ty_to_string;
|
use rustc_hir_pretty::ty_to_string;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::traits::{
|
use rustc_trait_selection::traits::{
|
||||||
@ -67,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// arm for inconsistent arms or to the whole match when a `()` type
|
// arm for inconsistent arms or to the whole match when a `()` type
|
||||||
// is required).
|
// is required).
|
||||||
Expectation::ExpectHasType(ety) if ety != tcx.types.unit => ety,
|
Expectation::ExpectHasType(ety) if ety != tcx.types.unit => ety,
|
||||||
_ => self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span }),
|
_ => self.next_ty_var(expr.span),
|
||||||
};
|
};
|
||||||
CoerceMany::with_coercion_sites(coerce_first, arms)
|
CoerceMany::with_coercion_sites(coerce_first, arms)
|
||||||
};
|
};
|
||||||
@ -575,8 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// ...but otherwise we want to use any supertype of the
|
// ...but otherwise we want to use any supertype of the
|
||||||
// scrutinee. This is sort of a workaround, see note (*) in
|
// scrutinee. This is sort of a workaround, see note (*) in
|
||||||
// `check_pat` for some details.
|
// `check_pat` for some details.
|
||||||
let scrut_ty =
|
let scrut_ty = self.next_ty_var(scrut.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: scrut.span });
|
|
||||||
self.check_expr_has_type_or_error(scrut, scrut_ty, |_| {});
|
self.check_expr_has_type_or_error(scrut, scrut_ty, |_| {});
|
||||||
scrut_ty
|
scrut_ty
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,8 @@ use rustc_hir::def_id::DefId;
|
|||||||
use rustc_hir_analysis::autoderef::Autoderef;
|
use rustc_hir_analysis::autoderef::Autoderef;
|
||||||
use rustc_infer::{
|
use rustc_infer::{
|
||||||
infer,
|
infer,
|
||||||
traits::{self, Obligation},
|
traits::{self, Obligation, ObligationCause},
|
||||||
};
|
};
|
||||||
use rustc_infer::{infer::type_variable::TypeVariableOrigin, traits::ObligationCause};
|
|
||||||
use rustc_middle::ty::adjustment::{
|
use rustc_middle::ty::adjustment::{
|
||||||
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
||||||
};
|
};
|
||||||
@ -180,14 +179,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
infer::FnCall,
|
infer::FnCall,
|
||||||
closure_args.coroutine_closure_sig(),
|
closure_args.coroutine_closure_sig(),
|
||||||
);
|
);
|
||||||
let tupled_upvars_ty = self
|
let tupled_upvars_ty = self.next_ty_var(callee_expr.span);
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
|
|
||||||
// We may actually receive a coroutine back whose kind is different
|
// We may actually receive a coroutine back whose kind is different
|
||||||
// from the closure that this dispatched from. This is because when
|
// from the closure that this dispatched from. This is because when
|
||||||
// we have no captures, we automatically implement `FnOnce`. This
|
// we have no captures, we automatically implement `FnOnce`. This
|
||||||
// impl forces the closure kind to `FnOnce` i.e. `u8`.
|
// impl forces the closure kind to `FnOnce` i.e. `u8`.
|
||||||
let kind_ty = self
|
let kind_ty = self.next_ty_var(callee_expr.span);
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: callee_expr.span });
|
|
||||||
let call_sig = self.tcx.mk_fn_sig(
|
let call_sig = self.tcx.mk_fn_sig(
|
||||||
[coroutine_closure_sig.tupled_inputs_ty],
|
[coroutine_closure_sig.tupled_inputs_ty],
|
||||||
coroutine_closure_sig.to_coroutine(
|
coroutine_closure_sig.to_coroutine(
|
||||||
@ -298,12 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let Some(trait_def_id) = opt_trait_def_id else { continue };
|
let Some(trait_def_id) = opt_trait_def_id else { continue };
|
||||||
|
|
||||||
let opt_input_type = opt_arg_exprs.map(|arg_exprs| {
|
let opt_input_type = opt_arg_exprs.map(|arg_exprs| {
|
||||||
Ty::new_tup_from_iter(
|
Ty::new_tup_from_iter(self.tcx, arg_exprs.iter().map(|e| self.next_ty_var(e.span)))
|
||||||
self.tcx,
|
|
||||||
arg_exprs.iter().map(|e| {
|
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: e.span })
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(ok) = self.lookup_method_in_trait(
|
if let Some(ok) = self.lookup_method_in_trait(
|
||||||
|
@ -8,7 +8,6 @@ use rustc_hir::def::DefKind;
|
|||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir_analysis::check::{check_function_signature, forbid_intrinsic_abi};
|
use rustc_hir_analysis::check::{check_function_signature, forbid_intrinsic_abi};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::RegionVariableOrigin;
|
use rustc_infer::infer::RegionVariableOrigin;
|
||||||
use rustc_infer::traits::WellFormedLoc;
|
use rustc_infer::traits::WellFormedLoc;
|
||||||
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
|
||||||
@ -142,7 +141,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||||||
// We have special-cased the case where the function is declared
|
// We have special-cased the case where the function is declared
|
||||||
// `-> dyn Foo` and we don't actually relate it to the
|
// `-> dyn Foo` and we don't actually relate it to the
|
||||||
// `fcx.ret_coercion`, so just instantiate a type variable.
|
// `fcx.ret_coercion`, so just instantiate a type variable.
|
||||||
actual_return_ty = fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
|
actual_return_ty = fcx.next_ty_var(span);
|
||||||
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
|
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ use rustc_errors::ErrorGuaranteed;
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
||||||
use rustc_infer::infer::{InferOk, InferResult};
|
use rustc_infer::infer::{InferOk, InferResult};
|
||||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||||
@ -73,8 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let parent_args =
|
let parent_args =
|
||||||
GenericArgs::identity_for_item(tcx, tcx.typeck_root_def_id(expr_def_id.to_def_id()));
|
GenericArgs::identity_for_item(tcx, tcx.typeck_root_def_id(expr_def_id.to_def_id()));
|
||||||
|
|
||||||
let tupled_upvars_ty =
|
let tupled_upvars_ty = self.next_ty_var(expr_span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
|
||||||
|
|
||||||
// FIXME: We could probably actually just unify this further --
|
// FIXME: We could probably actually just unify this further --
|
||||||
// instead of having a `FnSig` and a `Option<CoroutineTypes>`,
|
// instead of having a `FnSig` and a `Option<CoroutineTypes>`,
|
||||||
@ -101,9 +99,7 @@ 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 => {
|
None => self.next_ty_var(expr_span),
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let closure_args = ty::ClosureArgs::new(
|
let closure_args = ty::ClosureArgs::new(
|
||||||
@ -122,10 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let yield_ty = match kind {
|
let yield_ty = match kind {
|
||||||
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
|
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
|
||||||
| hir::CoroutineKind::Coroutine(_) => {
|
| hir::CoroutineKind::Coroutine(_) => {
|
||||||
let yield_ty = self.next_ty_var(TypeVariableOrigin {
|
let yield_ty = self.next_ty_var(expr_span);
|
||||||
param_def_id: None,
|
|
||||||
span: expr_span,
|
|
||||||
});
|
|
||||||
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
||||||
yield_ty
|
yield_ty
|
||||||
}
|
}
|
||||||
@ -134,10 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// in this block in projection correctly. In the new trait solver, it is
|
// in this block in projection correctly. In the new trait solver, it is
|
||||||
// not a problem.
|
// not a problem.
|
||||||
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
|
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
|
||||||
let yield_ty = self.next_ty_var(TypeVariableOrigin {
|
let yield_ty = self.next_ty_var(expr_span);
|
||||||
param_def_id: None,
|
|
||||||
span: expr_span,
|
|
||||||
});
|
|
||||||
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
||||||
|
|
||||||
Ty::new_adt(
|
Ty::new_adt(
|
||||||
@ -163,8 +153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// Resume type defaults to `()` if the coroutine has no argument.
|
// Resume type defaults to `()` if the coroutine has no argument.
|
||||||
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
|
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
|
||||||
|
|
||||||
let interior =
|
let interior = self.next_ty_var(expr_span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
|
||||||
self.deferred_coroutine_interiors.borrow_mut().push((
|
self.deferred_coroutine_interiors.borrow_mut().push((
|
||||||
expr_def_id,
|
expr_def_id,
|
||||||
body.id(),
|
body.id(),
|
||||||
@ -177,7 +166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// ty of `().`
|
// ty of `().`
|
||||||
let kind_ty = match kind {
|
let kind_ty = match kind {
|
||||||
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
|
hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) => {
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
|
self.next_ty_var(expr_span)
|
||||||
}
|
}
|
||||||
_ => tcx.types.unit,
|
_ => tcx.types.unit,
|
||||||
};
|
};
|
||||||
@ -212,23 +201,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Compute all of the variables that will be used to populate the coroutine.
|
// Compute all of the variables that will be used to populate the coroutine.
|
||||||
let resume_ty =
|
let resume_ty = self.next_ty_var(expr_span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
let interior = self.next_ty_var(expr_span);
|
||||||
let interior =
|
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
|
||||||
|
|
||||||
let closure_kind_ty = match expected_kind {
|
let closure_kind_ty = match expected_kind {
|
||||||
Some(kind) => Ty::from_closure_kind(tcx, kind),
|
Some(kind) => Ty::from_closure_kind(tcx, kind),
|
||||||
|
|
||||||
// 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 => {
|
None => self.next_ty_var(expr_span),
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let coroutine_captures_by_ref_ty =
|
let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
|
||||||
let closure_args = ty::CoroutineClosureArgs::new(
|
let closure_args = ty::CoroutineClosureArgs::new(
|
||||||
tcx,
|
tcx,
|
||||||
ty::CoroutineClosureArgsParts {
|
ty::CoroutineClosureArgsParts {
|
||||||
@ -260,13 +244,10 @@ 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 => {
|
None => self.next_ty_var(expr_span),
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span })
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let coroutine_upvars_ty =
|
let coroutine_upvars_ty = self.next_ty_var(expr_span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr_span });
|
|
||||||
|
|
||||||
// We need to turn the liberated signature that we got from HIR, which
|
// We need to turn the liberated signature that we got from HIR, which
|
||||||
// looks something like `|Args...| -> T`, into a signature that is suitable
|
// looks something like `|Args...| -> T`, into a signature that is suitable
|
||||||
|
@ -41,7 +41,6 @@ use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
|
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
|
||||||
use rustc_infer::traits::{IfExpressionCause, MatchExpressionArmCause};
|
use rustc_infer::traits::{IfExpressionCause, MatchExpressionArmCause};
|
||||||
use rustc_infer::traits::{Obligation, PredicateObligation};
|
use rustc_infer::traits::{Obligation, PredicateObligation};
|
||||||
@ -257,11 +256,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
|
|
||||||
if b.is_ty_var() {
|
if b.is_ty_var() {
|
||||||
// Two unresolved type variables: create a `Coerce` predicate.
|
// Two unresolved type variables: create a `Coerce` predicate.
|
||||||
let target_ty = if self.use_lub {
|
let target_ty = if self.use_lub { self.next_ty_var(self.cause.span) } else { b };
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.cause.span })
|
|
||||||
} else {
|
|
||||||
b
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut obligations = Vec::with_capacity(2);
|
let mut obligations = Vec::with_capacity(2);
|
||||||
for &source_ty in &[a, b] {
|
for &source_ty in &[a, b] {
|
||||||
@ -557,8 +552,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
|||||||
// the `CoerceUnsized` target type and the expected type.
|
// the `CoerceUnsized` target type and the expected type.
|
||||||
// We only have the latter, so we use an inference variable
|
// We only have the latter, so we use an inference variable
|
||||||
// for the former and let type inference do the rest.
|
// for the former and let type inference do the rest.
|
||||||
let origin = TypeVariableOrigin { param_def_id: None, span: self.cause.span };
|
let coerce_target = self.next_ty_var(self.cause.span);
|
||||||
let coerce_target = self.next_ty_var(origin);
|
|
||||||
let mut coercion = self.unify_and(coerce_target, target, |target| {
|
let mut coercion = self.unify_and(coerce_target, target, |target| {
|
||||||
let unsize = Adjustment { kind: Adjust::Pointer(PointerCoercion::Unsize), target };
|
let unsize = Adjustment { kind: Adjust::Pointer(PointerCoercion::Unsize), target };
|
||||||
match reborrow {
|
match reborrow {
|
||||||
|
@ -330,16 +330,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
hir.body(hir.maybe_body_owned_by(self.body_id).expect("expected item to have body"));
|
hir.body(hir.maybe_body_owned_by(self.body_id).expect("expected item to have body"));
|
||||||
expr_finder.visit_expr(body.value);
|
expr_finder.visit_expr(body.value);
|
||||||
|
|
||||||
use rustc_infer::infer::type_variable::*;
|
|
||||||
use rustc_middle::infer::unify_key::*;
|
|
||||||
// Replaces all of the variables in the given type with a fresh inference variable.
|
// Replaces all of the variables in the given type with a fresh inference variable.
|
||||||
let mut fudger = BottomUpFolder {
|
let mut fudger = BottomUpFolder {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
ty_op: |ty| {
|
ty_op: |ty| {
|
||||||
if let ty::Infer(infer) = ty.kind() {
|
if let ty::Infer(infer) = ty.kind() {
|
||||||
match infer {
|
match infer {
|
||||||
ty::TyVar(_) => self
|
ty::TyVar(_) => self.next_ty_var(DUMMY_SP),
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP }),
|
|
||||||
ty::IntVar(_) => self.next_int_var(),
|
ty::IntVar(_) => self.next_int_var(),
|
||||||
ty::FloatVar(_) => self.next_float_var(),
|
ty::FloatVar(_) => self.next_float_var(),
|
||||||
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
|
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
|
||||||
@ -353,10 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
lt_op: |_| self.tcx.lifetimes.re_erased,
|
lt_op: |_| self.tcx.lifetimes.re_erased,
|
||||||
ct_op: |ct| {
|
ct_op: |ct| {
|
||||||
if let ty::ConstKind::Infer(_) = ct.kind() {
|
if let ty::ConstKind::Infer(_) = ct.kind() {
|
||||||
self.next_const_var(
|
self.next_const_var(ct.ty(), DUMMY_SP)
|
||||||
ct.ty(),
|
|
||||||
ConstVariableOrigin { param_def_id: None, span: DUMMY_SP },
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
ct
|
ct
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
@ -110,7 +109,6 @@ impl<'a, 'tcx> Expectation<'tcx> {
|
|||||||
/// Like `only_has_type`, but instead of returning `None` if no
|
/// Like `only_has_type`, but instead of returning `None` if no
|
||||||
/// hard constraint exists, creates a fresh type variable.
|
/// hard constraint exists, creates a fresh type variable.
|
||||||
pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> {
|
pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> {
|
||||||
self.only_has_type(fcx)
|
self.only_has_type(fcx).unwrap_or_else(|| fcx.next_ty_var(span))
|
||||||
.unwrap_or_else(|| fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span }))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ use rustc_hir::lang_items::LangItem;
|
|||||||
use rustc_hir::{ExprKind, HirId, QPath};
|
use rustc_hir::{ExprKind, HirId, QPath};
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _;
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::DefineOpaqueTypes;
|
use rustc_infer::infer::DefineOpaqueTypes;
|
||||||
use rustc_infer::infer::InferOk;
|
use rustc_infer::infer::InferOk;
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
@ -80,8 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return Ty::new_error(self.tcx(), reported);
|
return Ty::new_error(self.tcx(), reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let adj_ty =
|
let adj_ty = self.next_ty_var(expr.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span });
|
|
||||||
self.apply_adjustments(
|
self.apply_adjustments(
|
||||||
expr,
|
expr,
|
||||||
vec![Adjustment { kind: Adjust::NeverToAny, target: adj_ty }],
|
vec![Adjustment { kind: Adjust::NeverToAny, target: adj_ty }],
|
||||||
@ -1412,9 +1410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
|
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| self.next_ty_var(expr.span));
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span })
|
|
||||||
});
|
|
||||||
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
|
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
|
||||||
assert_eq!(self.diverges.get(), Diverges::Maybe);
|
assert_eq!(self.diverges.get(), Diverges::Maybe);
|
||||||
for e in args {
|
for e in args {
|
||||||
@ -1424,7 +1420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
coerce.complete(self)
|
coerce.complete(self)
|
||||||
} else {
|
} else {
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span })
|
self.next_ty_var(expr.span)
|
||||||
};
|
};
|
||||||
let array_len = args.len() as u64;
|
let array_len = args.len() as u64;
|
||||||
self.suggest_array_len(expr, array_len);
|
self.suggest_array_len(expr, array_len);
|
||||||
@ -1507,8 +1503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
(uty, uty)
|
(uty, uty)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let ty =
|
let ty = self.next_ty_var(element.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: element.span });
|
|
||||||
let element_ty = self.check_expr_has_type_or_error(element, ty, |_| {});
|
let element_ty = self.check_expr_has_type_or_error(element, ty, |_| {});
|
||||||
(element_ty, ty)
|
(element_ty, ty)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
|||||||
use rustc_hir_analysis::structured_errors::StructuredDiag;
|
use rustc_hir_analysis::structured_errors::StructuredDiag;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
|
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::TypeTrace;
|
use rustc_infer::infer::TypeTrace;
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
use rustc_middle::traits::ObligationCauseCode::ExprBindingObligation;
|
use rustc_middle::traits::ObligationCauseCode::ExprBindingObligation;
|
||||||
@ -40,7 +39,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
|
|||||||
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
|
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::{kw, Ident};
|
use rustc_span::symbol::{kw, Ident};
|
||||||
use rustc_span::{sym, BytePos, Span};
|
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
|
||||||
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
|
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
@ -2180,13 +2179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let trait_ref = ty::TraitRef::new(
|
let trait_ref = ty::TraitRef::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.tcx.fn_trait_kind_to_def_id(call_kind)?,
|
self.tcx.fn_trait_kind_to_def_id(call_kind)?,
|
||||||
[
|
[callee_ty, self.next_ty_var(DUMMY_SP)],
|
||||||
callee_ty,
|
|
||||||
self.next_ty_var(TypeVariableOrigin {
|
|
||||||
param_def_id: None,
|
|
||||||
span: rustc_span::DUMMY_SP,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
let obligation = traits::Obligation::new(
|
let obligation = traits::Obligation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
|
@ -19,8 +19,6 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
|||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
|
use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
|
||||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
|
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
@ -239,7 +237,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
|
|||||||
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
||||||
match param {
|
match param {
|
||||||
Some(param) => self.var_for_def(span, param).as_type().unwrap(),
|
Some(param) => self.var_for_def(span, param).as_type().unwrap(),
|
||||||
None => self.next_ty_var(TypeVariableOrigin { param_def_id: None, span }),
|
None => self.next_ty_var(span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +256,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
|
|||||||
},
|
},
|
||||||
) => self.var_for_effect(param).as_const().unwrap(),
|
) => self.var_for_effect(param).as_const().unwrap(),
|
||||||
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
|
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
|
||||||
None => self.next_const_var(ty, ConstVariableOrigin { span, param_def_id: None }),
|
None => self.next_const_var(ty, span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ use crate::FnCtxt;
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{HirId, PatKind};
|
use rustc_hir::{HirId, PatKind};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_middle::ty::UserType;
|
use rustc_middle::ty::UserType;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
@ -72,7 +71,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
|||||||
match ty_opt {
|
match ty_opt {
|
||||||
None => {
|
None => {
|
||||||
// Infer the variable's type.
|
// Infer the variable's type.
|
||||||
let var_ty = self.fcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
|
let var_ty = self.fcx.next_ty_var(span);
|
||||||
self.fcx.locals.borrow_mut().insert(nid, var_ty);
|
self.fcx.locals.borrow_mut().insert(nid, var_ty);
|
||||||
var_ty
|
var_ty
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ use rustc_hir::intravisit::Visitor;
|
|||||||
use rustc_hir::{HirId, HirIdMap, Node};
|
use rustc_hir::{HirId, HirIdMap, Node};
|
||||||
use rustc_hir_analysis::check::check_abi;
|
use rustc_hir_analysis::check::check_abi;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::traits;
|
use rustc_middle::traits;
|
||||||
@ -246,7 +245,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
|
|||||||
tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args;
|
tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args;
|
||||||
Some(tcx.type_of(trait_item).instantiate(tcx, args))
|
Some(tcx.type_of(trait_item).instantiate(tcx, args))
|
||||||
} else {
|
} else {
|
||||||
Some(fcx.next_ty_var(TypeVariableOrigin { span, param_def_id: None }))
|
Some(fcx.next_ty_var(span))
|
||||||
}
|
}
|
||||||
} else if let Node::AnonConst(_) = node {
|
} else if let Node::AnonConst(_) = node {
|
||||||
let id = tcx.local_def_id_to_hir_id(def_id);
|
let id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
@ -254,7 +253,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
|
|||||||
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), span, .. })
|
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), span, .. })
|
||||||
if anon_const.hir_id == id =>
|
if anon_const.hir_id == id =>
|
||||||
{
|
{
|
||||||
Some(fcx.next_ty_var(TypeVariableOrigin { span, param_def_id: None }))
|
Some(fcx.next_ty_var(span))
|
||||||
}
|
}
|
||||||
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. })
|
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. })
|
||||||
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), span, .. }) => {
|
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), span, .. }) => {
|
||||||
@ -264,7 +263,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
|
|||||||
Some(fcx.next_int_var())
|
Some(fcx.next_int_var())
|
||||||
}
|
}
|
||||||
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
|
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
|
||||||
Some(fcx.next_ty_var(TypeVariableOrigin { span, param_def_id: None }))
|
Some(fcx.next_ty_var(span))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -7,7 +7,6 @@ use hir::HirId;
|
|||||||
use hir::ItemKind;
|
use hir::ItemKind;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
|
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
|
||||||
use rustc_span::symbol::kw::{Empty, Underscore};
|
use rustc_span::symbol::kw::{Empty, Underscore};
|
||||||
@ -218,8 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// If we know it does not, we don't need to warn.
|
// If we know it does not, we don't need to warn.
|
||||||
if method_name.name == sym::from_iter {
|
if method_name.name == sym::from_iter {
|
||||||
if let Some(trait_def_id) = self.tcx.get_diagnostic_item(sym::FromIterator) {
|
if let Some(trait_def_id) = self.tcx.get_diagnostic_item(sym::FromIterator) {
|
||||||
let any_type =
|
let any_type = self.infcx.next_ty_var(span);
|
||||||
self.infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
|
|
||||||
if !self
|
if !self
|
||||||
.infcx
|
.infcx
|
||||||
.type_implements_trait(trait_def_id, [self_ty, any_type], self.param_env)
|
.type_implements_trait(trait_def_id, [self_ty, any_type], self.param_env)
|
||||||
|
@ -22,8 +22,7 @@ use rustc_hir::lang_items::LangItem;
|
|||||||
use rustc_hir::PatKind::Binding;
|
use rustc_hir::PatKind::Binding;
|
||||||
use rustc_hir::PathSegment;
|
use rustc_hir::PathSegment;
|
||||||
use rustc_hir::{ExprKind, Node, QPath};
|
use rustc_hir::{ExprKind, Node, QPath};
|
||||||
use rustc_infer::infer::{self, type_variable::TypeVariableOrigin, RegionVariableOrigin};
|
use rustc_infer::infer::{self, RegionVariableOrigin};
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
|
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
|
||||||
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
||||||
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
|
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
|
||||||
@ -75,11 +74,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.autoderef(span, ty).any(|(ty, _)| {
|
self.autoderef(span, ty).any(|(ty, _)| {
|
||||||
info!("check deref {:?} impl FnOnce", ty);
|
info!("check deref {:?} impl FnOnce", ty);
|
||||||
self.probe(|_| {
|
self.probe(|_| {
|
||||||
let trait_ref = ty::TraitRef::new(
|
let trait_ref =
|
||||||
tcx,
|
ty::TraitRef::new(tcx, fn_once, [ty, self.next_ty_var(span)]);
|
||||||
fn_once,
|
|
||||||
[ty, self.next_ty_var(TypeVariableOrigin { param_def_id: None, span })],
|
|
||||||
);
|
|
||||||
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
||||||
let obligation = Obligation::misc(
|
let obligation = Obligation::misc(
|
||||||
tcx,
|
tcx,
|
||||||
@ -1259,12 +1255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
args.map(|args| {
|
args.map(|args| {
|
||||||
args.iter()
|
args.iter()
|
||||||
.map(|expr| {
|
.map(|expr| {
|
||||||
self.node_ty_opt(expr.hir_id).unwrap_or_else(|| {
|
self.node_ty_opt(expr.hir_id).unwrap_or_else(|| self.next_ty_var(expr.span))
|
||||||
self.next_ty_var(TypeVariableOrigin {
|
|
||||||
param_def_id: None,
|
|
||||||
span: expr.span,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}),
|
}),
|
||||||
@ -1846,18 +1837,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
GenericArgKind::Lifetime(_) => self
|
GenericArgKind::Lifetime(_) => self
|
||||||
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
|
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
|
||||||
.into(),
|
.into(),
|
||||||
GenericArgKind::Type(_) => self
|
GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(),
|
||||||
.next_ty_var(TypeVariableOrigin {
|
GenericArgKind::Const(arg) => {
|
||||||
span: DUMMY_SP,
|
self.next_const_var(arg.ty(), DUMMY_SP).into()
|
||||||
param_def_id: None,
|
}
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
GenericArgKind::Const(arg) => self
|
|
||||||
.next_const_var(
|
|
||||||
arg.ty(),
|
|
||||||
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
arg
|
arg
|
||||||
|
@ -7,7 +7,6 @@ use rustc_ast as ast;
|
|||||||
use rustc_data_structures::packed::Pu128;
|
use rustc_data_structures::packed::Pu128;
|
||||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
|
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::traits::ObligationCauseCode;
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::adjustment::{
|
use rustc_middle::ty::adjustment::{
|
||||||
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
||||||
@ -219,8 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// e.g., adding `&'a T` and `&'b T`, given `&'x T: Add<&'x T>`, will result
|
// e.g., adding `&'a T` and `&'b T`, given `&'x T: Add<&'x T>`, will result
|
||||||
// in `&'a T <: &'x T` and `&'b T <: &'x T`, instead of `'a = 'b = 'x`.
|
// in `&'a T <: &'x T` and `&'b T <: &'x T`, instead of `'a = 'b = 'x`.
|
||||||
let lhs_ty = self.check_expr(lhs_expr);
|
let lhs_ty = self.check_expr(lhs_expr);
|
||||||
let fresh_var = self
|
let fresh_var = self.next_ty_var(lhs_expr.span);
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: lhs_expr.span });
|
|
||||||
self.demand_coerce(lhs_expr, lhs_ty, fresh_var, Some(rhs_expr), AllowTwoPhase::No)
|
self.demand_coerce(lhs_expr, lhs_ty, fresh_var, Some(rhs_expr), AllowTwoPhase::No)
|
||||||
}
|
}
|
||||||
IsAssign::Yes => {
|
IsAssign::Yes => {
|
||||||
@ -239,8 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// using this variable as the expected type, which sometimes lets
|
// using this variable as the expected type, which sometimes lets
|
||||||
// us do better coercions than we would be able to do otherwise,
|
// us do better coercions than we would be able to do otherwise,
|
||||||
// particularly for things like `String + &String`.
|
// particularly for things like `String + &String`.
|
||||||
let rhs_ty_var =
|
let rhs_ty_var = self.next_ty_var(rhs_expr.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: rhs_expr.span });
|
|
||||||
|
|
||||||
let result = self.lookup_op_method(
|
let result = self.lookup_op_method(
|
||||||
(lhs_expr, lhs_ty),
|
(lhs_expr, lhs_ty),
|
||||||
|
@ -9,7 +9,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
|
|||||||
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
|
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
|
||||||
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, Pat, PatKind};
|
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, Pat, PatKind};
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
||||||
@ -1419,8 +1418,7 @@ 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 =
|
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
|
||||||
(0..max_len).map(|_| self.next_ty_var(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) {
|
||||||
@ -2046,8 +2044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
// Here, `demand::subtype` is good enough, but I don't
|
// Here, `demand::subtype` is good enough, but I don't
|
||||||
// think any errors can be introduced by using `demand::eqtype`.
|
// think any errors can be introduced by using `demand::eqtype`.
|
||||||
let inner_ty =
|
let inner_ty = self.next_ty_var(inner.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: inner.span });
|
|
||||||
let box_ty = Ty::new_box(tcx, inner_ty);
|
let box_ty = Ty::new_box(tcx, inner_ty);
|
||||||
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info);
|
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info);
|
||||||
(box_ty, inner_ty)
|
(box_ty, inner_ty)
|
||||||
@ -2142,10 +2139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
.insert(pat.hir_id);
|
.insert(pat.hir_id);
|
||||||
(expected, expected)
|
(expected, expected)
|
||||||
} else {
|
} else {
|
||||||
let inner_ty = self.next_ty_var(TypeVariableOrigin {
|
let inner_ty = self.next_ty_var(inner.span);
|
||||||
param_def_id: None,
|
|
||||||
span: inner.span,
|
|
||||||
});
|
|
||||||
let ref_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
|
let ref_ty = self.new_ref_ty(pat.span, mutbl, inner_ty);
|
||||||
debug!("check_pat_ref: demanding {:?} = {:?}", expected, ref_ty);
|
debug!("check_pat_ref: demanding {:?} = {:?}", expected, ref_ty);
|
||||||
let err = self.demand_eqtype_pat_diag(
|
let err = self.demand_eqtype_pat_diag(
|
||||||
@ -2194,8 +2188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let len = before.len();
|
let len = before.len();
|
||||||
let ty_var_origin = TypeVariableOrigin { param_def_id: None, span };
|
let inner_ty = self.next_ty_var(span);
|
||||||
let inner_ty = self.next_ty_var(ty_var_origin);
|
|
||||||
|
|
||||||
Some(Ty::new_array(tcx, inner_ty, len.try_into().unwrap()))
|
Some(Ty::new_array(tcx, inner_ty, len.try_into().unwrap()))
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use rustc_ast as ast;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir_analysis::autoderef::Autoderef;
|
use rustc_hir_analysis::autoderef::Autoderef;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::InferOk;
|
use rustc_infer::infer::InferOk;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref, PointerCoercion};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref, PointerCoercion};
|
||||||
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
||||||
@ -147,8 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// If some lookup succeeds, write callee into table and extract index/element
|
// If some lookup succeeds, write callee into table and extract index/element
|
||||||
// type from the method signature.
|
// type from the method signature.
|
||||||
// If some lookup succeeded, install method in table
|
// If some lookup succeeded, install method in table
|
||||||
let input_ty =
|
let input_ty = self.next_ty_var(base_expr.span);
|
||||||
self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: base_expr.span });
|
|
||||||
let method =
|
let method =
|
||||||
self.try_overloaded_place_op(expr.span, self_ty, &[input_ty], PlaceOp::Index);
|
self.try_overloaded_place_op(expr.span, self_ty, &[input_ty], PlaceOp::Index);
|
||||||
|
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
|
||||||
|
|
||||||
use crate::infer::ConstVariableOrigin;
|
use crate::infer::{InferCtxt, RegionVariableOrigin};
|
||||||
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
|
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::infer::unify_key::EffectVarValue;
|
use rustc_middle::infer::unify_key::EffectVarValue;
|
||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::TypeFoldable;
|
||||||
@ -114,10 +113,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
match cv_info.kind {
|
match cv_info.kind {
|
||||||
CanonicalVarKind::Ty(ty_kind) => {
|
CanonicalVarKind::Ty(ty_kind) => {
|
||||||
let ty = match ty_kind {
|
let ty = match ty_kind {
|
||||||
CanonicalTyVarKind::General(ui) => self.next_ty_var_in_universe(
|
CanonicalTyVarKind::General(ui) => {
|
||||||
TypeVariableOrigin { param_def_id: None, span },
|
self.next_ty_var_in_universe(span, universe_map(ui))
|
||||||
universe_map(ui),
|
}
|
||||||
),
|
|
||||||
|
|
||||||
CanonicalTyVarKind::Int => self.next_int_var(),
|
CanonicalTyVarKind::Int => self.next_int_var(),
|
||||||
|
|
||||||
@ -145,13 +143,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
ty::Region::new_placeholder(self.tcx, placeholder_mapped).into()
|
ty::Region::new_placeholder(self.tcx, placeholder_mapped).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
CanonicalVarKind::Const(ui, ty) => self
|
CanonicalVarKind::Const(ui, ty) => {
|
||||||
.next_const_var_in_universe(
|
self.next_const_var_in_universe(ty, span, universe_map(ui)).into()
|
||||||
ty,
|
}
|
||||||
ConstVariableOrigin { param_def_id: None, span },
|
|
||||||
universe_map(ui),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
CanonicalVarKind::Effect => {
|
CanonicalVarKind::Effect => {
|
||||||
let vid = self
|
let vid = self
|
||||||
.inner
|
.inner
|
||||||
|
@ -3,7 +3,6 @@ use crate::errors::{
|
|||||||
SourceKindMultiSuggestion, SourceKindSubdiag,
|
SourceKindMultiSuggestion, SourceKindSubdiag,
|
||||||
};
|
};
|
||||||
use crate::infer::error_reporting::TypeErrCtxt;
|
use crate::infer::error_reporting::TypeErrCtxt;
|
||||||
use crate::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use rustc_errors::{codes::*, Diag, IntoDiagArg};
|
use rustc_errors::{codes::*, Diag, IntoDiagArg};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -13,7 +12,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
|
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableValue};
|
use rustc_middle::infer::unify_key::ConstVariableValue;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||||
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
|
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
@ -542,18 +541,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
match arg.unpack() {
|
match arg.unpack() {
|
||||||
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
|
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
|
||||||
GenericArgKind::Type(_) => self
|
GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(),
|
||||||
.next_ty_var(TypeVariableOrigin {
|
GenericArgKind::Const(arg) => {
|
||||||
span: DUMMY_SP,
|
self.next_const_var(arg.ty(), DUMMY_SP).into()
|
||||||
param_def_id: None,
|
}
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
GenericArgKind::Const(arg) => self
|
|
||||||
.next_const_var(
|
|
||||||
arg.ty(),
|
|
||||||
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -569,9 +560,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
|
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
|
||||||
let placeholder = Some(
|
let placeholder = Some(self.next_ty_var(DUMMY_SP));
|
||||||
self.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
|
||||||
);
|
|
||||||
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
|
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
|
||||||
let mut printer = fmt_printer(self, Namespace::ValueNS);
|
let mut printer = fmt_printer(self, Namespace::ValueNS);
|
||||||
printer.print_def_path(def_id, args).unwrap();
|
printer.print_def_path(def_id, args).unwrap();
|
||||||
@ -605,9 +594,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
|
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
|
||||||
let placeholder = Some(
|
let placeholder = Some(self.next_ty_var(DUMMY_SP));
|
||||||
self.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
|
||||||
);
|
|
||||||
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
|
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
|
||||||
let ty_info = ty_to_string(self, ty, None);
|
let ty_info = ty_to_string(self, ty, None);
|
||||||
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
|
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
|
||||||
|
@ -989,41 +989,50 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
self.inner.borrow_mut().type_variables().num_vars()
|
self.inner.borrow_mut().type_variables().num_vars()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_var_id(&self, origin: TypeVariableOrigin) -> TyVid {
|
pub fn next_ty_var(&self, span: Span) -> Ty<'tcx> {
|
||||||
self.inner.borrow_mut().type_variables().new_var(self.universe(), origin)
|
self.next_ty_var_with_origin(TypeVariableOrigin { span, param_def_id: None })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
|
pub fn next_ty_var_with_origin(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
|
||||||
Ty::new_var(self.tcx, self.next_ty_var_id(origin))
|
let vid = self.inner.borrow_mut().type_variables().new_var(self.universe(), origin);
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_ty_var_id_in_universe(
|
|
||||||
&self,
|
|
||||||
origin: TypeVariableOrigin,
|
|
||||||
universe: ty::UniverseIndex,
|
|
||||||
) -> TyVid {
|
|
||||||
self.inner.borrow_mut().type_variables().new_var(universe, origin)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_ty_var_in_universe(
|
|
||||||
&self,
|
|
||||||
origin: TypeVariableOrigin,
|
|
||||||
universe: ty::UniverseIndex,
|
|
||||||
) -> Ty<'tcx> {
|
|
||||||
let vid = self.next_ty_var_id_in_universe(origin, universe);
|
|
||||||
Ty::new_var(self.tcx, vid)
|
Ty::new_var(self.tcx, vid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
|
pub fn next_ty_var_id_in_universe(&self, span: Span, universe: ty::UniverseIndex) -> TyVid {
|
||||||
ty::Const::new_var(self.tcx, self.next_const_var_id(origin), ty)
|
let origin = TypeVariableOrigin { span, param_def_id: None };
|
||||||
|
self.inner.borrow_mut().type_variables().new_var(universe, origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_ty_var_in_universe(&self, span: Span, universe: ty::UniverseIndex) -> Ty<'tcx> {
|
||||||
|
let vid = self.next_ty_var_id_in_universe(span, universe);
|
||||||
|
Ty::new_var(self.tcx, vid)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_const_var(&self, ty: Ty<'tcx>, span: Span) -> ty::Const<'tcx> {
|
||||||
|
self.next_const_var_with_origin(ty, ConstVariableOrigin { span, param_def_id: None })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_const_var_with_origin(
|
||||||
|
&self,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
origin: ConstVariableOrigin,
|
||||||
|
) -> ty::Const<'tcx> {
|
||||||
|
let vid = self
|
||||||
|
.inner
|
||||||
|
.borrow_mut()
|
||||||
|
.const_unification_table()
|
||||||
|
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
|
||||||
|
.vid;
|
||||||
|
ty::Const::new_var(self.tcx, vid, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var_in_universe(
|
pub fn next_const_var_in_universe(
|
||||||
&self,
|
&self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
origin: ConstVariableOrigin,
|
span: Span,
|
||||||
universe: ty::UniverseIndex,
|
universe: ty::UniverseIndex,
|
||||||
) -> ty::Const<'tcx> {
|
) -> ty::Const<'tcx> {
|
||||||
|
let origin = ConstVariableOrigin { span, param_def_id: None };
|
||||||
let vid = self
|
let vid = self
|
||||||
.inner
|
.inner
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
@ -1033,28 +1042,14 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
ty::Const::new_var(self.tcx, vid, ty)
|
ty::Const::new_var(self.tcx, vid, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid {
|
|
||||||
self.inner
|
|
||||||
.borrow_mut()
|
|
||||||
.const_unification_table()
|
|
||||||
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
|
|
||||||
.vid
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next_int_var_id(&self) -> IntVid {
|
|
||||||
self.inner.borrow_mut().int_unification_table().new_key(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_int_var(&self) -> Ty<'tcx> {
|
pub fn next_int_var(&self) -> Ty<'tcx> {
|
||||||
Ty::new_int_var(self.tcx, self.next_int_var_id())
|
let vid = self.inner.borrow_mut().int_unification_table().new_key(None);
|
||||||
}
|
Ty::new_int_var(self.tcx, vid)
|
||||||
|
|
||||||
fn next_float_var_id(&self) -> FloatVid {
|
|
||||||
self.inner.borrow_mut().float_unification_table().new_key(None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_float_var(&self) -> Ty<'tcx> {
|
pub fn next_float_var(&self) -> Ty<'tcx> {
|
||||||
Ty::new_float_var(self.tcx, self.next_float_var_id())
|
let vid = self.inner.borrow_mut().float_unification_table().new_key(None);
|
||||||
|
Ty::new_float_var(self.tcx, vid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a fresh region variable with the next available index.
|
/// Creates a fresh region variable with the next available index.
|
||||||
@ -1468,24 +1463,13 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||||
self.map
|
self.map
|
||||||
.entry(bt.var)
|
.entry(bt.var)
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| self.infcx.next_ty_var(self.span).into())
|
||||||
self.infcx
|
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.span })
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
.expect_ty()
|
.expect_ty()
|
||||||
}
|
}
|
||||||
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||||
self.map
|
self.map
|
||||||
.entry(bv)
|
.entry(bv)
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| self.infcx.next_const_var(ty, self.span).into())
|
||||||
self.infcx
|
|
||||||
.next_const_var(
|
|
||||||
ty,
|
|
||||||
ConstVariableOrigin { param_def_id: None, span: self.span },
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
.expect_const()
|
.expect_const()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use super::type_variable::TypeVariableOrigin;
|
|
||||||
use super::{DefineOpaqueTypes, InferResult};
|
use super::{DefineOpaqueTypes, InferResult};
|
||||||
use crate::errors::OpaqueHiddenTypeDiag;
|
use crate::errors::OpaqueHiddenTypeDiag;
|
||||||
use crate::infer::{InferCtxt, InferOk};
|
use crate::infer::{InferCtxt, InferOk};
|
||||||
@ -65,7 +64,7 @@ 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);
|
||||||
let ty_var = self.next_ty_var(TypeVariableOrigin { param_def_id: None, span });
|
let ty_var = self.next_ty_var(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,
|
||||||
);
|
);
|
||||||
|
@ -3,7 +3,6 @@ use rustc_middle::ty::{self, Ty};
|
|||||||
|
|
||||||
use crate::traits::{Obligation, PredicateObligation};
|
use crate::traits::{Obligation, PredicateObligation};
|
||||||
|
|
||||||
use super::type_variable::TypeVariableOrigin;
|
|
||||||
use super::InferCtxt;
|
use super::InferCtxt;
|
||||||
|
|
||||||
impl<'tcx> InferCtxt<'tcx> {
|
impl<'tcx> InferCtxt<'tcx> {
|
||||||
@ -23,10 +22,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
debug_assert!(!self.next_trait_solver());
|
debug_assert!(!self.next_trait_solver());
|
||||||
let def_id = projection_ty.def_id;
|
let def_id = projection_ty.def_id;
|
||||||
let ty_var = self.next_ty_var(TypeVariableOrigin {
|
let ty_var = self.next_ty_var(self.tcx.def_span(def_id));
|
||||||
param_def_id: None,
|
|
||||||
span: self.tcx.def_span(def_id),
|
|
||||||
});
|
|
||||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Projection(
|
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Projection(
|
||||||
ty::ProjectionPredicate { projection_ty, term: ty_var.into() },
|
ty::ProjectionPredicate { projection_ty, term: ty_var.into() },
|
||||||
)));
|
)));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use super::StructurallyRelateAliases;
|
use super::StructurallyRelateAliases;
|
||||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableValue};
|
use crate::infer::type_variable::TypeVariableValue;
|
||||||
use crate::infer::{InferCtxt, ObligationEmittingRelation, RegionVariableOrigin};
|
use crate::infer::{InferCtxt, ObligationEmittingRelation, RegionVariableOrigin};
|
||||||
use rustc_data_structures::sso::SsoHashMap;
|
use rustc_data_structures::sso::SsoHashMap;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
@ -357,10 +357,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
|
|||||||
//
|
//
|
||||||
// cc trait-system-refactor-initiative#110
|
// cc trait-system-refactor-initiative#110
|
||||||
if self.infcx.next_trait_solver() && !alias.has_escaping_bound_vars() && !self.in_alias {
|
if self.infcx.next_trait_solver() && !alias.has_escaping_bound_vars() && !self.in_alias {
|
||||||
return Ok(self.infcx.next_ty_var_in_universe(
|
return Ok(self.infcx.next_ty_var_in_universe(self.span, self.for_universe));
|
||||||
TypeVariableOrigin { param_def_id: None, span: self.span },
|
|
||||||
self.for_universe,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_nested_alias = mem::replace(&mut self.in_alias, true);
|
let is_nested_alias = mem::replace(&mut self.in_alias, true);
|
||||||
@ -380,10 +377,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("generalization failure in alias");
|
debug!("generalization failure in alias");
|
||||||
Ok(self.infcx.next_ty_var_in_universe(
|
Ok(self.infcx.next_ty_var_in_universe(self.span, self.for_universe))
|
||||||
TypeVariableOrigin { param_def_id: None, span: self.span },
|
|
||||||
self.for_universe,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
//! [lattices]: https://en.wikipedia.org/wiki/Lattice_(order)
|
//! [lattices]: https://en.wikipedia.org/wiki/Lattice_(order)
|
||||||
|
|
||||||
use super::combine::ObligationEmittingRelation;
|
use super::combine::ObligationEmittingRelation;
|
||||||
use crate::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use crate::infer::{DefineOpaqueTypes, InferCtxt};
|
use crate::infer::{DefineOpaqueTypes, InferCtxt};
|
||||||
use crate::traits::ObligationCause;
|
use crate::traits::ObligationCause;
|
||||||
|
|
||||||
@ -88,14 +87,12 @@ where
|
|||||||
// iterate on the subtype obligations that are returned, but I
|
// iterate on the subtype obligations that are returned, but I
|
||||||
// think this suffices. -nmatsakis
|
// think this suffices. -nmatsakis
|
||||||
(&ty::Infer(TyVar(..)), _) => {
|
(&ty::Infer(TyVar(..)), _) => {
|
||||||
let v = infcx
|
let v = infcx.next_ty_var(this.cause().span);
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: this.cause().span });
|
|
||||||
this.relate_bound(v, b, a)?;
|
this.relate_bound(v, b, a)?;
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
(_, &ty::Infer(TyVar(..))) => {
|
(_, &ty::Infer(TyVar(..))) => {
|
||||||
let v = infcx
|
let v = infcx.next_ty_var(this.cause().span);
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: this.cause().span });
|
|
||||||
this.relate_bound(v, a, b)?;
|
this.relate_bound(v, a, b)?;
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
|||||||
// Recreate it with a fresh variable here.
|
// Recreate it with a fresh variable here.
|
||||||
let idx = vid.as_usize() - self.type_vars.0.start.as_usize();
|
let idx = vid.as_usize() - self.type_vars.0.start.as_usize();
|
||||||
let origin = self.type_vars.1[idx];
|
let origin = self.type_vars.1[idx];
|
||||||
self.infcx.next_ty_var(origin)
|
self.infcx.next_ty_var_with_origin(origin)
|
||||||
} else {
|
} else {
|
||||||
// This variable was created before the
|
// This variable was created before the
|
||||||
// "fudging". Since we refresh all type
|
// "fudging". Since we refresh all type
|
||||||
@ -244,7 +244,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
|||||||
// Recreate it with a fresh variable here.
|
// Recreate it with a fresh variable here.
|
||||||
let idx = vid.index() - self.const_vars.0.start.index();
|
let idx = vid.index() - self.const_vars.0.start.index();
|
||||||
let origin = self.const_vars.1[idx];
|
let origin = self.const_vars.1[idx];
|
||||||
self.infcx.next_const_var(ct.ty(), origin)
|
self.infcx.next_const_var_with_origin(ct.ty(), origin)
|
||||||
} else {
|
} else {
|
||||||
ct
|
ct
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
|
||||||
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::ty::{self, Binder, Ty, TyCtxt, TypeFoldable, TypeFolder};
|
use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable, TypeFolder};
|
||||||
@ -337,7 +336,7 @@ impl<'a, 'tcx, F: FnMut(DefId) -> bool> TypeFolder<TyCtxt<'tcx>>
|
|||||||
if let Some(def) = t.ty_adt_def()
|
if let Some(def) = t.ty_adt_def()
|
||||||
&& (self.did_has_local_parent)(def.did())
|
&& (self.did_has_local_parent)(def.did())
|
||||||
{
|
{
|
||||||
self.infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.infer_span })
|
self.infcx.next_ty_var(self.infer_span)
|
||||||
} else {
|
} else {
|
||||||
t.super_fold_with(self)
|
t.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ use crate::build::expr::as_place::{PlaceBase, PlaceBuilder};
|
|||||||
use crate::build::matches::{Binding, Candidate, FlatPat, MatchPair, TestCase};
|
use crate::build::matches::{Binding, Candidate, FlatPat, MatchPair, TestCase};
|
||||||
use crate::build::Builder;
|
use crate::build::Builder;
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::thir::{self, *};
|
use rustc_middle::thir::{self, *};
|
||||||
use rustc_middle::ty::TypeVisitableExt;
|
use rustc_middle::ty::TypeVisitableExt;
|
||||||
@ -180,9 +179,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
|
|||||||
cx.tcx,
|
cx.tcx,
|
||||||
ty::InlineConstArgsParts {
|
ty::InlineConstArgsParts {
|
||||||
parent_args: ty::GenericArgs::identity_for_item(cx.tcx, parent_id),
|
parent_args: ty::GenericArgs::identity_for_item(cx.tcx, parent_id),
|
||||||
ty: cx
|
ty: cx.infcx.next_ty_var(span),
|
||||||
.infcx
|
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span }),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.args;
|
.args;
|
||||||
|
@ -19,12 +19,10 @@ use rustc_infer::infer::canonical::query_response::make_query_region_constraints
|
|||||||
use rustc_infer::infer::canonical::CanonicalVarValues;
|
use rustc_infer::infer::canonical::CanonicalVarValues;
|
||||||
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
|
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
|
||||||
use rustc_infer::infer::resolve::EagerResolver;
|
use rustc_infer::infer::resolve::EagerResolver;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::RegionVariableOrigin;
|
use rustc_infer::infer::RegionVariableOrigin;
|
||||||
use rustc_infer::infer::{InferCtxt, InferOk};
|
use rustc_infer::infer::{InferCtxt, InferOk};
|
||||||
use rustc_infer::traits::solve::NestedNormalizationGoals;
|
use rustc_infer::traits::solve::NestedNormalizationGoals;
|
||||||
use rustc_middle::infer::canonical::Canonical;
|
use rustc_middle::infer::canonical::Canonical;
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::traits::query::NoSolution;
|
use rustc_middle::traits::query::NoSolution;
|
||||||
use rustc_middle::traits::solve::{
|
use rustc_middle::traits::solve::{
|
||||||
ExternalConstraintsData, MaybeCause, PredefinedOpaquesData, QueryInput,
|
ExternalConstraintsData, MaybeCause, PredefinedOpaquesData, QueryInput,
|
||||||
@ -425,12 +423,8 @@ pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt
|
|||||||
ty::GenericArgKind::Lifetime(_) => {
|
ty::GenericArgKind::Lifetime(_) => {
|
||||||
infcx.next_region_var(RegionVariableOrigin::MiscVariable(span)).into()
|
infcx.next_region_var(RegionVariableOrigin::MiscVariable(span)).into()
|
||||||
}
|
}
|
||||||
ty::GenericArgKind::Type(_) => {
|
ty::GenericArgKind::Type(_) => infcx.next_ty_var(span).into(),
|
||||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span }).into()
|
ty::GenericArgKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
|
||||||
}
|
|
||||||
ty::GenericArgKind::Const(ct) => infcx
|
|
||||||
.next_const_var(ct.ty(), ConstVariableOrigin { param_def_id: None, span })
|
|
||||||
.into(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
orig_values.push(unconstrained);
|
orig_values.push(unconstrained);
|
||||||
|
@ -2,7 +2,6 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
|
|||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::at::ToTrace;
|
use rustc_infer::infer::at::ToTrace;
|
||||||
use rustc_infer::infer::canonical::CanonicalVarValues;
|
use rustc_infer::infer::canonical::CanonicalVarValues;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{
|
use rustc_infer::infer::{
|
||||||
BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk, TyCtxtInferExt,
|
BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk, TyCtxtInferExt,
|
||||||
};
|
};
|
||||||
@ -11,7 +10,6 @@ use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
|
|||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_macros::{extension, HashStable};
|
use rustc_macros::{extension, HashStable};
|
||||||
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
use rustc_middle::infer::canonical::CanonicalVarInfos;
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::traits::solve::inspect;
|
use rustc_middle::traits::solve::inspect;
|
||||||
use rustc_middle::traits::solve::{
|
use rustc_middle::traits::solve::{
|
||||||
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
|
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
|
||||||
@ -600,15 +598,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn next_ty_infer(&mut self) -> Ty<'tcx> {
|
pub(super) fn next_ty_infer(&mut self) -> Ty<'tcx> {
|
||||||
let ty = self.infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP });
|
let ty = self.infcx.next_ty_var(DUMMY_SP);
|
||||||
self.inspect.add_var_value(ty);
|
self.inspect.add_var_value(ty);
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn next_const_infer(&mut self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
pub(super) fn next_const_infer(&mut self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||||
let ct = self
|
let ct = self.infcx.next_const_var(ty, DUMMY_SP);
|
||||||
.infcx
|
|
||||||
.next_const_var(ty, ConstVariableOrigin { param_def_id: None, span: DUMMY_SP });
|
|
||||||
self.inspect.add_var_value(ct);
|
self.inspect.add_var_value(ct);
|
||||||
ct
|
ct
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,8 @@
|
|||||||
use rustc_ast_ir::try_visit;
|
use rustc_ast_ir::try_visit;
|
||||||
use rustc_ast_ir::visit::VisitorResult;
|
use rustc_ast_ir::visit::VisitorResult;
|
||||||
use rustc_infer::infer::resolve::EagerResolver;
|
use rustc_infer::infer::resolve::EagerResolver;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
|
||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::traits::query::NoSolution;
|
use rustc_middle::traits::query::NoSolution;
|
||||||
use rustc_middle::traits::solve::{inspect, QueryResult};
|
use rustc_middle::traits::solve::{inspect, QueryResult};
|
||||||
use rustc_middle::traits::solve::{Certainty, Goal};
|
use rustc_middle::traits::solve::{Certainty, Goal};
|
||||||
@ -206,15 +204,8 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
|||||||
.map(|(source, goal)| match goal.predicate.kind().no_bound_vars() {
|
.map(|(source, goal)| match goal.predicate.kind().no_bound_vars() {
|
||||||
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
|
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
|
||||||
let unconstrained_term = match term.unpack() {
|
let unconstrained_term = match term.unpack() {
|
||||||
ty::TermKind::Ty(_) => infcx
|
ty::TermKind::Ty(_) => infcx.next_ty_var(span).into(),
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span })
|
ty::TermKind::Const(ct) => infcx.next_const_var(ct.ty(), span).into(),
|
||||||
.into(),
|
|
||||||
ty::TermKind::Const(ct) => infcx
|
|
||||||
.next_const_var(
|
|
||||||
ct.ty(),
|
|
||||||
ConstVariableOrigin { param_def_id: None, span },
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
};
|
};
|
||||||
let goal =
|
let goal =
|
||||||
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });
|
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });
|
||||||
|
@ -3,11 +3,9 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
|
|||||||
use crate::traits::{BoundVarReplacer, PlaceholderReplacer};
|
use crate::traits::{BoundVarReplacer, PlaceholderReplacer};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_infer::infer::at::At;
|
use rustc_infer::infer::at::At;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_infer::traits::TraitEngineExt;
|
use rustc_infer::traits::TraitEngineExt;
|
||||||
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
|
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
|
||||||
use rustc_middle::infer::unify_key::ConstVariableOrigin;
|
|
||||||
use rustc_middle::traits::ObligationCause;
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
|
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
|
||||||
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
||||||
@ -74,8 +72,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||||||
|
|
||||||
self.depth += 1;
|
self.depth += 1;
|
||||||
|
|
||||||
let new_infer_ty =
|
let new_infer_ty = infcx.next_ty_var(self.at.cause.span);
|
||||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.at.cause.span });
|
|
||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
self.at.cause.clone(),
|
self.at.cause.clone(),
|
||||||
@ -120,10 +117,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||||||
|
|
||||||
self.depth += 1;
|
self.depth += 1;
|
||||||
|
|
||||||
let new_infer_ct = infcx.next_const_var(
|
let new_infer_ct = infcx.next_const_var(ty, self.at.cause.span);
|
||||||
ty,
|
|
||||||
ConstVariableOrigin { param_def_id: None, span: self.at.cause.span },
|
|
||||||
);
|
|
||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
self.at.cause.clone(),
|
self.at.cause.clone(),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||||
use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, Diag};
|
use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, Diag};
|
||||||
@ -218,8 +217,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
let Some(trait_def_id) = trait_def_id else { continue };
|
let Some(trait_def_id) = trait_def_id else { continue };
|
||||||
// Make a fresh inference variable so we can determine what the generic parameters
|
// Make a fresh inference variable so we can determine what the generic parameters
|
||||||
// of the trait are.
|
// of the trait are.
|
||||||
let var =
|
let var = self.next_ty_var(DUMMY_SP);
|
||||||
self.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None });
|
|
||||||
// FIXME(effects)
|
// FIXME(effects)
|
||||||
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]);
|
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]);
|
||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
|
@ -24,7 +24,6 @@ use rustc_hir::is_range_literal;
|
|||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node};
|
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node};
|
||||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk};
|
||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
use rustc_middle::hir::map;
|
use rustc_middle::hir::map;
|
||||||
@ -1893,8 +1892,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => {
|
ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => {
|
||||||
infcx.tcx.mk_fn_sig(
|
infcx.tcx.mk_fn_sig(
|
||||||
*inputs,
|
*inputs,
|
||||||
infcx
|
infcx.next_ty_var(DUMMY_SP),
|
||||||
.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
|
||||||
false,
|
false,
|
||||||
hir::Unsafety::Normal,
|
hir::Unsafety::Normal,
|
||||||
abi::Abi::Rust,
|
abi::Abi::Rust,
|
||||||
@ -1902,7 +1900,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
_ => infcx.tcx.mk_fn_sig(
|
_ => infcx.tcx.mk_fn_sig(
|
||||||
[inputs],
|
[inputs],
|
||||||
infcx.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, param_def_id: None }),
|
infcx.next_ty_var(DUMMY_SP),
|
||||||
false,
|
false,
|
||||||
hir::Unsafety::Normal,
|
hir::Unsafety::Normal,
|
||||||
abi::Abi::Rust,
|
abi::Abi::Rust,
|
||||||
@ -4263,7 +4261,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let origin = TypeVariableOrigin { param_def_id: None, span };
|
|
||||||
// Make `Self` be equivalent to the type of the call chain
|
// Make `Self` be equivalent to the type of the call chain
|
||||||
// expression we're looking at now, so that we can tell what
|
// expression we're looking at now, so that we can tell what
|
||||||
// for example `Iterator::Item` is at this point in the chain.
|
// for example `Iterator::Item` is at this point in the chain.
|
||||||
@ -4277,7 +4274,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
// This will hold the resolved type of the associated type, if the
|
// This will hold the resolved type of the associated type, if the
|
||||||
// current expression implements the trait that associated type is
|
// current expression implements the trait that associated type is
|
||||||
// in. For example, this would be what `Iterator::Item` is here.
|
// in. For example, this would be what `Iterator::Item` is here.
|
||||||
let ty = self.infcx.next_ty_var(origin);
|
let ty = self.infcx.next_ty_var(span);
|
||||||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||||
|
@ -6,7 +6,6 @@ use crate::errors::{
|
|||||||
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
|
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
|
||||||
};
|
};
|
||||||
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
||||||
use crate::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use crate::infer::InferCtxtExt as _;
|
use crate::infer::InferCtxtExt as _;
|
||||||
use crate::infer::{self, InferCtxt};
|
use crate::infer::{self, InferCtxt};
|
||||||
use crate::traits::error_reporting::infer_ctxt_ext::InferCtxtExt;
|
use crate::traits::error_reporting::infer_ctxt_ext::InferCtxtExt;
|
||||||
@ -2826,9 +2825,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Param(_) = *ty.kind() {
|
if let ty::Param(_) = *ty.kind() {
|
||||||
let infcx = self.infcx;
|
let infcx = self.infcx;
|
||||||
*self.var_map.entry(ty).or_insert_with(|| {
|
*self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var(DUMMY_SP))
|
||||||
infcx.next_ty_var(TypeVariableOrigin { param_def_id: None, span: DUMMY_SP })
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
ty.super_fold_with(self)
|
ty.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ use rustc_middle::traits::ImplSource;
|
|||||||
use rustc_middle::traits::ImplSourceUserDefinedData;
|
use rustc_middle::traits::ImplSourceUserDefinedData;
|
||||||
|
|
||||||
use crate::errors::InherentProjectionNormalizationOverflow;
|
use crate::errors::InherentProjectionNormalizationOverflow;
|
||||||
use crate::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use crate::infer::{BoundRegionConversionTime, InferOk};
|
use crate::infer::{BoundRegionConversionTime, InferOk};
|
||||||
use crate::traits::normalize::normalize_with_depth;
|
use crate::traits::normalize::normalize_with_depth;
|
||||||
use crate::traits::normalize::normalize_with_depth_to;
|
use crate::traits::normalize::normalize_with_depth_to;
|
||||||
@ -521,10 +520,7 @@ fn normalize_to_error<'a, 'tcx>(
|
|||||||
predicate: trait_ref.to_predicate(selcx.tcx()),
|
predicate: trait_ref.to_predicate(selcx.tcx()),
|
||||||
};
|
};
|
||||||
let tcx = selcx.infcx.tcx;
|
let tcx = selcx.infcx.tcx;
|
||||||
let new_value = selcx.infcx.next_ty_var(TypeVariableOrigin {
|
let new_value = selcx.infcx.next_ty_var(tcx.def_span(projection_ty.def_id));
|
||||||
param_def_id: None,
|
|
||||||
span: tcx.def_span(projection_ty.def_id),
|
|
||||||
});
|
|
||||||
Normalized { value: new_value, obligations: vec![trait_obligation] }
|
Normalized { value: new_value, obligations: vec![trait_obligation] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use rustc_infer::infer::at::At;
|
use rustc_infer::infer::at::At;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::traits::{FulfillmentError, TraitEngine};
|
use rustc_infer::traits::{FulfillmentError, TraitEngine};
|
||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
@ -20,9 +19,7 @@ impl<'tcx> At<'_, 'tcx> {
|
|||||||
return Ok(ty);
|
return Ok(ty);
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_infer_ty = self
|
let new_infer_ty = self.infcx.next_ty_var(self.cause.span);
|
||||||
.infcx
|
|
||||||
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: self.cause.span });
|
|
||||||
|
|
||||||
// We simply emit an `alias-eq` goal here, since that will take care of
|
// We simply emit an `alias-eq` goal here, since that will take care of
|
||||||
// normalizing the LHS of the projection until it is a rigid projection
|
// normalizing the LHS of the projection until it is a rigid projection
|
||||||
|
@ -10,7 +10,6 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
|
use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::mir::interpret::Scalar;
|
use rustc_middle::mir::interpret::Scalar;
|
||||||
@ -276,11 +275,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|arg| {
|
.map(|arg| {
|
||||||
arg.into().unwrap_or_else(|| {
|
arg.into().unwrap_or_else(|| {
|
||||||
let orig = TypeVariableOrigin {
|
infcx.next_ty_var(DUMMY_SP).into()
|
||||||
span: DUMMY_SP,
|
|
||||||
param_def_id: None,
|
|
||||||
};
|
|
||||||
infcx.next_ty_var(orig).into()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
Loading…
Reference in New Issue
Block a user