@@ -16,7 +16,7 @@ use rustc_resolve::ParentScope;
16
16
use rustc_session:: lint:: Lint ;
17
17
use rustc_span:: hygiene:: MacroKind ;
18
18
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
19
- use rustc_span:: { BytePos , DUMMY_SP } ;
19
+ use rustc_span:: BytePos ;
20
20
use smallvec:: { smallvec, SmallVec } ;
21
21
22
22
use std:: borrow:: Cow ;
@@ -97,14 +97,6 @@ impl Res {
97
97
}
98
98
}
99
99
100
- fn as_hir_res ( self ) -> Option < rustc_hir:: def:: Res > {
101
- match self {
102
- Res :: Def ( kind, id) => Some ( rustc_hir:: def:: Res :: Def ( kind, id) ) ,
103
- // FIXME: maybe this should handle the subset of PrimitiveType that fits into hir::PrimTy?
104
- Res :: Primitive ( _) => None ,
105
- }
106
- }
107
-
108
100
/// Used for error reporting.
109
101
fn disambiguator_suggestion ( self ) -> Suggestion {
110
102
let kind = match self {
@@ -189,9 +181,6 @@ enum ResolutionFailure<'a> {
189
181
/// In `[std::io::Error::x]`, `x` would be unresolved.
190
182
unresolved : Cow < ' a , str > ,
191
183
} ,
192
- /// This happens when rustdoc can't determine the parent scope for an item.
193
- /// It is always a bug in rustdoc.
194
- NoParentItem ,
195
184
/// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
196
185
MalformedGenerics ( MalformedGenerics ) ,
197
186
/// Used to communicate that this should be ignored, but shouldn't be reported to the user.
@@ -616,8 +605,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
616
605
// item a separate function.
617
606
Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , _) => assert_eq ! ( ns, ValueNS ) ,
618
607
Res :: Def ( DefKind :: AssocTy , _) => assert_eq ! ( ns, TypeNS ) ,
619
- Res :: Def ( DefKind :: Variant , _) => {
620
- return handle_variant ( self . cx , res) ;
608
+ Res :: Def ( DefKind :: Variant , def_id) => {
609
+ let enum_def_id = self . cx . tcx . parent ( def_id) . expect ( "variant has no parent" ) ;
610
+ return Ok ( (
611
+ Res :: Def ( DefKind :: Enum , enum_def_id) ,
612
+ Some ( ItemFragment ( FragmentKind :: Variant , def_id) ) ,
613
+ ) ) ;
621
614
}
622
615
// Not a trait item; just return what we found.
623
616
_ => return Ok ( ( res, None ) ) ,
@@ -1268,19 +1261,7 @@ impl LinkCollector<'_, '_> {
1268
1261
// parent_node first.
1269
1262
let base_node =
1270
1263
if item. is_mod ( ) && inner_docs { self . mod_ids . last ( ) . copied ( ) } else { parent_node } ;
1271
-
1272
- let Some ( module_id) = base_node else {
1273
- // This is a bug.
1274
- debug ! ( "attempting to resolve item without parent module: {}" , path_str) ;
1275
- resolution_failure (
1276
- self ,
1277
- diag_info,
1278
- path_str,
1279
- disambiguator,
1280
- smallvec ! [ ResolutionFailure :: NoParentItem ] ,
1281
- ) ;
1282
- return None ;
1283
- } ;
1264
+ let module_id = base_node. expect ( "doc link without parent module" ) ;
1284
1265
1285
1266
let ( mut res, fragment) = self . resolve_with_disambiguator_cached (
1286
1267
ResolutionInfo {
@@ -2140,17 +2121,6 @@ fn resolution_failure(
2140
2121
expected_ns. descr( )
2141
2122
)
2142
2123
}
2143
- ResolutionFailure :: NoParentItem => {
2144
- // FIXME(eddyb) this doesn't belong here, whatever made
2145
- // the `ResolutionFailure::NoParentItem` should emit an
2146
- // immediate or delayed `span_bug` about the issue.
2147
- tcx. sess . delay_span_bug (
2148
- sp. unwrap_or ( DUMMY_SP ) ,
2149
- "intra-doc link missing parent item" ,
2150
- ) ;
2151
-
2152
- "BUG: all intra-doc links should have a parent item" . to_owned ( )
2153
- }
2154
2124
ResolutionFailure :: MalformedGenerics ( variant) => match variant {
2155
2125
MalformedGenerics :: UnbalancedAngleBrackets => {
2156
2126
String :: from ( "unbalanced angle brackets" )
@@ -2331,17 +2301,6 @@ fn privacy_error(cx: &DocContext<'_>, diag_info: &DiagnosticInfo<'_>, path_str:
2331
2301
} ) ;
2332
2302
}
2333
2303
2334
- /// Given an enum variant's res, return the res of its enum and the associated fragment.
2335
- fn handle_variant (
2336
- cx : & DocContext < ' _ > ,
2337
- res : Res ,
2338
- ) -> Result < ( Res , Option < ItemFragment > ) , ErrorKind < ' static > > {
2339
- let parent = cx. tcx . parent ( res. def_id ( cx. tcx ) ) ;
2340
- let parent_def = Res :: Def ( DefKind :: Enum , parent) ;
2341
- let variant = cx. tcx . expect_variant_res ( res. as_hir_res ( ) . unwrap ( ) ) ;
2342
- Ok ( ( parent_def, Some ( ItemFragment ( FragmentKind :: Variant , variant. def_id ) ) ) )
2343
- }
2344
-
2345
2304
/// Resolve a primitive type or value.
2346
2305
fn resolve_primitive ( path_str : & str , ns : Namespace ) -> Option < Res > {
2347
2306
if ns != TypeNS {
0 commit comments