File: into-iter-on-arrays-lint.fixed

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,517,036 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (63 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// run-pass
// run-rustfix
// rustfix-only-machine-applicable

#[allow(unused_must_use, unused_allocation)]
fn main() {
    let small = [1, 2];
    let big = [0u8; 33];

    // Expressions that should trigger the lint
    small.iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    [1, 2].iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    big.iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    [0u8; 33].iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning

    Box::new(small).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new([1, 2]).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new(big).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new([0u8; 33]).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning

    Box::new(Box::new(small)).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new(Box::new([1, 2])).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new(Box::new(big)).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning
    Box::new(Box::new([0u8; 33])).iter();
    //~^ WARNING this method call resolves to `<&[T; N] as IntoIterator>::into_iter`
    //~| WARNING this changes meaning

    // Expressions that should not
    (&[1, 2]).into_iter();
    (&small).into_iter();
    (&[0u8; 33]).into_iter();
    (&big).into_iter();

    for _ in &[1, 2] {}
    (&small as &[_]).into_iter();
    small[..].into_iter();
    std::iter::IntoIterator::into_iter(&[1, 2]);

    #[allow(array_into_iter)]
    [0, 1].into_iter();
}