@@ -21,6 +21,7 @@ use rustc_hir::def::Namespace::{self, *};
2121use rustc_hir:: def:: { self , CtorKind , DefKind , LifetimeRes , NonMacroAttrKind , PartialRes , PerNS } ;
2222use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
2323use rustc_hir:: { BindingAnnotation , PrimTy , TraitCandidate } ;
24+ use rustc_metadata:: creader:: CStore ;
2425use rustc_middle:: middle:: resolve_bound_vars:: Set1 ;
2526use rustc_middle:: { bug, span_bug} ;
2627use rustc_session:: config:: { CrateType , ResolveDocLinks } ;
@@ -4455,14 +4456,20 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
44554456 if let Some ( res) = res
44564457 && let Some ( def_id) = res. opt_def_id ( )
44574458 && !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- )
44634459 {
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 ) ;
44664473 }
44674474 res
44684475 } ) ;
0 commit comments