Skip to content

Commit 1789be6

Browse files
authored
Merge pull request #5 from eholk/nightly-update
Update to rustc nightly 2022-03-14
2 parents dc2b7e8 + 4999226 commit 1789be6

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

src/lib.rs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@
115115
//! // Generic associated types, the return values are moved to here.
116116
//! // NOTE: all #[send] methods also get the `Send` trait bound.
117117
//! type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> +
118-
//! ::core::marker::Send + 'a;
119-
//! type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
120-
//! type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
121-
//! type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
118+
//! ::core::marker::Send + 'a where Self: 'a;
119+
//! type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
120+
//! type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
121+
//! type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
122122
//! }
123123
//! ```
124124
//!
@@ -133,10 +133,10 @@
133133
//! # fn read<'a>(&'a self, fd: FileDescriptor, buf: &'a mut [u8]) -> Self::ReadFuture<'a>;
134134
//! # fn write<'a>(&'a self, fd: FileDescriptor, buf: &'a [u8]) -> Self::WriteFuture<'a>;
135135
//! # fn close<'a>(&'a self, fd: FileDescriptor) -> Self::CloseFuture<'a>;
136-
//! # type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> + Send + 'a;
137-
//! # type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
138-
//! # type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
139-
//! # type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
136+
//! # type OpenFuture<'a>: ::core::future::Future<Output = Result<FileDescriptor, Errno>> + Send + 'a where Self: 'a;
137+
//! # type ReadFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
138+
//! # type WriteFuture<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
139+
//! # type CloseFuture<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
140140
//! # }
141141
//! # const ENOENT: Errno = Errno;
142142
//! # const EBADF: Errno = Errno;
@@ -188,13 +188,15 @@
188188
189189
extern crate proc_macro;
190190

191+
use std::iter::FromIterator;
191192
use std::str::FromStr;
192193
use std::{iter, mem};
193194

194195
use proc_macro2::{Span, TokenStream};
195196
use quote::quote;
196197
use syn::punctuated::Punctuated;
197-
use syn::token;
198+
use syn::token::Where;
199+
use syn::{token, PredicateType, WhereClause, WherePredicate};
198200
use syn::{
199201
AngleBracketedGenericArguments, AttrStyle, Attribute, Binding, Block, Expr, ExprAsync, FnArg,
200202
GenericArgument, GenericParam, Generics, Ident, ImplItem, ImplItemType, ItemImpl, ItemTrait,
@@ -311,7 +313,32 @@ fn handle_item_impl(mut item: ItemImpl) -> TokenStream {
311313
generics: Generics {
312314
lt_token: Some(Token!(<)(Span::call_site())),
313315
gt_token: Some(Token!(>)(Span::call_site())),
314-
where_clause: None,
316+
where_clause: Some(WhereClause {
317+
where_token: Where::default(),
318+
predicates: function_lifetimes
319+
.iter()
320+
.cloned()
321+
.map(|lifetimedef| {
322+
WherePredicate::Type(PredicateType {
323+
colon_token: Token!(:)(Span::call_site()),
324+
lifetimes: None,
325+
bounded_ty: Type::Path(TypePath {
326+
qself: None,
327+
path: Path {
328+
leading_colon: None,
329+
segments: Punctuated::from_iter([PathSegment {
330+
ident: Ident::new("Self", Span::call_site()),
331+
arguments: PathArguments::None,
332+
}]),
333+
},
334+
}),
335+
bounds: Punctuated::from_iter([TypeParamBound::Lifetime(
336+
lifetimedef.lifetime,
337+
)]),
338+
})
339+
})
340+
.collect(),
341+
}),
315342
params: function_lifetimes
316343
.iter()
317344
.cloned()
@@ -590,7 +617,32 @@ fn handle_item_trait(mut item: ItemTrait) -> TokenStream {
590617
generics: Generics {
591618
lt_token: Some(Token!(<)(Span::call_site())),
592619
gt_token: Some(Token!(>)(Span::call_site())),
593-
where_clause: None,
620+
where_clause: Some(WhereClause {
621+
where_token: Where::default(),
622+
predicates: function_lifetimes
623+
.iter()
624+
.cloned()
625+
.map(|lifetimedef| {
626+
WherePredicate::Type(PredicateType {
627+
colon_token: Token!(:)(Span::call_site()),
628+
lifetimes: None,
629+
bounded_ty: Type::Path(TypePath {
630+
qself: None,
631+
path: Path {
632+
leading_colon: None,
633+
segments: Punctuated::from_iter([PathSegment {
634+
ident: Ident::new("Self", Span::call_site()),
635+
arguments: PathArguments::None,
636+
}]),
637+
},
638+
}),
639+
bounds: Punctuated::from_iter([TypeParamBound::Lifetime(
640+
lifetimedef.lifetime,
641+
)]),
642+
})
643+
})
644+
.collect(),
645+
}),
594646
params: function_lifetimes
595647
.iter()
596648
.cloned()

src/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ fn correct_trait_output() {
1616
fn write<'a>(&'a mut self, fd: usize, buf: &'a [u8]) -> Self::__real_async_trait_impl_TypeFor_write<'a>;
1717
fn close<'a>(&'a mut self, fd: usize) -> Self::__real_async_trait_impl_TypeFor_close<'a>;
1818

19-
type __real_async_trait_impl_TypeFor_open<'a>: ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a;
20-
type __real_async_trait_impl_TypeFor_read<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
21-
type __real_async_trait_impl_TypeFor_write<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a;
22-
type __real_async_trait_impl_TypeFor_close<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a;
19+
type __real_async_trait_impl_TypeFor_open<'a>: ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a where Self: 'a;
20+
type __real_async_trait_impl_TypeFor_read<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
21+
type __real_async_trait_impl_TypeFor_write<'a>: ::core::future::Future<Output = Result<usize, Errno>> + 'a where Self: 'a;
22+
type __real_async_trait_impl_TypeFor_close<'a>: ::core::future::Future<Output = Result<(), Errno>> + 'a where Self: 'a;
2323
}
2424
};
2525
let actual_output = crate::real_async_trait2(proc_macro2::TokenStream::new(), input);
@@ -65,10 +65,10 @@ fn correct_impl_output() {
6565
async move { Ok(()) }
6666
}
6767

68-
type __real_async_trait_impl_TypeFor_open<'a> = __real_async_trait_impl_ExistentialTypeFor_open<'a>;
69-
type __real_async_trait_impl_TypeFor_read<'a> = __real_async_trait_impl_ExistentialTypeFor_read<'a>;
70-
type __real_async_trait_impl_TypeFor_write<'a> = __real_async_trait_impl_ExistentialTypeFor_write<'a>;
71-
type __real_async_trait_impl_TypeFor_close<'a> = __real_async_trait_impl_ExistentialTypeFor_close<'a>;
68+
type __real_async_trait_impl_TypeFor_open<'a> = __real_async_trait_impl_ExistentialTypeFor_open<'a> where Self: 'a;
69+
type __real_async_trait_impl_TypeFor_read<'a> = __real_async_trait_impl_ExistentialTypeFor_read<'a> where Self: 'a;
70+
type __real_async_trait_impl_TypeFor_write<'a> = __real_async_trait_impl_ExistentialTypeFor_write<'a> where Self: 'a;
71+
type __real_async_trait_impl_TypeFor_close<'a> = __real_async_trait_impl_ExistentialTypeFor_close<'a> where Self: 'a;
7272
}
7373
type __real_async_trait_impl_ExistentialTypeFor_open<'a> = impl ::core::future::Future<Output = Result<usize, Errno>> + ::core::marker::Send + 'a;
7474
type __real_async_trait_impl_ExistentialTypeFor_read<'a> = impl ::core::future::Future<Output = Result<usize, Errno>> + 'a;

0 commit comments

Comments
 (0)