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

ICE involving traits with lifetime params (?) #10201

Closed
scharris opened this issue Oct 31, 2013 · 4 comments
Closed

ICE involving traits with lifetime params (?) #10201

scharris opened this issue Oct 31, 2013 · 4 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@scharris
Copy link

The following code produces an ICE (unbuntu 13.04 x86-64, 10/30/2013 nightly 0.9-pre build):

trait Trait_A {}
pub struct Struct_A;
impl Trait_A for Struct_A {}


trait Trait_B<A> {}
struct Struct_B<A>;
impl<A:Trait_A> Trait_B<A> for Struct_B<A> {}


struct C<A,B>;

trait Trait_D<'self, A:Trait_A, B:Trait_B<A>> {
  fn c(&self) -> &'self C<A,B>;
}
struct Struct_D<'self,A,B> {
  c: &'self C<A,B>,
}
impl<'self,A:Trait_A,B:Trait_B<A>> Trait_D<'self,A,B> for Struct_D<'self,A,B> {
  fn c(&self) -> &'self C<A,B> {
    self.c
  }
}

fn foo<'self, A: Trait_A, B: Trait_B<A>, D: Trait_D<'self, A, B>>(d: &'self D) -> uint {
  0u
}

pub fn main() {
  let c = C;
  let d = Struct_D { c: &c};

  let z = foo(&d); 

  println(z.to_str());
}

Ubuntu 13.04, x86-64, nightly build of 10/31/2013:

$ rustc scratch4.rs
task '' failed at 'assertion failed: rp.is_none()', /build/buildd/rust-nightly-201310300805e42e378raring/src/librustc/middle/typeck/collect.rs:1108
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task '' failed at 'explicit failure', /build/buildd/rust-nightly-201310300805e42e378raring/src/librustc/rustc.rs:396

@alexcrichton
Copy link
Member

This is likely a dupe of any number of other rp.is_none() assertions being seen (if you search github for rp.is_none you'll see a fair amount), but I believe that this will be closed by #10153 (although @nikomatsakis would have to confirm that).

Regardless, thanks for the report!

@nikomatsakis
Copy link
Contributor

Certainly the assertion will go away. I expect the test cases will work properly, but one of the "to do" items is to go through and test them all.

@erickt
Copy link
Contributor

erickt commented May 10, 2014

I've modernized this code here, and it now is erroring out instead of ICE-ing:

trait Trait_A {}
struct Struct_A;
impl Trait_A for Struct_A {}


trait Trait_B<A> {}
struct Struct_B<A>;
impl<A:Trait_A> Trait_B<A> for Struct_B<A> {}

struct C<A,B>;

trait Trait_D<'a, A:Trait_A, B:Trait_B<A>> {
    fn c(&self) -> &'a C<A,B>;
}

struct Struct_D<'a,A,B> {
    c: &'a C<A,B>,
}

impl<'a,A:Trait_A,B:Trait_B<A>> Trait_D<'a,A,B> for Struct_D<'a,A,B> {
    fn c(&self) -> &'a C<A,B> {
        self.c
    }
}

fn foo<'a, A: Trait_A, B: Trait_B<A>, D: Trait_D<'a, A, B>>(d: &'a D) -> uint {
    0u
}

pub fn main() {
    let c = C;
    let d = Struct_D { c: &c };

    let z = foo(&d); 

    println!("{}", z.to_str());
}

produces:

ice.rs:34:13: 34:16 error: cannot determine a type for this bounded type parameter: unconstrained type
ice.rs:34     let z = foo(&d);
                      ^~~

I don't quite understand how this initial code was supposed to work, so I'm not going to close it yet. @nikomatsakis: can we close this?

@scharris
Copy link
Author

Erick, thanks for resurrecting this and doing the modernizing.

I had gone too far simplifying things when trying to make the smallest test case, so the type parameters A and B which C depends on weren't determined, just as the helpful compiler message now says (previously hidden by the ICE).

So giving A and B concrete types (as they were in the real program), the program now compiles.

(Compiles)

trait Trait_A {}
struct Struct_A;
impl Trait_A for Struct_A {}


trait Trait_B<A> {}
struct Struct_B<A>;
impl<A:Trait_A> Trait_B<A> for Struct_B<A> {}

struct C<A,B>;

trait Trait_D<'a, A:Trait_A, B:Trait_B<A>> {
    fn c(&self) -> &'a C<A,B>;
}

struct Struct_D<'a,A,B> {
    c: &'a C<A,B>,
}

impl<'a,A:Trait_A,B:Trait_B<A>> Trait_D<'a,A,B> for Struct_D<'a,A,B> {
    fn c(&self) -> &'a C<A,B> {
        self.c
    }
}

fn foo<'a, A: Trait_A, B: Trait_B<A>, D: Trait_D<'a, A, B>>(d: &'a D) -> uint {
    0u
}

pub fn main() {
    let a = Struct_A;
    let b: Struct_B<Struct_A> = Struct_B;
    let c: C<Struct_A, Struct_B<Struct_A>> = C;
    let d = Struct_D { c: &c };

    let z = foo(&d); 

    println!("{}", z.to_str());
}

I think this one can be closed, great job yall.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2023
Add missing arguments to `new_lint` example of `cargo` lints

changelog: Add missing arguments to `new_lint` code example.

From the surrounding text, it seems like this code example is missing the arguments to create a new `cargo` lint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants