Skip to content

Commit 43fd619

Browse files
committed
auto merge of #17286 : vberger/rust/deprecated_in_macros, r=aturon
Closes #17185. The stability lint will now check code generated by macro expansion. It will allow to detect : - arguments passed to macros using deprecated (and others) items - macro expansion generating code using deprecated items due to its arguments (hence the second commit, fixing such issue found in libcollections) Checking is still done at expansion, but it will also detect a macro explicitly using a deprecated item in its definition.
2 parents 4b5f456 + d845857 commit 43fd619

File tree

18 files changed

+94
-42
lines changed

18 files changed

+94
-42
lines changed

src/liballoc/arc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ mod tests {
311311

312312
task::spawn(proc() {
313313
let arc_v: Arc<Vec<int>> = rx.recv();
314-
assert_eq!(*arc_v.get(3), 4);
314+
assert_eq!((*arc_v)[3], 4);
315315
});
316316

317317
tx.send(arc_v.clone());
318318

319-
assert_eq!(*arc_v.get(2), 3);
320-
assert_eq!(*arc_v.get(4), 5);
319+
assert_eq!((*arc_v)[2], 3);
320+
assert_eq!((*arc_v)[4], 5);
321321

322322
info!("{:?}", arc_v);
323323
}

src/libcollections/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
131131
/// let mut map = HashMap::new();
132132
/// assert_eq!(map.insert("key", 2i), true);
133133
/// assert_eq!(map.insert("key", 9i), false);
134-
/// assert_eq!(map.get(&"key"), &9i);
134+
/// assert_eq!(map["key"], 9i);
135135
/// ```
136136
#[inline]
137137
fn insert(&mut self, key: K, value: V) -> bool {
@@ -171,7 +171,7 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
171171
///
172172
/// map.insert("a", 1i);
173173
/// assert_eq!(map.swap("a", 37i), Some(1i));
174-
/// assert_eq!(map.get(&"a"), &37i);
174+
/// assert_eq!(map["a"], 37i);
175175
/// ```
176176
fn swap(&mut self, k: K, v: V) -> Option<V>;
177177

@@ -203,7 +203,7 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
203203
/// Some(x) => *x = 7i,
204204
/// None => (),
205205
/// }
206-
/// assert_eq!(map.get(&"a"), &7i);
206+
/// assert_eq!(map["a"], 7i);
207207
/// ```
208208
fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>;
209209
}

