Skip to content

Commit 2639caa

Browse files
authored
Rollup merge of rust-lang#89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2 parents 829ce5c + 9532e78 commit 2639caa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

std/src/collections/hash/map.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ impl<K, V, S> HashMap<K, V, S> {
414414
/// println!("key: {} val: {}", key, val);
415415
/// }
416416
/// ```
417+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
417418
#[stable(feature = "rust1", since = "1.0.0")]
418419
pub fn iter(&self) -> Iter<'_, K, V> {
419420
Iter { base: self.base.iter() }
@@ -442,6 +443,7 @@ impl<K, V, S> HashMap<K, V, S> {
442443
/// println!("key: {} val: {}", key, val);
443444
/// }
444445
/// ```
446+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
445447
#[stable(feature = "rust1", since = "1.0.0")]
446448
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
447449
IterMut { base: self.base.iter_mut() }
@@ -502,6 +504,7 @@ impl<K, V, S> HashMap<K, V, S> {
502504
/// assert!(a.is_empty());
503505
/// ```
504506
#[inline]
507+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
505508
#[stable(feature = "drain", since = "1.6.0")]
506509
pub fn drain(&mut self) -> Drain<'_, K, V> {
507510
Drain { base: self.base.drain() }
@@ -543,6 +546,7 @@ impl<K, V, S> HashMap<K, V, S> {
543546
/// assert_eq!(odds, vec![1, 3, 5, 7]);
544547
/// ```
545548
#[inline]
549+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
546550
#[unstable(feature = "hash_drain_filter", issue = "59618")]
547551
pub fn drain_filter<F>(&mut self, pred: F) -> DrainFilter<'_, K, V, F>
548552
where
@@ -949,6 +953,7 @@ where
949953
/// assert_eq!(map.len(), 4);
950954
/// ```
951955
#[inline]
956+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
952957
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
953958
pub fn retain<F>(&mut self, f: F)
954959
where
@@ -978,6 +983,7 @@ where
978983
/// assert_eq!(vec, ["a", "b", "c"]);
979984
/// ```
980985
#[inline]
986+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
981987
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
982988
pub fn into_keys(self) -> IntoKeys<K, V> {
983989
IntoKeys { inner: self.into_iter() }
@@ -1004,6 +1010,7 @@ where
10041010
/// assert_eq!(vec, [1, 2, 3]);
10051011
/// ```
10061012
#[inline]
1013+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
10071014
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
10081015
pub fn into_values(self) -> IntoValues<K, V> {
10091016
IntoValues { inner: self.into_iter() }
@@ -1969,6 +1976,7 @@ impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> {
19691976
type IntoIter = Iter<'a, K, V>;
19701977

19711978
#[inline]
1979+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
19721980
fn into_iter(self) -> Iter<'a, K, V> {
19731981
self.iter()
19741982
}
@@ -1980,6 +1988,7 @@ impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S> {
19801988
type IntoIter = IterMut<'a, K, V>;
19811989

19821990
#[inline]
1991+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
19831992
fn into_iter(self) -> IterMut<'a, K, V> {
19841993
self.iter_mut()
19851994
}
@@ -2008,6 +2017,7 @@ impl<K, V, S> IntoIterator for HashMap<K, V, S> {
20082017
/// let vec: Vec<(&str, i32)> = map.into_iter().collect();
20092018
/// ```
20102019
#[inline]
2020+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
20112021
fn into_iter(self) -> IntoIter<K, V> {
20122022
IntoIter { base: self.base.into_iter() }
20132023
}

std/src/collections/hash/set.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl<T, S> HashSet<T, S> {
185185
/// }
186186
/// ```
187187
#[inline]
188+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
188189
#[stable(feature = "rust1", since = "1.0.0")]
189190
pub fn iter(&self) -> Iter<'_, T> {
190191
Iter { base: self.base.iter() }
@@ -244,6 +245,7 @@ impl<T, S> HashSet<T, S> {
244245
/// assert!(set.is_empty());
245246
/// ```
246247
#[inline]
248+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
247249
#[stable(feature = "drain", since = "1.6.0")]
248250
pub fn drain(&mut self) -> Drain<'_, T> {
249251
Drain { base: self.base.drain() }
@@ -282,6 +284,7 @@ impl<T, S> HashSet<T, S> {
282284
/// assert_eq!(odds, vec![1, 3, 5, 7]);
283285
/// ```
284286
#[inline]
287+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
285288
#[unstable(feature = "hash_drain_filter", issue = "59618")]
286289
pub fn drain_filter<F>(&mut self, pred: F) -> DrainFilter<'_, T, F>
287290
where
@@ -506,6 +509,7 @@ where
506509
/// assert_eq!(diff, [4].iter().collect());
507510
/// ```
508511
#[inline]
512+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
509513
#[stable(feature = "rust1", since = "1.0.0")]
510514
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
511515
Difference { iter: self.iter(), other }
@@ -533,6 +537,7 @@ where
533537
/// assert_eq!(diff1, [1, 4].iter().collect());
534538
/// ```
535539
#[inline]
540+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
536541
#[stable(feature = "rust1", since = "1.0.0")]
537542
pub fn symmetric_difference<'a>(
538543
&'a self,
@@ -560,6 +565,7 @@ where
560565
/// assert_eq!(intersection, [2, 3].iter().collect());
561566
/// ```
562567
#[inline]
568+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
563569
#[stable(feature = "rust1", since = "1.0.0")]
564570
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
565571
if self.len() <= other.len() {
@@ -588,6 +594,7 @@ where
588594
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
589595
/// ```
590596
#[inline]
597+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
591598
#[stable(feature = "rust1", since = "1.0.0")]
592599
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
593600
if self.len() >= other.len() {
@@ -922,6 +929,7 @@ where
922929
/// set.retain(|&k| k % 2 == 0);
923930
/// assert_eq!(set.len(), 3);
924931
/// ```
932+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
925933
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
926934
pub fn retain<F>(&mut self, f: F)
927935
where
@@ -1403,6 +1411,7 @@ impl<'a, T, S> IntoIterator for &'a HashSet<T, S> {
14031411
type IntoIter = Iter<'a, T>;
14041412

14051413
#[inline]
1414+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
14061415
fn into_iter(self) -> Iter<'a, T> {
14071416
self.iter()
14081417
}
@@ -1434,6 +1443,7 @@ impl<T, S> IntoIterator for HashSet<T, S> {
14341443
/// }
14351444
/// ```
14361445
#[inline]
1446+
#[cfg_attr(not(bootstrap), rustc_lint_query_instability)]
14371447
fn into_iter(self) -> IntoIter<T> {
14381448
IntoIter { base: self.base.into_iter() }
14391449
}

0 commit comments

Comments
 (0)