Skip to content

Commit 98ad6a5

Browse files
committed
Auto merge of rust-lang#101946 - matthiaskrgr:rollup-jqkhsku, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#101672 (array docs - advertise how to get array from slice) - rust-lang#101781 (Extend list of targets that support dyanmic linking for llvm tools) - rust-lang#101783 (Improve handing of env vars during bootstrap process) - rust-lang#101801 (add note for `layout_of` when query depth overflows) - rust-lang#101824 (rustdoc: add test cases for turning ``[Vec<T>]`` into ``[`Vec<T>`]``) - rust-lang#101861 (Update stdarch) - rust-lang#101873 (Allow building `rust-analyzer-proc-macro-srv` as a standalone tool) - rust-lang#101918 (rustdoc: clean up CSS for All Items and All Crates lists) - rust-lang#101934 (Continue migration of CSS themes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c773c13 + 1f31bee commit 98ad6a5

File tree

31 files changed

+476
-154
lines changed

31 files changed

+476
-154
lines changed

Diff for: Cargo.lock

+6-2
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ name = "cfg-if"
507507
version = "1.0.0"
508508
source = "registry+https://github.com/rust-lang/crates.io-index"
509509
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
510+
dependencies = [
511+
"compiler_builtins",
512+
"rustc-std-workspace-core",
513+
]
510514

511515
[[package]]
512516
name = "chalk-derive"
@@ -4613,7 +4617,7 @@ version = "0.0.0"
46134617
dependencies = [
46144618
"addr2line 0.16.0",
46154619
"alloc",
4616-
"cfg-if 0.1.10",
4620+
"cfg-if 1.0.0",
46174621
"compiler_builtins",
46184622
"core",
46194623
"dlmalloc",
@@ -4637,7 +4641,7 @@ dependencies = [
46374641
name = "std_detect"
46384642
version = "0.1.5"
46394643
dependencies = [
4640-
"cfg-if 0.1.10",
4644+
"cfg-if 1.0.0",
46414645
"compiler_builtins",
46424646
"libc",
46434647
"rustc-std-workspace-alloc",

Diff for: compiler/rustc_error_messages/locales/en-US/query_system.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
2323
query_system_cycle_which_requires = ...which requires {$desc}...
2424
2525
query_system_query_overflow = queries overflow the depth limit!
26+
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
27+
28+
query_system_layout_of_depth = query depth increased by {$depth} when {$desc}

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ use rustc_query_system::query::{
1919
force_query, QueryConfig, QueryContext, QueryDescription, QueryJobId, QueryMap,
2020
QuerySideEffects, QueryStackFrame,
2121
};
22-
use rustc_query_system::Value;
22+
use rustc_query_system::{LayoutOfDepth, QueryOverflow, Value};
2323
use rustc_serialize::Decodable;
24+
use rustc_session::Limit;
25+
use rustc_span::def_id::LOCAL_CRATE;
2426
use std::any::Any;
2527
use std::num::NonZeroU64;
2628
use thin_vec::ThinVec;
@@ -109,7 +111,7 @@ impl QueryContext for QueryCtxt<'_> {
109111
// when accessing the `ImplicitCtxt`.
110112
tls::with_related_context(**self, move |current_icx| {
111113
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
112-
self.depth_limit_error();
114+
self.depth_limit_error(token);
113115
}
114116

115117
// Update the `ImplicitCtxt` to point to our new query job.
@@ -127,6 +129,29 @@ impl QueryContext for QueryCtxt<'_> {
127129
})
128130
})
129131
}
132+
133+
fn depth_limit_error(&self, job: QueryJobId) {
134+
let mut span = None;
135+
let mut layout_of_depth = None;
136+
if let Some(map) = self.try_collect_active_jobs() {
137+
if let Some((info, depth)) = job.try_find_layout_root(map) {
138+
span = Some(info.job.span);
139+
layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth });
140+
}
141+
}
142+
143+
let suggested_limit = match self.recursion_limit() {
144+
Limit(0) => Limit(2),
145+
limit => limit * 2,
146+
};
147+
148+
self.sess.emit_fatal(QueryOverflow {
149+
span,
150+
layout_of_depth,
151+
suggested_limit,
152+
crate_name: self.crate_name(LOCAL_CRATE),
153+
});
154+
}
130155
}
131156

