diff --git a/text/3606-temporary-lifetimes-in-tail-expressions.md b/text/3606-temporary-lifetimes-in-tail-expressions.md index 5cef3ca91aa..1fc5a725d42 100644 --- a/text/3606-temporary-lifetimes-in-tail-expressions.md +++ b/text/3606-temporary-lifetimes-in-tail-expressions.md @@ -9,6 +9,12 @@ In the next edition, drop temporaries in tail expressions *before* dropping locals, rather than after. +![A diagram showing a function with one let statement "let x = g();" and a tail expression "temp().h()" +and a visualisation of how long x and temp live before and after this change. +Before: x is created first, then temp is created, then x is dropped, then temp is dropped. +After: x is created first, then temp is created, then temp is dropped, then x is dropped. +](3606-temporary-lifetimes-in-tail-expressions/diagram.svg) + # Motivation Temporaries in the tail expression in a block live longer than the block itself, diff --git a/text/3606-temporary-lifetimes-in-tail-expressions/diagram.svg b/text/3606-temporary-lifetimes-in-tail-expressions/diagram.svg new file mode 100644 index 00000000000..33d72faad94 --- /dev/null +++ b/text/3606-temporary-lifetimes-in-tail-expressions/diagram.svg @@ -0,0 +1,4 @@ + + + +
let x
temp()
drop
drop
let x
temp()
drop
drop
before
after
fn f() {
    let x = g();

    temp().h()
}
\ No newline at end of file