diff --git a/sqlx-macros/src/derives/attributes.rs b/sqlx-macros/src/derives/attributes.rs index ba1b382b06..bdf2812999 100644 --- a/sqlx-macros/src/derives/attributes.rs +++ b/sqlx-macros/src/derives/attributes.rs @@ -40,7 +40,7 @@ impl TypeName { let val = &self.val; if self.deprecated_rename { quote_spanned!(self.span=> { - sqlx::_rename(); + ::sqlx::_rename(); #val }) } else { diff --git a/sqlx-macros/src/derives/decode.rs b/sqlx-macros/src/derives/decode.rs index e3c5cc783c..90dddc6a9e 100644 --- a/sqlx-macros/src/derives/decode.rs +++ b/sqlx-macros/src/derives/decode.rs @@ -61,18 +61,18 @@ fn expand_derive_decode_transparent( // add db type for impl generics & where clause let mut generics = generics.clone(); - generics.params.insert(0, parse_quote!(DB: sqlx::Database)); + generics.params.insert(0, parse_quote!(DB: ::sqlx::Database)); generics.params.insert(0, parse_quote!('r)); generics .make_where_clause() .predicates - .push(parse_quote!(#ty: sqlx::decode::Decode<'r, DB>)); + .push(parse_quote!(#ty: ::sqlx::decode::Decode<'r, DB>)); let (impl_generics, _, where_clause) = generics.split_for_impl(); let tts = quote!( - impl #impl_generics sqlx::decode::Decode<'r, DB> for #ident #ty_generics #where_clause { - fn decode(value: >::ValueRef) -> std::result::Result> { - <#ty as sqlx::decode::Decode<'r, DB>>::decode(value).map(Self) + impl #impl_generics ::sqlx::decode::Decode<'r, DB> for #ident #ty_generics #where_clause { + fn decode(value: >::ValueRef) -> ::std::result::Result> { + <#ty as ::sqlx::decode::Decode<'r, DB>>::decode(value).map(Self) } } ); @@ -94,19 +94,19 @@ fn expand_derive_decode_weak_enum( .iter() .map(|v| { let id = &v.ident; - parse_quote!(_ if (#ident :: #id as #repr) == value => Ok(#ident :: #id),) + parse_quote!(_ if (#ident :: #id as #repr) == value => ::std::result::Result::Ok(#ident :: #id),) }) .collect::>(); Ok(quote!( - impl<'r, DB: sqlx::Database> sqlx::decode::Decode<'r, DB> for #ident where #repr: sqlx::decode::Decode<'r, DB> { - fn decode(value: >::ValueRef) -> std::result::Result> { - let value = <#repr as sqlx::decode::Decode<'r, DB>>::decode(value)?; + impl<'r, DB: ::sqlx::Database> ::sqlx::decode::Decode<'r, DB> for #ident where #repr: ::sqlx::decode::Decode<'r, DB> { + fn decode(value: >::ValueRef) -> ::std::result::Result> { + let value = <#repr as ::sqlx::decode::Decode<'r, DB>>::decode(value)?; match value { #(#arms)* - _ => Err(Box::new(sqlx::Error::Decode(format!("invalid value {:?} for enum {}", value, #ident_s).into()))) + _ => ::std::result::Result::Err(::std::boxed::Box::new(::sqlx::Error::Decode(::std::format!("invalid value {:?} for enum {}", value, #ident_s).into()))) } } } @@ -127,14 +127,14 @@ fn expand_derive_decode_strong_enum( let attributes = parse_child_attributes(&v.attrs).unwrap(); if let Some(rename) = attributes.rename { - parse_quote!(#rename => Ok(#ident :: #id),) + parse_quote!(#rename => ::std::result::Result::Ok(#ident :: #id),) } else if let Some(pattern) = cattr.rename_all { let name = rename_all(&*id.to_string(), pattern); - parse_quote!(#name => Ok(#ident :: #id),) + parse_quote!(#name => ::std::result::Result::Ok(#ident :: #id),) } else { let name = id.to_string(); - parse_quote!(#name => Ok(#ident :: #id),) + parse_quote!(#name => ::std::result::Result::Ok(#ident :: #id),) } }); @@ -150,9 +150,9 @@ fn expand_derive_decode_strong_enum( if cfg!(feature = "mysql") { tts.extend(quote!( - impl<'r> sqlx::decode::Decode<'r, sqlx::mysql::MySql> for #ident { - fn decode(value: sqlx::mysql::MySqlValueRef<'r>) -> std::result::Result> { - let value = <&'r str as sqlx::decode::Decode<'r, sqlx::mysql::MySql>>::decode(value)?; + impl<'r> ::sqlx::decode::Decode<'r, ::sqlx::mysql::MySql> for #ident { + fn decode(value: ::sqlx::mysql::MySqlValueRef<'r>) -> ::std::result::Result> { + let value = <&'r ::std::primitive::str as ::sqlx::decode::Decode<'r, ::sqlx::mysql::MySql>>::decode(value)?; #values } @@ -162,9 +162,9 @@ fn expand_derive_decode_strong_enum( if cfg!(feature = "postgres") { tts.extend(quote!( - impl<'r> sqlx::decode::Decode<'r, sqlx::postgres::Postgres> for #ident { - fn decode(value: sqlx::postgres::PgValueRef<'r>) -> std::result::Result> { - let value = <&'r str as sqlx::decode::Decode<'r, sqlx::postgres::Postgres>>::decode(value)?; + impl<'r> ::sqlx::decode::Decode<'r, ::sqlx::postgres::Postgres> for #ident { + fn decode(value: ::sqlx::postgres::PgValueRef<'r>) -> ::std::result::Result> { + let value = <&'r ::std::primitive::str as ::sqlx::decode::Decode<'r, ::sqlx::postgres::Postgres>>::decode(value)?; #values } @@ -174,9 +174,9 @@ fn expand_derive_decode_strong_enum( if cfg!(feature = "sqlite") { tts.extend(quote!( - impl<'r> sqlx::decode::Decode<'r, sqlx::sqlite::Sqlite> for #ident { - fn decode(value: sqlx::sqlite::SqliteValueRef<'r>) -> std::result::Result> { - let value = <&'r str as sqlx::decode::Decode<'r, sqlx::sqlite::Sqlite>>::decode(value)?; + impl<'r> ::sqlx::decode::Decode<'r, ::sqlx::sqlite::Sqlite> for #ident { + fn decode(value: ::sqlx::sqlite::SqliteValueRef<'r>) -> ::std::result::Result> { + let value = <&'r ::std::primitive::str as ::sqlx::decode::Decode<'r, ::sqlx::sqlite::Sqlite>>::decode(value)?; #values } @@ -211,8 +211,8 @@ fn expand_derive_decode_struct( for field in fields { let ty = &field.ty; - predicates.push(parse_quote!(#ty: sqlx::decode::Decode<'r, sqlx::Postgres>)); - predicates.push(parse_quote!(#ty: sqlx::types::Type)); + predicates.push(parse_quote!(#ty: ::sqlx::decode::Decode<'r, ::sqlx::Postgres>)); + predicates.push(parse_quote!(#ty: ::sqlx::types::Type<::sqlx::Postgres>)); } let (impl_generics, _, where_clause) = generics.split_for_impl(); @@ -229,13 +229,13 @@ fn expand_derive_decode_struct( let names = fields.iter().map(|field| &field.ident); tts.extend(quote!( - impl #impl_generics sqlx::decode::Decode<'r, sqlx::Postgres> for #ident #ty_generics #where_clause { - fn decode(value: sqlx::postgres::PgValueRef<'r>) -> std::result::Result> { - let mut decoder = sqlx::postgres::types::PgRecordDecoder::new(value)?; + impl #impl_generics ::sqlx::decode::Decode<'r, ::sqlx::Postgres> for #ident #ty_generics #where_clause { + fn decode(value: ::sqlx::postgres::PgValueRef<'r>) -> ::std::result::Result> { + let mut decoder = ::sqlx::postgres::types::PgRecordDecoder::new(value)?; #(#reads)* - Ok(#ident { + ::std::result::Result::Ok(#ident { #(#names),* }) } diff --git a/sqlx-macros/src/derives/encode.rs b/sqlx-macros/src/derives/encode.rs index dbff8032e3..5c1e740c95 100644 --- a/sqlx-macros/src/derives/encode.rs +++ b/sqlx-macros/src/derives/encode.rs @@ -68,25 +68,25 @@ fn expand_derive_encode_transparent( .params .insert(0, LifetimeDef::new(lifetime.clone()).into()); - generics.params.insert(0, parse_quote!(DB: sqlx::Database)); + generics.params.insert(0, parse_quote!(DB: ::sqlx::Database)); generics .make_where_clause() .predicates - .push(parse_quote!(#ty: sqlx::encode::Encode<#lifetime, DB>)); + .push(parse_quote!(#ty: ::sqlx::encode::Encode<#lifetime, DB>)); let (impl_generics, _, where_clause) = generics.split_for_impl(); Ok(quote!( - impl #impl_generics sqlx::encode::Encode<#lifetime, DB> for #ident #ty_generics #where_clause { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> sqlx::encode::IsNull { - <#ty as sqlx::encode::Encode<#lifetime, DB>>::encode_by_ref(&self.0, buf) + impl #impl_generics ::sqlx::encode::Encode<#lifetime, DB> for #ident #ty_generics #where_clause { + fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> ::sqlx::encode::IsNull { + <#ty as ::sqlx::encode::Encode<#lifetime, DB>>::encode_by_ref(&self.0, buf) } fn produces(&self) -> Option { - <#ty as sqlx::encode::Encode<#lifetime, DB>>::produces(&self.0) + <#ty as ::sqlx::encode::Encode<#lifetime, DB>>::produces(&self.0) } fn size_hint(&self) -> usize { - <#ty as sqlx::encode::Encode<#lifetime, DB>>::size_hint(&self.0) + <#ty as ::sqlx::encode::Encode<#lifetime, DB>>::size_hint(&self.0) } } )) @@ -108,17 +108,17 @@ fn expand_derive_encode_weak_enum( } Ok(quote!( - impl<'q, DB: sqlx::Database> sqlx::encode::Encode<'q, DB> for #ident where #repr: sqlx::encode::Encode<'q, DB> { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> sqlx::encode::IsNull { + impl<'q, DB: ::sqlx::Database> ::sqlx::encode::Encode<'q, DB> for #ident where #repr: ::sqlx::encode::Encode<'q, DB> { + fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> ::sqlx::encode::IsNull { let value = match self { #(#values)* }; - <#repr as sqlx::encode::Encode>::encode_by_ref(&value, buf) + <#repr as ::sqlx::encode::Encode>::encode_by_ref(&value, buf) } fn size_hint(&self) -> usize { - <#repr as sqlx::encode::Encode>::size_hint(&Default::default()) + <#repr as ::sqlx::encode::Encode>::size_hint(&Default::default()) } } )) @@ -151,21 +151,21 @@ fn expand_derive_encode_strong_enum( } Ok(quote!( - impl<'q, DB: sqlx::Database> sqlx::encode::Encode<'q, DB> for #ident where &'q str: sqlx::encode::Encode<'q, DB> { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> sqlx::encode::IsNull { + impl<'q, DB: ::sqlx::Database> ::sqlx::encode::Encode<'q, DB> for #ident where &'q ::std::primitive::str: ::sqlx::encode::Encode<'q, DB> { + fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> ::sqlx::encode::IsNull { let val = match self { #(#value_arms)* }; - <&str as sqlx::encode::Encode<'q, DB>>::encode(val, buf) + <&::std::primitive::str as ::sqlx::encode::Encode<'q, DB>>::encode(val, buf) } - fn size_hint(&self) -> usize { + fn size_hint(&self) -> ::std::primitive::usize { let val = match self { #(#value_arms)* }; - <&str as sqlx::encode::Encode<'q, DB>>::size_hint(&val) + <&::std::primitive::str as ::sqlx::encode::Encode<'q, DB>>::size_hint(&val) } } )) @@ -195,8 +195,8 @@ fn expand_derive_encode_struct( for field in fields { let ty = &field.ty; - predicates.push(parse_quote!(#ty: for<'q> sqlx::encode::Encode<'q, sqlx::Postgres>)); - predicates.push(parse_quote!(#ty: sqlx::types::Type)); + predicates.push(parse_quote!(#ty: for<'q> ::sqlx::encode::Encode<'q, ::sqlx::Postgres>)); + predicates.push(parse_quote!(#ty: ::sqlx::types::Type<::sqlx::Postgres>)); } let (impl_generics, _, where_clause) = generics.split_for_impl(); @@ -214,23 +214,23 @@ fn expand_derive_encode_struct( let ty = &field.ty; parse_quote!( - <#ty as sqlx::encode::Encode>::size_hint(&self. #id) + <#ty as ::sqlx::encode::Encode<::sqlx::Postgres>>::size_hint(&self. #id) ) }); tts.extend(quote!( - impl #impl_generics sqlx::encode::Encode<'_, sqlx::Postgres> for #ident #ty_generics #where_clause { - fn encode_by_ref(&self, buf: &mut sqlx::postgres::PgArgumentBuffer) -> sqlx::encode::IsNull { - let mut encoder = sqlx::postgres::types::PgRecordEncoder::new(buf); + impl #impl_generics ::sqlx::encode::Encode<'_, ::sqlx::Postgres> for #ident #ty_generics #where_clause { + fn encode_by_ref(&self, buf: &mut ::sqlx::postgres::PgArgumentBuffer) -> ::sqlx::encode::IsNull { + let mut encoder = ::sqlx::postgres::types::PgRecordEncoder::new(buf); #(#writes)* encoder.finish(); - sqlx::encode::IsNull::No + ::sqlx::encode::IsNull::No } - fn size_hint(&self) -> usize { + fn size_hint(&self) -> ::std::primitive::usize { #column_count * (4 + 4) // oid (int) and length (int) for each column + #(#sizes)+* // sum of the size hints for each column } diff --git a/sqlx-macros/src/derives/row.rs b/sqlx-macros/src/derives/row.rs index 388dcc2d51..be6db208b4 100644 --- a/sqlx-macros/src/derives/row.rs +++ b/sqlx-macros/src/derives/row.rs @@ -53,7 +53,7 @@ fn expand_derive_from_row_struct( let (_, ty_generics, _) = generics.split_for_impl(); let mut generics = generics.clone(); - generics.params.insert(0, parse_quote!(R: sqlx::Row)); + generics.params.insert(0, parse_quote!(R: ::sqlx::Row)); if provided { generics.params.insert(0, parse_quote!(#lifetime)); @@ -61,13 +61,13 @@ fn expand_derive_from_row_struct( let predicates = &mut generics.make_where_clause().predicates; - predicates.push(parse_quote!(&#lifetime str: sqlx::ColumnIndex)); + predicates.push(parse_quote!(&#lifetime ::std::primitive::str: ::sqlx::ColumnIndex)); for field in fields { let ty = &field.ty; - predicates.push(parse_quote!(#ty: sqlx::decode::Decode<#lifetime, R::Database>)); - predicates.push(parse_quote!(#ty: sqlx::types::Type)); + predicates.push(parse_quote!(#ty: ::sqlx::decode::Decode<#lifetime, R::Database>)); + predicates.push(parse_quote!(#ty: ::sqlx::types::Type)); } let (impl_generics, _, where_clause) = generics.split_for_impl(); @@ -91,10 +91,10 @@ fn expand_derive_from_row_struct( if attributes.default { Some( parse_quote!(let #id: #ty = row.try_get(#id_s).or_else(|e| match e { - sqlx::Error::ColumnNotFound(_) => { - Ok(Default::default()) + ::sqlx::Error::ColumnNotFound(_) => { + ::std::result::Result::Ok(Default::default()) }, - e => Err(e) + e => ::std::result::Result::Err(e) })?;), ) } else { @@ -107,11 +107,11 @@ fn expand_derive_from_row_struct( let names = fields.iter().map(|field| &field.ident); Ok(quote!( - impl #impl_generics sqlx::FromRow<#lifetime, R> for #ident #ty_generics #where_clause { - fn from_row(row: &#lifetime R) -> sqlx::Result { + impl #impl_generics ::sqlx::FromRow<#lifetime, R> for #ident #ty_generics #where_clause { + fn from_row(row: &#lifetime R) -> ::sqlx::Result { #(#reads)* - Ok(#ident { + ::std::result::Result::Ok(#ident { #(#names),* }) } @@ -136,7 +136,7 @@ fn expand_derive_from_row_struct_unnamed( let (_, ty_generics, _) = generics.split_for_impl(); let mut generics = generics.clone(); - generics.params.insert(0, parse_quote!(R: sqlx::Row)); + generics.params.insert(0, parse_quote!(R: ::sqlx::Row)); if provided { generics.params.insert(0, parse_quote!(#lifetime)); @@ -144,13 +144,13 @@ fn expand_derive_from_row_struct_unnamed( let predicates = &mut generics.make_where_clause().predicates; - predicates.push(parse_quote!(usize: sqlx::ColumnIndex)); + predicates.push(parse_quote!(::std::primitive::usize: ::sqlx::ColumnIndex)); for field in fields { let ty = &field.ty; - predicates.push(parse_quote!(#ty: sqlx::decode::Decode<#lifetime, R::Database>)); - predicates.push(parse_quote!(#ty: sqlx::types::Type)); + predicates.push(parse_quote!(#ty: ::sqlx::decode::Decode<#lifetime, R::Database>)); + predicates.push(parse_quote!(#ty: ::sqlx::types::Type)); } let (impl_generics, _, where_clause) = generics.split_for_impl(); @@ -161,9 +161,9 @@ fn expand_derive_from_row_struct_unnamed( .map(|(idx, _)| quote!(row.try_get(#idx)?)); Ok(quote!( - impl #impl_generics sqlx::FromRow<#lifetime, R> for #ident #ty_generics #where_clause { - fn from_row(row: &#lifetime R) -> sqlx::Result { - Ok(#ident ( + impl #impl_generics ::sqlx::FromRow<#lifetime, R> for #ident #ty_generics #where_clause { + fn from_row(row: &#lifetime R) -> ::sqlx::Result { + ::std::result::Result::Ok(#ident ( #(#gets),* )) } diff --git a/sqlx-macros/src/derives/type.rs b/sqlx-macros/src/derives/type.rs index 143b9c7b9d..ebc3f9127f 100644 --- a/sqlx-macros/src/derives/type.rs +++ b/sqlx-macros/src/derives/type.rs @@ -59,22 +59,22 @@ fn expand_derive_has_sql_type_transparent( if attr.transparent { let mut generics = generics.clone(); - generics.params.insert(0, parse_quote!(DB: sqlx::Database)); + generics.params.insert(0, parse_quote!(DB: ::sqlx::Database)); generics .make_where_clause() .predicates - .push(parse_quote!(#ty: sqlx::Type)); + .push(parse_quote!(#ty: ::sqlx::Type)); let (impl_generics, _, where_clause) = generics.split_for_impl(); return Ok(quote!( - impl #impl_generics sqlx::Type< DB > for #ident #ty_generics #where_clause { + impl #impl_generics ::sqlx::Type< DB > for #ident #ty_generics #where_clause { fn type_info() -> DB::TypeInfo { - <#ty as sqlx::Type>::type_info() + <#ty as ::sqlx::Type>::type_info() } - fn compatible(ty: &DB::TypeInfo) -> bool { - <#ty as sqlx::Type>::compatible(ty) + fn compatible(ty: &DB::TypeInfo) -> ::std::bool { + <#ty as ::sqlx::Type>::compatible(ty) } } )); @@ -89,9 +89,9 @@ fn expand_derive_has_sql_type_transparent( .unwrap_or_else(|| quote! { #ident }); tts.extend(quote!( - impl sqlx::Type< sqlx::postgres::Postgres > for #ident #ty_generics { - fn type_info() -> sqlx::postgres::PgTypeInfo { - sqlx::postgres::PgTypeInfo::with_name(#ty_name) + impl ::sqlx::Type<::sqlx::postgres::Postgres> for #ident #ty_generics { + fn type_info() -> ::sqlx::postgres::PgTypeInfo { + ::sqlx::postgres::PgTypeInfo::with_name(#ty_name) } } )); @@ -108,12 +108,12 @@ fn expand_derive_has_sql_type_weak_enum( let repr = attr.repr.unwrap(); let ident = &input.ident; let ts = quote!( - impl sqlx::Type for #ident + impl ::sqlx::Type for #ident where - #repr: sqlx::Type, + #repr: ::sqlx::Type, { fn type_info() -> DB::TypeInfo { - <#repr as sqlx::Type>::type_info() + <#repr as ::sqlx::Type>::type_info() } } ); @@ -132,13 +132,13 @@ fn expand_derive_has_sql_type_strong_enum( if cfg!(feature = "mysql") { tts.extend(quote!( - impl sqlx::Type< sqlx::MySql > for #ident { - fn type_info() -> sqlx::mysql::MySqlTypeInfo { - sqlx::mysql::MySqlTypeInfo::__enum() + impl ::sqlx::Type<::sqlx::MySql> for #ident { + fn type_info() -> ::sqlx::mysql::MySqlTypeInfo { + ::sqlx::mysql::MySqlTypeInfo::__enum() } - fn compatible(ty: &sqlx::mysql::MySqlTypeInfo) -> bool { - *ty == sqlx::mysql::MySqlTypeInfo::__enum() + fn compatible(ty: &::sqlx::mysql::MySqlTypeInfo) -> ::std::bool { + *ty == ::sqlx::mysql::MySqlTypeInfo::__enum() } } )); @@ -151,9 +151,9 @@ fn expand_derive_has_sql_type_strong_enum( .unwrap_or_else(|| quote! { #ident }); tts.extend(quote!( - impl sqlx::Type< sqlx::Postgres > for #ident { - fn type_info() -> sqlx::postgres::PgTypeInfo { - sqlx::postgres::PgTypeInfo::with_name(#ty_name) + impl ::sqlx::Type<::sqlx::Postgres> for #ident { + fn type_info() -> ::sqlx::postgres::PgTypeInfo { + ::sqlx::postgres::PgTypeInfo::with_name(#ty_name) } } )); @@ -161,13 +161,13 @@ fn expand_derive_has_sql_type_strong_enum( if cfg!(feature = "sqlite") { tts.extend(quote!( - impl sqlx::Type< sqlx::Sqlite > for #ident { - fn type_info() -> sqlx::sqlite::SqliteTypeInfo { - >::type_info() + impl sqlx::Type<::sqlx::Sqlite> for #ident { + fn type_info() -> ::sqlx::sqlite::SqliteTypeInfo { + <::std::primitive::str as ::sqlx::Type>::type_info() } - fn compatible(ty: &sqlx::sqlite::SqliteTypeInfo) -> bool { - <&str as sqlx::types::Type>::compatible(ty) + fn compatible(ty: &::sqlx::sqlite::SqliteTypeInfo) -> ::std::bool { + <&::str::str as ::sqlx::types::Type>::compatible(ty) } } )); @@ -192,9 +192,9 @@ fn expand_derive_has_sql_type_struct( .unwrap_or_else(|| quote! { #ident }); tts.extend(quote!( - impl sqlx::Type< sqlx::Postgres > for #ident { - fn type_info() -> sqlx::postgres::PgTypeInfo { - sqlx::postgres::PgTypeInfo::with_name(#ty_name) + impl ::sqlx::Type<::sqlx::Postgres> for #ident { + fn type_info() -> ::sqlx::postgres::PgTypeInfo { + ::sqlx::postgres::PgTypeInfo::with_name(#ty_name) } } )); diff --git a/sqlx-macros/src/lib.rs b/sqlx-macros/src/lib.rs index d23b0b30fb..d2a1a3ef2b 100644 --- a/sqlx-macros/src/lib.rs +++ b/sqlx-macros/src/lib.rs @@ -31,7 +31,7 @@ pub fn expand_query(input: TokenStream) -> TokenStream { parse_err.to_compile_error().into() } else { let msg = e.to_string(); - quote!(compile_error!(#msg)).into() + quote!(::std::compile_error!(#msg)).into() } } } @@ -87,7 +87,7 @@ pub fn migrate(input: TokenStream) -> TokenStream { parse_err.to_compile_error().into() } else { let msg = e.to_string(); - quote!(compile_error!(#msg)).into() + quote!(::std::compile_error!(#msg)).into() } } } @@ -108,7 +108,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { - sqlx_rt::tokio::runtime::Builder::new_multi_thread() + ::sqlx_rt::tokio::runtime::Builder::new_multi_thread() .enable_io() .enable_time() .build() @@ -121,7 +121,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { - sqlx_rt::async_std::task::block_on(async { #body }) + ::sqlx_rt::async_std::task::block_on(async { #body }) } } } else if cfg!(feature = "_rt-actix") { @@ -129,7 +129,7 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { - sqlx_rt::actix_rt::System::new("sqlx-test") + ::sqlx_rt::actix_rt::System::new("sqlx-test") .block_on(async { #body }) } } diff --git a/sqlx-macros/src/migrate.rs b/sqlx-macros/src/migrate.rs index e6b3e0343c..37b699cf45 100644 --- a/sqlx-macros/src/migrate.rs +++ b/sqlx-macros/src/migrate.rs @@ -10,10 +10,10 @@ pub struct QuotedMigrationType(MigrationType); impl ToTokens for QuotedMigrationType { fn to_tokens(&self, tokens: &mut TokenStream) { let ts = match self.0 { - MigrationType::Simple => quote! { sqlx::migrate::MigrationType::Simple }, - MigrationType::ReversibleUp => quote! { sqlx::migrate::MigrationType::ReversibleUp }, + MigrationType::Simple => quote! { ::sqlx::migrate::MigrationType::Simple }, + MigrationType::ReversibleUp => quote! { ::sqlx::migrate::MigrationType::ReversibleUp }, MigrationType::ReversibleDown => { - quote! { sqlx::migrate::MigrationType::ReversibleDown } + quote! { ::sqlx::migrate::MigrationType::ReversibleDown } } }; tokens.append_all(ts.into_iter()); @@ -39,12 +39,12 @@ impl ToTokens for QuotedMigration { } = &self; let ts = quote! { - sqlx::migrate::Migration { + ::sqlx::migrate::Migration { version: #version, - description: std::borrow::Cow::Borrowed(#description), + description: ::std::borrow::Cow::Borrowed(#description), migration_type: #migration_type, - sql: std::borrow::Cow::Borrowed(#sql), - checksum: std::borrow::Cow::Borrowed(&[ + sql: :std::borrow::Cow::Borrowed(#sql), + checksum: :std::borrow::Cow::Borrowed(&[ #(#checksum),* ]), } @@ -102,8 +102,8 @@ pub(crate) fn expand_migrator_from_dir(dir: LitStr) -> crate::Result( if input.arg_exprs.is_empty() { return Ok(quote! { - let query_args = <#db_path as sqlx::database::HasArguments>::Arguments::default(); + let query_args = <#db_path as ::sqlx::database::HasArguments>::Arguments::default(); }); } @@ -76,21 +76,21 @@ pub fn quote_args( Ok(quote_spanned!(expr.span() => // this shouldn't actually run if false { - use sqlx::ty_match::{WrapSameExt as _, MatchBorrowExt as _}; + use ::sqlx::ty_match::{WrapSameExt as _, MatchBorrowExt as _}; // evaluate the expression only once in case it contains moves - let _expr = sqlx::ty_match::dupe_value(#name); + let _expr = ::sqlx::ty_match::dupe_value(#name); // if `_expr` is `Option`, get `Option<$ty>`, otherwise `$ty` - let ty_check = sqlx::ty_match::WrapSame::<#param_ty, _>::new(&_expr).wrap_same(); + let ty_check = ::sqlx::ty_match::WrapSame::<#param_ty, _>::new(&_expr).wrap_same(); // if `_expr` is `&str`, convert `String` to `&str` - let (mut _ty_check, match_borrow) = sqlx::ty_match::MatchBorrow::new(ty_check, &_expr); + let (mut _ty_check, match_borrow) = ::sqlx::ty_match::MatchBorrow::new(ty_check, &_expr); _ty_check = match_borrow.match_borrow(); // this causes move-analysis to effectively ignore this block - panic!(); + ::std::panic!(); } )) }) @@ -105,10 +105,10 @@ pub fn quote_args( #args_check - let mut query_args = <#db_path as sqlx::database::HasArguments>::Arguments::default(); + let mut query_args = <#db_path as ::sqlx::database::HasArguments>::Arguments::default(); query_args.reserve( #args_count, - 0 #(+ sqlx::encode::Encode::<#db_path>::size_hint(#arg_name))* + 0 #(+ ::sqlx::encode::Encode::<#db_path>::size_hint(#arg_name))* ); #(query_args.add(#arg_name);)* }) diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index 68170dddff..2c1a71544d 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -253,7 +253,7 @@ where let sql = &input.src; quote! { - sqlx::query_with::<#db_path, _>(#sql, #query_args) + ::sqlx::query_with::<#db_path, _>(#sql, #query_args) } } else { match input.record_type { @@ -309,7 +309,7 @@ where { #[allow(clippy::all)] { - use sqlx::Arguments as _; + use ::sqlx::Arguments as _; #args_tokens diff --git a/sqlx-macros/src/query/output.rs b/sqlx-macros/src/query/output.rs index cde6a85ab7..22df14f3f4 100644 --- a/sqlx-macros/src/query/output.rs +++ b/sqlx-macros/src/query/output.rs @@ -34,7 +34,7 @@ impl ToTokens for ColumnType { tokens.append_all(match &self { ColumnType::Exact(type_) => type_.clone().into_iter(), ColumnType::Wildcard => quote! { _ }.into_iter(), - ColumnType::OptWildcard => quote! { Option<_> }.into_iter(), + ColumnType::OptWildcard => quote! { ::std::option::Option<_> }.into_iter(), }) } } @@ -96,7 +96,7 @@ fn column_to_rust(describe: &Describe, i: usize) -> crate:: }; let type_ = match (type_, nullable) { (ColumnTypeOverride::Exact(type_), false) => ColumnType::Exact(type_.to_token_stream()), - (ColumnTypeOverride::Exact(type_), true) => ColumnType::Exact(quote! { Option<#type_> }), + (ColumnTypeOverride::Exact(type_), true) => ColumnType::Exact(quote! { ::std::option::Option<#type_> }), (ColumnTypeOverride::Wildcard, false) => ColumnType::Wildcard, (ColumnTypeOverride::Wildcard, true) => ColumnType::OptWildcard, @@ -106,7 +106,7 @@ fn column_to_rust(describe: &Describe, i: usize) -> crate:: if !nullable { ColumnType::Exact(type_) } else { - ColumnType::Exact(quote! { Option<#type_> }) + ColumnType::Exact(quote! { ::std::option::Option<#type_> }) } } }; @@ -143,7 +143,7 @@ pub fn quote_query_as( // type was overridden to be a wildcard so we fallback to the runtime check (true, ColumnType::Wildcard) => quote! ( let #ident = row.try_get(#i)?; ), (true, ColumnType::OptWildcard) => { - quote! ( let #ident = row.try_get::, _>(#i)?; ) + quote! ( let #ident = row.try_get::<::std::option::Option<_>, _>(#i)?; ) } // macro is the `_unchecked!()` variant so this will die in decoding if it's wrong (false, _) => quote!( let #ident = row.try_get_unchecked(#i)?; ), @@ -158,8 +158,8 @@ pub fn quote_query_as( let sql = &input.src; quote! { - sqlx::query_with::<#db_path, _>(#sql, #bind_args).try_map(|row: #row_path| { - use sqlx::Row as _; + ::sqlx::query_with::<#db_path, _>(#sql, #bind_args).try_map(|row: #row_path| { + use ::sqlx::Row as _; #(#instantiations)* @@ -189,7 +189,7 @@ pub fn quote_query_scalar( } else if input.checked { let ty = get_column_type::(0, &columns[0]); if describe.nullable(0).unwrap_or(true) { - quote! { Option<#ty> } + quote! { ::std::option::Option<#ty> } } else { ty } @@ -201,7 +201,7 @@ pub fn quote_query_scalar( let query = &input.src; Ok(quote! { - sqlx::query_scalar_with::<#db, #ty, _>(#query, #bind_args) + ::sqlx::query_scalar_with::<#db, #ty, _>(#query, #bind_args) }) }