Closed
Description
Save this program as dangling.rs. When you try to compile this program with rustc dangling.rs, you'll get an interesting (and long) error message:
dangling.rs:3:12: 3:14 error: `i` does not live long enough
dangling.rs:3 return &i;
^~
dangling.rs:1:23: 4:2 note: reference must be valid for the anonymous lifetime #1 defined on the block at 1:22...
dangling.rs:1 fn dangling() -> &int {
dangling.rs:2 let i = 1234;
dangling.rs:3 return &i;
dangling.rs:4 }
dangling.rs:1:23: 4:2 note: ...but borrowed value is only valid for the block at 1:22
dangling.rs:1 fn dangling() -> &int {
dangling.rs:2 let i = 1234;
dangling.rs:3 return &i;
dangling.rs:4 }
error: aborting due to previous error
rustc 0.12.0
dangling.rs:1:18: 1:22 error: missing lifetime specifier [E0106]
dangling.rs:1 fn dangling() -> &int {
^~~~
error: aborting due to previous error
Metadata
Metadata
Assignees
Labels
No labels