@@ -30,9 +30,7 @@ use std::convert::{TryFrom, TryInto};
30
30
use std:: mem;
31
31
use std:: ops:: Range ;
32
32
33
- use crate :: clean:: {
34
- self , utils:: find_nearest_parent_module, Crate , FakeDefId , Item , ItemLink , PrimitiveType ,
35
- } ;
33
+ use crate :: clean:: { self , utils:: find_nearest_parent_module, Crate , Item , ItemLink , PrimitiveType } ;
36
34
use crate :: core:: DocContext ;
37
35
use crate :: fold:: DocFolder ;
38
36
use crate :: html:: markdown:: { markdown_links, MarkdownLink } ;
@@ -248,7 +246,7 @@ enum AnchorFailure {
248
246
249
247
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
250
248
struct ResolutionInfo {
251
- module_id : FakeDefId ,
249
+ module_id : DefId ,
252
250
dis : Option < Disambiguator > ,
253
251
path_str : String ,
254
252
extra_fragment : Option < String > ,
@@ -274,7 +272,7 @@ struct LinkCollector<'a, 'tcx> {
274
272
///
275
273
/// The last module will be used if the parent scope of the current item is
276
274
/// unknown.
277
- mod_ids : Vec < FakeDefId > ,
275
+ mod_ids : Vec < DefId > ,
278
276
/// This is used to store the kind of associated items,
279
277
/// because `clean` and the disambiguator code expect them to be different.
280
278
/// See the code for associated items on inherent impls for details.
@@ -861,7 +859,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
861
859
let inner_docs = item. inner_docs ( self . cx . tcx ) ;
862
860
863
861
if item. is_mod ( ) && inner_docs {
864
- self . mod_ids . push ( item. def_id ) ;
862
+ self . mod_ids . push ( item. def_id . expect_real ( ) ) ;
865
863
}
866
864
867
865
// We want to resolve in the lexical scope of the documentation.
@@ -888,7 +886,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
888
886
889
887
Some ( if item. is_mod ( ) {
890
888
if !inner_docs {
891
- self . mod_ids . push ( item. def_id ) ;
889
+ self . mod_ids . push ( item. def_id . expect_real ( ) ) ;
892
890
}
893
891
894
892
let ret = self . fold_item_recur ( item) ;
@@ -1070,11 +1068,8 @@ impl LinkCollector<'_, '_> {
1070
1068
// we've already pushed this node onto the resolution stack but
1071
1069
// for outer comments we explicitly try and resolve against the
1072
1070
// parent_node first.
1073
- let base_node = if item. is_mod ( ) && inner_docs {
1074
- self . mod_ids . last ( ) . copied ( )
1075
- } else {
1076
- parent_node. map ( |id| FakeDefId :: new_real ( id) )
1077
- } ;
1071
+ let base_node =
1072
+ if item. is_mod ( ) && inner_docs { self . mod_ids . last ( ) . copied ( ) } else { parent_node } ;
1078
1073
1079
1074
let mut module_id = if let Some ( id) = base_node {
1080
1075
id
@@ -1119,7 +1114,7 @@ impl LinkCollector<'_, '_> {
1119
1114
resolved_self = format ! ( "self::{}" , & path_str[ "crate::" . len( ) ..] ) ;
1120
1115
path_str = & resolved_self;
1121
1116
}
1122
- module_id = FakeDefId :: new_real ( DefId { krate, index : CRATE_DEF_INDEX } ) ;
1117
+ module_id = DefId { krate, index : CRATE_DEF_INDEX } ;
1123
1118
}
1124
1119
1125
1120
let ( mut res, mut fragment) = self . resolve_with_disambiguator_cached (
@@ -1180,8 +1175,8 @@ impl LinkCollector<'_, '_> {
1180
1175
report_diagnostic ( self . cx . tcx , BROKEN_INTRA_DOC_LINKS , & msg, & diag_info, callback) ;
1181
1176
} ;
1182
1177
1183
- let verify = |kind : DefKind , id : FakeDefId | {
1184
- let ( kind, id) = self . kind_side_channel . take ( ) . unwrap_or ( ( kind, id. expect_real ( ) ) ) ;
1178
+ let verify = |kind : DefKind , id : DefId | {
1179
+ let ( kind, id) = self . kind_side_channel . take ( ) . unwrap_or ( ( kind, id) ) ;
1185
1180
debug ! ( "intra-doc link to {} resolved to {:?} (id: {:?})" , path_str, res, id) ;
1186
1181
1187
1182
// Disallow e.g. linking to enums with `struct@`
@@ -1341,7 +1336,7 @@ impl LinkCollector<'_, '_> {
1341
1336
1342
1337
match disambiguator. map ( Disambiguator :: ns) {
1343
1338
Some ( expected_ns @ ( ValueNS | TypeNS ) ) => {
1344
- match self . resolve ( path_str, expected_ns, base_node. expect_real ( ) , extra_fragment) {
1339
+ match self . resolve ( path_str, expected_ns, base_node, extra_fragment) {
1345
1340
Ok ( res) => Some ( res) ,
1346
1341
Err ( ErrorKind :: Resolve ( box mut kind) ) => {
1347
1342
// We only looked in one namespace. Try to give a better error if possible.
@@ -1350,12 +1345,9 @@ impl LinkCollector<'_, '_> {
1350
1345
// FIXME: really it should be `resolution_failure` that does this, not `resolve_with_disambiguator`
1351
1346
// See https://github.com/rust-lang/rust/pull/76955#discussion_r493953382 for a good approach
1352
1347
for & new_ns in & [ other_ns, MacroNS ] {
1353
- if let Some ( res) = self . check_full_res (
1354
- new_ns,
1355
- path_str,
1356
- base_node. expect_real ( ) ,
1357
- extra_fragment,
1358
- ) {
1348
+ if let Some ( res) =
1349
+ self . check_full_res ( new_ns, path_str, base_node, extra_fragment)
1350
+ {
1359
1351
kind = ResolutionFailure :: WrongNamespace { res, expected_ns } ;
1360
1352
break ;
1361
1353
}
@@ -1377,14 +1369,9 @@ impl LinkCollector<'_, '_> {
1377
1369
// Try everything!
1378
1370
let mut candidates = PerNS {
1379
1371
macro_ns : self
1380
- . resolve_macro ( path_str, base_node. expect_real ( ) )
1372
+ . resolve_macro ( path_str, base_node)
1381
1373
. map ( |res| ( res, extra_fragment. clone ( ) ) ) ,
1382
- type_ns : match self . resolve (
1383
- path_str,
1384
- TypeNS ,
1385
- base_node. expect_real ( ) ,
1386
- extra_fragment,
1387
- ) {
1374
+ type_ns : match self . resolve ( path_str, TypeNS , base_node, extra_fragment) {
1388
1375
Ok ( res) => {
1389
1376
debug ! ( "got res in TypeNS: {:?}" , res) ;
1390
1377
Ok ( res)
@@ -1395,12 +1382,7 @@ impl LinkCollector<'_, '_> {
1395
1382
}
1396
1383
Err ( ErrorKind :: Resolve ( box kind) ) => Err ( kind) ,
1397
1384
} ,
1398
- value_ns : match self . resolve (
1399
- path_str,
1400
- ValueNS ,
1401
- base_node. expect_real ( ) ,
1402
- extra_fragment,
1403
- ) {
1385
+ value_ns : match self . resolve ( path_str, ValueNS , base_node, extra_fragment) {
1404
1386
Ok ( res) => Ok ( res) ,
1405
1387
Err ( ErrorKind :: AnchorFailure ( msg) ) => {
1406
1388
anchor_failure ( self . cx , diag, msg) ;
@@ -1456,17 +1438,14 @@ impl LinkCollector<'_, '_> {
1456
1438
}
1457
1439
}
1458
1440
Some ( MacroNS ) => {
1459
- match self . resolve_macro ( path_str, base_node. expect_real ( ) ) {
1441
+ match self . resolve_macro ( path_str, base_node) {
1460
1442
Ok ( res) => Some ( ( res, extra_fragment. clone ( ) ) ) ,
1461
1443
Err ( mut kind) => {
1462
1444
// `resolve_macro` only looks in the macro namespace. Try to give a better error if possible.
1463
1445
for & ns in & [ TypeNS , ValueNS ] {
1464
- if let Some ( res) = self . check_full_res (
1465
- ns,
1466
- path_str,
1467
- base_node. expect_real ( ) ,
1468
- extra_fragment,
1469
- ) {
1446
+ if let Some ( res) =
1447
+ self . check_full_res ( ns, path_str, base_node, extra_fragment)
1448
+ {
1470
1449
kind =
1471
1450
ResolutionFailure :: WrongNamespace { res, expected_ns : MacroNS } ;
1472
1451
break ;
0 commit comments