Skip to content

cargo build panics with include_bytes!() of the file itself #53956

Closed
@ghost

Description

This code looks meaningless, but it's still valid code. However it can cause cargo to panic.

// This file is: main.rs
fn main() {
    let mut bytes = vec![];
    bytes.append(&mut include_bytes!("main.rs").to_vec());
    println!("Byte count: {}", bytes.len());
}

First build is ok. Then call shell touch main.rs and build again, cargo will crash with:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 1',
/checkout/src/libcore/slice/mod.rs:2079:10

Version: cargo 1.28.0 (96a2c7d16 2018-07-13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions