diff options
| author | Luca Versari <veluca93@gmail.com> | 2024-07-13 19:35:05 +0200 |
|---|---|---|
| committer | Luca Versari <veluca93@gmail.com> | 2024-11-01 22:24:35 +0100 |
| commit | c8b76bcf58298cced4ef3ca9dd823eb318fc11f5 (patch) | |
| tree | 3418691183ea0ba07f66ad7a2aba5ce557105dff /tests/crashes | |
| parent | 4d296eabe4c5cfbce9bb68e6221bca2165aae97b (diff) | |
| download | rust-c8b76bcf58298cced4ef3ca9dd823eb318fc11f5.tar.gz rust-c8b76bcf58298cced4ef3ca9dd823eb318fc11f5.zip | |
Emit warning when calling/declaring functions with unavailable vectors.
On some architectures, vector types may have a different ABI depending on whether the relevant target features are enabled. (The ABI when the feature is disabled is often not specified, but LLVM implements some de-facto ABI.) As discussed in rust-lang/lang-team#235, this turns out to very easily lead to unsound code. This commit makes it a post-monomorphization future-incompat warning to declare or call functions using those vector types in a context in which the corresponding target features are disabled, if using an ABI for which the difference is relevant. This ensures that these functions are always called with a consistent ABI. See the [nomination comment](https://github.com/rust-lang/rust/pull/127731#issuecomment-2288558187) for more discussion. Part of #116558
Diffstat (limited to 'tests/crashes')
| -rw-r--r-- | tests/crashes/131342-2.rs | 40 | ||||
| -rw-r--r-- | tests/crashes/131342.rs | 17 |
2 files changed, 8 insertions, 49 deletions
diff --git a/tests/crashes/131342-2.rs b/tests/crashes/131342-2.rs deleted file mode 100644 index 79b6a837a49..00000000000 --- a/tests/crashes/131342-2.rs +++ /dev/null @@ -1,40 +0,0 @@ -//@ known-bug: #131342 -// see also: 131342.rs - -fn main() { - problem_thingy(Once); -} - -struct Once; - -impl Iterator for Once { - type Item = (); -} - -fn problem_thingy(items: impl Iterator) { - let peeker = items.peekable(); - problem_thingy(&peeker); -} - -trait Iterator { - type Item; - - fn peekable(self) -> Peekable<Self> - where - Self: Sized, - { - loop {} - } -} - -struct Peekable<I: Iterator> { - _peeked: I::Item, -} - -impl<I: Iterator> Iterator for Peekable<I> { - type Item = I::Item; -} - -impl<I: Iterator + ?Sized> Iterator for &I { - type Item = I::Item; -} diff --git a/tests/crashes/131342.rs b/tests/crashes/131342.rs index 7f7ee9c9ac1..f4404092917 100644 --- a/tests/crashes/131342.rs +++ b/tests/crashes/131342.rs @@ -1,16 +1,15 @@ //@ known-bug: #131342 -// see also: 131342-2.rs fn main() { - let mut items = vec![1, 2, 3, 4, 5].into_iter(); - problem_thingy(&mut items); + let mut items = vec![1, 2, 3, 4, 5].into_iter(); + problem_thingy(&mut items); } fn problem_thingy(items: &mut impl Iterator<Item = u8>) { - let mut peeker = items.peekable(); - match peeker.peek() { - Some(_) => (), - None => return (), - } - problem_thingy(&mut peeker); + let mut peeker = items.peekable(); + match peeker.peek() { + Some(_) => (), + None => return (), + } + problem_thingy(&mut peeker); } |
