diff --git a/tests/mir-opt/inline/auxiliary/wrapper.rs b/tests/mir-opt/inline/auxiliary/wrapper.rs new file mode 100644 index 000000000000..35d3ae788239 --- /dev/null +++ b/tests/mir-opt/inline/auxiliary/wrapper.rs @@ -0,0 +1,10 @@ +//@ no-prefer-dynamic +//@ compile-flags: -O + +pub trait Compare { + fn eq(self); +} + +pub fn wrap(a: A) { + Compare::eq(a); +} diff --git a/tests/mir-opt/inline/recursion_limit_prevents_cycle_discovery.rs b/tests/mir-opt/inline/recursion_limit_prevents_cycle_discovery.rs new file mode 100644 index 000000000000..866d6fbd9e97 --- /dev/null +++ b/tests/mir-opt/inline/recursion_limit_prevents_cycle_discovery.rs @@ -0,0 +1,54 @@ +//@ aux-build: wrapper.rs +//@ compile-flags: -Zmir-opt-level=2 -Zinline-mir +// skip-filecheck + +// This is a regression test for https://github.com/rust-lang/rust/issues/146998 + +extern crate wrapper; +use wrapper::{Compare, wrap}; + +pub struct BundleInner; + +impl Compare for BundleInner { + fn eq(self) { + lots_of_calls(); + wrap(Resource::ExtensionValue); + } +} + +pub enum Resource { + Bundle, + ExtensionValue, +} + +impl Compare for Resource { + fn eq(self) { + match self { + Self::Bundle => wrap(BundleInner), + Self::ExtensionValue => lots_of_calls(), + } + } +} + +macro_rules! units { + ($($n: ident)*) => { + $( + struct $n; + + impl Compare for $n { + fn eq(self) { } + } + + wrap($n); + )* + }; +} + +fn lots_of_calls() { + units! { + O1 O2 O3 O4 O5 O6 O7 O8 O9 O10 O11 O12 O13 O14 O15 O16 O17 O18 O19 O20 + O21 O22 O23 O24 O25 O26 O27 O28 O29 O30 O31 O32 O33 O34 O35 O36 O37 O38 O39 O40 + O41 O42 O43 O44 O45 O46 O47 O48 O49 O50 O51 O52 O53 O54 O55 O56 O57 O58 O59 O60 + O61 O62 O63 O64 O65 + } +}