From c35c46821a69af14e6b38e0238f70e22433a3e8e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 30 Mar 2015 09:40:52 -0400 Subject: Fallout in public-facing and semi-public-facing libs --- src/libstd/rt/libunwind.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/libunwind.rs b/src/libstd/rt/libunwind.rs index b7769910564..4b754bd5f58 100644 --- a/src/libstd/rt/libunwind.rs +++ b/src/libstd/rt/libunwind.rs @@ -25,7 +25,7 @@ use libc; #[cfg(any(not(target_arch = "arm"), target_os = "ios"))] #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub enum _Unwind_Action { _UA_SEARCH_PHASE = 1, _UA_CLEANUP_PHASE = 2, -- cgit 1.4.1-3-g733a5 From 3225b04c7d335b8f6e224c7d90ab95717ed84cc3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 1 Apr 2015 12:36:37 +0200 Subject: fallout from feature-gating unary negation on unsigned integers. --- src/libcollections/slice.rs | 2 +- src/libcore/atomic.rs | 2 +- src/libcore/cell.rs | 2 +- src/libcore/num/mod.rs | 2 +- src/libcore/ops.rs | 24 ++++++++++++++++++++---- src/libcore/str/mod.rs | 2 +- src/liblibc/lib.rs | 2 +- src/libstd/rt/mod.rs | 2 +- 8 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4599aff000d..29301bfd6fe 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1123,7 +1123,7 @@ impl Iterator for ElementSwaps { // #[inline] fn next(&mut self) -> Option<(usize, usize)> { fn new_pos_wrapping(i: usize, s: Direction) -> usize { - i.wrapping_add(match s { Pos => 1, Neg => -1 }) + i.wrapping_add(match s { Pos => 1, Neg => !0 /* aka -1 */ }) } fn new_pos(i: usize, s: Direction) -> usize { diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 8c396a4e7fb..d738ff947c4 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -161,7 +161,7 @@ pub const ATOMIC_USIZE_INIT: AtomicUsize = AtomicUsize { v: UnsafeCell { value: 0, } }; // NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly -const UINT_TRUE: usize = -1; +const UINT_TRUE: usize = !0; impl AtomicBool { /// Creates a new `AtomicBool`. diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 906c87f3ffd..76e09eedbdf 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -287,7 +287,7 @@ pub enum BorrowState { // (will not outgrow its range since `usize` is the size of the address space) type BorrowFlag = usize; const UNUSED: BorrowFlag = 0; -const WRITING: BorrowFlag = -1; +const WRITING: BorrowFlag = !0; impl RefCell { /// Creates a new `RefCell` containing `value`. diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index a4829ed96b3..13f168b3fdb 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -517,7 +517,7 @@ macro_rules! uint_impl { fn min_value() -> $T { 0 } #[inline] - fn max_value() -> $T { -1 } + fn max_value() -> $T { !0 } #[inline] fn count_ones(self) -> u32 { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 862eb16d0bf..e1a9efd69ad 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -482,8 +482,10 @@ pub trait Neg { fn neg(self) -> Self::Output; } -macro_rules! neg_impl { - ($($t:ty)*) => ($( + + +macro_rules! neg_impl_core { + ($id:ident => $body:expr, $($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] #[allow(unsigned_negation)] impl Neg for $t { @@ -492,14 +494,28 @@ macro_rules! neg_impl { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn neg(self) -> $t { -self } + fn neg(self) -> $t { let $id = self; $body } } forward_ref_unop! { impl Neg, neg for $t } )*) } -neg_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } +macro_rules! neg_impl_numeric { + ($($t:ty)*) => { neg_impl_core!{ x => -x, $($t)*} } +} + +macro_rules! neg_impl_unsigned { + ($($t:ty)*) => { + neg_impl_core!{ x => { + #[cfg(stage0)] + use ::num::wrapping::WrappingOps; + !x.wrapping_add(1) + }, $($t)*} } +} + +neg_impl_unsigned! { usize u8 u16 u32 u64 } +neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 } /// The `Not` trait is used to specify the functionality of unary `!`. /// diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 934c4515614..c78fa803361 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -873,7 +873,7 @@ impl TwoWaySearcher { #[allow(dead_code)] #[allow(deprecated)] fn maximal_suffix(arr: &[u8], reversed: bool) -> (usize, usize) { - let mut left: usize = -1; // Corresponds to i in the paper + let mut left: usize = !0; // Corresponds to i in the paper let mut right = 0; // Corresponds to j in the paper let mut offset = 1; // Corresponds to k in the paper let mut period = 1; // Corresponds to p in the paper diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index b7162c4a177..77e18be298b 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -4696,7 +4696,7 @@ pub mod consts { pub const MAP_FIXED : c_int = 0x0010; pub const MAP_ANON : c_int = 0x1000; - pub const MAP_FAILED : *mut c_void = -1 as *mut c_void; + pub const MAP_FAILED : *mut c_void = !0 as *mut c_void; pub const MCL_CURRENT : c_int = 0x0001; pub const MCL_FUTURE : c_int = 0x0002; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 696c7960c3e..7ea77a79619 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -117,7 +117,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use libc; use libc::funcs::posix01::signal::signal; unsafe { - assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != -1); + assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0); } } ignore_sigpipe(); -- cgit 1.4.1-3-g733a5 From e3b7e6caa25bffcffe6b04f550f551e1ae086f6b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 1 Apr 2015 18:44:53 -0700 Subject: Tweak relese notes + rebase fixes --- RELEASES.md | 4 +-- src/liblibc/lib.rs | 45 ++++++++++++++++++++------- src/librustc/middle/traits/coherence.rs | 2 +- src/libstd/rt/unwind.rs | 2 +- src/libstd/sys/common/net.rs | 4 +-- src/libstd/sys/windows/c.rs | 1 - src/libstd/sys/windows/tcp.rs | 5 +-- src/libsyntax/diagnostic.rs | 2 +- src/libterm/win.rs | 5 +-- src/libtest/lib.rs | 2 +- src/test/compile-fail/coherence-impls-copy.rs | 2 ++ 11 files changed, 50 insertions(+), 24 deletions(-) (limited to 'src/libstd/rt') diff --git a/RELEASES.md b/RELEASES.md index 4068d2ef9f2..7da73afb411 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -34,7 +34,7 @@ Version 1.0.0-beta (April 2015) downcasting via the `Any` trait is effectively limited to concrete types. This helps retain the potentially-important "parametricity" property: generic code cannot behave differently - for different type arguments. + for different type arguments except in minor ways. * The `unsafe_destructor` feature is now deprecated in favor of the [new `dropck`][dropck]. This change is a major reduction in unsafe code. @@ -78,7 +78,7 @@ Version 1.0.0-beta (April 2015) [scoped]: http://static.rust-lang.org/doc/master/std/thread/fn.scoped.html [moar-ufcs]: https://github.com/rust-lang/rust/pull/22172 [prim-inherent]: https://github.com/rust-lang/rust/pull/23104 -[overflow]: https://github.com/rust-lang/rust/pull/22532 +[overflow]: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md [metadata-shrink]: https://github.com/rust-lang/rust/pull/22971 [self-sized]: https://github.com/rust-lang/rust/pull/22301 [assoc-where]: https://github.com/rust-lang/rust/pull/22512 diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index a3a7edac230..44d689059d1 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -291,7 +291,6 @@ pub mod types { } pub mod bsd44 { - use core::clone::Clone; use types::common::c95::{c_void}; use types::os::arch::c95::{c_char, c_int, c_uint}; @@ -313,7 +312,7 @@ pub mod types { #[cfg(target_pointer_width = "64")] pub __ss_pad2: [u8; 128 - 2 * 8], } - impl Clone for sockaddr_storage { + impl ::core::clone::Clone for sockaddr_storage { fn clone(&self) -> sockaddr_storage { *self } } #[repr(C)] @@ -376,7 +375,7 @@ pub mod types { pub sun_family: sa_family_t, pub sun_path: [c_char; 108] } - impl Clone for sockaddr_un { + impl ::core::clone::Clone for sockaddr_un { fn clone(&self) -> sockaddr_un { *self } } @@ -1634,12 +1633,15 @@ pub mod types { pub sa_data: [u8; 14], } #[repr(C)] - #[derive(Copy, Clone)] pub struct sockaddr_storage { + #[derive(Copy)] pub struct sockaddr_storage { pub ss_family: sa_family_t, pub __ss_pad1: [u8; 6], pub __ss_align: i64, pub __ss_pad2: [u8; 112], } + impl ::core::clone::Clone for sockaddr_storage { + fn clone(&self) -> sockaddr_storage { *self } + } #[repr(C)] #[derive(Copy, Clone)] pub struct sockaddr_in { pub sin_family: sa_family_t, @@ -1685,10 +1687,13 @@ pub mod types { pub ai_next: *mut addrinfo, } #[repr(C)] - #[derive(Copy, Clone)] pub struct sockaddr_un { + #[derive(Copy)] pub struct sockaddr_un { pub sun_family: sa_family_t, pub sun_path: [c_char; 108] } + impl ::core::clone::Clone for sockaddr_un { + fn clone(&self) -> sockaddr_un { *self } + } } } @@ -1933,7 +1938,7 @@ pub mod types { pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN; #[repr(C)] - #[derive(Copy, Clone)] pub struct WSAPROTOCOL_INFO { + #[derive(Copy)] pub struct WSAPROTOCOL_INFO { pub dwServiceFlags1: DWORD, pub dwServiceFlags2: DWORD, pub dwServiceFlags3: DWORD, @@ -1955,13 +1960,16 @@ pub mod types { pub dwProviderReserved: DWORD, pub szProtocol: [u8; WSAPROTOCOL_LEN as usize + 1], } + impl ::core::clone::Clone for WSAPROTOCOL_INFO { + fn clone(&self) -> WSAPROTOCOL_INFO { *self } + } pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; pub type GROUP = c_uint; #[repr(C)] - #[derive(Copy, Clone)] pub struct WIN32_FIND_DATAW { + #[derive(Copy)] pub struct WIN32_FIND_DATAW { pub dwFileAttributes: DWORD, pub ftCreationTime: FILETIME, pub ftLastAccessTime: FILETIME, @@ -1973,6 +1981,9 @@ pub mod types { pub cFileName: [wchar_t; 260], // #define MAX_PATH 260 pub cAlternateFileName: [wchar_t; 14], } + impl ::core::clone::Clone for WIN32_FIND_DATAW { + fn clone(&self) -> WIN32_FIND_DATAW { *self } + } pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW; } @@ -2073,13 +2084,16 @@ pub mod types { } #[repr(C)] - #[derive(Copy, Clone)] pub struct sockaddr_storage { + #[derive(Copy)] pub struct sockaddr_storage { pub ss_len: u8, pub ss_family: sa_family_t, pub __ss_pad1: [u8; 6], pub __ss_align: i64, pub __ss_pad2: [u8; 112], } + impl ::core::clone::Clone for sockaddr_storage { + fn clone(&self) -> sockaddr_storage { *self } + } #[repr(C)] #[derive(Copy, Clone)] pub struct sockaddr_in { @@ -2135,11 +2149,14 @@ pub mod types { } #[repr(C)] - #[derive(Copy, Clone)] pub struct sockaddr_un { + #[derive(Copy)] pub struct sockaddr_un { pub sun_len: u8, pub sun_family: sa_family_t, pub sun_path: [c_char; 104] } + impl ::core::clone::Clone for sockaddr_un { + fn clone(&self) -> sockaddr_un { *self } + } #[repr(C)] #[derive(Copy, Clone)] pub struct ifaddrs { @@ -2239,10 +2256,13 @@ pub mod types { } #[repr(C)] - #[derive(Copy, Clone)] pub struct pthread_attr_t { + #[derive(Copy)] pub struct pthread_attr_t { pub __sig: c_long, pub __opaque: [c_char; 36] } + impl ::core::clone::Clone for pthread_attr_t { + fn clone(&self) -> pthread_attr_t { *self } + } } pub mod posix08 { } @@ -2345,10 +2365,13 @@ pub mod types { } #[repr(C)] - #[derive(Copy, Clone)] pub struct pthread_attr_t { + #[derive(Copy)] pub struct pthread_attr_t { pub __sig: c_long, pub __opaque: [c_char; 56] } + impl ::core::clone::Clone for pthread_attr_t { + fn clone(&self) -> pthread_attr_t { *self } + } } pub mod posix08 { } diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index 411be28b896..2f2db8f38bd 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -25,7 +25,7 @@ use syntax::ast; use syntax::codemap::{DUMMY_SP, Span}; use util::ppaux::Repr; -#[derive(Copy)] +#[derive(Copy, Clone)] struct ParamIsLocal(bool); /// True if there exist types that satisfy both of the two given impls. diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index e4927bbd3d2..f71811b1ead 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -398,7 +398,7 @@ pub mod eabi { pub struct DISPATCHER_CONTEXT; #[repr(C)] - #[derive(Copy)] + #[derive(Copy, Clone)] pub enum EXCEPTION_DISPOSITION { ExceptionContinueExecution, ExceptionContinueSearch, diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 1a0ee17904a..fc21effb45a 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -115,9 +115,9 @@ pub fn socket(addr: SocketAddr, ty: libc::c_int) -> IoResult { Ipv4Addr(..) => libc::AF_INET, Ipv6Addr(..) => libc::AF_INET6, }; - match libc::socket(fam, ty, 0) { + match libc::socket(fam, ty, 0) as i32 { -1 => Err(last_net_error()), - fd => Ok(fd), + fd => Ok(fd as sock_t), } } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 99abe10c8a4..4804f650441 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -89,7 +89,6 @@ pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS; pub type WSAEVENT = libc::HANDLE; #[repr(C)] -#[derive(Copy)] pub struct WSAPROTOCOL_INFO { pub dwServiceFlags1: libc::DWORD, pub dwServiceFlags2: libc::DWORD, diff --git a/src/libstd/sys/windows/tcp.rs b/src/libstd/sys/windows/tcp.rs index 2ac8ac10aa9..41e97dc8475 100644 --- a/src/libstd/sys/windows/tcp.rs +++ b/src/libstd/sys/windows/tcp.rs @@ -15,6 +15,7 @@ use prelude::v1::*; use old_io::net::ip; use old_io::IoResult; use libc; +use libc::consts::os::extra::INVALID_SOCKET; use mem; use ptr; use super::{last_error, last_net_error, sock_t}; @@ -183,8 +184,8 @@ impl TcpAcceptor { match unsafe { libc::accept(self.socket(), ptr::null_mut(), ptr::null_mut()) } { - -1 if wouldblock() => {} - -1 => return Err(last_net_error()), + INVALID_SOCKET if wouldblock() => {} + INVALID_SOCKET => return Err(last_net_error()), // Accepted sockets inherit the same properties as the caller, // so we need to deregister our event and switch the socket back diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index c4690b9716c..f35cc8c8d23 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -371,7 +371,7 @@ fn stderr_isatty() -> bool { } #[cfg(windows)] fn stderr_isatty() -> bool { - const STD_ERROR_HANDLE: libc::DWORD = -12; + const STD_ERROR_HANDLE: libc::DWORD = -12i32 as libc::DWORD; extern "system" { fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; fn GetConsoleMode(hConsoleHandle: libc::HANDLE, diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 001313db676..66ef5e86617 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -104,7 +104,7 @@ impl WinConsole { // terminal! Admittedly, this is fragile, since stderr could be // redirected to a different console. This is good enough for // rustc though. See #13400. - let out = GetStdHandle(-11); + let out = GetStdHandle(-11i32 as libc::DWORD); SetConsoleTextAttribute(out, accum); } } @@ -116,7 +116,8 @@ impl WinConsole { let bg; unsafe { let mut buffer_info = ::std::mem::uninitialized(); - if GetConsoleScreenBufferInfo(GetStdHandle(-11), &mut buffer_info) != 0 { + if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as libc::DWORD), + &mut buffer_info) != 0 { fg = bits_to_color(buffer_info.wAttributes); bg = bits_to_color(buffer_info.wAttributes >> 4); } else { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 8d329367972..c84703b93ed 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -757,7 +757,7 @@ fn stdout_isatty() -> bool { } #[cfg(windows)] fn stdout_isatty() -> bool { - const STD_OUTPUT_HANDLE: libc::DWORD = -11; + const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD; extern "system" { fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE; fn GetConsoleMode(hConsoleHandle: libc::HANDLE, diff --git a/src/test/compile-fail/coherence-impls-copy.rs b/src/test/compile-fail/coherence-impls-copy.rs index f1a04a8ea57..1be606c3546 100644 --- a/src/test/compile-fail/coherence-impls-copy.rs +++ b/src/test/compile-fail/coherence-impls-copy.rs @@ -28,6 +28,8 @@ impl Copy for MyType {} impl Copy for &'static mut MyType {} //~^ ERROR E0206 +//~| ERROR E0277 +//~| ERROR E0277 impl Clone for MyType { fn clone(&self) -> Self { *self } } impl Copy for (MyType, MyType) {} -- cgit 1.4.1-3-g733a5