Open
Description
Code
pub trait StreamParser {
fn new(stream: Box<dyn BufRead>) -> Self;
fn next_triple(&mut self) -> Result<Option<Arc<Triple>>, SourceError>;
}
pub struct NTriplesParser();
impl StreamParser for NTriplesParser { .. }; // left out for conciseness
pub struct StreamParserIter<P: StreamParser>(P);
impl<P> Iterator for StreamParserIter<P>
where
P: StreamParser,
{
type Item = Arc<Triple>;
fn next(&mut self) -> Option<Self::Item> {
// FIXME handle errors somehow
self.0.next_triple().ok()?
}
}
impl<P> IntoIterator for P
where
P: StreamParser,
{
type Item = Arc<Triple>;
type IntoIter = StreamParserIter<P>;
fn into_iter(self) -> Self::IntoIter {
StreamParserIter(self)
}
}
Current output
error[E0210]: type parameter `P` must be used as the type parameter for some local type (e.g., `MyStruct<P>`)
--> core/src/sources/graphs/parsers.rs:32:6
|
32 | impl<P> IntoIterator for P
| ^ type parameter `P` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter
Desired output
note: implementing a foreign trait is only possible if all of the types for which it is implemented are local
Rationale and extra context
In the above example, clearly one type that satisfies P: StreamParser
is local. The real essence here is that some other crate might have at least one type that implements StreamParser
. So, in fact, all types hit by the generic trait bound must be local.
Other cases
No response
Rust Version
rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.80.0
LLVM version: 18.1.7
Anything else?
No response