From 160e6304e8e7971d38787e8ca81f154e31f5b772 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 10 Feb 2020 11:26:40 -0800 Subject: [PATCH] Add passing test for `Add` on generic struct --- .../generic-bound.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs diff --git a/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs new file mode 100644 index 000000000000..7829ffe2a38d --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs @@ -0,0 +1,32 @@ +// run-pass + +#![allow(incomplete_features)] +#![feature(const_trait_impl)] +#![feature(const_fn)] + +use std::marker::PhantomData; + +struct S(PhantomData); + +impl Copy for S {} +impl Clone for S { + fn clone(&self) -> Self { + S(PhantomData) + } +} + +impl const std::ops::Add for S { + type Output = Self; + + fn add(self, _: Self) -> Self { + S(std::marker::PhantomData) + } +} + +const fn twice(arg: S) -> S { + arg + arg +} + +fn main() { + let _ = twice(S(PhantomData::)); +}