132157
impl<'tcx> QueryCtxt<'tcx> {

Diff for: compiler/rustc_query_system/src/error.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_errors::AddSubdiagnostic;
2-
use rustc_span::Span;
2+
use rustc_session::Limit;
3+
use rustc_span::{Span, Symbol};
34

45
pub struct CycleStack {
56
pub span: Span,
@@ -76,5 +77,20 @@ pub struct IncrementCompilation {
7677
}
7778

7879
#[derive(SessionDiagnostic)]
80+
#[help]
7981
#[diag(query_system::query_overflow)]
80-
pub struct QueryOverflow;
82+
pub struct QueryOverflow {
83+
#[primary_span]
84+
pub span: Option<Span>,
85+
#[subdiagnostic]
86+
pub layout_of_depth: Option<LayoutOfDepth>,
87+
pub suggested_limit: Limit,
88+
pub crate_name: Symbol,
89+
}
90+
91+
#[derive(SessionSubdiagnostic)]
92+
#[note(query_system::layout_of_depth)]
93+
pub struct LayoutOfDepth {
94+
pub desc: String,
95+
pub depth: usize,
96+
}

Diff for: compiler/rustc_query_system/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ pub mod query;
2323
mod values;
2424

2525
pub use error::HandleCycleError;
26+
pub use error::LayoutOfDepth;
27+
pub use error::QueryOverflow;
2628
pub use values::Value;

Diff for: compiler/rustc_query_system/src/query/job.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl QueryJobId {
5959
}
6060
}
6161

62+
#[derive(Clone)]
6263
pub struct QueryJobInfo {
6364
pub query: QueryStackFrame,
6465
pub job: QueryJob,
@@ -116,10 +117,10 @@ impl QueryJob {
116117
}
117118
}
118119

119-
#[cfg(not(parallel_compiler))]
120120
impl QueryJobId {
121121
#[cold]
122122
#[inline(never)]
123+
#[cfg(not(parallel_compiler))]
123124
pub(super) fn find_cycle_in_stack(
124125
&self,
125126
query_map: QueryMap,
@@ -156,6 +157,24 @@ impl QueryJobId {
156157

157158
panic!("did not find a cycle")
158159
}
160+
161+
#[cold]
162+
#[inline(never)]
163+
pub fn try_find_layout_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> {
164+
let mut last_layout = None;
165+
let mut current_id = Some(*self);
166+
let mut depth = 0;
167+
168+
while let Some(id) = current_id {
169+
let info = query_map.get(&id).unwrap();
170+
if info.query.name == "layout_of" {
171+
depth += 1;
172+
last_layout = Some((info.clone(), depth));
173+
}
174+
current_id = info.job.parent;
175+
}
176+
last_layout
177+
}
159178
}
160179

161180
#[cfg(parallel_compiler)]

Diff for: compiler/rustc_query_system/src/query/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::caches::{
1414
mod config;
1515
pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
1616

17-
use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
17+
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
1818
use rustc_data_structures::sync::Lock;
1919
use rustc_errors::Diagnostic;
2020
use rustc_hir::def::DefKind;
@@ -123,7 +123,5 @@ pub trait QueryContext: HasDepContext {
123123
compute: impl FnOnce() -> R,
124124
) -> R;
125125

126-
fn depth_limit_error(&self) {
127-
self.dep_context().sess().emit_fatal(crate::error::QueryOverflow);
128-
}
126+
fn depth_limit_error(&self, job: QueryJobId);
129127
}

Diff for: library/core/src/array/mod.rs

+48
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
184184
}
185185
}
186186

