|
| 1 | +// Regression test for the Miri reproducer in rust-lang/rust#156313. |
| 2 | +// |
| 3 | +// The issue's exact recursive example ICEd while evaluating the argument |
| 4 | +// conversion before the recursion mattered. This keeps that same |
| 5 | +// `CustomMut`-to-`CustomRef` call path, but terminates after one recursive |
| 6 | +// call so it can be a pass test once the ICE is fixed. |
| 7 | + |
| 8 | +#![feature(reborrow)] |
| 9 | + |
| 10 | +use std::marker::{CoerceShared, Reborrow}; |
| 11 | + |
| 12 | +#[allow(unused)] |
| 13 | +struct CustomMut<'a, T>(&'a mut T); |
| 14 | +impl<'a, T> Reborrow for CustomMut<'a, T> {} |
| 15 | +impl<'a, T> CoerceShared<CustomRef<'a, T>> for CustomMut<'a, T> {} |
| 16 | + |
| 17 | +struct CustomRef<'a, T>(&'a T); |
| 18 | + |
| 19 | +impl<'a, T> Clone for CustomRef<'a, T> { |
| 20 | + fn clone(&self) -> Self { |
| 21 | + Self(self.0) |
| 22 | + } |
| 23 | +} |
| 24 | +impl<'a, T> Copy for CustomRef<'a, T> {} |
| 25 | + |
| 26 | +fn method(_a: CustomRef<'_, ()>) {} |
| 27 | + |
| 28 | +fn recursive_method(_a: CustomRef<'_, ()>, recurse: bool) { |
| 29 | + if recurse { |
| 30 | + let a = CustomMut(&mut ()); |
| 31 | + recursive_method(a, false); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +fn issue_156313_runtime_reproducer() { |
| 36 | + let a = CustomMut(&mut ()); |
| 37 | + method(a); |
| 38 | +} |
| 39 | + |
| 40 | +fn issue_156313_recursive_call_reproducer() { |
| 41 | + let a = CustomMut(&mut ()); |
| 42 | + recursive_method(a, true); |
| 43 | +} |
| 44 | + |
| 45 | +fn main() { |
| 46 | + issue_156313_runtime_reproducer(); |
| 47 | + issue_156313_recursive_call_reproducer(); |
| 48 | +} |
0 commit comments