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 upspecialization + overflow => generics that produce trans errors depending on type parameters #32498
Comments
Aatch
added
the
A-specialization
label
Mar 26, 2016
pnkfelix
added
the
T-lang
label
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated |
rust-highfive
added
the
I-nominated
label
Mar 26, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @aturon |
This comment has been minimized.
This comment has been minimized.
|
This is possible even without specialization. At least, it used to be with the old |
This comment has been minimized.
This comment has been minimized.
|
I made a mistake: the first example doesn't actually require specialization, and the simplified version I edited into the original post works the same way on stable. Though I think it may be more difficult to fix in the presence of specialization: the only reason |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high to investigate |
rust-highfive
added
P-high
and removed
I-nominated
labels
Mar 31, 2016
pnkfelix
assigned
aturon
Mar 31, 2016
This comment has been minimized.
This comment has been minimized.
|
So, I see the first example as a case that we should ultimately try to catch and give a better error for (as we do for more direct circular structs). But I don't think it's terribly urgent, personally. For the second case: I suspect that this is fundamental. That is, the proof search for traits fundamentally relies on an overflow cutoff to avoid infinite loops, and the fact that specialization lets you dispatch on types will always mean that you can selectively create these overflowing situations. I see the "blame" here as mostly the fact that the trait system can fail due to overflow, but that's inevitable in having as powerful of a system as we do. I'm going to renominate for triage of the bug listed in the top comment, which we could try to provide a better error for. I suggest that this is P-low, however. triage: I-nominated |
rust-highfive
added
I-nominated
and removed
P-high
labels
Apr 1, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-low @aturon's summary seems accurate. |
comex commentedMar 26, 2016
In which we sneakily define a type that contains itself:
(EDIT: Actually, this one didn't depend on specialization. There was previously a default impl of
Tr2not depending onTr, but it wasn't necessary. The second one does seem to depend on it.)produces:
This error comes from trans, and it goes away if either the call to
funcorfunc's usage ofS<T>is commented out. In other words,funcclaims to allow instantiation with any type but actually supports no types. (By adding more specializations it could be made to support only certain types.)A similar issue is when overflow occurs while determining whether a given specialization applies:
This happens to compile, but if the
u32in main is changed tou64, I get:Is this a known consequence of specialization? I haven't seen it discussed. It seems to violate Rust's normal policy of type-safe generics, and I'm not sure what a rule to prevent it upfront would look like (especially considering that the patterns can in some cases be split across multiple crates).