Repository navigation
ICE when trying to parameterize on ebml::writer::Encoder #11881
Copy link
Copy link
Closed
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Description
(pnkfelix: Here is a modern example that ICE's (feel free to replace as necessary as rustc changes):)
extern crate ser = "serialize";
use serialize = self::ser; // necessary for deriving(Encodable)
use ser::{Encodable, Encoder};
use ser::json;
use ser::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;
#[deriving(Encodable)]
struct Foo {
baz: bool,
}
#[deriving(Encodable)]
struct Bar {
froboz: uint
}
enum WireProtocol {
JSON,
EBML,
// ...
}
fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = json::Encoder::new(wr);
val.encode(&mut encoder);
}
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = writer::Encoder(wr);
val.encode(&mut encoder);
}
pub fn main() {
let target = Foo { baz: false };
let mut wr = MemWriter::new();
let proto = JSON;
match proto {
JSON => encode_json(&target, &mut wr),
EBML => encode_ebml(&target, &mut wr)
}
}Original bug description follows
Consider the following:
extern mod extra = "extra#0.10-pre";
use extra::serialize::{Encodable, Encoder};
use extra::json;
use extra::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;
#[deriving(Encodable)]
struct Foo {
baz: bool,
}
#[deriving(Encodable)]
struct Bar {
froboz: uint
}
enum WireProtocol {
JSON,
EBML,
// ...
}
fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = json::Encoder::new(wr);
val.encode(&mut encoder);
}
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = writer::Encoder(wr);
val.encode(&mut encoder);
}
fn main() {
let target = Foo { baz: false };
let mut wr = MemWriter::new();
let proto = JSON;
match proto {
JSON => encode_json(&target, &mut wr),
EBML => encode_ebml(&target, &mut wr)
}
}
This fails with the following ICE:
serialization-branch.rs:31:16: 31:28 error: internal compiler error: Cannot relate bound region: ReLateBound(167, BrNamed(syntax::ast::DefId{crate: 0u32, node: 185u32}, a)) <= ReInfer(0)
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
serialization-branch.rs:31 val.encode(&mut encoder);
But if you comment out the EBML code, like so:
extern mod extra = "extra#0.10-pre";
use extra::serialize::{Encodable, Encoder};
use extra::json;
use extra::ebml::writer;
use std::io::MemWriter;
use std::str::from_utf8_owned;
#[deriving(Encodable)]
struct Foo {
baz: bool,
}
#[deriving(Encodable)]
struct Bar {
froboz: uint
}
enum WireProtocol {
JSON,
EBML,
// ...
}
fn encode_json<'a, T: Encodable<json::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = json::Encoder::new(wr);
val.encode(&mut encoder);
}
/*
fn encode_ebml<'a, T: Encodable<writer::Encoder<'a>>>(val: &T, wr: &'a mut MemWriter) {
let mut encoder = writer::Encoder(wr);
val.encode(&mut encoder);
}
*/
fn main() {
let target = Foo { baz: false };
let mut wr = MemWriter::new();
let proto = JSON;
match proto {
JSON => encode_json(&target, &mut wr),
_ => {}
//EBML => encode_ebml(&target, &mut wr)
}
}
it compiles.
The JSON and EBML serialization code is identifical, but their Encoder impls and how they're exposed are slightly different (I assume because of their respective histories). Something about that difference is triggering this ICE, it seems.
Metadata
Metadata
Assignees
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Activity
olsonjeffery commentedon Jan 29, 2014
As observed by @huonw , probably related to #5121
pnkfelix commentedon Mar 21, 2014
still reproduces.
updated description to put in something that builds against
rustc 0.10-pre (caf17fe 2014-03-21)JustAPerson commentedon Mar 31, 2014
This no longer produces an ICE likely due to #13157 and related work towards resolving the outstanding #5121.
The updated version in the description no longer builds against master due to changes in the libserialize API, so I have updated it again here: https://gist.github.com/JustAPerson/a96dddcde35633ec9d27
A small diff is provided:
Tested with
sfackler commentedon Mar 31, 2014
Flagging as needstest
Auto merge of rust-lang#11881 - y21:issue11880, r=Alexendoo
Merge rust-lang#11881