Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upType inference problem with lifetimes and assoiated types #28046
Comments
This comment has been minimized.
This comment has been minimized.
|
Slightly simplified testcase: use std::ops::Range;
pub trait Iter {
type Type: Iterator;
}
pub struct S;
impl<'a> Iter for &'a S {
type Type = Range<usize>;
}
impl S {
fn f<'a>(&'a self) -> Range<usize> where &'a S: Iter {
let x: <&'static S as Iter>::Type = 0usize..10;
x
}
}
fn main() {}Basically, the compiler is getting confused by the where clause: it sees the bound on the implementation, and "resolves" the associated type based on that, rather than actually trying to look up the type. The problem is that the bound is trivial: depending on it actually reduces the amount of information available, rather than increasing it. |
This comment has been minimized.
This comment has been minimized.
|
This is one of the tentacles of #21974 - the only relation to #27987 is that we would have ignored the poisonous where-clause if its lifetime was use std::ops::Range;
pub trait Iter {
type Type: Iterator;
}
pub trait T {
fn f<'a>(&'a self) -> <&'a Self as Iter>::Type where &'a Self: Iter;
}
pub struct S;
impl<'a> Iter for &'a S {
type Type = Range<usize>;
}
impl T for S {
fn f<'a>(&'a self) -> <&'a Self as Iter>::Type
// need some (holding) bound on 'a to make it early-bound
where &'a (): Sized {
0usize..10
}
}
fn main() {} |
This comment has been minimized.
This comment has been minimized.
|
Is there an existing bug report about the |
This comment has been minimized.
This comment has been minimized.
|
It's not a bug, just a less-than-optimally-documented feature (early-bound vs. late-bound regions). See my comment at enum Region and the links referenced therein. Its the same reason you can't write fn foo<'a>(){}
fn main() {
foo::<'static>() //~ ERROR too many lifetime parameters provided
} |
This comment has been minimized.
This comment has been minimized.
|
Ah, right... we need to decide somehow whether the lifetime is part of the function type. |
steveklabnik
added
A-lifetimes
A-associated-items
labels
Sep 3, 2015
arielb1
referenced this issue
Sep 4, 2015
Open
Lifetime in trait method declaration affects RFC 1214 checks #27987
This comment has been minimized.
This comment has been minimized.
|
Current error:
|
malbarbo commentedAug 27, 2015
I am trying to get some lifetime polymorphism but I unable to do so because of some bugs (#24424, #23958). This time it seems that the type inference is not working.
gives