Mandatory inlined functions for unsized types and 'super lifetime?

Indeed, that's why I used &mut Option references instead of &out references that can be implemented in user code. Plus, when the optimizer does get knowledge of the functions involved, it can optimize away the check of the drop flag:

#[no_mangle] pub
fn f1 ()
{
    // `a` is an array of elems with drop glue.
    match lib::f2(&mut None) { a => unsafe {
        ::libc::write(1, a.as_ptr().cast(), 0);
    }}
}

becomes:

f1:
	pushq	%rbx
	subq	$16, %rsp
	movb	$1, (%rsp)
	leaq	1(%rsp), %rbx
	movq	$0, 1(%rsp)
	movw	$0, 9(%rsp)
	movl	$1, %edi
	movq	%rbx, %rsi
	xorl	%edx, %edx
	callq	*write@GOTPCREL(%rip)
	movq	%rbx, %rdi
	callq	core::ptr::drop_in_place
	addq	$16, %rsp
	popq	%rbx
	retq

So, as you can see, the flag check can be elided in some situations. When the buffer has no drop glue, it will be elided too. But when the function that initializes the caller value is not inlined, and if the value has drop glue, then indeed there may be a necessary flag check.


Regarding language sugar, I much prefer @illicitonion's suggestion of let a; … &out a (with an a: &'a out <existential impl Sized> for the callee) than the less usual super 'a notation :slightly_smiling_face:. But in the meantime, we do not need sugar, we just need that existential impl Sized in argument position to work. Once we get that, we'll be able to write this kind of pattern and experiment with it. Then (and imho, only then) would it be useful to discuss any sugaring of the pattern.

1 Like