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 upAssociated type projections don't play well with HRTBs and normalization #30472
Comments
soltanmm
changed the title
Trait A having blanket impl dependence on trait B may be satisfied, but trait B may not
A trait having blanket impl dependence on a 2nd trait may be satisfied, but the 2nd trait may not
Dec 19, 2015
soltanmm
changed the title
A trait having blanket impl dependence on a 2nd trait may be satisfied, but the 2nd trait may not
HKL bounds on associated types causes types that would otherwise be judged equivalent to not be
Dec 29, 2015
This comment has been minimized.
This comment has been minimized.
|
HRTBs (I've been using the wrong nomenclature the whole time!) make projections sad. ///////////////
// HRTB setup
//
trait A {
type S;
}
trait B<'self_> {
type T;
}
trait C: for<'self_> B<'self_> {
type U: for<'self_> A<S=<Self as B<'self_>>::T>; // requires normalizing through an HRTB
}
//////////////////////
// Problematic impls
//
impl A for usize {
type S = usize;
}
impl<'self_> B<'self_> for usize {
type T = usize;
}
impl C for usize {
type U = usize;
}
fn main() {}
Very likely a dupe of #28994. |
soltanmm
changed the title
HKL bounds on associated types causes types that would otherwise be judged equivalent to not be
Associated type projections don't play well with HRTBs and normalization
Dec 30, 2015
eddyb
added
A-lifetimes
A-associated-items
A-typesystem
labels
Jan 1, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Known issue. |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 (or @nikomatsakis? Still a bit unclear on y'all's role separation) |
This comment has been minimized.
This comment has been minimized.
|
@soltanmm actually, I'm not entirely sure. There are a serious of refactorings that I have in mind for the type system / trait resolver, and I've been figuring that after those are done, I would come back to revisit some of these issues, if they still occur, but it may be worth digging into this example (or #28994) in detail. Honestly it's not all fresh in my mind. The refactorings I am thinking of are, first, lazy normalization (as described in this discuss thread), which may indeed help here, though I've not thought it through very deeply. Second, I'd like to generally rework how the trait checker is working to make it easier to extend the environment as you go -- the current setup, where the set of assumptions etc is semi-fixed when the inference context is created -- makes it hard to "descend through" a binder like |
This comment has been minimized.
This comment has been minimized.
|
So, potentially w.r.t. lazy normalization, I've been playing with another bit of code (trying to shrink it a bit): trait Hkt<'a> { type Output; }
trait A where for<'s> <Self::B as Hkt<'s>>::Output: Clone {
type B: for<'s> Hkt<'s>;
}
trait C: A
where for<'s> <Self::B as Hkt<'s>>::Output: Clone
{}
impl<'a> Hkt<'a> for usize { type Output = usize; }
struct S;
impl A for S {
type B = usize;
}From reading the debug logs, it seems that when checking the well-formed-ness of An aside: does lazy normalization have something to do with this asterisk in |
soltanmm
referenced this issue
Apr 30, 2016
Merged
Generic associated types (associated type constructors) #1598
eddyb
referenced this issue
May 27, 2016
Closed
Type Checker getting confused with constraints + ICE #33904
eddyb
referenced this issue
Jul 15, 2016
Open
Spurious (?) "trait bound not satisfied" with associated type constructors #34834
TimNN
referenced this issue
Sep 11, 2016
Closed
ICE: 'rustc' panicked at 'assertion failed: concrete_substs.is_normalized_for_trans()' #36381
This comment has been minimized.
This comment has been minimized.
|
Is this #30867? It looks similar, but uncertain. |
Mark-Simulacrum
added
the
C-bug
label
Jul 24, 2017
This comment has been minimized.
This comment has been minimized.
|
What's the state of this now? I fairly frequently run into problems with associated types involved with HRTBs not projecting/unifying. |
soltanmm commentedDec 19, 2015
playpen link
This could've been written with
MyIntowritten asIntoand similarly forMyFrom/From. It was written this way only to make explicit the necessity of one blanket impl for satisfying the other.I'm guessing that extensional equality is not judged, even though it is possible to make such a judgment and such a judgment must be made to compile code that compiles today.
<Self as A<'self_>>::Ton line 12 ought to be equated tousize(which must be detected at some other point in time else line 13 wouldn't be able to compile).EDIT: Playing around a bit, it looks more and more like it's all about the HKL bounds...