@@ -291,20 +291,40 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
291
291
resolver. resolve_str_path_error ( DUMMY_SP , & path_str, ns, module_id)
292
292
} ) ;
293
293
debug ! ( "{} resolved to {:?} in namespace {:?}" , path_str, result, ns) ;
294
- let result = match result {
295
- Ok ( ( _, Res :: Err ) ) => Err ( ( ) ) ,
296
- x => x,
294
+ let result = match result. map ( |( _, res) | res) {
295
+ Ok ( Res :: Err ) | Err ( ( ) ) => {
296
+ // resolver doesn't know about true and false so we'll have to resolve them
297
+ // manually as bool
298
+ if let Some ( ( _, res) ) = is_bool_value ( path_str, ns) { Ok ( res) } else { Err ( ( ) ) }
299
+ }
300
+ Ok ( res) => Ok ( res. map_id ( |_| panic ! ( "unexpected node_id" ) ) ) ,
297
301
} ;
298
302
299
- if let Ok ( ( _, res) ) = result {
300
- let res = res. map_id ( |_| panic ! ( "unexpected node_id" ) ) ;
301
- // In case this is a trait item, skip the
302
- // early return and try looking for the trait.
303
- let value = match res {
304
- Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , _) => true ,
305
- Res :: Def ( DefKind :: AssocTy , _) => false ,
303
+ if let Ok ( res) = result {
304
+ match res {
305
+ Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , _) => {
306
+ if ns != ValueNS {
307
+ return Err ( ResolutionFailure :: WrongNamespace ( res, ns) . into ( ) ) ;
308
+ } else {
309
+ // In case this is a trait item, skip the
310
+ // early return and try looking for the trait.
311
+ }
312
+ }
313
+ Res :: Def ( DefKind :: AssocTy , _) => {
314
+ if ns == ValueNS {
315
+ return Err ( ResolutionFailure :: WrongNamespace ( res, ns) . into ( ) ) ;
316
+ } else {
317
+ // In case this is a trait item, skip the
318
+ // early return and try looking for the trait.
319
+ }
320
+ }
306
321
Res :: Def ( DefKind :: Variant , _) => {
307
- return handle_variant ( cx, res, extra_fragment) ;
322
+ if extra_fragment. is_some ( ) {
323
+ return Err ( ErrorKind :: AnchorFailure (
324
+ AnchorFailure :: RustdocAnchorConflict ( res) ,
325
+ ) ) ;
326
+ }
327
+ return handle_variant ( cx, res) ;
308
328
}
309
329
// Not a trait item; just return what we found.
310
330
Res :: PrimTy ( ty) => {
@@ -321,17 +341,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
321
341
_ => {
322
342
return Ok ( ( res, extra_fragment. clone ( ) ) ) ;
323
343
}
324
- } ;
325
-
326
- if value != ( ns == ValueNS ) {
327
- return Err ( ResolutionFailure :: WrongNamespace ( res, ns) . into ( ) ) ;
328
344
}
329
- // FIXME: why is this necessary?
330
- } else if let Some ( ( path, prim) ) = is_primitive ( path_str, ns) {
331
- if extra_fragment. is_some ( ) {
332
- return Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( prim) ) ) ;
333
- }
334
- return Ok ( ( prim, Some ( path. to_owned ( ) ) ) ) ;
335
345
}
336
346
337
347
// Try looking for methods and associated items.
@@ -1936,21 +1946,17 @@ fn privacy_error(
1936
1946
fn handle_variant (
1937
1947
cx : & DocContext < ' _ > ,
1938
1948
res : Res ,
1939
- extra_fragment : & Option < String > ,
1940
1949
) -> Result < ( Res , Option < String > ) , ErrorKind < ' static > > {
1941
1950
use rustc_middle:: ty:: DefIdTree ;
1942
1951
1943
- if extra_fragment. is_some ( ) {
1944
- return Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( res) ) ) ;
1945
- }
1946
- let parent = if let Some ( parent) = cx. tcx . parent ( res. def_id ( ) ) {
1947
- parent
1948
- } else {
1949
- return Err ( ResolutionFailure :: NoParentItem . into ( ) ) ;
1950
- } ;
1951
- let parent_def = Res :: Def ( DefKind :: Enum , parent) ;
1952
- let variant = cx. tcx . expect_variant_res ( res) ;
1953
- Ok ( ( parent_def, Some ( format ! ( "variant.{}" , variant. ident. name) ) ) )
1952
+ cx. tcx . parent ( res. def_id ( ) ) . map_or_else (
1953
+ || Err ( ResolutionFailure :: NoParentItem . into ( ) ) ,
1954
+ |parent| {
1955
+ let parent_def = Res :: Def ( DefKind :: Enum , parent) ;
1956
+ let variant = cx. tcx . expect_variant_res ( res) ;
1957
+ Ok ( ( parent_def, Some ( format ! ( "variant.{}" , variant. ident. name) ) ) )
1958
+ } ,
1959
+ )
1954
1960
}
1955
1961
1956
1962
const PRIMITIVES : & [ ( & str , Res ) ] = & [
@@ -1970,19 +1976,16 @@ const PRIMITIVES: &[(&str, Res)] = &[
1970
1976
( "f64" , Res :: PrimTy ( hir:: PrimTy :: Float ( rustc_ast:: FloatTy :: F64 ) ) ) ,
1971
1977
( "str" , Res :: PrimTy ( hir:: PrimTy :: Str ) ) ,
1972
1978
( "bool" , Res :: PrimTy ( hir:: PrimTy :: Bool ) ) ,
1973
- ( "true" , Res :: PrimTy ( hir:: PrimTy :: Bool ) ) ,
1974
- ( "false" , Res :: PrimTy ( hir:: PrimTy :: Bool ) ) ,
1975
1979
( "char" , Res :: PrimTy ( hir:: PrimTy :: Char ) ) ,
1976
1980
] ;
1977
1981
1978
1982
fn is_primitive ( path_str : & str , ns : Namespace ) -> Option < ( & ' static str , Res ) > {
1979
- if ns == TypeNS {
1980
- PRIMITIVES
1981
- . iter ( )
1982
- . filter ( |x| x. 0 == path_str)
1983
- . copied ( )
1984
- . map ( |x| if x. 0 == "true" || x. 0 == "false" { ( "bool" , x. 1 ) } else { x } )
1985
- . next ( )
1983
+ if ns == TypeNS { PRIMITIVES . iter ( ) . find ( |x| x. 0 == path_str) . copied ( ) } else { None }
1984
+ }
1985
+
1986
+ fn is_bool_value ( path_str : & str , ns : Namespace ) -> Option < ( & ' static str , Res ) > {
1987
+ if ns == TypeNS && ( path_str == "true" || path_str == "false" ) {
1988
+ Some ( ( "bool" , Res :: PrimTy ( hir:: PrimTy :: Bool ) ) )
1986
1989
} else {
1987
1990
None
1988
1991
}
0 commit comments