Skip to content

Commit 17b0e39

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 64a5984 + cb771b2 commit 17b0e39

File tree

19 files changed

+46
-0
lines changed

19 files changed

+46
-0
lines changed

alloc/src/collections/btree/map.rs

+2
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

+1
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

+1
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

+6
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

+7
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

+1
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

+1
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

+1
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

+2
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

+1
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),

core/src/str/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl str {
134134
/// ```
135135
#[stable(feature = "rust1", since = "1.0.0")]
136136
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
137+
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")]
137138
#[must_use]
138139
#[inline]
139140
pub const fn len(&self) -> usize {
@@ -1157,6 +1158,7 @@ impl str {
11571158
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
11581159
/// ```
11591160
#[stable(feature = "rust1", since = "1.0.0")]
1161+
#[cfg_attr(not(test), rustc_diagnostic_item = "str_starts_with")]
11601162
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
11611163
pat.is_prefix_of(self)
11621164
}
@@ -1181,6 +1183,7 @@ impl str {
11811183
/// assert!(!bananas.ends_with("nana"));
11821184
/// ```
11831185
#[stable(feature = "rust1", since = "1.0.0")]
1186+
#[cfg_attr(not(test), rustc_diagnostic_item = "str_ends_with")]
11841187
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool
11851188
where
11861189
for<'a> P::Searcher<'a>: ReverseSearcher<'a>,

core/src/task/wake.rs

+1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl<'a> ContextBuilder<'a> {
414414
/// [`Wake`]: ../../alloc/task/trait.Wake.html
415415
#[repr(transparent)]
416416
#[stable(feature = "futures_api", since = "1.36.0")]
417+
#[cfg_attr(not(test), rustc_diagnostic_item = "Waker")]
417418
pub struct Waker {
418419
waker: RawWaker,
419420
}

std/src/collections/hash/map.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ where
10371037
/// ```
10381038
#[inline]
10391039
#[stable(feature = "rust1", since = "1.0.0")]
1040+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_contains_key")]
10401041
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
10411042
where
10421043
K: Borrow<Q>,
@@ -1100,6 +1101,7 @@ where
11001101
#[inline]
11011102
#[stable(feature = "rust1", since = "1.0.0")]
11021103
#[rustc_confusables("push", "append", "put")]
1104+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_insert")]
11031105
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
11041106
self.base.insert(k, v)
11051107
}
@@ -1391,6 +1393,7 @@ where
13911393
/// let iter = map.iter();
13921394
/// ```
13931395
#[stable(feature = "rust1", since = "1.0.0")]
1396+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_iter_ty")]
13941397
pub struct Iter<'a, K: 'a, V: 'a> {
13951398
base: base::Iter<'a, K, V>,
13961399
}
@@ -1429,6 +1432,7 @@ impl<K: Debug, V: Debug> fmt::Debug for Iter<'_, K, V> {
14291432
/// let iter = map.iter_mut();
14301433
/// ```
14311434
#[stable(feature = "rust1", since = "1.0.0")]
1435+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_iter_mut_ty")]
14321436
pub struct IterMut<'a, K: 'a, V: 'a> {
14331437
base: base::IterMut<'a, K, V>,
14341438
}
@@ -1489,6 +1493,7 @@ impl<K, V> IntoIter<K, V> {
14891493
/// let iter_keys = map.keys();
14901494
/// ```
14911495
#[stable(feature = "rust1", since = "1.0.0")]
1496+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_keys_ty")]
14921497
pub struct Keys<'a, K: 'a, V: 'a> {
14931498
inner: Iter<'a, K, V>,
14941499
}
@@ -1527,6 +1532,7 @@ impl<K: Debug, V> fmt::Debug for Keys<'_, K, V> {
15271532
/// let iter_values = map.values();
15281533
/// ```
15291534
#[stable(feature = "rust1", since = "1.0.0")]
1535+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_values_ty")]
15301536
pub struct Values<'a, K: 'a, V: 'a> {
15311537
inner: Iter<'a, K, V>,
15321538
}
@@ -1565,6 +1571,7 @@ impl<K, V: Debug> fmt::Debug for Values<'_, K, V> {
15651571
/// let iter = map.drain();
15661572
/// ```
15671573
#[stable(feature = "drain", since = "1.6.0")]
1574+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_drain_ty")]
15681575
pub struct Drain<'a, K: 'a, V: 'a> {
15691576
base: base::Drain<'a, K, V>,
15701577
}
@@ -1622,6 +1629,7 @@ where
16221629
/// let iter_values = map.values_mut();
16231630
/// ```
16241631
#[stable(feature = "map_values_mut", since = "1.10.0")]
1632+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_values_mut_ty")]
16251633
pub struct ValuesMut<'a, K: 'a, V: 'a> {
16261634
inner: IterMut<'a, K, V>,
16271635
}

