Skip to content

Commit 5767cad

Browse files
committed
Auto merge of #113591 - mdibaiee:genericargs-cleanup, r=oli-obk
refactor(rustc_middle): Substs -> GenericArg resolves #110793 - [x] rename `SubstsRef` and `InternalSubsts` to `GenericArgsRef<'tcx>` and `GenericArgs<'tcx>`. - [x] rename variables and fields currently using `substs` to `args`. - [x] update the module name of `ty::subst` to `ty::generic_args` or sth. Make that module private and publicly reexport its content in the ty module. - [x] rename `EarlyBinder::subst(_identity)` to `EarlyBinder::instantiate(_identity)`. - [x] types called `[a-zA-Z]+Substs` renamed to `XArgs`. - [x] functions containing `substs` now use `args` or `generic_args` (mostly the former). However, the verb of "substituting" is still being used here and there, mostly in comments. I think that can be a separate PR as part of #110254 to change the verb to `replace_generics` or something similar.
2 parents bacf5bc + e55583c commit 5767cad

File tree

466 files changed

+4575
-4605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

466 files changed

+4575
-4605
lines changed

compiler/rustc_borrowck/src/constraint_generation.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_middle::mir::{
77
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, SourceInfo, Statement,
88
StatementKind, Terminator, TerminatorKind, UserTypeProjection,
99
};
10-
use rustc_middle::ty::subst::SubstsRef;
1110
use rustc_middle::ty::visit::TypeVisitable;
11+
use rustc_middle::ty::GenericArgsRef;
1212
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
1313