187+
/// Tries to create an array `[T; N]` by copying from a slice `&[T]`. Succeeds if
188+
/// `slice.len() == N`.
189+
///
190+
/// ```
191+
/// let bytes: [u8; 3] = [1, 0, 2];
192+
///
193+
/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap();
194+
/// assert_eq!(1, u16::from_le_bytes(bytes_head));
195+
///
196+
/// let bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap();
197+
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
198+
/// ```
187199
#[stable(feature = "try_from", since = "1.34.0")]
188200
impl<T, const N: usize> TryFrom<&[T]> for [T; N]
189201
where
@@ -196,6 +208,18 @@ where
196208
}
197209
}
198210

211+
/// Tries to create an array `[T; N]` by copying from a mutable slice `&mut [T]`.
212+
/// Succeeds if `slice.len() == N`.
213+
///
214+
/// ```
215+
/// let mut bytes: [u8; 3] = [1, 0, 2];
216+
///
217+
/// let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
218+
/// assert_eq!(1, u16::from_le_bytes(bytes_head));
219+
///
220+
/// let bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
221+
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
222+
/// ```
199223
#[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")]
200224
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]
201225
where
@@ -208,6 +232,18 @@ where
208232
}
209233
}
210234

235+
/// Tries to create an array ref `&[T; N]` from a slice ref `&[T]`. Succeeds if
236+
/// `slice.len() == N`.
237+
///
238+
/// ```
239+
/// let bytes: [u8; 3] = [1, 0, 2];
240+
///
241+
/// let bytes_head: &[u8; 2] = <&[u8; 2]>::try_from(&bytes[0..2]).unwrap();
242+
/// assert_eq!(1, u16::from_le_bytes(*bytes_head));
243+
///
244+
/// let bytes_tail: &[u8; 2] = bytes[1..3].try_into().unwrap();
245+
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
246+
/// ```
211247
#[stable(feature = "try_from", since = "1.34.0")]
212248
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
213249
type Error = TryFromSliceError;
@@ -223,6 +259,18 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
223259
}
224260
}
225261

262+
/// Tries to create a mutable array ref `&mut [T; N]` from a mutable slice ref
263+
/// `&mut [T]`. Succeeds if `slice.len() == N`.
264+
///
265+
/// ```
266+
/// let mut bytes: [u8; 3] = [1, 0, 2];
267+
///
268+
/// let bytes_head: &mut [u8; 2] = <&mut [u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
269+
/// assert_eq!(1, u16::from_le_bytes(*bytes_head));
270+
///
271+
/// let bytes_tail: &mut [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
272+
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
273+
/// ```
226274
#[stable(feature = "try_from", since = "1.34.0")]
227275
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
228276
type Error = TryFromSliceError;

Diff for: library/core/src/primitive_docs.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,19 @@ mod prim_pointer {}
611611
///
612612
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
613613
/// an array. Indeed, this provides most of the API for working with arrays.
614-
/// Slices have a dynamic size and do not coerce to arrays.
614+
///
615+
/// Slices have a dynamic size and do not coerce to arrays. Instead, use
616+
/// `slice.try_into().unwrap()` or `<ArrayType>::try_from(slice).unwrap()`.
617+
///
618+
/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()`
619+
/// array implementations) succeed if the input slice length is the same as the result
620+
/// array length. They optimize especially well when the optimizer can easily determine
621+
/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements
622+
/// [TryFrom](crate::convert::TryFrom) returning:
623+
///
624+
/// - `[T; N]` copies from the slice's elements
625+
/// - `&[T; N]` references the original slice's elements
626+
/// - `&mut [T; N]` references the original slice's elements
615627
///
616628
/// You can move elements out of an array with a [slice pattern]. If you want
617629
/// one element, see [`mem::replace`].
@@ -640,6 +652,15 @@ mod prim_pointer {}
640652
/// for x in &array { }
641653
/// ```
642654
///
655+
/// You can use `<ArrayType>::try_from(slice)` or `slice.try_into()` to get an array from
656+
/// a slice:
657+
///
658+
/// ```
659+
/// let bytes: [u8; 3] = [1, 0, 2];
660+
/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap()));
661+
/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap()));
662+
/// ```
663+
///
643664
/// You can use a [slice pattern] to move elements out of an array:
644665
///
645666
/// ```

