Skip to content

Commit e810f75

Browse files
committed
Auto merge of #97548 - Dylan-DPC:rollup-9x0va1d, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #97494 (Use Box::new() instead of box syntax in library tests) - #97499 (Remove "sys isn't exported yet" phrase) - #97504 (Ensure source file present when calculating max line number) - #97519 (Re-add help_on_error for download-ci-llvm) - #97531 (Note pattern mismatch coming from `for` loop desugaring) - #97545 (Reword safety comments in core/hash/sip.rs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 946a88a + a352ad5 commit e810f75

File tree

36 files changed

+219
-105
lines changed

36 files changed

+219
-105
lines changed

compiler/rustc_errors/src/emitter.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1261,16 +1261,23 @@ impl EmitterWriter {
12611261
return 0;
12621262
};
12631263

1264+
let will_be_emitted = |span: Span| {
1265+
!span.is_dummy() && {
1266+
let file = sm.lookup_source_file(span.hi());
1267+
sm.ensure_source_file_source_present(file)
1268+
}
1269+
};
1270+
12641271
let mut max = 0;
12651272
for primary_span in msp.primary_spans() {
1266-
if !primary_span.is_dummy() {
1273+
if will_be_emitted(*primary_span) {
12671274
let hi = sm.lookup_char_pos(primary_span.hi());
12681275
max = (hi.line).max(max);
12691276
}
12701277
}
12711278
if !self.short_message {
12721279
for span_label in msp.span_labels() {
1273-
if !span_label.span.is_dummy() {
1280+
if will_be_emitted(span_label.span) {
12741281
let hi = sm.lookup_char_pos(span_label.span.hi());
12751282
max = (hi.line).max(max);
12761283
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
609609
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
610610
{
611611
// don't show type `_`
612-
err.span_label(span, format!("this expression has type `{}`", ty));
612+
if span.desugaring_kind() == Some(DesugaringKind::ForLoop)
613+
&& let ty::Adt(def, substs) = ty.kind()
614+
&& Some(def.did()) == self.tcx.get_diagnostic_item(sym::Option)
615+
{
616+
err.span_label(span, format!("this is an iterator with items of type `{}`", substs.type_at(0)));
617+
} else {
618+
err.span_label(span, format!("this expression has type `{}`", ty));
619+
}
613620
}
614621
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found
615622
&& ty.is_box() && ty.boxed_ty() == found

library/alloc/src/alloc/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ fn allocate_zeroed() {
2525
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
2626
fn alloc_owned_small(b: &mut Bencher) {
2727
b.iter(|| {
28-
let _: Box<_> = box 10;
28+
let _: Box<_> = Box::new(10);
2929
})
3030
}

library/alloc/src/collections/binary_heap/tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,22 @@ fn test_push() {
183183

184184
#[test]
185185
fn test_push_unique() {
186-
let mut heap = BinaryHeap::<Box<_>>::from(vec![box 2, box 4, box 9]);
186+
let mut heap = BinaryHeap::<Box<_>>::from(vec![Box::new(2), Box::new(4), Box::new(9)]);
187187
assert_eq!(heap.len(), 3);
188188
assert!(**heap.peek().unwrap() == 9);
189-
heap.push(box 11);
189+
heap.push(Box::new(11));
190190
assert_eq!(heap.len(), 4);
191191
assert!(**heap.peek().unwrap() == 11);
192-
heap.push(box 5);
192+
heap.push(Box::new(5));
193193
assert_eq!(heap.len(), 5);
194194
assert!(**heap.peek().unwrap() == 11);
195-
heap.push(box 27);
195+
heap.push(Box::new(27));
196196
assert_eq!(heap.len(), 6);
197197
assert!(**heap.peek().unwrap() == 27);
198-
heap.push(box 3);
198+
heap.push(Box::new(3));
199199
assert_eq!(heap.len(), 7);
200200
assert!(**heap.peek().unwrap() == 27);
201-
heap.push(box 103);
201+
heap.push(Box::new(103));
202202
assert_eq!(heap.len(), 8);
203203
assert!(**heap.peek().unwrap() == 103);
204204
}

library/alloc/src/collections/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ impl<T> LinkedList<T> {
791791
/// ```
792792
#[stable(feature = "rust1", since = "1.0.0")]
793793
pub fn push_front(&mut self, elt: T) {
794-
self.push_front_node(box Node::new(elt));
794+
self.push_front_node(Box::new(Node::new(elt)));
795795
}
796796

797797
/// Removes the first element and returns it, or `None` if the list is
@@ -834,7 +834,7 @@ impl<T> LinkedList<T> {
834834
/// ```
835835
#[stable(feature = "rust1", since = "1.0.0")]
836836
pub fn push_back(&mut self, elt: T) {
837-
self.push_back_node(box Node::new(elt));
837+
self.push_back_node(Box::new(Node::new(elt)));
838838
}
839839

840840
/// Removes the last element from a list and returns it, or `None` if

library/alloc/src/collections/linked_list/tests.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ fn test_basic() {
1212
assert_eq!(m.pop_front(), None);
1313
assert_eq!(m.pop_back(), None);
1414
assert_eq!(m.pop_front(), None);
15-
m.push_front(box 1);
16-
assert_eq!(m.pop_front(), Some(box 1));
17-
m.push_back(box 2);
18-
m.push_back(box 3);
15+
m.push_front(Box::new(1));
16+
assert_eq!(m.pop_front(), Some(Box::new(1)));
17+
m.push_back(Box::new(2));
18+
m.push_back(Box::new(3));
1919
assert_eq!(m.len(), 2);
20-
assert_eq!(m.pop_front(), Some(box 2));
21-
assert_eq!(m.pop_front(), Some(box 3));
20+
assert_eq!(m.pop_front(), Some(Box::new(2)));
21+
assert_eq!(m.pop_front(), Some(Box::new(3)));
2222
assert_eq!(m.len(), 0);
2323
assert_eq!(m.pop_front(), None);
24-
m.push_back(box 1);
25-
m.push_back(box 3);
26-
m.push_back(box 5);
27-
m.push_back(box 7);
28-
assert_eq!(m.pop_front(), Some(box 1));
24+
m.push_back(Box::new(1));
25+
m.push_back(Box::new(3));
26+
m.push_back(Box::new(5));
27+
m.push_back(Box::new(7));
28+
assert_eq!(m.pop_front(), Some(Box::new(1)));
2929

3030
let mut n = LinkedList::new();
3131
n.push_front(2);

library/alloc/src/rc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ impl<T> Rc<T> {
369369
// if the weak pointer is stored inside the strong one.
370370
unsafe {
371371
Self::from_inner(
372-
Box::leak(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value }).into(),
372+
Box::leak(Box::new(RcBox { strong: Cell::new(1), weak: Cell::new(1), value }))
373+
.into(),
373374
)
374375
}
375376
}
@@ -433,11 +434,11 @@ impl<T> Rc<T> {
433434
{
434435
// Construct the inner in the "uninitialized" state with a single
435436
// weak reference.
436-
let uninit_ptr: NonNull<_> = Box::leak(box RcBox {
437+
let uninit_ptr: NonNull<_> = Box::leak(Box::new(RcBox {
437438
strong: Cell::new(0),
438439
weak: Cell::new(1),
439440
value: mem::MaybeUninit::<T>::uninit(),
440-
})
441+
}))
441442
.into();
442443

443444
let init_ptr: NonNull<RcBox<T>> = uninit_ptr.cast();

library/alloc/src/rc/tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn test_simple_clone() {
3232

3333
#[test]
3434
fn test_destructor() {
35-
let x: Rc<Box<_>> = Rc::new(box 5);
35+
let x: Rc<Box<_>> = Rc::new(Box::new(5));
3636
assert_eq!(**x, 5);
3737
}
3838

@@ -153,7 +153,7 @@ fn try_unwrap() {
153153

154154
#[test]
155155
fn into_from_raw() {
156-
let x = Rc::new(box "hello");
156+
let x = Rc::new(Box::new("hello"));
157157
let y = x.clone();
158158

159159
let x_ptr = Rc::into_raw(x);
@@ -192,7 +192,7 @@ fn test_into_from_raw_unsized() {
192192

193193
#[test]
194194
fn into_from_weak_raw() {
195-
let x = Rc::new(box "hello");
195+
let x = Rc::new(Box::new("hello"));
196196
let y = Rc::downgrade(&x);
197197

198198
let y_ptr = Weak::into_raw(y);
@@ -409,7 +409,7 @@ fn test_clone_from_slice_panic() {
409409

410410
#[test]
411411
fn test_from_box() {
412-
let b: Box<u32> = box 123;
412+
let b: Box<u32> = Box::new(123);
413413
let r: Rc<u32> = Rc::from(b);
414414

415415
assert_eq!(*r, 123);
@@ -438,7 +438,7 @@ fn test_from_box_trait() {
438438
use std::fmt::Display;
439439
use std::string::ToString;
440440

441-
let b: Box<dyn Display> = box 123;
441+
let b: Box<dyn Display> = Box::new(123);
442442
let r: Rc<dyn Display> = Rc::from(b);
443443

444444
assert_eq!(r.to_string(), "123");
@@ -448,7 +448,7 @@ fn test_from_box_trait() {
448448
fn test_from_box_trait_zero_sized() {
449449
use std::fmt::Debug;
450450

451-
let b: Box<dyn Debug> = box ();
451+
let b: Box<dyn Debug> = Box::new(());
452452
let r: Rc<dyn Debug> = Rc::from(b);
453453

454454
assert_eq!(format!("{r:?}"), "()");

library/alloc/src/sync.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ impl<T> Arc<T> {
343343
pub fn new(data: T) -> Arc<T> {
344344
// Start the weak pointer count as 1 which is the weak pointer that's
345345
// held by all the strong pointers (kinda), see std/rc.rs for more info
346-
let x: Box<_> = box ArcInner {
346+
let x: Box<_> = Box::new(ArcInner {
347347
strong: atomic::AtomicUsize::new(1),
348348
weak: atomic::AtomicUsize::new(1),
349349
data,
350-
};
350+
});
351351
unsafe { Self::from_inner(Box::leak(x).into()) }
352352
}
353353

@@ -411,11 +411,11 @@ impl<T> Arc<T> {
411411
{
412412
// Construct the inner in the "uninitialized" state with a single
413413
// weak reference.
414-
let uninit_ptr: NonNull<_> = Box::leak(box ArcInner {
414+
let uninit_ptr: NonNull<_> = Box::leak(Box::new(ArcInner {
415415
strong: atomic::AtomicUsize::new(0),
416416
weak: atomic::AtomicUsize::new(1),
417417
data: mem::MaybeUninit::<T>::uninit(),
418-
})
418+
}))
419419
.into();
420420
let init_ptr: NonNull<ArcInner<T>> = uninit_ptr.cast();
421421

library/alloc/src/sync/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn try_unwrap() {
103103

104104
#[test]
105105
fn into_from_raw() {
106-
let x = Arc::new(box "hello");
106+
let x = Arc::new(Box::new("hello"));
107107
let y = x.clone();
108108

109109
let x_ptr = Arc::into_raw(x);
@@ -142,7 +142,7 @@ fn test_into_from_raw_unsized() {
142142

143143
#[test]
144144
fn into_from_weak_raw() {
145-
let x = Arc::new(box "hello");
145+
let x = Arc::new(Box::new("hello"));
146146
let y = Arc::downgrade(&x);
147147

148148
let y_ptr = Weak::into_raw(y);
@@ -467,7 +467,7 @@ fn test_clone_from_slice_panic() {
467467

468468
#[test]
469469
fn test_from_box() {
470-
let b: Box<u32> = box 123;
470+
let b: Box<u32> = Box::new(123);
471471
let r: Arc<u32> = Arc::from(b);
472472

473473
assert_eq!(*r, 123);
@@ -496,7 +496,7 @@ fn test_from_box_trait() {
496496
use std::fmt::Display;
497497
use std::string::ToString;
498498

499-
let b: Box<dyn Display> = box 123;
499+
let b: Box<dyn Display> = Box::new(123);
500500
let r: Arc<dyn Display> = Arc::from(b);
501501

502502
assert_eq!(r.to_string(), "123");
@@ -506,7 +506,7 @@ fn test_from_box_trait() {
506506
fn test_from_box_trait_zero_sized() {
507507
use std::fmt::Debug;
508508

509-
let b: Box<dyn Debug> = box ();
509+
let b: Box<dyn Debug> = Box::new(());
510510
let r: Arc<dyn Debug> = Arc::from(b);
511511

512512
assert_eq!(format!("{r:?}"), "()");

library/alloc/tests/slice.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ fn test_swap_remove_fail() {
268268
fn test_swap_remove_noncopyable() {
269269
// Tests that we don't accidentally run destructors twice.
270270
let mut v: Vec<Box<_>> = Vec::new();
271-
v.push(box 0);
272-
v.push(box 0);
273-
v.push(box 0);
271+
v.push(Box::new(0));
272+
v.push(Box::new(0));
273+
v.push(Box::new(0));
274274
let mut _e = v.swap_remove(0);
275275
assert_eq!(v.len(), 2);
276276
_e = v.swap_remove(1);
@@ -296,7 +296,7 @@ fn test_push() {
296296

297297
#[test]
298298
fn test_truncate() {
299-
let mut v: Vec<Box<_>> = vec![box 6, box 5, box 4];
299+
let mut v: Vec<Box<_>> = vec![Box::new(6), Box::new(5), Box::new(4)];
300300
v.truncate(1);
301301
let v = v;
302302
assert_eq!(v.len(), 1);
@@ -306,7 +306,7 @@ fn test_truncate() {
306306

307307
#[test]
308308
fn test_clear() {
309-
let mut v: Vec<Box<_>> = vec![box 6, box 5, box 4];
309+
let mut v: Vec<Box<_>> = vec![Box::new(6), Box::new(5), Box::new(4)];
310310
v.clear();
311311
assert_eq!(v.len(), 0);
312312
// If the unsafe block didn't drop things properly, we blow up here.
@@ -1516,14 +1516,14 @@ fn test_mut_last() {
15161516

15171517
#[test]
15181518
fn test_to_vec() {
1519-
let xs: Box<_> = box [1, 2, 3];
1519+
let xs: Box<_> = Box::new([1, 2, 3]);
15201520
let ys = xs.to_vec();
15211521
assert_eq!(ys, [1, 2, 3]);
15221522
}
15231523

15241524
#[test]
15251525
fn test_in_place_iterator_specialization() {
1526-
let src: Box<[usize]> = box [1, 2, 3];
1526+
let src: Box<[usize]> = Box::new([1, 2, 3]);
15271527
let src_ptr = src.as_ptr();
15281528
let sink: Box<_> = src.into_vec().into_iter().map(std::convert::identity).collect();
15291529
let sink_ptr = sink.as_ptr();

library/alloc/tests/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ fn test_clone() {
266266
#[test]
267267
fn test_clone_from() {
268268
let mut v = vec![];
269-
let three: Vec<Box<_>> = vec![box 1, box 2, box 3];
270-
let two: Vec<Box<_>> = vec![box 4, box 5];
269+
let three: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(3)];
270+
let two: Vec<Box<_>> = vec![Box::new(4), Box::new(5)];
271271
// zero, long
272272
v.clone_from(&three);
273273
assert_eq!(v, three);
@@ -407,11 +407,11 @@ fn test_dedup_by() {
407407

408408
#[test]
409409
fn test_dedup_unique() {
410-
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
410+
let mut v0: Vec<Box<_>> = vec![Box::new(1), Box::new(1), Box::new(2), Box::new(3)];
411411
v0.dedup();
412-
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
412+
let mut v1: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(2), Box::new(3)];
413413
v1.dedup();
414-
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
414+
let mut v2: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(3), Box::new(3)];
415415
v2.dedup();
416416
// If the boxed pointers were leaked or otherwise misused, valgrind
417417
// and/or rt should raise errors.

library/core/src/hash/sip.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ macro_rules! compress {
9696
/// `copy_nonoverlapping` to let the compiler generate the most efficient way
9797
/// to load it from a possibly unaligned address.
9898
///
99-
/// Unsafe because: unchecked indexing at i..i+size_of(int_ty)
99+
/// Safety: this performs unchecked indexing of `$buf` at
100+
/// `$i..$i+size_of::<$int_ty>()`, so that must be in-bounds.
100101
macro_rules! load_int_le {
101102
($buf:expr, $i:expr, $int_ty:ident) => {{
102103
debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
@@ -114,7 +115,8 @@ macro_rules! load_int_le {
114115
/// `copy_nonoverlapping` calls that occur (via `load_int_le!`) all have fixed
115116
/// sizes and avoid calling `memcpy`, which is good for speed.
116117
///
117-
/// Unsafe because: unchecked indexing at start..start+len
118+
/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
119+
/// that must be in-bounds.
118120
#[inline]
119121
unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
120122
debug_assert!(len < 8);

library/core/tests/any.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ fn any_referenced() {
2424

2525
#[test]
2626
fn any_owning() {
27-
let (a, b, c) =
28-
(box 5_usize as Box<dyn Any>, box TEST as Box<dyn Any>, box Test as Box<dyn Any>);
27+
let (a, b, c) = (
28+
Box::new(5_usize) as Box<dyn Any>,
29+
Box::new(TEST) as Box<dyn Any>,
30+
Box::new(Test) as Box<dyn Any>,
31+
);
2932

3033
assert!(a.is::<usize>());
3134
assert!(!b.is::<usize>());
@@ -58,7 +61,7 @@ fn any_downcast_ref() {
5861
#[test]
5962
fn any_downcast_mut() {
6063
let mut a = 5_usize;
61-
let mut b: Box<_> = box 7_usize;
64+
let mut b: Box<_> = Box::new(7_usize);
6265

6366
let a_r = &mut a as &mut dyn Any;
6467
let tmp: &mut usize = &mut *b;

0 commit comments

Comments
 (0)