Skip to content

Stack overflow reported for &'static str into() #54155

Closed
@johnedmonds

Description

@johnedmonds
struct Test {
  s: String
}

impl<'a> From<&'a String> for Test {
  fn from(s: &'a String) -> Test {
    return Test {s: s.to_string()};
  }
}

impl From<&'static str> for Test {
  fn from(s: &'static str) -> Test {
    s.into()
  }
}

fn main() {
  let test: Test = "test".into();
}

Doing rustc main.rs && ./main results in

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6

The cause does not appear to actually be a stack overflow though. Running with rust-lldb reports EXC_BAD_ACCESS in the from method for &'static str.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions