From 7cae9e8c88e468e94c157d9aaee4b8e3cf90b9a4 Mon Sep 17 00:00:00 2001 From: maekawatoshiki Date: Fri, 31 Jul 2020 18:50:11 +0900 Subject: [PATCH 01/24] `#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit --- library/std/src/sys/hermit/alloc.rs | 25 ++++--- library/std/src/sys/hermit/args.rs | 16 +++-- library/std/src/sys/hermit/condvar.rs | 34 +++++++--- library/std/src/sys/hermit/fd.rs | 1 + library/std/src/sys/hermit/mod.rs | 22 ++++-- library/std/src/sys/hermit/mutex.rs | 26 ++++--- library/std/src/sys/hermit/os.rs | 2 + library/std/src/sys/hermit/rwlock.rs | 68 ++++++++++++------- library/std/src/sys/hermit/thread.rs | 21 +++--- .../std/src/sys/hermit/thread_local_dtor.rs | 7 +- 10 files changed, 147 insertions(+), 75 deletions(-) diff --git a/library/std/src/sys/hermit/alloc.rs b/library/std/src/sys/hermit/alloc.rs index d153914e77e10..04446172197f7 100644 --- a/library/std/src/sys/hermit/alloc.rs +++ b/library/std/src/sys/hermit/alloc.rs @@ -1,3 +1,5 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys::hermit::abi; @@ -6,26 +8,33 @@ use crate::sys::hermit::abi; unsafe impl GlobalAlloc for System { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - abi::malloc(layout.size(), layout.align()) + // SAFETY: The safety contract for `malloc` must be upheld by the caller. + unsafe { abi::malloc(layout.size(), layout.align()) } } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - let addr = abi::malloc(layout.size(), layout.align()); + // SAFETY: The safety contract for `malloc` must be upheld by the caller. + // Also, `addr` must be valid for writes of `layout.size() * size_of::()` bytes. + unsafe { + let addr = abi::malloc(layout.size(), layout.align()); - if !addr.is_null() { - ptr::write_bytes(addr, 0x00, layout.size()); - } + if !addr.is_null() { + ptr::write_bytes(addr, 0x00, layout.size()); + } - addr + addr + } } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - abi::free(ptr, layout.size(), layout.align()) + // SAFETY: The safety contract for `free` must be upheld by the caller. + unsafe { abi::free(ptr, layout.size(), layout.align()) } } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - abi::realloc(ptr, layout.size(), layout.align(), new_size) + // SAFETY: The safety contract for `realloc` must be upheld by the caller. + unsafe { abi::realloc(ptr, layout.size(), layout.align(), new_size) } } } diff --git a/library/std/src/sys/hermit/args.rs b/library/std/src/sys/hermit/args.rs index 72c1b8511cac8..dd8830599c37e 100644 --- a/library/std/src/sys/hermit/args.rs +++ b/library/std/src/sys/hermit/args.rs @@ -1,15 +1,17 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::ffi::OsString; use crate::marker::PhantomData; use crate::vec; /// One-time global initialization. pub unsafe fn init(argc: isize, argv: *const *const u8) { - imp::init(argc, argv) + unsafe { imp::init(argc, argv) } } /// One-time global cleanup. pub unsafe fn cleanup() { - imp::cleanup() + unsafe { imp::cleanup() } } /// Returns the command line arguments @@ -65,14 +67,18 @@ mod imp { pub unsafe fn init(argc: isize, argv: *const *const u8) { let _guard = LOCK.lock(); - ARGC = argc; - ARGV = argv; + unsafe { + ARGC = argc; + ARGV = argv; + } } pub unsafe fn cleanup() { let _guard = LOCK.lock(); ARGC = 0; - ARGV = ptr::null(); + unsafe { + ARGV = ptr::null(); + } } pub fn args() -> Args { diff --git a/library/std/src/sys/hermit/condvar.rs b/library/std/src/sys/hermit/condvar.rs index 52c8c3b17e826..662dc9394a36f 100644 --- a/library/std/src/sys/hermit/condvar.rs +++ b/library/std/src/sys/hermit/condvar.rs @@ -1,3 +1,5 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::ffi::c_void; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; @@ -23,33 +25,43 @@ impl Condvar { } pub unsafe fn init(&mut self) { - let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0); - let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0); + unsafe { + let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0); + let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0); + } } pub unsafe fn notify_one(&self) { if self.counter.load(SeqCst) > 0 { self.counter.fetch_sub(1, SeqCst); - abi::sem_post(self.sem1); - abi::sem_timedwait(self.sem2, 0); + unsafe { + abi::sem_post(self.sem1); + abi::sem_timedwait(self.sem2, 0); + } } } pub unsafe fn notify_all(&self) { let counter = self.counter.swap(0, SeqCst); for _ in 0..counter { - abi::sem_post(self.sem1); + unsafe { + abi::sem_post(self.sem1); + } } for _ in 0..counter { - abi::sem_timedwait(self.sem2, 0); + unsafe { + abi::sem_timedwait(self.sem2, 0); + } } } pub unsafe fn wait(&self, mutex: &Mutex) { self.counter.fetch_add(1, SeqCst); mutex.unlock(); - abi::sem_timedwait(self.sem1, 0); - abi::sem_post(self.sem2); + unsafe { + abi::sem_timedwait(self.sem1, 0); + abi::sem_post(self.sem2); + } mutex.lock(); } @@ -58,7 +70,9 @@ impl Condvar { } pub unsafe fn destroy(&self) { - let _ = abi::sem_destroy(self.sem1); - let _ = abi::sem_destroy(self.sem2); + unsafe { + let _ = abi::sem_destroy(self.sem1); + let _ = abi::sem_destroy(self.sem2); + } } } diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 97d1a38b41ab1..2914e5ad3dbe2 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_op_in_unsafe_fn)] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::io::{self, ErrorKind, Read}; diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 675b82ceb775f..0e4504020df42 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -13,6 +13,8 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! +#![deny(unsafe_op_in_unsafe_fn)] + use crate::intrinsics; use crate::os::raw::c_char; @@ -62,8 +64,12 @@ pub enum Void {} pub unsafe fn strlen(start: *const c_char) -> usize { let mut str = start; - while *str != 0 { - str = str.offset(1); + // SAFETY: The safety contract for `*str != 0` must be upheld by the caller. + // `start` must not be null. + unsafe { + while *str != 0 { + str = str.offset(1); + } } (str as usize) - (start as usize) @@ -111,13 +117,15 @@ pub unsafe extern "C" fn runtime_entry( fn main(argc: isize, argv: *const *const c_char) -> i32; } - // initialize environment - os::init_environment(env as *const *const i8); + unsafe { + // initialize environment + os::init_environment(env as *const *const i8); - let result = main(argc as isize, argv); + let result = main(argc as isize, argv); - run_dtors(); - abi::exit(result); + run_dtors(); + abi::exit(result); + } } pub fn decode_error_kind(errno: i32) -> ErrorKind { diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index 3d4813209cbc4..bcb2554ab2927 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -1,3 +1,5 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::ffi::c_void; use crate::ptr; use crate::sys::hermit::abi; @@ -16,28 +18,34 @@ impl Mutex { #[inline] pub unsafe fn init(&mut self) { - let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1); + unsafe { + let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1); + } } #[inline] pub unsafe fn lock(&self) { - let _ = abi::sem_timedwait(self.inner, 0); + unsafe { + let _ = abi::sem_timedwait(self.inner, 0); + } } #[inline] pub unsafe fn unlock(&self) { - let _ = abi::sem_post(self.inner); + unsafe { + let _ = abi::sem_post(self.inner); + } } #[inline] pub unsafe fn try_lock(&self) -> bool { - let result = abi::sem_trywait(self.inner); + let result = unsafe { abi::sem_trywait(self.inner) }; result == 0 } #[inline] pub unsafe fn destroy(&self) { - let _ = abi::sem_destroy(self.inner); + let _ = unsafe { abi::sem_destroy(self.inner) }; } } @@ -52,12 +60,12 @@ impl ReentrantMutex { #[inline] pub unsafe fn init(&self) { - let _ = abi::recmutex_init(&self.inner as *const *const c_void as *mut _); + let _ = unsafe { abi::recmutex_init(&self.inner as *const *const c_void as *mut _) }; } #[inline] pub unsafe fn lock(&self) { - let _ = abi::recmutex_lock(self.inner); + let _ = unsafe { abi::recmutex_lock(self.inner) }; } #[inline] @@ -67,11 +75,11 @@ impl ReentrantMutex { #[inline] pub unsafe fn unlock(&self) { - let _ = abi::recmutex_unlock(self.inner); + let _ = unsafe { abi::recmutex_unlock(self.inner) }; } #[inline] pub unsafe fn destroy(&self) { - let _ = abi::recmutex_destroy(self.inner); + let _ = unsafe { abi::recmutex_destroy(self.inner) }; } } diff --git a/library/std/src/sys/hermit/os.rs b/library/std/src/sys/hermit/os.rs index 78eabf8f81e98..d95940c9a76c8 100644 --- a/library/std/src/sys/hermit/os.rs +++ b/library/std/src/sys/hermit/os.rs @@ -1,3 +1,5 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::collections::HashMap; use crate::error::Error as StdError; use crate::ffi::{CStr, OsStr, OsString}; diff --git a/library/std/src/sys/hermit/rwlock.rs b/library/std/src/sys/hermit/rwlock.rs index 06442e925f4c8..a6c7bcc7641fc 100644 --- a/library/std/src/sys/hermit/rwlock.rs +++ b/library/std/src/sys/hermit/rwlock.rs @@ -1,3 +1,5 @@ +#![deny(unsafe_op_in_unsafe_fn)] + use crate::cell::UnsafeCell; use crate::sys::condvar::Condvar; use crate::sys::mutex::Mutex; @@ -32,62 +34,76 @@ impl RWLock { #[inline] pub unsafe fn read(&self) { - self.lock.lock(); - while !(*self.state.get()).inc_readers() { - self.cond.wait(&self.lock); + unsafe { + self.lock.lock(); + while !(*self.state.get()).inc_readers() { + self.cond.wait(&self.lock); + } + self.lock.unlock(); } - self.lock.unlock(); } #[inline] pub unsafe fn try_read(&self) -> bool { - self.lock.lock(); - let ok = (*self.state.get()).inc_readers(); - self.lock.unlock(); + unsafe { + self.lock.lock(); + let ok = (*self.state.get()).inc_readers(); + self.lock.unlock(); + } return ok; } #[inline] pub unsafe fn write(&self) { - self.lock.lock(); - while !(*self.state.get()).inc_writers() { - self.cond.wait(&self.lock); + unsafe { + self.lock.lock(); + while !(*self.state.get()).inc_writers() { + self.cond.wait(&self.lock); + } } self.lock.unlock(); } #[inline] pub unsafe fn try_write(&self) -> bool { - self.lock.lock(); - let ok = (*self.state.get()).inc_writers(); - self.lock.unlock(); + unsafe { + self.lock.lock(); + let ok = (*self.state.get()).inc_writers(); + self.lock.unlock(); + } return ok; } #[inline] pub unsafe fn read_unlock(&self) { - self.lock.lock(); - let notify = (*self.state.get()).dec_readers(); - self.lock.unlock(); - if notify { - // FIXME: should only wake up one of these some of the time - self.cond.notify_all(); + unsafe { + self.lock.lock(); + let notify = (*self.state.get()).dec_readers(); + self.lock.unlock(); + if notify { + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); + } } } #[inline] pub unsafe fn write_unlock(&self) { - self.lock.lock(); - (*self.state.get()).dec_writers(); - self.lock.unlock(); - // FIXME: should only wake up one of these some of the time - self.cond.notify_all(); + unsafe { + self.lock.lock(); + (*self.state.get()).dec_writers(); + self.lock.unlock(); + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); + } } #[inline] pub unsafe fn destroy(&self) { - self.lock.destroy(); - self.cond.destroy(); + unsafe { + self.lock.destroy(); + self.cond.destroy(); + } } } diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index e11afed668728..7c52112a80c2d 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![deny(unsafe_op_in_unsafe_fn)] use crate::ffi::CStr; use crate::io; @@ -25,18 +26,22 @@ impl Thread { core_id: isize, ) -> io::Result { let p = Box::into_raw(box p); - let tid = abi::spawn2( - thread_start, - p as usize, - abi::Priority::into(abi::NORMAL_PRIO), - stack, - core_id, - ); + let tid = unsafe { + abi::spawn2( + thread_start, + p as usize, + abi::Priority::into(abi::NORMAL_PRIO), + stack, + core_id, + ) + }; return if tid == 0 { // The thread failed to start and as a result p was not consumed. Therefore, it is // safe to reconstruct the box so that it gets deallocated. - drop(Box::from_raw(p)); + unsafe { + drop(Box::from_raw(p)); + } Err(io::Error::new(io::ErrorKind::Other, "Unable to create thread!")) } else { Ok(Thread { tid: tid }) diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 9b683fce15748..7998dd3cb4347 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -1,5 +1,6 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] +#![deny(unsafe_op_in_unsafe_fn)] // Simplify dtor registration by using a list of destructors. // The this solution works like the implementation of macOS and @@ -19,7 +20,8 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { DTORS.set(Box::into_raw(v)); } - let list: &mut List = &mut *DTORS.get(); + // SAFETY: `DTORS.get()` is not null. + let list: &mut List = unsafe { &mut *DTORS.get() }; list.push((t, dtor)); } @@ -27,7 +29,8 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { pub unsafe fn run_dtors() { let mut ptr = DTORS.replace(ptr::null_mut()); while !ptr.is_null() { - let list = Box::from_raw(ptr); + // SAFETY: `ptr` is not null. + let list = unsafe { Box::from_raw(ptr) }; for (ptr, dtor) in list.into_iter() { dtor(ptr); } From 3a46cca4aeb2f5c0dcbc9e982d915c519c44f783 Mon Sep 17 00:00:00 2001 From: maekawatoshiki Date: Fri, 21 Aug 2020 14:14:58 +0900 Subject: [PATCH 02/24] Revert "`#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit" This reverts commit 7cae9e8c88e468e94c157d9aaee4b8e3cf90b9a4. --- library/std/src/sys/hermit/alloc.rs | 25 +++---- library/std/src/sys/hermit/args.rs | 16 ++--- library/std/src/sys/hermit/condvar.rs | 34 +++------- library/std/src/sys/hermit/fd.rs | 1 - library/std/src/sys/hermit/mod.rs | 22 ++---- library/std/src/sys/hermit/mutex.rs | 26 +++---- library/std/src/sys/hermit/os.rs | 2 - library/std/src/sys/hermit/rwlock.rs | 68 +++++++------------ library/std/src/sys/hermit/thread.rs | 21 +++--- .../std/src/sys/hermit/thread_local_dtor.rs | 7 +- 10 files changed, 75 insertions(+), 147 deletions(-) diff --git a/library/std/src/sys/hermit/alloc.rs b/library/std/src/sys/hermit/alloc.rs index 04446172197f7..d153914e77e10 100644 --- a/library/std/src/sys/hermit/alloc.rs +++ b/library/std/src/sys/hermit/alloc.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys::hermit::abi; @@ -8,33 +6,26 @@ use crate::sys::hermit::abi; unsafe impl GlobalAlloc for System { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - // SAFETY: The safety contract for `malloc` must be upheld by the caller. - unsafe { abi::malloc(layout.size(), layout.align()) } + abi::malloc(layout.size(), layout.align()) } unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - // SAFETY: The safety contract for `malloc` must be upheld by the caller. - // Also, `addr` must be valid for writes of `layout.size() * size_of::()` bytes. - unsafe { - let addr = abi::malloc(layout.size(), layout.align()); - - if !addr.is_null() { - ptr::write_bytes(addr, 0x00, layout.size()); - } + let addr = abi::malloc(layout.size(), layout.align()); - addr + if !addr.is_null() { + ptr::write_bytes(addr, 0x00, layout.size()); } + + addr } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - // SAFETY: The safety contract for `free` must be upheld by the caller. - unsafe { abi::free(ptr, layout.size(), layout.align()) } + abi::free(ptr, layout.size(), layout.align()) } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - // SAFETY: The safety contract for `realloc` must be upheld by the caller. - unsafe { abi::realloc(ptr, layout.size(), layout.align(), new_size) } + abi::realloc(ptr, layout.size(), layout.align(), new_size) } } diff --git a/library/std/src/sys/hermit/args.rs b/library/std/src/sys/hermit/args.rs index dd8830599c37e..72c1b8511cac8 100644 --- a/library/std/src/sys/hermit/args.rs +++ b/library/std/src/sys/hermit/args.rs @@ -1,17 +1,15 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::ffi::OsString; use crate::marker::PhantomData; use crate::vec; /// One-time global initialization. pub unsafe fn init(argc: isize, argv: *const *const u8) { - unsafe { imp::init(argc, argv) } + imp::init(argc, argv) } /// One-time global cleanup. pub unsafe fn cleanup() { - unsafe { imp::cleanup() } + imp::cleanup() } /// Returns the command line arguments @@ -67,18 +65,14 @@ mod imp { pub unsafe fn init(argc: isize, argv: *const *const u8) { let _guard = LOCK.lock(); - unsafe { - ARGC = argc; - ARGV = argv; - } + ARGC = argc; + ARGV = argv; } pub unsafe fn cleanup() { let _guard = LOCK.lock(); ARGC = 0; - unsafe { - ARGV = ptr::null(); - } + ARGV = ptr::null(); } pub fn args() -> Args { diff --git a/library/std/src/sys/hermit/condvar.rs b/library/std/src/sys/hermit/condvar.rs index 662dc9394a36f..52c8c3b17e826 100644 --- a/library/std/src/sys/hermit/condvar.rs +++ b/library/std/src/sys/hermit/condvar.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::ffi::c_void; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; @@ -25,43 +23,33 @@ impl Condvar { } pub unsafe fn init(&mut self) { - unsafe { - let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0); - let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0); - } + let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0); + let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0); } pub unsafe fn notify_one(&self) { if self.counter.load(SeqCst) > 0 { self.counter.fetch_sub(1, SeqCst); - unsafe { - abi::sem_post(self.sem1); - abi::sem_timedwait(self.sem2, 0); - } + abi::sem_post(self.sem1); + abi::sem_timedwait(self.sem2, 0); } } pub unsafe fn notify_all(&self) { let counter = self.counter.swap(0, SeqCst); for _ in 0..counter { - unsafe { - abi::sem_post(self.sem1); - } + abi::sem_post(self.sem1); } for _ in 0..counter { - unsafe { - abi::sem_timedwait(self.sem2, 0); - } + abi::sem_timedwait(self.sem2, 0); } } pub unsafe fn wait(&self, mutex: &Mutex) { self.counter.fetch_add(1, SeqCst); mutex.unlock(); - unsafe { - abi::sem_timedwait(self.sem1, 0); - abi::sem_post(self.sem2); - } + abi::sem_timedwait(self.sem1, 0); + abi::sem_post(self.sem2); mutex.lock(); } @@ -70,9 +58,7 @@ impl Condvar { } pub unsafe fn destroy(&self) { - unsafe { - let _ = abi::sem_destroy(self.sem1); - let _ = abi::sem_destroy(self.sem2); - } + let _ = abi::sem_destroy(self.sem1); + let _ = abi::sem_destroy(self.sem2); } } diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 2914e5ad3dbe2..97d1a38b41ab1 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -1,4 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::io::{self, ErrorKind, Read}; diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 0e4504020df42..675b82ceb775f 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -13,8 +13,6 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -#![deny(unsafe_op_in_unsafe_fn)] - use crate::intrinsics; use crate::os::raw::c_char; @@ -64,12 +62,8 @@ pub enum Void {} pub unsafe fn strlen(start: *const c_char) -> usize { let mut str = start; - // SAFETY: The safety contract for `*str != 0` must be upheld by the caller. - // `start` must not be null. - unsafe { - while *str != 0 { - str = str.offset(1); - } + while *str != 0 { + str = str.offset(1); } (str as usize) - (start as usize) @@ -117,15 +111,13 @@ pub unsafe extern "C" fn runtime_entry( fn main(argc: isize, argv: *const *const c_char) -> i32; } - unsafe { - // initialize environment - os::init_environment(env as *const *const i8); + // initialize environment + os::init_environment(env as *const *const i8); - let result = main(argc as isize, argv); + let result = main(argc as isize, argv); - run_dtors(); - abi::exit(result); - } + run_dtors(); + abi::exit(result); } pub fn decode_error_kind(errno: i32) -> ErrorKind { diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index bcb2554ab2927..3d4813209cbc4 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::ffi::c_void; use crate::ptr; use crate::sys::hermit::abi; @@ -18,34 +16,28 @@ impl Mutex { #[inline] pub unsafe fn init(&mut self) { - unsafe { - let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1); - } + let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1); } #[inline] pub unsafe fn lock(&self) { - unsafe { - let _ = abi::sem_timedwait(self.inner, 0); - } + let _ = abi::sem_timedwait(self.inner, 0); } #[inline] pub unsafe fn unlock(&self) { - unsafe { - let _ = abi::sem_post(self.inner); - } + let _ = abi::sem_post(self.inner); } #[inline] pub unsafe fn try_lock(&self) -> bool { - let result = unsafe { abi::sem_trywait(self.inner) }; + let result = abi::sem_trywait(self.inner); result == 0 } #[inline] pub unsafe fn destroy(&self) { - let _ = unsafe { abi::sem_destroy(self.inner) }; + let _ = abi::sem_destroy(self.inner); } } @@ -60,12 +52,12 @@ impl ReentrantMutex { #[inline] pub unsafe fn init(&self) { - let _ = unsafe { abi::recmutex_init(&self.inner as *const *const c_void as *mut _) }; + let _ = abi::recmutex_init(&self.inner as *const *const c_void as *mut _); } #[inline] pub unsafe fn lock(&self) { - let _ = unsafe { abi::recmutex_lock(self.inner) }; + let _ = abi::recmutex_lock(self.inner); } #[inline] @@ -75,11 +67,11 @@ impl ReentrantMutex { #[inline] pub unsafe fn unlock(&self) { - let _ = unsafe { abi::recmutex_unlock(self.inner) }; + let _ = abi::recmutex_unlock(self.inner); } #[inline] pub unsafe fn destroy(&self) { - let _ = unsafe { abi::recmutex_destroy(self.inner) }; + let _ = abi::recmutex_destroy(self.inner); } } diff --git a/library/std/src/sys/hermit/os.rs b/library/std/src/sys/hermit/os.rs index d95940c9a76c8..78eabf8f81e98 100644 --- a/library/std/src/sys/hermit/os.rs +++ b/library/std/src/sys/hermit/os.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::collections::HashMap; use crate::error::Error as StdError; use crate::ffi::{CStr, OsStr, OsString}; diff --git a/library/std/src/sys/hermit/rwlock.rs b/library/std/src/sys/hermit/rwlock.rs index a6c7bcc7641fc..06442e925f4c8 100644 --- a/library/std/src/sys/hermit/rwlock.rs +++ b/library/std/src/sys/hermit/rwlock.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use crate::cell::UnsafeCell; use crate::sys::condvar::Condvar; use crate::sys::mutex::Mutex; @@ -34,76 +32,62 @@ impl RWLock { #[inline] pub unsafe fn read(&self) { - unsafe { - self.lock.lock(); - while !(*self.state.get()).inc_readers() { - self.cond.wait(&self.lock); - } - self.lock.unlock(); + self.lock.lock(); + while !(*self.state.get()).inc_readers() { + self.cond.wait(&self.lock); } + self.lock.unlock(); } #[inline] pub unsafe fn try_read(&self) -> bool { - unsafe { - self.lock.lock(); - let ok = (*self.state.get()).inc_readers(); - self.lock.unlock(); - } + self.lock.lock(); + let ok = (*self.state.get()).inc_readers(); + self.lock.unlock(); return ok; } #[inline] pub unsafe fn write(&self) { - unsafe { - self.lock.lock(); - while !(*self.state.get()).inc_writers() { - self.cond.wait(&self.lock); - } + self.lock.lock(); + while !(*self.state.get()).inc_writers() { + self.cond.wait(&self.lock); } self.lock.unlock(); } #[inline] pub unsafe fn try_write(&self) -> bool { - unsafe { - self.lock.lock(); - let ok = (*self.state.get()).inc_writers(); - self.lock.unlock(); - } + self.lock.lock(); + let ok = (*self.state.get()).inc_writers(); + self.lock.unlock(); return ok; } #[inline] pub unsafe fn read_unlock(&self) { - unsafe { - self.lock.lock(); - let notify = (*self.state.get()).dec_readers(); - self.lock.unlock(); - if notify { - // FIXME: should only wake up one of these some of the time - self.cond.notify_all(); - } + self.lock.lock(); + let notify = (*self.state.get()).dec_readers(); + self.lock.unlock(); + if notify { + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); } } #[inline] pub unsafe fn write_unlock(&self) { - unsafe { - self.lock.lock(); - (*self.state.get()).dec_writers(); - self.lock.unlock(); - // FIXME: should only wake up one of these some of the time - self.cond.notify_all(); - } + self.lock.lock(); + (*self.state.get()).dec_writers(); + self.lock.unlock(); + // FIXME: should only wake up one of these some of the time + self.cond.notify_all(); } #[inline] pub unsafe fn destroy(&self) { - unsafe { - self.lock.destroy(); - self.cond.destroy(); - } + self.lock.destroy(); + self.cond.destroy(); } } diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index 7c52112a80c2d..e11afed668728 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -#![deny(unsafe_op_in_unsafe_fn)] use crate::ffi::CStr; use crate::io; @@ -26,22 +25,18 @@ impl Thread { core_id: isize, ) -> io::Result { let p = Box::into_raw(box p); - let tid = unsafe { - abi::spawn2( - thread_start, - p as usize, - abi::Priority::into(abi::NORMAL_PRIO), - stack, - core_id, - ) - }; + let tid = abi::spawn2( + thread_start, + p as usize, + abi::Priority::into(abi::NORMAL_PRIO), + stack, + core_id, + ); return if tid == 0 { // The thread failed to start and as a result p was not consumed. Therefore, it is // safe to reconstruct the box so that it gets deallocated. - unsafe { - drop(Box::from_raw(p)); - } + drop(Box::from_raw(p)); Err(io::Error::new(io::ErrorKind::Other, "Unable to create thread!")) } else { Ok(Thread { tid: tid }) diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 7998dd3cb4347..9b683fce15748 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -1,6 +1,5 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] -#![deny(unsafe_op_in_unsafe_fn)] // Simplify dtor registration by using a list of destructors. // The this solution works like the implementation of macOS and @@ -20,8 +19,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { DTORS.set(Box::into_raw(v)); } - // SAFETY: `DTORS.get()` is not null. - let list: &mut List = unsafe { &mut *DTORS.get() }; + let list: &mut List = &mut *DTORS.get(); list.push((t, dtor)); } @@ -29,8 +27,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { pub unsafe fn run_dtors() { let mut ptr = DTORS.replace(ptr::null_mut()); while !ptr.is_null() { - // SAFETY: `ptr` is not null. - let list = unsafe { Box::from_raw(ptr) }; + let list = Box::from_raw(ptr); for (ptr, dtor) in list.into_iter() { dtor(ptr); } From d94258e83ed5c873200b9ba3314144ef9251ebf9 Mon Sep 17 00:00:00 2001 From: maekawatoshiki Date: Fri, 21 Aug 2020 14:20:59 +0900 Subject: [PATCH 03/24] Add `#![allow(unsafe_op_in_unsafe_fn)]` in sys/hermit --- library/std/src/sys/hermit/alloc.rs | 2 ++ library/std/src/sys/hermit/args.rs | 2 ++ library/std/src/sys/hermit/condvar.rs | 2 ++ library/std/src/sys/hermit/fd.rs | 1 + library/std/src/sys/hermit/mod.rs | 2 ++ library/std/src/sys/hermit/mutex.rs | 2 ++ library/std/src/sys/hermit/os.rs | 2 ++ library/std/src/sys/hermit/rwlock.rs | 2 ++ library/std/src/sys/hermit/thread.rs | 1 + library/std/src/sys/hermit/thread_local_dtor.rs | 1 + 10 files changed, 17 insertions(+) diff --git a/library/std/src/sys/hermit/alloc.rs b/library/std/src/sys/hermit/alloc.rs index d153914e77e10..cebe317de5678 100644 --- a/library/std/src/sys/hermit/alloc.rs +++ b/library/std/src/sys/hermit/alloc.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys::hermit::abi; diff --git a/library/std/src/sys/hermit/args.rs b/library/std/src/sys/hermit/args.rs index 72c1b8511cac8..194d94805724b 100644 --- a/library/std/src/sys/hermit/args.rs +++ b/library/std/src/sys/hermit/args.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::ffi::OsString; use crate::marker::PhantomData; use crate::vec; diff --git a/library/std/src/sys/hermit/condvar.rs b/library/std/src/sys/hermit/condvar.rs index 52c8c3b17e826..a69ab2d643cd2 100644 --- a/library/std/src/sys/hermit/condvar.rs +++ b/library/std/src/sys/hermit/condvar.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::ffi::c_void; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index 97d1a38b41ab1..fcdf1f058b162 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -1,4 +1,5 @@ #![unstable(reason = "not public", issue = "none", feature = "fd")] +#![allow(unsafe_op_in_unsafe_fn)] use crate::io::{self, ErrorKind, Read}; use crate::mem; diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 675b82ceb775f..17a2cdf6bf8fa 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -13,6 +13,8 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! +#![allow(unsafe_op_in_unsafe_fn)] + use crate::intrinsics; use crate::os::raw::c_char; diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index 3d4813209cbc4..6af1854e7041c 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::ffi::c_void; use crate::ptr; use crate::sys::hermit::abi; diff --git a/library/std/src/sys/hermit/os.rs b/library/std/src/sys/hermit/os.rs index 78eabf8f81e98..ca0ffb7524d29 100644 --- a/library/std/src/sys/hermit/os.rs +++ b/library/std/src/sys/hermit/os.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::collections::HashMap; use crate::error::Error as StdError; use crate::ffi::{CStr, OsStr, OsString}; diff --git a/library/std/src/sys/hermit/rwlock.rs b/library/std/src/sys/hermit/rwlock.rs index 06442e925f4c8..5672118188b37 100644 --- a/library/std/src/sys/hermit/rwlock.rs +++ b/library/std/src/sys/hermit/rwlock.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_op_in_unsafe_fn)] + use crate::cell::UnsafeCell; use crate::sys::condvar::Condvar; use crate::sys::mutex::Mutex; diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index e11afed668728..22fe57f38d23e 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(unsafe_op_in_unsafe_fn)] use crate::ffi::CStr; use crate::io; diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 9b683fce15748..178788057a176 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -1,5 +1,6 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] +#![allow(unsafe_op_in_unsafe_fn)] // Simplify dtor registration by using a list of destructors. // The this solution works like the implementation of macOS and From 14158f551474d4114b9a2a583b0bf6c2502ad166 Mon Sep 17 00:00:00 2001 From: maekawatoshiki Date: Thu, 8 Oct 2020 22:13:14 +0900 Subject: [PATCH 04/24] Remove #![allow(unsafe_op_in_unsafe_fn)] except for mod.rs --- library/std/src/sys/hermit/alloc.rs | 2 -- library/std/src/sys/hermit/args.rs | 2 -- library/std/src/sys/hermit/condvar.rs | 2 -- library/std/src/sys/hermit/fd.rs | 1 - library/std/src/sys/hermit/mutex.rs | 2 -- library/std/src/sys/hermit/os.rs | 2 -- library/std/src/sys/hermit/rwlock.rs | 2 -- library/std/src/sys/hermit/thread.rs | 1 - library/std/src/sys/hermit/thread_local_dtor.rs | 1 - 9 files changed, 15 deletions(-) diff --git a/library/std/src/sys/hermit/alloc.rs b/library/std/src/sys/hermit/alloc.rs index cebe317de5678..d153914e77e10 100644 --- a/library/std/src/sys/hermit/alloc.rs +++ b/library/std/src/sys/hermit/alloc.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys::hermit::abi; diff --git a/library/std/src/sys/hermit/args.rs b/library/std/src/sys/hermit/args.rs index 194d94805724b..72c1b8511cac8 100644 --- a/library/std/src/sys/hermit/args.rs +++ b/library/std/src/sys/hermit/args.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::ffi::OsString; use crate::marker::PhantomData; use crate::vec; diff --git a/library/std/src/sys/hermit/condvar.rs b/library/std/src/sys/hermit/condvar.rs index a69ab2d643cd2..52c8c3b17e826 100644 --- a/library/std/src/sys/hermit/condvar.rs +++ b/library/std/src/sys/hermit/condvar.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::ffi::c_void; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; diff --git a/library/std/src/sys/hermit/fd.rs b/library/std/src/sys/hermit/fd.rs index fcdf1f058b162..97d1a38b41ab1 100644 --- a/library/std/src/sys/hermit/fd.rs +++ b/library/std/src/sys/hermit/fd.rs @@ -1,5 +1,4 @@ #![unstable(reason = "not public", issue = "none", feature = "fd")] -#![allow(unsafe_op_in_unsafe_fn)] use crate::io::{self, ErrorKind, Read}; use crate::mem; diff --git a/library/std/src/sys/hermit/mutex.rs b/library/std/src/sys/hermit/mutex.rs index 6af1854e7041c..3d4813209cbc4 100644 --- a/library/std/src/sys/hermit/mutex.rs +++ b/library/std/src/sys/hermit/mutex.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::ffi::c_void; use crate::ptr; use crate::sys::hermit::abi; diff --git a/library/std/src/sys/hermit/os.rs b/library/std/src/sys/hermit/os.rs index ca0ffb7524d29..78eabf8f81e98 100644 --- a/library/std/src/sys/hermit/os.rs +++ b/library/std/src/sys/hermit/os.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::collections::HashMap; use crate::error::Error as StdError; use crate::ffi::{CStr, OsStr, OsString}; diff --git a/library/std/src/sys/hermit/rwlock.rs b/library/std/src/sys/hermit/rwlock.rs index 5672118188b37..06442e925f4c8 100644 --- a/library/std/src/sys/hermit/rwlock.rs +++ b/library/std/src/sys/hermit/rwlock.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use crate::cell::UnsafeCell; use crate::sys::condvar::Condvar; use crate::sys::mutex::Mutex; diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index 22fe57f38d23e..e11afed668728 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -#![allow(unsafe_op_in_unsafe_fn)] use crate::ffi::CStr; use crate::io; diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 178788057a176..9b683fce15748 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -1,6 +1,5 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] -#![allow(unsafe_op_in_unsafe_fn)] // Simplify dtor registration by using a list of destructors. // The this solution works like the implementation of macOS and From 1e737249afa1219205f6cc182ce975ffe94f06f9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 28 Oct 2020 23:38:31 -0400 Subject: [PATCH 05/24] Allow using 1/2/3/4 for `x.py setup` options This undocumented feature allows you to typo 'a' as '1'. --- src/bootstrap/setup.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs index c6e1c99564c09..0945ceee6cee0 100644 --- a/src/bootstrap/setup.rs +++ b/src/bootstrap/setup.rs @@ -127,14 +127,17 @@ pub fn setup(src_path: &Path, profile: Profile) { // Used to get the path for `Subcommand::Setup` pub fn interactive_path() -> io::Result { - fn abbrev_all() -> impl Iterator { - ('a'..).map(|c| c.to_string()).zip(Profile::all()) + fn abbrev_all() -> impl Iterator { + ('a'..) + .zip(1..) + .map(|(letter, number)| (letter.to_string(), number.to_string())) + .zip(Profile::all()) } fn parse_with_abbrev(input: &str) -> Result { let input = input.trim().to_lowercase(); - for (letter, profile) in abbrev_all() { - if input == letter { + for ((letter, number), profile) in abbrev_all() { + if input == letter || input == number { return Ok(profile); } } @@ -142,13 +145,13 @@ pub fn interactive_path() -> io::Result { } println!("Welcome to the Rust project! What do you want to do with x.py?"); - for (letter, profile) in abbrev_all() { + for ((letter, _), profile) in abbrev_all() { println!("{}) {}: {}", letter, profile, profile.purpose()); } let template = loop { print!( "Please choose one ({}): ", - abbrev_all().map(|(l, _)| l).collect::>().join("/") + abbrev_all().map(|((l, _), _)| l).collect::>().join("/") ); io::stdout().flush()?; let mut input = String::new(); From be01d54f07b9c56d2426ddaebaea499575479b38 Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Thu, 29 Oct 2020 20:51:39 +0100 Subject: [PATCH 06/24] BTreeMap: document a curious assumption in test cases --- library/alloc/src/collections/btree/map/tests.rs | 1 + library/alloc/src/collections/btree/mod.rs | 1 + library/alloc/src/collections/btree/set/tests.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs index adb94972f5bb6..710aa2adfecbd 100644 --- a/library/alloc/src/collections/btree/map/tests.rs +++ b/library/alloc/src/collections/btree/map/tests.rs @@ -1661,6 +1661,7 @@ create_append_test!(test_append_239, 239); create_append_test!(test_append_1700, 1700); fn rand_data(len: usize) -> Vec<(u32, u32)> { + assert!(len * 2 <= 70029); // from that point on numbers repeat let mut rng = DeterministicRng::new(); Vec::from_iter((0..len).map(|_| (rng.next(), rng.next()))) } diff --git a/library/alloc/src/collections/btree/mod.rs b/library/alloc/src/collections/btree/mod.rs index 4c07795bd70cd..7bf1706dd6d57 100644 --- a/library/alloc/src/collections/btree/mod.rs +++ b/library/alloc/src/collections/btree/mod.rs @@ -49,6 +49,7 @@ impl DeterministicRng { DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb } } + /// Guarantees that the first 70029 results are unique. fn next(&mut self) -> u32 { let x = self.x; let t = x ^ (x << 11); diff --git a/library/alloc/src/collections/btree/set/tests.rs b/library/alloc/src/collections/btree/set/tests.rs index 9267435728216..eb3feef09e51e 100644 --- a/library/alloc/src/collections/btree/set/tests.rs +++ b/library/alloc/src/collections/btree/set/tests.rs @@ -680,6 +680,7 @@ fn test_first_last() { } fn rand_data(len: usize) -> Vec { + assert!(len <= 70029); // from that point on numbers repeat let mut rng = DeterministicRng::new(); Vec::from_iter((0..len).map(|_| rng.next())) } From 5fb5707f3524c9dfc2c8ae53a689bdced4aade2f Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 30 Oct 2020 16:42:07 +0900 Subject: [PATCH 07/24] Add LLVM upgrades from 7 to 10 to RELEASES.md Fixes #78464 --- RELEASES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index ce11a74b71f53..c9ff49287637d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -297,6 +297,7 @@ Compiler - [Added the `tiny` value to the `code-model` codegen flag.][72397] - [Added tier 3 support\* for the `mipsel-sony-psp` target.][72062] - [Added tier 3 support for the `thumbv7a-uwp-windows-msvc` target.][72133] +- [Upgraded to LLVM 10.][67759] \* Refer to Rust's [platform support page][forge-platform-support] for more information on Rust's tiered platform support. @@ -396,6 +397,7 @@ Internals Only [72062]: https://github.com/rust-lang/rust/pull/72062/ [72094]: https://github.com/rust-lang/rust/pull/72094/ [72133]: https://github.com/rust-lang/rust/pull/72133/ +[67759]: https://github.com/rust-lang/rust/pull/67759/ [71900]: https://github.com/rust-lang/rust/pull/71900/ [71928]: https://github.com/rust-lang/rust/pull/71928/ [71662]: https://github.com/rust-lang/rust/pull/71662/ @@ -1270,6 +1272,7 @@ Compiler `armv7-unknown-linux-musleabi` targets.][63107] - [Added tier 3 support for the `hexagon-unknown-linux-musl` target.][62814] - [Added tier 3 support for the `riscv32i-unknown-none-elf` target.][62784] +- [Upgraded to LLVM 9.][62592] \* Refer to Rust's [platform support page][forge-platform-support] for more information on Rust's tiered platform support. @@ -1336,6 +1339,7 @@ Compatibility Notes [62735]: https://github.com/rust-lang/rust/pull/62735/ [62766]: https://github.com/rust-lang/rust/pull/62766/ [62784]: https://github.com/rust-lang/rust/pull/62784/ +[62592]: https://github.com/rust-lang/rust/pull/62592/ [62785]: https://github.com/rust-lang/rust/issues/62785/ [62814]: https://github.com/rust-lang/rust/pull/62814/ [62896]: https://github.com/rust-lang/rust/issues/62896/ @@ -2431,6 +2435,7 @@ Compiler -------- - [Added the `riscv32imc-unknown-none-elf` target.][53822] - [Added the `aarch64-unknown-netbsd` target][53165] +- [Upgraded to LLVM 8.][53611] Libraries --------- @@ -2479,6 +2484,7 @@ Misc [53033]: https://github.com/rust-lang/rust/pull/53033/ [53044]: https://github.com/rust-lang/rust/pull/53044/ [53165]: https://github.com/rust-lang/rust/pull/53165/ +[53611]: https://github.com/rust-lang/rust/pull/53611/ [53213]: https://github.com/rust-lang/rust/pull/53213/ [53236]: https://github.com/rust-lang/rust/pull/53236/ [53272]: https://github.com/rust-lang/rust/pull/53272/ @@ -2537,6 +2543,7 @@ Compiler - [Bumped minimum LLVM version to 5.0.][51899] - [Added `powerpc64le-unknown-linux-musl` target.][51619] - [Added `aarch64-unknown-hermit` and `x86_64-unknown-hermit` targets.][52861] +- [Upgraded to LLVM 7.][51966] Libraries --------- @@ -2588,6 +2595,7 @@ Compatibility Notes [53893]: https://github.com/rust-lang/rust/pull/53893/ [52861]: https://github.com/rust-lang/rust/pull/52861/ +[51966]: https://github.com/rust-lang/rust/pull/51966/ [52656]: https://github.com/rust-lang/rust/pull/52656/ [52239]: https://github.com/rust-lang/rust/pull/52239/ [52330]: https://github.com/rust-lang/rust/pull/52330/ From f289a8762837a6b4e5603278c0098ec327ec449e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 3 Nov 2020 10:43:17 -0500 Subject: [PATCH 08/24] Print a summary of which test suite failed Especially on CI, where cross-compiling is common and single builder may end up with multiple hosts and multiple targets, it can be annoying to scroll back to the nearest start of test marker. This prints out a summary of the test suite being run directly in compiletest. --- src/bootstrap/test.rs | 1 + src/tools/compiletest/src/common.rs | 4 +++ src/tools/compiletest/src/header/tests.rs | 1 + src/tools/compiletest/src/main.rs | 32 +++++++++++++++++++++-- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 6c2c05ac7197e..84d69e52de635 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1039,6 +1039,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite)); cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite)); cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); + cmd.arg("--suite").arg(suite); cmd.arg("--mode").arg(mode); cmd.arg("--target").arg(target.rustc_target_arg()); cmd.arg("--host").arg(&*compiler.host.triple); diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 2f832b53a9039..24ef98cd784d8 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -224,6 +224,10 @@ pub struct Config { /// The test mode, compile-fail, run-fail, ui pub mode: Mode, + /// The test suite (essentially which directory is running, but without the + /// directory prefix such as src/test) + pub suite: String, + /// The debugger to use in debuginfo mode. Unset otherwise. pub debugger: Option, diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 1f82b137ee6cf..4bcbd89f09510 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -39,6 +39,7 @@ fn config() -> Config { let args = &[ "compiletest", "--mode=ui", + "--suite=ui", "--compile-lib-path=", "--run-lib-path=", "--rustc-path=", diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 2b2a6cfa8bd6f..2b167ac8e9fb2 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -70,6 +70,12 @@ pub fn parse_config(args: Vec) -> Config { "compile-fail | run-fail | run-pass-valgrind | pretty | debug-info | codegen | rustdoc \ codegen-units | incremental | run-make | ui | js-doc-test | mir-opt | assembly", ) + .reqopt( + "", + "suite", + "which suite of compile tests to run. used for nicer error reporting.", + "SUITE", + ) .optopt( "", "pass", @@ -201,6 +207,7 @@ pub fn parse_config(args: Vec) -> Config { build_base: opt_path(matches, "build-base"), stage_id: matches.opt_str("stage-id").unwrap(), mode: matches.opt_str("mode").unwrap().parse().expect("invalid mode"), + suite: matches.opt_str("suite").unwrap(), debugger: None, run_ignored, filter: matches.free.first().cloned(), @@ -340,7 +347,7 @@ pub fn run_tests(config: Config) { configs.extend(configure_lldb(&config)); } } else { - configs.push(config); + configs.push(config.clone()); }; let mut tests = Vec::new(); @@ -351,11 +358,32 @@ pub fn run_tests(config: Config) { let res = test::run_tests_console(&opts, tests); match res { Ok(true) => {} - Ok(false) => panic!("Some tests failed"), + Ok(false) => { + // We want to report that the tests failed, but we also want to give + // some indication of just what tests we were running. Especially on + // CI, where there can be cross-compiled tests for a lot of + // architectures, without this critical information it can be quite + // easy to miss which tests failed, and as such fail to reproduce + // the failure locally. + + eprintln!( + "Some tests failed in compiletest suite={}{} mode={} host={} target={}", + config.suite, + config.compare_mode.map(|c| format!(" compare_mode={:?}", c)).unwrap_or_default(), + config.mode, + config.host, + config.target + ); + + std::process::exit(1); + } Err(e) => { // We don't know if tests passed or not, but if there was an error // during testing we don't want to just suceeed (we may not have // tested something), so fail. + // + // This should realistically "never" happen, so don't try to make + // this a pretty error message. panic!("I/O failure during tests: {:?}", e); } } From 8db2bf2b0c9adcfd3cfa1f6a968742cb2811a224 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Nov 2020 11:06:42 +0100 Subject: [PATCH 09/24] Add link to rust website --- src/doc/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/index.md b/src/doc/index.md index 2d10230ffcf7a..2c92d5e2a1803 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -26,7 +26,7 @@ h2 { } -Welcome to an overview of the documentation provided by the Rust project. +Welcome to an overview of the documentation provided by the [Rust project]. All of these projects are managed by the Docs Team; there are other unofficial documentation resources as well! @@ -139,3 +139,4 @@ When developing for Bare Metal or Embedded Linux systems, you may find these res [The Embedded Rust Book] is targeted at developers familiar with embedded development and familiar with Rust, but have not used Rust for embedded development. [The Embedded Rust Book]: embedded-book/index.html +[Rust project]: https://www.rust-lang.org From 340c94ad76888d3cbc80f34651c08c29aa084e0d Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 4 Nov 2020 11:12:33 +0000 Subject: [PATCH 10/24] Expand explanation of reverse_bits --- library/core/src/num/int_macros.rs | 4 +++- library/core/src/num/uint_macros.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 295a876773c48..728381b658f7c 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -274,7 +274,8 @@ assert_eq!(m, ", $swapped, "); } doc_comment! { - concat!("Reverses the bit pattern of the integer. + concat!("Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, + second least-significant bit becomes second most-significant bit, etc. # Examples @@ -285,6 +286,7 @@ let n = ", $swap_op, stringify!($SelfT), "; let m = n.reverse_bits(); assert_eq!(m, ", $reversed, "); +assert_eq!(0, 0", stringify!($SelfT), ".reverse_bits()); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index bdea0ea3b08c0..adcbbf91433b6 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -272,7 +272,8 @@ assert_eq!(m, ", $swapped, "); } doc_comment! { - concat!("Reverses the bit pattern of the integer. + concat!("Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, + second least-significant bit becomes second most-significant bit, etc. # Examples @@ -283,6 +284,7 @@ let n = ", $swap_op, stringify!($SelfT), "; let m = n.reverse_bits(); assert_eq!(m, ", $reversed, "); +assert_eq!(0, 0", stringify!($SelfT), ".reverse_bits()); ```"), #[stable(feature = "reverse_bits", since = "1.37.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] From 6ca43aca1d550855e32f516cf8c89fd9e717d8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 5 Nov 2020 00:00:00 +0000 Subject: [PATCH 11/24] inliner: Copy unevaluated constants only after successful inlining Inliner copies the unevaluated constants from the callee body to the caller at the point where decision to inline is yet to be made. The constants will be unnecessary if inlining were to fail. Organize the code moving items from callee to the caller together in one place to avoid the issue. --- compiler/rustc_mir/src/transform/inline.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 5407226e386cb..4de9373999254 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -140,14 +140,6 @@ impl Inliner<'tcx> { continue; }; - // Copy only unevaluated constants from the callee_body into the caller_body. - // Although we are only pushing `ConstKind::Unevaluated` consts to - // `required_consts`, here we may not only have `ConstKind::Unevaluated` - // because we are calling `subst_and_normalize_erasing_regions`. - caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter( - |&constant| matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)), - )); - let start = caller_body.basic_blocks().len(); debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body); if !self.inline_call(callsite, caller_body, callee_body) { @@ -522,6 +514,16 @@ impl Inliner<'tcx> { kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) }, }); + // Copy only unevaluated constants from the callee_body into the caller_body. + // Although we are only pushing `ConstKind::Unevaluated` consts to + // `required_consts`, here we may not only have `ConstKind::Unevaluated` + // because we are calling `subst_and_normalize_erasing_regions`. + caller_body.required_consts.extend( + callee_body.required_consts.iter().copied().filter(|&constant| { + matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)) + }), + ); + true } kind => { From 9d9292cfda593c87100c8bb5b6c2c7f87f7f000a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 4 Nov 2020 23:33:00 -0500 Subject: [PATCH 12/24] `deny(invalid_codeblock_attributes)` --- compiler/rustc_error_codes/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index 4353a294cc31d..e4a702531442e 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -1,3 +1,4 @@ +#![deny(invalid_codeblock_attributes)] //! This library is used to gather all error codes into one place, //! the goal being to make their maintenance easier. From 03f0ca0cf4bf427516f9d87a959b7c97c9ff9447 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Oct 2020 19:32:59 +0100 Subject: [PATCH 13/24] Add test --- .../or-patterns/exhaustiveness-unreachable-pattern.rs | 11 +++++++++-- .../exhaustiveness-unreachable-pattern.stderr | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs index a1147cb5cfc9c..97a8f526176cf 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs @@ -77,10 +77,17 @@ fn main() { (false | true, false | true) => {} } match (true, true) { - (true, false) => {} - (false, true) => {} + (true, true) => {} + (false, false) => {} (false | true, false | true) => {} } + // https://github.com/rust-lang/rust/issues/76836 + match None { + Some(false) => {} + None | Some(true + | false) => {} // expected unreachable warning here + } + // A subpattern that is unreachable in all branches is overall unreachable. match (true, true) { (false, true) => {} diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index d92b545a8694f..e83cd247a57a7 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -101,13 +101,13 @@ LL | Some(0 | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:89:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:96:15 | LL | | true) => {} | ^^^^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:95:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:102:15 | LL | | true, | ^^^^ From 25e272e3886ecdc91f3e42436cedbe5a6fc6ff29 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 20 Oct 2020 22:08:19 +0100 Subject: [PATCH 14/24] Fix unreachable sub-branch detection This fixes https://github.com/rust-lang/rust/issues/76836 --- .../src/thir/pattern/_match.rs | 120 +++++++++++++----- .../src/thir/pattern/check_match.rs | 8 +- .../exhaustiveness-unreachable-pattern.rs | 2 +- .../exhaustiveness-unreachable-pattern.stderr | 16 ++- 4 files changed, 105 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/_match.rs b/compiler/rustc_mir_build/src/thir/pattern/_match.rs index e0de1351ac33e..d72a679dd5d3e 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/_match.rs @@ -1,5 +1,11 @@ -//! Note: most of the tests relevant to this file can be found (at the time of writing) in -//! src/tests/ui/pattern/usefulness. +//! Note: tests specific to this file can be found in: +//! - ui/pattern/usefulness +//! - ui/or-patterns +//! - ui/consts/const_in_pattern +//! - ui/rfc-2008-non-exhaustive +//! - probably many others +//! I (Nadrieril) prefer to put new tests in `ui/pattern/usefulness` unless there's a specific +//! reason not to, for example if they depend on a particular feature like or_patterns. //! //! This file includes the logic for exhaustiveness and usefulness checking for //! pattern-matching. Specifically, given a list of patterns for a type, we can @@ -1361,8 +1367,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> { #[derive(Clone, Debug)] crate enum Usefulness<'tcx> { - /// Carries a list of unreachable subpatterns. Used only in the presence of or-patterns. - Useful(Vec), + /// Carries, for each column in the matrix, a set of sub-branches that have been found to be + /// unreachable. Used only in the presence of or-patterns, otherwise it stays empty. + Useful(Vec>), /// Carries a list of witnesses of non-exhaustiveness. UsefulWithWitness(Vec>), NotUseful, @@ -1410,6 +1417,23 @@ impl<'tcx> Usefulness<'tcx> { }; UsefulWithWitness(new_witnesses) } + Useful(mut unreachables) => { + if !unreachables.is_empty() { + // When we apply a constructor, there are `arity` columns of the matrix that + // corresponded to its arguments. All the unreachables found in these columns + // will, after `apply`, come from the first column. So we take the union of all + // the corresponding sets and put them in the first column. + // Note that `arity` may be 0, in which case we just push a new empty set. + let len = unreachables.len(); + let arity = ctor_wild_subpatterns.len(); + let mut unioned = FxHashSet::default(); + for set in unreachables.drain((len - arity)..) { + unioned.extend(set) + } + unreachables.push(unioned); + } + Useful(unreachables) + } x => x, } } @@ -2091,13 +2115,14 @@ crate fn is_useful<'p, 'tcx>( // If the first pattern is an or-pattern, expand it. if let Some(vs) = v.expand_or_pat() { - // We need to push the already-seen patterns into the matrix in order to detect redundant - // branches like `Some(_) | Some(0)`. We also keep track of the unreachable subpatterns. - let mut matrix = matrix.clone(); - // `Vec` of all the unreachable branches of the current or-pattern. - let mut unreachable_branches = Vec::new(); - // Subpatterns that are unreachable from all branches. E.g. in the following case, the last - // `true` is unreachable only from one branch, so it is overall reachable. + // We expand the or pattern, trying each of its branches in turn and keeping careful track + // of possible unreachable sub-branches. + // + // If two branches have detected some unreachable sub-branches, we need to be careful. If + // they were detected in columns that are not the current one, we want to keep only the + // sub-branches that were unreachable in _all_ branches. Eg. in the following, the last + // `true` is unreachable in the second branch of the first or-pattern, but not otherwise. + // Therefore we don't want to lint that it is unreachable. // // ``` // match (true, true) { @@ -2105,41 +2130,72 @@ crate fn is_useful<'p, 'tcx>( // (false | true, false | true) => {} // } // ``` - let mut unreachable_subpats = FxHashSet::default(); - // Whether any branch at all is useful. + // If however the sub-branches come from the current column, they come from the inside of + // the current or-pattern, and we want to keep them all. Eg. in the following, we _do_ want + // to lint that the last `false` is unreachable. + // ``` + // match None { + // Some(false) => {} + // None | Some(true | false) => {} + // } + // ``` + + let mut matrix = matrix.clone(); + // We keep track of sub-branches separately depending on whether they come from this column + // or from others. + let mut unreachables_this_column: FxHashSet = FxHashSet::default(); + let mut unreachables_other_columns: Vec> = Vec::default(); + // Whether at least one branch is reachable. let mut any_is_useful = false; for v in vs { let res = is_useful(cx, &matrix, &v, witness_preference, hir_id, is_under_guard, false); match res { - Useful(pats) => { - if !any_is_useful { - any_is_useful = true; - // Initialize with the first set of unreachable subpatterns encountered. - unreachable_subpats = pats.into_iter().collect(); - } else { - // Keep the patterns unreachable from both this and previous branches. - unreachable_subpats = - pats.into_iter().filter(|p| unreachable_subpats.contains(p)).collect(); + Useful(unreachables) => { + if let Some((this_column, other_columns)) = unreachables.split_last() { + // We keep the union of unreachables found in the first column. + unreachables_this_column.extend(this_column); + // We keep the intersection of unreachables found in other columns. + if unreachables_other_columns.is_empty() { + unreachables_other_columns = other_columns.to_vec(); + } else { + unreachables_other_columns = unreachables_other_columns + .into_iter() + .zip(other_columns) + .map(|(x, y)| x.intersection(&y).copied().collect()) + .collect(); + } } + any_is_useful = true; } - NotUseful => unreachable_branches.push(v.head().span), - UsefulWithWitness(_) => { - bug!("Encountered or-pat in `v` during exhaustiveness checking") + NotUseful => { + unreachables_this_column.insert(v.head().span); } + UsefulWithWitness(_) => bug!( + "encountered or-pat in the expansion of `_` during exhaustiveness checking" + ), } - // If pattern has a guard don't add it to the matrix + + // If pattern has a guard don't add it to the matrix. if !is_under_guard { + // We push the already-seen patterns into the matrix in order to detect redundant + // branches like `Some(_) | Some(0)`. matrix.push(v); } } - if any_is_useful { - // Collect all the unreachable patterns. - unreachable_branches.extend(unreachable_subpats); - return Useful(unreachable_branches); + + return if any_is_useful { + let mut unreachables = if unreachables_other_columns.is_empty() { + let n_columns = v.len(); + (0..n_columns - 1).map(|_| FxHashSet::default()).collect() + } else { + unreachables_other_columns + }; + unreachables.push(unreachables_this_column); + Useful(unreachables) } else { - return NotUseful; - } + NotUseful + }; } // FIXME(Nadrieril): Hack to work around type normalization issues (see #72476). diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 30b700a1d4f63..317b8dc205eae 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -389,9 +389,11 @@ fn check_arms<'p, 'tcx>( hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar => {} } } - Useful(unreachable_subpatterns) => { - for span in unreachable_subpatterns { - unreachable_pattern(cx.tcx, span, id, None); + Useful(unreachables) => { + for set in unreachables { + for span in set { + unreachable_pattern(cx.tcx, span, id, None); + } } } UsefulWithWitness(_) => bug!(), diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs index 97a8f526176cf..512f1e283cb46 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs @@ -85,7 +85,7 @@ fn main() { match None { Some(false) => {} None | Some(true - | false) => {} // expected unreachable warning here + | false) => {} //~ ERROR unreachable } // A subpattern that is unreachable in all branches is overall unreachable. diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index e83cd247a57a7..3956a42c536b9 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -77,15 +77,15 @@ LL | (1 | 1,) => {} | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 | -LL | | 0 +LL | | 0] => {} | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 | -LL | | 0] => {} +LL | | 0 | ^ error: unreachable pattern @@ -100,6 +100,12 @@ error: unreachable pattern LL | Some(0 | ^ +error: unreachable pattern + --> $DIR/exhaustiveness-unreachable-pattern.rs:88:19 + | +LL | | false) => {} + | ^^^^^ + error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:96:15 | @@ -112,5 +118,5 @@ error: unreachable pattern LL | | true, | ^^^^ -error: aborting due to 18 previous errors +error: aborting due to 19 previous errors From 107a29a90146ac418c71f306691cd4857ce15c03 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 5 Nov 2020 22:17:26 +0000 Subject: [PATCH 15/24] Emit lints in the order in which they occur in the file. --- compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 9 +++++---- .../exhaustiveness-unreachable-pattern.stderr | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 317b8dc205eae..205ad850c0c80 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -390,10 +390,11 @@ fn check_arms<'p, 'tcx>( } } Useful(unreachables) => { - for set in unreachables { - for span in set { - unreachable_pattern(cx.tcx, span, id, None); - } + let mut unreachables: Vec<_> = unreachables.into_iter().flatten().collect(); + // Emit lints in the order in which they occur in the file. + unreachables.sort_unstable(); + for span in unreachables { + unreachable_pattern(cx.tcx, span, id, None); } } UsefulWithWitness(_) => bug!(), diff --git a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr index 3956a42c536b9..e968310d108dd 100644 --- a/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr @@ -77,15 +77,15 @@ LL | (1 | 1,) => {} | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 | -LL | | 0] => {} +LL | | 0 | ^ error: unreachable pattern - --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15 + --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15 | -LL | | 0 +LL | | 0] => {} | ^ error: unreachable pattern From fe6dfcd28a9cbb8080313433a825cdec7b6a78b3 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 15 Oct 2020 22:48:57 -0600 Subject: [PATCH 16/24] Intra-doc links for std::io::buffered --- library/std/src/io/buffered/bufreader.rs | 2 +- library/std/src/io/buffered/bufwriter.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index 8fe29f08a7bd7..777d376f99173 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -21,7 +21,7 @@ use crate::io::{self, BufRead, Initializer, IoSliceMut, Read, Seek, SeekFrom, DE /// unwrapping the `BufReader` with [`BufReader::into_inner`] can also cause /// data loss. /// -/// [`TcpStream::read`]: Read::read +/// [`TcpStream::read`]: super::super::super::net::TcpStream::read /// [`TcpStream`]: crate::net::TcpStream /// /// # Examples diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 3ec272fea6668..a1face6443ae6 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -59,9 +59,9 @@ use crate::io::{ /// together by the buffer and will all be written out in one system call when /// the `stream` is flushed. /// -/// [`TcpStream::write`]: Write::write +/// [`TcpStream::write`]: super::super::super::net::TcpStream::write /// [`TcpStream`]: crate::net::TcpStream -/// [`flush`]: Write::flush +/// [`flush`]: BufWriter::flush #[stable(feature = "rust1", since = "1.0.0")] pub struct BufWriter { inner: Option, From de2940ff6301f23fd721e0d6f38b23ae2e3a9746 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 6 Nov 2020 02:46:03 +0100 Subject: [PATCH 17/24] rustc_expand: use collect_bang helper instead of manual reimplementation --- compiler/rustc_expand/src/expand.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 3e5762ab992f4..f6959591b5660 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1436,9 +1436,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { item.attrs = attrs; self.check_attributes(&item.attrs); item.and_then(|item| match item.kind { - ItemKind::MacCall(mac) => self - .collect(AstFragmentKind::Items, InvocationKind::Bang { mac, span }) - .make_items(), + ItemKind::MacCall(mac) => { + self.collect_bang(mac, span, AstFragmentKind::Items).make_items() + } _ => unreachable!(), }) } From dfa5e46fd56337aee6ce8473526cd8e43787289f Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 6 Nov 2020 03:03:22 +0100 Subject: [PATCH 18/24] The renumber pass is long gone Originally, there has been a dedicated pass for renumbering AST NodeIds to have actual values. This pass had been added by commit a5ad4c379466519a0bf977864a5cdc50a7ade385. Then, later, this step was moved to where it resides now, macro expansion. See commit c86c8d41a26b2037e80c9fd028a59313a78b3a66 or PR #36438. The comment snippet, added by the original commit, has survived the times without any change, becoming outdated at removal of the dedicated pass. Nowadays, grepping for the next_node_id function will show up multiple places in the compiler that call it, but the main rewriting that the comment talks about is still done in the expansion step, inside an innocious looking visit_id function that's called during macro invocation collection. --- compiler/rustc_ast/src/node_id.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/node_id.rs b/compiler/rustc_ast/src/node_id.rs index 1035e945538f5..6e7d2bab2877e 100644 --- a/compiler/rustc_ast/src/node_id.rs +++ b/compiler/rustc_ast/src/node_id.rs @@ -13,8 +13,8 @@ rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId); pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0); /// When parsing and doing expansions, we initially give all AST nodes this AST -/// node value. Then later, in the renumber pass, we renumber them to have -/// small, positive ids. +/// node value. Then later, during expansion, we renumber them to have small, +/// positive ids. pub const DUMMY_NODE_ID: NodeId = NodeId::MAX; impl NodeId { From 8d48e3bbb2da2f5eb5f4a95efd6846e9ea93a160 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 5 Nov 2020 19:26:08 -0700 Subject: [PATCH 19/24] document HACKs --- library/std/src/io/buffered/bufreader.rs | 1 + library/std/src/io/buffered/bufwriter.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index 777d376f99173..16c18d6e14645 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -21,6 +21,7 @@ use crate::io::{self, BufRead, Initializer, IoSliceMut, Read, Seek, SeekFrom, DE /// unwrapping the `BufReader` with [`BufReader::into_inner`] can also cause /// data loss. /// +// HACK(#78696): can't use `crate` for associated items /// [`TcpStream::read`]: super::super::super::net::TcpStream::read /// [`TcpStream`]: crate::net::TcpStream /// diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index a1face6443ae6..067ed6ba7ff50 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -59,6 +59,7 @@ use crate::io::{ /// together by the buffer and will all be written out in one system call when /// the `stream` is flushed. /// +// HACK(#78696): can't use `crate` for associated items /// [`TcpStream::write`]: super::super::super::net::TcpStream::write /// [`TcpStream`]: crate::net::TcpStream /// [`flush`]: BufWriter::flush From 0af959d3a23a98e163b26fa577e4c34f3e67726d Mon Sep 17 00:00:00 2001 From: ankushduacodes Date: Fri, 6 Nov 2020 09:25:58 +0530 Subject: [PATCH 20/24] Fixing Spelling Typos --- compiler/rustc_mir/src/transform/check_unsafety.rs | 2 +- compiler/rustc_typeck/src/check/pat.rs | 2 +- src/test/ui/error-codes/E0027.stderr | 4 ++-- src/test/ui/structs/struct-field-cfg.stderr | 2 +- src/test/ui/structs/struct-pat-derived-error.stderr | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_unsafety.rs b/compiler/rustc_mir/src/transform/check_unsafety.rs index 3d68b862df2d0..acec3e8f82f43 100644 --- a/compiler/rustc_mir/src/transform/check_unsafety.rs +++ b/compiler/rustc_mir/src/transform/check_unsafety.rs @@ -693,7 +693,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { // should only issue a warning for the sake of backwards compatibility. // // The solution those 2 expectations is to always take the minimum of both lints. - // This prevent any new errors (unless both lints are explicitely set to `deny`). + // This prevent any new errors (unless both lints are explicitly set to `deny`). let lint = if tcx.lint_level_at_node(SAFE_PACKED_BORROWS, lint_root).0 <= tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, lint_root).0 { diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 53bc2069b76ce..f76f42dea1e03 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1500,7 +1500,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.span_suggestion( sp, &format!( - "if you don't care about {} missing field{}, you can explicitely ignore {}", + "if you don't care about {} missing field{}, you can explicitly ignore {}", if len == 1 { "this" } else { "these" }, if len == 1 { "" } else { "s" }, if len == 1 { "it" } else { "them" }, diff --git a/src/test/ui/error-codes/E0027.stderr b/src/test/ui/error-codes/E0027.stderr index c09f1ff1f2a8c..cf0ff6311483c 100644 --- a/src/test/ui/error-codes/E0027.stderr +++ b/src/test/ui/error-codes/E0027.stderr @@ -8,7 +8,7 @@ help: include the missing field in the pattern | LL | Dog { age: x, name } => {} | ^^^^^^ -help: if you don't care about this missing field, you can explicitely ignore it +help: if you don't care about this missing field, you can explicitly ignore it | LL | Dog { age: x, .. } => {} | ^^^^ @@ -23,7 +23,7 @@ help: include the missing fields in the pattern | LL | Dog { name, age } => {} | ^^^^^^^^^^^^^ -help: if you don't care about these missing fields, you can explicitely ignore them +help: if you don't care about these missing fields, you can explicitly ignore them | LL | Dog { .. } => {} | ^^^^^^ diff --git a/src/test/ui/structs/struct-field-cfg.stderr b/src/test/ui/structs/struct-field-cfg.stderr index b913b929079c6..740ea3829dc51 100644 --- a/src/test/ui/structs/struct-field-cfg.stderr +++ b/src/test/ui/structs/struct-field-cfg.stderr @@ -22,7 +22,7 @@ help: include the missing field in the pattern | LL | let Foo { present } = foo; | ^^^^^^^^^^^ -help: if you don't care about this missing field, you can explicitely ignore it +help: if you don't care about this missing field, you can explicitly ignore it | LL | let Foo { .. } = foo; | ^^^^^^ diff --git a/src/test/ui/structs/struct-pat-derived-error.stderr b/src/test/ui/structs/struct-pat-derived-error.stderr index f3e9ce76f1e2a..921d060faa38b 100644 --- a/src/test/ui/structs/struct-pat-derived-error.stderr +++ b/src/test/ui/structs/struct-pat-derived-error.stderr @@ -20,7 +20,7 @@ help: include the missing fields in the pattern | LL | let A { x, y, b, c } = self.d; | ^^^^^^ -help: if you don't care about these missing fields, you can explicitely ignore them +help: if you don't care about these missing fields, you can explicitly ignore them | LL | let A { x, y, .. } = self.d; | ^^^^ From f197da655ffe5df52dc5bf19ead9067c8439700c Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Tue, 3 Nov 2020 22:55:49 +0900 Subject: [PATCH 21/24] fix shellcheck error of SC2148 --- compiler/rustc_codegen_cranelift/scripts/config.sh | 1 + src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh | 1 + src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh | 1 + src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh | 1 + src/ci/docker/host-x86_64/dist-various-1/install-mips-musl.sh | 1 + src/ci/docker/host-x86_64/dist-various-1/install-mipsel-musl.sh | 1 + src/ci/docker/host-x86_64/dist-various-2/shared.sh | 1 + src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh | 1 + src/ci/docker/scripts/android-base-apt-get.sh | 1 + src/ci/docker/scripts/android-ndk.sh | 1 + src/ci/docker/scripts/android-sdk.sh | 1 + src/ci/docker/scripts/cross-apt-packages.sh | 1 + src/ci/docker/scripts/crosstool-ng-1.24.sh | 1 + src/ci/docker/scripts/crosstool-ng.sh | 1 + src/ci/docker/scripts/emscripten.sh | 1 + src/ci/docker/scripts/make3.sh | 1 + src/ci/docker/scripts/musl-toolchain.sh | 1 + src/ci/docker/scripts/musl.sh | 1 + src/ci/docker/scripts/rustbuild-setup.sh | 1 + src/ci/docker/scripts/sccache.sh | 1 + src/test/run-make/thumb-none-qemu/script.sh | 1 + src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh | 1 + 22 files changed, 22 insertions(+) diff --git a/compiler/rustc_codegen_cranelift/scripts/config.sh b/compiler/rustc_codegen_cranelift/scripts/config.sh index af181f4f72439..6120a550a27a1 100644 --- a/compiler/rustc_codegen_cranelift/scripts/config.sh +++ b/compiler/rustc_codegen_cranelift/scripts/config.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash set -e unamestr=`uname` diff --git a/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh b/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh index b873569278914..4b207031df8ac 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh @@ -1,3 +1,4 @@ +#!/bin/sh hide_output() { set +x on_err=" diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh b/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh index b873569278914..4b207031df8ac 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh @@ -1,3 +1,4 @@ +#!/bin/sh hide_output() { set +x on_err=" diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh b/src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh index fb067a79a5c85..3a40f6cddb369 100644 --- a/src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux/crosstool-ng.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex # Mirrored from https://github.com/crosstool-ng/crosstool-ng/archive/crosstool-ng-1.24.0.tar.gz diff --git a/src/ci/docker/host-x86_64/dist-various-1/install-mips-musl.sh b/src/ci/docker/host-x86_64/dist-various-1/install-mips-musl.sh index 9584258d23403..abab18093469c 100755 --- a/src/ci/docker/host-x86_64/dist-various-1/install-mips-musl.sh +++ b/src/ci/docker/host-x86_64/dist-various-1/install-mips-musl.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex mkdir /usr/local/mips-linux-musl diff --git a/src/ci/docker/host-x86_64/dist-various-1/install-mipsel-musl.sh b/src/ci/docker/host-x86_64/dist-various-1/install-mipsel-musl.sh index 50a8e554b1675..779acb2d84116 100755 --- a/src/ci/docker/host-x86_64/dist-various-1/install-mipsel-musl.sh +++ b/src/ci/docker/host-x86_64/dist-various-1/install-mipsel-musl.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex mkdir /usr/local/mipsel-linux-musl diff --git a/src/ci/docker/host-x86_64/dist-various-2/shared.sh b/src/ci/docker/host-x86_64/dist-various-2/shared.sh index 7abace65b9c03..267d8b79cc28b 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/shared.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/shared.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash hide_output() { { set +x; } 2>/dev/null on_err=" diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh index b873569278914..4b207031df8ac 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh @@ -1,3 +1,4 @@ +#!/bin/sh hide_output() { set +x on_err=" diff --git a/src/ci/docker/scripts/android-base-apt-get.sh b/src/ci/docker/scripts/android-base-apt-get.sh index 1795b1696d323..f1761f80643ba 100644 --- a/src/ci/docker/scripts/android-base-apt-get.sh +++ b/src/ci/docker/scripts/android-base-apt-get.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex apt-get update diff --git a/src/ci/docker/scripts/android-ndk.sh b/src/ci/docker/scripts/android-ndk.sh index dafcb3cb7a719..ba70c62ea3081 100644 --- a/src/ci/docker/scripts/android-ndk.sh +++ b/src/ci/docker/scripts/android-ndk.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex URL=https://dl.google.com/android/repository diff --git a/src/ci/docker/scripts/android-sdk.sh b/src/ci/docker/scripts/android-sdk.sh index e35be697a8df0..23360d309515e 100755 --- a/src/ci/docker/scripts/android-sdk.sh +++ b/src/ci/docker/scripts/android-sdk.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex export ANDROID_HOME=/android/sdk diff --git a/src/ci/docker/scripts/cross-apt-packages.sh b/src/ci/docker/scripts/cross-apt-packages.sh index 2de376443ad56..57cb6d5cda86d 100644 --- a/src/ci/docker/scripts/cross-apt-packages.sh +++ b/src/ci/docker/scripts/cross-apt-packages.sh @@ -1,3 +1,4 @@ +#!/bin/sh apt-get update && apt-get install -y --no-install-recommends \ automake \ bison \ diff --git a/src/ci/docker/scripts/crosstool-ng-1.24.sh b/src/ci/docker/scripts/crosstool-ng-1.24.sh index fb067a79a5c85..3a40f6cddb369 100644 --- a/src/ci/docker/scripts/crosstool-ng-1.24.sh +++ b/src/ci/docker/scripts/crosstool-ng-1.24.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex # Mirrored from https://github.com/crosstool-ng/crosstool-ng/archive/crosstool-ng-1.24.0.tar.gz diff --git a/src/ci/docker/scripts/crosstool-ng.sh b/src/ci/docker/scripts/crosstool-ng.sh index 2773e687ebe6f..1d0c28c8e5824 100644 --- a/src/ci/docker/scripts/crosstool-ng.sh +++ b/src/ci/docker/scripts/crosstool-ng.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex url="https://github.com/crosstool-ng/crosstool-ng/archive/crosstool-ng-1.22.0.tar.gz" diff --git a/src/ci/docker/scripts/emscripten.sh b/src/ci/docker/scripts/emscripten.sh index 9481ee95399db..61596a1ca30f4 100644 --- a/src/ci/docker/scripts/emscripten.sh +++ b/src/ci/docker/scripts/emscripten.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex hide_output() { diff --git a/src/ci/docker/scripts/make3.sh b/src/ci/docker/scripts/make3.sh index 47cb4158229d3..283700d06f6cc 100644 --- a/src/ci/docker/scripts/make3.sh +++ b/src/ci/docker/scripts/make3.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex curl -f https://ftp.gnu.org/gnu/make/make-3.81.tar.gz | tar xzf - diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index c56338a4f9562..e83367db35bd0 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -1,3 +1,4 @@ +#!/bin/sh # This script runs `musl-cross-make` to prepare C toolchain (Binutils, GCC, musl itself) # and builds static libunwind that we distribute for static target. # diff --git a/src/ci/docker/scripts/musl.sh b/src/ci/docker/scripts/musl.sh index 58393a5719a10..c5d6cdeba0327 100644 --- a/src/ci/docker/scripts/musl.sh +++ b/src/ci/docker/scripts/musl.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex hide_output() { diff --git a/src/ci/docker/scripts/rustbuild-setup.sh b/src/ci/docker/scripts/rustbuild-setup.sh index 94d7e600eacd2..baf2a68687196 100644 --- a/src/ci/docker/scripts/rustbuild-setup.sh +++ b/src/ci/docker/scripts/rustbuild-setup.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex groupadd -r rustbuild && useradd -m -r -g rustbuild rustbuild diff --git a/src/ci/docker/scripts/sccache.sh b/src/ci/docker/scripts/sccache.sh index cebba57344bfd..292b3c1d5627a 100644 --- a/src/ci/docker/scripts/sccache.sh +++ b/src/ci/docker/scripts/sccache.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -ex case "$(uname -m)" in diff --git a/src/test/run-make/thumb-none-qemu/script.sh b/src/test/run-make/thumb-none-qemu/script.sh index 045d02a8ed25d..a8aa72af1845b 100644 --- a/src/test/run-make/thumb-none-qemu/script.sh +++ b/src/test/run-make/thumb-none-qemu/script.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -exuo pipefail CRATE=example diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh index ec93c98016078..54645e9e257c9 100644 --- a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh +++ b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh @@ -1,3 +1,4 @@ +#!/bin/sh set -exuo pipefail function build { From ce4c124292cfa310d05c2fc48e162df1417c8a2c Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Mon, 2 Nov 2020 21:58:43 +0900 Subject: [PATCH 22/24] fix shellcheck error of SC1008 --- src/ci/shared.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ci/shared.sh b/src/ci/shared.sh index c93d4774e3992..3c196c9478cf8 100644 --- a/src/ci/shared.sh +++ b/src/ci/shared.sh @@ -1,4 +1,5 @@ #!/bin/false +# shellcheck shell=bash # This file is intended to be sourced with `. shared.sh` or # `source shared.sh`, hence the invalid shebang and not being From a1af001a551f382a1962276640e4455b40f7936b Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Mon, 2 Nov 2020 21:17:52 +0900 Subject: [PATCH 23/24] fix shellcheck error of SC2068 --- compiler/rustc_codegen_cranelift/scripts/cargo.sh | 4 ++-- compiler/rustc_codegen_cranelift/test.sh | 4 ++-- .../disabled/dist-x86_64-dragonfly/build-toolchain.sh | 2 +- .../host-x86_64/disabled/dist-x86_64-haiku/build-toolchain.sh | 2 +- .../docker/host-x86_64/dist-aarch64-linux/build-toolchains.sh | 2 +- src/ci/docker/host-x86_64/dist-arm-linux/build-toolchains.sh | 2 +- .../docker/host-x86_64/dist-armhf-linux/build-toolchains.sh | 2 +- .../docker/host-x86_64/dist-armv7-linux/build-toolchains.sh | 2 +- .../host-x86_64/dist-powerpc-linux/build-powerpc-toolchain.sh | 2 +- src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh | 2 +- src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh | 2 +- .../docker/host-x86_64/dist-riscv64-linux/build-toolchains.sh | 2 +- .../host-x86_64/dist-s390x-linux/build-s390x-toolchain.sh | 2 +- src/ci/docker/host-x86_64/dist-various-1/build-rumprun.sh | 2 +- src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh | 2 +- .../host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh | 2 +- src/ci/docker/scripts/emscripten.sh | 2 +- src/ci/docker/scripts/freebsd-toolchain.sh | 2 +- src/ci/docker/scripts/musl-toolchain.sh | 2 +- src/ci/docker/scripts/musl.sh | 4 ++-- src/ci/init_repo.sh | 2 +- 21 files changed, 24 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/scripts/cargo.sh b/compiler/rustc_codegen_cranelift/scripts/cargo.sh index e63daa40f3540..947b4a28798f2 100755 --- a/compiler/rustc_codegen_cranelift/scripts/cargo.sh +++ b/compiler/rustc_codegen_cranelift/scripts/cargo.sh @@ -10,7 +10,7 @@ cmd=$1 shift || true if [[ "$cmd" = "jit" ]]; then -cargo +${TOOLCHAIN} rustc $@ -- --jit +cargo +${TOOLCHAIN} rustc "$@" -- --jit else -cargo +${TOOLCHAIN} $cmd $@ +cargo +${TOOLCHAIN} $cmd "$@" fi diff --git a/compiler/rustc_codegen_cranelift/test.sh b/compiler/rustc_codegen_cranelift/test.sh index 3cdd4119d794c..c6c4956e48174 100755 --- a/compiler/rustc_codegen_cranelift/test.sh +++ b/compiler/rustc_codegen_cranelift/test.sh @@ -3,13 +3,13 @@ set -e export RUSTFLAGS="-Zrun_dsymutil=no" -./build.sh --without-sysroot $@ +./build.sh --without-sysroot "$@" rm -r target/out || true scripts/tests.sh no_sysroot -./build.sh $@ +./build.sh "$@" scripts/tests.sh base_sysroot scripts/tests.sh extended_sysroot diff --git a/src/ci/docker/host-x86_64/disabled/dist-x86_64-dragonfly/build-toolchain.sh b/src/ci/docker/host-x86_64/disabled/dist-x86_64-dragonfly/build-toolchain.sh index 112d747fe4ed6..409bca45c94dd 100755 --- a/src/ci/docker/host-x86_64/disabled/dist-x86_64-dragonfly/build-toolchain.sh +++ b/src/ci/docker/host-x86_64/disabled/dist-x86_64-dragonfly/build-toolchain.sh @@ -17,7 +17,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID set -x diff --git a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/build-toolchain.sh b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/build-toolchain.sh index faf30f36a20f9..189e537ecaeed 100755 --- a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/build-toolchain.sh +++ b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/build-toolchain.sh @@ -22,7 +22,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID set -x diff --git a/src/ci/docker/host-x86_64/dist-aarch64-linux/build-toolchains.sh b/src/ci/docker/host-x86_64/dist-aarch64-linux/build-toolchains.sh index 390ba1a1ddf9c..f15a7081612d8 100755 --- a/src/ci/docker/host-x86_64/dist-aarch64-linux/build-toolchains.sh +++ b/src/ci/docker/host-x86_64/dist-aarch64-linux/build-toolchains.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-arm-linux/build-toolchains.sh b/src/ci/docker/host-x86_64/dist-arm-linux/build-toolchains.sh index 2e790b77a96c2..3fd882521999a 100755 --- a/src/ci/docker/host-x86_64/dist-arm-linux/build-toolchains.sh +++ b/src/ci/docker/host-x86_64/dist-arm-linux/build-toolchains.sh @@ -12,7 +12,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-armhf-linux/build-toolchains.sh b/src/ci/docker/host-x86_64/dist-armhf-linux/build-toolchains.sh index a01c2e0eb0a7c..f425efd6057c6 100755 --- a/src/ci/docker/host-x86_64/dist-armhf-linux/build-toolchains.sh +++ b/src/ci/docker/host-x86_64/dist-armhf-linux/build-toolchains.sh @@ -12,7 +12,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-armv7-linux/build-toolchains.sh b/src/ci/docker/host-x86_64/dist-armv7-linux/build-toolchains.sh index 28f8ba2437b3d..17dda2dbd1680 100755 --- a/src/ci/docker/host-x86_64/dist-armv7-linux/build-toolchains.sh +++ b/src/ci/docker/host-x86_64/dist-armv7-linux/build-toolchains.sh @@ -12,7 +12,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-powerpc-linux/build-powerpc-toolchain.sh b/src/ci/docker/host-x86_64/dist-powerpc-linux/build-powerpc-toolchain.sh index d2e39834d6e96..264d0764f2957 100755 --- a/src/ci/docker/host-x86_64/dist-powerpc-linux/build-powerpc-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-powerpc-linux/build-powerpc-toolchain.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh b/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh index 4b207031df8ac..dc86dddd464f2 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-powerpc64-linux/shared.sh @@ -9,7 +9,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID set -x diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh b/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh index 4b207031df8ac..dc86dddd464f2 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux/shared.sh @@ -9,7 +9,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID set -x diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux/build-toolchains.sh b/src/ci/docker/host-x86_64/dist-riscv64-linux/build-toolchains.sh index 6a7c022d01a5d..a7025b2b7545e 100755 --- a/src/ci/docker/host-x86_64/dist-riscv64-linux/build-toolchains.sh +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux/build-toolchains.sh @@ -12,7 +12,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-s390x-linux/build-s390x-toolchain.sh b/src/ci/docker/host-x86_64/dist-s390x-linux/build-s390x-toolchain.sh index df9529da8a162..6f8d6be842b8e 100755 --- a/src/ci/docker/host-x86_64/dist-s390x-linux/build-s390x-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-s390x-linux/build-s390x-toolchain.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/host-x86_64/dist-various-1/build-rumprun.sh b/src/ci/docker/host-x86_64/dist-various-1/build-rumprun.sh index 9c7aaef4f436f..103dbbe6fdaba 100755 --- a/src/ci/docker/host-x86_64/dist-various-1/build-rumprun.sh +++ b/src/ci/docker/host-x86_64/dist-various-1/build-rumprun.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID rm /tmp/build.log diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh index 4b207031df8ac..dc86dddd464f2 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/shared.sh @@ -9,7 +9,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID set -x diff --git a/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh b/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh index f8697c698b9fb..5dfa47b4eed74 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh @@ -13,7 +13,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log rm /tmp/build.log trap - ERR kill $PING_LOOP_PID diff --git a/src/ci/docker/scripts/emscripten.sh b/src/ci/docker/scripts/emscripten.sh index 61596a1ca30f4..56dc96283edc1 100644 --- a/src/ci/docker/scripts/emscripten.sh +++ b/src/ci/docker/scripts/emscripten.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID rm -f /tmp/build.log diff --git a/src/ci/docker/scripts/freebsd-toolchain.sh b/src/ci/docker/scripts/freebsd-toolchain.sh index b10263d5a268e..c7ff78ca90c9d 100755 --- a/src/ci/docker/scripts/freebsd-toolchain.sh +++ b/src/ci/docker/scripts/freebsd-toolchain.sh @@ -19,7 +19,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & local ping_loop_pid=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $ping_loop_pid set -x diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index e83367db35bd0..59fc921ec260d 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -20,7 +20,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID rm /tmp/build.log diff --git a/src/ci/docker/scripts/musl.sh b/src/ci/docker/scripts/musl.sh index c5d6cdeba0327..65e1595055942 100644 --- a/src/ci/docker/scripts/musl.sh +++ b/src/ci/docker/scripts/musl.sh @@ -11,7 +11,7 @@ exit 1 trap "$on_err" ERR bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & PING_LOOP_PID=$! - $@ &> /tmp/build.log + "$@" &> /tmp/build.log trap - ERR kill $PING_LOOP_PID rm /tmp/build.log @@ -33,7 +33,7 @@ if [ ! -d $MUSL ]; then fi cd $MUSL -./configure --enable-optimize --enable-debug --disable-shared --prefix=/musl-$TAG $@ +./configure --enable-optimize --enable-debug --disable-shared --prefix=/musl-$TAG "$@" if [ "$TAG" = "i586" -o "$TAG" = "i686" ]; then hide_output make -j$(nproc) AR=ar RANLIB=ranlib else diff --git a/src/ci/init_repo.sh b/src/ci/init_repo.sh index 92c6e546a3895..0fc09d0c8e2e9 100755 --- a/src/ci/init_repo.sh +++ b/src/ci/init_repo.sh @@ -53,7 +53,7 @@ modules=($modules) use_git="" urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)" urls=($urls) -for i in ${!modules[@]}; do +for i in "${!modules[@]}"; do module=${modules[$i]} if [[ " $included " = *" $module "* ]]; then commit="$(git ls-tree HEAD $module | awk '{print $3}')" From 5ea028ef7651e65a0c4ba7c67d010dfa36658b3e Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Tue, 3 Nov 2020 22:57:56 +0900 Subject: [PATCH 24/24] ignore shellcheck error SC2068 --- src/ci/init_repo.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ci/init_repo.sh b/src/ci/init_repo.sh index 0fc09d0c8e2e9..060b3079dad5f 100755 --- a/src/ci/init_repo.sh +++ b/src/ci/init_repo.sh @@ -53,7 +53,8 @@ modules=($modules) use_git="" urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)" urls=($urls) -for i in "${!modules[@]}"; do +# shellcheck disable=SC2068 +for i in ${!modules[@]}; do module=${modules[$i]} if [[ " $included " = *" $module "* ]]; then commit="$(git ls-tree HEAD $module | awk '{print $3}')"