From c535326537964e44ee70d4f58a8b0985e3ab5574 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 16 Aug 2023 17:47:34 +0000 Subject: [PATCH] Add test. --- tests/ui/mir/debug-ref-undef.rs | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/ui/mir/debug-ref-undef.rs diff --git a/tests/ui/mir/debug-ref-undef.rs b/tests/ui/mir/debug-ref-undef.rs new file mode 100644 index 00000000000..37fd22a9dd2 --- /dev/null +++ b/tests/ui/mir/debug-ref-undef.rs @@ -0,0 +1,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 { + 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 } }) + { + } +}