-
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 due to ambiguity between impl and where-clause #22110
Comments
A more standalone version of that test: use std::vec::Vec;
use std::iter::Iterator;
use std::slice::{AsSlice, Split, SliceExt};
struct Path;
trait Foo<A> {
fn foo(&self, a: A);
}
impl<A,F:Fn(A)> Foo<A> for F {
fn foo(&self, a: A) { }
}
fn baz<F:for<'a> Foo<(&'a Path,)>>(f: F) { }
impl Path {
fn components<T>(&self, t: fn(&Path))
where fn(&Path) : for<'a> Foo<(&'a Path,)>,
{
baz(t)
}
}
fn main() {
} |
That version only works because we don't seem to be enforcing the rules against where-clauses with no type parameters fully. This alternate version also fails to compile but obeys those rules: use std::vec::Vec;
use std::iter::Iterator;
use std::slice::{AsSlice, Split, SliceExt};
struct Path;
trait Foo<A> {
fn foo(&self, a: A);
}
impl<A,F:Fn(A)> Foo<A> for F {
fn foo(&self, a: A) { }
}
fn baz<A,F:for<'a> Foo<(&'a A,)>>(f: F) { }
fn components<T,A>(t: fn(&A))
where fn(&A) : for<'a> Foo<(&'a A,)>,
{
baz(t)
}
fn main() {
} but the error is different:
|
A related example: use std::slice::Iter;
fn foo<'a,T>(v: Iter<'a,T>) -> Option<T>
where Iter<'a,T> : Iterator
{
v.next()
}
fn main() { } Here the explicit where clause matches, interfering with later attempts to project the type
|
cc me |
1 similar comment
cc me |
The fix in #22407 is simply to always allow where clauses to override impls. This seems like a conservative step -- everything where clauses tell you must be derived from an impl, after all. In he future, I'd like to improve the engine so that it can take advantage of impls as well to possibly glean more information than the where-clause is telling us, but it's tricky, because impls have preconditions. |
…soc-types, r=nikomatsakis Take 2. This PR includes a bunch of refactoring that was part of an experimental branch implementing [implied bounds]. That particular idea isn't ready to go yet, but the refactoring proved useful for fixing #22246. The implied bounds branch also exposed #22110 so a simple fix for that is included here. I still think some more refactoring would be a good idea here -- in particular I think most of the code in wf.rs is kind of duplicating the logic in implicator and should go, but I decided to post this PR and call it a day before diving into that. I'll write a bit more details about the solutions I adopted in the various bugs. I patched the two issues I was concerned about, which was the handling of supertraits and HRTB (the latter turned out to be fine, so I added a comment explaining why.) r? @pnkfelix (for now, anyway) cc @aturon [implied bounds]: http://smallcultfollowing.com/babysteps/blog/2014/07/06/implied-bounds/
…imes-of-assoc-types Take 2. This PR includes a bunch of refactoring that was part of an experimental branch implementing [implied bounds]. That particular idea isn't ready to go yet, but the refactoring proved useful for fixing rust-lang#22246. The implied bounds branch also exposed rust-lang#22110 so a simple fix for that is included here. I still think some more refactoring would be a good idea here -- in particular I think most of the code in wf.rs is kind of duplicating the logic in implicator and should go, but I decided to post this PR and call it a day before diving into that. I'll write a bit more details about the solutions I adopted in the various bugs. I patched the two issues I was concerned about, which was the handling of supertraits and HRTB (the latter turned out to be fine, so I added a comment explaining why.) r? @pnkfelix (for now, anyway) cc @aturon [implied bounds]: http://smallcultfollowing.com/babysteps/blog/2014/07/06/implied-bounds/
Example:
fails with
This is because the compiler considers both the bridging impl from
Fn
toFnMut
is an option and the where-clause to be valid options. Choosing between where-clauses and impls seems to be tricky.At minimum, the code that checks for overlap between the where-clause and the impl seems to have the subtyping relationship backwards. However, I am not sure whether it's a good idea to check anything, or maybe better to simply always prefer where-clauses.
The text was updated successfully, but these errors were encountered: