HRTB bug in streaming iterator #30786
Labels
A-lifetimes
Area: Lifetimes / regions
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Full code playpen
So, I've been working on a hacky streaming iterator library and ran into what looks like a bug in the type checker involving higher ranked trait bounds.
In the code below, I've defined a
Stream
trait. To implement a stream, one implementsStream
on&'a mut MyStream
for all lifetimes'a
.I then went ahead and implemented adapters for filter and map and an extension trait for applying these adapters:
The problem is the interaction between the
Filter
andMap
adapters. The following works iff the map adapter appears before the filter adapter.However, this should never work due to the
for<'b> &'b mut A: Stream<Item=T>
constraint on theFilter
implementation above (marked BAD). Basically, this constraint should assert the stream'sItem
is the same independent of'b
which should mean that this item doesn't borrow from it's stream (as a matter of fact, I'm using this exact constraint to implement an adapter for converting streams to iterators). However, items returned by both themap
andsource
streams above do obviously borrow from their streams.Correct error without map:
The text was updated successfully, but these errors were encountered: