From 7bf0cb76710e723ac71257e04f4a1bfbbfc87c3c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 7 Jan 2022 10:26:17 -0800 Subject: [PATCH] Add new tests, fix up old tests --- .../ui/autoref-autoderef/deref-into-array.rs | 17 ++++++++++++ .../deref-into-array-generic.rs | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/ui/autoref-autoderef/deref-into-array.rs create mode 100644 src/test/ui/const-generics/deref-into-array-generic.rs diff --git a/src/test/ui/autoref-autoderef/deref-into-array.rs b/src/test/ui/autoref-autoderef/deref-into-array.rs new file mode 100644 index 00000000000..855a82d2f9c --- /dev/null +++ b/src/test/ui/autoref-autoderef/deref-into-array.rs @@ -0,0 +1,17 @@ +// check-pass + +struct Test([T; 1]); + +impl std::ops::Deref for Test { + type Target = [T; 1]; + + fn deref(&self) -> &[T; 1] { + &self.0 + } +} + +fn main() { + let out = Test([(); 1]); + let blah = out.len(); + println!("{}", blah); +} diff --git a/src/test/ui/const-generics/deref-into-array-generic.rs b/src/test/ui/const-generics/deref-into-array-generic.rs new file mode 100644 index 00000000000..7d75af12bdf --- /dev/null +++ b/src/test/ui/const-generics/deref-into-array-generic.rs @@ -0,0 +1,27 @@ +// check-pass + +struct Test([T; N]); + +impl Default for Test { + fn default() -> Self { + Self([T::default(); N]) + } +} + +impl std::ops::Deref for Test { + type Target = [T; N]; + + fn deref(&self) -> &[T; N] { + &self.0 + } +} + +fn test() -> Test { + let test = Test::default(); + println!("{}", test.len()); + test +} + +fn main() { + test(); +}