Diff for: library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["dylib", "rlib"]
1111

1212
[dependencies]
1313
alloc = { path = "../alloc" }
14-
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
14+
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1515
panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }

Diff for: library/std/src/primitive_docs.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,19 @@ mod prim_pointer {}
611611
///
612612
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
613613
/// an array. Indeed, this provides most of the API for working with arrays.
614-
/// Slices have a dynamic size and do not coerce to arrays.
614+
///
615+
/// Slices have a dynamic size and do not coerce to arrays. Instead, use
616+
/// `slice.try_into().unwrap()` or `<ArrayType>::try_from(slice).unwrap()`.
617+
///
618+
/// Array's `try_from(slice)` implementations (and the corresponding `slice.try_into()`
619+
/// array implementations) succeed if the input slice length is the same as the result
620+
/// array length. They optimize especially well when the optimizer can easily determine
621+
/// the slice length, e.g. `<[u8; 4]>::try_from(&slice[4..8]).unwrap()`. Array implements
622+
/// [TryFrom](crate::convert::TryFrom) returning:
623+
///
624+
/// - `[T; N]` copies from the slice's elements
625+
/// - `&[T; N]` references the original slice's elements
626+
/// - `&mut [T; N]` references the original slice's elements
615627
///
616628
/// You can move elements out of an array with a [slice pattern]. If you want
617629
/// one element, see [`mem::replace`].
@@ -640,6 +652,15 @@ mod prim_pointer {}
640652
/// for x in &array { }
641653
/// ```
642654
///
655+
/// You can use `<ArrayType>::try_from(slice)` or `slice.try_into()` to get an array from
656+
/// a slice:
657+
///
658+
/// ```
659+
/// let bytes: [u8; 3] = [1, 0, 2];
660+
/// assert_eq!(1, u16::from_le_bytes(<[u8; 2]>::try_from(&bytes[0..2]).unwrap()));
661+
/// assert_eq!(512, u16::from_le_bytes(bytes[1..3].try_into().unwrap()));
662+
/// ```
663+
///
643664
/// You can use a [slice pattern] to move elements out of an array:
644665
///
645666
/// ```

Diff for: src/bootstrap/bootstrap.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,26 @@ def build_bootstrap(self, color):
732732
(os.pathsep + env["LIBRARY_PATH"]) \
733733
if "LIBRARY_PATH" in env else ""
734734

735+
# Export Stage0 snapshot compiler related env variables
736+
build_section = "target.{}".format(self.build)
737+
host_triple_sanitized = self.build.replace("-", "_")
738+
var_data = {
739+
"CC": "cc", "CXX": "cxx", "LD": "linker", "AR": "ar", "RANLIB": "ranlib"
740+
}
741+
for var_name, toml_key in var_data.items():
742+
toml_val = self.get_toml(toml_key, build_section)
743+
if toml_val != None:
744+
env["{}_{}".format(var_name, host_triple_sanitized)] = toml_val
745+
735746
# preserve existing RUSTFLAGS
736747
env.setdefault("RUSTFLAGS", "")
737-
build_section = "target.{}".format(self.build)
738748
target_features = []
739749
if self.get_toml("crt-static", build_section) == "true":
740750
target_features += ["+crt-static"]
741751
elif self.get_toml("crt-static", build_section) == "false":
742752
target_features += ["-crt-static"]
743753
if target_features:
744754
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
745-
target_linker = self.get_toml("linker", build_section)
746-
if target_linker is not None:
747-
env["RUSTFLAGS"] += " -C linker=" + target_linker
748755
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
749756
env["RUSTFLAGS"] += " -Wsemicolon_in_expressions_from_macros"
750757
if self.get_toml("deny-warnings", "rust") != "false":

0 commit comments

Comments
 (0)