-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Type inference problem with lifetimes and assoiated types #28046
Comments
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 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() {} |
Is there an existing bug report about the |
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
} |
Ah, right... we need to decide somehow whether the lifetime is part of the function type. |
Current error:
|
Triage: no change as of Rust 1.41:
|
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
The text was updated successfully, but these errors were encountered: