Skip to content

Commit 29e972d

Browse files
committed
Auto merge of rust-lang#97063 - Dylan-DPC:rollup-u5el7hb, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - rust-lang#96947 (Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket) - rust-lang#97021 (Added note in documentation) - rust-lang#97042 (Add new eslint rule about brace style) - rust-lang#97060 (Fix use of SetHandleInformation on UWP) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0f202d2 + d56c59e commit 29e972d

File tree

14 files changed

+123
-35
lines changed

14 files changed

+123
-35
lines changed

library/std/src/os/fd/owned.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
3232
// 32-bit c_int. Below is -2, in two's complement, but that only works out
3333
// because c_int is 32 bits.
3434
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
35+
#[rustc_nonnull_optimization_guaranteed]
3536
#[unstable(feature = "io_safety", issue = "87074")]
3637
pub struct BorrowedFd<'fd> {
3738
fd: RawFd,
@@ -52,6 +53,7 @@ pub struct BorrowedFd<'fd> {
5253
// 32-bit c_int. Below is -2, in two's complement, but that only works out
5354
// because c_int is 32 bits.
5455
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
56+
#[rustc_nonnull_optimization_guaranteed]
5557
#[unstable(feature = "io_safety", issue = "87074")]
5658
pub struct OwnedFd {
5759
fd: RawFd,

library/std/src/os/fd/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ fn test_fd() {
3232
assert_eq!(stdin_as_file.as_fd().as_raw_fd(), raw_fd);
3333
assert_eq!(Into::<OwnedFd>::into(stdin_as_file).into_raw_fd(), raw_fd);
3434
}
35+
36+
#[cfg(any(unix, target_os = "wasi"))]
37+
#[test]
38+
fn test_niche_optimizations() {
39+
use crate::mem::size_of;
40+
#[cfg(unix)]
41+
use crate::os::unix::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
42+
#[cfg(target_os = "wasi")]
43+
use crate::os::wasi::io::{BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
44+
45+
assert_eq!(size_of::<Option<OwnedFd>>(), size_of::<RawFd>());
46+
assert_eq!(size_of::<Option<BorrowedFd<'static>>>(), size_of::<RawFd>());
47+
unsafe {
48+
assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN);
49+
assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX);
50+
assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MIN)).unwrap().into_raw_fd(), RawFd::MIN);
51+
assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MAX)).unwrap().into_raw_fd(), RawFd::MAX);
52+
}
53+
}

library/std/src/os/windows/io/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl OwnedHandle {
206206
}
207207

208208
/// Allow child processes to inherit the handle.
209+
#[cfg(not(target_vendor = "uwp"))]
209210
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
210211
cvt(unsafe {
211212
c::SetHandleInformation(

library/std/src/os/windows/io/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ pub use handle::*;
5454
pub use raw::*;
5555
#[unstable(feature = "io_safety", issue = "87074")]
5656
pub use socket::*;
57+
58+
#[cfg(test)]
59+
mod tests;

library/std/src/os/windows/io/socket.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::mem;
1010
use crate::mem::forget;
1111
use crate::sys;
1212
use crate::sys::c;
13+
#[cfg(not(target_vendor = "uwp"))]
1314
use crate::sys::cvt;
1415

1516
/// A borrowed socket.
@@ -34,6 +35,7 @@ use crate::sys::cvt;
3435
target_pointer_width = "64",
3536
rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE)
3637
)]
38+
#[rustc_nonnull_optimization_guaranteed]
3739
#[unstable(feature = "io_safety", issue = "87074")]
3840
pub struct BorrowedSocket<'socket> {
3941
socket: RawSocket,
@@ -56,6 +58,7 @@ pub struct BorrowedSocket<'socket> {
5658
target_pointer_width = "64",
5759
rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FF_FF_FF_FF_FE)
5860
)]
61+
#[rustc_nonnull_optimization_guaranteed]
5962
#[unstable(feature = "io_safety", issue = "87074")]
6063
pub struct OwnedSocket {
6164
socket: RawSocket,
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[test]
2+
fn test_niche_optimizations_socket() {
3+
use crate::mem::size_of;
4+
use crate::os::windows::io::{
5+
BorrowedSocket, FromRawSocket, IntoRawSocket, OwnedSocket, RawSocket,
6+
};
7+
8+
assert_eq!(size_of::<Option<OwnedSocket>>(), size_of::<RawSocket>());
9+
assert_eq!(size_of::<Option<BorrowedSocket<'static>>>(), size_of::<RawSocket>(),);
10+
unsafe {
11+
#[cfg(target_pointer_width = "32")]
12+
let (min, max) = (i32::MIN as u32, i32::MAX as u32);
13+
#[cfg(target_pointer_width = "64")]
14+
let (min, max) = (i64::MIN as u64, i64::MAX as u64);
15+
16+
assert_eq!(OwnedSocket::from_raw_socket(min).into_raw_socket(), min);
17+
assert_eq!(OwnedSocket::from_raw_socket(max).into_raw_socket(), max);
18+
assert_eq!(Some(OwnedSocket::from_raw_socket(min)).unwrap().into_raw_socket(), min);
19+
assert_eq!(Some(OwnedSocket::from_raw_socket(max)).unwrap().into_raw_socket(), max);
20+
}
21+
}

library/std/src/sys/windows/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl Handle {
221221
Ok(Self(self.0.duplicate(access, inherit, options)?))
222222
}
223223

224+
#[cfg(not(target_vendor = "uwp"))]
224225
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
225226
self.0.set_inheritable()
226227
}

library/std/src/sys/windows/pipe.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ impl Pipes {
5757
} else {
5858
let (ours, theirs) = if ours_readable { (read, write) } else { (write, read) };
5959
let ours = Handle::from_raw_handle(ours);
60+
#[cfg(not(target_vendor = "uwp"))]
6061
let theirs = Handle::from_raw_handle(theirs);
62+
#[cfg(target_vendor = "uwp")]
63+
let mut theirs = Handle::from_raw_handle(theirs);
6164

6265
if their_handle_inheritable {
63-
theirs.set_inheritable()?;
66+
#[cfg(not(target_vendor = "uwp"))]
67+
{
68+
theirs.set_inheritable()?;
69+
}
70+
71+
#[cfg(target_vendor = "uwp")]
72+
{
73+
theirs = theirs.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?;
74+
}
6475
}
6576

6677
Ok(Pipes { ours: AnonPipe::Sync(ours), theirs: AnonPipe::Sync(theirs) })

src/doc/unstable-book/src/compiler-flags/sanitizer.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ This feature allows for use of one of following sanitizers:
2222

2323
To enable a sanitizer compile with `-Zsanitizer=address`,`-Zsanitizer=cfi`,
2424
`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`, `-Zsanitizer=memory`,
25-
`-Zsanitizer=memtag`, or `-Zsanitizer=thread`.
25+
`-Zsanitizer=memtag`, or `-Zsanitizer=thread`. You might also need the `--target` and `build-std` flags. Example:
26+
```shell
27+
$ RUSTFLAGS=-Zsanitizer=address cargo build -Zbuild-std --target x86_64-unknown-linux-gnu
28+
```
2629

2730
# AddressSanitizer
2831

src/librustdoc/html/static/.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@ module.exports = {
2929
"no-var": ["error"],
3030
"prefer-const": ["error"],
3131
"prefer-arrow-callback": ["error"],
32+
"brace-style": [
33+
"error",
34+
"1tbs",
35+
{ "allowSingleLine": false }
36+
],
3237
}
3338
};

src/librustdoc/html/static/js/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ function loadCss(cssFileName) {
709709
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
710710
if (e.parentNode.id !== "implementations-list" ||
711711
(!hasClass(e, "implementors-toggle") &&
712-
!hasClass(e, "type-contents-toggle")))
713-
{
712+
!hasClass(e, "type-contents-toggle"))
713+
) {
714714
e.open = false;
715715
}
716716
});

src/librustdoc/html/static/js/scrape-examples.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
// visible. This is necessary since updateScrapedExample calls scrollToLoc which
9999
// depends on offsetHeight, a property that requires an element to be visible to
100100
// compute correctly.
101-
setTimeout(() => { onEachLazy(moreExamples, updateScrapedExample); });
101+
setTimeout(() => {
102+
onEachLazy(moreExamples, updateScrapedExample);
103+
});
102104
}, {once: true});
103105
});
104106
})();

src/librustdoc/html/static/js/search.js

+45-28
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ window.initSearch = rawSearchIndex => {
320320
if (foundExclamation) {
321321
throw new Error("Cannot have more than one `!` in an ident");
322322
} else if (parserState.pos + 1 < parserState.length &&
323-
isIdentCharacter(parserState.userQuery[parserState.pos + 1]))
324-
{
323+
isIdentCharacter(parserState.userQuery[parserState.pos + 1])
324+
) {
325325
throw new Error("`!` can only be at the end of an ident");
326326
}
327327
foundExclamation = true;
@@ -330,12 +330,10 @@ window.initSearch = rawSearchIndex => {
330330
} else if (
331331
isStopCharacter(c) ||
332332
isSpecialStartCharacter(c) ||
333-
isSeparatorCharacter(c))
334-
{
333+
isSeparatorCharacter(c)
334+
) {
335335
break;
336-
}
337-
// If we allow paths ("str::string" for example).
338-
else if (c === ":") {
336+
} else if (c === ":") { // If we allow paths ("str::string" for example).
339337
if (!isPathStart(parserState)) {
340338
break;
341339
}
@@ -372,8 +370,8 @@ window.initSearch = rawSearchIndex => {
372370
end = getIdentEndPosition(parserState);
373371
}
374372
if (parserState.pos < parserState.length &&
375-
parserState.userQuery[parserState.pos] === "<")
376-
{
373+
parserState.userQuery[parserState.pos] === "<"
374+
) {
377375
if (isInGenerics) {
378376
throw new Error("Unexpected `<` after `<`");
379377
} else if (start >= end) {
@@ -592,8 +590,8 @@ window.initSearch = rawSearchIndex => {
592590

593591
if (elem &&
594592
elem.value !== "All crates" &&
595-
hasOwnPropertyRustdoc(rawSearchIndex, elem.value))
596-
{
593+
hasOwnPropertyRustdoc(rawSearchIndex, elem.value)
594+
) {
597595
return elem.value;
598596
}
599597
return null;
@@ -786,37 +784,51 @@ window.initSearch = rawSearchIndex => {
786784
// sort by exact match with regard to the last word (mismatch goes later)
787785
a = (aaa.word !== userQuery);
788786
b = (bbb.word !== userQuery);
789-
if (a !== b) { return a - b; }
787+
if (a !== b) {
788+
return a - b;
789+
}
790790

791791
// Sort by non levenshtein results and then levenshtein results by the distance
792792
// (less changes required to match means higher rankings)
793793
a = (aaa.lev);
794794
b = (bbb.lev);
795-
if (a !== b) { return a - b; }
795+
if (a !== b) {
796+
return a - b;
797+
}
796798

797799
// sort by crate (non-current crate goes later)
798800
a = (aaa.item.crate !== window.currentCrate);
799801
b = (bbb.item.crate !== window.currentCrate);
800-
if (a !== b) { return a - b; }
802+
if (a !== b) {
803+
return a - b;
804+
}
801805

802806
// sort by item name length (longer goes later)
803807
a = aaa.word.length;
804808
b = bbb.word.length;
805-
if (a !== b) { return a - b; }
809+
if (a !== b) {
810+
return a - b;
811+
}
806812

807813
// sort by item name (lexicographically larger goes later)
808814
a = aaa.word;
809815
b = bbb.word;
810-
if (a !== b) { return (a > b ? +1 : -1); }
816+
if (a !== b) {
817+
return (a > b ? +1 : -1);
818+
}
811819

812820
// sort by index of keyword in item name (no literal occurrence goes later)
813821
a = (aaa.index < 0);
814822
b = (bbb.index < 0);
815-
if (a !== b) { return a - b; }
823+
if (a !== b) {
824+
return a - b;
825+
}
816826
// (later literal occurrence, if any, goes later)
817827
a = aaa.index;
818828
b = bbb.index;
819-
if (a !== b) { return a - b; }
829+
if (a !== b) {
830+
return a - b;
831+
}
820832

821833
// special precedence for primitive and keyword pages
822834
if ((aaa.item.ty === TY_PRIMITIVE && bbb.item.ty !== TY_KEYWORD) ||
@@ -831,17 +843,23 @@ window.initSearch = rawSearchIndex => {
831843
// sort by description (no description goes later)
832844
a = (aaa.item.desc === "");
833845
b = (bbb.item.desc === "");
834-
if (a !== b) { return a - b; }
846+
if (a !== b) {
847+
return a - b;
848+
}
835849

836850
// sort by type (later occurrence in `itemTypes` goes later)
837851
a = aaa.item.ty;
838852
b = bbb.item.ty;
839-
if (a !== b) { return a - b; }
853+
if (a !== b) {
854+
return a - b;
855+
}
840856

841857
// sort by path (lexicographically larger goes later)
842858
a = aaa.item.path;
843859
b = bbb.item.path;
844-
if (a !== b) { return (a > b ? +1 : -1); }
860+
if (a !== b) {
861+
return (a > b ? +1 : -1);
862+
}
845863

846864
// que sera, sera
847865
return 0;
@@ -1315,16 +1333,15 @@ window.initSearch = rawSearchIndex => {
13151333
}
13161334

13171335
if (searchWord.indexOf(elem.pathLast) > -1 ||
1318-
row.normalizedName.indexOf(elem.pathLast) > -1)
1319-
{
1336+
row.normalizedName.indexOf(elem.pathLast) > -1
1337+
) {
13201338
// filter type: ... queries
13211339
if (!results_others[fullId] !== undefined) {
13221340
index = row.normalizedName.indexOf(elem.pathLast);
13231341
}
13241342
}
13251343
lev = levenshtein(searchWord, elem.pathLast);
1326-
if (lev > 0 && elem.pathLast.length > 2 && searchWord.indexOf(elem.pathLast) > -1)
1327-
{
1344+
if (lev > 0 && elem.pathLast.length > 2 && searchWord.indexOf(elem.pathLast) > -1) {
13281345
if (elem.pathLast.length < 6) {
13291346
lev = 1;
13301347
} else {
@@ -1670,8 +1687,8 @@ window.initSearch = rawSearchIndex => {
16701687
// By default, the search DOM element is "empty" (meaning it has no children not
16711688
// text content). Once a search has been run, it won't be empty, even if you press
16721689
// ESC or empty the search input (which also "cancels" the search).
1673-
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText)))
1674-
{
1690+
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))
1691+
) {
16751692
const elem = document.createElement("a");
16761693
elem.href = results.others[0].href;
16771694
removeClass(elem, "active");
@@ -1766,7 +1783,7 @@ window.initSearch = rawSearchIndex => {
17661783
let i = 0;
17671784
for (const elem of elems) {
17681785
const j = i;
1769-
elem.onclick = () => { printTab(j); };
1786+
elem.onclick = () => printTab(j);
17701787
searchState.focusedByTab.push(null);
17711788
i += 1;
17721789
}

src/librustdoc/html/static/js/settings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@
254254
function blurHandler(event) {
255255
const settingsButton = getSettingsButton();
256256
if (!elemIsInParent(document.activeElement, settingsButton) &&
257-
!elemIsInParent(event.relatedTarget, settingsButton))
258-
{
257+
!elemIsInParent(event.relatedTarget, settingsButton)
258+
) {
259259
window.hideSettings();
260260
}
261261
}

0 commit comments

Comments
 (0)