std/src/collections/hash/set.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ where
12711271
/// let mut iter = a.iter();
12721272
/// ```
12731273
#[stable(feature = "rust1", since = "1.0.0")]
1274+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_iter_ty")]
12741275
pub struct Iter<'a, K: 'a> {
12751276
base: base::Iter<'a, K>,
12761277
}
@@ -1313,6 +1314,7 @@ pub struct IntoIter<K> {
13131314
/// let mut drain = a.drain();
13141315
/// ```
13151316
#[stable(feature = "rust1", since = "1.0.0")]
1317+
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_drain_ty")]
13161318
pub struct Drain<'a, K: 'a> {
13171319
base: base::Drain<'a, K>,
13181320
}

std/src/ffi/os_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl OsString {
196196
/// let os_str = OsStr::new("foo");
197197
/// assert_eq!(os_string.as_os_str(), os_str);
198198
/// ```
199+
#[cfg_attr(not(test), rustc_diagnostic_item = "os_string_as_os_str")]
199200
#[stable(feature = "rust1", since = "1.0.0")]
200201
#[must_use]
201202
#[inline]
@@ -918,6 +919,7 @@ impl OsStr {
918919
#[must_use = "this returns the result of the operation, \
919920
without modifying the original"]
920921
#[inline]
922+
#[cfg_attr(not(test), rustc_diagnostic_item = "os_str_to_os_string")]
921923
pub fn to_os_string(&self) -> OsString {
922924
OsString { inner: self.inner.to_owned() }
923925
}

std/src/fs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ impl File {
466466
/// ```
467467
#[must_use]
468468
#[stable(feature = "with_options", since = "1.58.0")]
469+
#[cfg_attr(not(test), rustc_diagnostic_item = "file_options")]
469470
pub fn options() -> OpenOptions {
470471
OpenOptions::new()
471472
}
@@ -1009,6 +1010,7 @@ impl OpenOptions {
10091010
/// let mut options = OpenOptions::new();
10101011
/// let file = options.read(true).open("foo.txt");
10111012
/// ```
1013+
#[cfg_attr(not(test), rustc_diagnostic_item = "open_options_new")]
10121014
#[stable(feature = "rust1", since = "1.0.0")]
10131015
#[must_use]
10141016
pub fn new() -> Self {

std/src/os/unix/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ pub trait PermissionsExt {
334334
/// assert_eq!(permissions.mode(), 0o644);
335335
/// ```
336336
#[stable(feature = "fs_ext", since = "1.1.0")]
337+
#[cfg_attr(not(test), rustc_diagnostic_item = "permissions_from_mode")]
337338
fn from_mode(mode: u32) -> Self;
338339
}
339340

std/src/path.rs

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub fn is_separator(c: char) -> bool {
263263
///
264264
/// For example, `/` on Unix and `\` on Windows.
265265
#[stable(feature = "rust1", since = "1.0.0")]
266+
#[cfg_attr(not(test), rustc_diagnostic_item = "path_main_separator")]
266267
pub const MAIN_SEPARATOR: char = crate::sys::path::MAIN_SEP;
267268

268269
/// The primary separator of path components for the current platform.
@@ -1226,6 +1227,7 @@ impl PathBuf {
12261227
/// let p = PathBuf::from("/test");
12271228
/// assert_eq!(Path::new("/test"), p.as_path());
12281229
/// ```
1230+
#[cfg_attr(not(test), rustc_diagnostic_item = "pathbuf_as_path")]
12291231
#[stable(feature = "rust1", since = "1.0.0")]
12301232
#[must_use]
12311233
#[inline]
@@ -2264,6 +2266,7 @@ impl Path {
22642266
#[must_use = "this returns the result of the operation, \
22652267
without modifying the original"]
22662268
#[stable(feature = "rust1", since = "1.0.0")]
2269+
#[cfg_attr(not(test), rustc_diagnostic_item = "path_to_pathbuf")]
22672270
pub fn to_path_buf(&self) -> PathBuf {
22682271
PathBuf::from(self.inner.to_os_string())
22692272
}

std/src/time.rs

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl Instant {
280280
/// ```
281281
#[must_use]
282282
#[stable(feature = "time2", since = "1.8.0")]
283+
#[cfg_attr(not(test), rustc_diagnostic_item = "instant_now")]
283284
pub fn now() -> Instant {
284285
Instant(time::Instant::now())
285286
}

0 commit comments

Comments
 (0)