@@ -81,6 +81,7 @@ enum ResolutionFailure<'a> {
81
81
}
82
82
83
83
impl ResolutionFailure < ' a > {
84
+ // A partial or full resolution
84
85
fn res ( & self ) -> Option < Res > {
85
86
use ResolutionFailure :: * ;
86
87
match self {
@@ -93,6 +94,14 @@ impl ResolutionFailure<'a> {
93
94
NotInScope ( _) | NoParentItem | Dummy => None ,
94
95
}
95
96
}
97
+
98
+ // This resolved fully (not just partially) but is erroneous for some other reason
99
+ fn full_res ( & self ) -> Option < Res > {
100
+ match self {
101
+ Self :: WrongNamespace ( res, _) => Some ( * res) ,
102
+ _ => None ,
103
+ }
104
+ }
96
105
}
97
106
98
107
enum AnchorFailure {
@@ -128,6 +137,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
128
137
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
129
138
let cx = self . cx ;
130
139
140
+ debug ! ( "looking for enum variant {}" , path_str) ;
131
141
let mut split = path_str. rsplitn ( 3 , "::" ) ;
132
142
let variant_field_name = split
133
143
. next ( )
@@ -260,7 +270,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
260
270
debug ! ( "{} resolved to {:?} in namespace {:?}" , path_str, result, ns) ;
261
271
let result = match result {
262
272
Ok ( ( _, Res :: Err ) ) => Err ( ( ) ) ,
263
- _ => result . map_err ( |_| ( ) ) ,
273
+ x => x ,
264
274
} ;
265
275
266
276
if let Ok ( ( _, res) ) = result {
@@ -419,6 +429,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
419
429
Ok ( ( ty_res, Some ( format ! ( "{}.{}" , out, item_name) ) ) )
420
430
} )
421
431
} else if ns == Namespace :: ValueNS {
432
+ debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
422
433
match cx. tcx . type_of ( did) . kind ( ) {
423
434
ty:: Adt ( def, _) => {
424
435
let field = if def. is_enum ( ) {
@@ -838,12 +849,36 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
838
849
}
839
850
}
840
851
852
+ // used for reporting better errors
853
+ let check_full_res = |this : & mut Self , ns| {
854
+ match this. resolve ( path_str, ns, & current_item, base_node, & extra_fragment) {
855
+ Ok ( res) => {
856
+ debug ! (
857
+ "check_full_res: saw res for {} in {:?} ns: {:?}" ,
858
+ path_str, ns, res. 0
859
+ ) ;
860
+ Some ( res. 0 )
861
+ }
862
+ Err ( ErrorKind :: Resolve ( kind) ) => kind. full_res ( ) ,
863
+ // TODO: add `Res` to AnchorFailure
864
+ Err ( ErrorKind :: AnchorFailure ( _) ) => None ,
865
+ }
866
+ } ;
867
+
841
868
match disambiguator. map ( Disambiguator :: ns) {
842
869
Some ( ns @ ( ValueNS | TypeNS ) ) => {
843
870
match self . resolve ( path_str, ns, & current_item, base_node, & extra_fragment)
844
871
{
845
872
Ok ( res) => res,
846
- Err ( ErrorKind :: Resolve ( kind) ) => {
873
+ Err ( ErrorKind :: Resolve ( mut kind) ) => {
874
+ // We only looked in one namespace. Try to give a better error if possible.
875
+ // TODO: handle MacroNS too
876
+ if kind. full_res ( ) . is_none ( ) {
877
+ let other_ns = if ns == ValueNS { TypeNS } else { ValueNS } ;
878
+ if let Some ( res) = check_full_res ( self , other_ns) {
879
+ kind = ResolutionFailure :: WrongNamespace ( res, other_ns) ;
880
+ }
881
+ }
847
882
resolution_failure (
848
883
cx,
849
884
& item,
@@ -965,30 +1000,14 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
965
1000
Ok ( res) => ( res, extra_fragment) ,
966
1001
Err ( mut kind) => {
967
1002
// `macro_resolve` only looks in the macro namespace. Try to give a better error if possible.
1003
+ //if kind.res().is_none() {
968
1004
for & ns in & [ TypeNS , ValueNS ] {
969
- match self . resolve (
970
- path_str,
971
- ns,
972
- & current_item,
973
- base_node,
974
- & extra_fragment,
975
- ) {
976
- Ok ( res) => {
977
- kind = ResolutionFailure :: WrongNamespace ( res. 0 , MacroNS )
978
- }
979
- // This will show up in the other namespace, no need to handle it here
980
- Err ( ErrorKind :: Resolve (
981
- ResolutionFailure :: WrongNamespace ( ..) ,
982
- ) ) => { }
983
- Err ( ErrorKind :: AnchorFailure ( _) ) => { }
984
- Err ( ErrorKind :: Resolve ( inner_kind) ) => {
985
- if let Some ( res) = inner_kind. res ( ) {
986
- kind =
987
- ResolutionFailure :: WrongNamespace ( res, MacroNS ) ;
988
- }
989
- }
1005
+ if let Some ( res) = check_full_res ( self , ns) {
1006
+ kind = ResolutionFailure :: WrongNamespace ( res, MacroNS ) ;
1007
+ break ;
990
1008
}
991
1009
}
1010
+ //}
992
1011
resolution_failure (
993
1012
cx,
994
1013
& item,
0 commit comments