Skip to content

Commit a80e63f

Browse files
committed
Auto merge of rust-lang#67917 - Dylan-DPC:rollup-id05y91, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#67800 (Fix ICE involving calling `Instance.ty` during const evaluation) - rust-lang#67873 (change remove to have a PartialEq bound) - rust-lang#67897 (Use `as_deref()` to replace `as_ref().map(...)`) - rust-lang#67906 (Silence `TooGeneric` error) - rust-lang#67912 (macros: typo fix) - rust-lang#67915 (Use Self instead of $type) Failed merges: r? @ghost
2 parents 33640f0 + 34716a3 commit a80e63f

File tree

27 files changed

+172
-51
lines changed

27 files changed

+172
-51
lines changed

src/liballoc/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(associated_type_bounds)]
1212
#![feature(binary_heap_into_iter_sorted)]
1313
#![feature(binary_heap_drain_sorted)]
14+
#![feature(vec_remove_item)]
1415

1516
use std::collections::hash_map::DefaultHasher;
1617
use std::hash::{Hash, Hasher};

src/liballoc/tests/vec.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ fn test_extend_ref() {
131131
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7]);
132132
}
133133

134+
#[test]
135+
fn test_remove_item() {
136+
let mut v = vec![1, 2, 3];
137+
v.remove_item(&1);
138+
139+
assert_eq!(v.len(), 2);
140+
assert_eq!(v, [2, 3]);
141+
142+
let mut w = vec![1, 2, 3];
143+
w.remove_item(&4);
144+
145+
assert_eq!(w.len(), 3);
146+
w.remove_item(&4);
147+
}
148+
134149
#[test]
135150
fn test_slice_from_mut() {
136151
let mut values = vec![1, 2, 3, 4, 5];

src/liballoc/vec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,9 @@ impl<T: PartialEq> Vec<T> {
16881688
pub fn dedup(&mut self) {
16891689
self.dedup_by(|a, b| a == b)
16901690
}
1691+
}
16911692

1693+
impl<T> Vec<T> {
16921694
/// Removes the first instance of `item` from the vector if the item exists.
16931695
///
16941696
/// # Examples
@@ -1702,7 +1704,10 @@ impl<T: PartialEq> Vec<T> {
17021704
/// assert_eq!(vec, vec![2, 3, 1]);
17031705
/// ```
17041706
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
1705-
pub fn remove_item(&mut self, item: &T) -> Option<T> {
1707+
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
1708+
where
1709+
T: PartialEq<V>,
1710+
{
17061711
let pos = self.iter().position(|x| *x == *item)?;
17071712
Some(self.remove(pos))
17081713
}

src/libcore/convert/num.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ macro_rules! impl_from {
4747
#[doc = $doc]
4848
impl From<$Small> for $Large {
4949
#[inline]
50-
fn from(small: $Small) -> $Large {
51-
small as $Large
50+
fn from(small: $Small) -> Self {
51+
small as Self
5252
}
5353
}
5454
};
@@ -177,7 +177,7 @@ macro_rules! try_from_unbounded {
177177
/// is outside of the range of the target type.
178178
#[inline]
179179
fn try_from(value: $source) -> Result<Self, Self::Error> {
180-
Ok(value as $target)
180+
Ok(value as Self)
181181
}
182182
}
183183
)*}
@@ -194,9 +194,9 @@ macro_rules! try_from_lower_bounded {
194194
/// number type. This returns an error if the source value
195195
/// is outside of the range of the target type.
196196
#[inline]
197-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
197+
fn try_from(u: $source) -> Result<Self, Self::Error> {
198198
if u >= 0 {
199-
Ok(u as $target)
199+
Ok(u as Self)
200200
} else {
201201
Err(TryFromIntError(()))
202202
}
@@ -216,11 +216,11 @@ macro_rules! try_from_upper_bounded {
216216
/// number type. This returns an error if the source value
217217
/// is outside of the range of the target type.
218218
#[inline]
219-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
220-
if u > (<$target>::max_value() as $source) {
219+
fn try_from(u: $source) -> Result<Self, Self::Error> {
220+
if u > (Self::max_value() as $source) {
221221
Err(TryFromIntError(()))
222222
} else {
223-
Ok(u as $target)
223+
Ok(u as Self)
224224
}
225225
}
226226
}
@@ -238,13 +238,13 @@ macro_rules! try_from_both_bounded {
238238
/// number type. This returns an error if the source value
239239
/// is outside of the range of the target type.
240240
#[inline]
241-
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
242-
let min = <$target>::min_value() as $source;
243-
let max = <$target>::max_value() as $source;
241+
fn try_from(u: $source) -> Result<Self, Self::Error> {
242+
let min = Self::min_value() as $source;
243+
let max = Self::max_value() as $source;
244244
if u < min || u > max {
245245
Err(TryFromIntError(()))
246246
} else {
247-
Ok(u as $target)
247+
Ok(u as Self)
248248
}
249249
}
250250
}
@@ -385,10 +385,10 @@ macro_rules! nzint_impl_from {
385385
#[doc = $doc]
386386
impl From<$Small> for $Large {
387387
#[inline]
388-
fn from(small: $Small) -> $Large {
388+
fn from(small: $Small) -> Self {
389389
// SAFETY: input type guarantees the value is non-zero
390390
unsafe {
391-
<$Large>::new_unchecked(small.get().into())
391+
Self::new_unchecked(small.get().into())
392392
}
393393
}
394394
}

src/libcore/fmt/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ trait Int:
2424

2525
macro_rules! doit {
2626
($($t:ident)*) => ($(impl Int for $t {
27-
fn zero() -> $t { 0 }
28-
fn from_u8(u: u8) -> $t { u as $t }
27+
fn zero() -> Self { 0 }
28+
fn from_u8(u: u8) -> Self { u as Self }
2929
fn to_u8(&self) -> u8 { *self as u8 }
3030
fn to_u16(&self) -> u16 { *self as u16 }
3131
fn to_u32(&self) -> u32 { *self as u32 }

src/libcore/iter/traits/accum.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ macro_rules! integer_sum_product {
4444
(@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty)*) => ($(
4545
#[$attr]
4646
impl Sum for $a {
47-
fn sum<I: Iterator<Item=$a>>(iter: I) -> $a {
47+
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
4848
iter.fold($zero, Add::add)
4949
}
5050
}
5151

5252
#[$attr]
5353
impl Product for $a {
54-
fn product<I: Iterator<Item=$a>>(iter: I) -> $a {
54+
fn product<I: Iterator<Item=Self>>(iter: I) -> Self {
5555
iter.fold($one, Mul::mul)
5656
}
5757
}
5858

5959
#[$attr]
6060
impl<'a> Sum<&'a $a> for $a {
61-
fn sum<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
61+
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
6262
iter.fold($zero, Add::add)
6363
}
6464
}
6565

6666
#[$attr]
6767
impl<'a> Product<&'a $a> for $a {
68-
fn product<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
68+
fn product<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
6969
iter.fold($one, Mul::mul)
7070
}
7171
}
@@ -84,28 +84,28 @@ macro_rules! float_sum_product {
8484
($($a:ident)*) => ($(
8585
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
8686
impl Sum for $a {
87-
fn sum<I: Iterator<Item=$a>>(iter: I) -> $a {
87+
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
8888
iter.fold(0.0, Add::add)
8989
}
9090
}
9191

9292
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
9393
impl Product for $a {
94-
fn product<I: Iterator<Item=$a>>(iter: I) -> $a {
94+
fn product<I: Iterator<Item=Self>>(iter: I) -> Self {
9595
iter.fold(1.0, Mul::mul)
9696
}
9797
}
9898

9999
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
100100
impl<'a> Sum<&'a $a> for $a {
101-
fn sum<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
101+
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
102102
iter.fold(0.0, Add::add)
103103
}
104104
}
105105

106106
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
107107
impl<'a> Product<&'a $a> for $a {
108-
fn product<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
108+
fn product<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
109109
iter.fold(1.0, Mul::mul)
110110
}
111111
}

src/libcore/macros/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ macro_rules! unreachable {
551551

552552
/// Indicates unimplemented code by panicking with a message of "not implemented".
553553
///
554-
/// This allows the your code to type-check, which is useful if you are prototyping or
554+
/// This allows your code to type-check, which is useful if you are prototyping or
555555
/// implementing a trait that requires multiple methods which you don't plan of using all of.
556556
///
557557
/// The difference between `unimplemented!` and [`todo!`](macro.todo.html) is that while `todo!`

src/libcore/marker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,15 @@ macro_rules! impls {
505505

506506
#[stable(feature = "rust1", since = "1.0.0")]
507507
impl<T: ?Sized> Clone for $t<T> {
508-
fn clone(&self) -> $t<T> {
509-
$t
508+
fn clone(&self) -> Self {
509+
Self
510510
}
511511
}
512512

513513
#[stable(feature = "rust1", since = "1.0.0")]
514514
impl<T: ?Sized> Default for $t<T> {
515-
fn default() -> $t<T> {
516-
$t
515+
fn default() -> Self {
516+
Self
517517
}
518518
}
519519

src/libcore/num/bignum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ macro_rules! define_bignum {
455455
}
456456

457457
impl crate::clone::Clone for $name {
458-
fn clone(&self) -> $name {
459-
$name { size: self.size, base: self.base }
458+
fn clone(&self) -> Self {
459+
Self { size: self.size, base: self.base }
460460
}
461461
}
462462

src/librustc/traits/error_reporting.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::hir::Node;
1212
use crate::infer::error_reporting::TypeAnnotationNeeded as ErrorCode;
1313
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1414
use crate::infer::{self, InferCtxt};
15+
use crate::mir::interpret::ErrorHandled;
1516
use crate::session::DiagnosticMessageId;
1617
use crate::ty::error::ExpectedFound;
1718
use crate::ty::fast_reject;
@@ -1086,6 +1087,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10861087

10871088
// already reported in the query
10881089
ConstEvalFailure(err) => {
1090+
if let ErrorHandled::TooGeneric = err {
1091+
// Silence this error, as it can be produced during intermediate steps
1092+
// when a constant is not yet able to be evaluated (but will be later).
1093+
return;
1094+
}
10891095
self.tcx.sess.delay_span_bug(
10901096
span,
10911097
&format!("constant in type had an ignored error: {:?}", err),

0 commit comments

Comments
 (0)