about summary refs log tree commit diff
path: root/tests/mir-opt
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-08-21 22:39:34 +0000
committerMichael Goulet <michael@errs.io>2023-09-19 05:42:23 +0000
commita30ad3a5a6362c31b16d3bd3f21bbae1315bfaec (patch)
tree5dedf5cc643e184ade7eb3da7d05e6d0990e02aa /tests/mir-opt
parent55ce976e06e1dc9590a41cdc262688d4db8d93e4 (diff)
downloadrust-a30ad3a5a6362c31b16d3bd3f21bbae1315bfaec.tar.gz
rust-a30ad3a5a6362c31b16d3bd3f21bbae1315bfaec.zip
Don't resolve generic instances if they may be shadowed by dyn
Diffstat (limited to 'tests/mir-opt')
-rw-r--r--tests/mir-opt/dont_inline_type_id.call.Inline.diff19
-rw-r--r--tests/mir-opt/dont_inline_type_id.rs2
-rw-r--r--tests/mir-opt/inline_generically_if_sized.call.Inline.diff24
-rw-r--r--tests/mir-opt/inline_generically_if_sized.rs17
4 files changed, 43 insertions, 19 deletions
diff --git a/tests/mir-opt/dont_inline_type_id.call.Inline.diff b/tests/mir-opt/dont_inline_type_id.call.Inline.diff
index d67235ddbd2..80cfe07b0cb 100644
--- a/tests/mir-opt/dont_inline_type_id.call.Inline.diff
+++ b/tests/mir-opt/dont_inline_type_id.call.Inline.diff
@@ -5,31 +5,14 @@
       debug s => _1;
       let mut _0: std::any::TypeId;
       let mut _2: &T;
-+     scope 1 (inlined <T as Any>::type_id) {
-+         debug self => _2;
-+         scope 2 (inlined TypeId::of::<T>) {
-+             let _3: u128;
-+             let mut _4: u128;
-+             scope 3 {
-+                 debug t => _3;
-+             }
-+         }
-+     }
   
       bb0: {
           StorageLive(_2);
           _2 = &(*_1);
--         _0 = <T as Any>::type_id(move _2) -> [return: bb1, unwind unreachable];
-+         StorageLive(_3);
-+         _3 = std::intrinsics::type_id::<T>() -> [return: bb1, unwind unreachable];
+          _0 = <T as Any>::type_id(move _2) -> [return: bb1, unwind unreachable];
       }
   
       bb1: {
-+         StorageLive(_4);
-+         _4 = _3;
-+         _0 = TypeId { t: move _4 };
-+         StorageDead(_4);
-+         StorageDead(_3);
           StorageDead(_2);
           return;
       }
diff --git a/tests/mir-opt/dont_inline_type_id.rs b/tests/mir-opt/dont_inline_type_id.rs
index 6f4c21a3ab1..d8a56636094 100644
--- a/tests/mir-opt/dont_inline_type_id.rs
+++ b/tests/mir-opt/dont_inline_type_id.rs
@@ -10,6 +10,6 @@ struct A<T: ?Sized + 'static> {
 }
 
 // EMIT_MIR dont_inline_type_id.call.Inline.diff
-fn call<T: ?Sized + 'static>(s: &T) -> TypeId {
+pub fn call<T: ?Sized + 'static>(s: &T) -> TypeId {
     s.type_id()
 }
diff --git a/tests/mir-opt/inline_generically_if_sized.call.Inline.diff b/tests/mir-opt/inline_generically_if_sized.call.Inline.diff
new file mode 100644
index 00000000000..0cf4565dc99
--- /dev/null
+++ b/tests/mir-opt/inline_generically_if_sized.call.Inline.diff
@@ -0,0 +1,24 @@
+- // MIR for `call` before Inline
++ // MIR for `call` after Inline
+  
+  fn call(_1: &T) -> i32 {
+      debug s => _1;
+      let mut _0: i32;
+      let mut _2: &T;
++     scope 1 (inlined <T as Foo>::bar) {
++         debug self => _2;
++     }
+  
+      bb0: {
+          StorageLive(_2);
+          _2 = &(*_1);
+-         _0 = <T as Foo>::bar(move _2) -> [return: bb1, unwind unreachable];
+-     }
+- 
+-     bb1: {
++         _0 = const 0_i32;
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/inline_generically_if_sized.rs b/tests/mir-opt/inline_generically_if_sized.rs
new file mode 100644
index 00000000000..1acfff7a56b
--- /dev/null
+++ b/tests/mir-opt/inline_generically_if_sized.rs
@@ -0,0 +1,17 @@
+// unit-test: Inline
+// compile-flags: --crate-type=lib -C panic=abort
+
+trait Foo {
+    fn bar(&self) -> i32;
+}
+
+impl<T> Foo for T {
+    fn bar(&self) -> i32 {
+        0
+    }
+}
+
+// EMIT_MIR inline_generically_if_sized.call.Inline.diff
+pub fn call<T>(s: &T) -> i32 {
+    s.bar()
+}