Skip to content

Commit 74e2be2

Browse files
authored
Rollup merge of rust-lang#130553 - GnomedDev:remove-clippy-paths, r=compiler-errors
[Clippy] Get rid of most `std` `match_def_path` usage, swap to diagnostic items. Part of rust-lang/rust-clippy#5393. This was going to remove all `std` paths, but `SeekFrom` has issues being cleanly replaced with a diagnostic item as the paths are for variants, which currently cannot be diagnostic items. This also, as a last step, categories the paths to help with future path removals.
2 parents 685c146 + 610a25c commit 74e2be2

File tree

19 files changed

+46
-0
lines changed

19 files changed

+46
-0
lines changed

alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
916916
/// assert_eq!(map.contains_key(&2), false);
917917
/// ```
918918
#[stable(feature = "rust1", since = "1.0.0")]
919+
#[cfg_attr(not(test), rustc_diagnostic_item = "btreemap_contains_key")]
919920
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
920921
where
921922
K: Borrow<Q> + Ord,
@@ -981,6 +982,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
981982
/// ```
982983
#[stable(feature = "rust1", since = "1.0.0")]
983984
#[rustc_confusables("push", "put", "set")]
985+
#[cfg_attr(not(test), rustc_diagnostic_item = "btreemap_insert")]
984986
pub fn insert(&mut self, key: K, value: V) -> Option<V>
985987
where
986988
K: Ord,

