From d3c0a423d39ea66603840766dd7f43b97904941a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 18 Oct 2022 17:16:12 -0700 Subject: [PATCH] Tweak some spans to try for meaningful click-through on method names --- src/expand.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index 648c24b..b0dea84 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -159,19 +159,14 @@ fn transform_sig( has_default: bool, is_local: bool, ) { - sig.fn_token.span = sig.asyncness.take().unwrap().span; + let default_span = sig.asyncness.take().unwrap().span; + sig.fn_token.span = default_span; - let ret = match &sig.output { - ReturnType::Default => quote!(()), - ReturnType::Type(_, ret) => quote!(#ret), + let (ret_arrow, ret) = match &sig.output { + ReturnType::Default => (Token![->](default_span), quote_spanned!(default_span=> ())), + ReturnType::Type(arrow, ret) => (*arrow, quote!(#ret)), }; - let default_span = sig - .ident - .span() - .join(sig.paren_token.span) - .unwrap_or_else(|| sig.ident.span()); - let mut lifetimes = CollectLifetimes::new("'life", default_span); for arg in sig.inputs.iter_mut() { match arg { @@ -235,13 +230,12 @@ fn transform_sig( .push(parse_quote_spanned!(default_span=> 'async_trait)); if has_self { - let bound_span = sig.ident.span(); let bound = match sig.inputs.iter().next() { Some(FnArg::Receiver(Receiver { reference: Some(_), mutability: None, .. - })) => Ident::new("Sync", bound_span), + })) => Ident::new("Sync", default_span), Some(FnArg::Typed(arg)) if match (arg.pat.as_ref(), arg.ty.as_ref()) { (Pat::Ident(pat), Type::Reference(ty)) => { @@ -250,9 +244,9 @@ fn transform_sig( _ => false, } => { - Ident::new("Sync", bound_span) + Ident::new("Sync", default_span) } - _ => Ident::new("Send", bound_span), + _ => Ident::new("Send", default_span), }; let assume_bound = match context { @@ -262,9 +256,9 @@ fn transform_sig( let where_clause = where_clause_or_default(&mut sig.generics.where_clause); where_clause.predicates.push(if assume_bound || is_local { - parse_quote_spanned!(bound_span=> Self: 'async_trait) + parse_quote_spanned!(default_span=> Self: 'async_trait) } else { - parse_quote_spanned!(bound_span=> Self: ::core::marker::#bound + 'async_trait) + parse_quote_spanned!(default_span=> Self: ::core::marker::#bound + 'async_trait) }); } @@ -288,14 +282,13 @@ fn transform_sig( } } - let ret_span = sig.ident.span(); let bounds = if is_local { - quote_spanned!(ret_span=> 'async_trait) + quote_spanned!(default_span=> 'async_trait) } else { - quote_spanned!(ret_span=> ::core::marker::Send + 'async_trait) + quote_spanned!(default_span=> ::core::marker::Send + 'async_trait) }; - sig.output = parse_quote_spanned! {ret_span=> - -> ::core::pin::Pin + #ret_arrow ::core::pin::Pin + #bounds >> };