Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
johnedmonds opened this issue Sep 12, 2018 · 3 comments
Closed

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

johnedmonds opened this issue Sep 12, 2018 · 3 comments

Comments

@johnedmonds
Copy link

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.

@sfackler
Copy link
Member

What behavior do you expect for the impl From<&'static str> for Test impl? It's recursing into itself through the .into() method.

EXC_BAD_ACCESS is how stack overflows are reported.

@estebank
Copy link
Contributor

Same underlying problem as #45838.

@johnedmonds
Copy link
Author

Ah, you're right. I'm sorry, when it crashed I didn't get a stack trace, I only got the one frame so I assumed it was something else going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants