Skip to content

Commit 1d02f3b

Browse files
committed
Auto merge of #149153 - matthiaskrgr:rollup-t1gu3po, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #149033 (autodiff rlib handling) - #149088 (Add missing trailing period to RustDoc for fn create_dir().) - #149111 (fs: Run file lock tests on all platforms that support it) - #149113 (sgx: avoid unnecessarily creating a slice) - #149123 (std: sys: fs: uefi: Fix FileAttr size) - #149125 (In `BTreeMap::eq`, do not compare the elements if the sizes are different.) - #149133 (Remove an unused variable) - #149134 (std: sys: net: uefi: Implement read_vectored) - #149139 (Enable host tools for aarch64-unknown-linux-ohos) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7281a3b + 13031d2 commit 1d02f3b

File tree

19 files changed

+354
-88
lines changed

19 files changed

+354
-88
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::mir::BinOp;
1515
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
1616
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
1717
use rustc_middle::{bug, span_bug};
18+
use rustc_session::config::CrateType;
1819
use rustc_span::{Span, Symbol, sym};
1920
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
2021
use rustc_target::callconv::PassMode;
@@ -1136,8 +1137,17 @@ fn codegen_autodiff<'ll, 'tcx>(
11361137
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
11371138
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
11381139
}
1139-
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
1140-
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1140+
1141+
let ct = tcx.crate_types();
1142+
let lto = tcx.sess.lto();
1143+
if ct.len() == 1 && ct.contains(&CrateType::Executable) {
1144+
if lto != rustc_session::config::Lto::Fat {
1145+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1146+
}
1147+
} else {
1148+
if lto != rustc_session::config::Lto::Fat && !tcx.sess.opts.cg.linker_plugin_lto.enabled() {
1149+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1150+
}
11411151
}
11421152

11431153
let fn_args = instance.args;

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3434
return true;
3535
}
3636

37+
// FIXME(autodiff): replace this as per discussion in https://github.com/rust-lang/rust/pull/149033#discussion_r2535465880
38+
if tcx.has_attr(def_id, sym::autodiff_forward)
39+
|| tcx.has_attr(def_id, sym::autodiff_reverse)
40+
|| tcx.has_attr(def_id, sym::rustc_autodiff)
41+
{
42+
return true;
43+
}
44+
3745
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
3846
// Intrinsic fallback bodies are always cross-crate inlineable.
3947
// To ensure that the MIR inliner doesn't cluelessly try to inline fallback

compiler/rustc_monomorphize/src/collector/autodiff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::collector::{MonoItems, create_fn_mono_item};
77
// mono so this does not interfere in `autodiff` intrinsics
88
// codegen process. If they are unused, LLVM will remove them when
99
// compiling with O3.
10+
// FIXME(autodiff): Remove this whole file, as per discussion in
11+
// https://github.com/rust-lang/rust/pull/149033#discussion_r2535465880
1012
pub(crate) fn collect_autodiff_fn<'tcx>(
1113
tcx: TyCtxt<'tcx>,
1214
instance: ty::Instance<'tcx>,

compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn target() -> Target {
1111
metadata: TargetMetadata {
1212
description: Some("ARM64 OpenHarmony".into()),
1313
tier: Some(2),
14-
host_tools: Some(false),
14+
host_tools: Some(true),
1515
std: Some(true),
1616
},
1717
pointer_width: 64,

library/alloc/src/collections/btree/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ impl<K, V> Default for BTreeMap<K, V> {
24162416
#[stable(feature = "rust1", since = "1.0.0")]
24172417
impl<K: PartialEq, V: PartialEq, A: Allocator + Clone> PartialEq for BTreeMap<K, V, A> {
24182418
fn eq(&self, other: &BTreeMap<K, V, A>) -> bool {
2419-
self.iter().eq(other)
2419+
self.len() == other.len() && self.iter().zip(other).all(|(a, b)| a == b)
24202420
}
24212421
}
24222422

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//! Regression tests which fail if some collections' `PartialEq::eq` impls compare
2+
//! elements when the collections have different sizes.
3+
//! This behavior is not guaranteed either way, so regressing these tests is fine
4+
//! if it is done on purpose.
5+
use std::cmp::Ordering;
6+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList};
7+
8+
/// This intentionally has a panicking `PartialEq` impl, to test that various
9+
/// collections' `PartialEq` impls don't actually compare elements if their sizes
10+
/// are unequal.
11+
///
12+
/// This is not advisable in normal code.
13+
#[derive(Debug, Clone, Copy, Hash)]
14+
struct Evil;
15+
16+
impl PartialEq for Evil {
17+
fn eq(&self, _: &Self) -> bool {
18+
panic!("Evil::eq is evil");
19+
}
20+
}
21+
impl Eq for Evil {}
22+
23+
impl PartialOrd for Evil {
24+
fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
25+
Some(Ordering::Equal)
26+
}
27+
}
28+
29+
impl Ord for Evil {
30+
fn cmp(&self, _: &Self) -> Ordering {
31+
// Constructing a `BTreeSet`/`BTreeMap` uses `cmp` on the elements,
32+
// but comparing it with with `==` uses `eq` on the elements,
33+
// so Evil::cmp doesn't need to be evil.
34+
Ordering::Equal
35+
}
36+
}
37+
38+
// check Evil works
39+
#[test]
40+
#[should_panic = "Evil::eq is evil"]
41+
fn evil_eq_works() {
42+
let v1 = vec![Evil];
43+
let v2 = vec![Evil];
44+
45+
_ = v1 == v2;
46+
}
47+
48+
// check various containers don't compare if their sizes are different
49+
50+
#[test]
51+
fn vec_evil_eq() {
52+
let v1 = vec![Evil];
53+
let v2 = vec![Evil; 2];
54+
55+
assert_eq!(false, v1 == v2);
56+
}
57+
58+
#[test]
59+
fn hashset_evil_eq() {
60+
let s1 = HashSet::from([(0, Evil)]);
61+
let s2 = HashSet::from([(0, Evil), (1, Evil)]);
62+
63+
assert_eq!(false, s1 == s2);
64+
}
65+
66+
#[test]
67+
fn hashmap_evil_eq() {
68+
let m1 = HashMap::from([(0, Evil)]);
69+
let m2 = HashMap::from([(0, Evil), (1, Evil)]);
70+
71+
assert_eq!(false, m1 == m2);
72+
}
73+
74+
#[test]
75+
fn btreeset_evil_eq() {
76+
let s1 = BTreeSet::from([(0, Evil)]);
77+
let s2 = BTreeSet::from([(0, Evil), (1, Evil)]);
78+
79+
assert_eq!(false, s1 == s2);
80+
}
81+
82+
#[test]
83+
fn btreemap_evil_eq() {
84+
let m1 = BTreeMap::from([(0, Evil)]);
85+
let m2 = BTreeMap::from([(0, Evil), (1, Evil)]);
86+
87+
assert_eq!(false, m1 == m2);
88+
}
89+
90+
#[test]
91+
fn linkedlist_evil_eq() {
92+
let m1 = LinkedList::from([Evil]);
93+
let m2 = LinkedList::from([Evil; 2]);
94+
95+
assert_eq!(false, m1 == m2);
96+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mod binary_heap;
2+
mod eq_diff_len;

library/std/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ pub fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
29182918
fs_imp::canonicalize(path.as_ref())
29192919
}
29202920

2921-
/// Creates a new, empty directory at the provided path
2921+
/// Creates a new, empty directory at the provided path.
29222922
///
29232923
/// # Platform-specific behavior
29242924
///

library/std/src/fs/tests.rs

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
use rand::RngCore;
22

3-
#[cfg(any(
4-
windows,
5-
target_os = "freebsd",
6-
target_os = "linux",
7-
target_os = "netbsd",
8-
target_os = "illumos",
9-
target_vendor = "apple",
10-
))]
113
use crate::assert_matches::assert_matches;
12-
#[cfg(any(
13-
windows,
14-
target_os = "freebsd",
15-
target_os = "linux",
16-
target_os = "netbsd",
17-
target_os = "illumos",
18-
target_vendor = "apple",
19-
))]
20-
use crate::fs::TryLockError;
21-
use crate::fs::{self, File, FileTimes, OpenOptions};
4+
use crate::fs::{self, File, FileTimes, OpenOptions, TryLockError};
225
use crate::io::prelude::*;
236
use crate::io::{BorrowedBuf, ErrorKind, SeekFrom};
247
use crate::mem::MaybeUninit;
@@ -222,15 +205,22 @@ fn file_test_io_seek_and_write() {
222205
}
223206

