From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/array-slice-vec/slice.rs | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/ui/array-slice-vec/slice.rs (limited to 'src/test/ui/array-slice-vec/slice.rs') diff --git a/src/test/ui/array-slice-vec/slice.rs b/src/test/ui/array-slice-vec/slice.rs new file mode 100644 index 000000000..a514e2027 --- /dev/null +++ b/src/test/ui/array-slice-vec/slice.rs @@ -0,0 +1,81 @@ +// run-pass +#![allow(unused_variables)] + +// Test slicing sugar. + +extern crate core; +use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, RangeFull}; + +static mut COUNT: usize = 0; + +struct Foo; + +impl Index> for Foo { + type Output = Foo; + fn index(&self, index: Range) -> &Foo { + unsafe { COUNT += 1; } + self + } +} +impl Index> for Foo { + type Output = Foo; + fn index(&self, index: RangeTo) -> &Foo { + unsafe { COUNT += 1; } + self + } +} +impl Index> for Foo { + type Output = Foo; + fn index(&self, index: RangeFrom) -> &Foo { + unsafe { COUNT += 1; } + self + } +} +impl Index for Foo { + type Output = Foo; + fn index(&self, _index: RangeFull) -> &Foo { + unsafe { COUNT += 1; } + self + } +} + +impl IndexMut> for Foo { + fn index_mut(&mut self, index: Range) -> &mut Foo { + unsafe { COUNT += 1; } + self + } +} +impl IndexMut> for Foo { + fn index_mut(&mut self, index: RangeTo) -> &mut Foo { + unsafe { COUNT += 1; } + self + } +} +impl IndexMut> for Foo { + fn index_mut(&mut self, index: RangeFrom) -> &mut Foo { + unsafe { COUNT += 1; } + self + } +} +impl IndexMut for Foo { + fn index_mut(&mut self, _index: RangeFull) -> &mut Foo { + unsafe { COUNT += 1; } + self + } +} + + +fn main() { + let mut x = Foo; + let _ = &x[..]; + let _ = &x[Foo..]; + let _ = &x[..Foo]; + let _ = &x[Foo..Foo]; + let _ = &mut x[..]; + let _ = &mut x[Foo..]; + let _ = &mut x[..Foo]; + let _ = &mut x[Foo..Foo]; + unsafe { + assert_eq!(COUNT, 8); + } +} -- cgit v1.2.3