Skip to content

Commit 62878c2

Browse files
committed
Auto merge of rust-lang#73617 - Dylan-DPC:rollup-zugh80o, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#71660 (impl PartialEq<Vec<B>> for &[A], &mut [A]) - rust-lang#72623 (Prefer accessible paths in 'use' suggestions) - rust-lang#73502 (Add E0765) - rust-lang#73580 (deprecate wrapping_offset_from) - rust-lang#73582 (Miri: replace many bug! by span_bug!) - rust-lang#73585 (Do not send a notification for P-high stable regressions) Failed merges: - rust-lang#73581 (Create 0766 error code) r? @ghost
2 parents 1a4e2b6 + c5e6f48 commit 62878c2

32 files changed

+277
-129
lines changed

src/liballoc/tests/vec.rs

+54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::Cow;
22
use std::collections::TryReserveError::*;
3+
use std::fmt::Debug;
34
use std::mem::size_of;
45
use std::panic::{catch_unwind, AssertUnwindSafe};
56
use std::vec::{Drain, IntoIter};
@@ -1573,3 +1574,56 @@ fn test_push_growth_strategy() {
15731574
}
15741575
}
15751576
}
1577+
1578+
macro_rules! generate_assert_eq_vec_and_prim {
1579+
($name:ident<$B:ident>($type:ty)) => {
1580+
fn $name<A: PartialEq<$B> + Debug, $B: Debug>(a: Vec<A>, b: $type) {
1581+
assert!(a == b);
1582+
assert_eq!(a, b);
1583+
}
1584+
};
1585+
}
1586+
1587+
generate_assert_eq_vec_and_prim! { assert_eq_vec_and_slice <B>(&[B]) }
1588+
generate_assert_eq_vec_and_prim! { assert_eq_vec_and_array_3<B>([B; 3]) }
1589+
1590+
#[test]
1591+
fn partialeq_vec_and_prim() {
1592+
assert_eq_vec_and_slice(vec![1, 2, 3], &[1, 2, 3]);
1593+
assert_eq_vec_and_array_3(vec![1, 2, 3], [1, 2, 3]);
1594+
}
1595+
1596+
macro_rules! assert_partial_eq_valid {
1597+
($a2:ident, $a3:ident; $b2:ident, $b3: ident) => {
1598+
assert!($a2 == $b2);
1599+
assert!($a2 != $b3);
1600+
assert!($a3 != $b2);
1601+
assert!($a3 == $b3);
1602+
assert_eq!($a2, $b2);
1603+
assert_ne!($a2, $b3);
1604+
assert_ne!($a3, $b2);
1605+
assert_eq!($a3, $b3);
1606+
};
1607+
}
1608+
1609+
#[test]
1610+
fn partialeq_vec_full() {
1611+
let vec2: Vec<_> = vec![1, 2];
1612+
let vec3: Vec<_> = vec![1, 2, 3];
1613+
let slice2: &[_] = &[1, 2];
1614+
let slice3: &[_] = &[1, 2, 3];
1615+
let slicemut2: &[_] = &mut [1, 2];
1616+
let slicemut3: &[_] = &mut [1, 2, 3];
1617+
let array2: [_; 2] = [1, 2];
1618+
let array3: [_; 3] = [1, 2, 3];
1619+
let arrayref2: &[_; 2] = &[1, 2];
1620+
let arrayref3: &[_; 3] = &[1, 2, 3];
1621+
1622+
assert_partial_eq_valid!(vec2,vec3; vec2,vec3);
1623+
assert_partial_eq_valid!(vec2,vec3; slice2,slice3);
1624+
assert_partial_eq_valid!(vec2,vec3; slicemut2,slicemut3);
1625+
assert_partial_eq_valid!(slice2,slice3; vec2,vec3);
1626+
assert_partial_eq_valid!(slicemut2,slicemut3; vec2,vec3);
1627+
assert_partial_eq_valid!(vec2,vec3; array2,array3);
1628+
assert_partial_eq_valid!(vec2,vec3; arrayref2,arrayref3);
1629+
}

src/liballoc/vec.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -2342,12 +2342,12 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
23422342
}
23432343

