Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully qualify Result in macro output #294

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions edgedb-derive/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
let type_id_check = Some(quote! {
if ctx.has_implicit_tid {
if(!shape.elements[idx].flag_implicit) {
return Err(ctx.expected("implicit __tid__"));
return ::std::result::Result::Err(ctx.expected("implicit __tid__"));
}
idx += 1;
}
});
let type_name_check = Some(quote! {
if ctx.has_implicit_tname {
if(!shape.elements[idx].flag_implicit) {
return Err(ctx.expected("implicit __tname__"));
return ::std::result::Result::Err(ctx.expected("implicit __tname__"));
}
idx += 1;
}
});
let id_check = Some(quote! {
if ctx.has_implicit_id {
if(!shape.elements[idx].flag_implicit) {
return Err(ctx.expected("implicit id"));
return ::std::result::Result::Err(ctx.expected("implicit id"));
}
idx += 1;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
let mut result = quote!{
let el = &shape.elements[idx];
if(el.name != #name_str) {
return Err(ctx.wrong_field(#name_str, &el.name));
return ::std::result::Result::Err(ctx.wrong_field(#name_str, &el.name));
}
idx += 1;
};
Expand All @@ -127,7 +127,7 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
impl #impl_generics ::edgedb_protocol::queryable::Queryable
for #name #ty_generics {
fn decode(#decoder: &::edgedb_protocol::queryable::Decoder, #buf: &[u8])
-> Result<Self, ::edgedb_protocol::errors::DecodeError>
-> ::std::result::Result<Self, ::edgedb_protocol::errors::DecodeError>
{
let #nfields = #base_fields
+ if #decoder.has_implicit_id { 1 } else { 0 }
Expand All @@ -141,7 +141,7 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
#type_name_block
#id_block
#field_decoders
Ok(#name {
::std::result::Result::Ok(#name {
#(
#fieldname,
)*
Expand All @@ -150,14 +150,14 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
fn check_descriptor(
ctx: &::edgedb_protocol::queryable::DescriptorContext,
type_pos: ::edgedb_protocol::descriptors::TypePos)
-> Result<(), ::edgedb_protocol::queryable::DescriptorMismatch>
-> ::std::result::Result<(), ::edgedb_protocol::queryable::DescriptorMismatch>
{
use ::edgedb_protocol::descriptors::Descriptor::ObjectShape;
let desc = ctx.get(type_pos)?;
let shape = match desc {
ObjectShape(shape) => shape,
_ => {
return Err(ctx.wrong_type(desc, "str"))
return ::std::result::Result::Err(ctx.wrong_type(desc, "str"))
}
};

Expand All @@ -170,10 +170,10 @@ pub fn derive_struct(s: &syn::ItemStruct) -> syn::Result<TokenStream> {
#field_checks

if(shape.elements.len() != idx) {
return Err(ctx.field_number(
return ::std::result::Result::Err(ctx.field_number(
shape.elements.len(), idx));
}
Ok(())
::std::result::Result::Ok(())
}
}
};
Expand Down
9 changes: 9 additions & 0 deletions edgedb-derive/tests/no-prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// a macro should always fully qualify names it uses, so it works even if the relevant item hasn't been imported, or a conflicting item has been imported
// this test ensures that the code generated by the derive Queryable macro does not reference names from the prelude
#![no_implicit_prelude]

#[derive(::edgedb_derive::Queryable)]
#[allow(dead_code)]
struct Test {
field: i64,
}
Loading