1414
use crate::{
@@ -49,11 +49,11 @@ struct ConstraintGeneration<'cg, 'tcx> {
4949
}
5050

5151
impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
52-
/// We sometimes have `substs` within an rvalue, or within a
52+
/// We sometimes have `args` within an rvalue, or within a
5353
/// call. Make them live at the location where they appear.
54-
fn visit_substs(&mut self, substs: &SubstsRef<'tcx>, location: Location) {
55-
self.add_regular_live_constraint(*substs, location);
56-
self.super_substs(substs);
54+
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
55+
self.add_regular_live_constraint(*args, location);
56+
self.super_args(args);
5757
}
5858

5959
/// We sometimes have `region` within an rvalue, or within a

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
702702
.iter()
703703
.copied()
704704
.find_map(find_fn_kind_from_did),
705-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
705+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
706706
.explicit_item_bounds(def_id)
707-
.subst_iter_copied(tcx, substs)
707+
.arg_iter_copied(tcx, args)
708708
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
709-
ty::Closure(_, substs) => match substs.as_closure().kind() {
709+
ty::Closure(_, args) => match args.as_closure().kind() {
710710
ty::ClosureKind::Fn => Some(hir::Mutability::Not),
711711
ty::ClosureKind::FnMut => Some(hir::Mutability::Mut),
712712
_ => None,
@@ -1448,11 +1448,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14481448
}
14491449

14501450
// Get closure's arguments
1451-
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else {
1451+
let ty::Closure(_, args) = typeck_results.expr_ty(closure_expr).kind() else {
14521452
/* hir::Closure can be a generator too */
14531453
return;
14541454
};
1455-
let sig = substs.as_closure().sig();
1455+
let sig = args.as_closure().sig();
14561456
let tupled_params =
14571457
tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b));
14581458
let ty::Tuple(params) = tupled_params.kind() else { return };
@@ -2676,7 +2676,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26762676
kind: TerminatorKind::Call { call_source: CallSource::OverloadedOperator, .. },
26772677
..
26782678
}),
2679-
Some((method_did, method_substs)),
2679+
Some((method_did, method_args)),
26802680
) = (
26812681
&self.body[loan.reserve_location.block].terminator,
26822682
rustc_middle::util::find_self_call(
@@ -2689,7 +2689,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26892689
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
26902690
let deref_target =
26912691
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
2692-
Instance::resolve(tcx, self.param_env, deref_target, method_substs)
2692+
Instance::resolve(tcx, self.param_env, deref_target, method_args)
26932693
.transpose()
26942694
});
26952695
if let Some(Ok(instance)) = deref_target {
@@ -2856,11 +2856,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
28562856
if is_closure {
28572857
None
28582858
} else {
2859-
let ty = self.infcx.tcx.type_of(self.mir_def_id()).subst_identity();
2859+
let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity();
28602860
match ty.kind() {
28612861
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
28622862
self.mir_def_id(),
2863-
self.infcx.tcx.fn_sig(self.mir_def_id()).subst_identity(),
2863+
self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(),
28642864
),
28652865
_ => None,
28662866
}
@@ -2902,7 +2902,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29022902
);
29032903
// Check if our `target` was captured by a closure.
29042904
if let Rvalue::Aggregate(
2905-
box AggregateKind::Closure(def_id, substs),
2905+
box AggregateKind::Closure(def_id, args),
29062906
operands,
29072907
) = rvalue
29082908
{
@@ -2933,7 +2933,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29332933
// into a place then we should annotate the closure in
29342934
// case it ends up being assigned into the return place.
29352935
annotated_closure =
2936-
self.annotate_fn_sig(def_id, substs.as_closure().sig());
2936+
self.annotate_fn_sig(def_id, args.as_closure().sig());
29372937
debug!(
29382938
"annotate_argument_and_return_for_borrow: \
29392939
annotated_closure={:?} assigned_from_local={:?} \

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
168168
let local_decl = &body.local_decls[dropped_local];
169169
let mut ty = local_decl.ty;
170170
if local_decl.source_info.span.desugaring_kind() == Some(DesugaringKind::ForLoop) {
171-
if let ty::Adt(adt, substs) = local_decl.ty.kind() {
171+
if let ty::Adt(adt, args) = local_decl.ty.kind() {
172172
if tcx.is_diagnostic_item(sym::Option, adt.did()) {
173173
// in for loop desugaring, only look at the `Some(..)` inner type
174-
ty = substs.type_at(0);
174+
ty = args.type_at(0);
175175
}
176176
}
177177
}
178178
let (dtor_desc, type_desc) = match ty.kind() {
179179
// If type is an ADT that implements Drop, then
180180
// simplify output by reporting just the ADT name.
181-
ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => {
181+
ty::Adt(adt, _args) if adt.has_dtor(tcx) && !adt.is_box() => {
182182
("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did())))
183183
}
184184

compiler/rustc_borrowck/src/diagnostics/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -732,18 +732,18 @@ impl<'tcx> BorrowedContentSource<'tcx> {
732732

733733
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
734734
match *func.kind() {
735-
ty::FnDef(def_id, substs) => {
735+
ty::FnDef(def_id, args) => {
736736
let trait_id = tcx.trait_of_item(def_id)?;
737737

738738
let lang_items = tcx.lang_items();
739739
if Some(trait_id) == lang_items.deref_trait()
740740
|| Some(trait_id) == lang_items.deref_mut_trait()
741741
{
742-
Some(BorrowedContentSource::OverloadedDeref(substs.type_at(0)))
742+
Some(BorrowedContentSource::OverloadedDeref(args.type_at(0)))
743743
} else if Some(trait_id) == lang_items.index_trait()
744744
|| Some(trait_id) == lang_items.index_mut_trait()
745745
{
746-
Some(BorrowedContentSource::OverloadedIndex(substs.type_at(0)))
746+
Some(BorrowedContentSource::OverloadedIndex(args.type_at(0)))
747747
} else {
748748
None
749749
}
@@ -847,7 +847,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
847847
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
848848
}) = &self.body[location.block].terminator
849849
{
850-
let Some((method_did, method_substs)) = rustc_middle::util::find_self_call(
850+
let Some((method_did, method_args)) = rustc_middle::util::find_self_call(
851851
self.infcx.tcx,
852852
&self.body,
853853
target_temp,
@@ -860,7 +860,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
860860
self.infcx.tcx,
861861
self.param_env,
862862
method_did,
863-
method_substs,
863+
method_args,
864864
*fn_span,
865865
call_source.from_hir_call(),
866866
Some(self.infcx.tcx.fn_arg_names(method_did)[0]),
@@ -1039,7 +1039,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10391039
});
10401040
}
10411041
}
1042-
CallKind::Normal { self_arg, desugaring, method_did, method_substs } => {
1042+
CallKind::Normal { self_arg, desugaring, method_did, method_args } => {
10431043
let self_arg = self_arg.unwrap();
10441044
let tcx = self.infcx.tcx;
10451045
if let Some((CallDesugaringKind::ForLoopIntoIter, _)) = desugaring {
@@ -1106,13 +1106,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11061106
// Erase and shadow everything that could be passed to the new infcx.
11071107
let ty = moved_place.ty(self.body, tcx).ty;
11081108

1109-
if let ty::Adt(def, substs) = ty.kind()
1109+
if let ty::Adt(def, args) = ty.kind()
11101110
&& Some(def.did()) == tcx.lang_items().pin_type()
1111-
&& let ty::Ref(_, _, hir::Mutability::Mut) = substs.type_at(0).kind()
1111+
&& let ty::Ref(_, _, hir::Mutability::Mut) = args.type_at(0).kind()
11121112
&& let self_ty = self.infcx.instantiate_binder_with_fresh_vars(
11131113
fn_call_span,
11141114
LateBoundRegionConversionTime::FnCall,
1115-
tcx.fn_sig(method_did).subst(tcx, method_substs).input(0),
1115+
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
11161116
)
11171117
&& self.infcx.can_eq(self.param_env, ty, self_ty)
11181118
{
@@ -1161,7 +1161,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11611161
let parent_self_ty =
11621162
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
11631163
.then_some(parent_did)
1164-
.and_then(|did| match tcx.type_of(did).subst_identity().kind() {
1164+
.and_then(|did| match tcx.type_of(did).instantiate_identity().kind() {
11651165
ty::Adt(def, ..) => Some(def.did()),
11661166
_ => None,
11671167
});

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
324324
ty::Array(..) | ty::Slice(..) => {
325325
self.cannot_move_out_of_interior_noncopy(span, ty, None)
326326
}
327-
ty::Closure(def_id, closure_substs)
327+
ty::Closure(def_id, closure_args)
328328
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
329329
{
330-
let closure_kind_ty = closure_substs.as_closure().kind_ty();
330+
let closure_kind_ty = closure_args.as_closure().kind_ty();
331331
let closure_kind = match closure_kind_ty.to_opt_closure_kind() {
332332
Some(kind @ (ty::ClosureKind::Fn | ty::ClosureKind::FnMut)) => kind,
333333
Some(ty::ClosureKind::FnOnce) => {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_infer::infer::{
2222
};
2323
use rustc_middle::hir::place::PlaceBase;
2424
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
25-
use rustc_middle::ty::subst::InternalSubsts;
25+
use rustc_middle::ty::GenericArgs;
2626
use rustc_middle::ty::TypeVisitor;
2727
use rustc_middle::ty::{self, RegionVid, Ty};
2828
use rustc_middle::ty::{Region, TyCtxt};
@@ -183,9 +183,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
183183
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
184184
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref()
185185
&& let ty::BoundRegionKind::BrEnv = free_region.bound_region
186-
&& let DefiningTy::Closure(_, substs) = self.regioncx.universal_regions().defining_ty
186+
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
187187
{
188-
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
188+
return args.as_closure().kind() == ty::ClosureKind::FnMut;
189189
}
190190

191191
false
@@ -502,12 +502,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
502502
.to_string(),
503503
)
504504
}
505-
ty::Adt(adt, substs) => {
506-
let generic_arg = substs[param_index as usize];
507-
let identity_substs =
508-
InternalSubsts::identity_for_item(self.infcx.tcx, adt.did());
509-
let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_substs);
510-
let base_generic_arg = identity_substs[param_index as usize];
505+
ty::Adt(adt, args) => {
506+
let generic_arg = args[param_index as usize];
507+
let identity_args =
508+
GenericArgs::identity_for_item(self.infcx.tcx, adt.did());
509+
let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_args);
510+
let base_generic_arg = identity_args[param_index as usize];
511511
let adt_desc = adt.descr();
512512

513513
let desc = format!(
@@ -520,12 +520,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
520520
}
521521
ty::FnDef(def_id, _) => {
522522
let name = self.infcx.tcx.item_name(*def_id);
523-
let identity_substs =
524-
InternalSubsts::identity_for_item(self.infcx.tcx, *def_id);
523+
let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, *def_id);
525524
let desc = format!("a function pointer to `{name}`");
526525
let note = format!(
527526
"the function `{name}` is invariant over the parameter `{}`",
528-
identity_substs[param_index as usize]
527+
identity_args[param_index as usize]
529528
);
530529
(desc, note)
531530
}
@@ -573,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
573572

574573
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
575574
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
576-
output_ty = self.infcx.tcx.type_of(def_id).subst_identity()
575+
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity()
577576
};
578577

579578
debug!("report_fnmut_error: output_ty={:?}", output_ty);
@@ -899,14 +898,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
899898
let tcx = self.infcx.tcx;
900899

901900
let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
902-
let (fn_did, substs) = match func_ty.kind() {
903-
ty::FnDef(fn_did, substs) => (fn_did, substs),
901+
let (fn_did, args) = match func_ty.kind() {
902+
ty::FnDef(fn_did, args) => (fn_did, args),
904903
_ => return,
905904
};
906-
debug!(?fn_did, ?substs);
905+
debug!(?fn_did, ?args);
907906

908907
// Only suggest this on function calls, not closures
909-
let ty = tcx.type_of(fn_did).subst_identity();
908+
let ty = tcx.type_of(fn_did).instantiate_identity();
910909
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
911910
if let ty::Closure(_, _) = ty.kind() {
912911
return;
@@ -916,7 +915,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
916915
tcx,
917916
self.param_env,
918917
*fn_did,
919-
self.infcx.resolve_vars_if_possible(substs),
918+
self.infcx.resolve_vars_if_possible(args),
920919
) {
921920
instance
922921
} else {

0 commit comments

Comments
 (0)