23442344
macro_rules! __impl_slice_eq1 {
2345-
([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => {
2346-
#[stable(feature = "rust1", since = "1.0.0")]
2345+
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
2346+
#[$stability]
23472347
impl<A, B, $($vars)*> PartialEq<$rhs> for $lhs
23482348
where
23492349
A: PartialEq<B>,
2350-
$($constraints)*
2350+
$($ty: $bound)?
23512351
{
23522352
#[inline]
23532353
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
@@ -2357,18 +2357,23 @@ macro_rules! __impl_slice_eq1 {
23572357
}
23582358
}
23592359

2360-
__impl_slice_eq1! { [] Vec<A>, Vec<B>, }
2361-
__impl_slice_eq1! { [] Vec<A>, &[B], }
2362-
__impl_slice_eq1! { [] Vec<A>, &mut [B], }
2363-
__impl_slice_eq1! { [] Cow<'_, [A]>, Vec<B>, A: Clone }
2364-
__impl_slice_eq1! { [] Cow<'_, [A]>, &[B], A: Clone }
2365-
__impl_slice_eq1! { [] Cow<'_, [A]>, &mut [B], A: Clone }
2366-
__impl_slice_eq1! { [const N: usize] Vec<A>, [B; N], [B; N]: LengthAtMost32 }
2367-
__impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N], [B; N]: LengthAtMost32 }
2360+
__impl_slice_eq1! { [] Vec<A>, Vec<B>, #[stable(feature = "rust1", since = "1.0.0")] }
2361+
__impl_slice_eq1! { [] Vec<A>, &[B], #[stable(feature = "rust1", since = "1.0.0")] }
2362+
__impl_slice_eq1! { [] Vec<A>, &mut [B], #[stable(feature = "rust1", since = "1.0.0")] }
2363+
__impl_slice_eq1! { [] &[A], Vec<B>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
2364+
__impl_slice_eq1! { [] &mut [A], Vec<B>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
2365+
__impl_slice_eq1! { [] Cow<'_, [A]>, Vec<B> where A: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2366+
__impl_slice_eq1! { [] Cow<'_, [A]>, &[B] where A: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2367+
__impl_slice_eq1! { [] Cow<'_, [A]>, &mut [B] where A: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2368+
__impl_slice_eq1! { [const N: usize] Vec<A>, [B; N] where [B; N]: LengthAtMost32, #[stable(feature = "rust1", since = "1.0.0")] }
2369+
__impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N] where [B; N]: LengthAtMost32, #[stable(feature = "rust1", since = "1.0.0")] }
23682370

23692371
// NOTE: some less important impls are omitted to reduce code bloat
23702372
// FIXME(Centril): Reconsider this?
23712373
//__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], [B; N]: LengthAtMost32 }
2374+
//__impl_slice_eq1! { [const N: usize] [A; N], Vec<B>, [A; N]: LengthAtMost32 }
2375+
//__impl_slice_eq1! { [const N: usize] &[A; N], Vec<B>, [A; N]: LengthAtMost32 }
2376+
//__impl_slice_eq1! { [const N: usize] &mut [A; N], Vec<B>, [A; N]: LengthAtMost32 }
23722377
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], [B; N]: LengthAtMost32 }
23732378
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], [B; N]: LengthAtMost32 }
23742379
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], [B; N]: LengthAtMost32 }

src/libcore/ptr/const_ptr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ impl<T: ?Sized> *const T {
330330
/// assert_eq!(ptr2.wrapping_offset_from(ptr1), 2);
331331
/// ```
332332
#[unstable(feature = "ptr_wrapping_offset_from", issue = "41079")]
333+
#[rustc_deprecated(
334+
since = "1.46.0",
335+
reason = "Pointer distances across allocation \
336+
boundaries are not typically meaningful. \
337+
Use integer subtraction if you really need this."
338+
)]
333339
#[inline]
334340
pub fn wrapping_offset_from(self, origin: *const T) -> isize
335341
where

src/libcore/ptr/mut_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,18 @@ impl<T: ?Sized> *mut T {
380380
/// assert_eq!(ptr2.wrapping_offset_from(ptr1), 2);
381381
/// ```
382382
#[unstable(feature = "ptr_wrapping_offset_from", issue = "41079")]
383+
#[rustc_deprecated(
384+
since = "1.46.0",
385+
reason = "Pointer distances across allocation \
386+
boundaries are not typically meaningful. \
387+
Use integer subtraction if you really need this."
388+
)]
383389
#[inline]
384390
pub fn wrapping_offset_from(self, origin: *const T) -> isize
385391
where
386392
T: Sized,
387393
{
394+
#[allow(deprecated_in_future, deprecated)]
388395
(self as *const T).wrapping_offset_from(origin)
389396
}
390397

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ E0761: include_str!("./error_codes/E0761.md"),
445445
E0762: include_str!("./error_codes/E0762.md"),
446446
E0763: include_str!("./error_codes/E0763.md"),
447447
E0764: include_str!("./error_codes/E0764.md"),
448+
E0765: include_str!("./error_codes/E0765.md"),
448449
;
449450
// E0006, // merged with E0005
450451
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A double quote string (`"`) was not terminated.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0765
6+
let s = "; // error!
7+
```
8+
9+
To fix this error, add the missing double quote at the end of the string:
10+
11+
```
12+
let s = ""; // ok!
13+
```

src/librustc_mir/interpret/cast.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5252
}
5353

5454
if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
55-
bug!("reifying a fn ptr that requires const arguments");
55+
span_bug!(
56+
self.cur_span(),
57+
"reifying a fn ptr that requires const arguments"
58+
);
5659
}
5760

5861
let instance = ty::Instance::resolve_for_fn_ptr(
@@ -66,7 +69,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6669
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
6770
self.write_scalar(fn_ptr, dest)?;
6871
}
69-
_ => bug!("reify fn pointer on {:?}", src.layout.ty),
72+
_ => span_bug!(self.cur_span(), "reify fn pointer on {:?}", src.layout.ty),
7073
}
7174
}
7275

@@ -77,7 +80,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7780
// No change to value
7881
self.write_immediate(*src, dest)?;
7982
}
80-
_ => bug!("fn to unsafe fn cast on {:?}", cast_ty),
83+
_ => span_bug!(self.cur_span(), "fn to unsafe fn cast on {:?}", cast_ty),
8184
}
8285
}
8386

@@ -99,7 +102,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
99102
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
100103
self.write_scalar(fn_ptr, dest)?;
101104
}
102-
_ => bug!("closure fn pointer on {:?}", src.layout.ty),
105+
_ => span_bug!(self.cur_span(), "closure fn pointer on {:?}", src.layout.ty),
103106
}
104107
}
105108
}
@@ -162,7 +165,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
162165
assert!(src.layout.ty.is_unsafe_ptr());
163166
return match *src {
164167
Immediate::ScalarPair(data, _) => Ok(data.into()),
165-
Immediate::Scalar(..) => bug!(
168+
Immediate::Scalar(..) => span_bug!(
169+
self.cur_span(),
166170
"{:?} input to a fat-to-thin cast ({:?} -> {:?})",
167171
*src,
168172
src.layout.ty,
@@ -216,7 +220,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
216220
}
217221

218222
// Casts to bool are not permitted by rustc, no need to handle them here.
219-
_ => bug!("invalid int to {:?} cast", cast_ty),
223+
_ => span_bug!(self.cur_span(), "invalid int to {:?} cast", cast_ty),
220224
}
221225
}
222226

@@ -248,7 +252,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
248252
// float -> f64
249253
Float(FloatTy::F64) => Scalar::from_f64(f.convert(&mut false).value),
250254
// That's it.
251-
_ => bug!("invalid float to {:?} cast", dest_ty),
255+
_ => span_bug!(self.cur_span(), "invalid float to {:?} cast", dest_ty),
252256
}
253257
}
254258

@@ -287,7 +291,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
287291
self.write_immediate(val, dest)
288292
}
289293

290-
_ => bug!("invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty),
294+
_ => {
295+
span_bug!(self.cur_span(), "invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty)
296+
}
291297
}
292298
}
293299

@@ -307,7 +313,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
307313
assert_eq!(def_a, def_b);
308314
if def_a.is_box() || def_b.is_box() {
309315
if !def_a.is_box() || !def_b.is_box() {
310-
bug!("invalid unsizing between {:?} -> {:?}", src.layout.ty, cast_ty.ty);
316+
span_bug!(
317+
self.cur_span(),
318+
"invalid unsizing between {:?} -> {:?}",
319+
src.layout.ty,
320+
cast_ty.ty
321+
);
311322
}
312323
return self.unsize_into_ptr(
313324
src,
@@ -335,7 +346,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
335346
}
336347
Ok(())
337348
}
338-
_ => bug!("unsize_into: invalid conversion: {:?} -> {:?}", src.layout, dest.layout),
349+
_ => span_bug!(
350+
self.cur_span(),
351+
"unsize_into: invalid conversion: {:?} -> {:?}",
352+
src.layout,
353+
dest.layout
354+
),
339355
}
340356
}
341357
}

src/librustc_mir/interpret/eval_context.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
536536
if sized_size == Size::ZERO {
537537
return Ok(None);
538538
} else {
539-
bug!("Fields cannot be extern types, unless they are at offset 0")
539+
span_bug!(
540+
self.cur_span(),
541+
"Fields cannot be extern types, unless they are at offset 0"
542+
)
540543
}
541544
}
542545
};
@@ -584,7 +587,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
584587

585588
ty::Foreign(_) => Ok(None),
586589

587-
_ => bug!("size_and_align_of::<{:?}> not supported", layout.ty),
590+
_ => span_bug!(self.cur_span(), "size_and_align_of::<{:?}> not supported", layout.ty),
588591
}
589592
}
590593
#[inline]

src/librustc_mir/interpret/intrinsics.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
135135
let bits = self.force_bits(val, layout_of.size)?;
136136
let kind = match layout_of.abi {
137137
Abi::Scalar(ref scalar) => scalar.value,
138-
_ => bug!("{} called on invalid type {:?}", intrinsic_name, ty),
138+
_ => span_bug!(
139+
self.cur_span(),
140+
"{} called on invalid type {:?}",
141+
intrinsic_name,
142+
ty
143+
),
139144
};
140145
let (nonzero, intrinsic_name) = match intrinsic_name {
141146
sym::cttz_nonzero => (true, sym::cttz),

src/librustc_mir/interpret/operand.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
311311
if let Ok(imm) = self.try_read_immediate(op)? {
312312
Ok(imm)
313313
} else {
314-
bug!("primitive read failed for type: {:?}", op.layout.ty);
314+
span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty);
315315
}
316316
}
317317

@@ -360,9 +360,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
360360
let val = if offset.bytes() == 0 { a } else { b };
361361
Immediate::from(val)
362362
}
363-
Immediate::Scalar(val) => {
364-
bug!("field access on non aggregate {:#?}, {:#?}", val, op.layout)
365-
}
363+
Immediate::Scalar(val) => span_bug!(
364+
self.cur_span(),
365+
"field access on non aggregate {:#?}, {:#?}",
366+
val,
367+
op.layout
368+
),
366369
};
367370
Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout })
368371
}
@@ -545,7 +548,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
545548
ty::ConstKind::Infer(..)
546549
| ty::ConstKind::Bound(..)
547550
| ty::ConstKind::Placeholder(..) => {
548-
bug!("eval_const_to_op: Unexpected ConstKind {:?}", val)
551+
span_bug!(self.cur_span(), "eval_const_to_op: Unexpected ConstKind {:?}", val)
549552
}
550553
ty::ConstKind::Value(val_val) => val_val,
551554
};
@@ -656,7 +659,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
656659
.discriminants(def_id, *self.tcx)
657660
.find(|(_, var)| var.val == discr_bits)
658661
}
659-
_ => bug!("tagged layout for non-adt non-generator"),
662+
_ => span_bug!(self.cur_span(), "tagged layout for non-adt non-generator"),
660663
}
661664
.ok_or_else(|| err_ub!(InvalidTag(tag_val.erase_tag())))?;
662665
// Return the cast value, and the index.

0 commit comments

Comments
 (0)