summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_analysis/src/astconv
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_hir_analysis/src/astconv
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_hir_analysis/src/astconv')
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/bounds.rs45
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/errors.rs22
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/generics.rs50
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/lint.rs6
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/mod.rs319
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/object_safety.rs33
6 files changed, 251 insertions, 224 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
index b13de7701..ba152cd48 100644
--- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
@@ -13,7 +13,7 @@ use crate::astconv::{
AstConv, ConvertedBinding, ConvertedBindingKind, OnlySelfBounds, PredicateFilter,
};
use crate::bounds::Bounds;
-use crate::errors::{MultipleRelaxedDefaultBounds, ValueOfAssociatedStructAlreadySpecified};
+use crate::errors;
impl<'tcx> dyn AstConv<'tcx> + '_ {
/// Sets `implicitly_sized` to true on `Bounds` if necessary
@@ -35,7 +35,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
if unbound.is_none() {
unbound = Some(&ptr.trait_ref);
} else {
- tcx.sess.emit_err(MultipleRelaxedDefaultBounds { span });
+ tcx.sess.emit_err(errors::MultipleRelaxedDefaultBounds { span });
}
}
}
@@ -326,7 +326,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
dup_bindings
.entry(assoc_item.def_id)
.and_modify(|prev_span| {
- tcx.sess.emit_err(ValueOfAssociatedStructAlreadySpecified {
+ tcx.sess.emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
span: binding.span,
prev_span: *prev_span,
item_name: binding.item_name,
@@ -341,8 +341,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
// If we have an method return type bound, then we need to substitute
// the method's early bound params with suitable late-bound params.
let mut num_bound_vars = candidate.bound_vars().len();
- let substs =
- candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
+ let args =
+ candidate.skip_binder().args.extend_to(tcx, assoc_item.def_id, |param, _| {
let subst = match param.kind {
ty::GenericParamDefKind::Lifetime => ty::Region::new_late_bound(
tcx,
@@ -422,7 +422,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
// params (and trait ref's late bound params). This logic is very similar to
// `Predicate::subst_supertrait`, and it's no coincidence why.
let shifted_output = tcx.shift_bound_var_indices(num_bound_vars, output);
- let subst_output = ty::EarlyBinder::bind(shifted_output).subst(tcx, substs);
+ let subst_output = ty::EarlyBinder::bind(shifted_output).instantiate(tcx, args);
let bound_vars = tcx.late_bound_vars(binding.hir_id);
ty::Binder::bind_with_vars(subst_output, bound_vars)
@@ -438,16 +438,16 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
infer_args: false,
};
- let substs_trait_ref_and_assoc_item = self.create_substs_for_associated_item(
+ let args_trait_ref_and_assoc_item = self.create_args_for_associated_item(
path_span,
assoc_item.def_id,
&item_segment,
- trait_ref.substs,
+ trait_ref.args,
);
- debug!(?substs_trait_ref_and_assoc_item);
+ debug!(?args_trait_ref_and_assoc_item);
- tcx.mk_alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item)
+ tcx.mk_alias_ty(assoc_item.def_id, args_trait_ref_and_assoc_item)
})
};
@@ -488,6 +488,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
}
}
+ let assoc_item_def_id = projection_ty.skip_binder().def_id;
+ let def_kind = tcx.def_kind(assoc_item_def_id);
match binding.kind {
ConvertedBindingKind::Equality(..) if return_type_notation => {
return Err(self.tcx().sess.emit_err(
@@ -499,11 +501,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
// the "projection predicate" for:
//
// `<T as Iterator>::Item = u32`
- let assoc_item_def_id = projection_ty.skip_binder().def_id;
- let def_kind = tcx.def_kind(assoc_item_def_id);
match (def_kind, term.unpack()) {
- (hir::def::DefKind::AssocTy, ty::TermKind::Ty(_))
- | (hir::def::DefKind::AssocConst, ty::TermKind::Const(_)) => (),
+ (DefKind::AssocTy, ty::TermKind::Ty(_))
+ | (DefKind::AssocConst, ty::TermKind::Const(_)) => (),
(_, _) => {
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
let expected = tcx.def_descr(assoc_item_def_id);
@@ -516,7 +516,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
format!("{expected} defined here"),
);
- if let hir::def::DefKind::AssocConst = def_kind
+ if let DefKind::AssocConst = def_kind
&& let Some(t) = term.ty() && (t.is_enum() || t.references_error())
&& tcx.features().associated_const_equality {
err.span_suggestion(
@@ -528,12 +528,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
}
let reported = err.emit();
term = match def_kind {
- hir::def::DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
- hir::def::DefKind::AssocConst => ty::Const::new_error(
+ DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
+ DefKind::AssocConst => ty::Const::new_error(
tcx,
reported,
tcx.type_of(assoc_item_def_id)
- .subst(tcx, projection_ty.skip_binder().substs),
+ .instantiate(tcx, projection_ty.skip_binder().args),
)
.into(),
_ => unreachable!(),
@@ -548,6 +548,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
);
}
ConvertedBindingKind::Constraint(ast_bounds) => {
+ match def_kind {
+ DefKind::AssocTy => {}
+ _ => {
+ return Err(tcx.sess.emit_err(errors::AssocBoundOnConst {
+ span: assoc_ident.span,
+ descr: tcx.def_descr(assoc_item_def_id),
+ }));
+ }
+ }
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
//
// `<T as Iterator>::Item: Debug`
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs
index ddf99853b..bd311c98f 100644
--- a/compiler/rustc_hir_analysis/src/astconv/errors.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs
@@ -123,7 +123,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let all_candidate_names: Vec<_> = all_candidates()
.flat_map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
.filter_map(|item| {
- if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
+ if !item.is_impl_trait_in_trait() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None
@@ -164,7 +164,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.tcx().associated_items(*trait_def_id).in_definition_order()
})
.filter_map(|item| {
- if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
+ if !item.is_impl_trait_in_trait() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None
@@ -197,7 +197,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
- err.span_label(span, format!("associated type `{}` not found", assoc_name));
+ err.span_label(span, format!("associated type `{assoc_name}` not found"));
err.emit()
}
@@ -247,7 +247,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"the candidate".into()
};
- let impl_ty = tcx.at(span).type_of(impl_).subst_identity();
+ let impl_ty = tcx.at(span).type_of(impl_).instantiate_identity();
let note = format!("{title} is defined in an impl for the type `{impl_ty}`");
if let Some(span) = note_span {
@@ -295,7 +295,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let type_candidates = candidates
.iter()
.take(limit)
- .map(|&(impl_, _)| format!("- `{}`", tcx.at(span).type_of(impl_).subst_identity()))
+ .map(|&(impl_, _)| {
+ format!("- `{}`", tcx.at(span).type_of(impl_).instantiate_identity())
+ })
.collect::<Vec<_>>()
.join("\n");
let additional_types = if candidates.len() > limit {
@@ -356,13 +358,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// `<Foo as Iterator>::Item = String`.
let projection_ty = pred.skip_binder().projection_ty;
- let substs_with_infer_self = tcx.mk_substs_from_iter(
+ let args_with_infer_self = tcx.mk_args_from_iter(
std::iter::once(Ty::new_var(tcx, ty::TyVid::from_u32(0)).into())
- .chain(projection_ty.substs.iter().skip(1)),
+ .chain(projection_ty.args.iter().skip(1)),
);
let quiet_projection_ty =
- tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self);
+ tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
let term = pred.skip_binder().term;
@@ -391,7 +393,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.into_iter()
.map(|error| error.root_obligation.predicate)
.filter_map(format_pred)
- .map(|(p, _)| format!("`{}`", p))
+ .map(|(p, _)| format!("`{p}`"))
.collect();
bounds.sort();
bounds.dedup();
@@ -650,7 +652,7 @@ pub(crate) fn fn_trait_to_string(
}
.map(|s| {
// `s.empty()` checks to see if the type is the unit tuple, if so we don't want a comma
- if parenthesized || s.is_empty() { format!("({})", s) } else { format!("({},)", s) }
+ if parenthesized || s.is_empty() { format!("({s})") } else { format!("({s},)") }
})
.ok(),
_ => None,
diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs
index 39d1d1f2d..1372cc896 100644
--- a/compiler/rustc_hir_analysis/src/astconv/generics.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs
@@ -11,7 +11,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::GenericArg;
use rustc_middle::ty::{
- self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
+ self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
};
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::{symbol::kw, Span};
@@ -76,12 +76,12 @@ fn generic_arg_mismatch_err(
Res::Def(DefKind::TyParam, src_def_id) => {
if let Some(param_local_id) = param.def_id.as_local() {
let param_name = tcx.hir().ty_param_name(param_local_id);
- let param_type = tcx.type_of(param.def_id).subst_identity();
+ let param_type = tcx.type_of(param.def_id).instantiate_identity();
if param_type.is_suggestable(tcx, false) {
err.span_suggestion(
tcx.def_span(src_def_id),
"consider changing this type parameter to a const parameter",
- format!("const {}: {}", param_name, param_type),
+ format!("const {param_name}: {param_type}"),
Applicability::MaybeIncorrect,
);
};
@@ -102,7 +102,7 @@ fn generic_arg_mismatch_err(
err.span_suggestion(
arg.span(),
"array type provided where a `usize` was expected, try",
- format!("{{ {} }}", snippet),
+ format!("{{ {snippet} }}"),
Applicability::MaybeIncorrect,
);
}
@@ -130,7 +130,7 @@ fn generic_arg_mismatch_err(
} else {
(arg.descr(), param.kind.descr())
};
- err.note(format!("{} arguments must be provided before {} arguments", first, last));
+ err.note(format!("{first} arguments must be provided before {last} arguments"));
if let Some(help) = help {
err.help(help);
}
@@ -146,14 +146,14 @@ fn generic_arg_mismatch_err(
///
/// To start, we are given the `def_id` of the thing we are
/// creating the substitutions for, and a partial set of
-/// substitutions `parent_substs`. In general, the substitutions
+/// substitutions `parent_args`. In general, the substitutions
/// for an item begin with substitutions for all the "parents" of
/// that item -- e.g., for a method it might include the
/// parameters from the impl.
///
/// Therefore, the method begins by walking down these parents,
/// starting with the outermost parent and proceed inwards until
-/// it reaches `def_id`. For each parent `P`, it will check `parent_substs`
+/// it reaches `def_id`. For each parent `P`, it will check `parent_args`
/// first to see if the parent's substitutions are listed in there. If so,
/// we can append those and move on. Otherwise, it invokes the
/// three callback functions:
@@ -168,15 +168,15 @@ fn generic_arg_mismatch_err(
/// instantiate a `GenericArg`.
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
/// creates a suitable inference variable.
-pub fn create_substs_for_generic_args<'tcx, 'a>(
+pub fn create_args_for_parent_generic_args<'tcx, 'a>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- parent_substs: &[subst::GenericArg<'tcx>],
+ parent_args: &[ty::GenericArg<'tcx>],
has_self: bool,
self_ty: Option<Ty<'tcx>>,
arg_count: &GenericArgCountResult,
ctx: &mut impl CreateSubstsForGenericArgsCtxt<'a, 'tcx>,
-) -> SubstsRef<'tcx> {
+) -> GenericArgsRef<'tcx> {
// Collect the segments of the path; we need to substitute arguments
// for parameters throughout the entire path (wherever there are
// generic parameters).
@@ -191,27 +191,27 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
// We manually build up the substitution, rather than using convenience
// methods in `subst.rs`, so that we can iterate over the arguments and
// parameters in lock-step linearly, instead of trying to match each pair.
- let mut substs: SmallVec<[subst::GenericArg<'tcx>; 8]> = SmallVec::with_capacity(count);
+ let mut args: SmallVec<[ty::GenericArg<'tcx>; 8]> = SmallVec::with_capacity(count);
// Iterate over each segment of the path.
while let Some((def_id, defs)) = stack.pop() {
let mut params = defs.params.iter().peekable();
// If we have already computed substitutions for parents, we can use those directly.
while let Some(&param) = params.peek() {
- if let Some(&kind) = parent_substs.get(param.index as usize) {
- substs.push(kind);
+ if let Some(&kind) = parent_args.get(param.index as usize) {
+ args.push(kind);
params.next();
} else {
break;
}
}
- // `Self` is handled first, unless it's been handled in `parent_substs`.
+ // `Self` is handled first, unless it's been handled in `parent_args`.
if has_self {
if let Some(&param) = params.peek() {
if param.index == 0 {
if let GenericParamDefKind::Type { .. } = param.kind {
- substs.push(
+ args.push(
self_ty
.map(|ty| ty.into())
.unwrap_or_else(|| ctx.inferred_kind(None, param, true)),
@@ -226,7 +226,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
let (generic_args, infer_args) = ctx.args_for_def_id(def_id);
let args_iter = generic_args.iter().flat_map(|generic_args| generic_args.args.iter());
- let mut args = args_iter.clone().peekable();
+ let mut args_iter = args_iter.clone().peekable();
// If we encounter a type or const when we expect a lifetime, we infer the lifetimes.
// If we later encounter a lifetime, we know that the arguments were provided in the
@@ -239,7 +239,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
// provided, matching them with the generic parameters we expect.
// Mismatches can occur as a result of elided lifetimes, or for malformed
// input. We try to handle both sensibly.
- match (args.peek(), params.peek()) {
+ match (args_iter.peek(), params.peek()) {
(Some(&arg), Some(&param)) => {
match (arg, &param.kind, arg_count.explicit_late_bound) {
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
@@ -253,8 +253,8 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
GenericParamDefKind::Const { .. },
_,
) => {
- substs.push(ctx.provided_kind(param, arg));
- args.next();
+ args.push(ctx.provided_kind(param, arg));
+ args_iter.next();
params.next();
}
(
@@ -264,7 +264,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
) => {
// We expected a lifetime argument, but got a type or const
// argument. That means we're inferring the lifetimes.
- substs.push(ctx.inferred_kind(None, param, infer_args));
+ args.push(ctx.inferred_kind(None, param, infer_args));
force_infer_lt = Some((arg, param));
params.next();
}
@@ -273,7 +273,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
// the presence of explicit late bounds. This is most likely
// due to the presence of the explicit bound so we're just going to
// ignore it.
- args.next();
+ args_iter.next();
}
(_, _, _) => {
// We expected one kind of parameter, but the user provided
@@ -304,7 +304,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
"reorder the arguments: {}: `<{}>`",
param_types_present
.into_iter()
- .map(|ord| format!("{}s", ord))
+ .map(|ord| format!("{ord}s"))
.collect::<Vec<String>>()
.join(", then "),
ordered_params
@@ -327,7 +327,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
// errors. In this case, we're simply going to ignore the argument
// and any following arguments. The rest of the parameters will be
// inferred.
- while args.next().is_some() {}
+ while args_iter.next().is_some() {}
}
}
}
@@ -360,7 +360,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
(None, Some(&param)) => {
// If there are fewer arguments than parameters, it means
// we're inferring the remaining arguments.
- substs.push(ctx.inferred_kind(Some(&substs), param, infer_args));
+ args.push(ctx.inferred_kind(Some(&args), param, infer_args));
params.next();
}
@@ -369,7 +369,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
}
}
- tcx.mk_substs(&substs)
+ tcx.mk_args(&args)
}
/// Checks that the correct number of generic arguments have been provided.
diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/astconv/lint.rs
index 05a3ab63d..1bd1270be 100644
--- a/compiler/rustc_hir_analysis/src/astconv/lint.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/lint.rs
@@ -34,9 +34,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let param_name = generics.params.next_type_param_name(None);
let add_generic_sugg = if let Some(span) = generics.span_for_param_suggestion() {
- (span, format!(", {}: {}", param_name, impl_trait_name))
+ (span, format!(", {param_name}: {impl_trait_name}"))
} else {
- (generics.span, format!("<{}: {}>", param_name, impl_trait_name))
+ (generics.span, format!("<{param_name}: {impl_trait_name}>"))
};
diag.multipart_suggestion(
format!("alternatively use a blanket \
@@ -86,7 +86,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
));
}
- if self_ty.span.edition().rust_2021() {
+ if self_ty.span.edition().at_least_rust_2021() {
let msg = "trait objects must include the `dyn` keyword";
let label = "add `dyn` keyword before this trait";
let mut diag =
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs
index 3d6984628..668763f9b 100644
--- a/compiler/rustc_hir_analysis/src/astconv/mod.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs
@@ -9,7 +9,7 @@ mod lint;
mod object_safety;
use crate::astconv::errors::prohibit_assoc_ty_binding;
-use crate::astconv::generics::{check_generic_arg_count, create_substs_for_generic_args};
+use crate::astconv::generics::{check_generic_arg_count, create_args_for_parent_generic_args};
use crate::bounds::Bounds;
use crate::collect::HirPlaceholderCollector;
use crate::errors::{AmbiguousLifetimeBound, TypeofReservedKeywordUsed};
@@ -29,9 +29,10 @@ use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_infer::traits::ObligationCause;
use rustc_middle::middle::stability::AllowUnstable;
-use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::GenericParamDefKind;
-use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
+use rustc_middle::ty::{
+ self, Const, GenericArgKind, GenericArgsRef, IsSuggestable, Ty, TyCtxt, TypeVisitableExt,
+};
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{kw, Ident, Symbol};
@@ -220,14 +221,14 @@ pub trait CreateSubstsForGenericArgsCtxt<'a, 'tcx> {
&mut self,
param: &ty::GenericParamDef,
arg: &GenericArg<'_>,
- ) -> subst::GenericArg<'tcx>;
+ ) -> ty::GenericArg<'tcx>;
fn inferred_kind(
&mut self,
- substs: Option<&[subst::GenericArg<'tcx>]>,
+ args: Option<&[ty::GenericArg<'tcx>]>,
param: &ty::GenericParamDef,
infer_args: bool,
- ) -> subst::GenericArg<'tcx>;
+ ) -> ty::GenericArg<'tcx>;
}
impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
@@ -291,13 +292,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Given a path `path` that refers to an item `I` with the declared generics `decl_generics`,
/// returns an appropriate set of substitutions for this particular reference to `I`.
- pub fn ast_path_substs_for_ty(
+ pub fn ast_path_args_for_ty(
&self,
span: Span,
def_id: DefId,
item_segment: &hir::PathSegment<'_>,
- ) -> SubstsRef<'tcx> {
- let (substs, _) = self.create_substs_for_ast_path(
+ ) -> GenericArgsRef<'tcx> {
+ let (args, _) = self.create_args_for_ast_path(
span,
def_id,
&[],
@@ -311,7 +312,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span)));
}
- substs
+ args
}
/// Given the type/lifetime/const arguments provided to some path (along with
@@ -330,7 +331,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// 2. The path in question is the path to the trait `std::ops::Index`,
/// which will have been resolved to a `def_id`
/// 3. The `generic_args` contains info on the `<...>` contents. The `usize` type
- /// parameters are returned in the `SubstsRef`, the associated type bindings like
+ /// parameters are returned in the `GenericArgsRef`, the associated type bindings like
/// `Output = u32` are returned from `create_assoc_bindings_for_generic_args`.
///
/// Note that the type listing given here is *exactly* what the user provided.
@@ -341,22 +342,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// <Vec<u8> as Iterable<u8>>::Iter::<'a>
/// ```
///
- /// We have the parent substs are the substs for the parent trait:
+ /// We have the parent args are the args for the parent trait:
/// `[Vec<u8>, u8]` and `generic_args` are the arguments for the associated
- /// type itself: `['a]`. The returned `SubstsRef` concatenates these two
+ /// type itself: `['a]`. The returned `GenericArgsRef` concatenates these two
/// lists: `[Vec<u8>, u8, 'a]`.
#[instrument(level = "debug", skip(self, span), ret)]
- fn create_substs_for_ast_path<'a>(
+ fn create_args_for_ast_path<'a>(
&self,
span: Span,
def_id: DefId,
- parent_substs: &[subst::GenericArg<'tcx>],
+ parent_args: &[ty::GenericArg<'tcx>],
seg: &hir::PathSegment<'_>,
generic_args: &'a hir::GenericArgs<'_>,
infer_args: bool,
self_ty: Option<Ty<'tcx>>,
constness: ty::BoundConstness,
- ) -> (SubstsRef<'tcx>, GenericArgCountResult) {
+ ) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
@@ -369,7 +370,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if generics.parent.is_some() {
// The parent is a trait so it should have at least one subst
// for the `Self` type.
- assert!(!parent_substs.is_empty())
+ assert!(!parent_args.is_empty())
} else {
// This item (presumably a trait) needs a self-type.
assert!(self_ty.is_some());
@@ -395,7 +396,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// here and so associated type bindings will be handled regardless of whether there are any
// non-`Self` generic parameters.
if generics.params.is_empty() {
- return (tcx.mk_substs(parent_substs), arg_count);
+ return (tcx.mk_args(parent_args), arg_count);
}
struct SubstsForAstPathCtxt<'a, 'tcx> {
@@ -421,7 +422,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&mut self,
param: &ty::GenericParamDef,
arg: &GenericArg<'_>,
- ) -> subst::GenericArg<'tcx> {
+ ) -> ty::GenericArg<'tcx> {
let tcx = self.astconv.tcx();
let mut handle_ty_args = |has_default, ty: &hir::Ty<'_>| {
@@ -483,10 +484,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn inferred_kind(
&mut self,
- substs: Option<&[subst::GenericArg<'tcx>]>,
+ args: Option<&[ty::GenericArg<'tcx>]>,
param: &ty::GenericParamDef,
infer_args: bool,
- ) -> subst::GenericArg<'tcx> {
+ ) -> ty::GenericArg<'tcx> {
let tcx = self.astconv.tcx();
match param.kind {
GenericParamDefKind::Lifetime => self
@@ -506,15 +507,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
GenericParamDefKind::Type { has_default, .. } => {
if !infer_args && has_default {
// No type parameter provided, but a default exists.
- let substs = substs.unwrap();
- if substs.iter().any(|arg| match arg.unpack() {
+ let args = args.unwrap();
+ if args.iter().any(|arg| match arg.unpack() {
GenericArgKind::Type(ty) => ty.references_error(),
_ => false,
}) {
// Avoid ICE #86756 when type error recovery goes awry.
return Ty::new_misc_error(tcx).into();
}
- tcx.at(self.span).type_of(param.def_id).subst(tcx, substs).into()
+ tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into()
} else if infer_args {
self.astconv.ty_infer(Some(param), self.span).into()
} else {
@@ -531,8 +532,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Err(guar) = ty.error_reported() {
return ty::Const::new_error(tcx, guar, ty).into();
}
+ // FIXME(effects) see if we should special case effect params here
if !infer_args && has_default {
- tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
+ tcx.const_param_default(param.def_id)
+ .instantiate(tcx, args.unwrap())
+ .into()
} else {
if infer_args {
self.astconv.ct_infer(ty, Some(param), self.span).into()
@@ -546,7 +550,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
- let mut substs_ctx = SubstsForAstPathCtxt {
+ let mut args_ctx = SubstsForAstPathCtxt {
astconv: self,
def_id,
span,
@@ -554,14 +558,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
inferred_params: vec![],
infer_args,
};
- let substs = create_substs_for_generic_args(
+ let args = create_args_for_parent_generic_args(
tcx,
def_id,
- parent_substs,
+ parent_args,
self_ty.is_some(),
self_ty,
&arg_count,
- &mut substs_ctx,
+ &mut args_ctx,
);
if let ty::BoundConstness::ConstIfConst = constness
@@ -570,7 +574,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.sess.emit_err(crate::errors::ConstBoundForNonConstTrait { span } );
}
- (substs, arg_count)
+ (args, arg_count)
}
fn create_assoc_bindings_for_generic_args<'a>(
@@ -617,21 +621,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assoc_bindings
}
- pub fn create_substs_for_associated_item(
+ pub fn create_args_for_associated_item(
&self,
span: Span,
item_def_id: DefId,
item_segment: &hir::PathSegment<'_>,
- parent_substs: SubstsRef<'tcx>,
- ) -> SubstsRef<'tcx> {
+ parent_args: GenericArgsRef<'tcx>,
+ ) -> GenericArgsRef<'tcx> {
debug!(
- "create_substs_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
+ "create_args_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
span, item_def_id, item_segment
);
- let (args, _) = self.create_substs_for_ast_path(
+ let (args, _) = self.create_args_for_ast_path(
span,
item_def_id,
- parent_substs,
+ parent_args,
item_segment,
item_segment.args(),
item_segment.infer_args,
@@ -656,7 +660,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
trait_ref: &hir::TraitRef<'_>,
self_ty: Ty<'tcx>,
- constness: ty::BoundConstness,
) -> ty::TraitRef<'tcx> {
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
@@ -666,7 +669,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty,
trait_ref.path.segments.last().unwrap(),
true,
- constness,
+ ty::BoundConstness::NotConst,
)
}
@@ -687,7 +690,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty: Ty<'tcx>,
only_self_bounds: OnlySelfBounds,
) -> GenericArgCountResult {
- let (substs, arg_count) = self.create_substs_for_ast_path(
+ let (generic_args, arg_count) = self.create_args_for_ast_path(
trait_ref_span,
trait_def_id,
&[],
@@ -704,11 +707,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
- let poly_trait_ref =
- ty::Binder::bind_with_vars(ty::TraitRef::new(tcx, trait_def_id, substs), bound_vars);
+ let poly_trait_ref = ty::Binder::bind_with_vars(
+ ty::TraitRef::new(tcx, trait_def_id, generic_args),
+ bound_vars,
+ );
debug!(?poly_trait_ref, ?assoc_bindings);
- bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
+ bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
let mut dup_bindings = FxHashMap::default();
for binding in &assoc_bindings {
@@ -844,9 +849,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty: Ty<'tcx>,
trait_segment: &hir::PathSegment<'_>,
is_impl: bool,
+ // FIXME(effects) move all host param things in astconv to hir lowering
constness: ty::BoundConstness,
) -> ty::TraitRef<'tcx> {
- let (substs, _) = self.create_substs_for_ast_trait_ref(
+ let (generic_args, _) = self.create_args_for_ast_trait_ref(
span,
trait_def_id,
self_ty,
@@ -857,11 +863,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(b) = trait_segment.args().bindings.first() {
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span)));
}
- ty::TraitRef::new(self.tcx(), trait_def_id, substs)
+ ty::TraitRef::new(self.tcx(), trait_def_id, generic_args)
}
#[instrument(level = "debug", skip(self, span))]
- fn create_substs_for_ast_trait_ref<'a>(
+ fn create_args_for_ast_trait_ref<'a>(
&self,
span: Span,
trait_def_id: DefId,
@@ -869,10 +875,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait_segment: &'a hir::PathSegment<'a>,
is_impl: bool,
constness: ty::BoundConstness,
- ) -> (SubstsRef<'tcx>, GenericArgCountResult) {
+ ) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
- self.create_substs_for_ast_path(
+ self.create_args_for_ast_path(
span,
trait_def_id,
&[],
@@ -902,19 +908,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
did: DefId,
item_segment: &hir::PathSegment<'_>,
) -> Ty<'tcx> {
- let substs = self.ast_path_substs_for_ty(span, did, item_segment);
- let ty = self.tcx().at(span).type_of(did);
+ let tcx = self.tcx();
+ let args = self.ast_path_args_for_ty(span, did, item_segment);
+ let ty = tcx.at(span).type_of(did);
- if matches!(self.tcx().def_kind(did), DefKind::TyAlias)
- && (ty.skip_binder().has_opaque_types() || self.tcx().features().lazy_type_alias)
+ if let DefKind::TyAlias { lazy } = tcx.def_kind(did)
+ && (lazy || ty.skip_binder().has_opaque_types())
{
// Type aliases referring to types that contain opaque types (but aren't just directly
- // referencing a single opaque type) get encoded as a type alias that normalization will
+ // referencing a single opaque type) as well as those defined in crates that have the
+ // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of.
- let alias_ty = self.tcx().mk_alias_ty(did, substs);
- Ty::new_alias(self.tcx(), ty::Weak, alias_ty)
+ let alias_ty = tcx.mk_alias_ty(did, args);
+ Ty::new_alias(tcx, ty::Weak, alias_ty)
} else {
- ty.subst(self.tcx(), substs)
+ ty.instantiate(tcx, args)
}
}
@@ -1123,7 +1131,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ty_param_name
)
};
- err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
+ err.span_label(span, format!("ambiguous associated type `{assoc_name}`"));
let mut where_bounds = vec![];
for bound in bounds {
@@ -1267,9 +1275,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
"you might have meant to specify type parameters on enum \
`{type_name}`"
);
- let Some(args) = assoc_segment.args else { return; };
+ let Some(args) = assoc_segment.args else {
+ return;
+ };
// Get the span of the generics args *including* the leading `::`.
- let args_span = assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
+ let args_span =
+ assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
if tcx.generics_of(adt_def.did()).count() == 0 {
// FIXME(estebank): we could also verify that the arguments being
// work for the `enum`, instead of just looking if it takes *any*.
@@ -1281,49 +1292,56 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);
return;
}
- let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span) else {
+ let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span)
+ else {
err.note(msg);
return;
};
- let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
- hir::QPath::Resolved(_, path)
- ) = &qself.kind {
- // If the path segment already has type params, we want to overwrite
- // them.
- match &path.segments {
- // `segment` is the previous to last element on the path,
- // which would normally be the `enum` itself, while the last
- // `_` `PathSegment` corresponds to the variant.
- [.., hir::PathSegment {
- ident,
- args,
- res: Res::Def(DefKind::Enum, _),
- ..
- }, _] => (
- // We need to include the `::` in `Type::Variant::<Args>`
- // to point the span to `::<Args>`, not just `<Args>`.
- ident.span.shrink_to_hi().to(args.map_or(
- ident.span.shrink_to_hi(),
- |a| a.span_ext)),
- false,
- ),
- [segment] => (
- // We need to include the `::` in `Type::Variant::<Args>`
- // to point the span to `::<Args>`, not just `<Args>`.
- segment.ident.span.shrink_to_hi().to(segment.args.map_or(
- segment.ident.span.shrink_to_hi(),
- |a| a.span_ext)),
- kw::SelfUpper == segment.ident.name,
- ),
- _ => {
- err.note(msg);
- return;
+ let (qself_sugg_span, is_self) =
+ if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) =
+ &qself.kind
+ {
+ // If the path segment already has type params, we want to overwrite
+ // them.
+ match &path.segments {
+ // `segment` is the previous to last element on the path,
+ // which would normally be the `enum` itself, while the last
+ // `_` `PathSegment` corresponds to the variant.
+ [
+ ..,
+ hir::PathSegment {
+ ident,
+ args,
+ res: Res::Def(DefKind::Enum, _),
+ ..
+ },
+ _,
+ ] => (
+ // We need to include the `::` in `Type::Variant::<Args>`
+ // to point the span to `::<Args>`, not just `<Args>`.
+ ident.span.shrink_to_hi().to(args
+ .map_or(ident.span.shrink_to_hi(), |a| a.span_ext)),
+ false,
+ ),
+ [segment] => (
+ // We need to include the `::` in `Type::Variant::<Args>`
+ // to point the span to `::<Args>`, not just `<Args>`.
+ segment.ident.span.shrink_to_hi().to(segment
+ .args
+ .map_or(segment.ident.span.shrink_to_hi(), |a| {
+ a.span_ext
+ })),
+ kw::SelfUpper == segment.ident.name,
+ ),
+ _ => {
+ err.note(msg);
+ return;
+ }
}
- }
- } else {
- err.note(msg);
- return;
- };
+ } else {
+ err.note(msg);
+ return;
+ };
let suggestion = vec![
if is_self {
// Account for people writing `Self::Variant::<Args>`, where
@@ -1373,7 +1391,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};
self.one_bound_for_assoc_type(
- || traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
+ || {
+ traits::supertraits(
+ tcx,
+ ty::Binder::dummy(trait_ref.instantiate_identity()),
+ )
+ },
kw::SelfUpper,
assoc_ident,
span,
@@ -1387,7 +1410,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
_ => {
let reported = if variant_resolution.is_some() {
// Variant in type position
- let msg = format!("expected type, found variant `{}`", assoc_ident);
+ let msg = format!("expected type, found variant `{assoc_ident}`");
tcx.sess.span_err(span, msg)
} else if qself_ty.is_enum() {
let mut err = struct_span_err!(
@@ -1418,12 +1441,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
err.span_label(
assoc_ident.span,
- format!("variant not found in `{}`", qself_ty),
+ format!("variant not found in `{qself_ty}`"),
);
}
if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
- err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
+ err.span_label(sp, format!("variant `{assoc_ident}` not found here"));
}
err.emit()
@@ -1442,7 +1465,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let traits: Vec<_> =
self.probe_traits_that_match_assoc_ty(qself_ty, assoc_ident);
- // Don't print `TyErr` to the user.
+ // Don't print `ty::Error` to the user.
self.report_ambiguous_associated_type(
span,
&[qself_ty.to_string()],
@@ -1455,7 +1478,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};
let trait_did = bound.def_id();
- let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did) else {
+ let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did)
+ else {
// Assume that if it's not matched, there must be a const defined with the same name
// but it was used in a type position.
let msg = format!("found associated const `{assoc_ident}` when type was expected");
@@ -1609,8 +1633,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let ocx = ObligationCtxt::new(&infcx);
ocx.register_obligations(obligations.clone());
- let impl_substs = infcx.fresh_substs_for_item(span, impl_);
- let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);
+ let impl_args = infcx.fresh_args_for_item(span, impl_);
+ let impl_ty = tcx.type_of(impl_).instantiate(tcx, impl_args);
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
// Check that the self types can be related.
@@ -1622,7 +1646,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
// Check whether the impl imposes obligations we have to worry about.
- let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_substs);
+ let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args);
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
let impl_obligations = traits::predicates_for_generics(
|_, _| cause.clone(),
@@ -1654,18 +1678,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some((impl_, (assoc_item, def_scope))) = applicable_candidates.pop() {
self.check_assoc_ty(assoc_item, name, def_scope, block, span);
- // FIXME(fmease): Currently creating throwaway `parent_substs` to please
- // `create_substs_for_associated_item`. Modify the latter instead (or sth. similar) to
- // not require the parent substs logic.
- let parent_substs = InternalSubsts::identity_for_item(tcx, impl_);
- let substs =
- self.create_substs_for_associated_item(span, assoc_item, segment, parent_substs);
- let substs = tcx.mk_substs_from_iter(
+ // FIXME(fmease): Currently creating throwaway `parent_args` to please
+ // `create_args_for_associated_item`. Modify the latter instead (or sth. similar) to
+ // not require the parent args logic.
+ let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_);
+ let args = self.create_args_for_associated_item(span, assoc_item, segment, parent_args);
+ let args = tcx.mk_args_from_iter(
std::iter::once(ty::GenericArg::from(self_ty))
- .chain(substs.into_iter().skip(parent_substs.len())),
+ .chain(args.into_iter().skip(parent_args.len())),
);
- let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, substs));
+ let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, args));
return Ok(Some((ty, assoc_item)));
}
@@ -1769,9 +1792,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.any(|impl_def_id| {
let trait_ref = tcx.impl_trait_ref(impl_def_id);
trait_ref.is_some_and(|trait_ref| {
- let impl_ = trait_ref.subst(
+ let impl_ = trait_ref.instantiate(
tcx,
- infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id),
+ infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
);
let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
// FIXME: Don't bother dealing with non-lifetime binders here...
@@ -1814,7 +1837,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("qpath_to_ty: self.item_def_id()={:?}", def_id);
- let parent_def_id = def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
+ let parent_def_id = def_id
+ .as_local()
+ .map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
@@ -1835,7 +1860,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative
})
.filter_map(|impl_def_id| tcx.impl_trait_ref(impl_def_id))
- .map(|impl_| impl_.subst_identity().self_ty())
+ .map(|impl_| impl_.instantiate_identity().self_ty())
// We don't care about blanket impls.
.filter(|self_ty| !self_ty.has_non_region_param())
.map(|self_ty| tcx.erase_regions(self_ty).to_string())
@@ -1850,7 +1875,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&[path_str],
item_segment.ident.name,
);
- return Ty::new_error(tcx,reported)
+ return Ty::new_error(tcx, reported);
};
debug!("qpath_to_ty: self_type={:?}", self_ty);
@@ -1864,16 +1889,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
constness,
);
- let item_substs = self.create_substs_for_associated_item(
- span,
- item_def_id,
- item_segment,
- trait_ref.substs,
- );
+ let item_args =
+ self.create_args_for_associated_item(span, item_def_id, item_segment, trait_ref.args);
debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
- Ty::new_projection(tcx, item_def_id, item_substs)
+ Ty::new_projection(tcx, item_def_id, item_args)
}
pub fn prohibit_generics<'a>(
@@ -2128,19 +2149,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let span = path.span;
match path.res {
- Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
+ Res::Def(DefKind::OpaqueTy, did) => {
// Check for desugared `impl Trait`.
assert!(tcx.is_type_alias_impl_trait(did));
let item_segment = path.segments.split_last().unwrap();
self.prohibit_generics(item_segment.1.iter(), |err| {
err.note("`impl Trait` types can't have type parameters");
});
- let substs = self.ast_path_substs_for_ty(span, did, item_segment.0);
- Ty::new_opaque(tcx, did, substs)
+ let args = self.ast_path_args_for_ty(span, did, item_segment.0);
+ Ty::new_opaque(tcx, did, args)
}
Res::Def(
DefKind::Enum
- | DefKind::TyAlias
+ | DefKind::TyAlias { .. }
| DefKind::Struct
| DefKind::Union
| DefKind::ForeignTy,
@@ -2220,7 +2241,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// `Self` in impl (we know the concrete type).
assert_eq!(opt_self_ty, None);
// Try to evaluate any array length constants.
- let ty = tcx.at(span).type_of(def_id).subst_identity();
+ let ty = tcx.at(span).type_of(def_id).instantiate_identity();
let span_of_impl = tcx.span_of_impl(def_id);
self.prohibit_generics(path.segments.iter(), |err| {
let def_id = match *ty.kind() {
@@ -2439,7 +2460,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
// generate the def_id of an associated type for the trait and return as
// type a projection.
- let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty() {
+ let def_id = if in_trait {
tcx.associated_type_for_impl_trait_in_trait(local_def_id).to_def_id()
} else {
local_def_id.to_def_id()
@@ -2458,7 +2479,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
let def_id = tcx.require_lang_item(lang_item, Some(span));
- let (substs, _) = self.create_substs_for_ast_path(
+ let (args, _) = self.create_args_for_ast_path(
span,
def_id,
&[],
@@ -2468,7 +2489,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
None,
ty::BoundConstness::NotConst,
);
- tcx.at(span).type_of(def_id).subst(tcx, substs)
+ tcx.at(span).type_of(def_id).instantiate(tcx, args)
}
hir::TyKind::Array(ty, length) => {
let length = match length {
@@ -2481,7 +2502,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
}
hir::TyKind::Typeof(e) => {
- let ty_erased = tcx.type_of(e.def_id).subst_identity();
+ let ty_erased = tcx.type_of(e.def_id).instantiate_identity();
let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r }
});
@@ -2523,7 +2544,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let generics = tcx.generics_of(def_id);
debug!("impl_trait_ty_to_ty: generics={:?}", generics);
- let substs = InternalSubsts::for_item(tcx, def_id, |param, _| {
+ let args = ty::GenericArgs::for_item(tcx, def_id, |param, _| {
// We use `generics.count() - lifetimes.len()` here instead of `generics.parent_count`
// since return-position impl trait in trait squashes all of the generics from its source fn
// into its own generics, so the opaque's "own" params isn't always just lifetimes.
@@ -2537,12 +2558,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.mk_param_from_def(param)
}
});
- debug!("impl_trait_ty_to_ty: substs={:?}", substs);
+ debug!("impl_trait_ty_to_ty: args={:?}", args);
if in_trait {
- Ty::new_projection(tcx, def_id, substs)
+ Ty::new_projection(tcx, def_id, args)
} else {
- Ty::new_opaque(tcx, def_id, substs)
+ Ty::new_opaque(tcx, def_id, args)
}
}
@@ -2688,14 +2709,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let hir = tcx.hir();
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
- hir.get(fn_hir_id) else { return None };
+ hir.get(fn_hir_id)
+ else {
+ return None;
+ };
let i = hir.get_parent(fn_hir_id).expect_item().expect_impl();
- let trait_ref = self.instantiate_mono_trait_ref(
- i.of_trait.as_ref()?,
- self.ast_ty_to_ty(i.self_ty),
- ty::BoundConstness::NotConst,
- );
+ let trait_ref =
+ self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty));
let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind(
tcx,
@@ -2704,9 +2725,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait_ref.def_id,
)?;
- let fn_sig = tcx.fn_sig(assoc.def_id).subst(
+ let fn_sig = tcx.fn_sig(assoc.def_id).instantiate(
tcx,
- trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
+ trait_ref.args.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
);
let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
@@ -2729,7 +2750,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(..) | ty::BrEnv => {
"an anonymous lifetime".to_string()
}
- ty::BrNamed(_, name) => format!("lifetime `{}`", name),
+ ty::BrNamed(_, name) => format!("lifetime `{name}`"),
};
let mut err = generate_err(&br_name);
diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
index 9227ee934..30c2ab8f5 100644
--- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
@@ -62,11 +62,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
match bound_pred.skip_binder() {
ty::ClauseKind::Trait(trait_pred) => {
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
- trait_bounds.push((
- bound_pred.rebind(trait_pred.trait_ref),
- span,
- trait_pred.constness,
- ));
+ trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
}
ty::ClauseKind::Projection(proj) => {
projection_bounds.push((bound_pred.rebind(proj), span));
@@ -86,7 +82,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Expand trait aliases recursively and check that only one regular (non-auto) trait
// is used and no 'maybe' bounds are used.
let expanded_traits =
- traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b, _)| (a, b)));
+ traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b)| (a, b)));
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
@@ -126,7 +122,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if regular_traits.is_empty() && auto_traits.is_empty() {
let trait_alias_span = trait_bounds
.iter()
- .map(|&(trait_ref, _, _)| trait_ref.def_id())
+ .map(|&(trait_ref, _)| trait_ref.def_id())
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
.map(|trait_ref| tcx.def_span(trait_ref));
let reported =
@@ -157,10 +153,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let regular_traits_refs_spans = trait_bounds
.into_iter()
- .filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id()));
+ .filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
- for (base_trait_ref, span, constness) in regular_traits_refs_spans {
- assert_eq!(constness, ty::BoundConstness::NotConst);
+ for (base_trait_ref, span) in regular_traits_refs_spans {
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
for pred in traits::elaborate(tcx, [base_pred]) {
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);
@@ -173,7 +168,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.associated_items(pred.def_id())
.in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Type)
- .filter(|item| item.opt_rpitit_info.is_none())
+ .filter(|item| !item.is_impl_trait_in_trait())
.map(|item| item.def_id),
);
}
@@ -262,8 +257,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut missing_type_params = vec![];
let mut references_self = false;
let generics = tcx.generics_of(trait_ref.def_id);
- let substs: Vec<_> = trait_ref
- .substs
+ let args: Vec<_> = trait_ref
+ .args
.iter()
.enumerate()
.skip(1) // Remove `Self` for `ExistentialPredicate`.
@@ -279,7 +274,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
arg
})
.collect();
- let substs = tcx.mk_substs(&substs);
+ let args = tcx.mk_args(&args);
let span = i.bottom().1;
let empty_generic_args = hir_trait_bounds.iter().any(|hir_bound| {
@@ -310,7 +305,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.emit();
}
- ty::ExistentialTraitRef { def_id: trait_ref.def_id, substs }
+ ty::ExistentialTraitRef { def_id: trait_ref.def_id, args }
})
});
@@ -325,7 +320,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Like for trait refs, verify that `dummy_self` did not leak inside default type
// parameters.
- let references_self = b.projection_ty.substs.iter().skip(1).any(|arg| {
+ let references_self = b.projection_ty.args.iter().skip(1).any(|arg| {
if arg.walk().any(|arg| arg == dummy_self.into()) {
return true;
}
@@ -336,9 +331,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span,
"trait object projection bounds reference `Self`",
);
- let substs: Vec<_> = b
+ let args: Vec<_> = b
.projection_ty
- .substs
+ .args
.iter()
.map(|arg| {
if arg.walk().any(|arg| arg == dummy_self.into()) {
@@ -347,7 +342,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
arg
})
.collect();
- b.projection_ty.substs = tcx.mk_substs(&substs);
+ b.projection_ty.args = tcx.mk_args(&args);
}
ty::ExistentialProjection::erase_self_ty(tcx, b)