224207
#[test]
225-
#[cfg(any(
226-
windows,
227-
target_os = "freebsd",
228-
target_os = "linux",
229-
target_os = "netbsd",
230-
target_os = "solaris",
231-
target_os = "illumos",
232-
target_vendor = "apple",
233-
))]
208+
#[cfg_attr(
209+
not(any(
210+
windows,
211+
target_os = "aix",
212+
target_os = "cygwin",
213+
target_os = "freebsd",
214+
target_os = "fuchsia",
215+
target_os = "illumos",
216+
target_os = "linux",
217+
target_os = "netbsd",
218+
target_os = "openbsd",
219+
target_os = "solaris",
220+
target_vendor = "apple",
221+
)),
222+
should_panic
223+
)]
234224
fn file_lock_multiple_shared() {
235225
let tmpdir = tmpdir();
236226
let filename = &tmpdir.join("file_lock_multiple_shared_test.txt");
@@ -247,15 +237,22 @@ fn file_lock_multiple_shared() {
247237
}
248238

249239
#[test]
250-
#[cfg(any(
251-
windows,
252-
target_os = "freebsd",
253-
target_os = "linux",
254-
target_os = "netbsd",
255-
target_os = "solaris",
256-
target_os = "illumos",
257-
target_vendor = "apple",
258-
))]
240+
#[cfg_attr(
241+
not(any(
242+
windows,
243+
target_os = "aix",
244+
target_os = "cygwin",
245+
target_os = "freebsd",
246+
target_os = "fuchsia",
247+
target_os = "illumos",
248+
target_os = "linux",
249+
target_os = "netbsd",
250+
target_os = "openbsd",
251+
target_os = "solaris",
252+
target_vendor = "apple",
253+
)),
254+
should_panic
255+
)]
259256
fn file_lock_blocking() {
260257
let tmpdir = tmpdir();
261258
let filename = &tmpdir.join("file_lock_blocking_test.txt");
@@ -273,15 +270,22 @@ fn file_lock_blocking() {
273270
}
274271

275272
#[test]
276-
#[cfg(any(
277-
windows,
278-
target_os = "freebsd",
279-
target_os = "linux",
280-
target_os = "netbsd",
281-
target_os = "solaris",
282-
target_os = "illumos",
283-
target_vendor = "apple",
284-
))]
273+
#[cfg_attr(
274+
not(any(
275+
windows,
276+
target_os = "aix",
277+
target_os = "cygwin",
278+
target_os = "freebsd",
279+
target_os = "fuchsia",
280+
target_os = "illumos",
281+
target_os = "linux",
282+
target_os = "netbsd",
283+
target_os = "openbsd",
284+
target_os = "solaris",
285+
target_vendor = "apple",
286+
)),
287+
should_panic
288+
)]
285289
fn file_lock_drop() {
286290
let tmpdir = tmpdir();
287291
let filename = &tmpdir.join("file_lock_dup_test.txt");
@@ -296,15 +300,22 @@ fn file_lock_drop() {
296300
}
297301

298302
#[test]
299-
#[cfg(any(
300-
windows,
301-
target_os = "freebsd",
302-
target_os = "linux",
303-
target_os = "netbsd",
304-
target_os = "solaris",
305-
target_os = "illumos",
306-
target_vendor = "apple",
307-
))]
303+
#[cfg_attr(
304+
not(any(
305+
windows,
306+
target_os = "aix",
307+
target_os = "cygwin",
308+
target_os = "freebsd",
309+
target_os = "fuchsia",
310+
target_os = "illumos",
311+
target_os = "linux",
312+
target_os = "netbsd",
313+
target_os = "openbsd",
314+
target_os = "solaris",
315+
target_vendor = "apple",
316+
)),
317+
should_panic
318+
)]
308319
fn file_lock_dup() {
309320
let tmpdir = tmpdir();
310321
let filename = &tmpdir.join("file_lock_dup_test.txt");
@@ -1252,7 +1263,7 @@ fn readlink_not_symlink() {
12521263
}
12531264

12541265
#[test]
1255-
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
1266+
#[cfg_attr(target_os = "android", ignore = "Android SELinux rules prevent creating hardlinks")]
12561267
fn links_work() {
12571268
let tmpdir = tmpdir();
12581269
let input = tmpdir.join("in.txt");
@@ -1748,7 +1759,7 @@ fn metadata_access_times() {
17481759

17491760
/// Test creating hard links to symlinks.
17501761
#[test]
1751-
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
1762+
#[cfg_attr(target_os = "android", ignore = "Android SELinux rules prevent creating hardlinks")]
17521763
fn symlink_hard_link() {
17531764
let tmpdir = tmpdir();
17541765
if !got_symlink_permission(&tmpdir) {

library/std/src/sys/fs/uefi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl FileAttr {
8181
unsafe {
8282
Self {
8383
attr: (*info.as_ptr()).attribute,
84-
size: (*info.as_ptr()).size,
84+
size: (*info.as_ptr()).file_size,
8585
modified: uefi_fs::uefi_to_systemtime((*info.as_ptr()).modification_time),
8686
accessed: uefi_fs::uefi_to_systemtime((*info.as_ptr()).last_access_time),
8787
created: uefi_fs::uefi_to_systemtime((*info.as_ptr()).create_time),

0 commit comments

Comments
 (0)