|
115 | 115 | //! // Generic associated types, the return values are moved to here.
|
116 | 116 | //! // NOTE: all #[send] methods also get the `Send` trait bound.
|
117 | 117 | //! 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; |
122 | 122 | //! }
|
123 | 123 | //! ```
|
124 | 124 | //!
|
|
133 | 133 | //! # fn read<'a>(&'a self, fd: FileDescriptor, buf: &'a mut [u8]) -> Self::ReadFuture<'a>;
|
134 | 134 | //! # fn write<'a>(&'a self, fd: FileDescriptor, buf: &'a [u8]) -> Self::WriteFuture<'a>;
|
135 | 135 | //! # 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; |
140 | 140 | //! # }
|
141 | 141 | //! # const ENOENT: Errno = Errno;
|
142 | 142 | //! # const EBADF: Errno = Errno;
|
|
188 | 188 |
|
189 | 189 | extern crate proc_macro;
|
190 | 190 |
|
| 191 | +use std::iter::FromIterator; |
191 | 192 | use std::str::FromStr;
|
192 | 193 | use std::{iter, mem};
|
193 | 194 |
|
194 | 195 | use proc_macro2::{Span, TokenStream};
|
195 | 196 | use quote::quote;
|
196 | 197 | use syn::punctuated::Punctuated;
|
197 |
| -use syn::token; |
| 198 | +use syn::token::Where; |
| 199 | +use syn::{token, PredicateType, WhereClause, WherePredicate}; |
198 | 200 | use syn::{
|
199 | 201 | AngleBracketedGenericArguments, AttrStyle, Attribute, Binding, Block, Expr, ExprAsync, FnArg,
|
200 | 202 | GenericArgument, GenericParam, Generics, Ident, ImplItem, ImplItemType, ItemImpl, ItemTrait,
|
@@ -311,7 +313,32 @@ fn handle_item_impl(mut item: ItemImpl) -> TokenStream {
|
311 | 313 | generics: Generics {
|
312 | 314 | lt_token: Some(Token!(<)(Span::call_site())),
|
313 | 315 | 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 | + }), |
315 | 342 | params: function_lifetimes
|
316 | 343 | .iter()
|
317 | 344 | .cloned()
|
@@ -590,7 +617,32 @@ fn handle_item_trait(mut item: ItemTrait) -> TokenStream {
|
590 | 617 | generics: Generics {
|
591 | 618 | lt_token: Some(Token!(<)(Span::call_site())),
|
592 | 619 | 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 | + }), |
594 | 646 | params: function_lifetimes
|
595 | 647 | .iter()
|
596 | 648 | .cloned()
|
|
0 commit comments