diff --git a/Cargo.lock b/Cargo.lock index 69f96bcbe63b4..22fe7183a01f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,6 +507,10 @@ name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-core", +] [[package]] name = "chalk-derive" @@ -4613,7 +4617,7 @@ version = "0.0.0" dependencies = [ "addr2line 0.16.0", "alloc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "compiler_builtins", "core", "dlmalloc", @@ -4637,7 +4641,7 @@ dependencies = [ name = "std_detect" version = "0.1.5" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "compiler_builtins", "libc", "rustc-std-workspace-alloc", diff --git a/compiler/rustc_error_messages/locales/en-US/query_system.ftl b/compiler/rustc_error_messages/locales/en-US/query_system.ftl index 167704e46c07d..b914ba52a7353 100644 --- a/compiler/rustc_error_messages/locales/en-US/query_system.ftl +++ b/compiler/rustc_error_messages/locales/en-US/query_system.ftl @@ -23,3 +23,6 @@ query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive query_system_cycle_which_requires = ...which requires {$desc}... query_system_query_overflow = queries overflow the depth limit! + .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`) + +query_system_layout_of_depth = query depth increased by {$depth} when {$desc} diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 6f39bbfc0dc8a..d819f4774d54d 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -19,8 +19,10 @@ use rustc_query_system::query::{ force_query, QueryConfig, QueryContext, QueryDescription, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, }; -use rustc_query_system::Value; +use rustc_query_system::{LayoutOfDepth, QueryOverflow, Value}; use rustc_serialize::Decodable; +use rustc_session::Limit; +use rustc_span::def_id::LOCAL_CRATE; use std::any::Any; use std::num::NonZeroU64; use thin_vec::ThinVec; @@ -109,7 +111,7 @@ impl QueryContext for QueryCtxt<'_> { // when accessing the `ImplicitCtxt`. tls::with_related_context(**self, move |current_icx| { if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) { - self.depth_limit_error(); + self.depth_limit_error(token); } // Update the `ImplicitCtxt` to point to our new query job. @@ -127,6 +129,29 @@ impl QueryContext for QueryCtxt<'_> { }) }) } + + fn depth_limit_error(&self, job: QueryJobId) { + let mut span = None; + let mut layout_of_depth = None; + if let Some(map) = self.try_collect_active_jobs() { + if let Some((info, depth)) = job.try_find_layout_root(map) { + span = Some(info.job.span); + layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth }); + } + } + + let suggested_limit = match self.recursion_limit() { + Limit(0) => Limit(2), + limit => limit * 2, + }; + + self.sess.emit_fatal(QueryOverflow { + span, + layout_of_depth, + suggested_limit, + crate_name: self.crate_name(LOCAL_CRATE), + }); + } } impl<'tcx> QueryCtxt<'tcx> { diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 3fb06cbedbd50..bececca7585ae 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,5 +1,6 @@ use rustc_errors::AddSubdiagnostic; -use rustc_span::Span; +use rustc_session::Limit; +use rustc_span::{Span, Symbol}; pub struct CycleStack { pub span: Span, @@ -76,5 +77,20 @@ pub struct IncrementCompilation { } #[derive(SessionDiagnostic)] +#[help] #[diag(query_system::query_overflow)] -pub struct QueryOverflow; +pub struct QueryOverflow { + #[primary_span] + pub span: Option, + #[subdiagnostic] + pub layout_of_depth: Option, + pub suggested_limit: Limit, + pub crate_name: Symbol, +} + +#[derive(SessionSubdiagnostic)] +#[note(query_system::layout_of_depth)] +pub struct LayoutOfDepth { + pub desc: String, + pub depth: usize, +} diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index f92c3831f2689..5987651322af7 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -23,4 +23,6 @@ pub mod query; mod values; pub use error::HandleCycleError; +pub use error::LayoutOfDepth; +pub use error::QueryOverflow; pub use values::Value; diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 45b4079fb54f8..95305eabd0d34 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -59,6 +59,7 @@ impl QueryJobId { } } +#[derive(Clone)] pub struct QueryJobInfo { pub query: QueryStackFrame, pub job: QueryJob, @@ -116,10 +117,10 @@ impl QueryJob { } } -#[cfg(not(parallel_compiler))] impl QueryJobId { #[cold] #[inline(never)] + #[cfg(not(parallel_compiler))] pub(super) fn find_cycle_in_stack( &self, query_map: QueryMap, @@ -156,6 +157,24 @@ impl QueryJobId { panic!("did not find a cycle") } + + #[cold] + #[inline(never)] + pub fn try_find_layout_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> { + let mut last_layout = None; + let mut current_id = Some(*self); + let mut depth = 0; + + while let Some(id) = current_id { + let info = query_map.get(&id).unwrap(); + if info.query.name == "layout_of" { + depth += 1; + last_layout = Some((info.clone(), depth)); + } + current_id = info.job.parent; + } + last_layout + } } #[cfg(parallel_compiler)] diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 0b07bb64b6ae0..7a96c53b60481 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -14,7 +14,7 @@ pub use self::caches::{ mod config; pub use self::config::{QueryConfig, QueryDescription, QueryVTable}; -use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; +use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; use rustc_data_structures::sync::Lock; use rustc_errors::Diagnostic; use rustc_hir::def::DefKind; @@ -123,7 +123,5 @@ pub trait QueryContext: HasDepContext { compute: impl FnOnce() -> R, ) -> R; - fn depth_limit_error(&self) { - self.dep_context().sess().emit_fatal(crate::error::QueryOverflow); - } + fn depth_limit_error(&self, job: QueryJobId); } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 324ecc8047730..b8c35ecd34933 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../alloc" } -cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } +cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } diff --git a/library/stdarch b/library/stdarch index 42df7394d38bc..699c093a42283 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 42df7394d38bc7b945116ea3ad8a7cbcd1db50a9 +Subproject commit 699c093a42283c07e9763b4c19439a900ae2d321 diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index cc08ae5f99f0e..350d87d58a4dc 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -732,9 +732,19 @@ def build_bootstrap(self, color): (os.pathsep + env["LIBRARY_PATH"]) \ if "LIBRARY_PATH" in env else "" + # Export Stage0 snapshot compiler related env variables + build_section = "target.{}".format(self.build) + host_triple_sanitized = self.build.replace("-", "_") + var_data = { + "CC": "cc", "CXX": "cxx", "LD": "linker", "AR": "ar", "RANLIB": "ranlib" + } + for var_name, toml_key in var_data.items(): + toml_val = self.get_toml(toml_key, build_section) + if toml_val != None: + env["{}_{}".format(var_name, host_triple_sanitized)] = toml_val + # preserve existing RUSTFLAGS env.setdefault("RUSTFLAGS", "") - build_section = "target.{}".format(self.build) target_features = [] if self.get_toml("crt-static", build_section) == "true": target_features += ["+crt-static"] @@ -742,9 +752,6 @@ def build_bootstrap(self, color): target_features += ["-crt-static"] if target_features: env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features)) - target_linker = self.get_toml("linker", build_section) - if target_linker is not None: - env["RUSTFLAGS"] += " -C linker=" + target_linker env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes" env["RUSTFLAGS"] += " -Wsemicolon_in_expressions_from_macros" if self.get_toml("deny-warnings", "rust") != "false": diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 14e8ebd6876b4..535dd285cd6d4 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -708,6 +708,7 @@ impl<'a> Builder<'a> { Kind::Dist => describe!( dist::Docs, dist::RustcDocs, + dist::JsonDocs, dist::Mingw, dist::Rustc, dist::Std, @@ -1940,25 +1941,26 @@ impl<'a> Builder<'a> { _ => s.display().to_string(), } }; + let triple_underscored = target.triple.replace("-", "_"); let cc = ccacheify(&self.cc(target)); - cargo.env(format!("CC_{}", target.triple), &cc); + cargo.env(format!("CC_{}", triple_underscored), &cc); let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" "); - cargo.env(format!("CFLAGS_{}", target.triple), &cflags); + cargo.env(format!("CFLAGS_{}", triple_underscored), &cflags); if let Some(ar) = self.ar(target) { let ranlib = format!("{} s", ar.display()); cargo - .env(format!("AR_{}", target.triple), ar) - .env(format!("RANLIB_{}", target.triple), ranlib); + .env(format!("AR_{}", triple_underscored), ar) + .env(format!("RANLIB_{}", triple_underscored), ranlib); } if let Ok(cxx) = self.cxx(target) { let cxx = ccacheify(&cxx); let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "); cargo - .env(format!("CXX_{}", target.triple), &cxx) - .env(format!("CXXFLAGS_{}", target.triple), cxxflags); + .env(format!("CXX_{}", triple_underscored), &cxx) + .env(format!("CXXFLAGS_{}", triple_underscored), cxxflags); } } diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs index 280eba75f0c19..88bbcc93d072c 100644 --- a/src/bootstrap/builder/tests.rs +++ b/src/bootstrap/builder/tests.rs @@ -236,7 +236,7 @@ mod defaults { fn doc_default() { let mut config = configure("doc", &["A"], &["A"]); config.compiler_docs = true; - config.cmd = Subcommand::Doc { paths: Vec::new(), open: false }; + config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false }; let mut cache = run_build(&[], config); let a = TargetSelection::from_user("A"); @@ -587,7 +587,7 @@ mod dist { fn doc_ci() { let mut config = configure(&["A"], &["A"]); config.compiler_docs = true; - config.cmd = Subcommand::Doc { paths: Vec::new(), open: false }; + config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false }; let build = Build::new(config); let mut builder = Builder::new(&build); builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 1a59b3958f106..c9ee3c1c7d65d 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -87,6 +87,45 @@ impl Step for Docs { } } +#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)] +pub struct JsonDocs { + pub host: TargetSelection, +} + +impl Step for JsonDocs { + type Output = Option; + const DEFAULT: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + let default = run.builder.config.docs; + run.alias("rust-json-docs").default_condition(default) + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(JsonDocs { host: run.target }); + } + + /// Builds the `rust-json-docs` installer component. + fn run(self, builder: &Builder<'_>) -> Option { + // This prevents JSON docs from being built for "dist" or "install" + // on the stable/beta channels. The JSON format is not stable yet and + // should not be included in stable/beta toolchains. + if !builder.build.unstable_features() { + return None; + } + + let host = self.host; + builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host }); + + let dest = "share/doc/rust/json"; + + let mut tarball = Tarball::new(builder, "rust-json-docs", &host.triple); + tarball.set_product_name("Rust Documentation In JSON Format"); + tarball.add_bulk_dir(&builder.json_doc_out(host), dest); + Some(tarball.generate()) + } +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct RustcDocs { pub host: TargetSelection, diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index f909ecc0ab858..8de41c806807b 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -7,6 +7,7 @@ //! Everything here is basically just a shim around calling either `rustbook` or //! `rustdoc`. +use std::ffi::OsStr; use std::fs; use std::io; use std::path::{Path, PathBuf}; @@ -432,48 +433,24 @@ impl Step for Std { let stage = self.stage; let target = self.target; builder.info(&format!("Documenting stage{} std ({})", stage, target)); - if builder.no_std(target) == Some(true) { - panic!( - "building std documentation for no_std target {target} is not supported\n\ - Set `docs = false` in the config to disable documentation." - ); - } let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); - let compiler = builder.compiler(stage, builder.config.build); - - let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc"); - t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css"))); - let run_cargo_rustdoc_for = |package: &str| { - let mut cargo = - builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc"); - compile::std_cargo(builder, target, compiler.stage, &mut cargo); - - cargo - .arg("-p") - .arg(package) - .arg("-Zskip-rustdoc-fingerprint") - .arg("--") - .arg("--markdown-css") - .arg("rust.css") - .arg("--markdown-no-toc") - .arg("-Z") - .arg("unstable-options") - .arg("--resource-suffix") - .arg(&builder.version) - .arg("--index-page") - .arg(&builder.src.join("src/doc/index.md")); - - if !builder.config.docs_minification { - cargo.arg("--disable-minification"); - } - - builder.run(&mut cargo.into()); - }; + let index_page = builder.src.join("src/doc/index.md").into_os_string(); + let mut extra_args = vec![ + OsStr::new("--markdown-css"), + OsStr::new("rust.css"), + OsStr::new("--markdown-no-toc"), + OsStr::new("--index-page"), + &index_page, + ]; + + if !builder.config.docs_minification { + extra_args.push(OsStr::new("--disable-minification")); + } - let paths = builder + let requested_crates = builder .paths .iter() .map(components_simplified) @@ -491,30 +468,20 @@ impl Step for Std { }) .collect::>(); - // Only build the following crates. While we could just iterate over the - // folder structure, that would also build internal crates that we do - // not want to show in documentation. These crates will later be visited - // by the rustc step, so internal documentation will show them. - // - // Note that the order here is important! The crates need to be - // processed starting from the leaves, otherwise rustdoc will not - // create correct links between crates because rustdoc depends on the - // existence of the output directories to know if it should be a local - // or remote link. - let krates = ["core", "alloc", "std", "proc_macro", "test"]; - for krate in &krates { - run_cargo_rustdoc_for(krate); - if paths.iter().any(|p| p == krate) { - // No need to document more of the libraries if we have the one we want. - break; - } - } - builder.cp_r(&out_dir, &out); + doc_std( + builder, + DocumentationFormat::HTML, + stage, + target, + &out, + &extra_args, + &requested_crates, + ); // Look for library/std, library/core etc in the `x.py doc` arguments and // open the corresponding rendered docs. - for requested_crate in paths { - if krates.iter().any(|k| *k == requested_crate.as_str()) { + for requested_crate in requested_crates { + if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) { let index = out.join(requested_crate).join("index.html"); open(builder, &index); } @@ -522,6 +489,132 @@ impl Step for Std { } } +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct JsonStd { + pub stage: u32, + pub target: TargetSelection, +} + +impl Step for JsonStd { + type Output = (); + const DEFAULT: bool = false; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + let default = run.builder.config.docs && run.builder.config.cmd.json(); + run.all_krates("test").path("library").default_condition(default) + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target }); + } + + /// Build JSON documentation for the standard library crates. + /// + /// This is largely just a wrapper around `cargo doc`. + fn run(self, builder: &Builder<'_>) { + let stage = self.stage; + let target = self.target; + let out = builder.json_doc_out(target); + t!(fs::create_dir_all(&out)); + let extra_args = [OsStr::new("--output-format"), OsStr::new("json")]; + doc_std(builder, DocumentationFormat::JSON, stage, target, &out, &extra_args, &[]) + } +} + +/// Name of the crates that are visible to consumers of the standard library. +/// Documentation for internal crates is handled by the rustc step, so internal crates will show +/// up there. +/// +/// Order here is important! +/// Crates need to be processed starting from the leaves, otherwise rustdoc will not +/// create correct links between crates because rustdoc depends on the +/// existence of the output directories to know if it should be a local +/// or remote link. +const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "test"]; + +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +enum DocumentationFormat { + HTML, + JSON, +} + +impl DocumentationFormat { + fn as_str(&self) -> &str { + match self { + DocumentationFormat::HTML => "HTML", + DocumentationFormat::JSON => "JSON", + } + } +} + +/// Build the documentation for public standard library crates. +/// +/// `requested_crates` can be used to build only a subset of the crates. If empty, all crates will +/// be built. +fn doc_std( + builder: &Builder<'_>, + format: DocumentationFormat, + stage: u32, + target: TargetSelection, + out: &Path, + extra_args: &[&OsStr], + requested_crates: &[String], +) { + builder.info(&format!( + "Documenting stage{} std ({}) in {} format", + stage, + target, + format.as_str() + )); + if builder.no_std(target) == Some(true) { + panic!( + "building std documentation for no_std target {target} is not supported\n\ + Set `docs = false` in the config to disable documentation." + ); + } + let compiler = builder.compiler(stage, builder.config.build); + // This is directory where the compiler will place the output of the command. + // We will then copy the files from this directory into the final `out` directory, the specified + // as a function parameter. + let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc"); + // `cargo` uses the same directory for both JSON docs and HTML docs. + // This could lead to cross-contamination when copying files into the specified `out` directory. + // For example: + // ```bash + // x doc std + // x doc std --json + // ``` + // could lead to HTML docs being copied into the JSON docs output directory. + // To avoid this issue, we clean the doc folder before invoking `cargo`. + builder.remove_dir(&out_dir); + + let run_cargo_rustdoc_for = |package: &str| { + let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc"); + compile::std_cargo(builder, target, compiler.stage, &mut cargo); + cargo + .arg("-p") + .arg(package) + .arg("-Zskip-rustdoc-fingerprint") + .arg("--") + .arg("-Z") + .arg("unstable-options") + .arg("--resource-suffix") + .arg(&builder.version) + .args(extra_args); + builder.run(&mut cargo.into()); + }; + + for krate in STD_PUBLIC_CRATES { + run_cargo_rustdoc_for(krate); + if requested_crates.iter().any(|p| p == krate) { + // No need to document more of the libraries if we have the one we want. + break; + } + } + + builder.cp_r(&out_dir, &out); +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rustc { pub stage: u32, diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 789da74810035..802b49d748ac6 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -107,6 +107,7 @@ pub enum Subcommand { Doc { paths: Vec, open: bool, + json: bool, }, Test { paths: Vec, @@ -325,6 +326,11 @@ To learn more about a subcommand, run `./x.py -h`", } Kind::Doc => { opts.optflag("", "open", "open the docs in a browser"); + opts.optflag( + "", + "json", + "render the documentation in JSON format in addition to the usual HTML format", + ); } Kind::Clean => { opts.optflag("", "all", "clean all build artifacts"); @@ -493,6 +499,7 @@ Arguments: ./x.py doc src/doc/book ./x.py doc src/doc/nomicon ./x.py doc src/doc/book library/std + ./x.py doc library/std --json ./x.py doc library/std --open If no arguments are passed then everything is documented: @@ -581,7 +588,11 @@ Arguments: }, }, Kind::Bench => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") }, - Kind::Doc => Subcommand::Doc { paths, open: matches.opt_present("open") }, + Kind::Doc => Subcommand::Doc { + paths, + open: matches.opt_present("open"), + json: matches.opt_present("json"), + }, Kind::Clean => { if !paths.is_empty() { println!("\nclean does not take a path argument\n"); @@ -787,6 +798,13 @@ impl Subcommand { _ => false, } } + + pub fn json(&self) -> bool { + match *self { + Subcommand::Doc { json, .. } => json, + _ => false, + } + } } fn split(s: &[String]) -> Vec { diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index cc0cf12bd187a..b7d271e6494b1 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -825,6 +825,11 @@ impl Build { self.out.join(&*target.triple).join("doc") } + /// Output directory for all JSON-formatted documentation for a target + fn json_doc_out(&self, target: TargetSelection) -> PathBuf { + self.out.join(&*target.triple).join("json-doc") + } + fn test_out(&self, target: TargetSelection) -> PathBuf { self.out.join(&*target.triple).join("test") } @@ -1307,10 +1312,6 @@ impl Build { self.package_vers(&self.version) } - fn llvm_link_tools_dynamically(&self, target: TargetSelection) -> bool { - target.contains("linux-gnu") || target.contains("apple-darwin") - } - /// Returns the `version` string associated with this compiler for Rust /// itself. /// diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 62b56994afe70..d6ee6d489cf04 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -423,12 +423,7 @@ impl Step for Llvm { // which saves both memory during parallel links and overall disk space // for the tools. We don't do this on every platform as it doesn't work // equally well everywhere. - // - // If we're not linking rustc to a dynamic LLVM, though, then don't link - // tools to it. - let llvm_link_shared = - builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared(); - if llvm_link_shared { + if builder.llvm_link_shared() { cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); } @@ -553,7 +548,7 @@ impl Step for Llvm { // libLLVM.dylib will be built. However, llvm-config will still look // for a versioned path like libLLVM-14.dylib. Manually create a symbolic // link to make llvm-config happy. - if llvm_link_shared && target.contains("apple-darwin") { + if builder.llvm_link_shared() && target.contains("apple-darwin") { let mut cmd = Command::new(&build_llvm_config); let version = output(cmd.arg("--version")); let major = version.split('.').next().unwrap(); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 7d4ed24b64850..5d0c7d2bd9d44 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -746,14 +746,18 @@ impl Step for RustAnalyzerProcMacroSrv { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("src/tools/rust-analyzer").default_condition( - builder.config.extended - && builder - .config - .tools - .as_ref() - .map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")), - ) + + // Allow building `rust-analyzer-proc-macro-srv` both as part of the `rust-analyzer` and as a stand-alone tool. + run.path("src/tools/rust-analyzer") + .path("src/tools/rust-analyzer/crates/proc-macro-srv-cli") + .default_condition( + builder.config.extended + && builder.config.tools.as_ref().map_or(true, |tools| { + tools.iter().any(|tool| { + tool == "rust-analyzer" || tool == "rust-analyzer-proc-macro-srv" + }) + }), + ) } fn make_run(run: RunConfig<'_>) { @@ -764,7 +768,7 @@ impl Step for RustAnalyzerProcMacroSrv { } fn run(self, builder: &Builder<'_>) -> Option { - builder.ensure(ToolBuild { + let path = builder.ensure(ToolBuild { compiler: self.compiler, target: self.target, tool: "rust-analyzer-proc-macro-srv", @@ -773,7 +777,15 @@ impl Step for RustAnalyzerProcMacroSrv { extra_features: vec!["proc-macro-srv/sysroot-abi".to_owned()], is_optional_tool: false, source_type: SourceType::InTree, - }) + })?; + + // Copy `rust-analyzer-proc-macro-srv` to `/libexec/` + // so that r-a can use it. + let libexec_path = builder.sysroot(self.compiler).join("libexec"); + t!(fs::create_dir_all(&libexec_path)); + builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv")); + + Some(path) } } diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 6e4b0b0c2c3f1..7826fd514093e 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -286,7 +286,7 @@ jobs: - name: x86_64-gnu-llvm-13 <<: *job-linux-xl - + - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 1e6f20d2b491c..ced0ebdbb864a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -294,16 +294,15 @@ impl AllTypes { impl AllTypes { fn print(self, f: &mut Buffer) { - fn print_entries(f: &mut Buffer, e: &FxHashSet, title: &str, class: &str) { + fn print_entries(f: &mut Buffer, e: &FxHashSet, title: &str) { if !e.is_empty() { let mut e: Vec<&ItemEntry> = e.iter().collect(); e.sort(); write!( f, - "

{}

    ", + "

    {}

      ", title.replace(' ', "-"), // IDs cannot contain whitespaces. - title, - class + title ); for s in e.iter() { @@ -321,20 +320,20 @@ impl AllTypes { ); // Note: print_entries does not escape the title, because we know the current set of titles // doesn't require escaping. - print_entries(f, &self.structs, "Structs", "structs"); - print_entries(f, &self.enums, "Enums", "enums"); - print_entries(f, &self.unions, "Unions", "unions"); - print_entries(f, &self.primitives, "Primitives", "primitives"); - print_entries(f, &self.traits, "Traits", "traits"); - print_entries(f, &self.macros, "Macros", "macros"); - print_entries(f, &self.attributes, "Attribute Macros", "attributes"); - print_entries(f, &self.derives, "Derive Macros", "derives"); - print_entries(f, &self.functions, "Functions", "functions"); - print_entries(f, &self.typedefs, "Typedefs", "typedefs"); - print_entries(f, &self.trait_aliases, "Trait Aliases", "trait-aliases"); - print_entries(f, &self.opaque_tys, "Opaque Types", "opaque-types"); - print_entries(f, &self.statics, "Statics", "statics"); - print_entries(f, &self.constants, "Constants", "constants") + print_entries(f, &self.structs, "Structs"); + print_entries(f, &self.enums, "Enums"); + print_entries(f, &self.unions, "Unions"); + print_entries(f, &self.primitives, "Primitives"); + print_entries(f, &self.traits, "Traits"); + print_entries(f, &self.macros, "Macros"); + print_entries(f, &self.attributes, "Attribute Macros"); + print_entries(f, &self.derives, "Derive Macros"); + print_entries(f, &self.functions, "Functions"); + print_entries(f, &self.typedefs, "Typedefs"); + print_entries(f, &self.trait_aliases, "Trait Aliases"); + print_entries(f, &self.opaque_tys, "Opaque Types"); + print_entries(f, &self.statics, "Statics"); + print_entries(f, &self.constants, "Constants"); } } diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index fc4d46fe6b6f1..1c88528aa20a9 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -519,12 +519,12 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; let content = format!( "

      \ List of all crates\ -

        {}
      ", +
        {}
      ", krates .iter() .map(|s| { format!( - "
    • {}
    • ", + "
    • {}
    • ", ensure_trailing_slash(s), s ) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 3995c9fdb01b2..84ed056d0e1c8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -207,7 +207,6 @@ a.source, .out-of-band, span.since, details.rustdoc-toggle > summary::before, -.content ul.crate a.crate, a.srclink, #help-button > button, details.rustdoc-toggle.top-doc > summary, @@ -218,7 +217,7 @@ details.rustdoc-toggle.non-exhaustive > summary::before, .more-examples-toggle summary, .more-examples-toggle .hide-more, .example-links a, /* This selector is for the items listed in the "all items" page. */ -#main-content > ul.docblock > li > a { +ul.all-items { font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif; } @@ -241,6 +240,49 @@ pre.rust a, color: var(--main-color); } +.content span.enum, .content a.enum, +.content span.struct, .content a.struct, +.content span.union, .content a.union, +.content span.primitive, .content a.primitive, +.content span.type, .content a.type, +.content span.foreigntype, .content a.foreigntype { + color: var(--type-link-color); +} + +.content span.trait, .content a.trait, +.content span.traitalias, .content a.traitalias { + color: var(--trait-link-color); +} + +.content span.associatedtype, .content a.associatedtype, +.content span.constant, .content a.constant, +.content span.static, .content a.static { + color: var(--assoc-item-link-color); +} + +.content span.fn, .content a.fn, +.content .fnname { + color: var(--function-link-color); +} + +.content span.attr, .content a.attr, +.content span.derive, .content a.derive, +.content span.macro, .content a.macro { + color: var(--macro-link-color); +} + +.content span.mod, .content a.mod, .block a.current.mod { + color: var(--mod-link-color); +} + +.content span.keyword, .content a.keyword { + color: var(--keyword-link-color); +} + +a { + color: var(--link-color); +} + ol, ul { padding-left: 24px; } @@ -786,6 +828,7 @@ h2.small-section-header > .anchor { content: 'ยง'; } +.all-items a:hover, .docblock a:not(.srclink):not(.test-arrow):not(.scrape-help):hover, .docblock-short a:not(.srclink):not(.test-arrow):not(.scrape-help):hover, .item-info a { text-decoration: underline; @@ -1515,10 +1558,7 @@ kbd { cursor: default; } -#main-content > ul { - padding-left: 10px; -} -#main-content > ul > li { +ul.all-items > li { list-style: none; } diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index c292a8a7ef70b..e7a898e9fa62c 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -27,6 +27,14 @@ Original by Dempfi (https://github.com/dempfi/ayu) --codeblock-error-color: rgba(255, 0, 0, .5); --codeblock-ignore-hover-color: rgb(255, 142, 0); --codeblock-ignore-color: rgba(255, 142, 0, .6); + --type-link-color: #ffa0a5; + --trait-link-color: #39afd7; + --assoc-item-link-color: #39afd7; + --function-link-color: #fdd687; + --macro-link-color: #a37acc; + --keyword-link-color: #39afd7; + --mod-link-color: #39afd7; + --link-color: #39afd7; } .slider { @@ -111,44 +119,12 @@ pre, .rustdoc.source .example-wrap { .content .item-info::before { color: #ccc; } -.content span.foreigntype, .content a.foreigntype { color: #ffa0a5; } -.content span.union, .content a.union { color: #ffa0a5; } -.content span.constant, .content a.constant, -.content span.static, .content a.static { color: #39AFD7; } -.content span.primitive, .content a.primitive { color: #ffa0a5; } -.content span.traitalias, .content a.traitalias { color: #39AFD7; } -.content span.keyword, .content a.keyword { color: #39AFD7; } -.content span.mod, .content a.mod { - color: #39AFD7; -} -.content span.struct, .content a.struct { - color: #ffa0a5; -} -.content span.enum, .content a.enum { - color: #ffa0a5; -} -.content span.trait, .content a.trait { - color: #39AFD7; -} -.content span.type, .content a.type { color: #39AFD7; } -.content span.associatedtype, .content a.associatedtype { color: #39AFD7; } -.content span.fn, .content a.fn, -.content .fnname { color: #fdd687; } -.content span.attr, .content a.attr, .content span.derive, -.content a.derive, .content span.macro, .content a.macro { - color: #a37acc; -} - .sidebar a { color: #53b1db; } .sidebar a.current.type { color: #53b1db; } pre.rust .comment { color: #788797; } pre.rust .doccomment { color: #a1ac88; } -a { - color: #39AFD7; -} - .sidebar h2 a, .sidebar h3 a { color: white; diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 68542d3305ca0..07a1ed8b7db74 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -22,6 +22,14 @@ --codeblock-error-color: rgba(255, 0, 0, .5); --codeblock-ignore-hover-color: rgb(255, 142, 0); --codeblock-ignore-color: rgba(255, 142, 0, .6); + --type-link-color: #2dbfb8; + --trait-link-color: #b78cf2; + --assoc-item-link-color: #d2991d; + --function-link-color: #2bab63; + --macro-link-color: #09bd00; + --keyword-link-color: #d2991d; + --mod-link-color: #d2991d; + --link-color: #d2991d; } .slider { @@ -83,25 +91,6 @@ a.result-keyword:focus { background-color: #884719; } .content .item-info::before { color: #ccc; } -.content span.enum, .content a.enum { color: #2dbfb8; } -.content span.struct, .content a.struct { color: #2dbfb8; } -.content span.type, .content a.type { color: #2dbfb8; } -.content span.associatedtype, .content a.associatedtype { color: #D2991D; } -.content span.foreigntype, .content a.foreigntype { color: #2dbfb8; } -.content span.attr, .content a.attr, -.content span.derive, .content a.derive, -.content span.macro, .content a.macro { color: #09bd00; } -.content span.union, .content a.union { color: #2dbfb8; } -.content span.constant, .content a.constant, -.content span.static, .content a.static { color: #D2991D; } -.content span.primitive, .content a.primitive { color: #2dbfb8; } -.content span.mod, .content a.mod { color: #D2991D; } -.content span.trait, .content a.trait { color: #b78cf2; } -.content span.traitalias, .content a.traitalias { color: #b78cf2; } -.content span.fn, .content a.fn, -.content .fnname { color: #2BAB63; } -.content span.keyword, .content a.keyword { color: #D2991D; } - .sidebar a { color: #fdbf35; } .sidebar a.current.enum { color: #12ece2; } .sidebar a.current.struct { color: #12ece2; } @@ -122,10 +111,6 @@ a.result-keyword:focus { background-color: #884719; } pre.rust .comment { color: #8d8d8b; } pre.rust .doccomment { color: #8ca375; } -a { - color: #D2991D; -} - body.source .example-wrap pre.rust a { background: #333; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 0b7d1600e7aa4..64335f6292801 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -22,6 +22,14 @@ --codeblock-error-color: rgba(255, 0, 0, .5); --codeblock-ignore-hover-color: rgb(255, 142, 0); --codeblock-ignore-color: rgba(255, 142, 0, .6); + --type-link-color: #ad378a; + --trait-link-color: #6e4fc9; + --assoc-item-link-color: #3873ad; + --function-link-color: #ad7c37; + --macro-link-color: #068000; + --keyword-link-color: #3873ad; + --mod-link-color: #3873ad; + --link-color: #3873ad; } .slider { @@ -82,25 +90,6 @@ a.result-keyword:focus { background-color: #afc6e4; } .content .item-info::before { color: #ccc; } -.content span.enum, .content a.enum { color: #AD378A; } -.content span.struct, .content a.struct { color: #AD378A; } -.content span.type, .content a.type { color: #AD378A; } -.content span.associatedtype, .content a.associatedtype { color: #3873AD; } -.content span.foreigntype, .content a.foreigntype { color: #3873AD; } -.content span.attr, .content a.attr, -.content span.derive, .content a.derive, -.content span.macro, .content a.macro { color: #068000; } -.content span.union, .content a.union { color: #AD378A; } -.content span.constant, .content a.constant, -.content span.static, .content a.static { color: #3873AD; } -.content span.primitive, .content a.primitive { color: #AD378A; } -.content span.mod, .content a.mod { color: #3873AD; } -.content span.trait, .content a.trait { color: #6E4FC9; } -.content span.traitalias, .content a.traitalias { color: #5137AD; } -.content span.fn, .content a.fn, -.content .fnname { color: #AD7C37; } -.content span.keyword, .content a.keyword { color: #3873AD; } - .sidebar a { color: #356da4; } .sidebar a.current.enum { color: #a63283; } .sidebar a.current.struct { color: #a63283; } @@ -118,10 +107,6 @@ a.result-keyword:focus { background-color: #afc6e4; } .sidebar a.current.fn { color: #a67736; } .sidebar a.current.keyword { color: #356da4; } -a { - color: #3873AD; -} - body.source .example-wrap pre.rust a { background: #eee; } diff --git a/src/test/rustdoc-gui/links-color.goml b/src/test/rustdoc-gui/links-color.goml new file mode 100644 index 0000000000000..69c5b4a6733a8 --- /dev/null +++ b/src/test/rustdoc-gui/links-color.goml @@ -0,0 +1,85 @@ +// This test checks links colors. +goto: file://|DOC_PATH|/test_docs/index.html + +// This is needed so that the text color is computed. +show-text: true + +// Ayu theme +local-storage: { + "rustdoc-theme": "ayu", + "rustdoc-use-system-theme": "false", +} +reload: + +assert-css: (".item-table .mod", {"color": "rgb(57, 175, 215)"}, ALL) +assert-css: (".item-table .macro", {"color": "rgb(163, 122, 204)"}, ALL) +assert-css: (".item-table .struct", {"color": "rgb(255, 160, 165)"}, ALL) +assert-css: (".item-table .enum", {"color": "rgb(255, 160, 165)"}, ALL) +assert-css: (".item-table .trait", {"color": "rgb(57, 175, 215)"}, ALL) +assert-css: (".item-table .fn", {"color": "rgb(253, 214, 135)"}, ALL) +assert-css: (".item-table .type", {"color": "rgb(255, 160, 165)"}, ALL) +assert-css: (".item-table .union", {"color": "rgb(255, 160, 165)"}, ALL) +assert-css: (".item-table .keyword", {"color": "rgb(57, 175, 215)"}, ALL) + +assert-css: ( + ".sidebar-elems a:not(.current)", + {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, + ALL, +) +assert-css: ( + ".sidebar-elems a.current", + {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "500"}, + ALL, +) + + +// Dark theme +local-storage: {"rustdoc-theme": "dark"} +reload: + +assert-css: (".item-table .mod", {"color": "rgb(210, 153, 29)"}, ALL) +assert-css: (".item-table .macro", {"color": "rgb(9, 189, 0)"}, ALL) +assert-css: (".item-table .struct", {"color": "rgb(45, 191, 184)"}, ALL) +assert-css: (".item-table .enum", {"color": "rgb(45, 191, 184)"}, ALL) +assert-css: (".item-table .trait", {"color": "rgb(183, 140, 242)"}, ALL) +assert-css: (".item-table .fn", {"color": "rgb(43, 171, 99)"}, ALL) +assert-css: (".item-table .type", {"color": "rgb(45, 191, 184)"}, ALL) +assert-css: (".item-table .union", {"color": "rgb(45, 191, 184)"}, ALL) +assert-css: (".item-table .keyword", {"color": "rgb(210, 153, 29)"}, ALL) + +assert-css: ( + ".sidebar-elems a:not(.current)", + {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, + ALL, +) +assert-css: ( + ".sidebar-elems a.current", + {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)", "font-weight": "500"}, + ALL, +) + + +// Light theme +local-storage: {"rustdoc-theme": "light"} +reload: + +assert-css: (".item-table .mod", {"color": "rgb(56, 115, 173)"}, ALL) +assert-css: (".item-table .macro", {"color": "rgb(6, 128, 0)"}, ALL) +assert-css: (".item-table .struct", {"color": "rgb(173, 55, 138)"}, ALL) +assert-css: (".item-table .enum", {"color": "rgb(173, 55, 138)"}, ALL) +assert-css: (".item-table .trait", {"color": "rgb(110, 79, 201)"}, ALL) +assert-css: (".item-table .fn", {"color": "rgb(173, 124, 55)"}, ALL) +assert-css: (".item-table .type", {"color": "rgb(173, 55, 138)"}, ALL) +assert-css: (".item-table .union", {"color": "rgb(173, 55, 138)"}, ALL) +assert-css: (".item-table .keyword", {"color": "rgb(56, 115, 173)"}, ALL) + +assert-css: ( + ".sidebar-elems a:not(.current)", + {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)", "font-weight": "400"}, + ALL, +) +assert-css: ( + ".sidebar-elems a.current", + {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)", "font-weight": "500"}, + ALL, +) diff --git a/src/test/rustdoc/index-page.rs b/src/test/rustdoc/index-page.rs index be668a1276a01..5677019fbb88e 100644 --- a/src/test/rustdoc/index-page.rs +++ b/src/test/rustdoc/index-page.rs @@ -6,6 +6,6 @@ // @has foo/../index.html // @has - '//span[@class="in-band"]' 'List of all crates' -// @has - '//ul[@class="crate mod"]//a[@href="foo/index.html"]' 'foo' -// @has - '//ul[@class="crate mod"]//a[@href="all_item_types/index.html"]' 'all_item_types' +// @has - '//ul[@class="all-items"]//a[@href="foo/index.html"]' 'foo' +// @has - '//ul[@class="all-items"]//a[@href="all_item_types/index.html"]' 'all_item_types' pub struct Foo; diff --git a/src/test/ui/query-system/query_depth.rs b/src/test/ui/query-system/query_depth.rs new file mode 100644 index 0000000000000..e600c1c08e5cf --- /dev/null +++ b/src/test/ui/query-system/query_depth.rs @@ -0,0 +1,31 @@ +// build-fail + +#![recursion_limit = "64"] +type Byte = Option + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> + >>>> >>>> +>>>> >>>>; + +fn main() { +//~^ ERROR: queries overflow the depth limit! + println!("{}", std::mem::size_of::()); +} diff --git a/src/test/ui/query-system/query_depth.stderr b/src/test/ui/query-system/query_depth.stderr new file mode 100644 index 0000000000000..43a18b4e07455 --- /dev/null +++ b/src/test/ui/query-system/query_depth.stderr @@ -0,0 +1,11 @@ +error: queries overflow the depth limit! + --> $DIR/query_depth.rs:28:1 + | +LL | fn main() { + | ^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`) + = note: query depth increased by 66 when computing layout of `core::option::Option>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + +error: aborting due to previous error +