Skip to content

rustc hangs when printing block with no trailing newline #11493

Closed
@lilyball

Description

@lilyball

If rustc attempts to print an error message for a block that has no trailing newline, because it ends on the very last line of a file with no trailing newline, then rustc will hang forever attempting to print the block.

To test, the following code should print a lifetime error:

fn main() {
    let x = Some(3);
    let y = x.as_ref().unwrap_or(&5);
}

If the file has a trailing newline, it prints just fine. But without the trailing newline, it hangs forever after printing:

foo.rs:3:34: 3:36 error: borrowed value does not live long enough
foo.rs:3     let y = x.as_ref().unwrap_or(&5);
                                          ^~
foo.rs:1:11: 1:1 note: reference must be valid for the block at 1:10...
foo.rs:1 fn main() {

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions