1
Fork 0

Auto merge of #94857 - petrochenkov:doclink2, r=oli-obk

Resolve documentation links in rustc and store the results in metadata

This PR implements MCP https://github.com/rust-lang/compiler-team/issues/584.

Doc links are now resolved in rustc and stored into metadata, so rustdoc simply retrieves them through a query (local or extern),

Code that is no longer used is removed, and some code that no longer needs to be public is privatized.
The removed code includes resolver cloning, so this PR fixes https://github.com/rust-lang/rust/issues/83761.
This commit is contained in:
bors 2023-02-11 12:10:16 +00:00
commit 5b45024487
30 changed files with 764 additions and 873 deletions

View file

@ -419,6 +419,18 @@ pub enum TrimmedDefPaths {
GoodPath,
}
#[derive(Clone, Hash)]
pub enum ResolveDocLinks {
/// Do not resolve doc links.
None,
/// Resolve doc links on exported items only for crate types that have metadata.
ExportedMetadata,
/// Resolve doc links on exported items.
Exported,
/// Resolve doc links on all items.
All,
}
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
@ -788,6 +800,7 @@ impl Default for Options {
unstable_features: UnstableFeatures::Disallow,
debug_assertions: true,
actually_rustdoc: false,
resolve_doc_links: ResolveDocLinks::None,
trimmed_def_paths: TrimmedDefPaths::default(),
cli_forced_codegen_units: None,
cli_forced_local_thinlto_off: false,
@ -883,6 +896,15 @@ pub enum CrateType {
ProcMacro,
}
impl CrateType {
pub fn has_metadata(self) -> bool {
match self {
CrateType::Rlib | CrateType::Dylib | CrateType::ProcMacro => true,
CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib => false,
}
}
}
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub enum Passes {
Some(Vec<String>),
@ -2562,6 +2584,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
libs,
debug_assertions,
actually_rustdoc: false,
resolve_doc_links: ResolveDocLinks::ExportedMetadata,
trimmed_def_paths: TrimmedDefPaths::default(),
cli_forced_codegen_units: codegen_units,
cli_forced_local_thinlto_off: disable_local_thinlto,
@ -2825,8 +2848,9 @@ pub(crate) mod dep_tracking {
use super::{
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto, LocationDetail, LtoCli,
OomStrategy, OptLevel, OutputType, OutputTypes, Passes, SourceFileHashAlgorithm,
SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
OomStrategy, OptLevel, OutputType, OutputTypes, Passes, ResolveDocLinks,
SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion,
TraitSolver, TrimmedDefPaths,
};
use crate::lint;
use crate::options::WasiExecModel;
@ -2913,6 +2937,7 @@ pub(crate) mod dep_tracking {
TargetTriple,
Edition,
LinkerPluginLto,
ResolveDocLinks,
SplitDebuginfo,
SplitDwarfKind,
StackProtector,

View file

@ -169,6 +169,8 @@ top_level_options!(
/// is currently just a hack and will be removed eventually, so please
/// try to not rely on this too much.
actually_rustdoc: bool [TRACKED],
/// Whether name resolver should resolve documentation links.
resolve_doc_links: ResolveDocLinks [TRACKED],
/// Control path trimming.
trimmed_def_paths: TrimmedDefPaths [TRACKED],