Skip to content

in 《A 30-minute Introduction to Rust》 rustc dangling.rs output need update #17588

Closed
@electricface

Description

@electricface

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions