Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for GATs #44

Merged
merged 1 commit into from Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
rust:
- stable # It's useful to test applications of these macros to newer features so a 1.53 test doesn't work
- beta # It's useful to test applications of these macros to newer features so a 1.53 test doesn't work (beta to test GATs)
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
Expand Down
5 changes: 2 additions & 3 deletions ambassador/src/register.rs
Expand Up @@ -234,10 +234,9 @@ fn build_trait_items(
TraitItem::Type(TraitItemType {
ident, generics, ..
}) => {
let _where_clause = &generics.where_clause;
let where_clause = &generics.where_clause;
let item = quote! {
type #ident #generics = <$ty as #trait_ident<#gen_pat>>::#ident #generics;
// TODO add #where_clase to appropriate place once it is decided
type #ident #generics = <$ty as #trait_ident<#gen_pat>>::#ident #generics #where_clause;
};
(
item.clone(),
Expand Down
32 changes: 32 additions & 0 deletions ambassador/tests/run-pass/gat.rs
@@ -0,0 +1,32 @@
extern crate ambassador;

use ambassador::{delegatable_trait, Delegate};

#[delegatable_trait]
pub trait StreamingIterator {
type Output<'a>
where
Self: 'a;
fn next(&mut self) -> Option<Self::Output<'_>>;
}

struct RepeatMut<T>(T);

impl<T> StreamingIterator for RepeatMut<T> {
type Output<'a> = &'a mut T where T: 'a;

fn next(&mut self) -> Option<Self::Output<'_>> {
Some(&mut self.0)
}
}

#[derive(Delegate)]
#[delegate(StreamingIterator)]
pub struct Wrap<X>(X);

pub fn main() {
let mut x = Wrap(RepeatMut("forever".into()));
let m: &mut String = x.next().unwrap();
m.push('?');
assert_eq!(x.next().unwrap(), "forever?");
}