-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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: assertion failed: self.variance.is_some() #9597
Comments
Having lifetime parameter on trait does not have sense, but in any case triggers ICE.
|
Yeah, I'm pretty sure that the whole program is incorrect but I think that ICE is not the way by which I should be told about that incorrectness :) I tried adding lifetime parameters to traits in order to circumvent another problem which I have just described in my message on the mailing list. Apparently, this is not a valid workaround. And I deliberately try to avoid managed boxes because they limit the API. |
Well I think that following program solves your problem ;) trait Walker { // Some business-logic trait
fn walk(&mut self);
}
// A struct which is intended to be an implementor of Walker trait
// Note that it has lifetime parameter in order to work for any kind
// of pointer to a Reader
struct ReaderContainer {
priv reader: @Reader,
priv counter: int
}
// Some auxiliary structure for ReaderContainer
// It may be anything but it should have a reference to ReaderContainer
// We have to use lifetime parameter because this structure is 'attached'
// to ReaderContainer, hence it must be of the same lifetime
struct ReaderContainerIterator<'self> {
priv container: &'self mut ReaderContainer
}
// Some made-up implementation of iterator protocol for our
// auxiliary structure, it does not really matter
impl<'self> Iterator<u8> for ReaderContainerIterator<'self> {
fn next(&mut self) -> Option<u8> {
if self.container.counter < 10 {
self.container.counter += 1;
Some(self.container.reader.read_byte() as u8)
} else {
None
}
}
}
impl ReaderContainer {
// A constructor for ReaderContainer, nothing special
fn new(reader: @Reader) -> ReaderContainer {
ReaderContainer { reader: reader, counter: 0 }
}
// A method which returns our auxiliary structure, i.e. iterator
// Note that self parameter has lifetime 'self, otherwise this naturally
// does not compile
fn iter<'r>(&'r mut self) -> ReaderContainerIterator<'r> {
ReaderContainerIterator { container: self }
}
}
// Here is the problem: we cannot implement Walker trait!
impl Walker for ReaderContainer {
// See below for concrete errors description
fn walk(&mut self) { // <<<
for b in self.iter() {
println(fmt!("byte %?", b));
}
}
}
fn main() {
use std::io;
let r = io::stdin();
let mut c = ReaderContainer::new(r);
c.walk();
} |
@bmaxa wrapping code in
will get it formatted/highlighted as Rust code (I've edited your comment to add this). |
Probably a subbug of #4846. |
After updating the original code example to modern rust, and testing on the latest master (dc48adc) there is no longer any ICE. Instead, the following error:
|
I've once again updated it to modern rust, and it compiles fine (although I'm tripping over #14098):
So I'm closing this bug. |
Current compiler fails with the following error:
on the following code:
The code above is a reduced version of an attempt to avoid the problem I have described in my message on the mailing list in August. I probably should open an issue for that too.
The text was updated successfully, but these errors were encountered: