Hello,
I have been thinking about how to fix issue 7331
(https://github.com/mozilla/rust/issues/7331), because I think that
something like the `Constructable` trait is going to be important for
capnproto-rust (https://github.com/dwrensha/capnproto-rust).
I've managed to find a one-line change that prevents the ICE:
index 3f5e1ef..399a769 100644
--- a/src/librustc/middle/typeck/collect.rs
+++ b/src/librustc/middle/typeck/collect.rs
@@ -312,7 +312,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
// Self => D'
// D,E,F => E',F',G'
let substs = substs {
- regions: ty::NonerasedRegions(opt_vec::Empty),
+ regions:
ty::NonerasedRegions(opt_vec::with(ty::re_bound(ty::br_self))),
self_ty: Some(self_param),
tps: non_shifted_trait_tps + shifted_method_tps
};
However, if I try to use the `Constructable` trait that I can now
define, I run into borrow check errors, as shown in the example below.
--------------------
trait Constructable<'self> {
fn construct(&'self [u8]) -> Self;
}
struct Reader<'self> {
v : &'self [u8]
}
impl <'self> Constructable<'self> for Reader<'self> {
fn construct(v : &'self [u8]) -> Reader<'self> {
Reader { v : v }
}
}
// This works fine.
impl <'self> Reader<'self> {
fn get1(&self) -> Reader<'self> {
Constructable::construct(self.v)
}
}
// This gives a borrow check error:
/*
test.rs:19:8: 19:32 error: cannot infer an appropriate lifetime due to
conflicting requirements
test.rs:19 Constructable::construct(self.v)
^~~~~~~~~~~~~~~~~~~~~~~~
note: first, the lifetime must be contained by lifetime re_bound(br_self)...
test.rs:19:8: 19:32 note: ...due to the following expression
test.rs:19 Constructable::construct(self.v)
^~~~~~~~~~~~~~~~~~~~~~~~
test.rs:19:33: 19:39 note: but, the lifetime must also be contained by
the expression at 19:33...
test.rs:19 Constructable::construct(self.v)
^~~~~~
test.rs:19:33: 19:39 note: ...due to the following expression
test.rs:19 Constructable::construct(self.v)
*/
impl <'self, T : Constructable<'self>> Reader<'self> {
fn get2(&self) -> T {
Constructable::construct(self.v)
}
}
fn main() { }
-------------------
Can anyone help me out here? Am I doing something wrong in my example?
Is my fix wrong? Is something wrong elsewhere in typechecking?
Thanks,
David
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev