Skip to content

Commit 2973096

Browse files
committed
Auto merge of #11250 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents d3c5b48 + 65c5afd commit 2973096

File tree

108 files changed

+404
-391
lines changed

Some content is hidden

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

108 files changed

+404
-391
lines changed

clippy_lints/src/assertions_on_result_states.rs

+3-3
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

+1-1
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

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

clippy_lints/src/casts/cast_ptr_alignment.rs

+1-1
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

+1-1
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

+4-4
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
137137

138138
ExprKind::MethodCall(_, receiver, args, _) => {
139139
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
140-
let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder();
140+
let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder();
141141
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
142142
self.ty_bounds.push((*bound).into());
143143
self.visit_expr(expr);
@@ -163,7 +163,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
163163
.iter()
164164
.find_map(|f_def| {
165165
if f_def.ident(self.cx.tcx) == field.ident
166-
{ Some(self.cx.tcx.type_of(f_def.did).subst_identity()) }
166+
{ Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) }
167167
else { None }
168168
});
169169
self.ty_bounds.push(bound.into());
@@ -209,9 +209,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
209209

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

clippy_lints/src/dereference.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
379379
cx,
380380
&mut self.possible_borrowers,
381381
fn_id,
382-
typeck.node_substs(hir_id),
382+
typeck.node_args(hir_id),
383383
i,
384384
ty,
385385
expr,
@@ -438,11 +438,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
438438
&& let arg_ty
439439
= cx.tcx.erase_regions(use_cx.adjustments.last().map_or(expr_ty, |a| a.target))
440440
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
441-
&& let subs = cx
441+
&& let args = cx
442442
.typeck_results()
443-
.node_substs_opt(hir_id).map(|subs| &subs[1..]).unwrap_or_default()
443+
.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default()
444444
&& let impl_ty = if cx.tcx.fn_sig(fn_id)
445-
.subst_identity()
445+
.instantiate_identity()
446446
.skip_binder()
447447
.inputs()[0].is_ref()
448448
{
@@ -455,7 +455,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
455455
&& cx.tcx.infer_ctxt().build()
456456
.type_implements_trait(
457457
trait_id,
458-
[impl_ty.into()].into_iter().chain(subs.iter().copied()),
458+
[impl_ty.into()].into_iter().chain(args.iter().copied()),
459459
cx.param_env,
460460
)
461461
.must_apply_modulo_regions()
@@ -917,10 +917,10 @@ impl TyCoercionStability {
917917
| ty::Placeholder(_)
918918
| ty::Dynamic(..)
919919
| ty::Param(_) => Self::Reborrow,
920-
ty::Adt(_, substs)
920+
ty::Adt(_, args)
921921
if ty.has_placeholders()
922922
|| ty.has_opaque_types()
923-
|| (!for_return && substs.has_non_region_param()) =>
923+
|| (!for_return && args.has_non_region_param()) =>
924924
{
925925
Self::Reborrow
926926
},
@@ -992,7 +992,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
992992
cx: &LateContext<'tcx>,
993993
possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
994994
fn_id: DefId,
995-
callee_substs: &'tcx List<GenericArg<'tcx>>,
995+
callee_args: &'tcx List<GenericArg<'tcx>>,
996996
arg_index: usize,
997997
param_ty: ParamTy,
998998
mut expr: &Expr<'tcx>,
@@ -1001,7 +1001,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
10011001
let destruct_trait_def_id = cx.tcx.lang_items().destruct_trait();
10021002
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();
10031003

1004-
let fn_sig = cx.tcx.fn_sig(fn_id).subst_identity().skip_binder();
1004+
let fn_sig = cx.tcx.fn_sig(fn_id).instantiate_identity().skip_binder();
10051005
let predicates = cx.tcx.param_env(fn_id).caller_bounds();
10061006
let projection_predicates = predicates
10071007
.iter()
@@ -1050,9 +1050,9 @@ fn needless_borrow_generic_arg_count<'tcx>(
10501050
return 0;
10511051
}
10521052

1053-
// `substs_with_referent_ty` can be constructed outside of `check_referent` because the same
1053+
// `args_with_referent_ty` can be constructed outside of `check_referent` because the same
10541054
// elements are modified each time `check_referent` is called.
1055-
let mut substs_with_referent_ty = callee_substs.to_vec();
1055+
let mut args_with_referent_ty = callee_args.to_vec();
10561056

10571057
let mut check_reference_and_referent = |reference, referent| {
10581058
let referent_ty = cx.typeck_results().expr_ty(referent);
@@ -1076,7 +1076,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
10761076
fn_sig,
10771077
arg_index,
10781078
&projection_predicates,
1079-
&mut substs_with_referent_ty,
1079+
&mut args_with_referent_ty,
10801080
) {
10811081
return false;
10821082
}
@@ -1085,14 +1085,14 @@ fn needless_borrow_generic_arg_count<'tcx>(
10851085
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
10861086
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
10871087
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
1088-
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
1088+
&& let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack()
10891089
&& ty.is_array()
10901090
&& !msrv.meets(msrvs::ARRAY_INTO_ITERATOR)
10911091
{
10921092
return false;
10931093
}
10941094

1095-
let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty);
1095+
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty);
10961096
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
10971097
let infcx = cx.tcx.infer_ctxt().build();
10981098
infcx.predicate_must_hold_modulo_regions(&obligation)
@@ -1116,7 +1116,12 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
11161116
.in_definition_order()
11171117
.any(|assoc_item| {
11181118
if assoc_item.fn_has_self_parameter {
1119-
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
1119+
let self_ty = cx
1120+
.tcx
1121+
.fn_sig(assoc_item.def_id)
1122+
.instantiate_identity()
1123+
.skip_binder()
1124+
.inputs()[0];
11201125
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
11211126
} else {
11221127
false
@@ -1187,7 +1192,7 @@ fn referent_used_exactly_once<'tcx>(
11871192
}
11881193
}
11891194

1190-
// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting
1195+
// Iteratively replaces `param_ty` with `new_ty` in `args`, and similarly for each resulting
11911196
// projected type that is a type parameter. Returns `false` if replacing the types would have an
11921197
// effect on the function signature beyond substituting `new_ty` for `param_ty`.
11931198
// See: https://github.com/rust-lang/rust-clippy/pull/9136#discussion_r927212757
@@ -1198,11 +1203,11 @@ fn replace_types<'tcx>(
11981203
fn_sig: FnSig<'tcx>,
11991204
arg_index: usize,
12001205
projection_predicates: &[ProjectionPredicate<'tcx>],
1201-
substs: &mut [ty::GenericArg<'tcx>],
1206+
args: &mut [ty::GenericArg<'tcx>],
12021207
) -> bool {
1203-
let mut replaced = BitSet::new_empty(substs.len());
1208+
let mut replaced = BitSet::new_empty(args.len());
12041209

1205-
let mut deque = VecDeque::with_capacity(substs.len());
1210+
let mut deque = VecDeque::with_capacity(args.len());
12061211
deque.push_back((param_ty, new_ty));
12071212

12081213
while let Some((param_ty, new_ty)) = deque.pop_front() {
@@ -1216,7 +1221,7 @@ fn replace_types<'tcx>(
12161221
return false;
12171222
}
12181223

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

12211226
// The `replaced.insert(...)` check provides some protection against infinite loops.
12221227
if replaced.insert(param_ty.index) {
@@ -1231,7 +1236,7 @@ fn replace_types<'tcx>(
12311236
));
12321237

12331238
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
1234-
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
1239+
&& args[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
12351240
{
12361241
deque.push_back((*term_param_ty, projected_ty));
12371242
}

clippy_lints/src/derivable_impls.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
12-
use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults};
12+
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
1313
use rustc_session::{declare_tool_lint, impl_lint_pass};
1414
use rustc_span::sym;
1515

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

101-
// substs contains the generic parameters of the type declaration, while args contains the arguments
102-
// used at instantiation time. If both len are not equal, it means that some parameters were not
103-
// provided (which means that the default values were used); in this case we will not risk
104-
// suggesting too broad a rewrite. We won't either if any argument is a type or a const.
105-
if substs.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
101+
// ty_args contains the generic parameters of the type declaration, while args contains the
102+
// arguments used at instantiation time. If both len are not equal, it means that some
103+
// parameters were not provided (which means that the default values were used); in this
104+
// case we will not risk suggesting too broad a rewrite. We won't either if any argument
105+
// is a type or a const.
106+
if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
106107
return;
107108
}
108109
}
@@ -213,15 +214,15 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
213214
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
214215
if let ImplItemKind::Fn(_, b) = &impl_item.kind;
215216
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
216-
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();
217218
if let attrs = cx.tcx.hir().attrs(item.hir_id());
218219
if !attrs.iter().any(|attr| attr.doc_str().is_some());
219220
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
220221
if !child_attrs.iter().any(|attr| attr.doc_str().is_some());
221222

222223
then {
223224
if adt_def.is_struct() {
224-
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));
225226
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
226227
check_enum(cx, item, func_expr, adt_def);
227228
}

0 commit comments

Comments
 (0)