Auto merge of #11250 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
This commit is contained in:
commit
29730969b1
@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
|
||||
&& let result_type_with_refs = cx.typeck_results().expr_ty(recv)
|
||||
&& let result_type = result_type_with_refs.peel_refs()
|
||||
&& is_type_diagnostic_item(cx, result_type, sym::Result)
|
||||
&& let ty::Adt(_, substs) = result_type.kind()
|
||||
&& let ty::Adt(_, args) = result_type.kind()
|
||||
{
|
||||
if !is_copy(cx, result_type) {
|
||||
if result_type_with_refs != result_type {
|
||||
@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
|
||||
let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""};
|
||||
let mut app = Applicability::MachineApplicable;
|
||||
match method_segment.ident.as_str() {
|
||||
"is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => {
|
||||
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
ASSERTIONS_ON_RESULT_STATES,
|
||||
@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
|
||||
app,
|
||||
);
|
||||
}
|
||||
"is_err" if type_suitable_to_unwrap(cx, substs.type_at(0)) => {
|
||||
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
ASSERTIONS_ON_RESULT_STATES,
|
||||
|
@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
|
||||
)
|
||||
})
|
||||
.map_or(false, |assoc_item| {
|
||||
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
|
||||
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
|
||||
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
|
||||
|
||||
nty.is_bool()
|
||||
|
@ -15,7 +15,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
|
||||
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
|
||||
&& method_name.ident.name == rustc_span::sym::as_ptr
|
||||
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
|
||||
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity()
|
||||
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity()
|
||||
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
|
||||
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
|
||||
&& let Some(recv) = snippet_opt(cx, receiver.span)
|
||||
|
@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
|
||||
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
|
||||
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
|
||||
&& cx.tcx.type_of(def_id).subst_identity().is_unsafe_ptr()
|
||||
&& cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr()
|
||||
{
|
||||
true
|
||||
} else {
|
||||
|
@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
|
||||
of_trait: Some(ref trait_ref),
|
||||
..
|
||||
}) = item.kind;
|
||||
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
if is_copy(cx, ty);
|
||||
if let Some(trait_id) = trait_ref.trait_def_id();
|
||||
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);
|
||||
|
@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
|
||||
.fields
|
||||
.iter()
|
||||
.all(|field| {
|
||||
is_copy(cx, cx.tcx.type_of(field.did).subst_identity())
|
||||
is_copy(cx, cx.tcx.type_of(field.did).instantiate_identity())
|
||||
});
|
||||
if !has_drop(cx, binding_type) || all_fields_are_copy;
|
||||
then {
|
||||
@ -219,11 +219,11 @@ impl<'tcx> LateLintPass<'tcx> for Default {
|
||||
|
||||
// give correct suggestion if generics are involved (see #6944)
|
||||
let binding_type = if_chain! {
|
||||
if let ty::Adt(adt_def, substs) = binding_type.kind();
|
||||
if !substs.is_empty();
|
||||
if let ty::Adt(adt_def, args) = binding_type.kind();
|
||||
if !args.is_empty();
|
||||
then {
|
||||
let adt_def_ty_name = cx.tcx.item_name(adt_def.did());
|
||||
let generic_args = substs.iter().collect::<Vec<_>>();
|
||||
let generic_args = args.iter().collect::<Vec<_>>();
|
||||
let tys_str = generic_args
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
|
@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
|
||||
|
||||
ExprKind::MethodCall(_, receiver, args, _) => {
|
||||
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
|
||||
let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder();
|
||||
let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder();
|
||||
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
|
||||
self.ty_bounds.push((*bound).into());
|
||||
self.visit_expr(expr);
|
||||
@ -163,7 +163,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
|
||||
.iter()
|
||||
.find_map(|f_def| {
|
||||
if f_def.ident(self.cx.tcx) == field.ident
|
||||
{ Some(self.cx.tcx.type_of(f_def.did).subst_identity()) }
|
||||
{ Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) }
|
||||
else { None }
|
||||
});
|
||||
self.ty_bounds.push(bound.into());
|
||||
@ -209,9 +209,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
|
||||
|
||||
fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {
|
||||
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
|
||||
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
|
||||
// We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs.
|
||||
match node_ty.kind() {
|
||||
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()),
|
||||
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()),
|
||||
ty::FnPtr(fn_sig) => Some(*fn_sig),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
||||
cx,
|
||||
&mut self.possible_borrowers,
|
||||
fn_id,
|
||||
typeck.node_substs(hir_id),
|
||||
typeck.node_args(hir_id),
|
||||
i,
|
||||
ty,
|
||||
expr,
|
||||
@ -438,11 +438,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
||||
&& let arg_ty
|
||||
= cx.tcx.erase_regions(use_cx.adjustments.last().map_or(expr_ty, |a| a.target))
|
||||
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
|
||||
&& let subs = cx
|
||||
&& let args = cx
|
||||
.typeck_results()
|
||||
.node_substs_opt(hir_id).map(|subs| &subs[1..]).unwrap_or_default()
|
||||
.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default()
|
||||
&& let impl_ty = if cx.tcx.fn_sig(fn_id)
|
||||
.subst_identity()
|
||||
.instantiate_identity()
|
||||
.skip_binder()
|
||||
.inputs()[0].is_ref()
|
||||
{
|
||||
@ -455,7 +455,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
||||
&& cx.tcx.infer_ctxt().build()
|
||||
.type_implements_trait(
|
||||
trait_id,
|
||||
[impl_ty.into()].into_iter().chain(subs.iter().copied()),
|
||||
[impl_ty.into()].into_iter().chain(args.iter().copied()),
|
||||
cx.param_env,
|
||||
)
|
||||
.must_apply_modulo_regions()
|
||||
@ -917,10 +917,10 @@ impl TyCoercionStability {
|
||||
| ty::Placeholder(_)
|
||||
| ty::Dynamic(..)
|
||||
| ty::Param(_) => Self::Reborrow,
|
||||
ty::Adt(_, substs)
|
||||
ty::Adt(_, args)
|
||||
if ty.has_placeholders()
|
||||
|| ty.has_opaque_types()
|
||||
|| (!for_return && substs.has_non_region_param()) =>
|
||||
|| (!for_return && args.has_non_region_param()) =>
|
||||
{
|
||||
Self::Reborrow
|
||||
},
|
||||
@ -992,7 +992,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
|
||||
fn_id: DefId,
|
||||
callee_substs: &'tcx List<GenericArg<'tcx>>,
|
||||
callee_args: &'tcx List<GenericArg<'tcx>>,
|
||||
arg_index: usize,
|
||||
param_ty: ParamTy,
|
||||
mut expr: &Expr<'tcx>,
|
||||
@ -1001,7 +1001,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
|
||||
let destruct_trait_def_id = cx.tcx.lang_items().destruct_trait();
|
||||
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(fn_id).subst_identity().skip_binder();
|
||||
let fn_sig = cx.tcx.fn_sig(fn_id).instantiate_identity().skip_binder();
|
||||
let predicates = cx.tcx.param_env(fn_id).caller_bounds();
|
||||
let projection_predicates = predicates
|
||||
.iter()
|
||||
@ -1050,9 +1050,9 @@ fn needless_borrow_generic_arg_count<'tcx>(
|
||||
return 0;
|
||||
}
|
||||
|
||||
// `substs_with_referent_ty` can be constructed outside of `check_referent` because the same
|
||||
// `args_with_referent_ty` can be constructed outside of `check_referent` because the same
|
||||
// elements are modified each time `check_referent` is called.
|
||||
let mut substs_with_referent_ty = callee_substs.to_vec();
|
||||
let mut args_with_referent_ty = callee_args.to_vec();
|
||||
|
||||
let mut check_reference_and_referent = |reference, referent| {
|
||||
let referent_ty = cx.typeck_results().expr_ty(referent);
|
||||
@ -1076,7 +1076,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
|
||||
fn_sig,
|
||||
arg_index,
|
||||
&projection_predicates,
|
||||
&mut substs_with_referent_ty,
|
||||
&mut args_with_referent_ty,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@ -1085,14 +1085,14 @@ fn needless_borrow_generic_arg_count<'tcx>(
|
||||
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
|
||||
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
|
||||
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
|
||||
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
|
||||
&& let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack()
|
||||
&& ty.is_array()
|
||||
&& !msrv.meets(msrvs::ARRAY_INTO_ITERATOR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty);
|
||||
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty);
|
||||
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
infcx.predicate_must_hold_modulo_regions(&obligation)
|
||||
@ -1116,7 +1116,12 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
|
||||
.in_definition_order()
|
||||
.any(|assoc_item| {
|
||||
if assoc_item.fn_has_self_parameter {
|
||||
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
|
||||
let self_ty = cx
|
||||
.tcx
|
||||
.fn_sig(assoc_item.def_id)
|
||||
.instantiate_identity()
|
||||
.skip_binder()
|
||||
.inputs()[0];
|
||||
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
|
||||
} else {
|
||||
false
|
||||
@ -1187,7 +1192,7 @@ fn referent_used_exactly_once<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting
|
||||
// Iteratively replaces `param_ty` with `new_ty` in `args`, and similarly for each resulting
|
||||
// projected type that is a type parameter. Returns `false` if replacing the types would have an
|
||||
// effect on the function signature beyond substituting `new_ty` for `param_ty`.
|
||||
// See: https://github.com/rust-lang/rust-clippy/pull/9136#discussion_r927212757
|
||||
@ -1198,11 +1203,11 @@ fn replace_types<'tcx>(
|
||||
fn_sig: FnSig<'tcx>,
|
||||
arg_index: usize,
|
||||
projection_predicates: &[ProjectionPredicate<'tcx>],
|
||||
substs: &mut [ty::GenericArg<'tcx>],
|
||||
args: &mut [ty::GenericArg<'tcx>],
|
||||
) -> bool {
|
||||
let mut replaced = BitSet::new_empty(substs.len());
|
||||
let mut replaced = BitSet::new_empty(args.len());
|
||||
|
||||
let mut deque = VecDeque::with_capacity(substs.len());
|
||||
let mut deque = VecDeque::with_capacity(args.len());
|
||||
deque.push_back((param_ty, new_ty));
|
||||
|
||||
while let Some((param_ty, new_ty)) = deque.pop_front() {
|
||||
@ -1216,7 +1221,7 @@ fn replace_types<'tcx>(
|
||||
return false;
|
||||
}
|
||||
|
||||
substs[param_ty.index as usize] = ty::GenericArg::from(new_ty);
|
||||
args[param_ty.index as usize] = ty::GenericArg::from(new_ty);
|
||||
|
||||
// The `replaced.insert(...)` check provides some protection against infinite loops.
|
||||
if replaced.insert(param_ty.index) {
|
||||
@ -1231,7 +1236,7 @@ fn replace_types<'tcx>(
|
||||
));
|
||||
|
||||
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
|
||||
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
|
||||
&& args[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
|
||||
{
|
||||
deque.push_back((*term_param_ty, projected_ty));
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use rustc_hir::{
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
|
||||
use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults};
|
||||
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::sym;
|
||||
|
||||
@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
|
||||
fn contains_trait_object(ty: Ty<'_>) -> bool {
|
||||
match ty.kind() {
|
||||
ty::Ref(_, ty, _) => contains_trait_object(*ty),
|
||||
ty::Adt(def, substs) => def.is_box() && substs[0].as_type().map_or(false, contains_trait_object),
|
||||
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
|
||||
ty::Dynamic(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -91,18 +91,19 @@ fn check_struct<'tcx>(
|
||||
self_ty: &hir::Ty<'_>,
|
||||
func_expr: &Expr<'_>,
|
||||
adt_def: AdtDef<'_>,
|
||||
substs: SubstsRef<'_>,
|
||||
ty_args: GenericArgsRef<'_>,
|
||||
typeck_results: &'tcx TypeckResults<'tcx>,
|
||||
) {
|
||||
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
|
||||
if let Some(PathSegment { args, .. }) = p.segments.last() {
|
||||
let args = args.map(|a| a.args).unwrap_or(&[]);
|
||||
|
||||
// substs contains the generic parameters of the type declaration, while args contains the arguments
|
||||
// used at instantiation time. If both len are not equal, it means that some parameters were not
|
||||
// provided (which means that the default values were used); in this case we will not risk
|
||||
// suggesting too broad a rewrite. We won't either if any argument is a type or a const.
|
||||
if substs.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
|
||||
// ty_args contains the generic parameters of the type declaration, while args contains the
|
||||
// arguments used at instantiation time. If both len are not equal, it means that some
|
||||
// parameters were not provided (which means that the default values were used); in this
|
||||
// case we will not risk suggesting too broad a rewrite. We won't either if any argument
|
||||
// is a type or a const.
|
||||
if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -213,7 +214,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
||||
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
|
||||
if let ImplItemKind::Fn(_, b) = &impl_item.kind;
|
||||
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
|
||||
if let &Adt(adt_def, substs) = cx.tcx.type_of(item.owner_id).subst_identity().kind();
|
||||
if let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind();
|
||||
if let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
if !attrs.iter().any(|attr| attr.doc_str().is_some());
|
||||
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
|
||||
@ -221,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
||||
|
||||
then {
|
||||
if adt_def.is_struct() {
|
||||
check_struct(cx, item, self_ty, func_expr, adt_def, substs, cx.tcx.typeck_body(*b));
|
||||
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));
|
||||
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
|
||||
check_enum(cx, item, func_expr, adt_def);
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
|
||||
..
|
||||
}) = item.kind
|
||||
{
|
||||
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
|
||||
|
||||
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
|
||||
@ -251,7 +251,7 @@ fn check_hash_peq<'tcx>(
|
||||
|
||||
// Only care about `impl PartialEq<Foo> for Foo`
|
||||
// For `impl PartialEq<B> for A, input_types is [A, B]
|
||||
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||
if trait_ref.instantiate_identity().args.type_at(1) == ty {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
DERIVED_HASH_WITH_MANUAL_EQ,
|
||||
@ -299,7 +299,7 @@ fn check_ord_partial_ord<'tcx>(
|
||||
|
||||
// Only care about `impl PartialOrd<Foo> for Foo`
|
||||
// For `impl PartialOrd<B> for A, input_types is [A, B]
|
||||
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||
if trait_ref.instantiate_identity().args.type_at(1) == ty {
|
||||
let mess = if partial_ord_is_automatically_derived {
|
||||
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
|
||||
} else {
|
||||
@ -346,9 +346,9 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
|
||||
if !is_copy(cx, ty) {
|
||||
if ty_subs.non_erasable_generics().next().is_some() {
|
||||
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| {
|
||||
impls.iter().any(|&id| {
|
||||
matches!(cx.tcx.type_of(id).subst_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())
|
||||
})
|
||||
impls
|
||||
.iter()
|
||||
.any(|&id| matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did()))
|
||||
});
|
||||
if !has_copy_impl {
|
||||
return;
|
||||
@ -465,7 +465,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
|
||||
/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
|
||||
fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) {
|
||||
if_chain! {
|
||||
if let ty::Adt(adt, substs) = ty.kind();
|
||||
if let ty::Adt(adt, args) = ty.kind();
|
||||
if cx.tcx.visibility(adt.did()).is_public();
|
||||
if let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq);
|
||||
if let Some(def_id) = trait_ref.trait_def_id();
|
||||
@ -475,7 +475,7 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
|
||||
// If all of our fields implement `Eq`, we can implement `Eq` too
|
||||
if adt
|
||||
.all_fields()
|
||||
.map(|f| f.ty(cx.tcx, substs))
|
||||
.map(|f| f.ty(cx.tcx, args))
|
||||
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, []));
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
|
@ -729,7 +729,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
||||
false,
|
||||
TerminalUrl::No,
|
||||
);
|
||||
let handler = Handler::with_emitter(false, None, Box::new(emitter));
|
||||
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
|
||||
let sess = ParseSess::with_span_handler(handler, sm);
|
||||
|
||||
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
|
||||
|
@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
|
||||
}
|
||||
|
||||
if let ItemKind::Enum(..) = item.kind {
|
||||
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
|
||||
if adt.variants().is_empty() {
|
||||
span_lint_and_help(
|
||||
|
@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
|
||||
for var in def.variants {
|
||||
if let Some(anon_const) = &var.disr_expr {
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
|
||||
let mut ty = cx.tcx.type_of(def_id.to_def_id()).subst_identity();
|
||||
let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity();
|
||||
let constant = cx
|
||||
.tcx
|
||||
.const_eval_poly(def_id.to_def_id())
|
||||
|
@ -11,7 +11,7 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||
use rustc_middle::ty::binding::BindingMode;
|
||||
use rustc_middle::ty::{self, EarlyBinder, SubstsRef, Ty, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TypeVisitableExt};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
@ -108,18 +108,18 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
||||
if check_inputs(cx, body.params, None, args);
|
||||
let callee_ty = cx.typeck_results().expr_ty_adjusted(callee);
|
||||
let call_ty = cx.typeck_results().type_dependent_def_id(body.value.hir_id)
|
||||
.map_or(callee_ty, |id| cx.tcx.type_of(id).subst_identity());
|
||||
.map_or(callee_ty, |id| cx.tcx.type_of(id).instantiate_identity());
|
||||
if check_sig(cx, closure_ty, call_ty);
|
||||
let substs = cx.typeck_results().node_substs(callee.hir_id);
|
||||
let args = cx.typeck_results().node_args(callee.hir_id);
|
||||
// This fixes some false positives that I don't entirely understand
|
||||
if substs.is_empty() || !cx.typeck_results().expr_ty(expr).has_late_bound_regions();
|
||||
if args.is_empty() || !cx.typeck_results().expr_ty(expr).has_late_bound_regions();
|
||||
// A type param function ref like `T::f` is not 'static, however
|
||||
// it is if cast like `T::f as fn()`. This seems like a rustc bug.
|
||||
if !substs.types().any(|t| matches!(t.kind(), ty::Param(_)));
|
||||
if !args.types().any(|t| matches!(t.kind(), ty::Param(_)));
|
||||
let callee_ty_unadjusted = cx.typeck_results().expr_ty(callee).peel_refs();
|
||||
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc);
|
||||
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc);
|
||||
if let ty::Closure(_, substs) = *closure_ty.kind();
|
||||
if let ty::Closure(_, args) = *closure_ty.kind();
|
||||
// Don't lint if this is an inclusive range expression.
|
||||
// They desugar to a call to `RangeInclusiveNew` which would have odd suggestions. (#10684)
|
||||
if !matches!(higher::Range::hir(body.value), Some(higher::Range {
|
||||
@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
||||
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
|
||||
if let Some(mut snippet) = snippet_opt(cx, callee.span) {
|
||||
if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
|
||||
&& let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs()
|
||||
&& let args = cx.tcx.erase_late_bound_regions(args.as_closure().sig()).inputs()
|
||||
&& implements_trait(
|
||||
cx,
|
||||
callee_ty.peel_refs(),
|
||||
@ -160,12 +160,12 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
|
||||
if let ExprKind::MethodCall(path, receiver, args, _) = body.value.kind;
|
||||
if check_inputs(cx, body.params, Some(receiver), args);
|
||||
let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap();
|
||||
let substs = cx.typeck_results().node_substs(body.value.hir_id);
|
||||
let call_ty = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs);
|
||||
let args = cx.typeck_results().node_args(body.value.hir_id);
|
||||
let call_ty = cx.tcx.type_of(method_def_id).instantiate(cx.tcx, args);
|
||||
if check_sig(cx, closure_ty, call_ty);
|
||||
then {
|
||||
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| {
|
||||
let name = get_ufcs_type_name(cx, method_def_id, substs);
|
||||
let name = get_ufcs_type_name(cx, method_def_id, args);
|
||||
diag.span_suggestion(
|
||||
expr.span,
|
||||
"replace the closure with the method itself",
|
||||
@ -228,14 +228,14 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
|
||||
if !closure_ty.has_late_bound_regions() {
|
||||
return true;
|
||||
}
|
||||
let ty::Closure(_, substs) = closure_ty.kind() else {
|
||||
let ty::Closure(_, args) = closure_ty.kind() else {
|
||||
return false;
|
||||
};
|
||||
let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal);
|
||||
let closure_sig = cx.tcx.signature_unclosure(args.as_closure().sig(), Unsafety::Normal);
|
||||
cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig)
|
||||
}
|
||||
|
||||
fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs: SubstsRef<'tcx>) -> String {
|
||||
fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, args: GenericArgsRef<'tcx>) -> String {
|
||||
let assoc_item = cx.tcx.associated_item(method_def_id);
|
||||
let def_id = assoc_item.container_id(cx.tcx);
|
||||
match assoc_item.container {
|
||||
@ -251,7 +251,7 @@ fn get_ufcs_type_name<'tcx>(cx: &LateContext<'tcx>, method_def_id: DefId, substs
|
||||
| ty::Ref(..)
|
||||
| ty::Slice(_)
|
||||
| ty::Tuple(_) => {
|
||||
format!("<{}>", EarlyBinder::bind(ty).subst(cx.tcx, substs))
|
||||
format!("<{}>", EarlyBinder::bind(ty).instantiate(cx.tcx, args))
|
||||
},
|
||||
_ => ty.to_string(),
|
||||
}
|
||||
|
@ -77,9 +77,10 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
|
||||
// `impl Into<target_ty> for self_ty`
|
||||
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity)
|
||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
||||
.map(ty::EarlyBinder::instantiate_identity)
|
||||
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
||||
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
||||
&& !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -197,14 +197,14 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet)
|
||||
match *ty.kind() {
|
||||
// primitive types are never mutable
|
||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
|
||||
ty::Adt(adt, substs) => {
|
||||
ty::Adt(adt, args) => {
|
||||
tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.param_env)
|
||||
|| KNOWN_WRAPPER_TYS
|
||||
.iter()
|
||||
.any(|&sym| cx.tcx.is_diagnostic_item(sym, adt.did()))
|
||||
&& substs.types().any(|ty| is_mutable_ty(cx, ty, tys))
|
||||
&& args.types().any(|ty| is_mutable_ty(cx, ty, tys))
|
||||
},
|
||||
ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, tys)),
|
||||
ty::Tuple(args) => args.iter().any(|ty| is_mutable_ty(cx, ty, tys)),
|
||||
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, tys),
|
||||
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
|
||||
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, tys)
|
||||
|
@ -21,11 +21,11 @@ fn result_err_ty<'tcx>(
|
||||
) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> {
|
||||
if !in_external_macro(cx.sess(), item_span)
|
||||
&& let hir::FnRetTy::Return(hir_ty) = decl.output
|
||||
&& let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).subst_identity().output())
|
||||
&& let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).instantiate_identity().output())
|
||||
&& is_type_diagnostic_item(cx, ty, sym::Result)
|
||||
&& let ty::Adt(_, substs) = ty.kind()
|
||||
&& let ty::Adt(_, args) = ty.kind()
|
||||
{
|
||||
let err_ty = substs.type_at(1);
|
||||
let err_ty = args.type_at(1);
|
||||
Some((hir_ty, err_ty))
|
||||
} else {
|
||||
None
|
||||
|
@ -63,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||
return;
|
||||
}
|
||||
let ret_ty = return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(fn_def_id).expect_owner());
|
||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
|
||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() {
|
||||
let preds = cx.tcx.explicit_item_bounds(def_id);
|
||||
let mut is_future = false;
|
||||
for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
|
||||
for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) {
|
||||
if let Some(trait_pred) = p.as_trait_clause() {
|
||||
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
|
||||
is_future = true;
|
||||
|
@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
|
||||
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_integral();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_integral();
|
||||
then {
|
||||
print_lint_and_sugg(cx, var_name, expr)
|
||||
}
|
||||
@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
|
||||
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
|
||||
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_integral();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_integral();
|
||||
then {
|
||||
print_lint_and_sugg(cx, var_name, expr)
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ impl LateLintPass<'_> for IncorrectImpls {
|
||||
cx,
|
||||
hir_ty_to_ty(cx.tcx, imp.self_ty),
|
||||
*ord_def_id,
|
||||
trait_impl.substs,
|
||||
trait_impl.args,
|
||||
)
|
||||
{
|
||||
// If the `cmp` call likely needs to be fully qualified in the suggestion
|
||||
@ -217,7 +217,7 @@ impl LateLintPass<'_> for IncorrectImpls {
|
||||
{} else {
|
||||
// If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
|
||||
// suggestion tons more complex.
|
||||
if let [lhs, rhs, ..] = trait_impl.substs.as_slice() && lhs != rhs {
|
||||
if let [lhs, rhs, ..] = trait_impl.args.as_slice() && lhs != rhs {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
||||
)
|
||||
}) {
|
||||
for impl_id in impl_ids.iter().map(|id| id.expect_local()) {
|
||||
let impl_ty = cx.tcx.type_of(impl_id).subst_identity();
|
||||
let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity();
|
||||
match type_map.entry(impl_ty) {
|
||||
Entry::Vacant(e) => {
|
||||
// Store the id for the first impl block of this type. The span is retrieved lazily.
|
||||
|
@ -71,7 +71,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI
|
||||
if sig.decl.implicit_self.has_implicit_self() {
|
||||
let ret_ty = cx
|
||||
.tcx
|
||||
.erase_late_bound_regions(cx.tcx.fn_sig(fn_id).subst_identity().output());
|
||||
.erase_late_bound_regions(cx.tcx.fn_sig(fn_id).instantiate_identity().output());
|
||||
let ret_ty = cx
|
||||
.tcx
|
||||
.try_normalize_erasing_regions(cx.param_env, ret_ty)
|
||||
|
@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
||||
return;
|
||||
}
|
||||
if let ItemKind::Enum(ref def, _) = item.kind {
|
||||
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
let Adt(adt, subst) = ty.kind() else {
|
||||
panic!("already checked whether this is an enum")
|
||||
};
|
||||
@ -167,8 +167,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
||||
}
|
||||
|
||||
fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
if let Adt(_def, substs) = ty.kind()
|
||||
&& substs.types().next().is_some()
|
||||
if let Adt(_def, args) = ty.kind()
|
||||
&& args.types().next().is_some()
|
||||
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
|
||||
{
|
||||
return cx.tcx.non_blanket_impls_for_ty(copy_trait, ty).next().is_some();
|
||||
|
@ -145,7 +145,10 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
|
||||
if let Some(local_id) = ty_id.as_local();
|
||||
let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id);
|
||||
if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id);
|
||||
if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder());
|
||||
if let Some(output) = parse_len_output(
|
||||
cx,
|
||||
cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder()
|
||||
);
|
||||
then {
|
||||
let (name, kind) = match cx.tcx.hir().find(ty_hir_id) {
|
||||
Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"),
|
||||
@ -450,7 +453,7 @@ fn check_for_is_empty(
|
||||
if !(is_empty.fn_has_self_parameter
|
||||
&& check_is_empty_sig(
|
||||
cx,
|
||||
cx.tcx.fn_sig(is_empty.def_id).subst_identity().skip_binder(),
|
||||
cx.tcx.fn_sig(is_empty.def_id).instantiate_identity().skip_binder(),
|
||||
self_kind,
|
||||
output,
|
||||
)) =>
|
||||
|
@ -4,8 +4,7 @@ use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths};
|
||||
use rustc_hir::{Local, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::IsSuggestable;
|
||||
use rustc_middle::ty::{GenericArgKind, IsSuggestable};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
|
@ -125,7 +125,7 @@ fn is_ref_iterable<'tcx>(
|
||||
}
|
||||
|
||||
let res_ty = cx.tcx.erase_regions(EarlyBinder::bind(req_res_ty)
|
||||
.subst(cx.tcx, typeck.node_substs(call_expr.hir_id)));
|
||||
.instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)));
|
||||
let mutbl = if let ty::Ref(_, _, mutbl) = *req_self_ty.kind() {
|
||||
Some(mutbl)
|
||||
} else {
|
||||
|
@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &'
|
||||
if let ExprKind::Block(Block { stmts: [], expr: None, ..}, _) = body.kind;
|
||||
if let ExprKind::MethodCall(method, callee, ..) = unpack_cond(cond).kind;
|
||||
if [sym::load, sym::compare_exchange, sym::compare_exchange_weak].contains(&method.ident.name);
|
||||
if let ty::Adt(def, _substs) = cx.typeck_results().expr_ty(callee).kind();
|
||||
if let ty::Adt(def, _args) = cx.typeck_results().expr_ty(callee).kind();
|
||||
if cx.tcx.is_diagnostic_item(sym::AtomicBool, def.did());
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
|
@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
ExprKind::MethodCall(_, receiver, args, _) => {
|
||||
let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
|
||||
for (ty, expr) in iter::zip(
|
||||
self.cx.tcx.fn_sig(def_id).subst_identity().inputs().skip_binder(),
|
||||
self.cx.tcx.fn_sig(def_id).instantiate_identity().inputs().skip_binder(),
|
||||
std::iter::once(receiver).chain(args.iter()),
|
||||
) {
|
||||
self.prefer_mutable = false;
|
||||
|
@ -9,6 +9,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::{is_range_literal, BorrowKind, Expr, ExprKind, Pat};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::sym;
|
||||
|
||||
pub(super) fn check<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
@ -51,7 +52,7 @@ pub(super) fn check<'tcx>(
|
||||
},
|
||||
[],
|
||||
_,
|
||||
) if method.ident.name.as_str() == "iter_mut" => (arg, "&mut "),
|
||||
) if method.ident.name == sym::iter_mut => (arg, "&mut "),
|
||||
ExprKind::MethodCall(
|
||||
method,
|
||||
Expr {
|
||||
|
@ -110,7 +110,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<
|
||||
if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id();
|
||||
if cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id);
|
||||
then {
|
||||
cx.typeck_results().node_substs(count_func.hir_id).types().next().map(|resolved_ty| (*real_ty, resolved_ty))
|
||||
cx.typeck_results().node_args(count_func.hir_id).types().next().map(|resolved_ty| (*real_ty, resolved_ty))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ fn simplify_half<'tcx>(
|
||||
&& let ExprKind::Path(ref func_qpath) = func.kind
|
||||
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id)
|
||||
&& let Some(ty2) = cx.typeck_results().node_substs(func.hir_id).types().next()
|
||||
&& let Some(ty2) = cx.typeck_results().node_args(func.hir_id).types().next()
|
||||
// T1 == T2?
|
||||
&& *ty1 == ty2
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
if let ty::FnDef(id, _) = *ty.kind() {
|
||||
if let Some(fn_type) = cx.tcx.fn_sig(id).subst_identity().no_bound_vars() {
|
||||
if let Some(fn_type) = cx.tcx.fn_sig(id).instantiate_identity().no_bound_vars() {
|
||||
return is_unit_type(fn_type.output());
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
|
||||
let input_ty = cx.typeck_results().expr_ty(ex);
|
||||
|
||||
let cast = if_chain! {
|
||||
if let ty::Adt(_, substs) = input_ty.kind();
|
||||
let input_ty = substs.type_at(0);
|
||||
if let ty::Adt(_, substs) = output_ty.kind();
|
||||
let output_ty = substs.type_at(0);
|
||||
if let ty::Adt(_, args) = input_ty.kind();
|
||||
let input_ty = args.type_at(0);
|
||||
if let ty::Adt(_, args) = output_ty.kind();
|
||||
let output_ty = args.type_at(0);
|
||||
if let ty::Ref(_, output_ty, _) = *output_ty.kind();
|
||||
if input_ty != output_ty;
|
||||
then {
|
||||
|
@ -12,8 +12,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
|
||||
use rustc_hir::{Arm, Expr, ExprKind, Guard, Node, Pat, PatKind, QPath, UnOp};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::{self, GenericArgKind, Ty};
|
||||
use rustc_span::{sym, Symbol};
|
||||
use std::fmt::Write;
|
||||
use std::ops::ControlFlow;
|
||||
|
@ -10,7 +10,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
|
||||
if !pat.span.from_expansion();
|
||||
if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
|
||||
if let Some(def_id) = path.res.opt_def_id();
|
||||
let ty = cx.tcx.type_of(def_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(def_id).instantiate_identity();
|
||||
if let ty::Adt(def, _) = ty.kind();
|
||||
if def.is_struct() || def.is_union();
|
||||
if fields.len() == def.non_enum_variant().fields.len();
|
||||
|
@ -6,8 +6,7 @@ use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
|
||||
use rustc_span::Span;
|
||||
|
||||
use super::SIGNIFICANT_DROP_IN_SCRUTINEE;
|
||||
|
@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(
|
||||
let haystack = if let ExprKind::MethodCall(path, receiver, [], _) =
|
||||
filter_recv.kind {
|
||||
let p = path.ident.name;
|
||||
if p == sym::iter || p == sym!(iter_mut) {
|
||||
if p == sym::iter || p == sym::iter_mut {
|
||||
receiver
|
||||
} else {
|
||||
filter_recv
|
||||
|
@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(
|
||||
if_chain! {
|
||||
if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(bytes_id);
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_str();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_str();
|
||||
let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs();
|
||||
if ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String);
|
||||
then {
|
||||
|
@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_str();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_str();
|
||||
if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = arg.kind;
|
||||
if (2..=6).contains(&ext_literal.as_str().len());
|
||||
let ext_str = ext_literal.as_str();
|
||||
|
@ -46,7 +46,7 @@ pub(super) fn check(
|
||||
/// Given a `Result<T, E>` type, return its data (`T`).
|
||||
fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||
match ty.kind() {
|
||||
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().next(),
|
||||
ty::Adt(_, args) if is_type_diagnostic_item(cx, ty, sym::Result) => args.types().next(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ pub(super) fn check<'tcx>(
|
||||
if let hir::ExprKind::Path(ref p) = fun.kind {
|
||||
match cx.qpath_res(p, fun.hir_id) {
|
||||
hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!(
|
||||
cx.tcx.fn_sig(def_id).subst_identity().output().skip_binder().kind(),
|
||||
cx.tcx.fn_sig(def_id).instantiate_identity().output().skip_binder().kind(),
|
||||
ty::Ref(re, ..) if re.is_static(),
|
||||
),
|
||||
_ => false,
|
||||
@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(
|
||||
.type_dependent_def_id(arg.hir_id)
|
||||
.map_or(false, |method_id| {
|
||||
matches!(
|
||||
cx.tcx.fn_sig(method_id).subst_identity().output().skip_binder().kind(),
|
||||
cx.tcx.fn_sig(method_id).instantiate_identity().output().skip_binder().kind(),
|
||||
ty::Ref(re, ..) if re.is_static()
|
||||
)
|
||||
})
|
||||
|
@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, arg
|
||||
}
|
||||
let arg_ty = cx.typeck_results().expr_ty_adjusted(arg);
|
||||
let sig = match arg_ty.kind() {
|
||||
ty::Closure(_, substs) => substs.as_closure().sig(),
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ if arg_ty.is_fn() => arg_ty.fn_sig(cx.tcx),
|
||||
_ => return,
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_slice();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_slice();
|
||||
if let Some(_) = is_slice_of_primitives(cx, recv);
|
||||
if let hir::ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = arg.kind;
|
||||
then {
|
||||
|
@ -54,7 +54,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir
|
||||
.tcx
|
||||
.impl_of_method(method_def_id)
|
||||
.filter(|&impl_did| {
|
||||
cx.tcx.type_of(impl_did).subst_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()
|
||||
cx.tcx.type_of(impl_did).instantiate_identity().is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()
|
||||
})
|
||||
.is_some(),
|
||||
_ => false,
|
||||
|
@ -23,9 +23,9 @@ pub fn check(
|
||||
if args.is_empty() && method_name == sym::to_string;
|
||||
if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD);
|
||||
if let Some(substs) = cx.typeck_results().node_substs_opt(expr.hir_id);
|
||||
if let Some(args) = cx.typeck_results().node_args_opt(expr.hir_id);
|
||||
let arg_ty = cx.typeck_results().expr_ty_adjusted(receiver);
|
||||
let self_ty = substs.type_at(0);
|
||||
let self_ty = args.type_at(0);
|
||||
let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty);
|
||||
if deref_count >= 1;
|
||||
if specializes_tostring(cx, deref_self_ty);
|
||||
@ -64,8 +64,8 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let ty::Adt(adt, substs) = ty.kind() {
|
||||
cx.tcx.is_diagnostic_item(sym::Cow, adt.did()) && substs.type_at(1).is_str()
|
||||
if let ty::Adt(adt, args) = ty.kind() {
|
||||
cx.tcx.is_diagnostic_item(sym::Cow, adt.did()) && args.type_at(1).is_str()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Option);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Option);
|
||||
if let ExprKind::Call(err_path, [err_arg]) = or_expr.kind;
|
||||
if is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr);
|
||||
if is_ok_wrapping(cx, map_expr);
|
||||
|
@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id);
|
||||
if cx.tcx.impl_of_method(method_id)
|
||||
.map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id).subst_identity(), sym::Option))
|
||||
.map_or(false, |id| is_type_diagnostic_item(cx, cx.tcx.type_of(id).instantiate_identity(), sym::Option))
|
||||
|| is_diag_trait_item(cx, method_id, sym::Iterator);
|
||||
if let hir::ExprKind::Closure(&hir::Closure{ body, .. }) = arg.kind;
|
||||
then {
|
||||
|
@ -15,8 +15,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr
|
||||
let collect_ret_ty = cx.typeck_results().expr_ty(expr);
|
||||
if_chain! {
|
||||
if is_type_diagnostic_item(cx, collect_ret_ty, sym::Result);
|
||||
if let ty::Adt(_, substs) = collect_ret_ty.kind();
|
||||
if let Some(result_t) = substs.types().next();
|
||||
if let ty::Adt(_, args) = collect_ret_ty.kind();
|
||||
if let Some(result_t) = args.types().next();
|
||||
if result_t.is_unit();
|
||||
// get parts for snippet
|
||||
then {
|
||||
|
@ -9,7 +9,7 @@ use super::MAP_ERR_IGNORE;
|
||||
pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Result)
|
||||
&& is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Result)
|
||||
&& let ExprKind::Closure(&Closure {
|
||||
capture_clause: CaptureBy::Ref,
|
||||
body,
|
||||
|
@ -60,7 +60,7 @@ fn is_map_to_option(cx: &LateContext<'_>, map_arg: &Expr<'_>) -> bool {
|
||||
match map_closure_ty.kind() {
|
||||
ty::Closure(_, _) | ty::FnDef(_, _) | ty::FnPtr(_) => {
|
||||
let map_closure_sig = match map_closure_ty.kind() {
|
||||
ty::Closure(_, substs) => substs.as_closure().sig(),
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ => map_closure_ty.fn_sig(cx.tcx),
|
||||
};
|
||||
let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output());
|
||||
|
@ -3738,11 +3738,11 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||
let name = impl_item.ident.name.as_str();
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
|
||||
let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }));
|
||||
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind {
|
||||
let method_sig = cx.tcx.fn_sig(impl_item.owner_id).subst_identity();
|
||||
let method_sig = cx.tcx.fn_sig(impl_item.owner_id).instantiate_identity();
|
||||
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
|
||||
let first_arg_ty_opt = method_sig.inputs().iter().next().copied();
|
||||
// if this impl block implements a trait, lint in trait definition instead
|
||||
@ -4367,8 +4367,8 @@ impl SelfKind {
|
||||
} else if ty.is_box() {
|
||||
ty.boxed_ty() == parent_ty
|
||||
} else if is_type_diagnostic_item(cx, ty, sym::Rc) || is_type_diagnostic_item(cx, ty, sym::Arc) {
|
||||
if let ty::Adt(_, substs) = ty.kind() {
|
||||
substs.types().next().map_or(false, |t| t == parent_ty)
|
||||
if let ty::Adt(_, args) = ty.kind() {
|
||||
args.types().next().map_or(false, |t| t == parent_ty)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>, recv: &'
|
||||
if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind();
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(ex.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Mutex);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Mutex);
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -162,7 +162,7 @@ fn check_collect_into_intoiterator<'tcx>(
|
||||
// that contains `collect_expr`
|
||||
let inputs = cx
|
||||
.tcx
|
||||
.liberate_late_bound_regions(id, cx.tcx.fn_sig(id).subst_identity())
|
||||
.liberate_late_bound_regions(id, cx.tcx.fn_sig(id).instantiate_identity())
|
||||
.inputs();
|
||||
|
||||
// map IntoIterator generic bounds to their signature
|
||||
@ -200,7 +200,7 @@ fn check_collect_into_intoiterator<'tcx>(
|
||||
/// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool`
|
||||
fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool {
|
||||
cx.typeck_results().type_dependent_def_id(call_id).map_or(false, |id| {
|
||||
let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder();
|
||||
let sig = cx.tcx.fn_sig(id).instantiate_identity().skip_binder();
|
||||
sig.inputs().len() == 1 && sig.output().is_bool()
|
||||
})
|
||||
}
|
||||
@ -214,7 +214,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
|
||||
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty])
|
||||
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
|
||||
cx.param_env,
|
||||
Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.substs)
|
||||
Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.args)
|
||||
)
|
||||
{
|
||||
iter_item_ty == into_iter_item_ty
|
||||
@ -228,7 +228,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
|
||||
fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -> bool {
|
||||
let typeck = cx.typeck_results();
|
||||
if let Some(id) = typeck.type_dependent_def_id(call_id)
|
||||
&& let sig = cx.tcx.fn_sig(id).subst_identity()
|
||||
&& let sig = cx.tcx.fn_sig(id).instantiate_identity()
|
||||
&& sig.skip_binder().output().is_bool()
|
||||
&& let [_, search_ty] = *sig.skip_binder().inputs()
|
||||
&& let ty::Ref(_, search_ty, Mutability::Not) = *cx.tcx.erase_late_bound_regions(sig.rebind(search_ty)).kind()
|
||||
@ -236,11 +236,11 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
|
||||
&& let Some(iter_item) = cx.tcx
|
||||
.associated_items(iter_trait)
|
||||
.find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait)
|
||||
&& let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
|
||||
&& let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, substs)
|
||||
&& let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
|
||||
&& let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, args)
|
||||
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
|
||||
{
|
||||
item_ty == EarlyBinder::bind(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id))
|
||||
item_ty == EarlyBinder::bind(search_ty).instantiate(cx.tcx, cx.typeck_results().node_args(call_id))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
|
||||
/// Given a `Result<T, E>` type, return its error type (`E`).
|
||||
fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||
match ty.kind() {
|
||||
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().nth(1),
|
||||
ty::Adt(_, args) if is_type_diagnostic_item(cx, ty, sym::Result) => args.types().nth(1),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use super::NONSENSICAL_OPEN_OPTIONS;
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& match_type(cx, cx.tcx.type_of(impl_id).subst_identity(), &paths::OPEN_OPTIONS)
|
||||
&& match_type(cx, cx.tcx.type_of(impl_id).instantiate_identity(), &paths::OPEN_OPTIONS)
|
||||
{
|
||||
let mut options = Vec::new();
|
||||
get_open_options(cx, recv, &mut options);
|
||||
|
@ -52,12 +52,12 @@ pub(super) fn check<'tcx>(
|
||||
|
||||
let output_type_implements_default = |fun| {
|
||||
let fun_ty = cx.typeck_results().expr_ty(fun);
|
||||
if let ty::FnDef(def_id, substs) = fun_ty.kind() {
|
||||
let output_ty = cx.tcx.fn_sig(def_id).subst(cx.tcx, substs).skip_binder().output();
|
||||
if let ty::FnDef(def_id, args) = fun_ty.kind() {
|
||||
let output_ty = cx.tcx.fn_sig(def_id).instantiate(cx.tcx, args).skip_binder().output();
|
||||
cx.tcx
|
||||
.get_diagnostic_item(sym::Default)
|
||||
.map_or(false, |default_trait_id| {
|
||||
implements_trait(cx, output_ty, default_trait_id, substs)
|
||||
implements_trait(cx, output_ty, default_trait_id, args)
|
||||
})
|
||||
} else {
|
||||
false
|
||||
|
@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::PathBuf);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::PathBuf);
|
||||
if let ExprKind::Lit(lit) = arg.kind;
|
||||
if let LitKind::Str(ref path_lit, _) = lit.node;
|
||||
if let pushed_path = Path::new(path_lit.as_str());
|
||||
|
@ -35,8 +35,8 @@ pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<
|
||||
&& segment.ident.name == sym!(parse)
|
||||
&& let parse_result_ty = cx.typeck_results().expr_ty(parent)
|
||||
&& is_type_diagnostic_item(cx, parse_result_ty, sym::Result)
|
||||
&& let ty::Adt(_, substs) = parse_result_ty.kind()
|
||||
&& let Some(ok_ty) = substs[0].as_type()
|
||||
&& let ty::Adt(_, args) = parse_result_ty.kind()
|
||||
&& let Some(ok_ty) = args[0].as_type()
|
||||
&& parse_fails_on_trailing_newline(ok_ty)
|
||||
{
|
||||
let local_snippet = snippet(cx, expr.span, "<expr>");
|
||||
|
@ -10,7 +10,7 @@ use super::STABLE_SORT_PRIMITIVE;
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
|
||||
&& cx.tcx.type_of(impl_id).subst_identity().is_slice()
|
||||
&& cx.tcx.type_of(impl_id).instantiate_identity().is_slice()
|
||||
&& let Some(slice_type) = is_slice_of_primitives(cx, recv)
|
||||
{
|
||||
span_lint_and_then(
|
||||
|
@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
|
||||
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
|
||||
if cx.tcx.impl_trait_ref(impl_id).is_none();
|
||||
let self_ty = cx.tcx.type_of(impl_id).subst_identity();
|
||||
let self_ty = cx.tcx.type_of(impl_id).instantiate_identity();
|
||||
if self_ty.is_slice() || self_ty.is_str();
|
||||
then {
|
||||
// Ignore empty slice and string literals when used with a literal count.
|
||||
|
@ -24,9 +24,9 @@ pub(super) fn check(cx: &LateContext<'_>, receiver: &Expr<'_>, call_span: Span)
|
||||
|
||||
if let Some(Adjustment { target: recv_ty, .. }) = recv_adjusts.last()
|
||||
&& let ty::Ref(_, ty, _) = recv_ty.kind()
|
||||
&& let ty::Adt(adt, substs) = ty.kind()
|
||||
&& let ty::Adt(adt, args) = ty.kind()
|
||||
&& adt.is_box()
|
||||
&& is_dyn_any(cx, substs.type_at(0))
|
||||
&& is_dyn_any(cx, args.type_at(0))
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -6,8 +6,8 @@ use if_chain::if_chain;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Closure, Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::GenericArgKind;
|
||||
use rustc_span::sym;
|
||||
use rustc_span::symbol::Ident;
|
||||
use std::iter;
|
||||
@ -119,7 +119,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if cx.tcx.type_of(impl_id).subst_identity().is_slice();
|
||||
if cx.tcx.type_of(impl_id).instantiate_identity().is_slice();
|
||||
if let ExprKind::Closure(&Closure { body, .. }) = arg.kind;
|
||||
if let closure_body = cx.tcx.hir().body(body);
|
||||
if let &[
|
||||
|
@ -14,8 +14,10 @@ use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::Mutability;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{self, ClauseKind, EarlyBinder, ParamTy, ProjectionPredicate, TraitPredicate, Ty};
|
||||
use rustc_middle::ty::{
|
||||
self, ClauseKind, EarlyBinder, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate,
|
||||
TraitPredicate, Ty,
|
||||
};
|
||||
use rustc_span::{sym, Symbol};
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCause};
|
||||
@ -252,8 +254,8 @@ fn check_other_call_arg<'tcx>(
|
||||
) -> bool {
|
||||
if_chain! {
|
||||
if let Some((maybe_call, maybe_arg)) = skip_addr_of_ancestors(cx, expr);
|
||||
if let Some((callee_def_id, _, recv, call_args)) = get_callee_substs_and_args(cx, maybe_call);
|
||||
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
|
||||
if let Some((callee_def_id, _, recv, call_args)) = get_callee_generic_args_and_args(cx, maybe_call);
|
||||
let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder();
|
||||
if let Some(i) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == maybe_arg.hir_id);
|
||||
if let Some(input) = fn_sig.inputs().get(i);
|
||||
let (input, n_refs) = peel_mid_ty_refs(*input);
|
||||
@ -317,26 +319,31 @@ fn skip_addr_of_ancestors<'tcx>(
|
||||
}
|
||||
|
||||
/// Checks whether an expression is a function or method call and, if so, returns its `DefId`,
|
||||
/// `Substs`, and arguments.
|
||||
fn get_callee_substs_and_args<'tcx>(
|
||||
/// `GenericArgs`, and arguments.
|
||||
fn get_callee_generic_args_and_args<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
expr: &'tcx Expr<'tcx>,
|
||||
) -> Option<(DefId, SubstsRef<'tcx>, Option<&'tcx Expr<'tcx>>, &'tcx [Expr<'tcx>])> {
|
||||
) -> Option<(
|
||||
DefId,
|
||||
GenericArgsRef<'tcx>,
|
||||
Option<&'tcx Expr<'tcx>>,
|
||||
&'tcx [Expr<'tcx>],
|
||||
)> {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(callee, args) = expr.kind;
|
||||
let callee_ty = cx.typeck_results().expr_ty(callee);
|
||||
if let ty::FnDef(callee_def_id, _) = callee_ty.kind();
|
||||
then {
|
||||
let substs = cx.typeck_results().node_substs(callee.hir_id);
|
||||
return Some((*callee_def_id, substs, None, args));
|
||||
let generic_args = cx.typeck_results().node_args(callee.hir_id);
|
||||
return Some((*callee_def_id, generic_args, None, args));
|
||||
}
|
||||
}
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(_, recv, args, _) = expr.kind;
|
||||
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
then {
|
||||
let substs = cx.typeck_results().node_substs(expr.hir_id);
|
||||
return Some((method_def_id, substs, Some(recv), args));
|
||||
let generic_args = cx.typeck_results().node_args(expr.hir_id);
|
||||
return Some((method_def_id, generic_args, Some(recv), args));
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -390,17 +397,18 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||
}
|
||||
}
|
||||
Node::Expr(parent_expr) => {
|
||||
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
|
||||
if let Some((callee_def_id, call_generic_args, recv, call_args))
|
||||
= get_callee_generic_args_and_args(cx, parent_expr)
|
||||
{
|
||||
// FIXME: the `subst_identity()` below seems incorrect, since we eventually
|
||||
// FIXME: the `instantiate_identity()` below seems incorrect, since we eventually
|
||||
// call `tcx.try_subst_and_normalize_erasing_regions` further down
|
||||
// (i.e., we are explicitly not in the identity context).
|
||||
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
|
||||
let fn_sig = cx.tcx.fn_sig(callee_def_id).instantiate_identity().skip_binder();
|
||||
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
|
||||
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)
|
||||
&& let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind()
|
||||
// https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021
|
||||
&& (*param_index as usize) < call_substs.len()
|
||||
&& (*param_index as usize) < call_generic_args.len()
|
||||
{
|
||||
if fn_sig
|
||||
.inputs()
|
||||
@ -424,8 +432,8 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||
}
|
||||
});
|
||||
|
||||
let new_subst = cx.tcx.mk_substs_from_iter(
|
||||
call_substs.iter()
|
||||
let new_subst = cx.tcx.mk_args_from_iter(
|
||||
call_generic_args.iter()
|
||||
.enumerate()
|
||||
.map(|(i, t)|
|
||||
if i == (*param_index as usize) {
|
||||
@ -435,7 +443,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||
}));
|
||||
|
||||
if trait_predicates.any(|predicate| {
|
||||
let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, new_subst);
|
||||
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, new_subst);
|
||||
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
|
||||
!cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
|
||||
}) {
|
||||
@ -502,8 +510,8 @@ fn is_to_string_on_string_like<'a>(
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(substs) = cx.typeck_results().node_substs_opt(call_expr.hir_id)
|
||||
&& let [generic_arg] = substs.as_slice()
|
||||
if let Some(args) = cx.typeck_results().node_args_opt(call_expr.hir_id)
|
||||
&& let [generic_arg] = args.as_slice()
|
||||
&& let GenericArgKind::Type(ty) = generic_arg.unpack()
|
||||
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
|
||||
&& let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef)
|
||||
|
@ -143,7 +143,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for CloneOrCopyVisitor<'cx, 'tcx> {
|
||||
if_chain! {
|
||||
if args.iter().all(|arg| !self.is_binding(arg));
|
||||
if let Some(method_def_id) = self.cx.typeck_results().type_dependent_def_id(parent.hir_id);
|
||||
let method_ty = self.cx.tcx.type_of(method_def_id).subst_identity();
|
||||
let method_ty = self.cx.tcx.type_of(method_def_id).instantiate_identity();
|
||||
let self_ty = method_ty.fn_sig(self.cx.tcx).input(0).skip_binder();
|
||||
if matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Not));
|
||||
then {
|
||||
|
@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(
|
||||
if_chain! {
|
||||
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
|
||||
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::Vec);
|
||||
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).instantiate_identity(), sym::Vec);
|
||||
if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = count_arg.kind;
|
||||
if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = default_arg.kind;
|
||||
then {
|
||||
|
@ -139,7 +139,7 @@ impl MutableKeyType {
|
||||
}
|
||||
|
||||
fn check_sig(&self, cx: &LateContext<'_>, fn_def_id: LocalDefId, decl: &hir::FnDecl<'_>) {
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity();
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).instantiate_identity();
|
||||
for (hir_ty, ty) in iter::zip(decl.inputs, fn_sig.inputs().skip_binder()) {
|
||||
self.check_ty_(cx, hir_ty.span, *ty);
|
||||
}
|
||||
@ -150,7 +150,7 @@ impl MutableKeyType {
|
||||
// generics (because the compiler cannot ensure immutability for unknown types).
|
||||
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
||||
let ty = ty.peel_refs();
|
||||
if let Adt(def, substs) = ty.kind() {
|
||||
if let Adt(def, args) = ty.kind() {
|
||||
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
|
||||
.iter()
|
||||
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));
|
||||
@ -158,7 +158,7 @@ impl MutableKeyType {
|
||||
return;
|
||||
}
|
||||
|
||||
let subst_ty = substs.type_at(0);
|
||||
let subst_ty = args.type_at(0);
|
||||
// Determines if a type contains interior mutability which would affect its implementation of
|
||||
// [`Hash`] or [`Ord`].
|
||||
if is_interior_mut_ty(cx, subst_ty)
|
||||
|
@ -51,8 +51,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
|
||||
},
|
||||
ExprKind::MethodCall(path, receiver, arguments, _) => {
|
||||
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
|
||||
let substs = cx.typeck_results().node_substs(e.hir_id);
|
||||
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
|
||||
let args = cx.typeck_results().node_args(e.hir_id);
|
||||
let method_type = cx.tcx.type_of(def_id).instantiate(cx.tcx, args);
|
||||
check_arguments(
|
||||
cx,
|
||||
std::iter::once(receiver).chain(arguments.iter()).collect(),
|
||||
|
@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity();
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).instantiate_identity();
|
||||
let fn_sig = cx.tcx.liberate_late_bound_regions(fn_def_id.to_def_id(), fn_sig);
|
||||
|
||||
// If there are no `&mut` argument, no need to go any further.
|
||||
|
@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||
ctx
|
||||
};
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).subst_identity();
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id).instantiate_identity();
|
||||
let fn_sig = cx.tcx.liberate_late_bound_regions(fn_def_id.to_def_id(), fn_sig);
|
||||
|
||||
for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() {
|
||||
@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||
!preds.is_empty() && {
|
||||
let ty_empty_region = Ty::new_imm_ref(cx.tcx, cx.tcx.lifetimes.re_erased, ty);
|
||||
preds.iter().all(|t| {
|
||||
let ty_params = t.trait_ref.substs.iter().skip(1).collect::<Vec<_>>();
|
||||
let ty_params = t.trait_ref.args.iter().skip(1).collect::<Vec<_>>();
|
||||
implements_trait(cx, ty_empty_region, t.def_id(), &ty_params)
|
||||
})
|
||||
},
|
||||
|
@ -98,14 +98,14 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||
if name == sym::new;
|
||||
if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id);
|
||||
let self_def_id = cx.tcx.hir().get_parent_item(id.into());
|
||||
let self_ty = cx.tcx.type_of(self_def_id).subst_identity();
|
||||
let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity();
|
||||
if self_ty == return_ty(cx, id);
|
||||
if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default);
|
||||
then {
|
||||
if self.impling_types.is_none() {
|
||||
let mut impls = HirIdSet::default();
|
||||
cx.tcx.for_each_impl(default_trait_id, |d| {
|
||||
let ty = cx.tcx.type_of(d).subst_identity();
|
||||
let ty = cx.tcx.type_of(d).instantiate_identity();
|
||||
if let Some(ty_def) = ty.ty_adt_def() {
|
||||
if let Some(local_def_id) = ty_def.did().as_local() {
|
||||
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(local_def_id));
|
||||
@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
|
||||
// generics
|
||||
if_chain! {
|
||||
if let Some(ref impling_types) = self.impling_types;
|
||||
let self_def = cx.tcx.type_of(self_def_id).subst_identity();
|
||||
let self_def = cx.tcx.type_of(self_def_id).instantiate_identity();
|
||||
if let Some(self_def) = self_def.ty_adt_def();
|
||||
if let Some(self_local_did) = self_def.did().as_local();
|
||||
let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_local_did);
|
||||
|
@ -154,7 +154,7 @@ fn is_value_unfrozen_raw<'tcx>(
|
||||
ty::Adt(def, ..) if def.is_union() => false,
|
||||
ty::Array(ty, _) => val.unwrap_branch().iter().any(|field| inner(cx, *field, ty)),
|
||||
ty::Adt(def, _) if def.is_union() => false,
|
||||
ty::Adt(def, substs) if def.is_enum() => {
|
||||
ty::Adt(def, args) if def.is_enum() => {
|
||||
let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap();
|
||||
let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().try_to_u32().ok().unwrap());
|
||||
fields
|
||||
@ -164,19 +164,14 @@ fn is_value_unfrozen_raw<'tcx>(
|
||||
def.variants()[variant_index]
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| field.ty(cx.tcx, substs)),
|
||||
.map(|field| field.ty(cx.tcx, args)),
|
||||
)
|
||||
.any(|(field, ty)| inner(cx, field, ty))
|
||||
},
|
||||
ty::Adt(def, substs) => val
|
||||
ty::Adt(def, args) => val
|
||||
.unwrap_branch()
|
||||
.iter()
|
||||
.zip(
|
||||
def.non_enum_variant()
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| field.ty(cx.tcx, substs)),
|
||||
)
|
||||
.zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, args)))
|
||||
.any(|(field, ty)| inner(cx, *field, ty)),
|
||||
ty::Tuple(tys) => val
|
||||
.unwrap_branch()
|
||||
@ -217,8 +212,8 @@ fn is_value_unfrozen_raw<'tcx>(
|
||||
|
||||
fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<'tcx>) -> bool {
|
||||
let def_id = body_id.hir_id.owner.to_def_id();
|
||||
let substs = ty::InternalSubsts::identity_for_item(cx.tcx, def_id);
|
||||
let instance = ty::Instance::new(def_id, substs);
|
||||
let args = ty::GenericArgs::identity_for_item(cx.tcx, def_id);
|
||||
let instance = ty::Instance::new(def_id, args);
|
||||
let cid = rustc_middle::mir::interpret::GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
@ -229,9 +224,9 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<
|
||||
}
|
||||
|
||||
fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool {
|
||||
let substs = cx.typeck_results().node_substs(hir_id);
|
||||
let args = cx.typeck_results().node_args(hir_id);
|
||||
|
||||
let result = const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, substs), None);
|
||||
let result = const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), None);
|
||||
is_value_unfrozen_raw(cx, result, ty)
|
||||
}
|
||||
|
||||
@ -241,7 +236,7 @@ pub fn const_eval_resolve<'tcx>(
|
||||
ct: ty::UnevaluatedConst<'tcx>,
|
||||
span: Option<Span>,
|
||||
) -> EvalToValTreeResult<'tcx> {
|
||||
match ty::Instance::resolve(tcx, param_env, ct.def, ct.substs) {
|
||||
match ty::Instance::resolve(tcx, param_env, ct.def, ct.args) {
|
||||
Ok(Some(instance)) => {
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
@ -363,7 +358,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
|
||||
// and, in that case, the definition is *not* generic.
|
||||
cx.tcx.normalize_erasing_regions(
|
||||
cx.tcx.param_env(of_trait_def_id),
|
||||
cx.tcx.type_of(of_assoc_item).subst_identity(),
|
||||
cx.tcx.type_of(of_assoc_item).instantiate_identity(),
|
||||
),
|
||||
))
|
||||
.is_err();
|
||||
|
@ -7,8 +7,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{FieldDef, Item, ItemKind, Node};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::{self, GenericArgKind, Ty};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::sym;
|
||||
|
||||
@ -91,8 +90,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||
if send_trait == trait_id;
|
||||
if hir_impl.polarity == ImplPolarity::Positive;
|
||||
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
||||
if let self_ty = ty_trait_ref.subst_identity().self_ty();
|
||||
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
|
||||
if let self_ty = ty_trait_ref.instantiate_identity().self_ty();
|
||||
if let ty::Adt(adt_def, impl_trait_args) = self_ty.kind();
|
||||
then {
|
||||
let mut non_send_fields = Vec::new();
|
||||
|
||||
@ -105,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||
.as_local()
|
||||
.map(|local_def_id| hir_map.local_def_id_to_hir_id(local_def_id));
|
||||
if !is_lint_allowed(cx, NON_SEND_FIELDS_IN_SEND_TY, field_hir_id);
|
||||
if let field_ty = field.ty(cx.tcx, impl_trait_substs);
|
||||
if let field_ty = field.ty(cx.tcx, impl_trait_args);
|
||||
if !ty_allowed_in_send(cx, field_ty, send_trait);
|
||||
if let Node::Field(field_def) = hir_map.get(field_hir_id);
|
||||
then {
|
||||
@ -207,10 +206,10 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t
|
||||
.iter()
|
||||
.all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)),
|
||||
ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait),
|
||||
ty::Adt(_, substs) => {
|
||||
ty::Adt(_, args) => {
|
||||
if contains_pointer_like(cx, ty) {
|
||||
// descends only if ADT contains any raw pointers
|
||||
substs.iter().all(|generic_arg| match generic_arg.unpack() {
|
||||
args.iter().all(|generic_arg| match generic_arg.unpack() {
|
||||
GenericArgKind::Type(ty) => ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait),
|
||||
// Lifetimes and const generics are not solid part of ADT and ignored
|
||||
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => true,
|
||||
@ -225,7 +224,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the type contains any pointer-like types in substs (including nested ones)
|
||||
/// Checks if the type contains any pointer-like types in args (including nested ones)
|
||||
fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool {
|
||||
for ty_node in target_ty.walk() {
|
||||
if let GenericArgKind::Type(inner_ty) = ty_node.unpack() {
|
||||
|
@ -7,8 +7,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::hir_id::HirIdMap;
|
||||
use rustc_hir::{Body, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Node, PatKind, TraitItem, TraitItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::subst::{EarlyBinder, GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{self, ConstKind};
|
||||
use rustc_middle::ty::{self, ConstKind, EarlyBinder, GenericArgKind, GenericArgsRef};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::Span;
|
||||
@ -90,7 +89,7 @@ impl_lint_pass!(OnlyUsedInRecursion => [ONLY_USED_IN_RECURSION]);
|
||||
enum FnKind {
|
||||
Fn,
|
||||
TraitFn,
|
||||
// This is a hack. Ideally we would store a `SubstsRef<'tcx>` type here, but a lint pass must be `'static`.
|
||||
// This is a hack. Ideally we would store a `GenericArgsRef<'tcx>` type here, but a lint pass must be `'static`.
|
||||
// Substitutions are, however, interned. This allows us to store the pointer as a `usize` when comparing for
|
||||
// equality.
|
||||
ImplTraitFn(usize),
|
||||
@ -244,12 +243,12 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
})) => {
|
||||
#[allow(trivial_casts)]
|
||||
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
|
||||
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::subst_identity)
|
||||
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::instantiate_identity)
|
||||
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
|
||||
{
|
||||
(
|
||||
trait_item_id,
|
||||
FnKind::ImplTraitFn(cx.tcx.erase_regions(trait_ref.substs) as *const _ as usize),
|
||||
FnKind::ImplTraitFn(cx.tcx.erase_regions(trait_ref.args) as *const _ as usize),
|
||||
usize::from(sig.decl.implicit_self.has_implicit_self()),
|
||||
)
|
||||
} else {
|
||||
@ -289,7 +288,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
ExprKind::Call(callee, args)
|
||||
if path_def_id(cx, callee).map_or(false, |id| {
|
||||
id == param.fn_id
|
||||
&& has_matching_substs(param.fn_kind, typeck.node_substs(callee.hir_id))
|
||||
&& has_matching_args(param.fn_kind, typeck.node_args(callee.hir_id))
|
||||
}) =>
|
||||
{
|
||||
if let Some(idx) = args.iter().position(|arg| arg.hir_id == child_id) {
|
||||
@ -300,7 +299,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
ExprKind::MethodCall(_, receiver, args, _)
|
||||
if typeck.type_dependent_def_id(parent.hir_id).map_or(false, |id| {
|
||||
id == param.fn_id
|
||||
&& has_matching_substs(param.fn_kind, typeck.node_substs(parent.hir_id))
|
||||
&& has_matching_args(param.fn_kind, typeck.node_args(parent.hir_id))
|
||||
}) =>
|
||||
{
|
||||
if let Some(idx) = iter::once(receiver).chain(args).position(|arg| arg.hir_id == child_id) {
|
||||
@ -381,15 +380,15 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
}
|
||||
}
|
||||
|
||||
fn has_matching_substs(kind: FnKind, substs: SubstsRef<'_>) -> bool {
|
||||
fn has_matching_args(kind: FnKind, args: GenericArgsRef<'_>) -> bool {
|
||||
match kind {
|
||||
FnKind::Fn => true,
|
||||
FnKind::TraitFn => substs.iter().enumerate().all(|(idx, subst)| match subst.unpack() {
|
||||
FnKind::TraitFn => args.iter().enumerate().all(|(idx, subst)| match subst.unpack() {
|
||||
GenericArgKind::Lifetime(_) => true,
|
||||
GenericArgKind::Type(ty) => matches!(*ty.kind(), ty::Param(ty) if ty.index as usize == idx),
|
||||
GenericArgKind::Const(c) => matches!(c.kind(), ConstKind::Param(c) if c.index as usize == idx),
|
||||
}),
|
||||
#[allow(trivial_casts)]
|
||||
FnKind::ImplTraitFn(expected_substs) => substs as *const _ as usize == expected_substs,
|
||||
FnKind::ImplTraitFn(expected_args) => args as *const _ as usize == expected_args,
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ impl<'tcx> PassByRefOrValue {
|
||||
return;
|
||||
}
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(def_id).subst_identity();
|
||||
let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity();
|
||||
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));
|
||||
|
||||
// Gather all the lifetimes found in the output type which may affect whether
|
||||
|
@ -172,7 +172,11 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
||||
|
||||
for arg in check_fn_args(
|
||||
cx,
|
||||
cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder().inputs(),
|
||||
cx.tcx
|
||||
.fn_sig(item.owner_id)
|
||||
.instantiate_identity()
|
||||
.skip_binder()
|
||||
.inputs(),
|
||||
sig.decl.inputs,
|
||||
&sig.decl.output,
|
||||
&[],
|
||||
@ -232,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
||||
}
|
||||
|
||||
let decl = sig.decl;
|
||||
let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder();
|
||||
let sig = cx.tcx.fn_sig(item_id).instantiate_identity().skip_binder();
|
||||
let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, &decl.output, body.params)
|
||||
.filter(|arg| !is_trait_item || arg.mutability() == Mutability::Not)
|
||||
.collect();
|
||||
@ -436,7 +440,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
||||
.enumerate()
|
||||
.filter_map(move |(i, (ty, hir_ty))| {
|
||||
if let ty::Ref(_, ty, mutability) = *ty.kind()
|
||||
&& let ty::Adt(adt, substs) = *ty.kind()
|
||||
&& let ty::Adt(adt, args) = *ty.kind()
|
||||
&& let TyKind::Ref(lt, ref ty) = hir_ty.kind
|
||||
&& let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind
|
||||
// Check that the name as typed matches the actual name of the type.
|
||||
@ -456,7 +460,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
||||
} else {
|
||||
None
|
||||
}),
|
||||
substs.type_at(0),
|
||||
args.type_at(0),
|
||||
),
|
||||
),
|
||||
_ if Some(adt.did()) == cx.tcx.lang_items().string() => (
|
||||
@ -509,7 +513,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
||||
}
|
||||
|
||||
let ty_name =
|
||||
snippet_opt(cx, ty.span()).unwrap_or_else(|| substs.type_at(1).to_string());
|
||||
snippet_opt(cx, ty.span()).unwrap_or_else(|| args.type_at(1).to_string());
|
||||
|
||||
span_lint_hir_and_then(
|
||||
cx,
|
||||
@ -672,7 +676,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
|
||||
return;
|
||||
};
|
||||
|
||||
match *self.cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i]
|
||||
match *self.cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i]
|
||||
.peel_refs()
|
||||
.kind()
|
||||
{
|
||||
@ -738,7 +742,7 @@ fn matches_preds<'tcx>(
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) {
|
||||
ExistentialPredicate::Trait(p) => infcx
|
||||
.type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.substs.iter()), cx.param_env)
|
||||
.type_implements_trait(p.def_id, [ty.into()].into_iter().chain(p.args.iter()), cx.param_env)
|
||||
.must_apply_modulo_regions(),
|
||||
ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new(
|
||||
cx.tcx,
|
||||
|
@ -8,8 +8,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
|
||||
use rustc_lint::{LateContext, LateLintPass, Lint};
|
||||
use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc_middle::ty::subst::GenericArg;
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::{GenericArg, Ty};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
declare_clippy_lint! {
|
||||
@ -135,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||
} else if let Some(target_id) = cx.tcx.lang_items().deref_target() {
|
||||
if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions(
|
||||
cx.param_env,
|
||||
Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])),
|
||||
Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])),
|
||||
) {
|
||||
if deref_ty == expr_ty {
|
||||
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
|
||||
|
@ -11,8 +11,7 @@ use rustc_hir::{
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::{self, GenericArgKind, Ty};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::source_map::Span;
|
||||
@ -406,7 +405,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
|
||||
&& cx
|
||||
.tcx
|
||||
.fn_sig(def_id)
|
||||
.subst_identity()
|
||||
.instantiate_identity()
|
||||
.skip_binder()
|
||||
.output()
|
||||
.walk()
|
||||
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
|
||||
|
||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).subst_identity();
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
let ret_ty = return_ty(cx, impl_item.owner_id);
|
||||
|
||||
// Do not check trait impls
|
||||
|
@ -7,8 +7,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||
use rustc_hir::{self as hir};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{sym, Span, DUMMY_SP};
|
||||
|
@ -46,7 +46,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted:
|
||||
if let Some(def_id) = cx.qpath_res(count_func_qpath, count_func.hir_id).opt_def_id();
|
||||
if matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::mem_size_of | sym::mem_size_of_val));
|
||||
then {
|
||||
cx.typeck_results().node_substs(count_func.hir_id).types().next()
|
||||
cx.typeck_results().node_args(count_func.hir_id).types().next()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -100,7 +100,7 @@ fn get_pointee_ty_and_count_expr<'tcx>(
|
||||
if FUNCTIONS.iter().any(|func_path| match_def_path(cx, def_id, func_path));
|
||||
|
||||
// Get the pointee type
|
||||
if let Some(pointee_ty) = cx.typeck_results().node_substs(func.hir_id).types().next();
|
||||
if let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).types().next();
|
||||
then {
|
||||
return Some((pointee_ty, count));
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
|
||||
{
|
||||
// Don't lint. Byte strings produce `&[u8; N]` whereas `as_bytes()` produces
|
||||
// `&[u8]`. This change would prevent matching with different sized slices.
|
||||
} else {
|
||||
} else if !callsite.starts_with("env!") {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
STRING_LIT_AS_BYTES,
|
||||
|
@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::ty::is_c_void;
|
||||
use rustc_hir::Expr;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::{self, IntTy, SubstsRef, Ty, TypeAndMut, UintTy};
|
||||
use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, TypeAndMut, UintTy};
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
pub(super) fn check<'tcx>(
|
||||
@ -267,12 +267,12 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
|
||||
}
|
||||
ReducedTy::UnorderedFields(ty)
|
||||
},
|
||||
ty::Adt(def, substs) if def.is_struct() => {
|
||||
ty::Adt(def, args) if def.is_struct() => {
|
||||
let mut iter = def
|
||||
.non_enum_variant()
|
||||
.fields
|
||||
.iter()
|
||||
.map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs));
|
||||
.map(|f| cx.tcx.type_of(f.did).instantiate(cx.tcx, args));
|
||||
let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else {
|
||||
return ReducedTy::TypeErasure { raw_ptr_only: false };
|
||||
};
|
||||
@ -321,7 +321,7 @@ fn is_size_pair(ty: Ty<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> bool {
|
||||
fn same_except_params<'tcx>(subs1: GenericArgsRef<'tcx>, subs2: GenericArgsRef<'tcx>) -> bool {
|
||||
// TODO: check const parameters as well. Currently this will consider `Array<5>` the same as
|
||||
// `Array<6>`
|
||||
for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) {
|
||||
|
@ -10,7 +10,7 @@ use rustc_span::symbol::sym;
|
||||
/// Returns `true` if it's triggered, otherwise returns `false`.
|
||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
(ty::Adt(from_adt, from_substs), ty::Adt(to_adt, to_substs)) => {
|
||||
(ty::Adt(from_adt, from_args), ty::Adt(to_adt, to_args)) => {
|
||||
if from_adt.did() != to_adt.did() {
|
||||
return false;
|
||||
}
|
||||
@ -28,9 +28,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if from_substs
|
||||
if from_args
|
||||
.types()
|
||||
.zip(to_substs.types())
|
||||
.zip(to_args.types())
|
||||
.any(|(from_ty, to_ty)| is_layout_incompatible(cx, from_ty, to_ty))
|
||||
{
|
||||
span_lint(
|
||||
|
@ -88,7 +88,7 @@ fn handle_uninit_vec_pair<'tcx>(
|
||||
if let Some((set_len_self, call_span)) = extract_set_len_self(cx, maybe_set_len);
|
||||
if vec.location.eq_expr(cx, set_len_self);
|
||||
if let ty::Ref(_, vec_ty, _) = cx.typeck_results().expr_ty_adjusted(set_len_self).kind();
|
||||
if let ty::Adt(_, substs) = vec_ty.kind();
|
||||
if let ty::Adt(_, args) = vec_ty.kind();
|
||||
// `#[allow(...)]` attribute can be set on enclosing unsafe block of `set_len()`
|
||||
if !is_lint_allowed(cx, UNINIT_VEC, maybe_set_len.hir_id);
|
||||
then {
|
||||
@ -96,7 +96,7 @@ fn handle_uninit_vec_pair<'tcx>(
|
||||
// with_capacity / reserve -> set_len
|
||||
|
||||
// Check T of Vec<T>
|
||||
if !is_uninit_value_valid_for_ty(cx, substs.type_at(0)) {
|
||||
if !is_uninit_value_valid_for_ty(cx, args.type_at(0)) {
|
||||
// FIXME: #7698, false positive of the internal lints
|
||||
#[expect(clippy::collapsible_span_lint_calls)]
|
||||
span_lint_and_then(
|
||||
|
@ -65,7 +65,7 @@ fn get_projection_pred<'tcx>(
|
||||
generics.predicates.iter().find_map(|(proj_pred, _)| {
|
||||
if let ClauseKind::Projection(pred) = proj_pred.kind().skip_binder() {
|
||||
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred));
|
||||
if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs {
|
||||
if projection_pred.projection_ty.args == trait_pred.trait_ref.args {
|
||||
return Some(projection_pred);
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ fn get_projection_pred<'tcx>(
|
||||
fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> {
|
||||
let mut args_to_check = Vec::new();
|
||||
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
|
||||
let fn_sig = cx.tcx.fn_sig(def_id).subst_identity();
|
||||
let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity();
|
||||
let generics = cx.tcx.predicates_of(def_id);
|
||||
let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait());
|
||||
let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord));
|
||||
@ -120,8 +120,8 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
|
||||
fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option<Span>)> {
|
||||
if_chain! {
|
||||
if let ExprKind::Closure(&Closure { body, fn_decl_span, .. }) = arg.kind;
|
||||
if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind();
|
||||
let ret_ty = substs.as_closure().sig().output();
|
||||
if let ty::Closure(_def_id, args) = &cx.typeck_results().node_type(arg.hir_id).kind();
|
||||
let ret_ty = args.as_closure().sig().output();
|
||||
let ty = cx.tcx.erase_late_bound_regions(ret_ty);
|
||||
if ty.is_unit();
|
||||
then {
|
||||
|
@ -161,7 +161,7 @@ fn needs_inferred_result_ty(
|
||||
},
|
||||
_ => return false,
|
||||
};
|
||||
let sig = cx.tcx.fn_sig(id).subst_identity().skip_binder();
|
||||
let sig = cx.tcx.fn_sig(id).instantiate_identity().skip_binder();
|
||||
if let ty::Param(output_ty) = *sig.output().kind() {
|
||||
let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver {
|
||||
std::iter::once(receiver).chain(args.iter()).collect()
|
||||
|
@ -97,7 +97,7 @@ impl LateLintPass<'_> for UnnamedAddress {
|
||||
if let ExprKind::Path(ref func_qpath) = func.kind;
|
||||
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::PTR_EQ);
|
||||
let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0);
|
||||
let ty_param = cx.typeck_results().node_args(func.hir_id).type_at(0);
|
||||
if ty_param.is_trait();
|
||||
then {
|
||||
span_lint_and_help(
|
||||
|
@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
then {
|
||||
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
|
||||
// `Self`.
|
||||
let self_ty = impl_trait_ref.subst_identity().self_ty();
|
||||
let self_ty = impl_trait_ref.instantiate_identity().self_ty();
|
||||
|
||||
// `trait_method_sig` is the signature of the function, how it is declared in the
|
||||
// trait, not in the impl of the trait.
|
||||
@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
.associated_item(impl_item.owner_id)
|
||||
.trait_item_def_id
|
||||
.expect("impl method matches a trait method");
|
||||
let trait_method_sig = cx.tcx.fn_sig(trait_method).subst_identity();
|
||||
let trait_method_sig = cx.tcx.fn_sig(trait_method).instantiate_identity();
|
||||
let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig);
|
||||
|
||||
// `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the
|
||||
@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
} else {
|
||||
hir_ty_to_ty(cx.tcx, hir_ty)
|
||||
};
|
||||
if same_type_and_consts(ty, cx.tcx.type_of(impl_id).subst_identity());
|
||||
if same_type_and_consts(ty, cx.tcx.type_of(impl_id).instantiate_identity());
|
||||
then {
|
||||
span_lint(cx, hir_ty.span);
|
||||
}
|
||||
@ -237,7 +237,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
if !expr.span.from_expansion();
|
||||
if self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS);
|
||||
if let Some(&StackItem::Check { impl_id, .. }) = self.stack.last();
|
||||
if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).subst_identity();
|
||||
if cx.typeck_results().expr_ty(expr) == cx.tcx.type_of(impl_id).instantiate_identity();
|
||||
then {} else { return; }
|
||||
}
|
||||
match expr.kind {
|
||||
@ -261,7 +261,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||
if let PatKind::Path(QPath::Resolved(_, path))
|
||||
| PatKind::TupleStruct(QPath::Resolved(_, path), _, _)
|
||||
| PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind;
|
||||
if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).subst_identity();
|
||||
if cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).instantiate_identity();
|
||||
then {
|
||||
check_path(cx, path);
|
||||
}
|
||||
|
@ -226,8 +226,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(recv);
|
||||
if is_type_diagnostic_item(cx, a, sym::Result);
|
||||
if let ty::Adt(_, substs) = a.kind();
|
||||
if let Some(a_type) = substs.types().next();
|
||||
if let ty::Adt(_, args) = a.kind();
|
||||
if let Some(a_type) = args.types().next();
|
||||
if same_type_and_consts(a_type, b);
|
||||
|
||||
then {
|
||||
@ -254,8 +254,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||
if_chain! {
|
||||
if match_def_path(cx, def_id, &paths::TRY_FROM);
|
||||
if is_type_diagnostic_item(cx, a, sym::Result);
|
||||
if let ty::Adt(_, substs) = a.kind();
|
||||
if let Some(a_type) = substs.types().next();
|
||||
if let ty::Adt(_, args) = a.kind();
|
||||
if let Some(a_type) = args.types().next();
|
||||
if same_type_and_consts(a_type, b);
|
||||
|
||||
then {
|
||||
|
@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
|
||||
for item in cx.tcx.module_children(def_id) {
|
||||
if_chain! {
|
||||
if let Res::Def(DefKind::Const, item_def_id) = item.res;
|
||||
let ty = cx.tcx.type_of(item_def_id).subst_identity();
|
||||
let ty = cx.tcx.type_of(item_def_id).instantiate_identity();
|
||||
if match_type(cx, ty, &paths::SYMBOL);
|
||||
if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id);
|
||||
if let Ok(value) = value.to_u32();
|
||||
|
@ -74,10 +74,10 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
|
||||
let lang_items = cx.tcx.lang_items();
|
||||
// This list isn't complete, but good enough for our current list of paths.
|
||||
let incoherent_impls = [
|
||||
SimplifiedType::FloatSimplifiedType(FloatTy::F32),
|
||||
SimplifiedType::FloatSimplifiedType(FloatTy::F64),
|
||||
SimplifiedType::SliceSimplifiedType,
|
||||
SimplifiedType::StrSimplifiedType,
|
||||
SimplifiedType::Float(FloatTy::F32),
|
||||
SimplifiedType::Float(FloatTy::F64),
|
||||
SimplifiedType::Slice,
|
||||
SimplifiedType::Str,
|
||||
]
|
||||
.iter()
|
||||
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter().copied());
|
||||
|
@ -7,8 +7,7 @@ use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self};
|
||||
use rustc_middle::ty::{self, GenericArgKind};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
||||
declare_clippy_lint! {
|
||||
@ -40,7 +39,7 @@ impl LateLintPass<'_> for MsrvAttrImpl {
|
||||
if self_ty_def.all_fields().any(|f| {
|
||||
cx.tcx
|
||||
.type_of(f.did)
|
||||
.subst_identity()
|
||||
.instantiate_identity()
|
||||
.walk()
|
||||
.filter(|t| matches!(t.unpack(), GenericArgKind::Type(_)))
|
||||
.any(|t| match_type(cx, t.expect_ty(), &paths::MSRV))
|
||||
|
@ -229,11 +229,11 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve
|
||||
Res::Def(DefKind::Static(_), def_id) => read_mir_alloc_def_path(
|
||||
cx,
|
||||
cx.tcx.eval_static_initializer(def_id).ok()?.inner(),
|
||||
cx.tcx.type_of(def_id).subst_identity(),
|
||||
cx.tcx.type_of(def_id).instantiate_identity(),
|
||||
),
|
||||
Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? {
|
||||
ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => {
|
||||
read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).subst_identity())
|
||||
read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id).instantiate_identity())
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
|
@ -234,8 +234,8 @@ fn size_of(cx: &LateContext<'_>, expr: &Expr<'_>) -> u64 {
|
||||
|
||||
/// Returns the item type of the vector (i.e., the `T` in `Vec<T>`).
|
||||
fn vec_type(ty: Ty<'_>) -> Ty<'_> {
|
||||
if let ty::Adt(_, substs) = ty.kind() {
|
||||
substs.type_at(0)
|
||||
if let ty::Adt(_, args) = ty.kind() {
|
||||
args.type_at(0)
|
||||
} else {
|
||||
panic!("The type of `vec!` is a not a struct?");
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
|
||||
if !in_trait_impl(cx, hir_ty.hir_id);
|
||||
let ty = ty_from_hir_ty(cx, hir_ty);
|
||||
if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap);
|
||||
if let Adt(_, substs) = ty.kind();
|
||||
let ty = substs.type_at(1);
|
||||
if let Adt(_, args) = ty.kind();
|
||||
let ty = args.type_at(1);
|
||||
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
|
||||
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
|
||||
if !ty.has_escaping_bound_vars();
|
||||
|
@ -10,7 +10,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item
|
||||
use rustc_lexer::tokenize;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::ty::{self, EarlyBinder, FloatTy, List, ScalarInt, SubstsRef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, EarlyBinder, FloatTy, GenericArgsRef, List, ScalarInt, Ty, TyCtxt};
|
||||
use rustc_middle::{bug, mir, span_bug};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::SyntaxContext;
|
||||
@ -325,7 +325,7 @@ pub struct ConstEvalLateContext<'a, 'tcx> {
|
||||
typeck_results: &'a ty::TypeckResults<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
source: ConstantSource,
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
@ -335,7 +335,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
typeck_results,
|
||||
param_env: lcx.param_env,
|
||||
source: ConstantSource::Local,
|
||||
substs: List::empty(),
|
||||
args: List::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,16 +471,16 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let substs = self.typeck_results.node_substs(id);
|
||||
let substs = if self.substs.is_empty() {
|
||||
substs
|
||||
let args = self.typeck_results.node_args(id);
|
||||
let args = if self.args.is_empty() {
|
||||
args
|
||||
} else {
|
||||
EarlyBinder::bind(substs).subst(self.lcx.tcx, self.substs)
|
||||
EarlyBinder::bind(args).instantiate(self.lcx.tcx, self.args)
|
||||
};
|
||||
let result = self
|
||||
.lcx
|
||||
.tcx
|
||||
.const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, substs), None)
|
||||
.const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), None)
|
||||
.ok()
|
||||
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?;
|
||||
let result = miri_to_const(self.lcx, result)?;
|
||||
|
@ -51,7 +51,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg:
|
||||
let name = name.as_str();
|
||||
|
||||
let ty = match cx.tcx.impl_of_method(fn_id) {
|
||||
Some(id) => cx.tcx.type_of(id).subst_identity(),
|
||||
Some(id) => cx.tcx.type_of(id).instantiate_identity(),
|
||||
None => return Lazy,
|
||||
};
|
||||
|
||||
@ -68,19 +68,24 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg:
|
||||
// Types where the only fields are generic types (or references to) with no trait bounds other
|
||||
// than marker traits.
|
||||
// Due to the limited operations on these types functions should be fairly cheap.
|
||||
if def
|
||||
.variants()
|
||||
.iter()
|
||||
.flat_map(|v| v.fields.iter())
|
||||
.any(|x| matches!(cx.tcx.type_of(x.did).subst_identity().peel_refs().kind(), ty::Param(_)))
|
||||
&& all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::ClauseKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
|
||||
_ => true,
|
||||
})
|
||||
&& subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_)))
|
||||
if def.variants().iter().flat_map(|v| v.fields.iter()).any(|x| {
|
||||
matches!(
|
||||
cx.tcx.type_of(x.did).instantiate_identity().peel_refs().kind(),
|
||||
ty::Param(_)
|
||||
)
|
||||
}) && all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::ClauseKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
|
||||
_ => true,
|
||||
}) && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_)))
|
||||
{
|
||||
// Limit the function to either `(self) -> bool` or `(&self) -> bool`
|
||||
match &**cx.tcx.fn_sig(fn_id).subst_identity().skip_binder().inputs_and_output {
|
||||
match &**cx
|
||||
.tcx
|
||||
.fn_sig(fn_id)
|
||||
.instantiate_identity()
|
||||
.skip_binder()
|
||||
.inputs_and_output
|
||||
{
|
||||
[arg, res] if !arg.is_mutable_ptr() && arg.peel_refs() == ty && res.is_bool() => NoChange,
|
||||
_ => Lazy,
|
||||
}
|
||||
|
@ -99,10 +99,7 @@ use rustc_middle::hir::place::PlaceBase;
|
||||
use rustc_middle::mir::ConstantKind;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||
use rustc_middle::ty::binding::BindingMode;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType::{
|
||||
ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType,
|
||||
PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType,
|
||||
};
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
use rustc_middle::ty::{
|
||||
self as rustc_ty, Binder, BorrowKind, ClosureKind, FloatTy, IntTy, ParamEnv, ParamEnvAnd, Ty, TyCtxt, TypeAndMut,
|
||||
@ -306,7 +303,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str])
|
||||
/// Checks if a method is defined in an impl of a diagnostic item
|
||||
pub fn is_diag_item_method(cx: &LateContext<'_>, def_id: DefId, diag_item: Symbol) -> bool {
|
||||
if let Some(impl_did) = cx.tcx.impl_of_method(def_id) {
|
||||
if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() {
|
||||
if let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def() {
|
||||
return cx.tcx.is_diagnostic_item(diag_item, adt.did());
|
||||
}
|
||||
}
|
||||
@ -515,30 +512,30 @@ pub fn path_def_id<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx>
|
||||
|
||||
fn find_primitive_impls<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
let ty = match name {
|
||||
"bool" => BoolSimplifiedType,
|
||||
"char" => CharSimplifiedType,
|
||||
"str" => StrSimplifiedType,
|
||||
"array" => ArraySimplifiedType,
|
||||
"slice" => SliceSimplifiedType,
|
||||
"bool" => SimplifiedType::Bool,
|
||||
"char" => SimplifiedType::Char,
|
||||
"str" => SimplifiedType::Str,
|
||||
"array" => SimplifiedType::Array,
|
||||
"slice" => SimplifiedType::Slice,
|
||||
// FIXME: rustdoc documents these two using just `pointer`.
|
||||
//
|
||||
// Maybe this is something we should do here too.
|
||||
"const_ptr" => PtrSimplifiedType(Mutability::Not),
|
||||
"mut_ptr" => PtrSimplifiedType(Mutability::Mut),
|
||||
"isize" => IntSimplifiedType(IntTy::Isize),
|
||||
"i8" => IntSimplifiedType(IntTy::I8),
|
||||
"i16" => IntSimplifiedType(IntTy::I16),
|
||||
"i32" => IntSimplifiedType(IntTy::I32),
|
||||
"i64" => IntSimplifiedType(IntTy::I64),
|
||||
"i128" => IntSimplifiedType(IntTy::I128),
|
||||
"usize" => UintSimplifiedType(UintTy::Usize),
|
||||
"u8" => UintSimplifiedType(UintTy::U8),
|
||||
"u16" => UintSimplifiedType(UintTy::U16),
|
||||
"u32" => UintSimplifiedType(UintTy::U32),
|
||||
"u64" => UintSimplifiedType(UintTy::U64),
|
||||
"u128" => UintSimplifiedType(UintTy::U128),
|
||||
"f32" => FloatSimplifiedType(FloatTy::F32),
|
||||
"f64" => FloatSimplifiedType(FloatTy::F64),
|
||||
"const_ptr" => SimplifiedType::Ptr(Mutability::Not),
|
||||
"mut_ptr" => SimplifiedType::Ptr(Mutability::Mut),
|
||||
"isize" => SimplifiedType::Int(IntTy::Isize),
|
||||
"i8" => SimplifiedType::Int(IntTy::I8),
|
||||
"i16" => SimplifiedType::Int(IntTy::I16),
|
||||
"i32" => SimplifiedType::Int(IntTy::I32),
|
||||
"i64" => SimplifiedType::Int(IntTy::I64),
|
||||
"i128" => SimplifiedType::Int(IntTy::I128),
|
||||
"usize" => SimplifiedType::Uint(UintTy::Usize),
|
||||
"u8" => SimplifiedType::Uint(UintTy::U8),
|
||||
"u16" => SimplifiedType::Uint(UintTy::U16),
|
||||
"u32" => SimplifiedType::Uint(UintTy::U32),
|
||||
"u64" => SimplifiedType::Uint(UintTy::U64),
|
||||
"u128" => SimplifiedType::Uint(UintTy::U128),
|
||||
"f32" => SimplifiedType::Float(FloatTy::F32),
|
||||
"f64" => SimplifiedType::Float(FloatTy::F64),
|
||||
_ => return [].iter().copied(),
|
||||
};
|
||||
|
||||
@ -813,7 +810,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<
|
||||
if let QPath::TypeRelative(_, method) = path {
|
||||
if method.ident.name == sym::new {
|
||||
if let Some(impl_did) = cx.tcx.impl_of_method(def_id) {
|
||||
if let Some(adt) = cx.tcx.type_of(impl_did).subst_identity().ty_adt_def() {
|
||||
if let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def() {
|
||||
return std_types_symbols.iter().any(|&symbol| {
|
||||
cx.tcx.is_diagnostic_item(symbol, adt.did()) || Some(adt.did()) == cx.tcx.lang_items().string()
|
||||
});
|
||||
@ -1378,7 +1375,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
|
||||
.chain(args.iter())
|
||||
.position(|arg| arg.hir_id == id)?;
|
||||
let id = cx.typeck_results().type_dependent_def_id(e.hir_id)?;
|
||||
let ty = cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i];
|
||||
let ty = cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i];
|
||||
ty_is_fn_once_param(cx.tcx, ty, cx.tcx.param_env(id).caller_bounds()).then_some(())
|
||||
},
|
||||
_ => None,
|
||||
@ -1640,13 +1637,13 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
||||
|
||||
/// Convenience function to get the return type of a function.
|
||||
pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'tcx> {
|
||||
let ret_ty = cx.tcx.fn_sig(fn_def_id).subst_identity().output();
|
||||
let ret_ty = cx.tcx.fn_sig(fn_def_id).instantiate_identity().output();
|
||||
cx.tcx.erase_late_bound_regions(ret_ty)
|
||||
}
|
||||
|
||||
/// Convenience function to get the nth argument type of a function.
|
||||
pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> {
|
||||
let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth);
|
||||
let arg = cx.tcx.fn_sig(fn_def_id).instantiate_identity().input(nth);
|
||||
cx.tcx.erase_late_bound_regions(arg)
|
||||
}
|
||||
|
||||
@ -2573,7 +2570,8 @@ impl<'tcx> ExprUseNode<'tcx> {
|
||||
match *self {
|
||||
Self::Local(Local { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)),
|
||||
Self::ConstStatic(id) => Some(DefinedTy::Mir(
|
||||
cx.param_env.and(Binder::dummy(cx.tcx.type_of(id).subst_identity())),
|
||||
cx.param_env
|
||||
.and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())),
|
||||
)),
|
||||
Self::Return(id) => {
|
||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(id.def_id);
|
||||
@ -2588,7 +2586,7 @@ impl<'tcx> ExprUseNode<'tcx> {
|
||||
}
|
||||
} else {
|
||||
Some(DefinedTy::Mir(
|
||||
cx.param_env.and(cx.tcx.fn_sig(id).subst_identity().output()),
|
||||
cx.param_env.and(cx.tcx.fn_sig(id).instantiate_identity().output()),
|
||||
))
|
||||
}
|
||||
},
|
||||
@ -2609,7 +2607,7 @@ impl<'tcx> ExprUseNode<'tcx> {
|
||||
DefinedTy::Mir(
|
||||
cx.tcx
|
||||
.param_env(adt.did())
|
||||
.and(Binder::dummy(cx.tcx.type_of(field_def.did).subst_identity())),
|
||||
.and(Binder::dummy(cx.tcx.type_of(field_def.did).instantiate_identity())),
|
||||
)
|
||||
}),
|
||||
_ => None,
|
||||
|
@ -14,10 +14,9 @@ use rustc_middle::mir::{
|
||||
Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind,
|
||||
Terminator, TerminatorKind,
|
||||
};
|
||||
use rustc_middle::traits::{ImplSource, ObligationCause};
|
||||
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
|
||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, BoundConstness, TraitRef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, BoundConstness, GenericArgKind, TraitRef, Ty, TyCtxt};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
@ -35,7 +34,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
|
||||
// impl trait is gone in MIR, so check the return type manually
|
||||
check_ty(
|
||||
tcx,
|
||||
tcx.fn_sig(def_id).subst_identity().output().skip_binder(),
|
||||
tcx.fn_sig(def_id).instantiate_identity().output().skip_binder(),
|
||||
body.local_decls.iter().next().unwrap().source_info.span,
|
||||
)?;
|
||||
|
||||
@ -412,7 +411,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
|
||||
|
||||
if !matches!(
|
||||
impl_src,
|
||||
ImplSource::Builtin(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -877,7 +877,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> {
|
||||
.cx
|
||||
.typeck_results()
|
||||
.type_dependent_def_id(parent_expr.hir_id)
|
||||
.map(|did| self.cx.tcx.fn_sig(did).subst_identity().skip_binder())
|
||||
.map(|did| self.cx.tcx.fn_sig(did).instantiate_identity().skip_binder())
|
||||
{
|
||||
std::iter::once(receiver)
|
||||
.chain(call_args.iter())
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user