From 6ff72045dee098e5a95f42c27b2f2cf167f0d52d Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Thu, 7 Oct 2021 17:58:52 -0500 Subject: [PATCH 1/8] bootstrap: don't use `--merges` to find commits Shallow clones can cause `git rev-list --merges` to miss merge commits. Omit it, because the most recent bors commit is almost always a merge commit. --- src/bootstrap/bootstrap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 05d7b0f611f72..49121869282d3 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -460,7 +460,7 @@ def download_toolchain(self, stage0=True, rustc_channel=None): # LLVM more often than necessary. # # This git command finds that commit SHA, looking for bors-authored - # merges that modified src/llvm-project or other relevant version + # commits that modified src/llvm-project or other relevant version # stamp files. # # This works even in a repository that has not yet initialized @@ -470,7 +470,7 @@ def download_toolchain(self, stage0=True, rustc_channel=None): ]).decode(sys.getdefaultencoding()).strip() llvm_sha = subprocess.check_output([ "git", "rev-list", "--author=bors@rust-lang.org", "-n1", - "--merges", "--first-parent", "HEAD", + "--first-parent", "HEAD", "--", "{}/src/llvm-project".format(top_level), "{}/src/bootstrap/download-ci-llvm-stamp".format(top_level), @@ -685,7 +685,7 @@ def maybe_download_ci_toolchain(self): # Only commits merged by bors will have CI artifacts. merge_base = [ "git", "rev-list", "--author=bors@rust-lang.org", "-n1", - "--merges", "--first-parent", "HEAD" + "--first-parent", "HEAD" ] commit = subprocess.check_output(merge_base, universal_newlines=True).strip() From 8e467421decb43a1f1adc353c4984df7eecd0af7 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Thu, 7 Oct 2021 18:20:38 -0500 Subject: [PATCH 2/8] bootstrap: add error messages re shallow history Exit with an error if we can't find a commit hash for downloading LLVM or rustc snapshots. --- src/bootstrap/bootstrap.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 49121869282d3..817850b1ec7eb 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -540,6 +540,12 @@ def _download_component_helper( unpack(tarball, tarball_suffix, self.bin_root(stage0), match=pattern, verbose=self.verbose) def _download_ci_llvm(self, llvm_sha, llvm_assertions): + if not llvm_sha: + print("error: could not find commit hash for downloading LLVM") + print("help: maybe your repository history is too shallow?") + print("help: consider disabling `download-ci-llvm`") + print("help: or fetch enough history to include one upstream commit") + exit(1) cache_prefix = "llvm-{}-{}".format(llvm_sha, llvm_assertions) cache_dst = os.path.join(self.build_dir, "cache") rustc_cache = os.path.join(cache_dst, cache_prefix) @@ -688,6 +694,12 @@ def maybe_download_ci_toolchain(self): "--first-parent", "HEAD" ] commit = subprocess.check_output(merge_base, universal_newlines=True).strip() + if not commit: + print("error: could not find commit hash for downloading rustc") + print("help: maybe your repository history is too shallow?") + print("help: consider disabling `download-rustc`") + print("help: or fetch enough history to include one upstream commit") + exit(1) # Warn if there were changes to the compiler or standard library since the ancestor commit. status = subprocess.call(["git", "diff-index", "--quiet", commit, "--", compiler, library]) From 58cc18c56b9d9422b376fdf5c51c20fb0e494e66 Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Sun, 10 Oct 2021 01:50:06 -0400 Subject: [PATCH 3/8] Add #[must_use] to alloc constructors --- library/alloc/src/boxed.rs | 12 ++++++++++++ library/alloc/src/collections/binary_heap.rs | 2 ++ library/alloc/src/collections/btree/map.rs | 1 + library/alloc/src/collections/btree/set.rs | 1 + library/alloc/src/collections/linked_list.rs | 1 + library/alloc/src/collections/vec_deque/mod.rs | 2 ++ library/alloc/src/raw_vec.rs | 3 +++ library/alloc/src/rc.rs | 6 ++++++ library/alloc/src/string.rs | 2 ++ library/alloc/src/sync.rs | 6 ++++++ library/alloc/src/vec/mod.rs | 2 ++ src/test/ui/weak-new-uninhabited-issue-48493.rs | 4 ++-- 12 files changed, 40 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 85f908a7f5c7b..bd4f52560421b 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -187,6 +187,7 @@ impl Box { #[cfg(not(no_global_oom_handling))] #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(x: T) -> Self { box x } @@ -211,6 +212,7 @@ impl Box { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] #[inline] pub fn new_uninit() -> Box> { Self::new_uninit_in(Global) @@ -237,6 +239,7 @@ impl Box { #[cfg(not(no_global_oom_handling))] #[inline] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed() -> Box> { Self::new_zeroed_in(Global) } @@ -245,6 +248,7 @@ impl Box { /// `x` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] #[stable(feature = "pin", since = "1.33.0")] + #[must_use] #[inline(always)] pub fn pin(x: T) -> Pin> { (box x).into() @@ -339,6 +343,7 @@ impl Box { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] + #[must_use] #[inline] pub fn new_in(x: T, alloc: A) -> Self { let mut boxed = Self::new_uninit_in(alloc); @@ -395,6 +400,7 @@ impl Box { /// ``` #[unstable(feature = "allocator_api", issue = "32838")] #[cfg(not(no_global_oom_handling))] + #[must_use] // #[unstable(feature = "new_uninit", issue = "63291")] pub fn new_uninit_in(alloc: A) -> Box, A> { let layout = Layout::new::>(); @@ -459,6 +465,7 @@ impl Box { #[unstable(feature = "allocator_api", issue = "32838")] #[cfg(not(no_global_oom_handling))] // #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed_in(alloc: A) -> Box, A> { let layout = Layout::new::>(); // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable. @@ -503,6 +510,7 @@ impl Box { /// `x` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] + #[must_use] #[inline(always)] pub fn pin_in(x: T, alloc: A) -> Pin where @@ -561,6 +569,7 @@ impl Box<[T]> { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit]> { unsafe { RawVec::with_capacity(len).into_box(len) } } @@ -585,6 +594,7 @@ impl Box<[T]> { /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit]> { unsafe { RawVec::with_capacity_zeroed(len).into_box(len) } } @@ -681,6 +691,7 @@ impl Box<[T], A> { #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) } } @@ -708,6 +719,7 @@ impl Box<[T], A> { #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) } } diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 4ed3702f7d224..01453e2710def 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -364,6 +364,7 @@ impl BinaryHeap { /// heap.push(4); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> BinaryHeap { BinaryHeap { data: vec![] } } @@ -383,6 +384,7 @@ impl BinaryHeap { /// heap.push(4); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn with_capacity(capacity: usize) -> BinaryHeap { BinaryHeap { data: Vec::with_capacity(capacity) } } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index d6032372168f1..7de80291cbbea 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -502,6 +502,7 @@ impl BTreeMap { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] + #[must_use] pub const fn new() -> BTreeMap { BTreeMap { root: None, length: 0 } } diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 16150ceeb62c1..2699f3fba397d 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -248,6 +248,7 @@ impl BTreeSet { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_btree_new", issue = "71835")] + #[must_use] pub const fn new() -> BTreeSet { BTreeSet { map: BTreeMap::new() } } diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index a769c558b4fa9..6dcba318c3598 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -417,6 +417,7 @@ impl LinkedList { #[inline] #[rustc_const_stable(feature = "const_linked_list_new", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub const fn new() -> Self { LinkedList { head: None, tail: None, len: 0, marker: PhantomData } } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e996784bbad28..09ae1f7eebd09 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -475,6 +475,7 @@ impl VecDeque { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> VecDeque { VecDeque::new_in(Global) } @@ -490,6 +491,7 @@ impl VecDeque { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn with_capacity(capacity: usize) -> VecDeque { Self::with_capacity_in(capacity, Global) } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index be21018512d8b..75dbd4678bb47 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -69,6 +69,7 @@ impl RawVec { /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a /// `RawVec` with capacity `usize::MAX`. Useful for implementing /// delayed allocation. + #[must_use] pub const fn new() -> Self { Self::new_in(Global) } @@ -87,6 +88,7 @@ impl RawVec { /// /// Aborts on OOM. #[cfg(not(no_global_oom_handling))] + #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> Self { Self::with_capacity_in(capacity, Global) @@ -94,6 +96,7 @@ impl RawVec { /// Like `with_capacity`, but guarantees the buffer is zeroed. #[cfg(not(no_global_oom_handling))] + #[must_use] #[inline] pub fn with_capacity_zeroed(capacity: usize) -> Self { Self::with_capacity_zeroed_in(capacity, Global) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 81e97805a7214..bde0dc754fb32 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -452,6 +452,7 @@ impl Rc { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit() -> Rc> { unsafe { Rc::from_ptr(Rc::allocate_for_layout( @@ -484,6 +485,7 @@ impl Rc { /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed() -> Rc> { unsafe { Rc::from_ptr(Rc::allocate_for_layout( @@ -587,6 +589,7 @@ impl Rc { /// `value` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] #[stable(feature = "pin", since = "1.33.0")] + #[must_use] pub fn pin(value: T) -> Pin> { unsafe { Pin::new_unchecked(Rc::new(value)) } } @@ -658,6 +661,7 @@ impl Rc<[T]> { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit]> { unsafe { Rc::from_ptr(Rc::allocate_for_slice(len)) } } @@ -684,6 +688,7 @@ impl Rc<[T]> { /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit]> { unsafe { Rc::from_ptr(Rc::allocate_for_layout( @@ -2044,6 +2049,7 @@ impl Weak { /// assert!(empty.upgrade().is_none()); /// ``` #[stable(feature = "downgraded_weak", since = "1.10.0")] + #[must_use] pub fn new() -> Weak { Weak { ptr: NonNull::new(usize::MAX as *mut RcBox).expect("MAX is not 0") } } diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d88b8e398985a..d1bc80cc0265e 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -378,6 +378,7 @@ impl String { #[inline] #[rustc_const_stable(feature = "const_string_new", since = "1.39.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub const fn new() -> String { String { vec: Vec::new() } } @@ -422,6 +423,7 @@ impl String { #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn with_capacity(capacity: usize) -> String { String { vec: Vec::with_capacity(capacity) } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 6e8da849e64cd..482c3eac5f970 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -448,6 +448,7 @@ impl Arc { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit() -> Arc> { unsafe { Arc::from_ptr(Arc::allocate_for_layout( @@ -480,6 +481,7 @@ impl Arc { /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed() -> Arc> { unsafe { Arc::from_ptr(Arc::allocate_for_layout( @@ -494,6 +496,7 @@ impl Arc { /// `data` will be pinned in memory and unable to be moved. #[cfg(not(no_global_oom_handling))] #[stable(feature = "pin", since = "1.33.0")] + #[must_use] pub fn pin(data: T) -> Pin> { unsafe { Pin::new_unchecked(Arc::new(data)) } } @@ -662,6 +665,7 @@ impl Arc<[T]> { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_uninit_slice(len: usize) -> Arc<[mem::MaybeUninit]> { unsafe { Arc::from_ptr(Arc::allocate_for_slice(len)) } } @@ -688,6 +692,7 @@ impl Arc<[T]> { /// [zeroed]: mem::MaybeUninit::zeroed #[cfg(not(no_global_oom_handling))] #[unstable(feature = "new_uninit", issue = "63291")] + #[must_use] pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit]> { unsafe { Arc::from_ptr(Arc::allocate_for_layout( @@ -1678,6 +1683,7 @@ impl Weak { /// assert!(empty.upgrade().is_none()); /// ``` #[stable(feature = "downgraded_weak", since = "1.10.0")] + #[must_use] pub fn new() -> Weak { Weak { ptr: NonNull::new(usize::MAX as *mut ArcInner).expect("MAX is not 0") } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 4f18a054a0d98..a12acb1a1c07f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -420,6 +420,7 @@ impl Vec { #[inline] #[rustc_const_stable(feature = "const_vec_new", since = "1.39.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub const fn new() -> Self { Vec { buf: RawVec::NEW, len: 0 } } @@ -464,6 +465,7 @@ impl Vec { #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn with_capacity(capacity: usize) -> Self { Self::with_capacity_in(capacity, Global) } diff --git a/src/test/ui/weak-new-uninhabited-issue-48493.rs b/src/test/ui/weak-new-uninhabited-issue-48493.rs index 644fc8c248375..39fbf3c9eb4e2 100644 --- a/src/test/ui/weak-new-uninhabited-issue-48493.rs +++ b/src/test/ui/weak-new-uninhabited-issue-48493.rs @@ -2,6 +2,6 @@ fn main() { enum Void {} - std::rc::Weak::::new(); - std::sync::Weak::::new(); + let _ = std::rc::Weak::::new(); + let _ = std::sync::Weak::::new(); } From 5b5c12be1cf2b2531a1cbf7097d2b5102cfaccd8 Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Sun, 10 Oct 2021 02:44:26 -0400 Subject: [PATCH 4/8] Add #[must_use] to core and std constructors --- library/core/src/alloc/layout.rs | 1 + library/core/src/hash/sip.rs | 2 ++ library/core/src/lazy.rs | 1 + library/core/src/mem/maybe_uninit.rs | 3 +++ library/core/src/num/nonzero.rs | 2 ++ library/core/src/sync/atomic.rs | 2 ++ library/core/src/task/wake.rs | 1 + library/core/src/time.rs | 1 + library/std/src/collections/hash/map.rs | 4 ++++ library/std/src/collections/hash/set.rs | 2 ++ library/std/src/ffi/os_str.rs | 2 ++ library/std/src/fs.rs | 2 ++ library/std/src/io/mod.rs | 1 + library/std/src/lazy.rs | 1 + library/std/src/net/addr.rs | 3 +++ library/std/src/net/ip.rs | 2 ++ library/std/src/os/unix/net/ancillary.rs | 1 + library/std/src/path.rs | 2 ++ library/std/src/sync/barrier.rs | 1 + library/std/src/sync/condvar.rs | 1 + library/std/src/sync/once.rs | 1 + 21 files changed, 36 insertions(+) diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index ccf6e420de7a9..c98aa38e3df29 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -119,6 +119,7 @@ impl Layout { /// Constructs a `Layout` suitable for holding a value of type `T`. #[stable(feature = "alloc_layout", since = "1.28.0")] #[rustc_const_stable(feature = "alloc_layout_const_new", since = "1.42.0")] + #[must_use] #[inline] pub const fn new() -> Self { let (size, align) = size_align::(); diff --git a/library/core/src/hash/sip.rs b/library/core/src/hash/sip.rs index 6178b0af137e8..b9443e30074b0 100644 --- a/library/core/src/hash/sip.rs +++ b/library/core/src/hash/sip.rs @@ -157,6 +157,7 @@ impl SipHasher { since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead" )] + #[must_use] pub fn new() -> SipHasher { SipHasher::new_with_keys(0, 0) } @@ -168,6 +169,7 @@ impl SipHasher { since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead" )] + #[must_use] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher { SipHasher(SipHasher24 { hasher: Hasher::new_with_keys(key0, key1) }) } diff --git a/library/core/src/lazy.rs b/library/core/src/lazy.rs index e6bea462fa99a..d109141216aef 100644 --- a/library/core/src/lazy.rs +++ b/library/core/src/lazy.rs @@ -83,6 +83,7 @@ impl From for OnceCell { impl OnceCell { /// Creates a new empty cell. #[unstable(feature = "once_cell", issue = "74465")] + #[must_use] pub const fn new() -> OnceCell { OnceCell { inner: UnsafeCell::new(None) } } diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 9c88a62336161..b9772eaa67813 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -312,6 +312,7 @@ impl MaybeUninit { /// ``` #[stable(feature = "maybe_uninit", since = "1.36.0")] #[rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0")] + #[must_use] #[inline(always)] #[rustc_diagnostic_item = "maybe_uninit_uninit"] pub const fn uninit() -> MaybeUninit { @@ -349,6 +350,7 @@ impl MaybeUninit { /// ``` #[unstable(feature = "maybe_uninit_uninit_array", issue = "none")] #[rustc_const_unstable(feature = "maybe_uninit_uninit_array", issue = "none")] + #[must_use] #[inline(always)] pub const fn uninit_array() -> [Self; LEN] { // SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid. @@ -391,6 +393,7 @@ impl MaybeUninit { /// // This is undefined behavior. ⚠️ /// ``` #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[must_use] #[inline] #[rustc_diagnostic_item = "maybe_uninit_zeroed"] pub fn zeroed() -> MaybeUninit { diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index e44597279baf2..5b50b13b23e37 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -50,6 +50,7 @@ macro_rules! nonzero_integers { /// The value must not be zero. #[$stability] #[$const_new_unchecked_stability] + #[must_use] #[inline] pub const unsafe fn new_unchecked(n: $Int) -> Self { // SAFETY: this is guaranteed to be safe by the caller. @@ -59,6 +60,7 @@ macro_rules! nonzero_integers { /// Creates a non-zero if the given value is not zero. #[$stability] #[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")] + #[must_use] #[inline] pub const fn new(n: $Int) -> Option { if n != 0 { diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index d9de37e9c5197..b07752116e514 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -290,6 +290,7 @@ impl AtomicBool { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_atomic_new", since = "1.24.0")] + #[must_use] pub const fn new(v: bool) -> AtomicBool { AtomicBool { v: UnsafeCell::new(v as u8) } } @@ -1392,6 +1393,7 @@ macro_rules! atomic_int { #[inline] #[$stable] #[$const_stable] + #[must_use] pub const fn new(v: $int_type) -> Self { Self {v: UnsafeCell::new(v)} } diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index b775e022a54b4..2b540716154a1 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -39,6 +39,7 @@ impl RawWaker { #[rustc_promotable] #[stable(feature = "futures_api", since = "1.36.0")] #[rustc_const_stable(feature = "futures_api", since = "1.36.0")] + #[must_use] pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker { RawWaker { data, vtable } } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index d1533b8d67a6b..d2757ef71213f 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -181,6 +181,7 @@ impl Duration { #[stable(feature = "duration", since = "1.3.0")] #[inline] #[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")] + #[must_use] pub const fn new(secs: u64, nanos: u32) -> Duration { let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) { Some(secs) => secs, diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 528bb1bf6e9f9..7fa2e3ed3f6ac 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -223,6 +223,7 @@ impl HashMap { /// let mut map: HashMap<&str, i32> = HashMap::new(); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> HashMap { Default::default() @@ -240,6 +241,7 @@ impl HashMap { /// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn with_capacity(capacity: usize) -> HashMap { HashMap::with_capacity_and_hasher(capacity, Default::default()) @@ -2891,6 +2893,7 @@ impl RandomState { #[inline] #[allow(deprecated)] // rand + #[must_use] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")] pub fn new() -> RandomState { // Historically this function did not cache keys from the OS and instead @@ -2943,6 +2946,7 @@ impl DefaultHasher { /// instances created through `new` or `default`. #[stable(feature = "hashmap_default_hasher", since = "1.13.0")] #[allow(deprecated)] + #[must_use] pub fn new() -> DefaultHasher { DefaultHasher(SipHasher13::new_with_keys(0, 0)) } diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index dcfe322095082..5804701892e6e 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -126,6 +126,7 @@ impl HashSet { /// let set: HashSet = HashSet::new(); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> HashSet { Default::default() @@ -144,6 +145,7 @@ impl HashSet { /// assert!(set.capacity() >= 10); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn with_capacity(capacity: usize) -> HashSet { HashSet { base: base::HashSet::with_capacity_and_hasher(capacity, Default::default()) } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c305519dd4461..e4ad6cba88046 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -119,6 +119,7 @@ impl OsString { /// let os_string = OsString::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn new() -> OsString { OsString { inner: Buf::from_string(String::new()) } @@ -199,6 +200,7 @@ impl OsString { /// assert_eq!(capacity, os_string.capacity()); /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] + #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> OsString { OsString { inner: Buf::with_capacity(capacity) } diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 726c855c4fd36..85d350729239c 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -744,6 +744,7 @@ impl OpenOptions { /// let file = options.read(true).open("foo.txt"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> Self { OpenOptions(fs_imp::OpenOptions::new()) } @@ -2184,6 +2185,7 @@ impl DirBuilder { /// let builder = DirBuilder::new(); /// ``` #[stable(feature = "dir_builder", since = "1.6.0")] + #[must_use] pub fn new() -> DirBuilder { DirBuilder { inner: fs_imp::DirBuilder::new(), recursive: false } } diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 8c71138aa231d..abe29ba0f7caa 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -1206,6 +1206,7 @@ impl<'a> IoSlice<'a> { /// /// Panics on Windows if the slice is larger than 4GB. #[stable(feature = "iovec", since = "1.36.0")] + #[must_use] #[inline] pub fn new(buf: &'a [u8]) -> IoSlice<'a> { IoSlice(sys::io::IoSlice::new(buf)) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index 5afdb799f0c74..d7450962359df 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -171,6 +171,7 @@ impl Eq for SyncOnceCell {} impl SyncOnceCell { /// Creates a new empty cell. #[unstable(feature = "once_cell", issue = "74465")] + #[must_use] pub const fn new() -> SyncOnceCell { SyncOnceCell { once: Once::new(), diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs index f4ebcd53a25f7..cd2007cc2cb42 100644 --- a/library/std/src/net/addr.rs +++ b/library/std/src/net/addr.rs @@ -131,6 +131,7 @@ impl SocketAddr { /// assert_eq!(socket.port(), 8080); /// ``` #[stable(feature = "ip_addr", since = "1.7.0")] + #[must_use] pub fn new(ip: IpAddr, port: u16) -> SocketAddr { match ip { IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), @@ -272,6 +273,7 @@ impl SocketAddrV4 { /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { SocketAddrV4 { inner: c::sockaddr_in { @@ -368,6 +370,7 @@ impl SocketAddrV6 { /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { SocketAddrV6 { inner: c::sockaddr_in6 { diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index c05a32742ba1e..99922eef61f10 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -442,6 +442,7 @@ impl Ipv4Addr { /// ``` #[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { // `s_addr` is stored as BE on all machine and the array is in BE order. @@ -1192,6 +1193,7 @@ impl Ipv6Addr { /// ``` #[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { let addr16 = [ diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index 1f9d42812ecc7..57bb61903c147 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -189,6 +189,7 @@ impl SocketCred { /// /// PID, UID and GID is set to 0. #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + #[must_use] pub fn new() -> SocketCred { SocketCred(libc::ucred { pid: 0, uid: 0, gid: 0 }) } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index a45ecf6ea8c63..c5476c3d5267b 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1145,6 +1145,7 @@ impl PathBuf { /// let path = PathBuf::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn new() -> PathBuf { PathBuf { inner: OsString::new() } @@ -1169,6 +1170,7 @@ impl PathBuf { /// /// [`with_capacity`]: OsString::with_capacity #[stable(feature = "path_buf_capacity", since = "1.44.0")] + #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> PathBuf { PathBuf { inner: OsString::with_capacity(capacity) } diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index a17b82f82e8c2..0e28a2d166f13 100644 --- a/library/std/src/sync/barrier.rs +++ b/library/std/src/sync/barrier.rs @@ -80,6 +80,7 @@ impl Barrier { /// let barrier = Barrier::new(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(n: usize) -> Barrier { Barrier { lock: Mutex::new(BarrierState { count: 0, generation_id: 0 }), diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index 00a4afc570519..d8aca9651b867 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -121,6 +121,7 @@ impl Condvar { /// let condvar = Condvar::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> Condvar { Condvar { inner: sys::Condvar::new() } } diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index a2e935a0cebc4..1710c0053934a 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -186,6 +186,7 @@ impl Once { #[inline] #[stable(feature = "once_new", since = "1.2.0")] #[rustc_const_stable(feature = "const_once_new", since = "1.32.0")] + #[must_use] pub const fn new() -> Once { Once { state_and_queue: AtomicUsize::new(INCOMPLETE), _marker: marker::PhantomData } } From 9e6e89af697dad4e4505111adef37733cdcbe47e Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 10 Oct 2021 19:59:36 +0100 Subject: [PATCH 5/8] Fix RUSTC_LOG handling Rustc was incorrectly reading the value of `RUSTC_LOG` as the environment vairable with the logging configuration, rather than the logging configuration itself. --- compiler/rustc_driver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 05c7e11cbc29a..9a57ec991444a 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -1259,7 +1259,7 @@ pub fn init_env_logger(env: &str) { }; let filter = match std::env::var(env) { - Ok(env) => EnvFilter::from_env(env), + Ok(env) => EnvFilter::new(env), _ => EnvFilter::default().add_directive(filter::Directive::from(LevelFilter::WARN)), }; From cf2bcd10ed28b169b8df74383c2a35a4ffbdcf40 Mon Sep 17 00:00:00 2001 From: John Kugelman Date: Sun, 10 Oct 2021 18:22:40 -0400 Subject: [PATCH 6/8] Add #[must_use] to from_value conversions --- library/alloc/src/str.rs | 1 + library/alloc/src/string.rs | 1 + library/core/src/alloc/layout.rs | 1 + library/core/src/char/convert.rs | 3 +++ library/core/src/char/methods.rs | 5 ++++- library/core/src/num/f32.rs | 4 ++++ library/core/src/num/f64.rs | 4 ++++ library/core/src/num/int_macros.rs | 5 +++++ library/core/src/num/saturating.rs | 2 ++ library/core/src/num/uint_macros.rs | 5 +++++ library/core/src/num/wrapping.rs | 2 ++ library/core/src/str/converts.rs | 2 ++ library/core/src/str/lossy.rs | 2 ++ library/core/src/task/wake.rs | 2 ++ library/core/src/time.rs | 6 ++++++ library/std/src/ffi/c_str.rs | 5 +++++ library/std/src/io/error.rs | 1 + 17 files changed, 50 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 2900d01d9bdae..ac7f230445656 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -595,6 +595,7 @@ impl str { /// assert_eq!("☺", &*smile); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] +#[must_use] #[inline] pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box { unsafe { Box::from_raw(Box::into_raw(v) as *mut str) } diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d88b8e398985a..0c383b8bdb6c6 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -761,6 +761,7 @@ impl String { /// assert_eq!("💖", sparkle_heart); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_utf8_unchecked(bytes: Vec) -> String { String { vec: bytes } diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index ccf6e420de7a9..8086dd357306e 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -94,6 +94,7 @@ impl Layout { /// [`Layout::from_size_align`]. #[stable(feature = "alloc_layout", since = "1.28.0")] #[rustc_const_stable(feature = "alloc_layout", since = "1.36.0")] + #[must_use] #[inline] pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self { // SAFETY: the caller must ensure that `align` is greater than zero. diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 7a0ec32cc61a9..72921414fb3f2 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -48,6 +48,7 @@ use super::MAX; /// assert_eq!(None, c); /// ``` #[doc(alias = "chr")] +#[must_use] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn from_u32(i: u32) -> Option { @@ -88,6 +89,7 @@ pub fn from_u32(i: u32) -> Option { /// assert_eq!('❤', c); /// ``` #[inline] +#[must_use] #[stable(feature = "char_from_unchecked", since = "1.5.0")] pub unsafe fn from_u32_unchecked(i: u32) -> char { // SAFETY: the caller must guarantee that `i` is a valid char value. @@ -319,6 +321,7 @@ impl fmt::Display for CharTryFromError { /// let c = char::from_digit(1, 37); /// ``` #[inline] +#[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn from_digit(num: u32, radix: u32) -> Option { if radix > 36 { diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index b3af1f1ffb592..07ac08f45c79f 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -136,6 +136,7 @@ impl char { /// assert_eq!(None, c); /// ``` #[stable(feature = "assoc_char_funcs", since = "1.52.0")] + #[must_use] #[inline] pub fn from_u32(i: u32) -> Option { super::convert::from_u32(i) @@ -177,6 +178,7 @@ impl char { /// assert_eq!('❤', c); /// ``` #[stable(feature = "assoc_char_funcs", since = "1.52.0")] + #[must_use] #[inline] pub unsafe fn from_u32_unchecked(i: u32) -> char { // SAFETY: the safety contract must be upheld by the caller. @@ -230,9 +232,10 @@ impl char { /// use std::char; /// /// // this panics - /// char::from_digit(1, 37); + /// let _c = char::from_digit(1, 37); /// ``` #[stable(feature = "assoc_char_funcs", since = "1.52.0")] + #[must_use] #[inline] pub fn from_digit(num: u32, radix: u32) -> Option { super::convert::from_digit(num, radix) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index c47a2e8b05c4b..fd82be33d1abd 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -786,6 +786,7 @@ impl f32 { /// ``` #[stable(feature = "float_bits_conv", since = "1.20.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_bits(v: u32) -> Self { // SAFETY: `u32` is a plain old datatype so we can always transmute from it @@ -864,6 +865,7 @@ impl f32 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_be_bytes(bytes: [u8; 4]) -> Self { Self::from_bits(u32::from_be_bytes(bytes)) @@ -879,6 +881,7 @@ impl f32 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_le_bytes(bytes: [u8; 4]) -> Self { Self::from_bits(u32::from_le_bytes(bytes)) @@ -905,6 +908,7 @@ impl f32 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self { Self::from_bits(u32::from_ne_bytes(bytes)) diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index cfcc08b9addeb..e7dec62c04ead 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -800,6 +800,7 @@ impl f64 { /// ``` #[stable(feature = "float_bits_conv", since = "1.20.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_bits(v: u64) -> Self { // SAFETY: `u64` is a plain old datatype so we can always transmute from it @@ -878,6 +879,7 @@ impl f64 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_be_bytes(bytes: [u8; 8]) -> Self { Self::from_bits(u64::from_be_bytes(bytes)) @@ -893,6 +895,7 @@ impl f64 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_le_bytes(bytes: [u8; 8]) -> Self { Self::from_bits(u64::from_le_bytes(bytes)) @@ -919,6 +922,7 @@ impl f64 { /// ``` #[stable(feature = "float_to_from_bytes", since = "1.40.0")] #[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")] + #[must_use] #[inline] pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self { Self::from_bits(u64::from_ne_bytes(bytes)) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 12dda61400f2a..7ef2d5c40034d 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -282,6 +282,7 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] + #[must_use] #[inline] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -313,6 +314,7 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")] + #[must_use] #[inline] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -2620,6 +2622,7 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -2650,6 +2653,7 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -2691,6 +2695,7 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute to them #[inline] diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index f6dd3603c4914..cf8cf79fe46e0 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -644,6 +644,7 @@ macro_rules! saturating_int_impl { /// } /// ``` #[inline] + #[must_use] #[unstable(feature = "saturating_int_impl", issue = "87920")] pub const fn from_be(x: Self) -> Self { Saturating(<$t>::from_be(x.0)) @@ -671,6 +672,7 @@ macro_rules! saturating_int_impl { /// } /// ``` #[inline] + #[must_use] #[unstable(feature = "saturating_int_impl", issue = "87920")] pub const fn from_le(x: Self) -> Self { Saturating(<$t>::from_le(x.0)) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 25cd582bb67d7..eb03be2a62ae9 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -285,6 +285,7 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] + #[must_use] #[inline(always)] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -317,6 +318,7 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] + #[must_use] #[inline(always)] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -2278,6 +2280,7 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] #[inline] pub const fn from_be_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_be(Self::from_ne_bytes(bytes)) @@ -2308,6 +2311,7 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] #[inline] pub const fn from_le_bytes(bytes: [u8; mem::size_of::()]) -> Self { Self::from_le(Self::from_ne_bytes(bytes)) @@ -2349,6 +2353,7 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_to_from_bytes", since = "1.32.0")] #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] + #[must_use] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute to them #[inline] diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index b078cdf5479d7..cca83661b7ea6 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -638,6 +638,7 @@ macro_rules! wrapping_int_impl { /// } /// ``` #[inline] + #[must_use] #[unstable(feature = "wrapping_int_impl", issue = "32463")] pub const fn from_be(x: Self) -> Self { Wrapping(<$t>::from_be(x.0)) @@ -665,6 +666,7 @@ macro_rules! wrapping_int_impl { /// } /// ``` #[inline] + #[must_use] #[unstable(feature = "wrapping_int_impl", issue = "32463")] pub const fn from_le(x: Self) -> Self { Wrapping(<$t>::from_le(x.0)) diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index da6ef1b6678c6..ed9f49f159611 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -155,6 +155,7 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { /// assert_eq!("💖", sparkle_heart); /// ``` #[inline] +#[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_from_utf8_unchecked", since = "1.55.0")] pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { @@ -181,6 +182,7 @@ pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { /// assert_eq!("💖", heart); /// ``` #[inline] +#[must_use] #[stable(feature = "str_mut_extras", since = "1.20.0")] pub unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str { // SAFETY: the caller must guarantee that the bytes `v` diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 720a35bbc8f2c..d3c9d21c3c756 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -12,10 +12,12 @@ pub struct Utf8Lossy { } impl Utf8Lossy { + #[must_use] pub fn from_str(s: &str) -> &Utf8Lossy { Utf8Lossy::from_bytes(s.as_bytes()) } + #[must_use] pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy { // SAFETY: Both use the same memory layout, and UTF-8 correctness isn't required. unsafe { mem::transmute(bytes) } diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index b775e022a54b4..e1bbdfaef8016 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -158,6 +158,7 @@ pub struct Context<'a> { impl<'a> Context<'a> { /// Create a new `Context` from a `&Waker`. #[stable(feature = "futures_api", since = "1.36.0")] + #[must_use] #[inline] pub fn from_waker(waker: &'a Waker) -> Self { Context { waker, _marker: PhantomData } @@ -251,6 +252,7 @@ impl Waker { /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld. /// Therefore this method is unsafe. #[inline] + #[must_use] #[stable(feature = "futures_api", since = "1.36.0")] pub unsafe fn from_raw(waker: RawWaker) -> Waker { Waker { waker } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index d1533b8d67a6b..d57c959820d8d 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -203,6 +203,7 @@ impl Duration { /// assert_eq!(0, duration.subsec_nanos()); /// ``` #[stable(feature = "duration", since = "1.3.0")] + #[must_use] #[inline] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_secs(secs: u64) -> Duration { @@ -222,6 +223,7 @@ impl Duration { /// assert_eq!(569_000_000, duration.subsec_nanos()); /// ``` #[stable(feature = "duration", since = "1.3.0")] + #[must_use] #[inline] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_millis(millis: u64) -> Duration { @@ -244,6 +246,7 @@ impl Duration { /// assert_eq!(2000, duration.subsec_nanos()); /// ``` #[stable(feature = "duration_from_micros", since = "1.27.0")] + #[must_use] #[inline] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_micros(micros: u64) -> Duration { @@ -266,6 +269,7 @@ impl Duration { /// assert_eq!(123, duration.subsec_nanos()); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] + #[must_use] #[inline] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_nanos(nanos: u64) -> Duration { @@ -692,6 +696,7 @@ impl Duration { /// assert_eq!(dur, Duration::new(2, 700_000_000)); /// ``` #[stable(feature = "duration_float", since = "1.38.0")] + #[must_use] #[inline] #[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")] pub const fn from_secs_f64(secs: f64) -> Duration { @@ -753,6 +758,7 @@ impl Duration { /// assert_eq!(dur, Duration::new(2, 700_000_000)); /// ``` #[stable(feature = "duration_float", since = "1.38.0")] + #[must_use] #[inline] #[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")] pub const fn from_secs_f32(secs: f32) -> Duration { diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index fe1f28f00c403..e290350993d73 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -425,6 +425,7 @@ impl CString { /// let c_string = CString::from_vec_unchecked(raw); /// } /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { v.reserve_exact(1); @@ -476,6 +477,7 @@ impl CString { /// let c_string = CString::from_raw(raw); /// } /// ``` + #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"] #[stable(feature = "cstr_memory", since = "1.4.0")] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { // SAFETY: This is called with a pointer that was obtained from a call @@ -701,6 +703,7 @@ impl CString { /// unsafe { CString::from_vec_unchecked(b"abc".to_vec()) } /// ); /// ``` + #[must_use] #[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")] pub unsafe fn from_vec_with_nul_unchecked(v: Vec) -> Self { Self { inner: v.into_boxed_slice() } @@ -1162,6 +1165,7 @@ impl CStr { /// } /// # } /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr { // SAFETY: The caller has provided a pointer that points to a valid C @@ -1244,6 +1248,7 @@ impl CStr { /// } /// ``` #[inline] + #[must_use] #[stable(feature = "cstr_from_bytes", since = "1.10.0")] #[rustc_const_unstable(feature = "const_cstr_unchecked", issue = "none")] pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr { diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 51666c0a3c7f1..57b5c28430f1e 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -473,6 +473,7 @@ impl Error { /// # } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn from_raw_os_error(code: i32) -> Error { Error { repr: Repr::Os(code) } From 687cc5d4a67bf059233b8a606befae83167f3a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 11 Oct 2021 10:01:39 +0300 Subject: [PATCH 7/8] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 4b7675fcc30d3..ed4b312fa777e 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 4b7675fcc30d3e2c05eafc68a5724db66b58142c +Subproject commit ed4b312fa777ebb39ba1348fe3df574c441a485e From 4bd7e965b23e979e6afbda5640f0bd68e9ed50ec Mon Sep 17 00:00:00 2001 From: Stefan Schindler Date: Mon, 11 Oct 2021 00:38:56 +0200 Subject: [PATCH 8/8] Cleanup .item-table CSS --- src/librustdoc/html/static/css/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index cea3452780e6f..962af66368d3b 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -772,7 +772,7 @@ h2.small-section-header > .anchor { .block a.current.crate { font-weight: 500; } .item-table { - display: table-row; + display: table; } .item-row { display: table-row;