Skip to content

Commit 0f63c85

Browse files
Add comment explaining not explicitly passing lifetime parameters to inner functions
1 parent fe83565 commit 0f63c85

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/gen.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,27 @@ fn gen_method_item(
430430
// Generate the list of argument used to call the method.
431431
let args = get_arg_list(sig.decl.inputs.iter())?;
432432

433-
// Builds turbofish with generic types (without lifetimes)
433+
// Build the turbofish type parameters. We need to pass type parameters
434+
// explicitly as they cannot be inferred in all cases (e.g. something like
435+
// `mem::size_of`). However, we don't explicitly specify lifetime
436+
// parameters. Most lifetime parameters are so called late-bound lifetimes
437+
// (ones that stick to input parameters) and Rust prohibits us from
438+
// specifying late-bound lifetimes explicitly (which is not a problem,
439+
// because those can always be correctly inferred). It would be possible to
440+
// explicitly specify early-bound lifetimes, but this is hardly useful.
441+
// Early-bound lifetimes are lifetimes that are only attached to the return
442+
// type. Something like:
443+
//
444+
// fn foo<'a>() -> &'a i32
445+
//
446+
// It's hard to imagine how such a function would even work. So since those
447+
// functions are really rare and special, we won't support them. In
448+
// particular, for us to determine if a lifetime parameter is early- or
449+
// late-bound would be *really* difficult.
450+
//
451+
// So we just specify type parameters. In the future, however, we need to
452+
// add support for const parameters. But those are not remotely stable yet,
453+
// so we can wait a bit still.
434454
let generic_types = sig.decl.generics
435455
.type_params()
436456
.map(|param| {

0 commit comments

Comments
 (0)