From f81bb091b3fd7947d1eb772517b377e6efa968ac Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sat, 10 Feb 2024 00:05:48 +0000 Subject: [PATCH] Add `name-colon-bounds` test Let's add a test case using the full `NAME: BOUNDS` syntax to verify that compilation works and that we get the bounds that we want. --- trait-variant/tests/name-colon-bounds.rs | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 trait-variant/tests/name-colon-bounds.rs diff --git a/trait-variant/tests/name-colon-bounds.rs b/trait-variant/tests/name-colon-bounds.rs new file mode 100644 index 0000000..4a1f217 --- /dev/null +++ b/trait-variant/tests/name-colon-bounds.rs @@ -0,0 +1,65 @@ +// Copyright (c) 2023 Google LLC +// Copyright (c) 2023 Various contributors (see git history) +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[trait_variant::make(Trait: Send + Sync)] +pub trait LocalTrait { + const CONST: &'static (); + type Gat<'a> + where + Self: 'a; + async fn assoc_async_fn_no_ret(a: (), b: ()); + async fn assoc_async_method_no_ret(&self, a: (), b: ()); + async fn assoc_async_fn(a: (), b: ()) -> (); + async fn assoc_async_method(&self, a: (), b: ()) -> (); + fn assoc_sync_fn_no_ret(a: (), b: ()); + fn assoc_sync_method_no_ret(&self, a: (), b: ()); + fn assoc_sync_fn(a: (), b: ()) -> (); + fn assoc_sync_method(&self, a: (), b: ()) -> (); + // FIXME: See #17. + //async fn dft_assoc_async_fn_no_ret(_a: (), _b: ()) {} + //async fn dft_assoc_async_method_no_ret(&self, _a: (), _b: ()) {} + //async fn dft_assoc_async_fn(_a: (), _b: ()) -> () {} + //async fn dft_assoc_async_method(&self, _a: (), _b: ()) -> () {} + fn dft_assoc_sync_fn_no_ret(_a: (), _b: ()) {} + fn dft_assoc_sync_method_no_ret(&self, _a: (), _b: ()) {} + fn dft_assoc_sync_fn(_a: (), _b: ()) -> () {} + fn dft_assoc_sync_method(&self, _a: (), _b: ()) -> () {} +} + +impl Trait for () { + const CONST: &'static () = &(); + type Gat<'a> = (); + async fn assoc_async_fn_no_ret(_a: (), _b: ()) {} + async fn assoc_async_method_no_ret(&self, _a: (), _b: ()) {} + async fn assoc_async_fn(_a: (), _b: ()) -> () {} + async fn assoc_async_method(&self, _a: (), _b: ()) -> () {} + fn assoc_sync_fn_no_ret(_a: (), _b: ()) {} + fn assoc_sync_method_no_ret(&self, _a: (), _b: ()) {} + fn assoc_sync_fn(_a: (), _b: ()) -> () {} + fn assoc_sync_method(&self, _a: (), _b: ()) -> () {} +} + +fn is_bounded(_: T) {} + +#[test] +fn test() { + fn inner(x: T) { + let (a, b) = ((), ()); + is_bounded(::assoc_async_fn_no_ret(a, b)); + is_bounded(::assoc_async_method_no_ret(&x, a, b)); + is_bounded(::assoc_async_fn(a, b)); + is_bounded(::assoc_async_method(&x, a, b)); + // FIXME: See #17. + //is_bounded(::dft_assoc_async_fn_no_ret(a, b)); + //is_bounded(::dft_assoc_async_method_no_ret(&x, a, b)); + //is_bounded(::dft_assoc_async_fn(a, b)); + //is_bounded(::dft_assoc_async_method(&x, a, b)); + } + inner(()); +}