alloc/src/ffi/c_str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ impl CString {
576576
#[inline]
577577
#[must_use]
578578
#[stable(feature = "as_c_str", since = "1.20.0")]
579+
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_as_c_str")]
579580
pub fn as_c_str(&self) -> &CStr {
580581
&*self
581582
}

alloc/src/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ impl<T> [T] {
496496
#[rustc_allow_incoherent_impl]
497497
#[stable(feature = "rust1", since = "1.0.0")]
498498
#[inline]
499+
#[cfg_attr(not(test), rustc_diagnostic_item = "slice_into_vec")]
499500
pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
500501
// N.B., see the `hack` module in this file for more details.
501502
hack::into_vec(self)

alloc/src/string.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl String {
440440
/// ```
441441
#[inline]
442442
#[rustc_const_stable(feature = "const_string_new", since = "1.39.0")]
443+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_new")]
443444
#[stable(feature = "rust1", since = "1.0.0")]
444445
#[must_use]
445446
pub const fn new() -> String {
@@ -571,6 +572,7 @@ impl String {
571572
/// [`into_bytes`]: String::into_bytes
572573
#[inline]
573574
#[stable(feature = "rust1", since = "1.0.0")]
575+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_from_utf8")]
574576
pub fn from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error> {
575577
match str::from_utf8(&vec) {
576578
Ok(..) => Ok(String { vec }),
@@ -1073,6 +1075,7 @@ impl String {
10731075
#[inline]
10741076
#[must_use]
10751077
#[stable(feature = "string_as_str", since = "1.7.0")]
1078+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_as_str")]
10761079
pub fn as_str(&self) -> &str {
10771080
self
10781081
}
@@ -1092,6 +1095,7 @@ impl String {
10921095
#[inline]
10931096
#[must_use]
10941097
#[stable(feature = "string_as_str", since = "1.7.0")]
1098+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_as_mut_str")]
10951099
pub fn as_mut_str(&mut self) -> &mut str {
10961100
self
10971101
}
@@ -1111,6 +1115,7 @@ impl String {
11111115
#[inline]
11121116
#[stable(feature = "rust1", since = "1.0.0")]
11131117
#[rustc_confusables("append", "push")]
1118+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_push_str")]
11141119
pub fn push_str(&mut self, string: &str) {
11151120
self.vec.extend_from_slice(string.as_bytes())
11161121
}
@@ -1745,6 +1750,7 @@ impl String {
17451750
#[cfg(not(no_global_oom_handling))]
17461751
#[inline]
17471752
#[stable(feature = "insert_str", since = "1.16.0")]
1753+
#[cfg_attr(not(test), rustc_diagnostic_item = "string_insert_str")]
17481754
pub fn insert_str(&mut self, idx: usize, string: &str) {
17491755
assert!(self.is_char_boundary(idx));
17501756

alloc/src/vec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ impl<T> Vec<T> {
416416
/// ```
417417
#[inline]
418418
#[rustc_const_stable(feature = "const_vec_new", since = "1.39.0")]
419+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_new")]
419420
#[stable(feature = "rust1", since = "1.0.0")]
420421
#[must_use]
421422
pub const fn new() -> Self {
@@ -476,6 +477,7 @@ impl<T> Vec<T> {
476477
#[inline]
477478
#[stable(feature = "rust1", since = "1.0.0")]
478479
#[must_use]
480+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_with_capacity")]
479481
pub fn with_capacity(capacity: usize) -> Self {
480482
Self::with_capacity_in(capacity, Global)
481483
}
@@ -1545,6 +1547,7 @@ impl<T, A: Allocator> Vec<T, A> {
15451547
/// ```
15461548
#[inline]
15471549
#[stable(feature = "vec_as_slice", since = "1.7.0")]
1550+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_slice")]
15481551
pub fn as_slice(&self) -> &[T] {
15491552
self
15501553
}
@@ -1562,6 +1565,7 @@ impl<T, A: Allocator> Vec<T, A> {
15621565
/// ```
15631566
#[inline]
15641567
#[stable(feature = "vec_as_slice", since = "1.7.0")]
1568+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_as_mut_slice")]
15651569
pub fn as_mut_slice(&mut self) -> &mut [T] {
15661570
self
15671571
}
@@ -2380,6 +2384,7 @@ impl<T, A: Allocator> Vec<T, A> {
23802384
/// Takes *O*(1) time.
23812385
#[inline]
23822386
#[stable(feature = "rust1", since = "1.0.0")]
2387+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_pop")]
23832388
pub fn pop(&mut self) -> Option<T> {
23842389
if self.len == 0 {
23852390
None
@@ -2573,6 +2578,7 @@ impl<T, A: Allocator> Vec<T, A> {
25732578
/// assert!(!v.is_empty());
25742579
/// ```
25752580
#[stable(feature = "rust1", since = "1.0.0")]
2581+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_is_empty")]
25762582
pub fn is_empty(&self) -> bool {
25772583
self.len() == 0
25782584
}
@@ -3044,6 +3050,7 @@ impl<T: PartialEq, A: Allocator> Vec<T, A> {
30443050
#[doc(hidden)]
30453051
#[cfg(not(no_global_oom_handling))]
30463052
#[stable(feature = "rust1", since = "1.0.0")]
3053+
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_from_elem")]
30473054
pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
30483055
<T as SpecFromElem>::from_elem(elem, n, Global)
30493056
}

core/src/bool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl bool {
5555
/// assert_eq!(a, 1);
5656
/// ```
5757
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
58+
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")]
5859
#[inline]
5960
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6061
if self { Some(f()) } else { None }

core/src/num/f32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ impl f32 {
415415
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
416416
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
417417
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
418+
#[cfg_attr(not(test), rustc_diagnostic_item = "f32_epsilon")]
418419
pub const EPSILON: f32 = 1.19209290e-07_f32;
419420

420421
/// Smallest finite `f32` value.

core/src/num/f64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl f64 {
414414
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
415415
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
416416
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
417+
#[cfg_attr(not(test), rustc_diagnostic_item = "f64_epsilon")]
417418
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
418419

419420
/// Smallest finite `f64` value.

core/src/option.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ impl<T> Option<T> {
923923
#[inline]
924924
#[track_caller]
925925
#[stable(feature = "rust1", since = "1.0.0")]
926+
#[cfg_attr(not(test), rustc_diagnostic_item = "option_expect")]
926927
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
927928
pub const fn expect(self, msg: &str) -> T {
928929
match self {
@@ -960,6 +961,7 @@ impl<T> Option<T> {
960961
#[inline(always)]
961962
#[track_caller]
962963
#[stable(feature = "rust1", since = "1.0.0")]
964+
#[cfg_attr(not(test), rustc_diagnostic_item = "option_unwrap")]
963965
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
964966
pub const fn unwrap(self) -> T {
965967
match self {

core/src/result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ impl<T, E> Result<T, E> {
653653
/// ```
654654
#[inline]
655655
#[stable(feature = "rust1", since = "1.0.0")]
656+
#[cfg_attr(not(test), rustc_diagnostic_item = "result_ok_method")]
656657
pub fn ok(self) -> Option<T> {
657658
match self {
658659
Ok(x) => Some(x),

0 commit comments

Comments
 (0)