Skip to content

Commit 3157e1f

Browse files
authored
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.
2 parents 8d9f258 + 215decd commit 3157e1f

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
1212

1313
use super::UNNECESSARY_CAST;
1414

15-
pub(super) fn check(
16-
cx: &LateContext<'_>,
17-
expr: &Expr<'_>,
18-
cast_expr: &Expr<'_>,
19-
cast_from: Ty<'_>,
20-
cast_to: Ty<'_>,
15+
pub(super) fn check<'tcx>(
16+
cx: &LateContext<'tcx>,
17+
expr: &Expr<'tcx>,
18+
cast_expr: &Expr<'tcx>,
19+
cast_from: Ty<'tcx>,
20+
cast_to: Ty<'tcx>,
2121
) -> bool {
2222
// skip non-primitive type cast
2323
if_chain! {

src/tools/clippy/clippy_lints/src/dereference.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ fn try_parse_ref_op<'tcx>(
446446

447447
// Checks whether the type for a deref call actually changed the type, not just the mutability of
448448
// the reference.
449-
fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool {
449+
fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
450450
match (result_ty.kind(), arg_ty.kind()) {
451451
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty,
452452

@@ -541,8 +541,8 @@ fn is_auto_borrow_position(parent: Option<Node<'_>>, child_id: HirId) -> bool {
541541
/// Adjustments are sometimes made in the parent block rather than the expression itself.
542542
fn find_adjustments<'tcx>(
543543
tcx: TyCtxt<'tcx>,
544-
typeck: &'tcx TypeckResults<'_>,
545-
expr: &'tcx Expr<'_>,
544+
typeck: &'tcx TypeckResults<'tcx>,
545+
expr: &'tcx Expr<'tcx>,
546546
) -> &'tcx [Adjustment<'tcx>] {
547547
let map = tcx.hir();
548548
let mut iter = map.parent_iter(expr.hir_id);
@@ -581,7 +581,7 @@ fn find_adjustments<'tcx>(
581581
}
582582

583583
#[expect(clippy::needless_pass_by_value)]
584-
fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) {
584+
fn report<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, state: State, data: StateData) {
585585
match state {
586586
State::DerefMethod {
587587
ty_changed_count,
@@ -656,7 +656,7 @@ fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData)
656656
}
657657

658658
impl Dereferencing {
659-
fn check_local_usage(&mut self, cx: &LateContext<'_>, e: &Expr<'_>, local: HirId) {
659+
fn check_local_usage<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) {
660660
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
661661
if let Some(pat) = outer_pat {
662662
// Check for auto-deref

src/tools/clippy/clippy_lints/src/len_zero.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenO
259259
}
260260
}
261261

262-
impl LenOutput<'_> {
263-
fn matches_is_empty_output(self, ty: Ty<'_>) -> bool {
262+
impl<'tcx> LenOutput<'tcx> {
263+
fn matches_is_empty_output(self, ty: Ty<'tcx>) -> bool {
264264
match (self, ty.kind()) {
265265
(_, &ty::Bool) => true,
266266
(Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(),
@@ -292,7 +292,7 @@ impl LenOutput<'_> {
292292
}
293293

294294
/// Checks if the given signature matches the expectations for `is_empty`
295-
fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool {
295+
fn check_is_empty_sig<'tcx>(sig: FnSig<'tcx>, self_kind: ImplicitSelfKind, len_output: LenOutput<'tcx>) -> bool {
296296
match &**sig.inputs_and_output {
297297
[arg, res] if len_output.matches_is_empty_output(*res) => {
298298
matches!(
@@ -306,11 +306,11 @@ fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: L
306306
}
307307

308308
/// Checks if the given type has an `is_empty` method with the appropriate signature.
309-
fn check_for_is_empty(
310-
cx: &LateContext<'_>,
309+
fn check_for_is_empty<'tcx>(
310+
cx: &LateContext<'tcx>,
311311
span: Span,
312312
self_kind: ImplicitSelfKind,
313-
output: LenOutput<'_>,
313+
output: LenOutput<'tcx>,
314314
impl_ty: DefId,
315315
item_name: Symbol,
316316
item_kind: &str,

src/tools/clippy/clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ enum SelfKind {
28432843

28442844
impl SelfKind {
28452845
fn matches<'a>(self, cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool {
2846-
fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'_>, ty: Ty<'_>) -> bool {
2846+
fn matches_value<'a>(cx: &LateContext<'a>, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool {
28472847
if ty == parent_ty {
28482848
true
28492849
} else if ty.is_box() {

src/tools/clippy/clippy_lints/src/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ impl<'tcx> DerefTy<'tcx> {
395395

396396
fn check_fn_args<'cx, 'tcx: 'cx>(
397397
cx: &'cx LateContext<'tcx>,
398-
tys: &'tcx [Ty<'_>],
399-
hir_tys: &'tcx [hir::Ty<'_>],
400-
params: &'tcx [Param<'_>],
398+
tys: &'tcx [Ty<'tcx>],
399+
hir_tys: &'tcx [hir::Ty<'tcx>],
400+
params: &'tcx [Param<'tcx>],
401401
) -> impl Iterator<Item = PtrArg<'tcx>> + 'cx {
402402
tys.iter()
403403
.zip(hir_tys.iter())

src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn is_size_pair(ty: Ty<'_>) -> bool {
358358
}
359359
}
360360

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

src/tools/clippy/clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool
4242
}
4343

4444
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
45-
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
45+
pub fn contains_ty<'tcx>(ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
4646
ty.walk().any(|inner| match inner.unpack() {
4747
GenericArgKind::Type(inner_ty) => other_ty == inner_ty,
4848
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
@@ -51,7 +51,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
5151

5252
/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
5353
/// constructor.
54-
pub fn contains_adt_constructor(ty: Ty<'_>, adt: AdtDef<'_>) -> bool {
54+
pub fn contains_adt_constructor<'tcx>(ty: Ty<'tcx>, adt: AdtDef<'tcx>) -> bool {
5555
ty.walk().any(|inner| match inner.unpack() {
5656
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
5757
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,

0 commit comments

Comments
 (0)