//@ 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 { marker: PhantomData, } impl RawTable { fn iter(&self) -> RawIter { RawIter { marker: PhantomData } } } struct RawIter { marker: PhantomData, } impl Iterator for RawIter { type Item = (); fn next(&mut self) -> Option<()> { None } } struct HashMap { table: RawTable, } struct Iter { inner: RawIter, // Removing this breaks the reproducer } impl IntoIterator for &HashMap { type Item = T; type IntoIter = Iter; fn into_iter(self) -> Iter { Iter { inner: self.table.iter() } } } impl Iterator for Iter { type Item = T; fn next(&mut self) -> Option { None } } pub fn main() { let maybe_hash_set: Option> = None; for _ in maybe_hash_set.as_ref().unwrap_or(&HashMap { table: RawTable { marker: PhantomData } }) { } }