-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let's say that we want to create a `Send` variant of a trait but we don't need a non-`Send` variant of that trait at all. We could of course just write that trait, but adding the `Send` bounds in all the right places could be annoying. In this commit, we allow simply omitting the new variant name from the call to `make`. When called that way, we use the name from the item to emit only one variant with the bounds applied. We don't emit the original item. For completeness and explicit disambiguation, we support prefixing the bounds with a colon (but giving no variant name). Similarly, for completeness, we support giving the same name as the trait item. In both of these cases, we just emit the one variant. Since these are for completeness, we don't advertise these syntaxes in the documentation. That is, we now support: - `make(NAME: BOUNDS)` - `make(NAME:)` - `make(:BOUNDS)` - `make(BOUNDS)` This resolves #18.
- Loading branch information
1 parent
f81bb09
commit c8a15fe
Showing
8 changed files
with
336 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[trait_variant::make(Send + Sync)] | ||
pub trait Trait { | ||
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: Send + Sync>(_: T) {} | ||
|
||
#[test] | ||
fn test() { | ||
fn inner<T: Trait>(x: T) { | ||
let (a, b) = ((), ()); | ||
is_bounded(<T as Trait>::assoc_async_fn_no_ret(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method_no_ret(&x, a, b)); | ||
is_bounded(<T as Trait>::assoc_async_fn(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method(&x, a, b)); | ||
// FIXME: See #17. | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn_no_ret(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method_no_ret(&x, a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method(&x, a, b)); | ||
} | ||
inner(()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[trait_variant::make(: Send + Sync)] | ||
pub trait Trait { | ||
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: Send + Sync>(_: T) {} | ||
|
||
#[test] | ||
fn test() { | ||
fn inner<T: Trait>(x: T) { | ||
let (a, b) = ((), ()); | ||
is_bounded(<T as Trait>::assoc_async_fn_no_ret(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method_no_ret(&x, a, b)); | ||
is_bounded(<T as Trait>::assoc_async_fn(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method(&x, a, b)); | ||
// FIXME: See #17. | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn_no_ret(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method_no_ret(&x, a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method(&x, a, b)); | ||
} | ||
inner(()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2023 Google LLC | ||
// Copyright (c) 2023 Various contributors (see git history) | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[trait_variant::make(Trait:)] | ||
#[allow(async_fn_in_trait)] | ||
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>(_: T) {} | ||
|
||
#[test] | ||
fn test() { | ||
fn inner<T: Trait>(x: T) { | ||
let (a, b) = ((), ()); | ||
is_bounded(<T as Trait>::assoc_async_fn_no_ret(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method_no_ret(&x, a, b)); | ||
is_bounded(<T as Trait>::assoc_async_fn(a, b)); | ||
is_bounded(<T as Trait>::assoc_async_method(&x, a, b)); | ||
// FIXME: See #17. | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn_no_ret(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method_no_ret(&x, a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_fn(a, b)); | ||
//is_bounded(<T as Trait>::dft_assoc_async_method(&x, a, b)); | ||
} | ||
inner(()); | ||
} |
Oops, something went wrong.