diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/mir/mir-inlining | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/mir/mir-inlining')
-rw-r--r-- | tests/ui/mir/mir-inlining/array-clone-with-generic-size.rs | 11 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-100550-unnormalized-projection.rs | 30 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-45493.rs | 17 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-45885.rs | 29 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-68347.rs | 28 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-77306-1.rs | 17 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-77306-2.rs | 32 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/ice-issue-77564.rs | 38 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/no-trait-method-issue-40473.rs | 16 | ||||
-rw-r--r-- | tests/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs | 11 |
10 files changed, 229 insertions, 0 deletions
diff --git a/tests/ui/mir/mir-inlining/array-clone-with-generic-size.rs b/tests/ui/mir/mir-inlining/array-clone-with-generic-size.rs new file mode 100644 index 000000000..e36e8bd74 --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-100550-unnormalized-projection.rs b/tests/ui/mir/mir-inlining/ice-issue-100550-unnormalized-projection.rs new file mode 100644 index 000000000..f67b07354 --- /dev/null +++ b/tests/ui/mir/mir-inlining/ice-issue-100550-unnormalized-projection.rs @@ -0,0 +1,30 @@ +// This test verifies that we do not ICE due to MIR inlining in case of normalization failure +// in a projection. +// +// compile-flags: --crate-type lib -C opt-level=3 +// build-pass + +pub trait Trait { + type Associated; +} +impl<T> Trait for T { + type Associated = T; +} + +pub struct Struct<T>(<T as Trait>::Associated); + +pub fn foo<T>() -> Struct<T> +where + T: Trait, +{ + bar() +} + +#[inline] +fn bar<T>() -> Struct<T> { + Struct(baz()) +} + +fn baz<T>() -> T { + unimplemented!() +} diff --git a/tests/ui/mir/mir-inlining/ice-issue-45493.rs b/tests/ui/mir/mir-inlining/ice-issue-45493.rs new file mode 100644 index 000000000..04a23212e --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-45885.rs b/tests/ui/mir/mir-inlining/ice-issue-45885.rs new file mode 100644 index 000000000..09b1279ef --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-68347.rs b/tests/ui/mir/mir-inlining/ice-issue-68347.rs new file mode 100644 index 000000000..7c1352509 --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-77306-1.rs b/tests/ui/mir/mir-inlining/ice-issue-77306-1.rs new file mode 100644 index 000000000..ef05ff9ce --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-77306-2.rs b/tests/ui/mir/mir-inlining/ice-issue-77306-2.rs new file mode 100644 index 000000000..cb2084013 --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/ice-issue-77564.rs b/tests/ui/mir/mir-inlining/ice-issue-77564.rs new file mode 100644 index 000000000..0d3fbfe5d --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/no-trait-method-issue-40473.rs b/tests/ui/mir/mir-inlining/no-trait-method-issue-40473.rs new file mode 100644 index 000000000..8b3cb703d --- /dev/null +++ b/tests/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/tests/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs b/tests/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs new file mode 100644 index 000000000..e26206826 --- /dev/null +++ b/tests/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); +} |