src/libcollections/ringbuf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ mod tests {
542542
use vec::Vec;
543543

544544
#[test]
545+
#[allow(deprecated)]
545546
fn test_simple() {
546547
let mut d = RingBuf::new();
547548
assert_eq!(d.len(), 0u);
@@ -587,6 +588,7 @@ mod tests {
587588
}
588589

589590
#[test]
591+
#[allow(deprecated)]
590592
fn test_boxes() {
591593
let a: Gc<int> = box(GC) 5;
592594
let b: Gc<int> = box(GC) 72;

src/libcollections/slice.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ mod tests {
904904
}
905905

906906
#[test]
907+
#[allow(deprecated)]
907908
fn test_initn() {
908909
let mut a = vec![11i, 12, 13];
909910
let b: &[int] = &[11, 12, 13];
@@ -1303,6 +1304,7 @@ mod tests {
13031304
}
13041305

13051306
#[test]
1307+
#[allow(deprecated)]
13061308
fn test_bsearch_elem() {
13071309
assert_eq!([1i,2,3,4,5].bsearch_elem(&5), Some(4));
13081310
assert_eq!([1i,2,3,4,5].bsearch_elem(&4), Some(3));
@@ -1350,11 +1352,11 @@ mod tests {
13501352
#[test]
13511353
fn test_reverse() {
13521354
let mut v: Vec<int> = vec![10i, 20];
1353-
assert_eq!(*v.get(0), 10);
1354-
assert_eq!(*v.get(1), 20);
1355+
assert_eq!(v[0], 10);
1356+
assert_eq!(v[1], 20);
13551357
v.reverse();
1356-
assert_eq!(*v.get(0), 20);
1357-
assert_eq!(*v.get(1), 10);
1358+
assert_eq!(v[0], 20);
1359+
assert_eq!(v[1], 10);
13581360

13591361
let mut v3: Vec<int> = vec![];
13601362
v3.reverse();
@@ -1462,6 +1464,7 @@ mod tests {
14621464
}
14631465

14641466
#[test]
1467+
#[allow(deprecated)]
14651468
fn test_shift() {
14661469
let mut x = vec![1i, 2, 3];
14671470
assert_eq!(x.shift(), Some(1));
@@ -1901,6 +1904,7 @@ mod tests {
19011904
}
19021905

19031906
#[test]
1907+
#[allow(deprecated)]
19041908
fn test_copy_from() {
19051909
let mut a = [1i,2,3,4,5];
19061910
let b = [6i,7,8];

src/libcollections/smallintmap.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ impl<V:Clone> SmallIntMap<V> {
348348
/// let mut map = SmallIntMap::new();
349349
///
350350
/// // Key does not exist, will do a simple insert
351-
/// assert!(map.update(1, vec![1i, 2], |old, new| old.append(new.as_slice())));
351+
/// assert!(map.update(1, vec![1i, 2], |mut old, new| { old.extend(new.into_iter()); old }));
352352
/// assert_eq!(map[1], vec![1i, 2]);
353353
///
354354
/// // Key exists, update the value
355-
/// assert!(!map.update(1, vec![3i, 4], |old, new| old.append(new.as_slice())));
355+
/// assert!(!map.update(1, vec![3i, 4], |mut old, new| { old.extend(new.into_iter()); old }));
356356
/// assert_eq!(map[1], vec![1i, 2, 3, 4]);
357357
/// ```
358358
pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool {
@@ -452,7 +452,7 @@ impl<V> Index<uint, V> for SmallIntMap<V> {
452452
}*/
453453

454454
macro_rules! iterator {
455-
(impl $name:ident -> $elem:ty, $getter:ident) => {
455+
(impl $name:ident -> $elem:ty, $($getter:ident),+) => {
456456
impl<'a, T> Iterator<$elem> for $name<'a, T> {
457457
#[inline]
458458
fn next(&mut self) -> Option<$elem> {
@@ -462,7 +462,7 @@ macro_rules! iterator {
462462
if elem.is_some() {
463463
let index = self.front;
464464
self.front += 1;
465-
return Some((index, elem. $getter ()));
465+
return Some((index, elem $(. $getter ())+));
466466
}
467467
}
468468
_ => ()
@@ -481,7 +481,7 @@ macro_rules! iterator {
481481
}
482482

483483
macro_rules! double_ended_iterator {
484-
(impl $name:ident -> $elem:ty, $getter:ident) => {
484+
(impl $name:ident -> $elem:ty, $($getter:ident),+) => {
485485
impl<'a, T> DoubleEndedIterator<$elem> for $name<'a, T> {
486486
#[inline]
487487
fn next_back(&mut self) -> Option<$elem> {
@@ -490,7 +490,7 @@ macro_rules! double_ended_iterator {
490490
Some(elem) => {
491491
if elem.is_some() {
492492
self.back -= 1;
493-
return Some((self.back, elem. $getter ()));
493+
return Some((self.back, elem$(. $getter ())+));
494494
}
495495
}
496496
_ => ()
@@ -510,8 +510,8 @@ pub struct Entries<'a, T:'a> {
510510
iter: slice::Items<'a, Option<T>>
511511
}
512512

513-
iterator!(impl Entries -> (uint, &'a T), get_ref)
514-
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
513+
iterator!(impl Entries -> (uint, &'a T), as_ref, unwrap)
514+
double_ended_iterator!(impl Entries -> (uint, &'a T), as_ref, unwrap)
515515

516516
/// Forward iterator over the key-value pairs of a map, with the
517517
/// values being mutable.
@@ -521,8 +521,8 @@ pub struct MutEntries<'a, T:'a> {
521521
iter: slice::MutItems<'a, Option<T>>
522522
}
523523

524-
iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
525-
double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
524+
iterator!(impl MutEntries -> (uint, &'a mut T), as_mut, unwrap)
525+
double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), as_mut, unwrap)
526526

527527
/// Forward iterator over the keys of a map
528528
pub type Keys<'a, T> =

src/libcollections/trie.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<T> TrieMap<T> {
434434
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
435435
bound!(MutEntries, self = self,
436436
key = key, is_upper = upper,
437-
slice_from = mut_slice_from, iter = mut_iter,
437+
slice_from = slice_from_mut, iter = iter_mut,
438438
mutability = mut)
439439
}
440440

@@ -1020,7 +1020,7 @@ macro_rules! iterator_impl {
10201020
}
10211021

10221022
iterator_impl! { Entries, iter = iter, mutability = }
1023-
iterator_impl! { MutEntries, iter = mut_iter, mutability = mut }
1023+
iterator_impl! { MutEntries, iter = iter_mut, mutability = mut }
10241024

10251025
/// A forward iterator over a set.
10261026
pub struct SetItems<'a> {

src/libcollections/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ impl<T> Vec<T> {
960960
/// # Example
961961
///
962962
/// ```
963+
/// #![allow(deprecated)]
963964
/// let vec = vec![1i, 2, 3, 4];
964965
/// assert!(vec.tailn(2) == [3, 4]);
965966
/// ```
@@ -1065,6 +1066,7 @@ impl<T> Vec<T> {
10651066
/// # Example
10661067
///
10671068
/// ```
1069+
/// #![allow(deprecated)]
10681070
/// let mut vec = vec![1i, 2, 3];
10691071
/// assert!(vec.shift() == Some(1));
10701072
/// assert_eq!(vec, vec![2, 3]);

src/libcore/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,11 @@ pub trait MutableCloneableSlice<T> {
10621062
/// let mut dst = [0i, 0, 0];
10631063
/// let src = [1i, 2];
10641064
///
1065-
/// assert!(dst.copy_from(src) == 2);
1065+
/// assert!(dst.clone_from_slice(src) == 2);
10661066
/// assert!(dst == [1, 2, 0]);
10671067
///
10681068
/// let src2 = [3i, 4, 5, 6];
1069-
/// assert!(dst.copy_from(src2) == 3);
1069+
/// assert!(dst.clone_from_slice(src2) == 3);
10701070
/// assert!(dst == [3i, 4, 5]);
10711071
/// ```
10721072
fn clone_from_slice(self, &[T]) -> uint;

src/libcoretest/cmp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn test_ordering_order() {
4242
}
4343

4444
#[test]
45+
#[allow(deprecated)]
4546
fn test_lexical_ordering() {
4647
fn t(o1: Ordering, o2: Ordering, e: Ordering) {
4748
assert_eq!(lexical_ordering(o1, o2), e);

src/libcoretest/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ fn test_ord() {
244244
}
245245

246246
#[test]
247+
#[allow(deprecated)]
247248
fn test_mutate() {
248249
let mut x = Some(3i);
249250
assert!(x.mutate(|i| i+1));

src/libgetopts/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ mod tests {
11421142
Ok(ref m) => {
11431143
// The next variable after the flag is just a free argument
11441144

1145-
assert!(*m.free.get(0) == "20".to_string());
1145+
assert!(m.free[0] == "20".to_string());
11461146
}
11471147
_ => fail!()
11481148
}
@@ -1298,8 +1298,8 @@ mod tests {
12981298
assert!(m.opt_present("t"));
12991299
assert_eq!(m.opt_str("t").unwrap(), "20".to_string());
13001300
let pair = m.opt_strs("test");
1301-
assert!(*pair.get(0) == "20".to_string());
1302-
assert!(*pair.get(1) == "30".to_string());
1301+
assert!(pair[0] == "20".to_string());
1302+
assert!(pair[1] == "30".to_string());
13031303
}
13041304
_ => fail!()
13051305
}
@@ -1351,19 +1351,19 @@ mod tests {
13511351
let rs = getopts(args.as_slice(), opts.as_slice());
13521352
match rs {
13531353
Ok(ref m) => {
1354-
assert!(*m.free.get(0) == "prog".to_string());
1355-
assert!(*m.free.get(1) == "free1".to_string());
1354+
assert!(m.free[0] == "prog".to_string());
1355+
assert!(m.free[1] == "free1".to_string());
13561356
assert_eq!(m.opt_str("s").unwrap(), "20".to_string());
1357-
assert!(*m.free.get(2) == "free2".to_string());
1357+
assert!(m.free[2] == "free2".to_string());
13581358
assert!((m.opt_present("flag")));
13591359
assert_eq!(m.opt_str("long").unwrap(), "30".to_string());
13601360
assert!((m.opt_present("f")));
13611361
let pair = m.opt_strs("m");
1362-
assert!(*pair.get(0) == "40".to_string());
1363-
assert!(*pair.get(1) == "50".to_string());
1362+
assert!(pair[0] == "40".to_string());
1363+
assert!(pair[1] == "50".to_string());
13641364
let pair = m.opt_strs("n");
1365-
assert!(*pair.get(0) == "-A B".to_string());
1366-
assert!(*pair.get(1) == "-60 70".to_string());
1365+
assert!(pair[0] == "-A B".to_string());
1366+
assert!(pair[1] == "-60 70".to_string());
13671367
assert!((!m.opt_present("notpresent")));
13681368
}
13691369
_ => fail!()

src/libglob/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ impl Pattern {
336336
* # Example
337337
*
338338
* ```rust
339+
* #![allow(deprecated)]
339340
* use glob::Pattern;
340341
*
341342
* assert!(Pattern::new("c?t").matches("cat"));

src/libnum/integer.rs

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub trait Integer: Num + PartialOrd
1818
/// # Examples
1919
///
2020
/// ```
21+
/// # #![allow(deprecated)]
2122
/// # use num::Integer;
2223
/// assert!(( 8i).div_floor(& 3) == 2);
2324
/// assert!(( 8i).div_floor(&-3) == -3);
@@ -34,6 +35,7 @@ pub trait Integer: Num + PartialOrd
3435
/// Floored integer modulo, satisfying:
3536
///
3637
/// ```
38+
/// # #![allow(deprecated)]
3739
/// # use num::Integer;
3840
/// # let n = 1i; let d = 1i;
3941
/// assert!(n.div_floor(&d) * d + n.mod_floor(&d) == n)
@@ -42,6 +44,7 @@ pub trait Integer: Num + PartialOrd
4244
/// # Examples
4345
///
4446
/// ```
47+
/// # #![allow(deprecated)]
4548
/// # use num::Integer;
4649
/// assert!(( 8i).mod_floor(& 3) == 2);
4750
/// assert!(( 8i).mod_floor(&-3) == -1);
@@ -60,6 +63,7 @@ pub trait Integer: Num + PartialOrd
6063
/// # Examples
6164
///
6265
/// ```
66+
/// # #![allow(deprecated)]
6367
/// # use num::Integer;
6468
/// assert_eq!(6i.gcd(&8), 2);
6569
/// assert_eq!(7i.gcd(&3), 1);
@@ -71,6 +75,7 @@ pub trait Integer: Num + PartialOrd
7175
/// # Examples
7276
///
7377
/// ```
78+
/// # #![allow(deprecated)]
7479
/// # use num::Integer;
7580
/// assert_eq!(7i.lcm(&3), 21);
7681
/// assert_eq!(2i.lcm(&4), 4);
@@ -86,6 +91,7 @@ pub trait Integer: Num + PartialOrd
8691
/// # Examples
8792
///
8893
/// ```
94+
/// # #![allow(deprecated)]
8995
/// # use num::Integer;
9096
/// assert_eq!(9i.is_multiple_of(&3), true);
9197
/// assert_eq!(3i.is_multiple_of(&9), false);
@@ -97,6 +103,7 @@ pub trait Integer: Num + PartialOrd
97103
/// # Examples
98104
///
99105
/// ```
106+
/// # #![allow(deprecated)]
100107
/// # use num::Integer;
101108
/// assert_eq!(3i.is_even(), false);
102109
/// assert_eq!(4i.is_even(), true);
@@ -108,6 +115,7 @@ pub trait Integer: Num + PartialOrd
108115
/// # Examples
109116
///
110117
/// ```
118+
/// # #![allow(deprecated)]
111119
/// # use num::Integer;
112120
/// assert_eq!(3i.is_odd(), true);
113121
/// assert_eq!(4i.is_odd(), false);
@@ -120,6 +128,7 @@ pub trait Integer: Num + PartialOrd
120128
/// # Examples
121129
///
122130
/// ```
131+
/// # #![allow(deprecated)]
123132
/// # use num::Integer;
124133
/// assert_eq!(( 8i).div_rem( &3), ( 2, 2));
125134
/// assert_eq!(( 8i).div_rem(&-3), (-2, 2));
@@ -142,6 +151,7 @@ pub trait Integer: Num + PartialOrd
142151
/// # Examples
143152
///
144153
/// ```
154+
/// # #![allow(deprecated)]
145155
/// # use num::Integer;
146156
/// assert_eq!(( 8i).div_mod_floor( &3), ( 2, 2));
147157
/// assert_eq!(( 8i).div_mod_floor(&-3), (-3, -1));

0 commit comments

Comments
 (0)