-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
This was on version 0.8
rustc 0.8
host: i686-pc-mingw32
I was writing a trial program to read in a file as ~[u8] then get a slice from that (ultimately as a str but not got that far)
Whilst mucking around with life times to get the get_slice function to compile I accidently tried this combination
fn get_slice<'r>(&'self self, length: uint) -> &'r [u8] {
self.data.slice(0, length)
}
This caused an internal compiler error
task failed at 'assertion failed: self.variance.is_some()', C:\bot\slave\dist2-win\build\src\librustc\middle\typeck\rscope.rs:186
error: internal compiler error: unexpected failure
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', c:\bot\slave\dist2-win\build\src\librustc\rustc.rs:391
The full source is below and will attempt to read a text file "d3d9.txt" so you will need to make one of those up (with anything in it)
use std::io::*;
use std::path::*;
use std::str::*;
struct Stream {
data: ~[u8],
length: uint,
offset: uint
}
impl Stream {
fn new(path: &Path) -> Stream {
let data = match read_whole_file(path) {
Ok(T) => T,
Err(err) => { println(err); fail!(); }
};
let s = from_utf8(data);
println(format!("{:s}", s));
let length = data.len();
Stream {
data: data,
length: length,
offset: 0
}
}
#[inline]
fn has_more(&self) -> bool {
self.offset < self.length
}
fn get_slice<'r>(&'self self, length: uint) -> &'r [u8] {
self.data.slice(0, length)
}
}
fn main() {
let path = WindowsPath("d3d9.txt");
let stream = Stream::new(&path);
let t = stream.get_slice(5);
println(format!("{:x}", stream.length));
}