@@ -21,6 +21,7 @@ use rustc_hir::def::Namespace::{self, *};
21
21
use rustc_hir:: def:: { self , CtorKind , DefKind , LifetimeRes , NonMacroAttrKind , PartialRes , PerNS } ;
22
22
use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
23
23
use rustc_hir:: { BindingAnnotation , PrimTy , TraitCandidate } ;
24
+ use rustc_metadata:: creader:: CStore ;
24
25
use rustc_middle:: middle:: resolve_bound_vars:: Set1 ;
25
26
use rustc_middle:: { bug, span_bug} ;
26
27
use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
@@ -4455,14 +4456,20 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
4455
4456
if let Some ( res) = res
4456
4457
&& let Some ( def_id) = res. opt_def_id ( )
4457
4458
&& !def_id. is_local ( )
4458
- && self . r . tcx . crate_types ( ) . contains ( & CrateType :: ProcMacro )
4459
- && matches ! (
4460
- self . r. tcx. sess. opts. resolve_doc_links,
4461
- ResolveDocLinks :: ExportedMetadata
4462
- )
4463
4459
{
4464
- // Encoding foreign def ids in proc macro crate metadata will ICE.
4465
- return None ;
4460
+ if self . r . tcx . crate_types ( ) . contains ( & CrateType :: ProcMacro )
4461
+ && matches ! (
4462
+ self . r. tcx. sess. opts. resolve_doc_links,
4463
+ ResolveDocLinks :: ExportedMetadata
4464
+ )
4465
+ {
4466
+ // Encoding foreign def ids in proc macro crate metadata will ICE.
4467
+ return None ;
4468
+ }
4469
+ // Doc paths should be resolved speculatively and should not produce any
4470
+ // diagnostics, but if they are indeed resolved, then we need to keep the
4471
+ // corresponding crate alive.
4472
+ CStore :: from_tcx_mut ( self . r . tcx ) . set_used_recursively ( def_id. krate ) ;
4466
4473
}
4467
4474
res
4468
4475
} ) ;
0 commit comments