1
Fork 0

refactor(rustc_middle): Substs -> GenericArg

This commit is contained in:
Mahdi Dibaiee 2023-07-11 22:35:29 +01:00
parent df5c2cf9bc
commit e55583c4b8
466 changed files with 4574 additions and 4604 deletions

View file

@ -11,7 +11,7 @@ use crate::infer::canonical::{
use crate::infer::InferCtxt;
use rustc_middle::ty::flags::FlagComputation;
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
use std::sync::atomic::Ordering;

View file

@ -25,7 +25,7 @@ use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
use rustc_index::IndexVec;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, List, Ty, TyCtxt};
use rustc_span::source_map::Span;
@ -88,7 +88,7 @@ impl<'tcx> InferCtxt<'tcx> {
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
) -> CanonicalVarValues<'tcx> {
CanonicalVarValues {
var_values: self.tcx.mk_substs_from_iter(
var_values: self.tcx.mk_args_from_iter(
variables
.iter()
.map(|info| self.instantiate_canonical_var(span, info, &universe_map)),

View file

@ -25,8 +25,8 @@ use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, BoundVar, ToPredicate, Ty, TyCtxt};
use rustc_middle::ty::{GenericArg, GenericArgKind};
use rustc_span::{Span, Symbol};
use std::fmt::Debug;
use std::iter;
@ -484,7 +484,7 @@ impl<'tcx> InferCtxt<'tcx> {
// given variable in the loop above, use that. Otherwise, use
// a fresh inference variable.
let result_subst = CanonicalVarValues {
var_values: self.tcx.mk_substs_from_iter(
var_values: self.tcx.mk_args_from_iter(
query_response.variables.iter().enumerate().map(|(index, info)| {
if info.is_existential() {
match opt_values[BoundVar::new(index)] {
@ -520,7 +520,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.at(cause, param_env)
.eq(
DefineOpaqueTypes::Yes,
Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.substs),
Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.args),
b,
)?
.obligations,

View file

@ -8,7 +8,7 @@
use crate::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::ty::fold::{FnMutDelegate, TypeFoldable};
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::{self, TyCtxt};
/// FIXME(-Ztrait-solver=next): This or public because it is shared with the

View file

@ -254,7 +254,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// in `ct` with `ct` itself.
///
/// This is especially important as unevaluated consts use their parents generics.
/// They therefore often contain unused substs, making these errors far more likely.
/// They therefore often contain unused args, making these errors far more likely.
///
/// A good example of this is the following:
///
@ -272,12 +272,12 @@ impl<'tcx> InferCtxt<'tcx> {
/// ```
///
/// Here `3 + 4` ends up as `ConstKind::Unevaluated` which uses the generics
/// of `fn bind` (meaning that its substs contain `N`).
/// of `fn bind` (meaning that its args contain `N`).
///
/// `bind(arr)` now infers that the type of `arr` must be `[u8; N]`.
/// The assignment `arr = bind(arr)` now tries to equate `N` with `3 + 4`.
///
/// As `3 + 4` contains `N` in its substs, this must not succeed.
/// As `3 + 4` contains `N` in its args, this must not succeed.
///
/// See `tests/ui/const-generics/occurs-check/` for more examples where this is relevant.
#[instrument(level = "debug", skip(self))]

View file

@ -5,7 +5,7 @@ use super::combine::{CombineFields, ObligationEmittingRelation};
use super::Subtype;
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::TyVar;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
@ -43,12 +43,12 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
self.a_is_expected
}
fn relate_item_substs(
fn relate_item_args(
&mut self,
_item_def_id: DefId,
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>,
) -> RelateResult<'tcx, SubstsRef<'tcx>> {
a_arg: GenericArgsRef<'tcx>,
b_arg: GenericArgsRef<'tcx>,
) -> RelateResult<'tcx, GenericArgsRef<'tcx>> {
// N.B., once we are equating types, we don't care about
// variance, so don't try to lookup the variance here. This
// also avoids some cycles (e.g., #41849) since looking up
@ -56,7 +56,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
// performing trait matching (which then performs equality
// unification).
relate::relate_substs(self, a_subst, b_subst)
relate::relate_args(self, a_arg, b_arg)
}
fn relate_with_variance<T: Relate<'tcx>>(

View file

@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime {
span,
opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.args),
opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
});
@ -386,16 +386,16 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
impl<'tcx> InferCtxt<'tcx> {
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
let (def_id, substs) = match *ty.kind() {
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
let (def_id, args) = match *ty.kind() {
ty::Alias(_, ty::AliasTy { def_id, args, .. })
if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) =>
{
(def_id, substs)
(def_id, args)
}
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
ty::Alias(_, ty::AliasTy { def_id, args, .. })
if self.tcx.is_impl_trait_in_trait(def_id) =>
{
(def_id, substs)
(def_id, args)
}
_ => return None,
};
@ -403,7 +403,7 @@ impl<'tcx> InferCtxt<'tcx> {
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
self.tcx.explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs).find_map(
self.tcx.explicit_item_bounds(def_id).arg_iter_copied(self.tcx, args).find_map(
|(predicate, _)| {
predicate
.kind()
@ -573,7 +573,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
use hir::def_id::CrateNum;
use rustc_hir::definitions::DisambiguatedDefPathData;
use ty::print::Printer;
use ty::subst::GenericArg;
use ty::GenericArg;
struct AbsolutePathPrinter<'tcx> {
tcx: TyCtxt<'tcx>,
@ -711,10 +711,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
{
// don't show type `_`
if span.desugaring_kind() == Some(DesugaringKind::ForLoop)
&& let ty::Adt(def, substs) = ty.kind()
&& let ty::Adt(def, args) = ty.kind()
&& Some(def.did()) == self.tcx.get_diagnostic_item(sym::Option)
{
err.span_label(span, format!("this is an iterator with items of type `{}`", substs.type_at(0)));
err.span_label(span, format!("this is an iterator with items of type `{}`", args.type_at(0)));
} else {
err.span_label(span, format!("this expression has type `{}`", ty));
}
@ -908,7 +908,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
value: &mut DiagnosticStyledString,
other_value: &mut DiagnosticStyledString,
name: String,
sub: ty::subst::SubstsRef<'tcx>,
sub: ty::GenericArgsRef<'tcx>,
pos: usize,
other_ty: Ty<'tcx>,
) {
@ -986,9 +986,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
other_path: String,
other_ty: Ty<'tcx>,
) -> Option<()> {
// FIXME/HACK: Go back to `SubstsRef` to use its inherent methods,
// FIXME/HACK: Go back to `GenericArgsRef` to use its inherent methods,
// ideally that shouldn't be necessary.
let sub = self.tcx.mk_substs(sub);
let sub = self.tcx.mk_args(sub);
for (i, ta) in sub.types().enumerate() {
if ta == other_ty {
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, other_ty);
@ -1180,9 +1180,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let did1 = def1.did();
let did2 = def2.did();
let sub_no_defaults_1 =
self.tcx.generics_of(did1).own_substs_no_defaults(self.tcx, sub1);
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
let sub_no_defaults_2 =
self.tcx.generics_of(did2).own_substs_no_defaults(self.tcx, sub2);
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
let path1 = self.tcx.def_path_str(did1);
let path2 = self.tcx.def_path_str(did2);
@ -1403,11 +1403,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
// When encountering tuples of the same size, highlight only the differing types
(&ty::Tuple(substs1), &ty::Tuple(substs2)) if substs1.len() == substs2.len() => {
(&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => {
let mut values =
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
let len = substs1.len();
for (i, (left, right)) in substs1.iter().zip(substs2).enumerate() {
let len = args1.len();
for (i, (left, right)) in args1.iter().zip(args2).enumerate() {
let (x1, x2) = self.cmp(left, right);
(values.0).0.extend(x1.0);
(values.1).0.extend(x2.0);
@ -1423,35 +1423,34 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
values
}
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
let mut values = self.cmp_fn_sig(&sig1, &sig2);
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1));
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2));
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
let same_path = path1 == path2;
values.0.push(path1, !same_path);
values.1.push(path2, !same_path);
values
}
(ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => {
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
(ty::FnDef(did1, args1), ty::FnPtr(sig2)) => {
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
let mut values = self.cmp_fn_sig(&sig1, sig2);
values.0.push_highlighted(format!(
" {{{}}}",
self.tcx.def_path_str_with_substs(*did1, substs1)
self.tcx.def_path_str_with_args(*did1, args1)
));
values
}
(ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => {
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
(ty::FnPtr(sig1), ty::FnDef(did2, args2)) => {
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
let mut values = self.cmp_fn_sig(sig1, &sig2);
values.1.push_normal(format!(
" {{{}}}",
self.tcx.def_path_str_with_substs(*did2, substs2)
));
values
.1
.push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
values
}

View file

@ -18,7 +18,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{self, InferConst};
use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef};
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{BytePos, Span};
@ -226,8 +226,8 @@ fn ty_to_string<'tcx>(
/// something users are familiar with. Directly printing the `fn_sig` of closures also
/// doesn't work as they actually use the "rust-call" API.
fn closure_as_fn_str<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String {
let ty::Closure(_, substs) = ty.kind() else { unreachable!() };
let fn_sig = substs.as_closure().sig();
let ty::Closure(_, args) = ty.kind() else { unreachable!() };
let fn_sig = args.as_closure().sig();
let args = fn_sig
.inputs()
.skip_binder()
@ -524,9 +524,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
});
}
}
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, substs, def_id } => {
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
let printer = fmt_printer(self, Namespace::ValueNS);
let def_path = printer.print_def_path(def_id, substs).unwrap().into_buffer();
let def_path = printer.print_def_path(def_id, args).unwrap().into_buffer();
// We only care about whether we have to add `&` or `&mut ` for now.
// This is the case if the last adjustment is a borrow and the
@ -659,7 +659,7 @@ enum InferSourceKind<'tcx> {
/// If the method has other arguments, this is ", " and the start of the first argument,
/// while for methods without arguments this is ")" and the end of the method call.
successor: (&'static str, BytePos),
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
def_id: DefId,
},
ClosureReturn {
@ -710,7 +710,7 @@ impl<'tcx> InferSourceKind<'tcx> {
#[derive(Debug)]
struct InsertableGenericArgs<'tcx> {
insert_span: Span,
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
generics_def_id: DefId,
def_id: DefId,
have_turbofish: bool,
@ -774,11 +774,11 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
ty::Closure(..) => 1000,
ty::FnDef(..) => 150,
ty::FnPtr(..) => 30,
ty::Adt(def, substs) => {
ty::Adt(def, args) => {
5 + self
.tcx
.generics_of(def.did())
.own_substs_no_defaults(self.tcx, substs)
.own_args_no_defaults(self.tcx, args)
.iter()
.map(|&arg| self.arg_cost(arg))
.sum::<usize>()
@ -805,8 +805,8 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
};
variant_cost + generic_args.iter().map(|&arg| ctx.arg_cost(arg)).sum::<usize>()
}
InferSourceKind::FullyQualifiedMethodCall { substs, .. } => {
20 + substs.iter().map(|arg| ctx.arg_cost(arg)).sum::<usize>()
InferSourceKind::FullyQualifiedMethodCall { args, .. } => {
20 + args.iter().map(|arg| ctx.arg_cost(arg)).sum::<usize>()
}
InferSourceKind::ClosureReturn { ty, should_wrap_expr, .. } => {
30 + ctx.ty_cost(ty) + if should_wrap_expr.is_some() { 10 } else { 0 }
@ -840,9 +840,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
}
fn node_substs_opt(&self, hir_id: HirId) -> Option<SubstsRef<'tcx>> {
let substs = self.typeck_results.node_substs_opt(hir_id);
self.infcx.resolve_vars_if_possible(substs)
fn node_args_opt(&self, hir_id: HirId) -> Option<GenericArgsRef<'tcx>> {
let args = self.typeck_results.node_args_opt(hir_id);
self.infcx.resolve_vars_if_possible(args)
}
fn opt_node_type(&self, hir_id: HirId) -> Option<Ty<'tcx>> {
@ -923,15 +923,15 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
false
}
fn expr_inferred_subst_iter(
fn expr_inferred_arg_iter(
&self,
expr: &'tcx hir::Expr<'tcx>,
) -> Box<dyn Iterator<Item = InsertableGenericArgs<'tcx>> + 'a> {
let tcx = self.infcx.tcx;
match expr.kind {
hir::ExprKind::Path(ref path) => {
if let Some(substs) = self.node_substs_opt(expr.hir_id) {
return self.path_inferred_subst_iter(expr.hir_id, substs, path);
if let Some(args) = self.node_args_opt(expr.hir_id) {
return self.path_inferred_arg_iter(expr.hir_id, args, path);
}
}
// FIXME(#98711): Ideally we would also deal with type relative
@ -943,7 +943,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
// However, the `type_dependent_def_id` for `Self::Output` in an
// impl is currently the `DefId` of `Output` in the trait definition
// which makes this somewhat difficult and prevents us from just
// using `self.path_inferred_subst_iter` here.
// using `self.path_inferred_arg_iter` here.
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _)
// FIXME(TaKO8Ki): Ideally we should support this. For that
// we have to map back from the self type to the
@ -953,9 +953,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
// a example.
if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
if let Some(ty) = self.opt_node_type(expr.hir_id)
&& let ty::Adt(_, substs) = ty.kind()
&& let ty::Adt(_, args) = ty.kind()
{
return Box::new(self.resolved_path_inferred_subst_iter(path, substs));
return Box::new(self.resolved_path_inferred_arg_iter(path, args));
}
}
hir::ExprKind::MethodCall(segment, ..) => {
@ -965,12 +965,12 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
if generics.has_impl_trait() {
None?
}
let substs = self.node_substs_opt(expr.hir_id)?;
let args = self.node_args_opt(expr.hir_id)?;
let span = tcx.hir().span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs {
insert_span,
substs,
args,
generics_def_id: def_id,
def_id,
have_turbofish: false,
@ -985,10 +985,10 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
Box::new(iter::empty())
}
fn resolved_path_inferred_subst_iter(
fn resolved_path_inferred_arg_iter(
&self,
path: &'tcx hir::Path<'tcx>,
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = InsertableGenericArgs<'tcx>> + 'a {
let tcx = self.infcx.tcx;
let have_turbofish = path.segments.iter().any(|segment| {
@ -1009,7 +1009,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
path.segments.last().unwrap().ident.span.shrink_to_hi().with_hi(path.span.hi());
InsertableGenericArgs {
insert_span,
substs,
args,
generics_def_id,
def_id: path.res.def_id(),
have_turbofish,
@ -1029,7 +1029,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
Some(InsertableGenericArgs {
insert_span,
substs,
args,
generics_def_id,
def_id: res.def_id(),
have_turbofish,
@ -1038,16 +1038,16 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
.chain(last_segment_using_path_data)
}
fn path_inferred_subst_iter(
fn path_inferred_arg_iter(
&self,
hir_id: HirId,
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
qpath: &'tcx hir::QPath<'tcx>,
) -> Box<dyn Iterator<Item = InsertableGenericArgs<'tcx>> + 'a> {
let tcx = self.infcx.tcx;
match qpath {
hir::QPath::Resolved(_self_ty, path) => {
Box::new(self.resolved_path_inferred_subst_iter(path, substs))
Box::new(self.resolved_path_inferred_arg_iter(path, args))
}
hir::QPath::TypeRelative(ty, segment) => {
let Some(def_id) = self.typeck_results.type_dependent_def_id(hir_id) else {
@ -1063,7 +1063,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs {
insert_span,
substs,
args,
generics_def_id: def_id,
def_id,
have_turbofish: false,
@ -1072,10 +1072,10 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
let parent_def_id = generics.parent.unwrap();
if let DefKind::Impl { .. } = tcx.def_kind(parent_def_id) {
let parent_ty = tcx.type_of(parent_def_id).subst(tcx, substs);
let parent_ty = tcx.type_of(parent_def_id).instantiate(tcx, args);
match (parent_ty.kind(), &ty.kind) {
(
ty::Adt(def, substs),
ty::Adt(def, args),
hir::TyKind::Path(hir::QPath::Resolved(_self_ty, path)),
) => {
if tcx.res_generics_def_id(path.res) != Some(def.did()) {
@ -1092,14 +1092,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
// so there's nothing for us to do here.
Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {}
_ => warn!(
"unexpected path: def={:?} substs={:?} path={:?}",
def, substs, path,
"unexpected path: def={:?} args={:?} path={:?}",
def, args, path,
),
}
} else {
return Box::new(
self.resolved_path_inferred_subst_iter(path, substs)
.chain(segment),
self.resolved_path_inferred_arg_iter(path, args).chain(segment),
);
}
}
@ -1187,27 +1186,27 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
_ => intravisit::walk_expr(self, expr),
}
for args in self.expr_inferred_subst_iter(expr) {
for args in self.expr_inferred_arg_iter(expr) {
debug!(?args);
let InsertableGenericArgs {
insert_span,
substs,
args,
generics_def_id,
def_id,
have_turbofish,
} = args;
let generics = tcx.generics_of(generics_def_id);
if let Some(mut argument_index) = generics
.own_substs(substs)
.own_args(args)
.iter()
.position(|&arg| self.generic_arg_contains_target(arg))
{
if generics.parent.is_none() && generics.has_self {
argument_index += 1;
}
let substs = self.infcx.resolve_vars_if_possible(substs);
let generic_args = &generics.own_substs_no_defaults(tcx, substs)
[generics.own_counts().lifetimes..];
let args = self.infcx.resolve_vars_if_possible(args);
let generic_args =
&generics.own_args_no_defaults(tcx, args)[generics.own_counts().lifetimes..];
let span = match expr.kind {
ExprKind::MethodCall(path, ..) => path.ident.span,
_ => expr.span,
@ -1230,10 +1229,10 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
if let Some(node_ty) = self.opt_node_type(expr.hir_id) {
if let (
&ExprKind::Closure(&Closure { fn_decl, body, fn_decl_span, .. }),
ty::Closure(_, substs),
ty::Closure(_, args),
) = (&expr.kind, node_ty.kind())
{
let output = substs.as_closure().sig().output().skip_binder();
let output = args.as_closure().sig().output().skip_binder();
if self.generic_arg_contains_target(output.into()) {
let body = self.infcx.tcx.hir().body(body);
let should_wrap_expr = if matches!(body.value.kind, ExprKind::Block(..)) {
@ -1259,22 +1258,22 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
})
.any(|generics| generics.has_impl_trait())
};
if let ExprKind::MethodCall(path, receiver, args, span) = expr.kind
&& let Some(substs) = self.node_substs_opt(expr.hir_id)
&& substs.iter().any(|arg| self.generic_arg_contains_target(arg))
if let ExprKind::MethodCall(path, receiver, method_args, span) = expr.kind
&& let Some(args) = self.node_args_opt(expr.hir_id)
&& args.iter().any(|arg| self.generic_arg_contains_target(arg))
&& let Some(def_id) = self.typeck_results.type_dependent_def_id(expr.hir_id)
&& self.infcx.tcx.trait_of_item(def_id).is_some()
&& !has_impl_trait(def_id)
{
let successor =
args.get(0).map_or_else(|| (")", span.hi()), |arg| (", ", arg.span.lo()));
let substs = self.infcx.resolve_vars_if_possible(substs);
method_args.get(0).map_or_else(|| (")", span.hi()), |arg| (", ", arg.span.lo()));
let args = self.infcx.resolve_vars_if_possible(args);
self.update_infer_source(InferSource {
span: path.ident.span,
kind: InferSourceKind::FullyQualifiedMethodCall {
receiver,
successor,
substs,
args,
def_id,
}
})

View file

@ -74,7 +74,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
};
// Next, let's figure out the set of trait objects with implicit static bounds
let ty = self.tcx().type_of(*impl_def_id).subst_identity();
let ty = self.tcx().type_of(*impl_def_id).instantiate_identity();
let mut v = super::static_impl_trait::TraitObjectVisitor(FxIndexSet::default());
v.visit_ty(ty);
let mut traits = vec![];

View file

@ -13,7 +13,7 @@ use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{self, RePlaceholder, Region, TyCtxt};
use std::fmt;
@ -196,11 +196,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sup_placeholder: Option<Region<'tcx>>,
value_pairs: &ValuePairs<'tcx>,
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
let (expected_substs, found_substs, trait_def_id) = match value_pairs {
let (expected_args, found_args, trait_def_id) = match value_pairs {
ValuePairs::TraitRefs(ExpectedFound { expected, found })
if expected.def_id == found.def_id =>
{
(expected.substs, found.substs, expected.def_id)
(expected.args, found.args, expected.def_id)
}
ValuePairs::PolyTraitRefs(ExpectedFound { expected, found })
if expected.def_id() == found.def_id() =>
@ -208,7 +208,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
// It's possible that the placeholders come from a binder
// outside of this value pair. Use `no_bound_vars` as a
// simple heuristic for that.
(expected.no_bound_vars()?.substs, found.no_bound_vars()?.substs, expected.def_id())
(expected.no_bound_vars()?.args, found.no_bound_vars()?.args, expected.def_id())
}
_ => return None,
};
@ -219,8 +219,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sub_placeholder,
sup_placeholder,
trait_def_id,
expected_substs,
found_substs,
expected_args,
found_args,
))
}
@ -241,8 +241,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sub_placeholder: Option<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
trait_def_id: DefId,
expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>,
expected_args: GenericArgsRef<'tcx>,
actual_args: GenericArgsRef<'tcx>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let span = cause.span();
@ -264,12 +264,12 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new(
self.cx.tcx,
trait_def_id,
expected_substs,
expected_args,
));
let actual_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new(
self.cx.tcx,
trait_def_id,
actual_substs,
actual_args,
));
// Search the expected and actual trait references to see (a)
@ -413,9 +413,9 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
if self_ty.value.is_closure() && self.tcx().is_fn_trait(expected_trait_ref.value.def_id)
{
let closure_sig = self_ty.map(|closure| {
if let ty::Closure(_, substs) = closure.kind() {
if let ty::Closure(_, args) = closure.kind() {
self.tcx().signature_unclosure(
substs.as_closure().sig(),
args.as_closure().sig(),
rustc_hir::Unsafety::Normal,
)
} else {

View file

@ -288,7 +288,7 @@ pub fn suggest_new_region_bound(
// Get the identity type for this RPIT
let did = item_id.owner_id.to_def_id();
let ty = Ty::new_opaque(tcx, did, ty::InternalSubsts::identity_for_item(tcx, did));
let ty = Ty::new_opaque(tcx, did, ty::GenericArgs::identity_for_item(tcx, did));
if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
GenericBound::Outlives(Lifetime {
@ -493,7 +493,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
tcx,
ctxt.param_env,
ctxt.assoc_item.def_id,
self.cx.resolve_vars_if_possible(ctxt.substs),
self.cx.resolve_vars_if_possible(ctxt.args),
) else {
return false;
};

View file

@ -65,7 +65,7 @@ pub fn find_param_with_region<'tcx>(
let owner_id = hir.body_owner(body_id);
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
let poly_fn_sig = tcx.fn_sig(id).subst_identity();
let poly_fn_sig = tcx.fn_sig(id).instantiate_identity();
let fn_sig = tcx.liberate_late_bound_regions(id, poly_fn_sig);
let body = hir.body(body_id);
@ -123,7 +123,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
br: ty::BoundRegionKind,
hir_sig: &hir::FnSig<'_>,
) -> Option<Span> {
let fn_ty = self.tcx().type_of(scope_def_id).subst_identity();
let fn_ty = self.tcx().type_of(scope_def_id).instantiate_identity();
if let ty::FnDef(_, _) = fn_ty.kind() {
let ret_ty = fn_ty.fn_sig(self.tcx()).output();
let span = hir_sig.decl.output.span();

View file

@ -302,18 +302,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let Some(trait_ref) = self.tcx.impl_trait_ref(impl_def_id) else {
return;
};
let trait_substs = trait_ref
.subst_identity()
let trait_args = trait_ref
.instantiate_identity()
// Replace the explicit self type with `Self` for better suggestion rendering
.with_self_ty(self.tcx, Ty::new_param(self.tcx, 0, kw::SelfUpper))
.substs;
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_substs);
.args;
let trait_item_args = ty::GenericArgs::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_args);
let Ok(trait_predicates) =
self.tcx
.explicit_predicates_of(trait_item_def_id)
.instantiate_own(self.tcx, trait_item_substs)
.instantiate_own(self.tcx, trait_item_args)
.map(|(pred, _)| {
if pred.is_suggestable(self.tcx, false) {
Ok(pred.to_string())

View file

@ -100,9 +100,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
{
// Synthesize the associated type restriction `Add<Output = Expected>`.
// FIXME: extract this logic for use in other diagnostics.
let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(tcx);
let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx);
let item_name = tcx.item_name(proj.def_id);
let item_args = self.format_generic_args(assoc_substs);
let item_args = self.format_generic_args(assoc_args);
// Here, we try to see if there's an existing
// trait implementation that matches the one that
@ -316,7 +316,7 @@ impl<T> Trait<T> for X {
) -> bool {
let tcx = self.tcx;
let assoc = tcx.associated_item(proj_ty.def_id);
let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(tcx);
let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx);
if let Some(item) = tcx.hir().get_if_local(body_owner_def_id) {
if let Some(hir_generics) = item.generics() {
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
@ -339,7 +339,7 @@ impl<T> Trait<T> for X {
&trait_ref,
pred.bounds,
assoc,
assoc_substs,
assoc_args,
ty,
&msg,
false,
@ -488,14 +488,14 @@ fn foo(&self) -> Self::T { String::new() }
return false;
};
let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(tcx);
let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx);
self.constrain_generic_bound_associated_type_structured_suggestion(
diag,
&trait_ref,
opaque_hir_ty.bounds,
assoc,
assoc_substs,
assoc_args,
ty,
msg,
true,
@ -527,7 +527,7 @@ fn foo(&self) -> Self::T { String::new() }
&& !tcx.is_doc_hidden(item.def_id)
})
.filter_map(|item| {
let method = tcx.fn_sig(item.def_id).subst_identity();
let method = tcx.fn_sig(item.def_id).instantiate_identity();
match *method.output().skip_binder().kind() {
ty::Alias(ty::Projection, ty::AliasTy { def_id: item_def_id, .. })
if item_def_id == proj_ty_item_def_id =>
@ -597,7 +597,7 @@ fn foo(&self) -> Self::T { String::new() }
if let hir::Defaultness::Default { has_value: true } =
tcx.defaultness(item.id.owner_id)
{
let assoc_ty = tcx.type_of(item.id.owner_id).subst_identity();
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
if self.infcx.can_eq(param_env, assoc_ty, found) {
diag.span_label(
item.span,
@ -618,7 +618,7 @@ fn foo(&self) -> Self::T { String::new() }
})) => {
for item in &items[..] {
if let hir::AssocItemKind::Type = item.kind {
let assoc_ty = tcx.type_of(item.id.owner_id).subst_identity();
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
if self.infcx.can_eq(param_env, assoc_ty, found) {
diag.span_label(item.span, "expected this associated type");
@ -645,7 +645,7 @@ fn foo(&self) -> Self::T { String::new() }
trait_ref: &ty::TraitRef<'tcx>,
bounds: hir::GenericBounds<'_>,
assoc: ty::AssocItem,
assoc_substs: &[ty::GenericArg<'tcx>],
assoc_args: &[ty::GenericArg<'tcx>],
ty: Ty<'tcx>,
msg: impl Fn() -> String,
is_bound_surely_present: bool,
@ -671,14 +671,7 @@ fn foo(&self) -> Self::T { String::new() }
_ => return false,
};
self.constrain_associated_type_structured_suggestion(
diag,
span,
assoc,
assoc_substs,
ty,
msg,
)
self.constrain_associated_type_structured_suggestion(diag, span, assoc, assoc_args, ty, msg)
}
/// Given a span corresponding to a bound, provide a structured suggestion to set an
@ -688,7 +681,7 @@ fn foo(&self) -> Self::T { String::new() }
diag: &mut Diagnostic,
span: Span,
assoc: ty::AssocItem,
assoc_substs: &[ty::GenericArg<'tcx>],
assoc_args: &[ty::GenericArg<'tcx>],
ty: Ty<'tcx>,
msg: impl Fn() -> String,
) -> bool {
@ -702,7 +695,7 @@ fn foo(&self) -> Self::T { String::new() }
let span = Span::new(pos, pos, span.ctxt(), span.parent());
(span, format!(", {} = {}", assoc.ident(tcx), ty))
} else {
let item_args = self.format_generic_args(assoc_substs);
let item_args = self.format_generic_args(assoc_args);
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(tcx), item_args, ty))
};
diag.span_suggestion_verbose(span, msg(), sugg, MaybeIncorrect);

View file

@ -105,7 +105,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Heavily inspired by `FnCtxt::suggest_compatible_variants`, with
// some modifications due to that being in typeck and this being in infer.
if let ObligationCauseCode::Pattern { .. } = cause.code() {
if let ty::Adt(expected_adt, substs) = exp_found.expected.kind() {
if let ty::Adt(expected_adt, args) = exp_found.expected.kind() {
let compatible_variants: Vec<_> = expected_adt
.variants()
.iter()
@ -114,7 +114,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
})
.filter_map(|variant| {
let sole_field = &variant.single_field();
let sole_field_ty = sole_field.ty(self.tcx, substs);
let sole_field_ty = sole_field.ty(self.tcx, args);
if self.same_type_modulo_infer(sole_field_ty, exp_found.found) {
let variant_path =
with_no_trimmed_paths!(self.tcx.def_path_str(variant.def_id));
@ -260,7 +260,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
"suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})",
cause, exp_found
);
if let ty::Adt(expected_def, expected_substs) = exp_found.expected.kind() {
if let ty::Adt(expected_def, expected_args) = exp_found.expected.kind() {
if expected_def.is_enum() {
return;
}
@ -270,7 +270,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.fields
.iter()
.filter(|field| field.vis.is_accessible_from(field.did, self.tcx))
.map(|field| (field.name, field.ty(self.tcx, expected_substs)))
.map(|field| (field.name, field.ty(self.tcx, expected_args)))
.find(|(_, ty)| self.same_type_modulo_infer(*ty, exp_found.found))
{
if let ObligationCauseCode::Pattern { span: Some(span), .. } = *cause.code() {
@ -304,12 +304,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
return;
}
match (&expected_inner.kind(), &found_inner.kind()) {
(ty::FnPtr(sig), ty::FnDef(did, substs)) => {
(ty::FnPtr(sig), ty::FnDef(did, args)) => {
let expected_sig = &(self.normalize_fn_sig)(*sig);
let found_sig =
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did).subst(self.tcx, substs));
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did).instantiate(self.tcx, args));
let fn_name = self.tcx.def_path_str_with_substs(*did, substs);
let fn_name = self.tcx.def_path_str_with_args(*did, args);
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
|| !sig.is_suggestable(self.tcx, true)
@ -332,11 +332,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
};
diag.subdiagnostic(sugg);
}
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
let expected_sig =
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did1).subst(self.tcx, substs1));
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did1).instantiate(self.tcx, args1));
let found_sig =
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did2).subst(self.tcx, substs2));
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did2).instantiate(self.tcx, args2));
if self.same_type_modulo_infer(*expected_sig, *found_sig) {
diag.subdiagnostic(FnUniqTypes);
@ -351,7 +351,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
return;
}
let fn_name = self.tcx.def_path_str_with_substs(*did2, substs2);
let fn_name = self.tcx.def_path_str_with_args(*did2, args2);
let sug = if found.is_ref() {
FunctionPointerSuggestion::CastBothRef {
span,
@ -370,16 +370,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
diag.subdiagnostic(sug);
}
(ty::FnDef(did, substs), ty::FnPtr(sig)) => {
(ty::FnDef(did, args), ty::FnPtr(sig)) => {
let expected_sig =
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did).subst(self.tcx, substs));
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did).instantiate(self.tcx, args));
let found_sig = &(self.normalize_fn_sig)(*sig);
if !self.same_type_modulo_infer(*found_sig, *expected_sig) {
return;
}
let fn_name = self.tcx.def_path_str_with_substs(*did, substs);
let fn_name = self.tcx.def_path_str_with_args(*did, args);
let casting = if expected.is_ref() {
format!("&({fn_name} as {found_sig})")
@ -400,10 +400,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
expected: Ty<'tcx>,
found: Ty<'tcx>,
) -> Option<SuggestAsRefKind> {
if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) =
if let (ty::Adt(exp_def, exp_args), ty::Ref(_, found_ty, _)) =
(expected.kind(), found.kind())
{
if let ty::Adt(found_def, found_substs) = *found_ty.kind() {
if let ty::Adt(found_def, found_args) = *found_ty.kind() {
if exp_def == &found_def {
let have_as_ref = &[
(sym::Option, SuggestAsRefKind::Option),
@ -414,7 +414,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}) {
let mut show_suggestion = true;
for (exp_ty, found_ty) in
std::iter::zip(exp_substs.types(), found_substs.types())
std::iter::zip(exp_args.types(), found_args.types())
{
match *exp_ty.kind() {
ty::Ref(_, exp_ty, _) => {
@ -535,12 +535,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
};
let hir::Body { params, .. } = self.tcx.hir().body(*body);
// 1. Get the substs of the closure.
// 1. Get the args of the closure.
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
let Some(expected) = exp_found.expected.skip_binder().substs.get(1) else {
let Some(expected) = exp_found.expected.skip_binder().args.get(1) else {
return;
};
let Some(found) = exp_found.found.skip_binder().substs.get(1) else {
let Some(found) = exp_found.found.skip_binder().args.get(1) else {
return;
};
let expected = expected.unpack();
@ -631,8 +631,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, .. }),
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
(
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds, .. }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds, .. }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, args: last_bounds, .. }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, args: exp_bounds, .. }),
) => {
debug!(
"both opaque, likely future {:?} {:?} {:?} {:?}",

View file

@ -11,7 +11,7 @@
//!
//! To handle closures, freshened types also have to contain the signature and kind of any
//! closure in the local inference context, as otherwise the cache key might be invalidated.
//! The way this is done is somewhat hacky - the closure signature is appended to the substs,
//! The way this is done is somewhat hacky - the closure signature is appended to the args,
//! as well as the closure kind "encoded" as a type. Also, special handling is needed when
//! the closure signature contains a reference to the original closure.
//!

View file

@ -173,21 +173,21 @@ where
true
}
fn relate_item_substs(
fn relate_item_args(
&mut self,
item_def_id: DefId,
a_subst: ty::SubstsRef<'tcx>,
b_subst: ty::SubstsRef<'tcx>,
) -> RelateResult<'tcx, ty::SubstsRef<'tcx>> {
a_subst: ty::GenericArgsRef<'tcx>,
b_subst: ty::GenericArgsRef<'tcx>,
) -> RelateResult<'tcx, ty::GenericArgsRef<'tcx>> {
if self.ambient_variance == ty::Variance::Invariant {
// Avoid fetching the variance if we are in an invariant
// context; no need, and it can induce dependency cycles
// (e.g., #41849).
relate::relate_substs(self, a_subst, b_subst)
relate::relate_args(self, a_subst, b_subst)
} else {
let tcx = self.tcx();
let opt_variances = tcx.variances_of(item_def_id);
relate::relate_substs_with_variances(
relate::relate_args_with_variances(
self,
item_def_id,
opt_variances,
@ -405,16 +405,16 @@ where
}
// FIXME: remove this branch once `structurally_relate_consts` is fully
// structural.
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
let substs = self.relate_with_variance(
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
let args = self.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
substs,
substs,
args,
args,
)?;
Ok(ty::Const::new_unevaluated(
self.tcx(),
ty::UnevaluatedConst { def, substs },
ty::UnevaluatedConst { def, args },
c.ty(),
))
}

View file

@ -30,11 +30,11 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::relate::RelateResult;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
pub use rustc_middle::ty::IntVarValue;
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtxt};
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
@ -1184,8 +1184,8 @@ impl<'tcx> InferCtxt<'tcx> {
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
/// type/region parameter to a fresh inference variable.
pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'tcx> {
InternalSubsts::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
pub fn fresh_args_for_item(&self, span: Span, def_id: DefId) -> GenericArgsRef<'tcx> {
GenericArgs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
}
/// Returns `true` if errors have been reported since this infcx was
@ -1474,8 +1474,8 @@ impl<'tcx> InferCtxt<'tcx> {
/// Obtains the latest type of the given closure; this may be a
/// closure in the current function, in which case its
/// `ClosureKind` may not yet be known.
pub fn closure_kind(&self, closure_substs: SubstsRef<'tcx>) -> Option<ty::ClosureKind> {
let closure_kind_ty = closure_substs.as_closure().kind_ty();
pub fn closure_kind(&self, closure_args: GenericArgsRef<'tcx>) -> Option<ty::ClosureKind> {
let closure_kind_ty = closure_args.as_closure().kind_ty();
let closure_kind_ty = self.shallow_resolve(closure_kind_ty);
closure_kind_ty.to_opt_closure_kind()
}
@ -1534,7 +1534,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// too generic for the constant to be evaluated then `Err(ErrorHandled::TooGeneric)` is
/// returned.
///
/// This handles inferences variables within both `param_env` and `substs` by
/// This handles inferences variables within both `param_env` and `args` by
/// performing the operation on their respective canonical forms.
#[instrument(skip(self), level = "debug")]
pub fn const_eval_resolve(
@ -1543,34 +1543,34 @@ impl<'tcx> InferCtxt<'tcx> {
unevaluated: ty::UnevaluatedConst<'tcx>,
span: Option<Span>,
) -> EvalToValTreeResult<'tcx> {
let mut substs = self.resolve_vars_if_possible(unevaluated.substs);
debug!(?substs);
let mut args = self.resolve_vars_if_possible(unevaluated.args);
debug!(?args);
// Postpone the evaluation of constants whose substs depend on inference
// Postpone the evaluation of constants whose args depend on inference
// variables
let tcx = self.tcx;
if substs.has_non_region_infer() {
if args.has_non_region_infer() {
if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? {
let ct = tcx.expand_abstract_consts(ct.subst(tcx, substs));
let ct = tcx.expand_abstract_consts(ct.instantiate(tcx, args));
if let Err(e) = ct.error_reported() {
return Err(ErrorHandled::Reported(e.into()));
} else if ct.has_non_region_infer() || ct.has_non_region_param() {
return Err(ErrorHandled::TooGeneric);
} else {
substs = replace_param_and_infer_substs_with_placeholder(tcx, substs);
args = replace_param_and_infer_args_with_placeholder(tcx, args);
}
} else {
substs = InternalSubsts::identity_for_item(tcx, unevaluated.def);
args = GenericArgs::identity_for_item(tcx, unevaluated.def);
param_env = tcx.param_env(unevaluated.def);
}
}
let param_env_erased = tcx.erase_regions(param_env);
let substs_erased = tcx.erase_regions(substs);
let args_erased = tcx.erase_regions(args);
debug!(?param_env_erased);
debug!(?substs_erased);
debug!(?args_erased);
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, substs: substs_erased };
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, args: args_erased };
// The return value is the evaluated value which doesn't contain any reference to inference
// variables, thus we don't need to substitute back the original values.
@ -1959,13 +1959,13 @@ impl RegionVariableOrigin {
}
}
/// Replaces substs that reference param or infer variables with suitable
/// Replaces args that reference param or infer variables with suitable
/// placeholders. This function is meant to remove these param and infer
/// substs when they're not actually needed to evaluate a constant.
fn replace_param_and_infer_substs_with_placeholder<'tcx>(
/// args when they're not actually needed to evaluate a constant.
fn replace_param_and_infer_args_with_placeholder<'tcx>(
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
) -> SubstsRef<'tcx> {
args: GenericArgsRef<'tcx>,
) -> GenericArgsRef<'tcx> {
struct ReplaceParamAndInferWithPlaceholder<'tcx> {
tcx: TyCtxt<'tcx>,
idx: u32,
@ -2023,5 +2023,5 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
}
}
substs.fold_with(&mut ReplaceParamAndInferWithPlaceholder { tcx, idx: 0 })
args.fold_with(&mut ReplaceParamAndInferWithPlaceholder { tcx, idx: 0 })
}

View file

@ -103,7 +103,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) if def_id.is_local() => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
let def_id = def_id.expect_local();
match self.defining_use_anchor {
DefiningAnchor::Bind(_) => {
@ -165,7 +165,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
}
Some(self.register_hidden_type(
OpaqueTypeKey { def_id, substs },
OpaqueTypeKey { def_id, args },
cause.clone(),
param_env,
b,
@ -214,12 +214,12 @@ impl<'tcx> InferCtxt<'tcx> {
/// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
/// // ^^^^ ^^
/// // | |
/// // | substs
/// // | args
/// // def_id
/// ```
///
/// As indicating in the comments above, each of those references
/// is (in the compiler) basically a substitution (`substs`)
/// is (in the compiler) basically a substitution (`args`)
/// applied to the type of a suitable `def_id` (which identifies
/// `Foo1` or `Foo2`).
///
@ -278,7 +278,7 @@ impl<'tcx> InferCtxt<'tcx> {
///
/// We generally prefer to make `<=` constraints, since they
/// integrate best into the region solver. To do that, we find the
/// "minimum" of all the arguments that appear in the substs: that
/// "minimum" of all the arguments that appear in the args: that
/// is, some region which is less than all the others. In the case
/// of `Foo1<'a>`, that would be `'a` (it's the only choice, after
/// all). Then we apply that as a least bound to the variables
@ -350,7 +350,7 @@ impl<'tcx> InferCtxt<'tcx> {
// opaque type definition.
let choice_regions: Lrc<Vec<ty::Region<'tcx>>> = Lrc::new(
opaque_type_key
.substs
.args
.iter()
.enumerate()
.filter(|(i, _)| variances[*i] == ty::Variance::Invariant)
@ -445,28 +445,28 @@ where
}
match ty.kind() {
ty::Closure(_, ref substs) => {
ty::Closure(_, ref args) => {
// Skip lifetime parameters of the enclosing item(s)
substs.as_closure().tupled_upvars_ty().visit_with(self);
substs.as_closure().sig_as_fn_ptr_ty().visit_with(self);
args.as_closure().tupled_upvars_ty().visit_with(self);
args.as_closure().sig_as_fn_ptr_ty().visit_with(self);
}
ty::Generator(_, ref substs, _) => {
ty::Generator(_, ref args, _) => {
// Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions.
substs.as_generator().tupled_upvars_ty().visit_with(self);
substs.as_generator().return_ty().visit_with(self);
substs.as_generator().yield_ty().visit_with(self);
substs.as_generator().resume_ty().visit_with(self);
args.as_generator().tupled_upvars_ty().visit_with(self);
args.as_generator().return_ty().visit_with(self);
args.as_generator().yield_ty().visit_with(self);
args.as_generator().resume_ty().visit_with(self);
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs, .. }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref args, .. }) => {
// Skip lifetime parameters that are not captures.
let variances = self.tcx.variances_of(*def_id);
for (v, s) in std::iter::zip(variances, substs.iter()) {
for (v, s) in std::iter::zip(variances, args.iter()) {
if *v != ty::Variance::Bivariant {
s.visit_with(self);
}
@ -519,7 +519,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.add_item_bounds_for_hidden_type(
opaque_type_key.def_id.to_def_id(),
opaque_type_key.substs,
opaque_type_key.args,
cause,
param_env,
hidden_ty,
@ -582,7 +582,7 @@ impl<'tcx> InferCtxt<'tcx> {
pub fn add_item_bounds_for_hidden_type(
&self,
def_id: DefId,
substs: ty::SubstsRef<'tcx>,
args: ty::GenericArgsRef<'tcx>,
cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
hidden_ty: Ty<'tcx>,
@ -591,7 +591,7 @@ impl<'tcx> InferCtxt<'tcx> {
let tcx = self.tcx;
let item_bounds = tcx.explicit_item_bounds(def_id);
for (predicate, _) in item_bounds.subst_iter_copied(tcx, substs) {
for (predicate, _) in item_bounds.arg_iter_copied(tcx, args) {
let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx,
ty_op: |ty| match *ty.kind() {
@ -614,17 +614,18 @@ impl<'tcx> InferCtxt<'tcx> {
}
// Replace all other mentions of the same opaque type with the hidden type,
// as the bounds must hold on the hidden type after all.
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2, .. })
if def_id == def_id2 && substs == substs2 =>
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, args: args2, .. })
if def_id == def_id2 && args == args2 =>
{
hidden_ty
}
// FIXME(RPITIT): This can go away when we move to associated types
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
ty::Alias(
ty::Projection,
ty::AliasTy { def_id: def_id2, substs: substs2, .. },
) if def_id == def_id2 && substs == substs2 => hidden_ty,
ty::Alias(ty::Projection, ty::AliasTy { def_id: def_id2, args: args2, .. })
if def_id == def_id2 && args == args2 =>
{
hidden_ty
}
_ => ty,
},
lt_op: |lt| lt,

View file

@ -3,8 +3,8 @@
// RFC for reference.
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{GenericArg, GenericArgKind};
use smallvec::{smallvec, SmallVec};
#[derive(Debug)]
@ -71,15 +71,15 @@ fn compute_components<'tcx>(
// in the `subtys` iterator (e.g., when encountering a
// projection).
match *ty.kind() {
ty::FnDef(_, substs) => {
// HACK(eddyb) ignore lifetimes found shallowly in `substs`.
// This is inconsistent with `ty::Adt` (including all substs)
// and with `ty::Closure` (ignoring all substs other than
ty::FnDef(_, args) => {
// HACK(eddyb) ignore lifetimes found shallowly in `args`.
// This is inconsistent with `ty::Adt` (including all args)
// and with `ty::Closure` (ignoring all args other than
// upvars, of which a `ty::FnDef` doesn't have any), but
// consistent with previous (accidental) behavior.
// See https://github.com/rust-lang/rust/issues/70917
// for further background and discussion.
for child in substs {
for child in args {
match child.unpack() {
GenericArgKind::Type(ty) => {
compute_components(tcx, ty, out, visited);
@ -97,14 +97,14 @@ fn compute_components<'tcx>(
compute_components(tcx, element, out, visited);
}
ty::Closure(_, ref substs) => {
let tupled_ty = substs.as_closure().tupled_upvars_ty();
ty::Closure(_, ref args) => {
let tupled_ty = args.as_closure().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);
}
ty::Generator(_, ref substs, _) => {
ty::Generator(_, ref args, _) => {
// Same as the closure case
let tupled_ty = substs.as_generator().tupled_upvars_ty();
let tupled_ty = args.as_generator().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited);
// We ignore regions in the generator interior as we don't
@ -189,7 +189,7 @@ fn compute_components<'tcx>(
}
}
/// Collect [Component]s for *all* the substs of `parent`.
/// Collect [Component]s for *all* the args of `parent`.
///
/// This should not be used to get the components of `parent` itself.
/// Use [push_outlives_components] instead.
@ -201,7 +201,7 @@ pub(super) fn compute_alias_components_recursive<'tcx>(
) {
let ty::Alias(kind, alias_ty) = alias_ty.kind() else { bug!() };
let opt_variances = if *kind == ty::Opaque { tcx.variances_of(alias_ty.def_id) } else { &[] };
for (index, child) in alias_ty.substs.iter().enumerate() {
for (index, child) in alias_ty.args.iter().enumerate() {
if opt_variances.get(index) == Some(&ty::Bivariant) {
continue;
}
@ -225,7 +225,7 @@ pub(super) fn compute_alias_components_recursive<'tcx>(
}
}
/// Collect [Component]s for *all* the substs of `parent`.
/// Collect [Component]s for *all* the args of `parent`.
///
/// This should not be used to get the components of `parent` itself.
/// Use [push_outlives_components] instead.

View file

@ -68,8 +68,8 @@ use crate::infer::{
use crate::traits::{ObligationCause, ObligationCauseCode};
use rustc_data_structures::undo_log::UndoLogs;
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, Region, SubstsRef, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::{self, GenericArgsRef, Region, Ty, TyCtxt, TypeVisitableExt};
use smallvec::smallvec;
use super::env::OutlivesEnvironment;
@ -279,7 +279,7 @@ where
alias_ty: ty::AliasTy<'tcx>,
) {
// An optimization for a common case with opaque types.
if alias_ty.substs.is_empty() {
if alias_ty.args.is_empty() {
return;
}
@ -348,7 +348,7 @@ where
{
debug!("no declared bounds");
let opt_variances = is_opaque.then(|| self.tcx.variances_of(alias_ty.def_id));
self.substs_must_outlive(alias_ty.substs, origin, region, opt_variances);
self.args_must_outlive(alias_ty.args, origin, region, opt_variances);
return;
}
@ -395,15 +395,15 @@ where
}
#[instrument(level = "debug", skip(self))]
fn substs_must_outlive(
fn args_must_outlive(
&mut self,
substs: SubstsRef<'tcx>,
args: GenericArgsRef<'tcx>,
origin: infer::SubregionOrigin<'tcx>,
region: ty::Region<'tcx>,
opt_variances: Option<&[ty::Variance]>,
) {
let constraint = origin.to_constraint_category();
for (index, k) in substs.iter().enumerate() {
for (index, k) in args.iter().enumerate() {
match k.unpack() {
GenericArgKind::Lifetime(lt) => {
let variance = if let Some(variances) = opt_variances {

View file

@ -157,7 +157,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
a: T,
b: T,
) -> RelateResult<'tcx, T> {
// Opaque types substs have lifetime parameters.
// Opaque types args have lifetime parameters.
// We must not check them to be equal, as we never insert anything to make them so.
if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) }
}

View file

@ -295,7 +295,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
let bounds = tcx.item_bounds(alias_ty.def_id);
trace!("{:#?}", bounds.skip_binder());
bounds
.subst_iter(tcx, alias_ty.substs)
.arg_iter(tcx, alias_ty.args)
.filter_map(|p| p.as_type_outlives_clause())
.filter_map(|p| p.no_bound_vars())
.map(|OutlivesPredicate(_, r)| r)

View file

@ -125,7 +125,7 @@ pub enum TypeVariableOriginKind {
OpaqueTypeInference(DefId),
TypeParameterDefinition(Symbol, DefId),
/// One of the upvars or closure kind parameters in a `ClosureSubsts`
/// One of the upvars or closure kind parameters in a `ClosureArgs`
/// (before it has been determined).
// FIXME(eddyb) distinguish upvar inference variables from the rest.
ClosureSynthetic,