diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2020-11-22 15:51:05 +0100 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2020-11-22 15:51:05 +0100 |
| commit | cb406848eccc3665dfadb241d94fe27137bd0dcb (patch) | |
| tree | c0583aab0b48a3b693417a92411f744ba40d188d | |
| parent | e69fcea6094e89253e1412a99f890c6db5ea62ef (diff) | |
| download | rust-cb406848eccc3665dfadb241d94fe27137bd0dcb.tar.gz rust-cb406848eccc3665dfadb241d94fe27137bd0dcb.zip | |
Add some more tests
| -rw-r--r-- | src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs | 24 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs new file mode 100644 index 00000000000..6a511f4ed3e --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs @@ -0,0 +1,27 @@ +//! Basic test for calling methods on generic type parameters in `const fn`. + +// check-pass + +#![feature(const_fn)] +#![feature(const_trait_impl)] +#![allow(incomplete_features)] + +struct S; + +impl const PartialEq for S { + fn eq(&self, _: &S) -> bool { + true + } +} + +const fn equals_self<T: PartialEq>(t: &T) -> bool { + *t == *t +} + +const fn equals_self_wrapper<T: PartialEq>(t: &T) -> bool { + equals_self(t) +} + +pub const EQ: bool = equals_self_wrapper(&S); + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs new file mode 100644 index 00000000000..b39d27779f4 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs @@ -0,0 +1,24 @@ +// check-pass + +#![feature(const_fn)] +#![feature(const_trait_impl)] +#![feature(const_trait_bound_opt_out)] +#![allow(incomplete_features)] + +struct S; + +impl const PartialEq for S { + fn eq(&self, _: &S) -> bool { + true + } +} + +// This duplicate bound should not result in ambiguities. It should be equivalent to a single const +// bound. +const fn equals_self<T: PartialEq + ?const PartialEq>(t: &T) -> bool { + *t == *t +} + +pub const EQ: bool = equals_self(&S); + +fn main() {} |
