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

Compiler out of stack on generic base trait impl restricted to a derived trait #5988

Closed
mzabaluev opened this issue Apr 21, 2013 · 7 comments · Fixed by #19780
Closed

Compiler out of stack on generic base trait impl restricted to a derived trait #5988

mzabaluev opened this issue Apr 21, 2013 · 7 comments · Fixed by #19780
Labels
A-traits Area: Trait system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-low Low priority

Comments

@mzabaluev
Copy link
Contributor

Rustc runs out of stack on this program:

use std::io;
trait B {
    fn f(&self);
}

trait T : B {
}

struct A;

impl<U: T> B for U {
    fn f(&self) { io::println("Hey, I'm a T!"); }
}

impl T for A {
}

fn main() {
    let a = A;
    let br = &a as &B;
    // let tr = &a as &T;
    // let br = tr as &B;
    br.f();
}

The inheritance of trait T from B seemingly triggers the recursion: without it, the program compiles and runs fine.

P.S. The commented-out lines illustrate what I was actually trying to achieve: upcasting a trait pointer to the base trait. That didn't work for other reasons.

@bblum
Copy link
Contributor

bblum commented Jul 3, 2013

A little more minimal:

use std::io;
trait B {
    fn f(&self);
}

trait T : B { }

impl<U: T> B for U {
    fn f(&self) { io::println("Hey, I'm a T!"); }
}

impl T for int { }

fn main() {
    let _br = @0 as @B;
}

The stack overflow is a cycle between lookup_vtables, lookup_vtable, back to lookup_vtables, and each_bound_trait_and_supertraits.

@bblum
Copy link
Contributor

bblum commented Jul 3, 2013

nominating well-covered milestone

@graydon
Copy link
Contributor

graydon commented Aug 22, 2013

accepted for production-ready milestone

@pnkfelix
Copy link
Member

just a bug, assigning P-low.

@japaric
Copy link
Member

japaric commented Nov 2, 2014

Both examples compile on:

rustc 0.13.0-dev (3327ecca4 2014-11-01 22:41:48 +0000)

@nikomatsakis Can we close this? Or should we add a test (if it's not covered in the test suite already)?

@alexcrichton
Copy link
Member

Flagging as needstest (just in case)

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 3, 2014
@nikomatsakis
Copy link
Contributor

Wacky. I don't think there is a test specifically covering this scenario.

bors added a commit that referenced this issue Dec 18, 2014
Closes #5988.
Closes #10176.
Closes #10456.
Closes #12744.
Closes #13264.
Closes #13324.
Closes #14182.
Closes #15381.
Closes #15444.
Closes #15480.
Closes #15756.
Closes #16822.
Closes #16966.
Closes #17351.
Closes #17503.
Closes #17545.
Closes #17771.
Closes #17816.
Closes #17897.
Closes #17905.
Closes #18188.
Closes #18232.
Closes #18345.
Closes #18389.
Closes #18400.
Closes #18502.
Closes #18611.
Closes #18783.
Closes #19009.
Closes #19081.
Closes #19098.
Closes #19127.
Closes #19135.
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 10, 2020
Syntax-highlight `single_char_push_str` lint

It wasn't being syntax highlighted in the online lint index:

![image](https://user-images.githubusercontent.com/37223377/91666682-8fc02000-eab3-11ea-95fa-6671472712c8.png)

changelog: none
notriddle pushed a commit to notriddle/rust that referenced this issue Sep 20, 2022
…_arg, r=DesmondWillowbrook

New assist: move_format_string_arg

The name might need some improving.

```rust
fn main() {
    print!("{x + 1}");
}
```
to
```rust
fn main() {
    print!("{}"$0, x + 1);
}
```

fixes rust-lang#13180

ref to rust-lang#5988 for similar work

* extracted `format_like`'s parser to it's own module in `ide-db`
* reworked the parser's API to be more direct
* added assist to extract expressions in format args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants