summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_analysis/src/astconv/generics.rs
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/generics.rs
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/generics.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/generics.rs50
1 files changed, 25 insertions, 25 deletions
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.