Skip to content

Commit

Permalink
Auto merge of #97548 - Dylan-DPC:rollup-9x0va1d, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 30, 2022
2 parents 946a88a + a352ad5 commit e810f75
Show file tree
Hide file tree
Showing 36 changed files with 219 additions and 105 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,16 +1261,23 @@ impl EmitterWriter {
return 0;
};

let will_be_emitted = |span: Span| {
!span.is_dummy() && {
let file = sm.lookup_source_file(span.hi());
sm.ensure_source_file_source_present(file)
}
};

let mut max = 0;
for primary_span in msp.primary_spans() {
if !primary_span.is_dummy() {
if will_be_emitted(*primary_span) {
let hi = sm.lookup_char_pos(primary_span.hi());
max = (hi.line).max(max);
}
}
if !self.short_message {
for span_label in msp.span_labels() {
if !span_label.span.is_dummy() {
if will_be_emitted(span_label.span) {
let hi = sm.lookup_char_pos(span_label.span.hi());
max = (hi.line).max(max);
}
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
{
// don't show type `_`
err.span_label(span, format!("this expression has type `{}`", ty));
if span.desugaring_kind() == Some(DesugaringKind::ForLoop)
&& let ty::Adt(def, substs) = ty.kind()
&& Some(def.did()) == self.tcx.get_diagnostic_item(sym::Option)
{
err.span_label(span, format!("this is an iterator with items of type `{}`", substs.type_at(0)));
} else {
err.span_label(span, format!("this expression has type `{}`", ty));
}
}
if let Some(ty::error::ExpectedFound { found, .. }) = exp_found
&& ty.is_box() && ty.boxed_ty() == found
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/alloc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ fn allocate_zeroed() {
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
let _: Box<_> = box 10;
let _: Box<_> = Box::new(10);
})
}
12 changes: 6 additions & 6 deletions library/alloc/src/collections/binary_heap/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ fn test_push() {

#[test]
fn test_push_unique() {
let mut heap = BinaryHeap::<Box<_>>::from(vec![box 2, box 4, box 9]);
let mut heap = BinaryHeap::<Box<_>>::from(vec![Box::new(2), Box::new(4), Box::new(9)]);
assert_eq!(heap.len(), 3);
assert!(**heap.peek().unwrap() == 9);
heap.push(box 11);
heap.push(Box::new(11));
assert_eq!(heap.len(), 4);
assert!(**heap.peek().unwrap() == 11);
heap.push(box 5);
heap.push(Box::new(5));
assert_eq!(heap.len(), 5);
assert!(**heap.peek().unwrap() == 11);
heap.push(box 27);
heap.push(Box::new(27));
assert_eq!(heap.len(), 6);
assert!(**heap.peek().unwrap() == 27);
heap.push(box 3);
heap.push(Box::new(3));
assert_eq!(heap.len(), 7);
assert!(**heap.peek().unwrap() == 27);
heap.push(box 103);
heap.push(Box::new(103));
assert_eq!(heap.len(), 8);
assert!(**heap.peek().unwrap() == 103);
}
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl<T> LinkedList<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, elt: T) {
self.push_front_node(box Node::new(elt));
self.push_front_node(Box::new(Node::new(elt)));
}

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

/// Removes the last element from a list and returns it, or `None` if
Expand Down
22 changes: 11 additions & 11 deletions library/alloc/src/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ fn test_basic() {
assert_eq!(m.pop_front(), None);
assert_eq!(m.pop_back(), None);
assert_eq!(m.pop_front(), None);
m.push_front(box 1);
assert_eq!(m.pop_front(), Some(box 1));
m.push_back(box 2);
m.push_back(box 3);
m.push_front(Box::new(1));
assert_eq!(m.pop_front(), Some(Box::new(1)));
m.push_back(Box::new(2));
m.push_back(Box::new(3));
assert_eq!(m.len(), 2);
assert_eq!(m.pop_front(), Some(box 2));
assert_eq!(m.pop_front(), Some(box 3));
assert_eq!(m.pop_front(), Some(Box::new(2)));
assert_eq!(m.pop_front(), Some(Box::new(3)));
assert_eq!(m.len(), 0);
assert_eq!(m.pop_front(), None);
m.push_back(box 1);
m.push_back(box 3);
m.push_back(box 5);
m.push_back(box 7);
assert_eq!(m.pop_front(), Some(box 1));
m.push_back(Box::new(1));
m.push_back(Box::new(3));
m.push_back(Box::new(5));
m.push_back(Box::new(7));
assert_eq!(m.pop_front(), Some(Box::new(1)));

let mut n = LinkedList::new();
n.push_front(2);
Expand Down
7 changes: 4 additions & 3 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ impl<T> Rc<T> {
// if the weak pointer is stored inside the strong one.
unsafe {
Self::from_inner(
Box::leak(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value }).into(),
Box::leak(Box::new(RcBox { strong: Cell::new(1), weak: Cell::new(1), value }))
.into(),
)
}
}
Expand Down Expand Up @@ -433,11 +434,11 @@ impl<T> Rc<T> {
{
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box RcBox {
let uninit_ptr: NonNull<_> = Box::leak(Box::new(RcBox {
strong: Cell::new(0),
weak: Cell::new(1),
value: mem::MaybeUninit::<T>::uninit(),
})
}))
.into();

let init_ptr: NonNull<RcBox<T>> = uninit_ptr.cast();
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/rc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn test_simple_clone() {

#[test]
fn test_destructor() {
let x: Rc<Box<_>> = Rc::new(box 5);
let x: Rc<Box<_>> = Rc::new(Box::new(5));
assert_eq!(**x, 5);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ fn try_unwrap() {

#[test]
fn into_from_raw() {
let x = Rc::new(box "hello");
let x = Rc::new(Box::new("hello"));
let y = x.clone();

let x_ptr = Rc::into_raw(x);
Expand Down Expand Up @@ -192,7 +192,7 @@ fn test_into_from_raw_unsized() {

#[test]
fn into_from_weak_raw() {
let x = Rc::new(box "hello");
let x = Rc::new(Box::new("hello"));
let y = Rc::downgrade(&x);

let y_ptr = Weak::into_raw(y);
Expand Down Expand Up @@ -409,7 +409,7 @@ fn test_clone_from_slice_panic() {

#[test]
fn test_from_box() {
let b: Box<u32> = box 123;
let b: Box<u32> = Box::new(123);
let r: Rc<u32> = Rc::from(b);

assert_eq!(*r, 123);
Expand Down Expand Up @@ -438,7 +438,7 @@ fn test_from_box_trait() {
use std::fmt::Display;
use std::string::ToString;

let b: Box<dyn Display> = box 123;
let b: Box<dyn Display> = Box::new(123);
let r: Rc<dyn Display> = Rc::from(b);

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

let b: Box<dyn Debug> = box ();
let b: Box<dyn Debug> = Box::new(());
let r: Rc<dyn Debug> = Rc::from(b);

assert_eq!(format!("{r:?}"), "()");
Expand Down
8 changes: 4 additions & 4 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ impl<T> Arc<T> {
pub fn new(data: T) -> Arc<T> {
// Start the weak pointer count as 1 which is the weak pointer that's
// held by all the strong pointers (kinda), see std/rc.rs for more info
let x: Box<_> = box ArcInner {
let x: Box<_> = Box::new(ArcInner {
strong: atomic::AtomicUsize::new(1),
weak: atomic::AtomicUsize::new(1),
data,
};
});
unsafe { Self::from_inner(Box::leak(x).into()) }
}

Expand Down Expand Up @@ -411,11 +411,11 @@ impl<T> Arc<T> {
{
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box ArcInner {
let uninit_ptr: NonNull<_> = Box::leak(Box::new(ArcInner {
strong: atomic::AtomicUsize::new(0),
weak: atomic::AtomicUsize::new(1),
data: mem::MaybeUninit::<T>::uninit(),
})
}))
.into();
let init_ptr: NonNull<ArcInner<T>> = uninit_ptr.cast();

Expand Down
10 changes: 5 additions & 5 deletions library/alloc/src/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn try_unwrap() {

#[test]
fn into_from_raw() {
let x = Arc::new(box "hello");
let x = Arc::new(Box::new("hello"));
let y = x.clone();

let x_ptr = Arc::into_raw(x);
Expand Down Expand Up @@ -142,7 +142,7 @@ fn test_into_from_raw_unsized() {

#[test]
fn into_from_weak_raw() {
let x = Arc::new(box "hello");
let x = Arc::new(Box::new("hello"));
let y = Arc::downgrade(&x);

let y_ptr = Weak::into_raw(y);
Expand Down Expand Up @@ -467,7 +467,7 @@ fn test_clone_from_slice_panic() {

#[test]
fn test_from_box() {
let b: Box<u32> = box 123;
let b: Box<u32> = Box::new(123);
let r: Arc<u32> = Arc::from(b);

assert_eq!(*r, 123);
Expand Down Expand Up @@ -496,7 +496,7 @@ fn test_from_box_trait() {
use std::fmt::Display;
use std::string::ToString;

let b: Box<dyn Display> = box 123;
let b: Box<dyn Display> = Box::new(123);
let r: Arc<dyn Display> = Arc::from(b);

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

let b: Box<dyn Debug> = box ();
let b: Box<dyn Debug> = Box::new(());
let r: Arc<dyn Debug> = Arc::from(b);

assert_eq!(format!("{r:?}"), "()");
Expand Down
14 changes: 7 additions & 7 deletions library/alloc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ fn test_swap_remove_fail() {
fn test_swap_remove_noncopyable() {
// Tests that we don't accidentally run destructors twice.
let mut v: Vec<Box<_>> = Vec::new();
v.push(box 0);
v.push(box 0);
v.push(box 0);
v.push(Box::new(0));
v.push(Box::new(0));
v.push(Box::new(0));
let mut _e = v.swap_remove(0);
assert_eq!(v.len(), 2);
_e = v.swap_remove(1);
Expand All @@ -296,7 +296,7 @@ fn test_push() {

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

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

#[test]
fn test_to_vec() {
let xs: Box<_> = box [1, 2, 3];
let xs: Box<_> = Box::new([1, 2, 3]);
let ys = xs.to_vec();
assert_eq!(ys, [1, 2, 3]);
}

#[test]
fn test_in_place_iterator_specialization() {
let src: Box<[usize]> = box [1, 2, 3];
let src: Box<[usize]> = Box::new([1, 2, 3]);
let src_ptr = src.as_ptr();
let sink: Box<_> = src.into_vec().into_iter().map(std::convert::identity).collect();
let sink_ptr = sink.as_ptr();
Expand Down
10 changes: 5 additions & 5 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ fn test_clone() {
#[test]
fn test_clone_from() {
let mut v = vec![];
let three: Vec<Box<_>> = vec![box 1, box 2, box 3];
let two: Vec<Box<_>> = vec![box 4, box 5];
let three: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(3)];
let two: Vec<Box<_>> = vec![Box::new(4), Box::new(5)];
// zero, long
v.clone_from(&three);
assert_eq!(v, three);
Expand Down Expand Up @@ -407,11 +407,11 @@ fn test_dedup_by() {

#[test]
fn test_dedup_unique() {
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
let mut v0: Vec<Box<_>> = vec![Box::new(1), Box::new(1), Box::new(2), Box::new(3)];
v0.dedup();
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
let mut v1: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(2), Box::new(3)];
v1.dedup();
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
let mut v2: Vec<Box<_>> = vec![Box::new(1), Box::new(2), Box::new(3), Box::new(3)];
v2.dedup();
// If the boxed pointers were leaked or otherwise misused, valgrind
// and/or rt should raise errors.
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ macro_rules! compress {
/// `copy_nonoverlapping` to let the compiler generate the most efficient way
/// to load it from a possibly unaligned address.
///
/// Unsafe because: unchecked indexing at i..i+size_of(int_ty)
/// Safety: this performs unchecked indexing of `$buf` at
/// `$i..$i+size_of::<$int_ty>()`, so that must be in-bounds.
macro_rules! load_int_le {
($buf:expr, $i:expr, $int_ty:ident) => {{
debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
Expand All @@ -114,7 +115,8 @@ macro_rules! load_int_le {
/// `copy_nonoverlapping` calls that occur (via `load_int_le!`) all have fixed
/// sizes and avoid calling `memcpy`, which is good for speed.
///
/// Unsafe because: unchecked indexing at start..start+len
/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
/// that must be in-bounds.
#[inline]
unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
debug_assert!(len < 8);
Expand Down
9 changes: 6 additions & 3 deletions library/core/tests/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ fn any_referenced() {

#[test]
fn any_owning() {
let (a, b, c) =
(box 5_usize as Box<dyn Any>, box TEST as Box<dyn Any>, box Test as Box<dyn Any>);
let (a, b, c) = (
Box::new(5_usize) as Box<dyn Any>,
Box::new(TEST) as Box<dyn Any>,
Box::new(Test) as Box<dyn Any>,
);

assert!(a.is::<usize>());
assert!(!b.is::<usize>());
Expand Down Expand Up @@ -58,7 +61,7 @@ fn any_downcast_ref() {
#[test]
fn any_downcast_mut() {
let mut a = 5_usize;
let mut b: Box<_> = box 7_usize;
let mut b: Box<_> = Box::new(7_usize);

let a_r = &mut a as &mut dyn Any;
let tmp: &mut usize = &mut *b;
Expand Down
Loading

0 comments on commit e810f75

Please sign in to comment.