Skip to content

Regression in beta: unsafe-free, pure Rust pgm. with no deps segfaults #36401

Closed
@osa1

Description

@osa1
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Key {
    AltArrow(Arrow),
    Arrow(Arrow),
    Ctrl(char),
    Char(char),
    Esc,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Arrow { Left, Right, Up, Down }

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Event {
    Key(Key),
    String(String),
    Resize,
    Unknown(Vec<u8>),
}

static XTERM_SINGLE_BYTES : [(u8, Event); 5] =
    [ (1,  Event::Key(Key::Ctrl('a'))),
      (5,  Event::Key(Key::Ctrl('e'))),
      (23, Event::Key(Key::Ctrl('w'))),
      (11, Event::Key(Key::Ctrl('k'))),
      (4,  Event::Key(Key::Ctrl('d'))),
    ];

fn main() {
    println!("{:?}", XTERM_SINGLE_BYTES);
}

(can be tested here: https://is.gd/EkJ3by)

When run with beta or nightly, this program segfaults.

I tried to simplify this a little bit, but my attempts either turned segfault into a stack overflow, or made it working. Here are some changes I've tried:

  • I tried [(u8, char)] for XTERM_SINGLE_BYTES and it worked fine.
  • I tried removing Event::Keys (e.g. [(u8, Key)]) and it worked.
  • I removed some of the constructors from Event enum, most of the time the error turned into a stack overflow.

In my original program I'm iterating the array, and for the u8 part I'm getting random bytes instead of bytes I put in the array. I'm using rustc 1.13.0-nightly (70598e0 2016-09-03).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions