Skip to content

Commit ff28254

Browse files
committed
Don't forget that the lifetime on hir types is 'tcx
1 parent 7bdd60c commit ff28254

File tree

23 files changed

+92
-85
lines changed

23 files changed

+92
-85
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub struct InferArg {
256256
}
257257

258258
impl InferArg {
259-
pub fn to_ty(&self) -> Ty<'_> {
259+
pub fn to_ty(&self) -> Ty<'static> {
260260
Ty { kind: TyKind::Infer, span: self.span, hir_id: self.hir_id }
261261
}
262262
}

compiler/rustc_hir_analysis/src/astconv/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn generic_arg_mismatch_err(
169169
/// instantiate a `GenericArg`.
170170
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
171171
/// creates a suitable inference variable.
172-
pub fn create_substs_for_generic_args<'tcx, 'a>(
172+
pub fn create_substs_for_generic_args<'tcx: 'a, 'a>(
173173
tcx: TyCtxt<'tcx>,
174174
def_id: DefId,
175175
parent_substs: &[subst::GenericArg<'tcx>],

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait AstConv<'tcx> {
106106
&self,
107107
span: Span,
108108
item_def_id: DefId,
109-
item_segment: &hir::PathSegment<'_>,
109+
item_segment: &hir::PathSegment<'tcx>,
110110
poly_trait_ref: ty::PolyTraitRef<'tcx>,
111111
) -> Ty<'tcx>;
112112

@@ -140,14 +140,14 @@ struct ConvertedBinding<'a, 'tcx> {
140140
hir_id: hir::HirId,
141141
item_name: Ident,
142142
kind: ConvertedBindingKind<'a, 'tcx>,
143-
gen_args: &'a GenericArgs<'a>,
143+
gen_args: &'tcx GenericArgs<'tcx>,
144144
span: Span,
145145
}
146146

147147
#[derive(Debug)]
148148
enum ConvertedBindingKind<'a, 'tcx> {
149149
Equality(ty::Term<'tcx>),
150-
Constraint(&'a [hir::GenericBound<'a>]),
150+
Constraint(&'a [hir::GenericBound<'tcx>]),
151151
}
152152

153153
/// New-typed boolean indicating whether explicit late-bound lifetimes
@@ -199,12 +199,12 @@ pub struct GenericArgCountResult {
199199
}
200200

201201
pub trait CreateSubstsForGenericArgsCtxt<'a, 'tcx> {
202-
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'a>>, bool);
202+
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool);
203203

204204
fn provided_kind(
205205
&mut self,
206206
param: &ty::GenericParamDef,
207-
arg: &GenericArg<'_>,
207+
arg: &GenericArg<'tcx>,
208208
) -> subst::GenericArg<'tcx>;
209209

210210
fn inferred_kind(
@@ -279,7 +279,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
279279
&self,
280280
span: Span,
281281
def_id: DefId,
282-
item_segment: &hir::PathSegment<'_>,
282+
item_segment: &hir::PathSegment<'tcx>,
283283
) -> SubstsRef<'tcx> {
284284
let (substs, _) = self.create_substs_for_ast_path(
285285
span,
@@ -336,7 +336,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
336336
def_id: DefId,
337337
parent_substs: &[subst::GenericArg<'tcx>],
338338
seg: &hir::PathSegment<'_>,
339-
generic_args: &'a hir::GenericArgs<'_>,
339+
generic_args: &'a hir::GenericArgs<'tcx>,
340340
infer_args: bool,
341341
self_ty: Option<Ty<'tcx>>,
342342
constness: ty::BoundConstness,
@@ -385,14 +385,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
385385
struct SubstsForAstPathCtxt<'a, 'tcx> {
386386
astconv: &'a (dyn AstConv<'tcx> + 'a),
387387
def_id: DefId,
388-
generic_args: &'a GenericArgs<'a>,
388+
generic_args: &'a GenericArgs<'tcx>,
389389
span: Span,
390390
inferred_params: Vec<Span>,
391391
infer_args: bool,
392392
}
393393

394394
impl<'a, 'tcx> CreateSubstsForGenericArgsCtxt<'a, 'tcx> for SubstsForAstPathCtxt<'a, 'tcx> {
395-
fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'a>>, bool) {
395+
fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool) {
396396
if did == self.def_id {
397397
(Some(self.generic_args), self.infer_args)
398398
} else {
@@ -404,11 +404,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
404404
fn provided_kind(
405405
&mut self,
406406
param: &ty::GenericParamDef,
407-
arg: &GenericArg<'_>,
407+
arg: &GenericArg<'tcx>,
408408
) -> subst::GenericArg<'tcx> {
409409
let tcx = self.astconv.tcx();
410410

411-
let mut handle_ty_args = |has_default, ty: &hir::Ty<'_>| {
411+
let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| {
412412
if has_default {
413413
tcx.check_optional_stability(
414414
param.def_id,
@@ -556,7 +556,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
556556

557557
fn create_assoc_bindings_for_generic_args<'a>(
558558
&self,
559-
generic_args: &'a hir::GenericArgs<'_>,
559+
generic_args: &'a hir::GenericArgs<'tcx>,
560560
) -> Vec<ConvertedBinding<'a, 'tcx>> {
561561
// Convert associated-type bindings or constraints into a separate vector.
562562
// Example: Given this:
@@ -602,7 +602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
602602
&self,
603603
span: Span,
604604
item_def_id: DefId,
605-
item_segment: &hir::PathSegment<'_>,
605+
item_segment: &hir::PathSegment<'tcx>,
606606
parent_substs: SubstsRef<'tcx>,
607607
) -> SubstsRef<'tcx> {
608608
debug!(
@@ -635,7 +635,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
635635
/// are disallowed. Otherwise, they are pushed onto the vector given.
636636
pub fn instantiate_mono_trait_ref(
637637
&self,
638-
trait_ref: &hir::TraitRef<'_>,
638+
trait_ref: &hir::TraitRef<'tcx>,
639639
self_ty: Ty<'tcx>,
640640
constness: ty::BoundConstness,
641641
) -> ty::TraitRef<'tcx> {
@@ -662,7 +662,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
662662
trait_ref_span: Span,
663663
trait_def_id: DefId,
664664
trait_segment: &hir::PathSegment<'_>,
665-
args: &GenericArgs<'_>,
665+
args: &GenericArgs<'tcx>,
666666
infer_args: bool,
667667
self_ty: Ty<'tcx>,
668668
) -> GenericArgCountResult {
@@ -730,7 +730,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
730730
#[instrument(level = "debug", skip(self, span, constness, bounds, speculative))]
731731
pub(crate) fn instantiate_poly_trait_ref(
732732
&self,
733-
trait_ref: &hir::TraitRef<'_>,
733+
trait_ref: &hir::TraitRef<'tcx>,
734734
span: Span,
735735
constness: ty::BoundConstness,
736736
self_ty: Ty<'tcx>,
@@ -769,7 +769,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
769769
lang_item: hir::LangItem,
770770
span: Span,
771771
hir_id: hir::HirId,
772-
args: &GenericArgs<'_>,
772+
args: &GenericArgs<'tcx>,
773773
self_ty: Ty<'tcx>,
774774
bounds: &mut Bounds<'tcx>,
775775
) {
@@ -802,7 +802,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
802802
span: Span,
803803
trait_def_id: DefId,
804804
self_ty: Ty<'tcx>,
805-
trait_segment: &hir::PathSegment<'_>,
805+
trait_segment: &hir::PathSegment<'tcx>,
806806
is_impl: bool,
807807
constness: ty::BoundConstness,
808808
) -> ty::TraitRef<'tcx> {
@@ -826,7 +826,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
826826
span: Span,
827827
trait_def_id: DefId,
828828
self_ty: Ty<'tcx>,
829-
trait_segment: &'a hir::PathSegment<'a>,
829+
trait_segment: &'a hir::PathSegment<'tcx>,
830830
is_impl: bool,
831831
constness: ty::BoundConstness,
832832
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
@@ -937,13 +937,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
937937
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
938938
/// for more details.
939939
#[instrument(level = "debug", skip(self, ast_bounds, bounds))]
940-
pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'hir>>>(
940+
pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
941941
&self,
942942
param_ty: Ty<'tcx>,
943943
ast_bounds: I,
944944
bounds: &mut Bounds<'tcx>,
945945
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
946-
) {
946+
) where
947+
'tcx: 'hir,
948+
{
947949
for ast_bound in ast_bounds {
948950
match ast_bound {
949951
hir::GenericBound::Trait(poly_trait_ref, modifier) => {
@@ -1001,7 +1003,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10011003
pub(crate) fn compute_bounds(
10021004
&self,
10031005
param_ty: Ty<'tcx>,
1004-
ast_bounds: &[hir::GenericBound<'_>],
1006+
ast_bounds: &[hir::GenericBound<'tcx>],
10051007
) -> Bounds<'tcx> {
10061008
self.compute_bounds_inner(param_ty, ast_bounds)
10071009
}
@@ -1011,7 +1013,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10111013
pub(crate) fn compute_bounds_that_match_assoc_type(
10121014
&self,
10131015
param_ty: Ty<'tcx>,
1014-
ast_bounds: &[hir::GenericBound<'_>],
1016+
ast_bounds: &[hir::GenericBound<'tcx>],
10151017
assoc_name: Ident,
10161018
) -> Bounds<'tcx> {
10171019
let mut result = Vec::new();
@@ -1031,7 +1033,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10311033
fn compute_bounds_inner(
10321034
&self,
10331035
param_ty: Ty<'tcx>,
1034-
ast_bounds: &[hir::GenericBound<'_>],
1036+
ast_bounds: &[hir::GenericBound<'tcx>],
10351037
) -> Bounds<'tcx> {
10361038
let mut bounds = Bounds::default();
10371039

@@ -1269,7 +1271,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12691271
&self,
12701272
span: Span,
12711273
did: DefId,
1272-
item_segment: &hir::PathSegment<'_>,
1274+
item_segment: &hir::PathSegment<'tcx>,
12731275
) -> Ty<'tcx> {
12741276
let substs = self.ast_path_substs_for_ty(span, did, item_segment);
12751277
self.tcx().at(span).bound_type_of(did).subst(self.tcx(), substs)
@@ -1278,7 +1280,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12781280
fn conv_object_ty_poly_trait_ref(
12791281
&self,
12801282
span: Span,
1281-
hir_trait_bounds: &[hir::PolyTraitRef<'_>],
1283+
hir_trait_bounds: &[hir::PolyTraitRef<'tcx>],
12821284
lifetime: &hir::Lifetime,
12831285
borrowed: bool,
12841286
representation: DynKind,
@@ -1925,7 +1927,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19251927
span: Span,
19261928
qself_ty: Ty<'tcx>,
19271929
qself: &hir::Ty<'_>,
1928-
assoc_segment: &hir::PathSegment<'_>,
1930+
assoc_segment: &hir::PathSegment<'tcx>,
19291931
permit_variants: bool,
19301932
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
19311933
let tcx = self.tcx();
@@ -2286,8 +2288,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22862288
span: Span,
22872289
opt_self_ty: Option<Ty<'tcx>>,
22882290
item_def_id: DefId,
2289-
trait_segment: &hir::PathSegment<'_>,
2290-
item_segment: &hir::PathSegment<'_>,
2291+
trait_segment: &hir::PathSegment<'tcx>,
2292+
item_segment: &hir::PathSegment<'tcx>,
22912293
constness: ty::BoundConstness,
22922294
) -> Ty<'tcx> {
22932295
let tcx = self.tcx();
@@ -2604,7 +2606,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26042606
pub fn res_to_ty(
26052607
&self,
26062608
opt_self_ty: Option<Ty<'tcx>>,
2607-
path: &hir::Path<'_>,
2609+
path: &hir::Path<'tcx>,
26082610
permit_variants: bool,
26092611
) -> Ty<'tcx> {
26102612
let tcx = self.tcx();
@@ -2843,20 +2845,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28432845

28442846
/// Parses the programmer's textual representation of a type into our
28452847
/// internal notion of a type.
2846-
pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
2848+
pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
28472849
self.ast_ty_to_ty_inner(ast_ty, false, false)
28482850
}
28492851

28502852
/// Parses the programmer's textual representation of a type into our
28512853
/// internal notion of a type. This is meant to be used within a path.
2852-
pub fn ast_ty_to_ty_in_path(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
2854+
pub fn ast_ty_to_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
28532855
self.ast_ty_to_ty_inner(ast_ty, false, true)
28542856
}
28552857

28562858
/// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait
28572859
/// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors.
28582860
#[instrument(level = "debug", skip(self), ret)]
2859-
fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
2861+
fn ast_ty_to_ty_inner(
2862+
&self,
2863+
ast_ty: &hir::Ty<'tcx>,
2864+
borrowed: bool,
2865+
in_path: bool,
2866+
) -> Ty<'tcx> {
28602867
let tcx = self.tcx();
28612868

28622869
let result_ty = match &ast_ty.kind {
@@ -3014,7 +3021,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30143021
if in_trait { tcx.mk_projection(def_id, substs) } else { tcx.mk_opaque(def_id, substs) }
30153022
}
30163023

3017-
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
3024+
pub fn ty_of_arg(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
30183025
match ty.kind {
30193026
hir::TyKind::Infer if expected_ty.is_some() => {
30203027
self.record_ty(ty.hir_id, expected_ty.unwrap(), ty.span);
@@ -3030,7 +3037,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30303037
hir_id: hir::HirId,
30313038
unsafety: hir::Unsafety,
30323039
abi: abi::Abi,
3033-
decl: &hir::FnDecl<'_>,
3040+
decl: &hir::FnDecl<'tcx>,
30343041
generics: Option<&hir::Generics<'_>>,
30353042
hir_ty: Option<&hir::Ty<'_>>,
30363043
) -> ty::PolyFnSig<'tcx> {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ fn receiver_is_implemented<'tcx>(
18151815
fn check_variances_for_type_defn<'tcx>(
18161816
tcx: TyCtxt<'tcx>,
18171817
item: &hir::Item<'tcx>,
1818-
hir_generics: &hir::Generics<'_>,
1818+
hir_generics: &hir::Generics<'tcx>,
18191819
) {
18201820
let ty = tcx.type_of(item.owner_id);
18211821
if tcx.has_error_field(ty) {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'tcx> ItemCtxt<'tcx> {
351351
ItemCtxt { tcx, item_def_id }
352352
}
353353

354-
pub fn to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> {
354+
pub fn to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
355355
self.astconv().ast_ty_to_ty(ast_ty)
356356
}
357357

@@ -410,7 +410,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
410410
&self,
411411
span: Span,
412412
item_def_id: DefId,
413-
item_segment: &hir::PathSegment<'_>,
413+
item_segment: &hir::PathSegment<'tcx>,
414414
poly_trait_ref: ty::PolyTraitRef<'tcx>,
415415
) -> Ty<'tcx> {
416416
if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
@@ -1179,7 +1179,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>>
11791179

11801180
fn infer_return_ty_for_fn_sig<'tcx>(
11811181
tcx: TyCtxt<'tcx>,
1182-
sig: &hir::FnSig<'_>,
1182+
sig: &hir::FnSig<'tcx>,
11831183
generics: &hir::Generics<'_>,
11841184
def_id: LocalDefId,
11851185
icx: &ItemCtxt<'tcx>,

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
539539

540540
/// A quasi-deprecated helper used in rustdoc and clippy to get
541541
/// the type from a HIR node.
542-
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
542+
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
543543
// In case there are any projections, etc., find the "environment"
544544
// def-ID that will be used to determine the traits/predicates in
545545
// scope. This is derived from the enclosing item-like thing.
@@ -550,7 +550,7 @@ pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
550550

551551
pub fn hir_trait_to_predicates<'tcx>(
552552
tcx: TyCtxt<'tcx>,
553-
hir_trait: &hir::TraitRef<'_>,
553+
hir_trait: &hir::TraitRef<'tcx>,
554554
self_ty: Ty<'tcx>,
555555
) -> Bounds<'tcx> {
556556
// In case there are any projections, etc., find the "environment"

0 commit comments

Comments
 (0)