Skip to content

Commit 0446743

Browse files
committed
Auto merge of rust-lang#89813 - the8472:rollup-f1f99mb, r=the8472
Rollup of 7 pull requests Successful merges: - rust-lang#89778 (Add #[must_use] to as_type conversions) - rust-lang#89784 (Remove built-in query cache_hit tracking) - rust-lang#89796 (Add #[must_use] to non-mutating verb methods) - rust-lang#89797 (Add #[must_use] to is_condition tests) - rust-lang#89799 (fix minor spelling error in Poll::ready docs) - rust-lang#89800 (Update books) - rust-lang#89809 (Remap ssa RealPredicate to llvm RealPredicate) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9475e60 + 6cdf803 commit 0446743

File tree

35 files changed

+152
-57
lines changed

35 files changed

+152
-57
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
828828
}
829829

830830
fn fcmp(&mut self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
831+
let op = llvm::RealPredicate::from_generic(op);
831832
unsafe { llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, UNNAMED) }
832833
}
833834

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+27
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,33 @@ pub enum RealPredicate {
223223
RealPredicateTrue = 15,
224224
}
225225

226+
impl RealPredicate {
227+
pub fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self {
228+
match realp {
229+
rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse => {
230+
RealPredicate::RealPredicateFalse
231+
}
232+
rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
233+
rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
234+
rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
235+
rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
236+
rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
237+
rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
238+
rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
239+
rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
240+
rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
241+
rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
242+
rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
243+
rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
244+
rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
245+
rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
246+
rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue => {
247+
RealPredicate::RealPredicateTrue
248+
}
249+
}
250+
}
251+
}
252+
226253
/// LLVMTypeKind
227254
#[derive(Copy, Clone, PartialEq, Debug)]
228255
#[repr(C)]

compiler/rustc_query_impl/src/stats.rs

-27
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
55

66
use std::any::type_name;
77
use std::mem;
8-
#[cfg(debug_assertions)]
9-
use std::sync::atomic::Ordering;
108

119
trait KeyStats {
1210
fn key_stats(&self, stats: &mut QueryStats);
@@ -27,7 +25,6 @@ impl KeyStats for DefId {
2725
#[derive(Clone)]
2826
struct QueryStats {
2927
name: &'static str,
30-
cache_hits: usize,
3128
key_size: usize,
3229
key_type: &'static str,
3330
value_size: usize,
@@ -42,10 +39,6 @@ where
4239
{
4340
let mut stats = QueryStats {
4441
name,
45-
#[cfg(debug_assertions)]
46-
cache_hits: map.cache_hits.load(Ordering::Relaxed),
47-
#[cfg(not(debug_assertions))]
48-
cache_hits: 0,
4942
key_size: mem::size_of::<C::Key>(),
5043
key_type: type_name::<C::Key>(),
5144
value_size: mem::size_of::<C::Value>(),
@@ -63,12 +56,6 @@ where
6356
pub fn print_stats(tcx: TyCtxt<'_>) {
6457
let queries = query_stats(tcx);
6558

66-
if cfg!(debug_assertions) {
67-
let hits: usize = queries.iter().map(|s| s.cache_hits).sum();
68-
let results: usize = queries.iter().map(|s| s.entry_count).sum();
69-
eprintln!("\nQuery cache hit rate: {}", hits as f64 / (hits + results) as f64);
70-
}
71-
7259
let mut query_key_sizes = queries.clone();
7360
query_key_sizes.sort_by_key(|q| q.key_size);
7461
eprintln!("\nLarge query keys:");
@@ -83,20 +70,6 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
8370
eprintln!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type);
8471
}
8572

86-
if cfg!(debug_assertions) {
87-
let mut query_cache_hits = queries.clone();
88-
query_cache_hits.sort_by_key(|q| q.cache_hits);
89-
eprintln!("\nQuery cache hits:");
90-
for q in query_cache_hits.iter().rev() {
91-
eprintln!(
92-
" {} - {} ({}%)",
93-
q.name,
94-
q.cache_hits,
95-
q.cache_hits as f64 / (q.cache_hits + q.entry_count) as f64
96-
);
97-
}
98-
}
99-
10073
let mut query_value_count = queries.clone();
10174
query_value_count.sort_by_key(|q| q.entry_count);
10275
eprintln!("\nQuery value count:");

compiler/rustc_query_system/src/query/plumbing.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,15 @@ use std::hash::{Hash, Hasher};
2626
use std::mem;
2727
use std::num::NonZeroU32;
2828
use std::ptr;
29-
#[cfg(debug_assertions)]
30-
use std::sync::atomic::{AtomicUsize, Ordering};
3129

3230
pub struct QueryCacheStore<C: QueryCache> {
3331
cache: C,
3432
shards: Sharded<C::Sharded>,
35-
#[cfg(debug_assertions)]
36-
pub cache_hits: AtomicUsize,
3733
}
3834

3935
impl<C: QueryCache + Default> Default for QueryCacheStore<C> {
4036
fn default() -> Self {
41-
Self {
42-
cache: C::default(),
43-
shards: Default::default(),
44-
#[cfg(debug_assertions)]
45-
cache_hits: AtomicUsize::new(0),
46-
}
37+
Self { cache: C::default(), shards: Default::default() }
4738
}
4839
}
4940

@@ -377,10 +368,6 @@ where
377368
if unlikely!(tcx.profiler().enabled()) {
378369
tcx.profiler().query_cache_hit(index.into());
379370
}
380-
#[cfg(debug_assertions)]
381-
{
382-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
383-
}
384371
tcx.dep_graph().read_index(index);
385372
on_hit(value)
386373
})
@@ -429,10 +416,6 @@ where
429416
if unlikely!(tcx.dep_context().profiler().enabled()) {
430417
tcx.dep_context().profiler().query_cache_hit(index.into());
431418
}
432-
#[cfg(debug_assertions)]
433-
{
434-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
435-
}
436419
query_blocked_prof_timer.finish_with_query_invocation_id(index.into());
437420

438421
(v, Some(index))
@@ -705,10 +688,6 @@ where
705688
if unlikely!(tcx.dep_context().profiler().enabled()) {
706689
tcx.dep_context().profiler().query_cache_hit(index.into());
707690
}
708-
#[cfg(debug_assertions)]
709-
{
710-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
711-
}
712691
});
713692

714693
let lookup = match cached {

library/alloc/src/collections/binary_heap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ impl<T> BinaryHeap<T> {
10091009
///
10101010
/// io::sink().write(heap.as_slice()).unwrap();
10111011
/// ```
1012+
#[must_use]
10121013
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
10131014
pub fn as_slice(&self) -> &[T] {
10141015
self.data.as_slice()

library/alloc/src/collections/linked_list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ impl<'a, T> CursorMut<'a, T> {
13851385
/// The lifetime of the returned `Cursor` is bound to that of the
13861386
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
13871387
/// `CursorMut` is frozen for the lifetime of the `Cursor`.
1388+
#[must_use]
13881389
#[unstable(feature = "linked_list_cursors", issue = "58533")]
13891390
pub fn as_cursor(&self) -> Cursor<'_, T> {
13901391
Cursor { list: self.list, current: self.current, index: self.index }

library/alloc/src/rc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,7 @@ impl<T: ?Sized> Weak<T> {
20932093
/// ```
20942094
///
20952095
/// [`null`]: ptr::null
2096+
#[must_use]
20962097
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
20972098
pub fn as_ptr(&self) -> *const T {
20982099
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
@@ -2229,6 +2230,8 @@ impl<T: ?Sized> Weak<T> {
22292230
///
22302231
/// assert!(weak_five.upgrade().is_none());
22312232
/// ```
2233+
#[must_use = "this returns a new `Rc`, \
2234+
without modifying the original weak pointer"]
22322235
#[stable(feature = "rc_weak", since = "1.4.0")]
22332236
pub fn upgrade(&self) -> Option<Rc<T>> {
22342237
let inner = self.inner()?;

library/alloc/src/string.rs

+5
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ impl String {
803803
/// assert_eq!("foo", s.as_str());
804804
/// ```
805805
#[inline]
806+
#[must_use]
806807
#[stable(feature = "string_as_str", since = "1.7.0")]
807808
pub fn as_str(&self) -> &str {
808809
self
@@ -823,6 +824,7 @@ impl String {
823824
/// assert_eq!("FOOBAR", s_mut_str);
824825
/// ```
825826
#[inline]
827+
#[must_use]
826828
#[stable(feature = "string_as_str", since = "1.7.0")]
827829
pub fn as_mut_str(&mut self) -> &mut str {
828830
self
@@ -1163,6 +1165,7 @@ impl String {
11631165
/// assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());
11641166
/// ```
11651167
#[inline]
1168+
#[must_use]
11661169
#[stable(feature = "rust1", since = "1.0.0")]
11671170
pub fn as_bytes(&self) -> &[u8] {
11681171
&self.vec
@@ -1766,6 +1769,7 @@ impl FromUtf8Error {
17661769
///
17671770
/// assert_eq!(&[0, 159], value.unwrap_err().as_bytes());
17681771
/// ```
1772+
#[must_use]
17691773
#[stable(feature = "from_utf8_error_as_bytes", since = "1.26.0")]
17701774
pub fn as_bytes(&self) -> &[u8] {
17711775
&self.bytes[..]
@@ -2782,6 +2786,7 @@ impl<'a> Drain<'a> {
27822786
/// let _ = drain.next().unwrap();
27832787
/// assert_eq!(drain.as_str(), "bc");
27842788
/// ```
2789+
#[must_use]
27852790
#[stable(feature = "string_drain_as_str", since = "1.55.0")]
27862791
pub fn as_str(&self) -> &str {
27872792
self.iter.as_str()

library/alloc/src/sync.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ macro_rules! acquire {
146146
/// use std::sync::Arc;
147147
///
148148
/// let my_arc = Arc::new(());
149-
/// Arc::downgrade(&my_arc);
149+
/// let my_weak = Arc::downgrade(&my_arc);
150150
/// ```
151151
///
152152
/// `Arc<T>`'s implementations of traits like `Clone` may also be called using
@@ -827,6 +827,7 @@ impl<T: ?Sized> Arc<T> {
827827
/// assert_eq!(x_ptr, Arc::as_ptr(&y));
828828
/// assert_eq!(unsafe { &*x_ptr }, "hello");
829829
/// ```
830+
#[must_use]
830831
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
831832
pub fn as_ptr(this: &Self) -> *const T {
832833
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
@@ -897,6 +898,8 @@ impl<T: ?Sized> Arc<T> {
897898
///
898899
/// let weak_five = Arc::downgrade(&five);
899900
/// ```
901+
#[must_use = "this returns a new `Weak` pointer, \
902+
without modifying the original `Arc`"]
900903
#[stable(feature = "arc_weak", since = "1.4.0")]
901904
pub fn downgrade(this: &Self) -> Weak<T> {
902905
// This Relaxed is OK because we're checking the value in the CAS
@@ -1724,6 +1727,7 @@ impl<T: ?Sized> Weak<T> {
17241727
/// ```
17251728
///
17261729
/// [`null`]: core::ptr::null "ptr::null"
1730+
#[must_use]
17271731
#[stable(feature = "weak_into_raw", since = "1.45.0")]
17281732
pub fn as_ptr(&self) -> *const T {
17291733
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
@@ -1861,6 +1865,8 @@ impl<T: ?Sized> Weak<T> {
18611865
///
18621866
/// assert!(weak_five.upgrade().is_none());
18631867
/// ```
1868+
#[must_use = "this returns a new `Arc`, \
1869+
without modifying the original weak pointer"]
18641870
#[stable(feature = "arc_weak", since = "1.4.0")]
18651871
pub fn upgrade(&self) -> Option<Arc<T>> {
18661872
// We use a CAS loop to increment the strong count instead of a

library/alloc/src/vec/drain.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
5252
/// let _ = drain.next().unwrap();
5353
/// assert_eq!(drain.as_slice(), &['b', 'c']);
5454
/// ```
55+
#[must_use]
5556
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
5657
pub fn as_slice(&self) -> &[T] {
5758
self.iter.as_slice()

library/core/src/alloc/layout.rs

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ impl Layout {
112112
/// The minimum byte alignment for a memory block of this layout.
113113
#[stable(feature = "alloc_layout", since = "1.28.0")]
114114
#[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")]
115+
#[must_use = "this returns the minimum alignment, \
116+
without modifying the layout"]
115117
#[inline]
116118
pub const fn align(&self) -> usize {
117119
self.align_.get()
@@ -229,6 +231,8 @@ impl Layout {
229231
/// satisfy this constraint is to ensure `align <= self.align()`.
230232
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
231233
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
234+
#[must_use = "this returns the padding needed, \
235+
without modifying the `Layout`"]
232236
#[inline]
233237
pub const fn padding_needed_for(&self, align: usize) -> usize {
234238
let len = self.size();
@@ -262,6 +266,8 @@ impl Layout {
262266
/// This is equivalent to adding the result of `padding_needed_for`
263267
/// to the layout's current size.
264268
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
269+
#[must_use = "this returns a new `Layout`, \
270+
without modifying the original"]
265271
#[inline]
266272
pub fn pad_to_align(&self) -> Layout {
267273
let pad = self.padding_needed_for(self.align());

library/core/src/fmt/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ impl<'a> Arguments<'a> {
491491
/// ```
492492
#[stable(feature = "fmt_as_str", since = "1.52.0")]
493493
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "none")]
494+
#[must_use]
494495
#[inline]
495496
pub const fn as_str(&self) -> Option<&'static str> {
496497
match (self.pieces, self.args) {

library/core/src/option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ impl<T> Option<T> {
657657
///
658658
/// [&]: reference "shared reference"
659659
#[inline]
660+
#[must_use]
660661
#[stable(feature = "pin", since = "1.33.0")]
661662
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
662663
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
@@ -668,6 +669,7 @@ impl<T> Option<T> {
668669
///
669670
/// [&mut]: reference "mutable reference"
670671
#[inline]
672+
#[must_use]
671673
#[stable(feature = "pin", since = "1.33.0")]
672674
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
673675
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.

0 commit comments

Comments
 (0)