Skip to content

Commit 64e30b6

Browse files
committed
Auto merge of #92062 - matthiaskrgr:rollup-en3p4sb, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #91439 (Mark defaulted `PartialEq`/`PartialOrd` methods as const) - #91516 (Improve suggestion to change struct field to &mut) - #91896 (Remove `in_band_lifetimes` for `rustc_passes`) - #91909 (:arrow_up: rust-analyzer) - #91922 (Remove `in_band_lifetimes` from `rustc_mir_dataflow`) - #92025 (Revert "socket ancillary data implementation for dragonflybsd.") - #92030 (Update stdlib to the 2021 edition) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fad429d + 84e2ce0 commit 64e30b6

File tree

9 files changed

+59
-106
lines changed

9 files changed

+59
-106
lines changed

core/src/cmp.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
215215
#[inline]
216216
#[must_use]
217217
#[stable(feature = "rust1", since = "1.0.0")]
218+
#[default_method_body_is_const]
218219
fn ne(&self, other: &Rhs) -> bool {
219220
!self.eq(other)
220221
}
@@ -1031,6 +1032,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10311032
#[inline]
10321033
#[must_use]
10331034
#[stable(feature = "rust1", since = "1.0.0")]
1035+
#[default_method_body_is_const]
10341036
fn lt(&self, other: &Rhs) -> bool {
10351037
matches!(self.partial_cmp(other), Some(Less))
10361038
}
@@ -1050,6 +1052,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10501052
#[inline]
10511053
#[must_use]
10521054
#[stable(feature = "rust1", since = "1.0.0")]
1055+
#[default_method_body_is_const]
10531056
fn le(&self, other: &Rhs) -> bool {
10541057
// Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`.
10551058
// FIXME: The root cause was fixed upstream in LLVM with:
@@ -1072,6 +1075,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10721075
#[inline]
10731076
#[must_use]
10741077
#[stable(feature = "rust1", since = "1.0.0")]
1078+
#[default_method_body_is_const]
10751079
fn gt(&self, other: &Rhs) -> bool {
10761080
matches!(self.partial_cmp(other), Some(Greater))
10771081
}
@@ -1091,6 +1095,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10911095
#[inline]
10921096
#[must_use]
10931097
#[stable(feature = "rust1", since = "1.0.0")]
1098+
#[default_method_body_is_const]
10941099
fn ge(&self, other: &Rhs) -> bool {
10951100
matches!(self.partial_cmp(other), Some(Greater | Equal))
10961101
}

core/tests/cmp.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,36 @@ fn cmp_default() {
203203
assert!(Fool(false) != Fool(false));
204204
assert_eq!(Fool(false), Fool(true));
205205
}
206+
207+
#[cfg(not(bootstrap))]
208+
mod const_cmp {
209+
use super::*;
210+
211+
struct S(i32);
212+
213+
impl const PartialEq for S {
214+
fn eq(&self, other: &Self) -> bool {
215+
self.0 == other.0
216+
}
217+
}
218+
219+
impl const PartialOrd for S {
220+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
221+
let ret = match (self.0, other.0) {
222+
(a, b) if a > b => Ordering::Greater,
223+
(a, b) if a < b => Ordering::Less,
224+
_ => Ordering::Equal,
225+
};
226+
227+
Some(ret)
228+
}
229+
}
230+
231+
const _: () = assert!(S(1) == S(1));
232+
const _: () = assert!(S(0) != S(1));
233+
234+
const _: () = assert!(S(1) <= S(1));
235+
const _: () = assert!(S(1) >= S(1));
236+
const _: () = assert!(S(0) < S(1));
237+
const _: () = assert!(S(1) > S(0));
238+
}

std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
license = "MIT OR Apache-2.0"
55
repository = "https://github.com/rust-lang/rust.git"
66
description = "The Rust Standard Library"
7-
edition = "2018"
7+
edition = "2021"
88

99
[lib]
1010
crate-type = ["dylib", "rlib"]

std/src/fs/tests.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ macro_rules! error {
3838
($e:expr, $s:expr) => {
3939
match $e {
4040
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
41-
Err(ref err) => assert!(
42-
err.raw_os_error() == Some($s),
43-
format!("`{}` did not have a code of `{}`", err, $s)
44-
),
41+
Err(ref err) => {
42+
assert!(err.raw_os_error() == Some($s), "`{}` did not have a code of `{}`", err, $s)
43+
}
4544
}
4645
};
4746
}
@@ -58,7 +57,7 @@ macro_rules! error_contains {
5857
match $e {
5958
Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
6059
Err(ref err) => {
61-
assert!(err.to_string().contains($s), format!("`{}` did not contain `{}`", err, $s))
60+
assert!(err.to_string().contains($s), "`{}` did not contain `{}`", err, $s)
6261
}
6362
}
6463
};

std/src/os/unix/net/ancillary.rs

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ mod libc {
1616
pub use libc::c_int;
1717
pub struct ucred;
1818
pub struct cmsghdr;
19-
#[cfg(target_os = "dragonfly")]
20-
pub struct cmsgcred;
2119
pub type pid_t = i32;
2220
pub type gid_t = u32;
2321
pub type uid_t = u32;
@@ -185,11 +183,6 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
185183
#[derive(Clone)]
186184
pub struct SocketCred(libc::ucred);
187185

188-
#[cfg(target_os = "dragonfly")]
189-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
190-
#[derive(Clone)]
191-
pub struct SocketCred(libc::cmsgcred);
192-
193186
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
194187
impl SocketCred {
195188
/// Create a Unix credential struct.
@@ -241,57 +234,6 @@ impl SocketCred {
241234
}
242235
}
243236

244-
#[cfg(target_os = "dragonfly")]
245-
impl SocketCred {
246-
/// Create a Unix credential struct.
247-
///
248-
/// PID, UID and GID is set to 0.
249-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
250-
#[must_use]
251-
pub fn new() -> SocketCred {
252-
SocketCred(libc::cmsgcred { cmsgcred_pid: 0, cmsgcred_uid: 0, cmsgcred_gid: 0 })
253-
}
254-
255-
/// Set the PID.
256-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
257-
pub fn set_pid(&mut self, pid: libc::pid_t) {
258-
self.0.cmsgcred_pid = pid;
259-
}
260-
261-
/// Get the current PID.
262-
#[must_use]
263-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
264-
pub fn get_pid(&self) -> libc::pid_t {
265-
self.0.cmsgcred_pid
266-
}
267-
268-
/// Set the UID.
269-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
270-
pub fn set_uid(&mut self, uid: libc::uid_t) {
271-
self.0.cmsgcred_uid = uid;
272-
}
273-
274-
/// Get the current UID.
275-
#[must_use]
276-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
277-
pub fn get_uid(&self) -> libc::uid_t {
278-
self.0.cmsgcred_uid
279-
}
280-
281-
/// Set the GID.
282-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
283-
pub fn set_gid(&mut self, gid: libc::gid_t) {
284-
self.0.cmsgcred_gid = gid;
285-
}
286-
287-
/// Get the current GID.
288-
#[must_use]
289-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
290-
pub fn get_gid(&self) -> libc::gid_t {
291-
self.0.cmsgcred_gid
292-
}
293-
}
294-
295237
/// This control message contains file descriptors.
296238
///
297239
/// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_RIGHTS`.
@@ -314,11 +256,7 @@ impl<'a> Iterator for ScmRights<'a> {
314256
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
315257
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>);
316258

317-
#[cfg(target_os = "dragonfly")]
318-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
319-
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::cmsgcred>);
320-
321-
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))]
259+
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
322260
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
323261
impl<'a> Iterator for ScmCredentials<'a> {
324262
type Item = SocketCred;
@@ -362,7 +300,7 @@ impl<'a> AncillaryData<'a> {
362300
/// # Safety
363301
///
364302
/// `data` must contain a valid control message and the control message must be type of
365-
/// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDS`.
303+
/// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDENTIALS`.
366304
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
367305
unsafe fn as_credentials(data: &'a [u8]) -> Self {
368306
let ancillary_data_iter = AncillaryDataIter::new(data);
@@ -382,9 +320,6 @@ impl<'a> AncillaryData<'a> {
382320
libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)),
383321
#[cfg(any(target_os = "android", target_os = "linux",))]
384322
libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)),
385-
#[cfg(target_os = "dragonfly")]
386-
libc::SCM_CREDS => Ok(AncillaryData::as_credentials(data)),
387-
388323
cmsg_type => {
389324
Err(AncillaryError::Unknown { cmsg_level: libc::SOL_SOCKET, cmsg_type })
390325
}
@@ -609,19 +544,6 @@ impl<'a> SocketAncillary<'a> {
609544
)
610545
}
611546

612-
#[cfg(target_os = "dragonfly")]
613-
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
614-
pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool {
615-
self.truncated = false;
616-
add_to_ancillary_data(
617-
&mut self.buffer,
618-
&mut self.length,
619-
creds,
620-
libc::SOL_SOCKET,
621-
libc::SCM_CREDS,
622-
)
623-
}
624-
625547
/// Clears the ancillary data, removing all values.
626548
///
627549
/// # Example

std/src/os/unix/net/datagram.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,14 +854,8 @@ impl UnixDatagram {
854854
///
855855
/// # Examples
856856
///
857-
#[cfg_attr(
858-
any(target_os = "android", target_os = "linux", target_os = "dragonfly"),
859-
doc = "```no_run"
860-
)]
861-
#[cfg_attr(
862-
not(any(target_os = "android", target_os = "linux", target_os = "dragonfly")),
863-
doc = "```ignore"
864-
)]
857+
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
858+
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
865859
/// #![feature(unix_socket_ancillary_data)]
866860
/// use std::os::unix::net::UnixDatagram;
867861
///
@@ -871,7 +865,7 @@ impl UnixDatagram {
871865
/// Ok(())
872866
/// }
873867
/// ```
874-
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))]
868+
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
875869
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
876870
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
877871
self.0.set_passcred(passcred)
@@ -883,7 +877,7 @@ impl UnixDatagram {
883877
/// Get the socket option `SO_PASSCRED`.
884878
///
885879
/// [`set_passcred`]: UnixDatagram::set_passcred
886-
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))]
880+
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
887881
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
888882
pub fn passcred(&self) -> io::Result<bool> {
889883
self.0.passcred()

std/src/process.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,6 @@ impl ExitStatusError {
16001600
/// ```
16011601
/// #![feature(exit_status_error)]
16021602
/// # if cfg!(unix) {
1603-
/// use std::convert::TryFrom;
16041603
/// use std::num::NonZeroI32;
16051604
/// use std::process::Command;
16061605
///

std/src/sys/unix/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,12 @@ impl Socket {
408408
Ok(raw != 0)
409409
}
410410

411-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))]
411+
#[cfg(any(target_os = "android", target_os = "linux",))]
412412
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
413413
setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int)
414414
}
415415

416-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))]
416+
#[cfg(any(target_os = "android", target_os = "linux",))]
417417
pub fn passcred(&self) -> io::Result<bool> {
418418
let passcred: libc::c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED)?;
419419
Ok(passcred != 0)

std/src/thread/tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::Builder;
22
use crate::any::Any;
33
use crate::mem;
4+
use crate::panic::panic_any;
45
use crate::result;
56
use crate::sync::{
67
mpsc::{channel, Sender},
@@ -183,7 +184,7 @@ fn test_simple_newsched_spawn() {
183184
}
184185

185186
#[test]
186-
fn test_try_panic_message_static_str() {
187+
fn test_try_panic_message_string_literal() {
187188
match thread::spawn(move || {
188189
panic!("static string");
189190
})
@@ -199,9 +200,9 @@ fn test_try_panic_message_static_str() {
199200
}
200201

201202
#[test]
202-
fn test_try_panic_message_owned_str() {
203+
fn test_try_panic_any_message_owned_str() {
203204
match thread::spawn(move || {
204-
panic!("owned string".to_string());
205+
panic_any("owned string".to_string());
205206
})
206207
.join()
207208
{
@@ -215,9 +216,9 @@ fn test_try_panic_message_owned_str() {
215216
}
216217

217218
#[test]
218-
fn test_try_panic_message_any() {
219+
fn test_try_panic_any_message_any() {
219220
match thread::spawn(move || {
220-
panic!(box 413u16 as Box<dyn Any + Send>);
221+
panic_any(box 413u16 as Box<dyn Any + Send>);
221222
})
222223
.join()
223224
{
@@ -233,10 +234,10 @@ fn test_try_panic_message_any() {
233234
}
234235

235236
#[test]
236-
fn test_try_panic_message_unit_struct() {
237+
fn test_try_panic_any_message_unit_struct() {
237238
struct Juju;
238239

239-
match thread::spawn(move || panic!(Juju)).join() {
240+
match thread::spawn(move || panic_any(Juju)).join() {
240241
Err(ref e) if e.is::<Juju>() => {}
241242
Err(_) | Ok(()) => panic!(),
242243
}

0 commit comments

Comments
 (0)