Rollup merge of #97289 - compiler-errors:tcxify-clippy, r=Mark-Simulacrum

Lifetime variance fixes for clippy

#97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be shortened to some common lifetime.

This is doable, since everything is already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`.

Split out from #97287 so the clippy team can review independently.
This commit is contained in:
Yuki Okushi 2022-05-24 12:18:31 +09:00 committed by GitHub
commit 3157e1f4bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 24 deletions

View file

@ -12,12 +12,12 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
use super::UNNECESSARY_CAST; use super::UNNECESSARY_CAST;
pub(super) fn check( pub(super) fn check<'tcx>(
cx: &LateContext<'_>, cx: &LateContext<'tcx>,
expr: &Expr<'_>, expr: &Expr<'tcx>,
cast_expr: &Expr<'_>, cast_expr: &Expr<'tcx>,
cast_from: Ty<'_>, cast_from: Ty<'tcx>,
cast_to: Ty<'_>, cast_to: Ty<'tcx>,
) -> bool { ) -> bool {
// skip non-primitive type cast // skip non-primitive type cast
if_chain! { if_chain! {

View file

@ -446,7 +446,7 @@ fn try_parse_ref_op<'tcx>(
// Checks whether the type for a deref call actually changed the type, not just the mutability of // Checks whether the type for a deref call actually changed the type, not just the mutability of
// the reference. // the reference.
fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool { fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
match (result_ty.kind(), arg_ty.kind()) { match (result_ty.kind(), arg_ty.kind()) {
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty, (ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty,
@ -541,8 +541,8 @@ fn is_auto_borrow_position(parent: Option<Node<'_>>, child_id: HirId) -> bool {
/// Adjustments are sometimes made in the parent block rather than the expression itself. /// Adjustments are sometimes made in the parent block rather than the expression itself.
fn find_adjustments<'tcx>( fn find_adjustments<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
typeck: &'tcx TypeckResults<'_>, typeck: &'tcx TypeckResults<'tcx>,
expr: &'tcx Expr<'_>, expr: &'tcx Expr<'tcx>,
) -> &'tcx [Adjustment<'tcx>] { ) -> &'tcx [Adjustment<'tcx>] {
let map = tcx.hir(); let map = tcx.hir();
let mut iter = map.parent_iter(expr.hir_id); let mut iter = map.parent_iter(expr.hir_id);
@ -581,7 +581,7 @@ fn find_adjustments<'tcx>(
} }
#[expect(clippy::needless_pass_by_value)] #[expect(clippy::needless_pass_by_value)]
fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) { fn report<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, state: State, data: StateData) {
match state { match state {
State::DerefMethod { State::DerefMethod {
ty_changed_count, ty_changed_count,
@ -656,7 +656,7 @@ fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData)
} }
impl Dereferencing { impl Dereferencing {
fn check_local_usage(&mut self, cx: &LateContext<'_>, e: &Expr<'_>, local: HirId) { fn check_local_usage<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) {
if let Some(outer_pat) = self.ref_locals.get_mut(&local) { if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
if let Some(pat) = outer_pat { if let Some(pat) = outer_pat {
// Check for auto-deref // Check for auto-deref

View file

@ -259,8 +259,8 @@ fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenO
} }
} }
impl LenOutput<'_> { impl<'tcx> LenOutput<'tcx> {
fn matches_is_empty_output(self, ty: Ty<'_>) -> bool { fn matches_is_empty_output(self, ty: Ty<'tcx>) -> bool {
match (self, ty.kind()) { match (self, ty.kind()) {
(_, &ty::Bool) => true, (_, &ty::Bool) => true,
(Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(),
@ -292,7 +292,7 @@ impl LenOutput<'_> {
} }
/// Checks if the given signature matches the expectations for `is_empty` /// Checks if the given signature matches the expectations for `is_empty`
fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool { fn check_is_empty_sig<'tcx>(sig: FnSig<'tcx>, self_kind: ImplicitSelfKind, len_output: LenOutput<'tcx>) -> bool {
match &**sig.inputs_and_output { match &**sig.inputs_and_output {
[arg, res] if len_output.matches_is_empty_output(*res) => { [arg, res] if len_output.matches_is_empty_output(*res) => {
matches!( matches!(
@ -306,11 +306,11 @@ fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: L
} }
/// Checks if the given type has an `is_empty` method with the appropriate signature. /// Checks if the given type has an `is_empty` method with the appropriate signature.
fn check_for_is_empty( fn check_for_is_empty<'tcx>(
cx: &LateContext<'_>, cx: &LateContext<'tcx>,
span: Span, span: Span,
self_kind: ImplicitSelfKind, self_kind: ImplicitSelfKind,
output: LenOutput<'_>, output: LenOutput<'tcx>,
impl_ty: DefId, impl_ty: DefId,
item_name: Symbol, item_name: Symbol,
item_kind: &str, item_kind: &str,

View file

@ -2843,7 +2843,7 @@ enum SelfKind {
impl SelfKind { impl SelfKind {
fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool {
fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool { fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool {
if ty == parent_ty { if ty == parent_ty {
true true
} else if ty.is_box() { } else if ty.is_box() {

View file

@ -395,9 +395,9 @@ impl<'tcx> DerefTy<'tcx> {
fn check_fn_args<'cx, 'tcx: 'cx>( fn check_fn_args<'cx, 'tcx: 'cx>(
cx: &'cx LateContext<'tcx>, cx: &'cx LateContext<'tcx>,
tys: &'tcx [Ty<'_>], tys: &'tcx [Ty<'tcx>],
hir_tys: &'tcx [hir::Ty<'_>], hir_tys: &'tcx [hir::Ty<'tcx>],
params: &'tcx [Param<'_>], params: &'tcx [Param<'tcx>],
) -> impl Iterator<Item = PtrArg<'tcx>> + 'cx { ) -> impl Iterator<Item = PtrArg<'tcx>> + 'cx {
tys.iter() tys.iter()
.zip(hir_tys.iter()) .zip(hir_tys.iter())

View file

@ -358,7 +358,7 @@ fn is_size_pair(ty: Ty<'_>) -> bool {
} }
} }
fn same_except_params(subs1: SubstsRef<'_>, subs2: SubstsRef<'_>) -> bool { fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> bool {
// TODO: check const parameters as well. Currently this will consider `Array<5>` the same as // TODO: check const parameters as well. Currently this will consider `Array<5>` the same as
// `Array<6>` // `Array<6>`
for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) { for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) {

View file

@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool
} }
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { pub fn contains_ty<'tcx>(ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
ty.walk().any(|inner| match inner.unpack() { ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => other_ty == inner_ty, GenericArgKind::Type(inner_ty) => other_ty == inner_ty,
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
@ -51,7 +51,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
/// constructor. /// constructor.
pub fn contains_adt_constructor(ty: Ty<'_>, adt: AdtDef<'_>) -> bool { pub fn contains_adt_constructor<'tcx>(ty: Ty<'tcx>, adt: AdtDef<'tcx>) -> bool {
ty.walk().any(|inner| match inner.unpack() { ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,