Description
I tried this code (using cargo test
):
use std::fmt::{Display, Formatter};
use std::fmt;
pub struct A(Vec<u32>);
impl Display for A {
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
self.0[0];
Ok(())
}
}
#[test]
fn main() {
let a = A(vec![]);
eprintln!("{}", a);
}
I expected to see this happen:
The thread should've panicked with 'Index out of bounds: the len is 0 but the index is 0'
Instead, this happened:
Thread crashes with SIGILL (illegal instruction)
Meta
This bug works in stable, beta and nightly.
It also does the same in rust playground.
Here is my cpu info (I figured that it might be useful given the nature of the bug).
The bug doesn't appear if run from main, nor if run directly (without passing from the Display impl).
rustc --version --verbose
:
rustc 1.41.1 (f3e1a954d 2020-02-24)
binary: rustc
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
commit-date: 2020-02-24
host: x86_64-unknown-linux-gnu
release: 1.41.1
LLVM version: 9.0
Backtrace
running 1 test
thread panicked while processing panic. aborting.
error: test failed, to rerun pass '--lib'
Caused by:
process didn't exit successfully: /path/to/proj/target/debug/deps/proj-296b7cb53c6210d6
(signal: 4, SIGILL: illegal instruction)