Skip to content

Commit c18514d

Browse files
committed
Auto merge of rust-lang#109019 - matthiaskrgr:rollup-ihjntil, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#104363 (Make `unused_allocation` lint against `Box::new` too) - rust-lang#106633 (Stabilize `nonzero_min_max`) - rust-lang#106844 (allow negative numeric literals in `concat!`) - rust-lang#108071 (Implement goal caching with the new solver) - rust-lang#108542 (Force parentheses around `match` expression in binary expression) - rust-lang#108690 (Place size limits on query keys and values) - rust-lang#108708 (Prevent overflow through Arc::downgrade) - rust-lang#108739 (Prevent the `start_bx` basic block in codegen from having two `Builder`s at the same time) - rust-lang#108806 (Querify register_tools and post-expansion early lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf3c7f9 + ce22e7e commit c18514d

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

alloc/src/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl<T> Box<T> {
214214
#[inline(always)]
215215
#[stable(feature = "rust1", since = "1.0.0")]
216216
#[must_use]
217+
#[rustc_diagnostic_item = "box_new"]
217218
pub fn new(x: T) -> Self {
218219
#[rustc_box]
219220
Box::new(x)

alloc/src/sync.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ mod tests;
5151
///
5252
/// Going above this limit will abort your program (although not
5353
/// necessarily) at _exactly_ `MAX_REFCOUNT + 1` references.
54+
/// Trying to go above it might call a `panic` (if not actually going above it).
55+
///
56+
/// This is a global invariant, and also applies when using a compare-exchange loop.
57+
///
58+
/// See comment in `Arc::clone`.
5459
const MAX_REFCOUNT: usize = (isize::MAX) as usize;
5560

61+
/// The error in case either counter reaches above `MAX_REFCOUNT`, and we can `panic` safely.
62+
const INTERNAL_OVERFLOW_ERROR: &str = "Arc counter overflow";
63+
5664
#[cfg(not(sanitize = "thread"))]
5765
macro_rules! acquire {
5866
($x:expr) => {
@@ -1104,6 +1112,9 @@ impl<T: ?Sized> Arc<T> {
11041112
continue;
11051113
}
11061114

1115+
// We can't allow the refcount to increase much past `MAX_REFCOUNT`.
1116+
assert!(cur <= MAX_REFCOUNT, "{}", INTERNAL_OVERFLOW_ERROR);
1117+
11071118
// NOTE: this code currently ignores the possibility of overflow
11081119
// into usize::MAX; in general both Rc and Arc need to be adjusted
11091120
// to deal with overflow.
@@ -1519,6 +1530,11 @@ impl<T: ?Sized> Clone for Arc<T> {
15191530
// the worst already happened and we actually do overflow the `usize` counter. However, that
15201531
// requires the counter to grow from `isize::MAX` to `usize::MAX` between the increment
15211532
// above and the `abort` below, which seems exceedingly unlikely.
1533+
//
1534+
// This is a global invariant, and also applies when using a compare-exchange loop to increment
1535+
// counters in other methods.
1536+
// Otherwise, the counter could be brought to an almost-overflow using a compare-exchange loop,
1537+
// and then overflow using a few `fetch_add`s.
15221538
if old_size > MAX_REFCOUNT {
15231539
abort();
15241540
}
@@ -2180,9 +2196,7 @@ impl<T: ?Sized> Weak<T> {
21802196
return None;
21812197
}
21822198
// See comments in `Arc::clone` for why we do this (for `mem::forget`).
2183-
if n > MAX_REFCOUNT {
2184-
abort();
2185-
}
2199+
assert!(n <= MAX_REFCOUNT, "{}", INTERNAL_OVERFLOW_ERROR);
21862200
Some(n + 1)
21872201
})
21882202
.ok()

alloc/src/tests.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use core::any::Any;
44
use core::clone::Clone;
55
use core::convert::TryInto;
66
use core::ops::Deref;
7-
use core::result::Result::{Err, Ok};
87

98
use std::boxed::Box;
109

@@ -15,32 +14,25 @@ fn test_owned_clone() {
1514
assert!(a == b);
1615
}
1716

18-
#[derive(PartialEq, Eq)]
17+
#[derive(Debug, PartialEq, Eq)]
1918
struct Test;
2019

2120
#[test]
2221
fn any_move() {
2322
let a = Box::new(8) as Box<dyn Any>;
2423
let b = Box::new(Test) as Box<dyn Any>;
2524

26-
match a.downcast::<i32>() {
27-
Ok(a) => {
28-
assert!(a == Box::new(8));
29-
}
30-
Err(..) => panic!(),
31-
}
32-
match b.downcast::<Test>() {
33-
Ok(a) => {
34-
assert!(a == Box::new(Test));
35-
}
36-
Err(..) => panic!(),
37-
}
25+
let a: Box<i32> = a.downcast::<i32>().unwrap();
26+
assert_eq!(*a, 8);
27+
28+
let b: Box<Test> = b.downcast::<Test>().unwrap();
29+
assert_eq!(*b, Test);
3830

3931
let a = Box::new(8) as Box<dyn Any>;
4032
let b = Box::new(Test) as Box<dyn Any>;
4133

42-
assert!(a.downcast::<Box<Test>>().is_err());
43-
assert!(b.downcast::<Box<i32>>().is_err());
34+
assert!(a.downcast::<Box<i32>>().is_err());
35+
assert!(b.downcast::<Box<Test>>().is_err());
4436
}
4537

4638
#[test]

core/src/num/nonzero.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +1147,10 @@ macro_rules! nonzero_min_max_unsigned {
11471147
/// # Examples
11481148
///
11491149
/// ```
1150-
/// #![feature(nonzero_min_max)]
1151-
///
11521150
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
11531151
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
11541152
/// ```
1155-
#[unstable(feature = "nonzero_min_max", issue = "89065")]
1153+
#[stable(feature = "nonzero_min_max", since = "CURRENT_RUSTC_VERSION")]
11561154
pub const MIN: Self = Self::new(1).unwrap();
11571155

11581156
/// The largest value that can be represented by this non-zero
@@ -1162,12 +1160,10 @@ macro_rules! nonzero_min_max_unsigned {
11621160
/// # Examples
11631161
///
11641162
/// ```
1165-
/// #![feature(nonzero_min_max)]
1166-
///
11671163
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
11681164
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
11691165
/// ```
1170-
#[unstable(feature = "nonzero_min_max", issue = "89065")]
1166+
#[stable(feature = "nonzero_min_max", since = "CURRENT_RUSTC_VERSION")]
11711167
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
11721168
}
11731169
)+
@@ -1189,12 +1185,10 @@ macro_rules! nonzero_min_max_signed {
11891185
/// # Examples
11901186
///
11911187
/// ```
1192-
/// #![feature(nonzero_min_max)]
1193-
///
11941188
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
11951189
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), ", stringify!($Int), "::MIN);")]
11961190
/// ```
1197-
#[unstable(feature = "nonzero_min_max", issue = "89065")]
1191+
#[stable(feature = "nonzero_min_max", since = "CURRENT_RUSTC_VERSION")]
11981192
pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
11991193

12001194
/// The largest value that can be represented by this non-zero
@@ -1208,12 +1202,10 @@ macro_rules! nonzero_min_max_signed {
12081202
/// # Examples
12091203
///
12101204
/// ```
1211-
/// #![feature(nonzero_min_max)]
1212-
///
12131205
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
12141206
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
12151207
/// ```
1216-
#[unstable(feature = "nonzero_min_max", issue = "89065")]
1208+
#[stable(feature = "nonzero_min_max", since = "CURRENT_RUSTC_VERSION")]
12171209
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
12181210
}
12191211
)+

0 commit comments

Comments
 (0)