From 705a7667c5e14c7155145041ca2abe45c2863ea7 Mon Sep 17 00:00:00 2001 From: "Doug Cook (WINDOWS)" Date: Sat, 10 Sep 2022 19:37:07 -0700 Subject: [PATCH 01/13] array docs - advertise how to get array from slice On my first Rust project, I spent more time than I care to admit figuring out how to efficiently get an array from a slice. Update the array documentation to explain this a bit more clearly. (As a side note, it's a bit unfortunate that get-array-from-slice is only available via trait since that means it can't be used from const functions yet.) --- library/core/src/array/mod.rs | 48 ++++++++++++++++++++++++++++++ library/core/src/primitive_docs.rs | 23 +++++++++++++- library/std/src/primitive_docs.rs | 23 +++++++++++++- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 9effb37901609..165b9d24d934b 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -184,6 +184,18 @@ impl const BorrowMut<[T]> for [T; N] { } } +/// Tries to create an array `[T; N]` by copying from a slice `&[T]`. Succeeds if +/// `slice.len() == N`. +/// +/// ``` +/// let bytes: [u8; 3] = [1, 0, 2]; +/// +/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap(); +/// assert_eq!(1, u16::from_le_bytes(bytes_head)); +/// +/// let bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap(); +/// assert_eq!(512, u16::from_le_bytes(bytes_tail)); +/// ``` #[stable(feature = "try_from", since = "1.34.0")] impl TryFrom<&[T]> for [T; N] where @@ -196,6 +208,18 @@ where } } +/// Tries to create an array `[T; N]` by copying from a mutable slice `&mut [T]`. +/// Succeeds if `slice.len() == N`. +/// +/// ``` +/// let mut bytes: [u8; 3] = [1, 0, 2]; +/// +/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap(); +/// assert_eq!(1, u16::from_le_bytes(bytes_head)); +/// +/// let bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap(); +/// assert_eq!(512, u16::from_le_bytes(bytes_tail)); +/// ``` #[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")] impl TryFrom<&mut [T]> for [T; N] where @@ -208,6 +232,18 @@ where } } +/// Tries to create an array ref `&[T; N]` from a slice ref `&[T]`. Succeeds if +/// `slice.len() == N`. +/// +/// ``` +/// let bytes: [u8; 3] = [1, 0, 2]; +/// +/// let bytes_head: &[u8; 2] = <&[u8; 2]>::try_from(&bytes[0..2]).unwrap(); +/// assert_eq!(1, u16::from_le_bytes(*bytes_head)); +/// +/// let bytes_tail: &[u8; 2] = bytes[1..3].try_into().unwrap(); +/// assert_eq!(512, u16::from_le_bytes(*bytes_tail)); +/// ``` #[stable(feature = "try_from", since = "1.34.0")] impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { type Error = TryFromSliceError; @@ -223,6 +259,18 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { } } +/// Tries to create a mutable array ref `&mut [T; N]` from a mutable slice ref +/// `&mut [T]`. Succeeds if `slice.len() == N`. +/// +/// ``` +/// let mut bytes: [u8; 3] = [1, 0, 2]; +/// +/// let bytes_head: &mut [u8; 2] = <&mut [u8; 2]>::try_from(&mut bytes[0..2]).unwrap(); +/// assert_eq!(1, u16::from_le_bytes(*bytes_head)); +/// +/// let bytes_tail: &mut [u8; 2] = (&mut bytes[1..3]).try_into().unwrap(); +/// assert_eq!(512, u16::from_le_bytes(*bytes_tail)); +/// ``` #[stable(feature = "try_from", since = "1.34.0")] impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] { type Error = TryFromSliceError; diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index 242f44ade8a2d..331714a993c60 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -611,7 +611,19 @@ mod prim_pointer {} /// /// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on /// an array. Indeed, this provides most of the API for working with arrays. -/// Slices have a dynamic size and do not coerce to arrays. +/// +/// Slices have a dynamic size and do not coerce to arrays. Instead, use +/// `slice.try_into().unwrap()` or `::try_from(slice).unwrap()`. +/// +/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()` +/// array implementations) succeed if the input slice length is the same as the result +/// array length. They optimize especially well when the optimizer can easily determine +/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements +/// [TryFrom](crate::convert::TryFrom) returning: +/// +/// - `[T; N]` copies from the slice's elements +/// - `&[T; N]` references the original slice's elements +/// - `&mut [T; N]` references the original slice's elements /// /// You can move elements out of an array with a [slice pattern]. If you want /// one element, see [`mem::replace`]. @@ -640,6 +652,15 @@ mod prim_pointer {} /// for x in &array { } /// ``` /// +/// You can use `::try_from(slice)` or `slice.try_into()` to get an array from +/// a slice: +/// +/// ``` +/// let bytes: [u8; 3] = [1, 0, 2]; +/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap())); +/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap())); +/// ``` +/// /// You can use a [slice pattern] to move elements out of an array: /// /// ``` diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 242f44ade8a2d..331714a993c60 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -611,7 +611,19 @@ mod prim_pointer {} /// /// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on /// an array. Indeed, this provides most of the API for working with arrays. -/// Slices have a dynamic size and do not coerce to arrays. +/// +/// Slices have a dynamic size and do not coerce to arrays. Instead, use +/// `slice.try_into().unwrap()` or `::try_from(slice).unwrap()`. +/// +/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()` +/// array implementations) succeed if the input slice length is the same as the result +/// array length. They optimize especially well when the optimizer can easily determine +/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements +/// [TryFrom](crate::convert::TryFrom) returning: +/// +/// - `[T; N]` copies from the slice's elements +/// - `&[T; N]` references the original slice's elements +/// - `&mut [T; N]` references the original slice's elements /// /// You can move elements out of an array with a [slice pattern]. If you want /// one element, see [`mem::replace`]. @@ -640,6 +652,15 @@ mod prim_pointer {} /// for x in &array { } /// ``` /// +/// You can use `::try_from(slice)` or `slice.try_into()` to get an array from +/// a slice: +/// +/// ``` +/// let bytes: [u8; 3] = [1, 0, 2]; +/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap())); +/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap())); +/// ``` +/// /// You can use a [slice pattern] to move elements out of an array: /// /// ``` From 1ec92c8fb8887b468d47e8e417605ab13a7800e9 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 14 Sep 2022 13:41:29 -0700 Subject: [PATCH 02/13] rustdoc: add test cases for turning ``[Vec]`` into ``[`Vec`]`` --- .../suggestions/html-as-generics.fixed | 10 ++++++++ .../suggestions/html-as-generics.rs | 10 ++++++++ .../suggestions/html-as-generics.stderr | 24 ++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.fixed b/src/test/rustdoc-ui/suggestions/html-as-generics.fixed index 07c8c9ff254bc..003542d3855a4 100644 --- a/src/test/rustdoc-ui/suggestions/html-as-generics.fixed +++ b/src/test/rustdoc-ui/suggestions/html-as-generics.fixed @@ -70,3 +70,13 @@ pub struct NestedGenericsWithPunct; //~^ ERROR unclosed HTML tag `i32` //~|HELP try marking as source pub struct NestedGenericsWithPunct2; + +/// This [`Vec`] thing! +//~^ERROR unclosed HTML tag `i32` +//~|HELP try marking as source +pub struct IntraDocLink; + +/// This [`Vec::`] thing! +//~^ERROR unclosed HTML tag `i32` +//~|HELP try marking as source +pub struct IntraDocLinkTurbofish; diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.rs b/src/test/rustdoc-ui/suggestions/html-as-generics.rs index cdd652f397ec4..4254a660b19ec 100644 --- a/src/test/rustdoc-ui/suggestions/html-as-generics.rs +++ b/src/test/rustdoc-ui/suggestions/html-as-generics.rs @@ -70,3 +70,13 @@ pub struct NestedGenericsWithPunct; //~^ ERROR unclosed HTML tag `i32` //~|HELP try marking as source pub struct NestedGenericsWithPunct2; + +/// This [Vec] thing! +//~^ERROR unclosed HTML tag `i32` +//~|HELP try marking as source +pub struct IntraDocLink; + +/// This [Vec::] thing! +//~^ERROR unclosed HTML tag `i32` +//~|HELP try marking as source +pub struct IntraDocLinkTurbofish; diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.stderr b/src/test/rustdoc-ui/suggestions/html-as-generics.stderr index 211dd4210d50c..481278bdaf9a2 100644 --- a/src/test/rustdoc-ui/suggestions/html-as-generics.stderr +++ b/src/test/rustdoc-ui/suggestions/html-as-generics.stderr @@ -157,5 +157,27 @@ help: try marking as source code LL | /// Generics with punct `Vec>`! | + + -error: aborting due to 14 previous errors +error: unclosed HTML tag `i32` + --> $DIR/html-as-generics.rs:74:14 + | +LL | /// This [Vec] thing! + | ^^^^^ + | +help: try marking as source code + | +LL | /// This [`Vec`] thing! + | + + + +error: unclosed HTML tag `i32` + --> $DIR/html-as-generics.rs:79:16 + | +LL | /// This [Vec::] thing! + | ^^^^^ + | +help: try marking as source code + | +LL | /// This [`Vec::`] thing! + | + + + +error: aborting due to 16 previous errors From 44506f38e079caec1b6c14e05a9b86e19544757f Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Wed, 14 Sep 2022 21:00:00 +0800 Subject: [PATCH 03/13] add note for `layout_of` when query depth overflows --- .../locales/en-US/query_system.ftl | 2 ++ compiler/rustc_query_impl/src/plumbing.rs | 2 +- compiler/rustc_query_system/src/error.rs | 14 ++++++++++- compiler/rustc_query_system/src/query/job.rs | 24 ++++++++++++++++++- compiler/rustc_query_system/src/query/mod.rs | 15 ++++++++++-- 5 files changed, 52 insertions(+), 5 deletions(-) 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..050a41fc7f9dd 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,5 @@ 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! + +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 6fb3c69b1f47e..3ca657cbca17c 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -109,7 +109,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. diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 3fb06cbedbd50..5f57a1510aa5f 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -77,4 +77,16 @@ pub struct IncrementCompilation { #[derive(SessionDiagnostic)] #[diag(query_system::query_overflow)] -pub struct QueryOverflow; +pub struct QueryOverflow { + #[subdiagnostic] + pub layout_of_depth: Option, +} + +#[derive(SessionSubdiagnostic)] +#[note(query_system::layout_of_depth)] +pub struct LayoutOfDepth { + #[primary_span] + pub span: Span, + pub desc: String, + pub depth: usize, +} diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 45b4079fb54f8..a5ea3a098a649 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,27 @@ impl QueryJobId { panic!("did not find a cycle") } + + #[cold] + #[inline(never)] + pub(super) 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..e29e8815331ee 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -123,7 +123,18 @@ 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) { + let sess = self.dep_context().sess(); + 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) { + layout_of_depth = Some(crate::error::LayoutOfDepth { + span: info.job.span, + desc: info.query.description, + depth, + }); + } + } + sess.emit_fatal(crate::error::QueryOverflow { layout_of_depth }); } } From 89fd6ae458c96f7c3be00d93861ed3f0aa53d95b Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Thu, 15 Sep 2022 15:45:17 +0800 Subject: [PATCH 04/13] correct span, add help message and add UI test when query depth overflows --- .../locales/en-US/query_system.ftl | 3 +- compiler/rustc_query_impl/src/plumbing.rs | 27 +++++++++++++++- compiler/rustc_query_system/src/error.rs | 10 ++++-- compiler/rustc_query_system/src/lib.rs | 2 ++ compiler/rustc_query_system/src/query/job.rs | 5 +-- compiler/rustc_query_system/src/query/mod.rs | 17 ++-------- src/test/ui/query-system/query_depth.rs | 31 +++++++++++++++++++ src/test/ui/query-system/query_depth.stderr | 11 +++++++ 8 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 src/test/ui/query-system/query_depth.rs create mode 100644 src/test/ui/query-system/query_depth.stderr 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 050a41fc7f9dd..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,5 +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}! +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 3ca657cbca17c..b9edb757b568a 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; @@ -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 5f57a1510aa5f..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,17 +77,20 @@ pub struct IncrementCompilation { } #[derive(SessionDiagnostic)] +#[help] #[diag(query_system::query_overflow)] 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 { - #[primary_span] - pub span: Span, 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 8a88b5c334078..78b06f520a855 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 a5ea3a098a649..95305eabd0d34 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -160,10 +160,7 @@ impl QueryJobId { #[cold] #[inline(never)] - pub(super) fn try_find_layout_root( - &self, - query_map: QueryMap, - ) -> Option<(QueryJobInfo, usize)> { + 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; diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index e29e8815331ee..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,18 +123,5 @@ pub trait QueryContext: HasDepContext { compute: impl FnOnce() -> R, ) -> R; - fn depth_limit_error(&self, job: QueryJobId) { - let sess = self.dep_context().sess(); - 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) { - layout_of_depth = Some(crate::error::LayoutOfDepth { - span: info.job.span, - desc: info.query.description, - depth, - }); - } - } - sess.emit_fatal(crate::error::QueryOverflow { layout_of_depth }); - } + fn depth_limit_error(&self, job: QueryJobId); } 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 + From 9286c3c3f5ff1880a27d90f8f4a4c21165f98adb Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 15 Sep 2022 11:39:03 -0400 Subject: [PATCH 05/13] Update stdarch stdarch updated their version of `cfg-if` so we need to update the one used by libstd as well. --- Cargo.lock | 8 ++++++-- library/std/Cargo.toml | 2 +- library/stdarch | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e0e72d34153f..787ba8acfe2e5 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" @@ -4603,7 +4607,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", @@ -4627,7 +4631,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/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 From 532e3a50ebf5ed0b2c6b097bab5fc34ee576216f Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 16 Sep 2022 01:27:47 +0400 Subject: [PATCH 06/13] Allow building `rust-analyzer-proc-macro-srv` as a standalone tool --- src/bootstrap/tool.rs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index c3b04a9bbce3f..77109659ca7e6 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -745,14 +745,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<'_>) { @@ -763,7 +767,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", @@ -772,7 +776,19 @@ 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 `build/triple/stageN/libexec/` + // so that r-a can use it. + let libexec_path = builder + .out + .join(&*builder.config.build.triple) + .join(format!("stage{}", self.compiler.stage)) + .join("libexec"); + t!(fs::create_dir_all(&libexec_path)); + builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv")); + + Some(path) } } From 9c3c88c94563ed9c42b7c6549c89e5fc8cc5615e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 16 Sep 2022 11:10:20 +0400 Subject: [PATCH 07/13] Use `builder.sysroot(...)` instead of a hack --- src/bootstrap/tool.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 77109659ca7e6..d603f2bb8ab07 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -778,13 +778,9 @@ impl Step for RustAnalyzerProcMacroSrv { source_type: SourceType::InTree, })?; - // Copy `rust-analyzer-proc-macro-srv` to `build/triple/stageN/libexec/` + // Copy `rust-analyzer-proc-macro-srv` to `/libexec/` // so that r-a can use it. - let libexec_path = builder - .out - .join(&*builder.config.build.triple) - .join(format!("stage{}", self.compiler.stage)) - .join("libexec"); + 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")); From 1c659977d6f2ff3b2d70cfb2607cd8725d9fbe03 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 16 Sep 2022 17:57:07 +0200 Subject: [PATCH 08/13] Create new CSS variables for links color --- src/librustdoc/html/static/css/rustdoc.css | 43 +++++++++++++++++++ src/librustdoc/html/static/css/themes/ayu.css | 40 ++++------------- .../html/static/css/themes/dark.css | 31 ++++--------- .../html/static/css/themes/light.css | 31 ++++--------- 4 files changed, 67 insertions(+), 78 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 8bfaaf21c8e57..1f2138cf1919a 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -242,6 +242,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; } 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; } From 5d449a017b1740939d56d42ab5025f9854b407b2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 16 Sep 2022 18:22:23 +0200 Subject: [PATCH 09/13] Add GUI test for links colors --- src/test/rustdoc-gui/links-color.goml | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/rustdoc-gui/links-color.goml 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, +) From 999502978612be1379240f792614f8580e49d123 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Tue, 13 Sep 2022 16:06:07 -0700 Subject: [PATCH 10/13] Remove the allow-list for dynamic linking of LLVM tools This commit removes an allow-list for the dynamic linking of the LLVM tools and instead relies on the builder's linking preference only. --- src/bootstrap/lib.rs | 4 ---- src/bootstrap/native.rs | 9 ++------- src/ci/github-actions/ci.yml | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index cc0cf12bd187a..fade44ecb158b 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1307,10 +1307,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/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 From b72de9be74dd5ac1d8b23d5ece03a7690274a14c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Sep 2022 13:40:21 -0700 Subject: [PATCH 11/13] rustdoc: clean up CSS for All Items and All Crates lists This reduces the amount of CSS, and makes these two pages more consistent (which, necessarily, means changing them a bit). --- src/librustdoc/html/render/mod.rs | 35 +++++++++++----------- src/librustdoc/html/render/write_shared.rs | 4 +-- src/librustdoc/html/static/css/rustdoc.css | 9 ++---- 3 files changed, 22 insertions(+), 26 deletions(-) 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 ccb302620603c..7570c92c211ed 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; } @@ -788,6 +787,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; @@ -1517,10 +1517,7 @@ kbd { cursor: default; } -#main-content > ul { - padding-left: 10px; -} -#main-content > ul > li { +ul.all-items > li { list-style: none; } From a87a883f4adfc6be528a04216a3615e4907fffd4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Sep 2022 14:40:24 -0700 Subject: [PATCH 12/13] rustdoc: update test case for All Crates page --- src/test/rustdoc/index-page.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From d1291dc8b4ac9a98ff1d286402559e4ba5d68488 Mon Sep 17 00:00:00 2001 From: Chris Wailes Date: Tue, 13 Sep 2022 16:13:43 -0700 Subject: [PATCH 13/13] Improve handing of env vars during bootstrap process This CL modifies the handing of env vars during the bootstrap process in two ways: 1. Replaces '-' characters with '_' characters in target names to increase compatibility with different shells 2. Passes Stage0 snapshot compiler related env vars to early invocations of Cargo --- src/bootstrap/bootstrap.py | 15 +++++++++++---- src/bootstrap/builder.rs | 13 +++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) 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..b654db6dbe9a3 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1940,25 +1940,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); } }