-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Support use of non-repeating tokens in repeating blocks #7
Comments
I think I can make this work with specialization. Basically specialize something which is the identity function for anything that is already iterable, and |
Hmm the hard part is what happens if everything in a repeating block is non-repeating, you don't want it to |
After three ICEs (#33017, #35676, #38091) and two hacky workarounds (diamond pattern and default type) I think I am one lifetime puzzler away from getting this working. @sfackler can you give me a hand? In vastly simplified form it looks like this. There is a trait Iterate which creates a Repetition over any value T (shown here) or an IntoIterator (not shown). #![feature(specialization)]
struct Repeat<T>(T);
trait Iterate<'a> {
type Ty: Repetition<'a>;
fn iterate(self) -> Self::Ty;
}
impl<'a, T: 'a> Iterate<'a> for T {
type Ty = Repeat<T>;
fn iterate(self) -> Self::Ty { unimplemented!() }
}
trait Repetition<'a> {
type Item;
fn next(&'a mut self) -> Self::Item;
}
impl<'a, T: 'a> Repetition<'a> for Repeat<T> {
type Item = &'a T;
fn next(&'a mut self) -> Self::Item { &self.0 }
}
fn main() {
let mut x = Iterate::iterate(0);
Repetition::next(&mut x);
Repetition::next(&mut x);
} The problem is if you change Adding a second lifetime parameter to Iterate, the first call to trait Iterate<'a, 'b: 'a> {
type Ty: Repetition<'a> + 'b;
fn iterate(self) -> Self::Ty;
}
impl<'a, 'b: 'a, T: 'b> Iterate<'a, 'b> for T {
default type Ty = Repeat<T>;
fn iterate(self) -> Self::Ty { unimplemented!() }
} What is the right bound for |
These traits look a lot like |
Closing as an acknowledged limitation because I don't plan to pursue this. If anyone comes up with a PR to make this work better, I would be willing to consider it. |
Added an indication of the limitation in the docs: f81fdb4. |
From https://github.com/dtolnay/quote/releases/tag/0.3.0:
Filing as an issue so I'll know when it's fixed :)
The text was updated successfully, but these errors were encountered: