-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Convert T::Foo
resolution to use where clauses, not bounds
#20300
Labels
A-associated-items
Area: Associated items (types, constants & functions)
Milestone
Comments
Nominating and placing on 1.0 alpha milestone. Ultimately PROBABLY a nice to have, but it's really surprising that this doesn't work. |
nikomatsakis
added
the
A-associated-items
Area: Associated items (types, constants & functions)
label
Jan 7, 2015
nikomatsakis
changed the title
Convert
Convert Jan 8, 2015
T::Foo
resolution to use where clauses, not bounds`T::Foo
resolution to use where clauses, not bounds
cc me |
Until this is implemented, you can also use a qualified type path trait Trait {
type Item;
}
struct Foo;
impl Foo {
fn foo1<T: Trait>(_x: T::Item) {}
fn foo2<T>(_x: <T as Trait>::Item) where T: Trait {}
}
struct Bar;
impl Trait for Bar {
type Item = i32;
}
fn main() {
Foo::foo1::<Bar>(5i32);
Foo::foo2::<Bar>(5i32);
} |
cc me |
Would anyone mind mentoring this? |
@ahmedcharles a fix is in progress already, actually, but it turns out to be quite a tricky problem. Much trickier than it appeared at first. |
This was referenced Feb 21, 2015
bors
added a commit
that referenced
this issue
Feb 25, 2015
…ds, r=nikomatsakis This is a fix for #20300 though as a side-sweep it fixes a number of stack overflows because it integrates cycle detection into the conversion process. I didn't go through and retest everything. The tricky part here is that in some cases we have to go find the information we need from the AST -- we can't use the converted form of the where-clauses because we often have to handle something like `T::Item` *while converting the where-clauses themselves*. Since this is also not a fixed-point process we can't just try and keep trying to find the best order. So instead I modified the `AstConv` interface to allow you to request the bounds for a type parameter; we'll then do a secondary scan of the where-clauses to figure out what we need. This may create a cycle in some cases, but we have code to catch that. Another approach that is NOT taken by this PR would be to "convert" `T::Item` into a form that does not specify what trait it's using. This then kind of defers the problem of picking the trait till later. That might be a good idea, but it would make normalization and everything else much harder, so I'm holding off on that (and hoping to find a better way for handling things like `i32::T`). This PR also removes "most of" the `bounds` struct from `TypeParameterDef`. Still a little ways to go before `ParamBounds` can be removed entirely -- it's used for supertraits, for example (though those really ought to be converted, I think, to a call to `get_type_parameter_bounds` on `Self` from within the trait definition). cc @jroesch Fixes #20300
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently referencing an associated type like
T::Foo
searches the bounds onT
rather than the full set of where clauses. This is no good.The text was updated successfully, but these errors were encountered: