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

Update to rustc nightly 2022-03-14 #5

Merged
merged 2 commits into from
Jun 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 63 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
//! // Generic associated types, the return values are moved to here.
//! // NOTE: all #[send] methods also get the `Send` trait bound.
//! type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> +
//! ::core::marker::Send + 'a;
//! type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
//! type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
//! type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
//! ::core::marker::Send + 'a where Self: 'a;
//! type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
//! type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
//! type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
//! }
//! ```
//!
Expand All @@ -133,10 +133,10 @@
//! # fn read<'a>(&'a self, fd: FileDescriptor, buf: &'a mut [u8]) -> Self::ReadFuture<'a>;
//! # fn write<'a>(&'a self, fd: FileDescriptor, buf: &'a [u8]) -> Self::WriteFuture<'a>;
//! # fn close<'a>(&'a self, fd: FileDescriptor) -> Self::CloseFuture<'a>;
//! # type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> + Send + 'a;
//! # type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
//! # type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
//! # type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
//! # type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> + Send + 'a where Self: 'a;
//! # type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
//! # type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
//! # type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
//! # }
//! # const ENOENT: Errno = Errno;
//! # const EBADF: Errno = Errno;
Expand Down Expand Up @@ -188,13 +188,15 @@

extern crate proc_macro;

use std::iter::FromIterator;
use std::str::FromStr;
use std::{iter, mem};

use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::punctuated::Punctuated;
use syn::token;
use syn::token::Where;
use syn::{token, PredicateType, WhereClause, WherePredicate};
use syn::{
AngleBracketedGenericArguments, AttrStyle, Attribute, Binding, Block, Expr, ExprAsync, FnArg,
GenericArgument, GenericParam, Generics, Ident, ImplItem, ImplItemType, ItemImpl, ItemTrait,
Expand Down Expand Up @@ -311,7 +313,32 @@ fn handle_item_impl(mut item: ItemImpl) -> TokenStream {
generics: Generics {
lt_token: Some(Token!(<)(Span::call_site())),
gt_token: Some(Token!(>)(Span::call_site())),
where_clause: None,
where_clause: Some(WhereClause {
where_token: Where::default(),
predicates: function_lifetimes
.iter()
.cloned()
.map(|lifetimedef| {
WherePredicate::Type(PredicateType {
colon_token: Token!(:)(Span::call_site()),
lifetimes: None,
bounded_ty: Type::Path(TypePath {
qself: None,
path: Path {
leading_colon: None,
segments: Punctuated::from_iter([PathSegment {
ident: Ident::new("Self", Span::call_site()),
arguments: PathArguments::None,
}]),
},
}),
bounds: Punctuated::from_iter([TypeParamBound::Lifetime(
lifetimedef.lifetime,
)]),
})
})
.collect(),
}),
params: function_lifetimes
.iter()
.cloned()
Expand Down Expand Up @@ -590,7 +617,32 @@ fn handle_item_trait(mut item: ItemTrait) -> TokenStream {
generics: Generics {
lt_token: Some(Token!(<)(Span::call_site())),
gt_token: Some(Token!(>)(Span::call_site())),
where_clause: None,
where_clause: Some(WhereClause {
where_token: Where::default(),
predicates: function_lifetimes
.iter()
.cloned()
.map(|lifetimedef| {
WherePredicate::Type(PredicateType {
colon_token: Token!(:)(Span::call_site()),
lifetimes: None,
bounded_ty: Type::Path(TypePath {
qself: None,
path: Path {
leading_colon: None,
segments: Punctuated::from_iter([PathSegment {
ident: Ident::new("Self", Span::call_site()),
arguments: PathArguments::None,
}]),
},
}),
bounds: Punctuated::from_iter([TypeParamBound::Lifetime(
lifetimedef.lifetime,
)]),
})
})
.collect(),
}),
params: function_lifetimes
.iter()
.cloned()
Expand Down
16 changes: 8 additions & 8 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fn correct_trait_output() {
fn write<'a>(&'a mut self, fd: usize, buf: &'a [u8]) -> Self::__real_async_trait_impl_TypeFor_write<'a>;
fn close<'a>(&'a mut self, fd: usize) -> Self::__real_async_trait_impl_TypeFor_close<'a>;

type __real_async_trait_impl_TypeFor_open<'a>: ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a;
type __real_async_trait_impl_TypeFor_read<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
type __real_async_trait_impl_TypeFor_write<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
type __real_async_trait_impl_TypeFor_close<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
type __real_async_trait_impl_TypeFor_open<'a>: ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a where Self: 'a;
type __real_async_trait_impl_TypeFor_read<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
type __real_async_trait_impl_TypeFor_write<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
type __real_async_trait_impl_TypeFor_close<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
}
};
let actual_output = crate::real_async_trait2(proc_macro2::TokenStream::new(), input);
Expand Down Expand Up @@ -65,10 +65,10 @@ fn correct_impl_output() {
async move { Ok(()) }
}

type __real_async_trait_impl_TypeFor_open<'a> = __real_async_trait_impl_ExistentialTypeFor_open<'a>;
type __real_async_trait_impl_TypeFor_read<'a> = __real_async_trait_impl_ExistentialTypeFor_read<'a>;
type __real_async_trait_impl_TypeFor_write<'a> = __real_async_trait_impl_ExistentialTypeFor_write<'a>;
type __real_async_trait_impl_TypeFor_close<'a> = __real_async_trait_impl_ExistentialTypeFor_close<'a>;
type __real_async_trait_impl_TypeFor_open<'a> = __real_async_trait_impl_ExistentialTypeFor_open<'a> where Self: 'a;
type __real_async_trait_impl_TypeFor_read<'a> = __real_async_trait_impl_ExistentialTypeFor_read<'a> where Self: 'a;
type __real_async_trait_impl_TypeFor_write<'a> = __real_async_trait_impl_ExistentialTypeFor_write<'a> where Self: 'a;
type __real_async_trait_impl_TypeFor_close<'a> = __real_async_trait_impl_ExistentialTypeFor_close<'a> where Self: 'a;
}
type __real_async_trait_impl_ExistentialTypeFor_open<'a> = impl ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a;
type __real_async_trait_impl_ExistentialTypeFor_read<'a> = impl ::core::future::Future<Output = Result<usize, Errno>> + 'a;
Expand Down