Skip to content

Commit 40daa06

Browse files
authored
Rollup merge of #58926 - gabi-250:tcx-lifetimes, r=petrochenkov
Make the lifetime parameters of tcx consistent. I have implemented `codegen_allocator` for my backend, but I've had to make a small change to its signature in `ExtraBackendMethods`. I wonder if this change is justified, or if it is too specific to my use case to be useful to anyone else. `write_metadata` and `codegen_allocator` are both called from `codegen_crate` (in `librustc_codegen_ssa/base.rs`), and they both receive the same `tcx` as an argument: https://github.com/rust-lang/rust/blob/c196097e588b05e86b5ce6de992b2a6e6a7027bd/src/librustc_codegen_ssa/base.rs#L555-L557 and: https://github.com/rust-lang/rust/blob/c196097e588b05e86b5ce6de992b2a6e6a7027bd/src/librustc_codegen_ssa/base.rs#L640-L642 However, `codegen_allocator` accepts a `TyCtxt` with any lifetime parameters (`tcx: TyCtxt<'_, '_, '_>`), while `write_metadata` requires that the `tcx` argument is of type `TyCtxt<'b, 'gcx, 'gcx>`. In my implementation, I've found that it's necessary for `tcx` in `codegen_allocator` to also have the `<'b, 'gcx, 'gcx>` lifetime parameters. Have I misunderstood the purpose of the parameters of `TyCtxt`? I've read [here](https://rust-lang.github.io/rustc-guide/ty.html) that the last two parameters only need to be distinct if the function needs to be used during type inference, but I don't think that is the case here.
2 parents 416edc1 + cd9a0cf commit 40daa06

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/librustc_codegen_llvm/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
123123
) -> EncodedMetadata {
124124
base::write_metadata(tcx, metadata)
125125
}
126-
fn codegen_allocator(
126+
fn codegen_allocator<'b, 'gcx>(
127127
&self,
128-
tcx: TyCtxt<'_, '_, '_>,
128+
tcx: TyCtxt<'b, 'gcx, 'gcx>,
129129
mods: &mut ModuleLlvm,
130130
kind: AllocatorKind
131131
) {

src/librustc_codegen_ssa/traits/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
3838
tcx: TyCtxt<'b, 'gcx, 'gcx>,
3939
metadata: &mut Self::Module,
4040
) -> EncodedMetadata;
41-
fn codegen_allocator(
41+
fn codegen_allocator<'b, 'gcx>(
4242
&self,
43-
tcx: TyCtxt<'_, '_, '_>,
43+
tcx: TyCtxt<'b, 'gcx, 'gcx>,
4444
mods: &mut Self::Module,
4545
kind: AllocatorKind
4646
);

0 commit comments

Comments
 (0)