Skip to content

Commit a9544f2

Browse files
committed
Add tests.
1 parent c049b56 commit a9544f2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ edition:2024
2+
3+
fn temp() -> String {
4+
String::from("Hello")
5+
}
6+
7+
#[derive(Debug)]
8+
struct X<'a>(&'a String);
9+
10+
fn main() {
11+
let a = &temp();
12+
let b = Some(&temp());
13+
let c = Option::Some::<&String>(&temp());
14+
use Option::Some as S;
15+
let d = S(&temp());
16+
let e = X(&temp());
17+
let f = Some(Ok::<_, ()>(std::borrow::Cow::Borrowed(if true {
18+
&temp()
19+
} else {
20+
panic!()
21+
})));
22+
let some = Some; // Turn the ctor into a regular function.
23+
let g = some(&temp()); //~ERROR temporary value dropped while borrowe
24+
println!("{a:?} {b:?} {c:?} {d:?} {e:?} {f:?} {g:?}");
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:23:19
3+
|
4+
LL | let g = some(&temp());
5+
| ^^^^^^ - temporary value is freed at the end of this statement
6+
| |
7+
| creates a temporary value which is freed while still in use
8+
LL | println!("{a:?} {b:?} {c:?} {d:?} {e:?} {f:?} {g:?}");
9+
| ----- borrow later used here
10+
|
11+
help: consider using a `let` binding to create a longer lived value
12+
|
13+
LL ~ let binding = temp();
14+
LL ~ let g = some(&binding);
15+
|
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0716`.

0 commit comments

Comments
 (0)