File tree 1 file changed +14
-23
lines changed 1 file changed +14
-23
lines changed Original file line number Diff line number Diff line change @@ -474,13 +474,22 @@ feature is making this code cleaner or easier to reason about).
474
474
[ impl item example ] : #impl-item-example
475
475
476
476
``` rust
477
- pub struct S ;
477
+ pub struct S ( i32 ) ;
478
478
479
479
mod a {
480
- pub fn call_foo (s : & S ) { s . foo (); }
480
+ pub fn call_foo (s : & super :: S ) { s . foo (); }
481
481
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
+ }
484
493
}
485
494
}
486
495
@@ -807,25 +816,7 @@ itself not accessible in `mod b`?
807
816
808
817
pnkfelix is personally inclined to make this sort of thing illegal,
809
818
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.
829
820
830
821
## Implicit Restriction Satisfaction (IRS: PUNPM )
831
822
You can’t perform that action at this time.
0 commit comments