summaryrefslogtreecommitdiffstats
path: root/src/test/ui/mir/mir-inlining
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/mir/mir-inlining
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/mir/mir-inlining')
-rw-r--r--src/test/ui/mir/mir-inlining/array-clone-with-generic-size.rs11
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-45493.rs17
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-45885.rs29
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-68347.rs28
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs17
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-77306-2.rs32
-rw-r--r--src/test/ui/mir/mir-inlining/ice-issue-77564.rs38
-rw-r--r--src/test/ui/mir/mir-inlining/no-trait-method-issue-40473.rs16
-rw-r--r--src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs11
9 files changed, 199 insertions, 0 deletions
diff --git a/src/test/ui/mir/mir-inlining/array-clone-with-generic-size.rs b/src/test/ui/mir/mir-inlining/array-clone-with-generic-size.rs
new file mode 100644
index 000000000..e36e8bd74
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/array-clone-with-generic-size.rs
@@ -0,0 +1,11 @@
+// Checks that we can build a clone shim for array with generic size.
+// Regression test for issue #79269.
+//
+// build-pass
+// compile-flags: -Zmir-opt-level=3 -Zvalidate-mir
+#[derive(Clone)]
+struct Array<T, const N: usize>([T; N]);
+
+fn main() {
+ let _ = Array([0u32, 1u32, 2u32]).clone();
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-45493.rs b/src/test/ui/mir/mir-inlining/ice-issue-45493.rs
new file mode 100644
index 000000000..04a23212e
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-45493.rs
@@ -0,0 +1,17 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+
+trait Array {
+ type Item;
+}
+
+fn foo<A: Array>() {
+ let _: *mut A::Item = std::ptr::null_mut();
+}
+
+struct Foo;
+impl Array for Foo { type Item = i32; }
+
+fn main() {
+ foo::<Foo>();
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-45885.rs b/src/test/ui/mir/mir-inlining/ice-issue-45885.rs
new file mode 100644
index 000000000..09b1279ef
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-45885.rs
@@ -0,0 +1,29 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+
+pub enum Enum {
+ A,
+ B,
+}
+
+trait SliceIndex {
+ type Output;
+ fn get(&self) -> &Self::Output;
+}
+
+impl SliceIndex for usize {
+ type Output = Enum;
+ #[inline(never)]
+ fn get(&self) -> &Enum {
+ &Enum::A
+ }
+}
+
+#[inline(always)]
+fn index<T: SliceIndex>(t: &T) -> &T::Output {
+ t.get()
+}
+
+fn main() {
+ match *index(&0) { Enum::A => true, _ => false };
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-68347.rs b/src/test/ui/mir/mir-inlining/ice-issue-68347.rs
new file mode 100644
index 000000000..7c1352509
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-68347.rs
@@ -0,0 +1,28 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+pub fn main() {
+ let _x: fn() = handle_debug_column;
+}
+
+fn handle_debug_column() {
+ let sampler = sample_columns();
+
+ let foo = || {
+ sampler.get(17);
+ };
+ foo();
+}
+
+fn sample_columns() -> impl Sampler {
+ ColumnGen {}
+}
+
+struct ColumnGen {}
+
+trait Sampler {
+ fn get(&self, index: i32);
+}
+
+impl Sampler for ColumnGen {
+ fn get(&self, _index: i32) {}
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs b/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs
new file mode 100644
index 000000000..ef05ff9ce
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs
@@ -0,0 +1,17 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+
+// Previously ICEd because we did not normalize during inlining,
+// see https://github.com/rust-lang/rust/pull/77306 for more discussion.
+
+pub fn write() {
+ create()()
+}
+
+pub fn create() -> impl FnOnce() {
+ || ()
+}
+
+fn main() {
+ write();
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-77306-2.rs b/src/test/ui/mir/mir-inlining/ice-issue-77306-2.rs
new file mode 100644
index 000000000..cb2084013
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-77306-2.rs
@@ -0,0 +1,32 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+
+struct Cursor {}
+struct TokenTree {}
+
+impl Iterator for Cursor {
+ type Item = TokenTree;
+
+ fn next(&mut self) -> Option<TokenTree> {
+ None
+ }
+}
+
+fn tokenstream_probably_equal_for_proc_macro() {
+ fn break_tokens(_tree: TokenTree) -> impl Iterator<Item = TokenTree> {
+ let token_trees: Vec<TokenTree> = vec![];
+ token_trees.into_iter()
+ }
+
+ let c1 = Cursor {};
+ let c2 = Cursor {};
+
+ let mut t1 = c1.flat_map(break_tokens);
+ let mut t2 = c2.flat_map(break_tokens);
+
+ for (_t1, _t2) in t1.by_ref().zip(t2.by_ref()) {}
+}
+
+fn main() {
+ tokenstream_probably_equal_for_proc_macro();
+}
diff --git a/src/test/ui/mir/mir-inlining/ice-issue-77564.rs b/src/test/ui/mir/mir-inlining/ice-issue-77564.rs
new file mode 100644
index 000000000..0d3fbfe5d
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/ice-issue-77564.rs
@@ -0,0 +1,38 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+
+use std::mem::MaybeUninit;
+const N: usize = 2;
+
+trait CollectArray<A>: Iterator<Item = A> {
+ fn inner_array(&mut self) -> [A; N];
+ fn collect_array(&mut self) -> [A; N] {
+ let result = self.inner_array();
+ assert!(self.next().is_none());
+ result
+ }
+}
+
+impl<A, I: ?Sized> CollectArray<A> for I
+where
+ I: Iterator<Item = A>,
+{
+ fn inner_array(&mut self) -> [A; N] {
+ let mut result: [MaybeUninit<A>; N] = unsafe { MaybeUninit::uninit().assume_init() };
+ for (dest, item) in result.iter_mut().zip(self) {
+ *dest = MaybeUninit::new(item);
+ }
+ let temp_ptr: *const [MaybeUninit<A>; N] = &result;
+ unsafe { std::ptr::read(temp_ptr as *const [A; N]) }
+ }
+}
+
+fn main() {
+ assert_eq!(
+ [[1, 2], [3, 4]]
+ .iter()
+ .map(|row| row.iter().collect_array())
+ .collect_array(),
+ [[&1, &2], [&3, &4]]
+ );
+}
diff --git a/src/test/ui/mir/mir-inlining/no-trait-method-issue-40473.rs b/src/test/ui/mir/mir-inlining/no-trait-method-issue-40473.rs
new file mode 100644
index 000000000..8b3cb703d
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/no-trait-method-issue-40473.rs
@@ -0,0 +1,16 @@
+// run-pass
+// compile-flags:-Zmir-opt-level=3
+pub trait Foo {
+ fn bar(&self) -> usize { 2 }
+}
+
+impl Foo for () {
+ fn bar(&self) -> usize { 3 }
+}
+
+// Test a case where MIR would inline the default trait method
+// instead of bailing out. Issue #40473.
+fn main() {
+ let result = ().bar();
+ assert_eq!(result, 3);
+}
diff --git a/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs b/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs
new file mode 100644
index 000000000..e26206826
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs
@@ -0,0 +1,11 @@
+// run-pass
+// compile-flags: -Z mir-opt-level=3 -C opt-level=0 -C debuginfo=2
+
+#[inline(never)]
+pub fn foo(bar: usize) -> usize {
+ std::convert::identity(bar)
+}
+
+fn main() {
+ foo(0);
+}