Skip to content

Commit 833cbd6

Browse files
committed
Auto merge of #120100 - oli-obk:astconv_lifetimes, r=BoxyUwU
Don't forget that the lifetime on hir types is `'tcx` This PR just tracks the `'tcx` lifetime to wherever the original objects actually have that lifetime. This code is needed for rust-lang/rust#107606 (now #120131) so that `ast_ty_to_ty` can invoke `lit_to_const` on an argument passed to it. Currently the argument is `&hir::Ty<'_>`, but after this PR it is `&'tcx hir::Ty<'tcx>`.
2 parents 8b0931a + 7a1e7d7 commit 833cbd6

9 files changed

+23
-23
lines changed

clippy_lints/src/default_union_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
7575
/// (ZST fields having an arbitrary offset is completely inconsequential, and
7676
/// if there is only one field left after ignoring ZST fields then the offset
7777
/// of that field does not matter either.)
78-
fn is_union_with_two_non_zst_fields(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
78+
fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
7979
if let ItemKind::Union(..) = &item.kind
8080
&& let ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
8181
{

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ enum ImplicitHasherType<'tcx> {
210210

211211
impl<'tcx> ImplicitHasherType<'tcx> {
212212
/// Checks that `ty` is a target type without a `BuildHasher`.
213-
fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option<Self> {
213+
fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Option<Self> {
214214
if let TyKind::Path(QPath::Resolved(None, path)) = hir_ty.kind {
215215
let params: Vec<_> = path
216216
.segments

clippy_lints/src/types/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BO
314314
impl<'tcx> LateLintPass<'tcx> for Types {
315315
fn check_fn(
316316
&mut self,
317-
cx: &LateContext<'_>,
317+
cx: &LateContext<'tcx>,
318318
fn_kind: FnKind<'_>,
319-
decl: &FnDecl<'_>,
319+
decl: &FnDecl<'tcx>,
320320
_: &Body<'_>,
321321
_: Span,
322322
def_id: LocalDefId,
@@ -346,7 +346,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
346346
);
347347
}
348348

349-
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
349+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
350350
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
351351

352352
match item.kind {
@@ -363,7 +363,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
363363
}
364364
}
365365

366-
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
366+
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) {
367367
match item.kind {
368368
ImplItemKind::Const(ty, _) => {
369369
let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx
@@ -391,7 +391,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
391391
}
392392
}
393393

394-
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
394+
fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &hir::FieldDef<'tcx>) {
395395
let is_exported = cx.effective_visibilities.is_exported(field.def_id);
396396

397397
self.check_ty(
@@ -404,7 +404,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
404404
);
405405
}
406406

407-
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) {
407+
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'tcx>) {
408408
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
409409

410410
let context = CheckTyContext {
@@ -421,7 +421,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
421421
}
422422
}
423423

424-
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
424+
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
425425
if let Some(ty) = local.ty {
426426
self.check_ty(
427427
cx,
@@ -444,7 +444,7 @@ impl Types {
444444
}
445445
}
446446

447-
fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>, context: CheckTyContext) {
447+
fn check_fn_decl<'tcx>(&mut self, cx: &LateContext<'tcx>, decl: &FnDecl<'tcx>, context: CheckTyContext) {
448448
// Ignore functions in trait implementations as they are usually forced by the trait definition.
449449
//
450450
// FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard
@@ -466,7 +466,7 @@ impl Types {
466466
/// lint found.
467467
///
468468
/// The parameter `is_local` distinguishes the context of the type.
469-
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, mut context: CheckTyContext) {
469+
fn check_ty<'tcx>(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, mut context: CheckTyContext) {
470470
if hir_ty.span.from_expansion() {
471471
return;
472472
}

clippy_lints/src/types/redundant_allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_span::symbol::sym;
1111

1212
use super::{utils, REDUNDANT_ALLOCATION};
1313

14-
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
14+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: &QPath<'tcx>, def_id: DefId) -> bool {
1515
let mut applicability = Applicability::MaybeIncorrect;
1616
let outer_sym = if Some(def_id) == cx.tcx.lang_items().owned_box() {
1717
"Box"

clippy_lints/src/types/vec_box.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc_span::symbol::sym;
1313

1414
use super::VEC_BOX;
1515

16-
pub(super) fn check(
17-
cx: &LateContext<'_>,
16+
pub(super) fn check<'tcx>(
17+
cx: &LateContext<'tcx>,
1818
hir_ty: &hir::Ty<'_>,
19-
qpath: &QPath<'_>,
19+
qpath: &QPath<'tcx>,
2020
def_id: DefId,
2121
box_size_threshold: u64,
2222
) -> bool {

clippy_lints/src/unconditional_recursion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn get_ty_def_id(ty: Ty<'_>) -> Option<DefId> {
7777
}
7878
}
7979

80-
fn get_hir_ty_def_id(tcx: TyCtxt<'_>, hir_ty: rustc_hir::Ty<'_>) -> Option<DefId> {
80+
fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Option<DefId> {
8181
let TyKind::Path(qpath) = hir_ty.kind else { return None };
8282
match qpath {
8383
QPath::Resolved(_, path) => path.res.opt_def_id(),
@@ -229,7 +229,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local
229229
}
230230
}
231231

232-
fn is_default_method_on_current_ty(tcx: TyCtxt<'_>, qpath: QPath<'_>, implemented_ty_id: DefId) -> bool {
232+
fn is_default_method_on_current_ty<'tcx>(tcx: TyCtxt<'tcx>, qpath: QPath<'tcx>, implemented_ty_id: DefId) -> bool {
233233
match qpath {
234234
QPath::Resolved(_, path) => match path.segments {
235235
[first, .., last] => last.ident.name == kw::Default && first.res.opt_def_id() == Some(implemented_ty_id),

clippy_lints/src/uninhabited_references.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl LateLintPass<'_> for UninhabitedReferences {
5757
}
5858
}
5959

60-
fn check_fn(
60+
fn check_fn<'tcx>(
6161
&mut self,
62-
cx: &LateContext<'_>,
62+
cx: &LateContext<'tcx>,
6363
kind: FnKind<'_>,
64-
fndecl: &'_ FnDecl<'_>,
64+
fndecl: &'_ FnDecl<'tcx>,
6565
_: &'_ Body<'_>,
6666
span: Span,
6767
_: LocalDefId,

clippy_lints/src/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
207207
}
208208
}
209209

210-
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
210+
fn check_ty(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) {
211211
if !hir_ty.span.from_expansion()
212212
&& self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS)
213213
&& let Some(&StackItem::Check {

clippy_lints/src/zero_sized_map_values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ declare_clippy_lint! {
4444
declare_lint_pass!(ZeroSizedMapValues => [ZERO_SIZED_MAP_VALUES]);
4545

4646
impl LateLintPass<'_> for ZeroSizedMapValues {
47-
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
47+
fn check_ty<'tcx>(&mut self, cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) {
4848
if !hir_ty.span.from_expansion()
4949
&& !in_trait_impl(cx, hir_ty.hir_id)
5050
&& let ty = ty_from_hir_ty(cx, hir_ty)
@@ -82,7 +82,7 @@ fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
8282
false
8383
}
8484

85-
fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
85+
fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
8686
cx.maybe_typeck_results()
8787
.and_then(|results| {
8888
if results.hir_owner == hir_ty.hir_id.owner {

0 commit comments

Comments
 (0)