@@ -848,10 +848,8 @@ impl AttributesExt for Attributes {
848
848
/// they exist in both namespaces (structs and modules)
849
849
fn value_ns_kind ( def : Def , path_str : & str ) -> Option < ( & ' static str , String ) > {
850
850
match def {
851
- // structs and mods exist in both namespaces. skip them
852
- Def :: StructCtor ( ..) | Def :: Mod ( ..) => None ,
853
- Def :: Variant ( ..) | Def :: VariantCtor ( ..)
854
- => Some ( ( "variant" , format ! ( "{}()" , path_str) ) ) ,
851
+ // structs, variants, and mods exist in both namespaces. skip them
852
+ Def :: StructCtor ( ..) | Def :: Mod ( ..) | Def :: Variant ( ..) | Def :: VariantCtor ( ..) => None ,
855
853
Def :: Fn ( ..)
856
854
=> Some ( ( "function" , format ! ( "{}()" , path_str) ) ) ,
857
855
Def :: Method ( ..)
@@ -897,6 +895,20 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
897
895
. emit ( ) ;
898
896
}
899
897
898
+ /// Given an enum variant's def, return the def of its enum and the associated fragment
899
+ fn handle_variant ( cx : & DocContext , def : Def ) -> Result < ( Def , Option < String > ) , ( ) > {
900
+ use rustc:: ty:: DefIdTree ;
901
+
902
+ let parent = if let Some ( parent) = cx. tcx . parent ( def. def_id ( ) ) {
903
+ parent
904
+ } else {
905
+ return Err ( ( ) )
906
+ } ;
907
+ let parent_def = Def :: Enum ( parent) ;
908
+ let variant = cx. tcx . expect_variant_def ( def) ;
909
+ Ok ( ( parent_def, Some ( format ! ( "{}.v" , variant. name) ) ) )
910
+ }
911
+
900
912
/// Resolve a given string as a path, along with whether or not it is
901
913
/// in the value namespace. Also returns an optional URL fragment in the case
902
914
/// of variants and methods
@@ -917,6 +929,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
917
929
let value = match result. def {
918
930
Def :: Method ( _) | Def :: AssociatedConst ( _) => true ,
919
931
Def :: AssociatedTy ( _) => false ,
932
+ Def :: Variant ( _) => return handle_variant ( cx, result. def ) ,
920
933
// not a trait item, just return what we found
921
934
_ => return Ok ( ( result. def , None ) )
922
935
} ;
0 commit comments