Skip to content

Commit cf38675

Browse files
committed
update the [impl item example], incorporating oli-obk feedback from 2015dec21.
1 parent e35b298 commit cf38675

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

text/0000-pub-restricted.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,22 @@ feature is making this code cleaner or easier to reason about).
474474
[impl item example]: #impl-item-example
475475

476476
```rust
477-
pub struct S;
477+
pub struct S(i32);
478478

479479
mod a {
480-
pub fn call_foo(s: &S) { s.foo(); }
480+
pub fn call_foo(s: &super::S) { s.foo(); }
481481

482-
impl S {
483-
pub(a) fn foo(&self) { println!("only callable within `a`"); }
482+
mod b {
483+
fn some_method_private_to_b() {
484+
println!("inside some_method_private_to_b");
485+
}
486+
487+
impl super::super::S {
488+
pub(a) fn foo(&self) {
489+
some_method_private_to_b();
490+
println!("only callable within `a`: {}", self.0);
491+
}
492+
}
484493
}
485494
}
486495

@@ -807,25 +816,7 @@ itself not accessible in `mod b`?
807816

808817
pnkfelix is personally inclined to make this sort of thing illegal,
809818
mainly because he finds it totally unintuitive, but is interested in
810-
hearing counter-arguments. Certainly the earlier [impl item example][]
811-
would look prettier as:
812-
813-
```rust
814-
pub struct S;
815-
816-
impl S {
817-
pub(a) fn foo(&self) { println!("only callable within `a`"); }
818-
}
819-
820-
mod a {
821-
pub fn call_foo(s: &S) { s.foo(); }
822-
823-
}
824-
825-
fn rejected(s: &S) {
826-
s.foo(); //~ ERROR: `S::foo` not visible outside of module `a`
827-
}
828-
```
819+
hearing counter-arguments.
829820

830821
## Implicit Restriction Satisfaction (IRS:PUNPM)
831822

0 commit comments

Comments
 (0)