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 with specialization enabled #39618

Closed
ghost opened this issue Feb 7, 2017 · 2 comments · Fixed by #69192
Closed

Stack overflow with specialization enabled #39618

ghost opened this issue Feb 7, 2017 · 2 comments · Fixed by #69192
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-specialization `#![feature(specialization)]` I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Feb 7, 2017

#![feature(specialization)]

trait Foo {
    fn foo(&self);
}

trait Bar {
    fn bar(&self);
}

impl<T> Bar for T where T: Foo {
    fn bar(&self) {}
}

impl<T> Foo for T where T: Bar {
    fn foo(&self) {}
}

impl Foo for u64 {}

fn main() {
}

Compiling this code results in:

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow

There is no backtrace.

If I disable specialization feature, rustc reports an error:

error[E0119]: conflicting implementations of trait `Foo` for type `u64`

Rustc details:

rustc 1.17.0-nightly (0648517fa 2017-02-03)
binary: rustc
commit-hash: 0648517faf1e2cf37c8b6770cbd0180a816ed9a0
commit-date: 2017-02-03
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9
@steveklabnik steveklabnik added the A-specialization Area: Trait impl specialization label Feb 7, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@zmt00
Copy link

zmt00 commented May 31, 2018

This seems to compile as of the most recent nightly.

[-@- rust]$ cat foo.rs
#![feature(specialization)]
trait Foo {
    fn foo(&self);
}
trait Bar {
    fn bar(&self);
}
impl<T> Bar for T where T: Foo {
    fn bar(&self) {}
}
impl<T> Foo for T where T: Bar {
    fn foo(&self) {}
}
impl Foo for u64 {}
fn main() {
}
[-@- rust]$ rustc foo.rs
[-@- rust]$ rustc --version --verbose
rustc 1.28.0-nightly (5d0631a64 2018-05-30)
binary: rustc
commit-hash: 5d0631a6438cf30cac236b7176371663e35c8d07
commit-date: 2018-05-30
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0

@ghost
Copy link
Author

ghost commented Jun 1, 2018

Good to hear that!

Would it make sense to add this example to the test suite to prevent regressions in the future?

@jonas-schievink jonas-schievink added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Feb 12, 2020
Centril added a commit to Centril/rust that referenced this issue Feb 17, 2020
@bors bors closed this as completed in d1f175b Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-specialization `#![feature(specialization)]` I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants