From 260e671d43bfc6345561c40f377d6d70efc1d99e Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 27 Oct 2023 14:50:48 -0500 Subject: [PATCH] Use mixed-site spans to avoid clippy 'uri!' error. Closes #2630. --- core/codegen/src/attribute/route/mod.rs | 3 ++- core/codegen/src/bang/uri.rs | 2 +- core/codegen/src/exports.rs | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/codegen/src/attribute/route/mod.rs b/core/codegen/src/attribute/route/mod.rs index 1079f306..93fac9b9 100644 --- a/core/codegen/src/attribute/route/mod.rs +++ b/core/codegen/src/attribute/route/mod.rs @@ -10,6 +10,7 @@ use crate::proc_macro_ext::StringLit; use crate::syn_ext::{IdentExt, TypeExt as _}; use crate::http_codegen::{Method, Optional}; use crate::attribute::param::Guard; +use crate::exports::mixed; use self::parse::{Route, Attribute, MethodAttribute}; @@ -242,7 +243,7 @@ fn responder_outcome_expr(route: &Route) -> TokenStream { .map(|a| quote_spanned!(a.span() => .await)); define_spanned_export!(ret_span => __req, _route); - quote_spanned! { Span::mixed_site().located_at(ret_span) => + quote_spanned! { mixed(ret_span) => let ___responder = #user_handler_fn_name(#(#parameter_names),*) #_await; #_route::Outcome::from(#__req, ___responder) } diff --git a/core/codegen/src/bang/uri.rs b/core/codegen/src/bang/uri.rs index 175b73da..b8e6c1d4 100644 --- a/core/codegen/src/bang/uri.rs +++ b/core/codegen/src/bang/uri.rs @@ -126,7 +126,7 @@ fn add_binding(to: &mut Vec, ident: &Ident, ty: &Type let tmp_ident = ident.clone().with_span(expr.span()); let let_stmt = quote_spanned!(span => let #tmp_ident = #expr); - to.push(quote_spanned!(span => + to.push(quote_spanned!(mixed(span) => #[allow(non_snake_case)] #let_stmt; let #ident = <#ty as #_fmt::FromUriParam<#part, _>>::from_uri_param(#tmp_ident); )); diff --git a/core/codegen/src/exports.rs b/core/codegen/src/exports.rs index d6c1f4d9..1c947ac3 100644 --- a/core/codegen/src/exports.rs +++ b/core/codegen/src/exports.rs @@ -106,3 +106,9 @@ define_exported_paths! { macro_rules! define_spanned_export { ($span:expr => $($name:ident),*) => ($(define!($span => $name $name);)*) } + +/// Convenience: returns a "mixed site" span located at `span`. +#[inline(always)] +pub fn mixed(span: Span) -> Span { + Span::mixed_site().located_at(span) +}