Add test for temporary lifetime extension in Self() syntax.
This commit is contained in:
parent
578fa8e945
commit
855ea48ccc
2 changed files with 12 additions and 1 deletions
|
|
@ -7,6 +7,17 @@ fn temp() -> String {
|
|||
#[derive(Debug)]
|
||||
struct X<'a>(&'a String);
|
||||
|
||||
trait T<'a> {
|
||||
const A: X<'a>;
|
||||
const B: X<'a>;
|
||||
}
|
||||
|
||||
impl<'a> T<'a> for X<'a> {
|
||||
// Check both Self() and X() syntax:
|
||||
const A: X<'a> = Self(&String::new());
|
||||
const B: X<'a> = X(&String::new());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = &temp();
|
||||
let b = Some(&temp());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:23:19
|
||||
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:34:19
|
||||
|
|
||||
LL | let g = some(&temp());
|
||||
| ^^^^^^ - temporary value is freed at the end of this statement
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue