Skip to content

Commit 4f66117

Browse files
committed
Auto merge of rust-lang#76265 - Dylan-DPC:rollup-j3i509l, r=Dylan-DPC
Rollup of 12 pull requests Successful merges: - rust-lang#75150 (Add a note for Ipv4Addr::to_ipv6_compatible) - rust-lang#76120 (Add `[T; N]::as_[mut_]slice`) - rust-lang#76142 (Make all methods of `std::net::Ipv4Addr` const) - rust-lang#76164 (Link to slice pattern in array docs) - rust-lang#76167 (Replace MinGW library hack with heuristic controlling link mode) - rust-lang#76204 (Rename and expose LoopState as ControlFlow) - rust-lang#76238 (Move to intra-doc links for library/core/src/iter/traits/iterator.rs) - rust-lang#76242 (Read: adjust a FIXME reference) - rust-lang#76243 (Fix typos in vec try_reserve(_exact) docs) - rust-lang#76245 (inliner: Avoid query cycles when optimizing generators) - rust-lang#76255 (Update books) - rust-lang#76261 (Use intra-doc links in `core::marker`) Failed merges: r? @ghost
2 parents 51f79b6 + af331a2 commit 4f66117

File tree

25 files changed

+365
-304
lines changed

25 files changed

+365
-304
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+25-92
Original file line numberDiff line numberDiff line change
@@ -1014,86 +1014,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
10141014
}
10151015
}
10161016

1017-
// Because windows-gnu target is meant to be self-contained for pure Rust code it bundles
1018-
// own mingw-w64 libraries. These libraries are usually not compatible with mingw-w64
1019-
// installed in the system. This breaks many cases where Rust is mixed with other languages
1020-
// (e.g. *-sys crates).
1021-
// We prefer system mingw-w64 libraries if they are available to avoid this issue.
1022-
fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
1023-
fn find_exe_in_path<P>(exe_name: P) -> Option<PathBuf>
1024-
where
1025-
P: AsRef<Path>,
1026-
{
1027-
for dir in env::split_paths(&env::var_os("PATH")?) {
1028-
let full_path = dir.join(&exe_name);
1029-
if full_path.is_file() {
1030-
return Some(fix_windows_verbatim_for_gcc(&full_path));
1031-
}
1032-
}
1033-
None
1034-
}
1035-
1036-
fn probe(sess: &Session) -> Option<PathBuf> {
1037-
if let (linker, LinkerFlavor::Gcc) = linker_and_flavor(&sess) {
1038-
let linker_path = if cfg!(windows) && linker.extension().is_none() {
1039-
linker.with_extension("exe")
1040-
} else {
1041-
linker
1042-
};
1043-
if let Some(linker_path) = find_exe_in_path(linker_path) {
1044-
let mingw_arch = match &sess.target.target.arch {
1045-
x if x == "x86" => "i686",
1046-
x => x,
1047-
};
1048-
let mingw_bits = &sess.target.target.target_pointer_width;
1049-
let mingw_dir = format!("{}-w64-mingw32", mingw_arch);
1050-
// Here we have path/bin/gcc but we need path/
1051-
let mut path = linker_path;
1052-
path.pop();
1053-
path.pop();
1054-
// Loosely based on Clang MinGW driver
1055-
let probe_paths = vec![
1056-
path.join(&mingw_dir).join("lib"), // Typical path
1057-
path.join(&mingw_dir).join("sys-root/mingw/lib"), // Rare path
1058-
path.join(format!(
1059-
"lib/mingw/tools/install/mingw{}/{}/lib",
1060-
&mingw_bits, &mingw_dir
1061-
)), // Chocolatey is creative
1062-
];
1063-
for probe_path in probe_paths {
1064-
if probe_path.join("crt2.o").exists() {
1065-
return Some(probe_path);
1066-
};
1067-
}
1068-
};
1069-
};
1070-
None
1071-
}
1072-
1073-
let mut system_library_path = sess.system_library_path.borrow_mut();
1074-
match &*system_library_path {
1075-
Some(Some(compiler_libs_path)) => Some(compiler_libs_path.clone()),
1076-
Some(None) => None,
1077-
None => {
1078-
let path = probe(sess);
1079-
*system_library_path = Some(path.clone());
1080-
path
1081-
}
1082-
}
1083-
}
1084-
10851017
fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> PathBuf {
1086-
// prefer system {,dll}crt2.o libs, see get_crt_libs_path comment for more details
1087-
if sess.opts.cg.link_self_contained.is_none()
1088-
&& sess.target.target.llvm_target.contains("windows-gnu")
1089-
{
1090-
if let Some(compiler_libs_path) = get_crt_libs_path(sess) {
1091-
let file_path = compiler_libs_path.join(name);
1092-
if file_path.exists() {
1093-
return file_path;
1094-
}
1095-
}
1096-
}
10971018
let fs = sess.target_filesearch(PathKind::Native);
10981019
let file_path = fs.get_lib_path().join(name);
10991020
if file_path.exists() {
@@ -1286,6 +1207,28 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
12861207
}
12871208
}
12881209

1210+
// Returns true if linker is located within sysroot
1211+
fn detect_self_contained_mingw(sess: &Session) -> bool {
1212+
let (linker, _) = linker_and_flavor(&sess);
1213+
// Assume `-C linker=rust-lld` as self-contained mode
1214+
if linker == Path::new("rust-lld") {
1215+
return true;
1216+
}
1217+
let linker_with_extension = if cfg!(windows) && linker.extension().is_none() {
1218+
linker.with_extension("exe")
1219+
} else {
1220+
linker
1221+
};
1222+
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
1223+
let full_path = dir.join(&linker_with_extension);
1224+
// If linker comes from sysroot assume self-contained mode
1225+
if full_path.is_file() && !full_path.starts_with(&sess.sysroot) {
1226+
return false;
1227+
}
1228+
}
1229+
true
1230+
}
1231+
12891232
/// Whether we link to our own CRT objects instead of relying on gcc to pull them.
12901233
/// We only provide such support for a very limited number of targets.
12911234
fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
@@ -1298,10 +1241,10 @@ fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
12981241
// based on host and linker path, for example.
12991242
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
13001243
Some(CrtObjectsFallback::Musl) => sess.crt_static(Some(crate_type)),
1301-
// FIXME: Find some heuristic for "native mingw toolchain is available",
1302-
// likely based on `get_crt_libs_path` (https://github.com/rust-lang/rust/pull/67429).
13031244
Some(CrtObjectsFallback::Mingw) => {
1304-
sess.host == sess.target.target && sess.target.target.target_vendor != "uwp"
1245+
sess.host == sess.target.target
1246+
&& sess.target.target.target_vendor != "uwp"
1247+
&& detect_self_contained_mingw(&sess)
13051248
}
13061249
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
13071250
Some(CrtObjectsFallback::Wasm) => true,
@@ -1498,16 +1441,6 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
14981441

14991442
/// Add sysroot and other globally set directories to the directory search list.
15001443
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
1501-
// Prefer system mingw-w64 libs, see get_crt_libs_path comment for more details.
1502-
if sess.opts.cg.link_self_contained.is_none()
1503-
&& cfg!(windows)
1504-
&& sess.target.target.llvm_target.contains("windows-gnu")
1505-
{
1506-
if let Some(compiler_libs_path) = get_crt_libs_path(sess) {
1507-
cmd.include_path(&compiler_libs_path);
1508-
}
1509-
}
1510-
15111444
// The default library location, we need this to find the runtime.
15121445
// The location of crates will be determined as needed.
15131446
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path();

compiler/rustc_mir/src/transform/inline.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ impl Inliner<'tcx> {
107107
// Avoid a cycle here by only using `optimized_mir` only if we have
108108
// a lower `HirId` than the callee. This ensures that the callee will
109109
// not inline us. This trick only works without incremental compilation.
110-
// So don't do it if that is enabled.
111-
if !self.tcx.dep_graph.is_fully_enabled() && self_hir_id < callee_hir_id {
110+
// So don't do it if that is enabled. Also avoid inlining into generators,
111+
// since their `optimized_mir` is used for layout computation, which can
112+
// create a cycle, even when no attempt is made to inline the function
113+
// in the other direction.
114+
if !self.tcx.dep_graph.is_fully_enabled()
115+
&& self_hir_id < callee_hir_id
116+
&& caller_body.generator_kind.is_none()
117+
{
112118
self.tcx.optimized_mir(callsite.callee)
113119
} else {
114120
continue;

library/alloc/src/collections/vec_deque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ impl<T> VecDeque<T> {
685685
}
686686

687687
/// Tries to reserve the minimum capacity for exactly `additional` more elements to
688-
/// be inserted in the given `VecDeque<T>`. After calling `reserve_exact`,
688+
/// be inserted in the given `VecDeque<T>`. After calling `try_reserve_exact`,
689689
/// capacity will be greater than or equal to `self.len() + additional`.
690690
/// Does nothing if the capacity is already sufficient.
691691
///
@@ -727,7 +727,7 @@ impl<T> VecDeque<T> {
727727

728728
/// Tries to reserve capacity for at least `additional` more elements to be inserted
729729
/// in the given `VecDeque<T>`. The collection may reserve more space to avoid
730-
/// frequent reallocations. After calling `reserve`, capacity will be
730+
/// frequent reallocations. After calling `try_reserve`, capacity will be
731731
/// greater than or equal to `self.len() + additional`. Does nothing if
732732
/// capacity is already sufficient.
733733
///

library/alloc/src/vec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<T> Vec<T> {
523523

524524
/// Tries to reserve capacity for at least `additional` more elements to be inserted
525525
/// in the given `Vec<T>`. The collection may reserve more space to avoid
526-
/// frequent reallocations. After calling `reserve`, capacity will be
526+
/// frequent reallocations. After calling `try_reserve`, capacity will be
527527
/// greater than or equal to `self.len() + additional`. Does nothing if
528528
/// capacity is already sufficient.
529529
///
@@ -559,7 +559,7 @@ impl<T> Vec<T> {
559559
}
560560

561561
/// Tries to reserves the minimum capacity for exactly `additional` more elements to
562-
/// be inserted in the given `Vec<T>`. After calling `reserve_exact`,
562+
/// be inserted in the given `Vec<T>`. After calling `try_reserve_exact`,
563563
/// capacity will be greater than or equal to `self.len() + additional`.
564564
/// Does nothing if the capacity is already sufficient.
565565
///
@@ -582,7 +582,7 @@ impl<T> Vec<T> {
582582
/// let mut output = Vec::new();
583583
///
584584
/// // Pre-reserve the memory, exiting if we can't
585-
/// output.try_reserve(data.len())?;
585+
/// output.try_reserve_exact(data.len())?;
586586
///
587587
/// // Now we know this can't OOM in the middle of our complex work
588588
/// output.extend(data.iter().map(|&val| {

library/core/src/array/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,17 @@ impl<T, const N: usize> [T; N] {
422422
// and we just need to cast it to the correct type.
423423
unsafe { crate::mem::transmute_copy::<_, [U; N]>(&dst) }
424424
}
425+
426+
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
427+
#[unstable(feature = "array_methods", issue = "76118")]
428+
pub fn as_slice(&self) -> &[T] {
429+
self
430+
}
431+
432+
/// Returns a mutable slice containing the entire array. Equivalent to
433+
/// `&mut s[..]`.
434+
#[unstable(feature = "array_methods", issue = "76118")]
435+
pub fn as_mut_slice(&mut self) -> &mut [T] {
436+
self
437+
}
425438
}

library/core/src/iter/adapters/mod.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::cmp;
22
use crate::fmt;
33
use crate::intrinsics;
4-
use crate::ops::{Add, AddAssign, Try};
4+
use crate::ops::{Add, AddAssign, ControlFlow, Try};
55

6-
use super::{from_fn, LoopState};
6+
use super::from_fn;
77
use super::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, Iterator, TrustedLen};
88

99
mod chain;
@@ -1164,10 +1164,10 @@ where
11641164
#[inline]
11651165
fn find<T, B>(
11661166
f: &mut impl FnMut(T) -> Option<B>,
1167-
) -> impl FnMut((), T) -> LoopState<(), B> + '_ {
1167+
) -> impl FnMut((), T) -> ControlFlow<(), B> + '_ {
11681168
move |(), x| match f(x) {
1169-
Some(x) => LoopState::Break(x),
1170-
None => LoopState::Continue(()),
1169+
Some(x) => ControlFlow::Break(x),
1170+
None => ControlFlow::Continue(()),
11711171
}
11721172
}
11731173

@@ -1864,13 +1864,13 @@ where
18641864
flag: &'a mut bool,
18651865
p: &'a mut impl FnMut(&T) -> bool,
18661866
mut fold: impl FnMut(Acc, T) -> R + 'a,
1867-
) -> impl FnMut(Acc, T) -> LoopState<Acc, R> + 'a {
1867+
) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
18681868
move |acc, x| {
18691869
if p(&x) {
1870-
LoopState::from_try(fold(acc, x))
1870+
ControlFlow::from_try(fold(acc, x))
18711871
} else {
18721872
*flag = true;
1873-
LoopState::Break(Try::from_ok(acc))
1873+
ControlFlow::Break(Try::from_ok(acc))
18741874
}
18751875
}
18761876
}
@@ -1963,8 +1963,8 @@ where
19631963
{
19641964
let Self { iter, predicate } = self;
19651965
iter.try_fold(init, |acc, x| match predicate(x) {
1966-
Some(item) => LoopState::from_try(fold(acc, item)),
1967-
None => LoopState::Break(Try::from_ok(acc)),
1966+
Some(item) => ControlFlow::from_try(fold(acc, item)),
1967+
None => ControlFlow::Break(Try::from_ok(acc)),
19681968
})
19691969
.into_try()
19701970
}
@@ -2135,11 +2135,11 @@ where
21352135
fn check<T, Acc, R: Try<Ok = Acc>>(
21362136
mut n: usize,
21372137
mut fold: impl FnMut(Acc, T) -> R,
2138-
) -> impl FnMut(Acc, T) -> LoopState<Acc, R> {
2138+
) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> {
21392139
move |acc, x| {
21402140
n -= 1;
21412141
let r = fold(acc, x);
2142-
if n == 0 { LoopState::Break(r) } else { LoopState::from_try(r) }
2142+
if n == 0 { ControlFlow::Break(r) } else { ControlFlow::from_try(r) }
21432143
}
21442144
}
21452145

@@ -2246,11 +2246,11 @@ where
22462246
fn check<'a, T, Acc, R: Try<Ok = Acc>>(
22472247
n: &'a mut usize,
22482248
mut fold: impl FnMut(Acc, T) -> R + 'a,
2249-
) -> impl FnMut(Acc, T) -> LoopState<Acc, R> + 'a {
2249+
) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
22502250
move |acc, x| {
22512251
*n -= 1;
22522252
let r = fold(acc, x);
2253-
if *n == 0 { LoopState::Break(r) } else { LoopState::from_try(r) }
2253+
if *n == 0 { ControlFlow::Break(r) } else { ControlFlow::from_try(r) }
22542254
}
22552255
}
22562256

@@ -2414,10 +2414,10 @@ where
24142414
state: &'a mut St,
24152415
f: &'a mut impl FnMut(&mut St, T) -> Option<B>,
24162416
mut fold: impl FnMut(Acc, B) -> R + 'a,
2417-
) -> impl FnMut(Acc, T) -> LoopState<Acc, R> + 'a {
2417+
) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
24182418
move |acc, x| match f(state, x) {
2419-
None => LoopState::Break(Try::from_ok(acc)),
2420-
Some(x) => LoopState::from_try(fold(acc, x)),
2419+
None => ControlFlow::Break(Try::from_ok(acc)),
2420+
Some(x) => ControlFlow::from_try(fold(acc, x)),
24212421
}
24222422
}
24232423

@@ -2638,10 +2638,10 @@ where
26382638
let error = &mut *self.error;
26392639
self.iter
26402640
.try_fold(init, |acc, x| match x {
2641-
Ok(x) => LoopState::from_try(f(acc, x)),
2641+
Ok(x) => ControlFlow::from_try(f(acc, x)),
26422642
Err(e) => {
26432643
*error = Err(e);
2644-
LoopState::Break(Try::from_ok(acc))
2644+
ControlFlow::Break(Try::from_ok(acc))
26452645
}
26462646
})
26472647
.into_try()

0 commit comments

Comments
 (0)