@@ -383,14 +383,26 @@ fn encode_info_for_mod(ecx: @EncodeContext, ebml_w: writer::Encoder,
383
383
ebml_w. end_tag ( ) ;
384
384
}
385
385
386
- fn encode_visibility ( ebml_w : writer:: Encoder , visibility : visibility ) {
386
+ fn encode_struct_field_family ( ebml_w : writer:: Encoder ,
387
+ visibility : visibility ) {
387
388
encode_family ( ebml_w, match visibility {
388
389
public => 'g' ,
389
390
private => 'j' ,
390
391
inherited => 'N'
391
392
} ) ;
392
393
}
393
394
395
+ fn encode_visibility ( ebml_w : writer:: Encoder , visibility : visibility ) {
396
+ ebml_w. start_tag ( tag_items_data_item_visibility) ;
397
+ let ch = match visibility {
398
+ public => 'y' ,
399
+ private => 'n' ,
400
+ inherited => 'i' ,
401
+ } ;
402
+ ebml_w. wr_str ( str:: from_char ( ch) ) ;
403
+ ebml_w. end_tag ( ) ;
404
+ }
405
+
394
406
fn encode_self_type ( ebml_w : writer:: Encoder , self_type : ast:: self_ty_ ) {
395
407
ebml_w. start_tag ( tag_item_trait_method_self_ty) ;
396
408
@@ -456,7 +468,7 @@ fn encode_info_for_struct(ecx: @EncodeContext, ebml_w: writer::Encoder,
456
468
ebml_w. start_tag ( tag_items_data_item) ;
457
469
debug ! ( "encode_info_for_struct: doing %s %d" ,
458
470
* tcx. sess. str_of( nm) , id) ;
459
- encode_visibility ( ebml_w, vis) ;
471
+ encode_struct_field_family ( ebml_w, vis) ;
460
472
encode_name ( ecx, ebml_w, nm) ;
461
473
encode_path ( ecx, ebml_w, path, ast_map:: path_name ( nm) ) ;
462
474
encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
@@ -525,6 +537,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
525
537
should_inline : bool ,
526
538
parent_id : node_id ,
527
539
m : @method ,
540
+ parent_visibility : ast:: visibility ,
528
541
owner_generics : & ast:: Generics ,
529
542
method_generics : & ast:: Generics ) {
530
543
debug ! ( "encode_info_for_method: %d %s %u %u" , m. id,
@@ -533,6 +546,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
533
546
method_generics. ty_params. len( ) ) ;
534
547
ebml_w. start_tag ( tag_items_data_item) ;
535
548
encode_def_id ( ebml_w, local_def ( m. id ) ) ;
549
+
536
550
match m. self_ty . node {
537
551
ast:: sty_static => {
538
552
encode_family ( ebml_w, purity_static_method_family ( m. purity ) ) ;
@@ -550,6 +564,14 @@ fn encode_info_for_method(ecx: @EncodeContext,
550
564
encode_name ( ecx, ebml_w, m. ident ) ;
551
565
encode_path ( ecx, ebml_w, impl_path, ast_map:: path_name ( m. ident ) ) ;
552
566
encode_self_type ( ebml_w, m. self_ty . node ) ;
567
+
568
+ // Combine parent visibility and this visibility.
569
+ let visibility = match m. vis {
570
+ ast:: inherited => parent_visibility,
571
+ vis => vis,
572
+ } ;
573
+ encode_visibility ( ebml_w, visibility) ;
574
+
553
575
if len > 0 u || should_inline {
554
576
( ecx. encode_inlined_item ) (
555
577
ecx, ebml_w, impl_path,
@@ -568,6 +590,7 @@ fn purity_fn_family(p: purity) -> char {
568
590
extern_fn => 'e'
569
591
}
570
592
}
593
+
571
594
fn purity_static_method_family( p : purity ) -> char {
572
595
match p {
573
596
unsafe_fn => 'U' ,
@@ -757,7 +780,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
757
780
match f.node.kind {
758
781
named_field(ident, _, vis) => {
759
782
ebml_w.start_tag(tag_item_field);
760
- encode_visibility (ebml_w, vis);
783
+ encode_struct_field_family (ebml_w, vis);
761
784
encode_name(ecx, ebml_w, ident);
762
785
encode_def_id(ebml_w, local_def(f.node.id));
763
786
ebml_w.end_tag();
@@ -808,12 +831,28 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
808
831
let mut impl_path = vec::append(~[], path);
809
832
impl_path += ~[ast_map::path_name(item.ident)];
810
833
834
+ // If there is a trait reference, treat the methods as always public.
835
+ // This is to work around some incorrect behavior in privacy checking:
836
+ // when the method belongs to a trait, it should acquire the privacy
837
+ // from the trait, not the impl. Forcing the visibility to be public
838
+ // makes things sorta work.
839
+ let parent_visibility = if opt_trait.is_some() {
840
+ ast::public
841
+ } else {
842
+ item.vis
843
+ };
844
+
811
845
for methods.each |m| {
812
846
index.push(entry {val: m.id, pos: ebml_w.writer.tell()});
813
- encode_info_for_method(ecx, ebml_w, impl_path,
847
+ encode_info_for_method(ecx,
848
+ ebml_w,
849
+ impl_path,
814
850
should_inline(m.attrs),
815
- item.id, *m,
816
- generics, &m.generics);
851
+ item.id,
852
+ *m,
853
+ parent_visibility,
854
+ generics,
855
+ &m.generics);
817
856
}
818
857
}
819
858
item_trait(ref generics, ref traits, ref ms) => {
@@ -902,9 +941,15 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
902
941
// of provided methods. I am not sure why this is. -ndm
903
942
let owner_generics = ast_util::empty_generics();
904
943
905
- encode_info_for_method(ecx, ebml_w, /*bad*/copy path,
906
- true, item.id, *m,
907
- &owner_generics, &m.generics);
944
+ encode_info_for_method(ecx,
945
+ ebml_w,
946
+ /*bad*/copy path,
947
+ true,
948
+ item.id,
949
+ *m,
950
+ item.vis,
951
+ &owner_generics,
952
+ &m.generics);
908
953
}
909
954
}
910
955
item_mac(*) => fail!(~" item macros unimplemented")
0 commit comments