@@ -24,6 +24,7 @@ import syntax::ast::{ty_u8, ty_uint, variant, view_item, view_item_export};
24
24
import syntax:: ast:: { view_item_import, view_item_use, view_path_glob} ;
25
25
import syntax:: ast:: { view_path_list, view_path_simple} ;
26
26
import syntax:: ast_util:: { def_id_of_def, local_def, new_def_hash, walk_pat} ;
27
+ import syntax:: attr:: { attr_metas, contains_name} ;
27
28
import syntax:: codemap:: span;
28
29
import syntax:: visit:: { default_visitor, fk_method, mk_vt, visit_block} ;
29
30
import syntax:: visit:: { visit_crate, visit_expr, visit_expr_opt, visit_fn} ;
@@ -125,11 +126,6 @@ enum ResolveResult<T> {
125
126
Success ( T ) // Successfully resolved the import.
126
127
}
127
128
128
- enum PrivacyFilter {
129
- PrivateOrPublic , //< Will match both public and private items.
130
- PublicOnly //< Will match only public items.
131
- }
132
-
133
129
enum TypeParameters /& {
134
130
NoTypeParameters , //< No type parameters.
135
131
HasTypeParameters ( & ~[ ty_param ] , //< Type parameters.
@@ -161,6 +157,18 @@ enum RibKind {
161
157
FunctionRibKind ( node_id )
162
158
}
163
159
160
+ // The X-ray flag indicates that a context has the X-ray privilege, which
161
+ // allows it to reference private names. Currently, this is used for the test
162
+ // runner.
163
+ //
164
+ // XXX: The X-ray flag is kind of questionable in the first place. It might
165
+ // be better to introduce an expr_xray_path instead.
166
+
167
+ enum XrayFlag {
168
+ NoXray , //< Private items cannot be accessed.
169
+ Xray //< Private items can be accessed.
170
+ }
171
+
164
172
// FIXME (issue #2550): Should be a class but then it becomes not implicitly
165
173
// copyable due to a kind bug.
166
174
@@ -380,17 +388,6 @@ class Module {
380
388
}
381
389
}
382
390
383
- pure fn is_crate_root ( module : @Module ) -> bool {
384
- alt module. def_id {
385
- none => {
386
- ret false ;
387
- }
388
- some ( def_id) => {
389
- ret def_id. crate == 0 && def_id. node == 0 ;
390
- }
391
- }
392
- }
393
-
394
391
// XXX: This is a workaround due to is_none in the standard library mistakenly
395
392
// requiring a T:copy.
396
393
@@ -566,6 +563,10 @@ class Resolver {
566
563
// The current set of local scopes, for types.
567
564
let type_ribs: @dvec < @Rib > ;
568
565
566
+ // Whether the current context is an X-ray context. An X-ray context is
567
+ // allowed to access private names of any module.
568
+ let mut xray_context: XrayFlag ;
569
+
569
570
// The atom for the keyword "self".
570
571
let self_atom: Atom ;
571
572
@@ -598,6 +599,7 @@ class Resolver {
598
599
self . current_module = ( * self . graph_root ) . get_module ( ) ;
599
600
self . value_ribs = @dvec ( ) ;
600
601
self . type_ribs = @dvec ( ) ;
602
+ self . xray_context = NoXray ;
601
603
602
604
self . self_atom = ( * self . atom_table ) . intern ( @"self ") ;
603
605
self . primitive_type_table = @PrimitiveTypeTable ( self . atom_table ) ;
@@ -1442,7 +1444,10 @@ class Resolver {
1442
1444
import_directive) ;
1443
1445
} else {
1444
1446
// First, resolve the module path for the directive, if necessary.
1445
- alt self . resolve_module_path_for_import ( module, module_path) {
1447
+ alt self . resolve_module_path_for_import ( module,
1448
+ module_path,
1449
+ NoXray ) {
1450
+
1446
1451
Failed {
1447
1452
resolution_result = Failed ;
1448
1453
}
@@ -1869,8 +1874,10 @@ class Resolver {
1869
1874
1870
1875
fn resolve_module_path_from_root ( module : @Module ,
1871
1876
module_path : @dvec < Atom > ,
1872
- index : uint )
1877
+ index : uint ,
1878
+ xray : XrayFlag )
1873
1879
-> ResolveResult < @Module > {
1880
+
1874
1881
let mut search_module = module;
1875
1882
let mut index = index;
1876
1883
let module_path_len = ( * module_path) . len ( ) ;
@@ -1882,7 +1889,7 @@ class Resolver {
1882
1889
while index < module_path_len {
1883
1890
let name = ( * module_path) . get_elt ( index) ;
1884
1891
alt self. resolve_name_in_module ( search_module, name, ModuleNS ,
1885
- PublicOnly ) {
1892
+ xray ) {
1886
1893
1887
1894
Failed {
1888
1895
// XXX: span_err
@@ -1925,7 +1932,8 @@ class Resolver {
1925
1932
the given module.
1926
1933
" ]
1927
1934
fn resolve_module_path_for_import ( module : @Module ,
1928
- module_path : @dvec < Atom > )
1935
+ module_path : @dvec < Atom > ,
1936
+ xray : XrayFlag )
1929
1937
-> ResolveResult < @Module > {
1930
1938
1931
1939
let module_path_len = ( * module_path) . len ( ) ;
@@ -1961,7 +1969,8 @@ class Resolver {
1961
1969
1962
1970
ret self. resolve_module_path_from_root ( search_module,
1963
1971
module_path,
1964
- 1 u) ;
1972
+ 1 u,
1973
+ xray) ;
1965
1974
}
1966
1975
1967
1976
fn resolve_item_in_lexical_scope ( module : @Module ,
@@ -2030,7 +2039,7 @@ class Resolver {
2030
2039
2031
2040
// Resolve the name in the parent module.
2032
2041
alt self. resolve_name_in_module ( search_module, name, namespace,
2033
- PrivateOrPublic ) {
2042
+ Xray ) {
2034
2043
Failed {
2035
2044
// Continue up the search chain.
2036
2045
}
@@ -2092,16 +2101,14 @@ class Resolver {
2092
2101
fn resolve_name_in_module ( module : @Module ,
2093
2102
name : Atom ,
2094
2103
namespace : Namespace ,
2095
- privacy_filter : PrivacyFilter )
2104
+ xray : XrayFlag )
2096
2105
-> ResolveResult < Target > {
2097
2106
2098
2107
#debug ( "(resolving name in module) resolving '%s' in '%s'" ,
2099
2108
* ( * self . atom_table ) . atom_to_str ( name) ,
2100
2109
self . module_to_str ( module) ) ;
2101
2110
2102
- if privacy_filter == PublicOnly &&
2103
- !self . name_is_exported ( module, name) {
2104
-
2111
+ if xray == NoXray && !self . name_is_exported ( module, name) {
2105
2112
#debug ( "(resolving name in module) name '%s' is unexported" ,
2106
2113
* ( * self . atom_table ) . atom_to_str ( name) ) ;
2107
2114
ret Failed ;
@@ -2711,6 +2718,13 @@ class Resolver {
2711
2718
fn resolve_item ( item : @item, visitor : ResolveVisitor ) {
2712
2719
#debug ( "(resolving item) resolving %s" , * item. ident ) ;
2713
2720
2721
+ // Items with the !resolve_unexported attribute are X-ray contexts.
2722
+ // This is used to allow the test runner to run unexported tests.
2723
+ let orig_xray_flag = self . xray_context ;
2724
+ if contains_name ( attr_metas ( item. attrs ) , "!resolve_unexported" ) {
2725
+ self . xray_context = Xray ;
2726
+ }
2727
+
2714
2728
alt item. node {
2715
2729
item_enum ( _, type_parameters, _) |
2716
2730
item_ty ( _, type_parameters, _) {
@@ -2821,7 +2835,6 @@ class Resolver {
2821
2835
2822
2836
if !self . session . building_library &&
2823
2837
is_none ( self . session . main_fn ) &&
2824
- is_crate_root ( self . current_module ) &&
2825
2838
str:: eq ( * item. ident , "main" ) {
2826
2839
2827
2840
self . session . main_fn = some ( ( item. id , item. span ) ) ;
@@ -2842,10 +2855,11 @@ class Resolver {
2842
2855
visit_item ( item, ( ) , visitor) ;
2843
2856
}
2844
2857
}
2858
+
2859
+ self . xray_context = orig_xray_flag;
2845
2860
}
2846
2861
2847
2862
fn with_type_parameter_rib ( type_parameters : TypeParameters , f : fn ( ) ) {
2848
-
2849
2863
alt type_parameters {
2850
2864
HasTypeParameters ( type_parameters, node_id, initial_index)
2851
2865
if ( * type_parameters) . len ( ) >= 1 u {
@@ -3496,11 +3510,15 @@ class Resolver {
3496
3510
}
3497
3511
3498
3512
if path. global {
3499
- ret self . resolve_crate_relative_path ( path, namespace) ;
3513
+ ret self . resolve_crate_relative_path ( path,
3514
+ self . xray_context ,
3515
+ namespace) ;
3500
3516
}
3501
3517
3502
3518
if path. idents . len ( ) > 1 u {
3503
- ret self . resolve_module_relative_path ( path, namespace) ;
3519
+ ret self . resolve_module_relative_path ( path,
3520
+ self . xray_context ,
3521
+ namespace) ;
3504
3522
}
3505
3523
3506
3524
ret self. resolve_identifier ( path. idents . last ( ) ,
@@ -3593,14 +3611,17 @@ class Resolver {
3593
3611
ret module_path_atoms;
3594
3612
}
3595
3613
3596
- fn resolve_module_relative_path ( path : @path, namespace : Namespace )
3614
+ fn resolve_module_relative_path ( path : @path,
3615
+ +xray : XrayFlag ,
3616
+ namespace : Namespace )
3597
3617
-> option < def > {
3598
3618
3599
3619
let module_path_atoms = self . intern_module_part_of_path ( path) ;
3600
3620
3601
3621
let mut containing_module;
3602
3622
alt self. resolve_module_path_for_import ( self . current_module ,
3603
- module_path_atoms) {
3623
+ module_path_atoms,
3624
+ xray) {
3604
3625
3605
3626
Failed {
3606
3627
self. session . span_err ( path. span ,
@@ -3640,7 +3661,9 @@ class Resolver {
3640
3661
}
3641
3662
}
3642
3663
3643
- fn resolve_crate_relative_path ( path : @path, namespace : Namespace )
3664
+ fn resolve_crate_relative_path ( path : @path,
3665
+ +xray : XrayFlag ,
3666
+ namespace : Namespace )
3644
3667
-> option < def > {
3645
3668
3646
3669
let module_path_atoms = self . intern_module_part_of_path ( path) ;
@@ -3650,7 +3673,8 @@ class Resolver {
3650
3673
let mut containing_module;
3651
3674
alt self. resolve_module_path_from_root ( root_module,
3652
3675
module_path_atoms,
3653
- 0 u) {
3676
+ 0 u,
3677
+ xray) {
3654
3678
3655
3679
Failed {
3656
3680
self. session . span_err ( path. span ,
0 commit comments