Skip to content

Pointer can be accessed after ownership was transfered and segfaults #11481

Closed
@lassej

Description

@lassej

This code segfaults on Mac OS X 10.8.5 with Rust 0.9:

struct Number {
  n: i64
}

impl ToStr for Number {
  fn to_str( &self) -> ~str {
    self.n.to_str()
  }
}

struct List {
  list: ~[~ToStr]
}

impl List {
  fn push( &mut self, n: ~ToStr) {
    self.list.push( n);
  }
}

fn main() {
  let n = ~Number{ n: 42 };
  let mut l = ~List{ list: ~[] };
  l.push( n);
  println!( "n: {}", n.to_str());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions