Closed
Description
STR
#![crate_type = "lib"]
pub struct Public;
struct Private;
impl Iterator for Public {
type Item = Private;
fn next(&mut self) -> Option<Private> { // OK(???) `Private` type in public method
unimplemented!();
}
}
// an inherent method rejects the same pattern
impl Public {
pub fn my_next(&mut self) -> Option<Private> { //~ error: private type in exported type signature
unimplemented!();
}
}
pub trait MyIterator<Item> {
fn next(&mut self) -> Option<Item>;
}
// the old version of `Iterator` doesn't allow returning `Private` from `next()` either
impl MyIterator<Private> for Public { //~ error: private type in exported type signature
fn next(&mut self) -> Option<Private> {
unimplemented!();
}
}
AFAIK, you can't put private types in "public" items (public as in marked with pub
). Iterator::next
is not explicitly marked with pub
, but for all intent and purposes all the methods in a trait are public if the trait is public. So, I think the impl Iterator for Public { type Item = Private; .. }
should be rejected by the privacy checker. (Or, I could be wrong and this is "correct" behavior - and this wouldn't be the first time that the privacy/module system allows things that I find unreasonable)
Version
rustc 1.0.0-nightly (e233987ce 2015-02-27) (built 2015-02-28)
Metadata
Metadata
Assignees
Labels
No labels