a: impl Iterator<Item = &'a u128>, introduces a hidden type parameter. You need to make that type parameter explicit, and acknowledge the dependency on it (because, as the error says, you're not allowed not to).
As a side note, it isn’t generally a good idea to work with references to primitives if you don’t have to, because they can be inefficient (requiring memory access instead of passing the data directly) and constraining (because there has to be something for the references to borrow). You should consider accepting u128 directly and simplifying your signature:
If someone has an iterator of &u128 to pass to your method, they can simply call .copied() on the iterator.
There may be even better ways to write this, but in order to suggest any of them I’d have to see what your iterator is actually doing (how the returned iterator relates to the input iterator a).
Yes, acknowledging a dependency on APIT would make sense if RPIT actually needed to capture its lifetime. But in this case, I don’t need to capture the lifetime of that iterator. The returned iterator is not tied to the input iterator in any way, shape, or form (for the sake of argument, you can assume the input iterator is first collected into a collection). Please let me know if I’m missing something here.
Also, a primitive type is used here for simplicity.
The matter at issue is capturing your function’s type parameter, not any of your lifetime parameters. Not capturing type parameters is simply not supported by the compiler — it can’t yet perform the necessary reasoning to verify the lack of relationship you claim.
This is a limitation of the compiler’s current abilities, not a necessary property of the language.
I am confused about the meaning of capturing just a type parameter. What does that even mean? Could you refer me to some resources where I can read more about this?
The return type is different when that type parameter is different. The return type of my_struct.method([&1]) is different from the return type of my_struct.method(some_vec.iter()).
The return type captures all lifetimes appearing in that type parameter (which might be more than just 'a — it’s up to what the caller provides).
These are both unavoidable in the case where you are returning something like an iterator that wraps the provided iterator I. And as previously discussed, the compiler doesn’t yet support not capturing in the cases where it is avoidable (but it should, someday).
Also, if you need to avoid the capture, and as you say, "assume the input iterator is first collected into a collection", then you can use an intermediate named type to help out: