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 with using a trait as a type alias #4016

Closed
erickt opened this issue Nov 22, 2012 · 4 comments
Closed

ICE with using a trait as a type alias #4016

erickt opened this issue Nov 22, 2012 · 4 comments
Labels
A-trait-system Area: Trait system A-type-system Area: Type system
Milestone

Comments

@erickt
Copy link
Contributor

erickt commented Nov 22, 2012

@graydon's workcache.rs file was trying to use a trait to make a type alias, which triggers an ICE:

extern mod std;

use send_map::linear;
use std::json;
use std::serialization::{Deserializable, deserialize};

trait JD : Deserializable<json::Deserializer> { }
//type JD = Deserializable<json::Deserializer>;

fn exec<T: JD>() {
    let doc = result::unwrap(json::from_str(""));
    let _v: T = deserialize(&json::Deserializer(move doc));
    fail
}

fn main() {}

It errors with:

error: internal compiler error: substitution a had opt_region &static and b had opt_region none with variance Some(rv_invariant)

If you use a proper type type alias, it compiles fine.

@ghost ghost assigned nikomatsakis Dec 4, 2012
@catamorphism
Copy link
Contributor

Now I get a proper borrow checker error instead of an ICE:

../src/test/run-pass/issue-4016.rs:12:29: 12:58 error: cannot infer an appropriate lifetime due to conflicting requirements
../src/test/run-pass/issue-4016.rs:12     let _v: T = deserialize(&json::Deserializer(move doc));
                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: first, the lifetime cannot outlive lifetime re_bound(br_self)...
../src/test/run-pass/issue-4016.rs:12:16: 12:27 note: ...due to the following expression
../src/test/run-pass/issue-4016.rs:12     let _v: T = deserialize(&json::Deserializer(move doc));
                                                      ^~~~~~~~~~~
../src/test/run-pass/issue-4016.rs:12:16: 12:59 note: but, the lifetime must be valid for the call at 12:16...
../src/test/run-pass/issue-4016.rs:12     let _v: T = deserialize(&json::Deserializer(move doc));
                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/test/run-pass/issue-4016.rs:12:29: 12:58 note: ...due to the following expression
../src/test/run-pass/issue-4016.rs:12     let _v: T = deserialize(&json::Deserializer(move doc));
                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

but it compiles with no errors if I change the trait to be an actual type. So there's still something fishy.

@catamorphism
Copy link
Contributor

Bumping to 0.7

@catamorphism
Copy link
Contributor

This compiles now. Updated test case:

extern mod std;

use std::json;
use std::serialize::Decodable;

trait JD : Decodable<json::Decoder> { }

fn exec<T: JD>() {
    let doc = result::unwrap(json::from_str(""));
    let mut decoder = json::Decoder(doc);
    let _v: T = Decodable::decode(&mut decoder);
    fail!()
}

fn main() {}

I'll check it in.

@ghost ghost assigned catamorphism May 23, 2013
@catamorphism
Copy link
Contributor

Test case is src/test/run-pass/issue-4016.rs

RalfJung added a commit to RalfJung/rust that referenced this issue Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants