Skip to content

Commit fdb2e36

Browse files
committed
refactor(rustc_middle): Substs -> GenericArg
1 parent 660ef4f commit fdb2e36

File tree

94 files changed

+307
-307
lines changed

Some content is hidden

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

94 files changed

+307
-307
lines changed

clippy_lints/src/assertions_on_result_states.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
4747
&& let result_type_with_refs = cx.typeck_results().expr_ty(recv)
4848
&& let result_type = result_type_with_refs.peel_refs()
4949
&& is_type_diagnostic_item(cx, result_type, sym::Result)
50-
&& let ty::Adt(_, substs) = result_type.kind()
50+
&& let ty::Adt(_, args) = result_type.kind()
5151
{
5252
if !is_copy(cx, result_type) {
5353
if result_type_with_refs != result_type {
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
6161
let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""};
6262
let mut app = Applicability::MachineApplicable;
6363
match method_segment.ident.as_str() {
64-
"is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => {
64+
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
6565
span_lint_and_sugg(
6666
cx,
6767
ASSERTIONS_ON_RESULT_STATES,
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
7575
app,
7676
);
7777
}
78-
"is_err" if type_suitable_to_unwrap(cx, substs.type_at(0)) => {
78+
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
7979
span_lint_and_sugg(
8080
cx,
8181
ASSERTIONS_ON_RESULT_STATES,

clippy_lints/src/bool_assert_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6161
)
6262
})
6363
.map_or(false, |assoc_item| {
64-
let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
64+
let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
6565
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6666

6767
nty.is_bool()

clippy_lints/src/casts/as_ptr_cast_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1717
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
1818
&& method_name.ident.name == rustc_span::sym::as_ptr
1919
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
20-
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity()
20+
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity()
2121
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
2222
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
2323
&& let Some(recv) = snippet_opt(cx, receiver.span)

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
6666
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
6767
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
6868
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
69-
&& cx.tcx.type_of(def_id).subst_identity().is_unsafe_ptr()
69+
&& cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr()
7070
{
7171
true
7272
} else {

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
4343
of_trait: Some(ref trait_ref),
4444
..
4545
}) = item.kind;
46-
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
46+
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
4747
if is_copy(cx, ty);
4848
if let Some(trait_id) = trait_ref.trait_def_id();
4949
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);

clippy_lints/src/default.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
150150
.fields
151151
.iter()
152152
.all(|field| {
153-
is_copy(cx, cx.tcx.type_of(field.did).subst_identity())
153+
is_copy(cx, cx.tcx.type_of(field.did).instantiate_identity())
154154
});
155155
if !has_drop(cx, binding_type) || all_fields_are_copy;
156156
then {
@@ -219,11 +219,11 @@ impl<'tcx> LateLintPass<'tcx> for Default {
219219

220220
// give correct suggestion if generics are involved (see #6944)
221221
let binding_type = if_chain! {
222-
if let ty::Adt(adt_def, substs) = binding_type.kind();
223-
if !substs.is_empty();
222+
if let ty::Adt(adt_def, args) = binding_type.kind();
223+
if !args.is_empty();
224224
then {
225225
let adt_def_ty_name = cx.tcx.item_name(adt_def.did());
226-
let generic_args = substs.iter().collect::<Vec<_>>();
226+
let generic_args = args.iter().collect::<Vec<_>>();
227227
let tys_str = generic_args
228228
.iter()
229229
.map(ToString::to_string)

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
141141

142142
ExprKind::MethodCall(_, receiver, args, _) => {
143143
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
144-
let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder();
144+
let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder();
145145
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
146146
self.ty_bounds.push((*bound).into());
147147
self.visit_expr(expr);
@@ -167,7 +167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
167167
.iter()
168168
.find_map(|f_def| {
169169
if f_def.ident(self.cx.tcx) == field.ident
170-
{ Some(self.cx.tcx.type_of(f_def.did).subst_identity()) }
170+
{ Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) }
171171
else { None }
172172
});
173173
self.ty_bounds.push(bound.into());
@@ -213,9 +213,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
213213

214214
fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {
215215
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
216-
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
216+
// We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs.
217217
match node_ty.kind() {
218-
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()),
218+
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()),
219219
ty::FnPtr(fn_sig) => Some(*fn_sig),
220220
_ => None,
221221
}

clippy_lints/src/dereference.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ fn walk_parents<'tcx>(
739739
span,
740740
..
741741
}) if span.ctxt() == ctxt => {
742-
let ty = cx.tcx.type_of(owner_id.def_id).subst_identity();
742+
let ty = cx.tcx.type_of(owner_id.def_id).instantiate_identity();
743743
Some(ty_auto_deref_stability(cx.tcx, cx.param_env, ty, precedence).position_for_result(cx))
744744
},
745745

@@ -763,7 +763,7 @@ fn walk_parents<'tcx>(
763763
}) if span.ctxt() == ctxt => {
764764
let output = cx
765765
.tcx
766-
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
766+
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).instantiate_identity().output());
767767
Some(ty_auto_deref_stability(cx.tcx, cx.param_env, output, precedence).position_for_result(cx))
768768
},
769769

@@ -785,7 +785,7 @@ fn walk_parents<'tcx>(
785785
cx.tcx,
786786
// Use the param_env of the target type.
787787
cx.tcx.param_env(adt.did()),
788-
cx.tcx.type_of(field_def.did).subst_identity(),
788+
cx.tcx.type_of(field_def.did).instantiate_identity(),
789789
precedence,
790790
)
791791
.position_for_arg()
@@ -808,7 +808,7 @@ fn walk_parents<'tcx>(
808808
} else {
809809
let output = cx
810810
.tcx
811-
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
811+
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).instantiate_identity().output());
812812
ty_auto_deref_stability(cx.tcx, cx.param_env, output, precedence).position_for_result(cx)
813813
},
814814
)
@@ -879,9 +879,9 @@ fn walk_parents<'tcx>(
879879
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
880880
&& let subs = cx
881881
.typeck_results()
882-
.node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default()
882+
.node_args_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default()
883883
&& let impl_ty = if cx.tcx.fn_sig(fn_id)
884-
.subst_identity()
884+
.instantiate_identity()
885885
.skip_binder()
886886
.inputs()[0].is_ref()
887887
{
@@ -905,7 +905,7 @@ fn walk_parents<'tcx>(
905905
return Some(Position::MethodReceiver);
906906
}
907907
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
908-
let ty = cx.tcx.fn_sig(fn_id).subst_identity().input(i + 1);
908+
let ty = cx.tcx.fn_sig(fn_id).instantiate_identity().input(i + 1);
909909
// `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739
910910
// `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782
911911
if e.hir_id == child_id
@@ -1124,10 +1124,10 @@ fn needless_borrow_impl_arg_position<'tcx>(
11241124
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();
11251125

11261126
let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) };
1127-
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
1128-
let substs_with_expr_ty = cx
1127+
let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder();
1128+
let args_with_expr_ty = cx
11291129
.typeck_results()
1130-
.node_substs(if let ExprKind::Call(callee, _) = parent.kind {
1130+
.node_args(if let ExprKind::Call(callee, _) = parent.kind {
11311131
callee.hir_id
11321132
} else {
11331133
parent.hir_id
@@ -1181,9 +1181,9 @@ fn needless_borrow_impl_arg_position<'tcx>(
11811181
return Position::Other(precedence);
11821182
}
11831183

1184-
// `substs_with_referent_ty` can be constructed outside of `check_referent` because the same
1184+
// `args_with_referent_ty` can be constructed outside of `check_referent` because the same
11851185
// elements are modified each time `check_referent` is called.
1186-
let mut substs_with_referent_ty = substs_with_expr_ty.to_vec();
1186+
let mut args_with_referent_ty = args_with_expr_ty.to_vec();
11871187

11881188
let mut check_reference_and_referent = |reference, referent| {
11891189
let referent_ty = cx.typeck_results().expr_ty(referent);
@@ -1207,7 +1207,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
12071207
fn_sig,
12081208
arg_index,
12091209
&projection_predicates,
1210-
&mut substs_with_referent_ty,
1210+
&mut args_with_referent_ty,
12111211
) {
12121212
return false;
12131213
}
@@ -1216,14 +1216,14 @@ fn needless_borrow_impl_arg_position<'tcx>(
12161216
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
12171217
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
12181218
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
1219-
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
1219+
&& let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack()
12201220
&& ty.is_array()
12211221
&& !msrv.meets(msrvs::ARRAY_INTO_ITERATOR)
12221222
{
12231223
return false;
12241224
}
12251225

1226-
let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty);
1226+
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty);
12271227
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
12281228
let infcx = cx.tcx.infer_ctxt().build();
12291229
infcx.predicate_must_hold_modulo_regions(&obligation)
@@ -1252,7 +1252,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
12521252
.in_definition_order()
12531253
.any(|assoc_item| {
12541254
if assoc_item.fn_has_self_parameter {
1255-
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
1255+
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).instantiate_identity().skip_binder().inputs()[0];
12561256
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
12571257
} else {
12581258
false
@@ -1323,7 +1323,7 @@ fn referent_used_exactly_once<'tcx>(
13231323
}
13241324
}
13251325

1326-
// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting
1326+
// Iteratively replaces `param_ty` with `new_ty` in `args`, and similarly for each resulting
13271327
// projected type that is a type parameter. Returns `false` if replacing the types would have an
13281328
// effect on the function signature beyond substituting `new_ty` for `param_ty`.
13291329
// See: https://github.com/rust-lang/rust-clippy/pull/9136#discussion_r927212757
@@ -1334,11 +1334,11 @@ fn replace_types<'tcx>(
13341334
fn_sig: FnSig<'tcx>,
13351335
arg_index: usize,
13361336
projection_predicates: &[ProjectionPredicate<'tcx>],
1337-
substs: &mut [ty::GenericArg<'tcx>],
1337+
args: &mut [ty::GenericArg<'tcx>],
13381338
) -> bool {
1339-
let mut replaced = BitSet::new_empty(substs.len());
1339+
let mut replaced = BitSet::new_empty(args.len());
13401340

1341-
let mut deque = VecDeque::with_capacity(substs.len());
1341+
let mut deque = VecDeque::with_capacity(args.len());
13421342
deque.push_back((param_ty, new_ty));
13431343

13441344
while let Some((param_ty, new_ty)) = deque.pop_front() {
@@ -1352,7 +1352,7 @@ fn replace_types<'tcx>(
13521352
return false;
13531353
}
13541354

1355-
substs[param_ty.index as usize] = ty::GenericArg::from(new_ty);
1355+
args[param_ty.index as usize] = ty::GenericArg::from(new_ty);
13561356

13571357
// The `replaced.insert(...)` check provides some protection against infinite loops.
13581358
if replaced.insert(param_ty.index) {
@@ -1367,7 +1367,7 @@ fn replace_types<'tcx>(
13671367
));
13681368

13691369
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
1370-
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
1370+
&& args[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
13711371
{
13721372
deque.push_back((*term_param_ty, projected_ty));
13731373
}
@@ -1442,7 +1442,7 @@ fn ty_auto_deref_stability<'tcx>(
14421442
ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => {
14431443
Position::ReborrowStable(precedence).into()
14441444
},
1445-
ty::Adt(_, substs) if substs.has_non_region_param() => {
1445+
ty::Adt(_, args) if args.has_non_region_param() => {
14461446
TyPosition::new_deref_stable_for_result(precedence, ty)
14471447
},
14481448
ty::Bool

clippy_lints/src/derivable_impls.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{
1010
};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
13-
use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults};
13+
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
1414
use rustc_session::{declare_tool_lint, impl_lint_pass};
1515
use rustc_span::sym;
1616

@@ -80,7 +80,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
8080
fn contains_trait_object(ty: Ty<'_>) -> bool {
8181
match ty.kind() {
8282
ty::Ref(_, ty, _) => contains_trait_object(*ty),
83-
ty::Adt(def, substs) => def.is_box() && substs[0].as_type().map_or(false, contains_trait_object),
83+
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
8484
ty::Dynamic(..) => true,
8585
_ => false,
8686
}
@@ -92,18 +92,18 @@ fn check_struct<'tcx>(
9292
self_ty: &hir::Ty<'_>,
9393
func_expr: &Expr<'_>,
9494
adt_def: AdtDef<'_>,
95-
substs: SubstsRef<'_>,
95+
ty_args: GenericArgsRef<'_>,
9696
typeck_results: &'tcx TypeckResults<'tcx>,
9797
) {
9898
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
9999
if let Some(PathSegment { args, .. }) = p.segments.last() {
100100
let args = args.map(|a| a.args).unwrap_or(&[]);
101101

102-
// substs contains the generic parameters of the type declaration, while args contains the arguments
102+
// ty_args contains the generic parameters of the type declaration, while args contains the arguments
103103
// used at instantiation time. If both len are not equal, it means that some parameters were not
104104
// provided (which means that the default values were used); in this case we will not risk
105105
// suggesting too broad a rewrite. We won't either if any argument is a type or a const.
106-
if substs.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
106+
if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
107107
return;
108108
}
109109
}
@@ -214,15 +214,15 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
214214
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
215215
if let ImplItemKind::Fn(_, b) = &impl_item.kind;
216216
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
217-
if let &Adt(adt_def, substs) = cx.tcx.type_of(item.owner_id).subst_identity().kind();
217+
if let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind();
218218
if let attrs = cx.tcx.hir().attrs(item.hir_id());
219219
if !attrs.iter().any(|attr| attr.doc_str().is_some());
220220
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
221221
if !child_attrs.iter().any(|attr| attr.doc_str().is_some());
222222

223223
then {
224224
if adt_def.is_struct() {
225-
check_struct(cx, item, self_ty, func_expr, adt_def, substs, cx.tcx.typeck_body(*b));
225+
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));
226226
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
227227
check_enum(cx, item, func_expr, adt_def);
228228
}

0 commit comments

Comments
 (0)