summaryrefslogtreecommitdiffstats
path: root/tests/ui/mir/debug-ref-undef.rs
blob: 37fd22a9dd2d0e08f311a1a8e819262d676351a9 (plain)
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
// run-pass
// compile-flags: -g -O -Zmir-opt-level=0 -Zinline-mir=y -Zmir-enable-passes=+ReferencePropagation

#![allow(dead_code)]

use std::marker::PhantomData;

struct RawTable<T> {
    marker: PhantomData<T>,
}

impl<T> RawTable<T> {
    fn iter(&self) -> RawIter<T> {
        RawIter { marker: PhantomData }
    }
}

struct RawIter<T> {
    marker: PhantomData<T>,
}

impl<T> Iterator for RawIter<T> {
    type Item = ();
    fn next(&mut self) -> Option<()> {
        None
    }
}

struct HashMap<T> {
    table: RawTable<T>,
}

struct Iter<T> {
    inner: RawIter<T>, // Removing this breaks the reproducer
}

impl<T> IntoIterator for &HashMap<T> {
    type Item = T;
    type IntoIter = Iter<T>;
    fn into_iter(self) -> Iter<T> {
        Iter { inner: self.table.iter() }
    }
}

impl<T> Iterator for Iter<T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        None
    }
}

pub fn main() {
    let maybe_hash_set: Option<HashMap<()>> = None;
    for _ in maybe_hash_set.as_ref().unwrap_or(&HashMap { table: RawTable { marker: PhantomData } })
    {
    }
}