juniper-from-schema icon indicating copy to clipboard operation
juniper-from-schema copied to clipboard

`unnecessary braces` warning while compiling

Open acelot opened this issue 5 years ago • 3 comments

I have very simple GraphQL schema:

schema {
    query: Query
}

type Query {
    ping: Boolean! @juniper(infallible: true, ownership: "owned")
}
use juniper_from_schema::graphql_schema_from_file;
use crate::resources::Resources;

graphql_schema_from_file!("schema.graphql");

pub struct Query;

pub struct Context {
    resources: Resources,
}

impl juniper::Context for Context {}

i get error like this when compiling:

warning: unnecessary braces around block return value
 --> src/graphql/schema.rs:4:1
  |
4 | graphql_schema_from_file!("schema.graphql");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these braces
  |
  = note: `#[warn(unused_braces)]` on by default

What does it mean?

My Cargo.toml:

[dependencies]
juniper = { git = "https://github.com/graphql-rust/juniper", branch = "master" }
juniper-from-schema = { git = "https://github.com/davidpdrsn/juniper-from-schema", branch = "master" }

acelot avatar Oct 16 '20 03:10 acelot

Yeah that warning is caused by some generated code. Haven't quite tracked it down yet. Have a hunch it might be coming from juniper itself.

In the meantime you can silence the warnings by adding #![allow(unused_braces)] at the top of your root module.

davidpdrsn avatar Oct 16 '20 06:10 davidpdrsn

I actually think it makes sense to keep this issue open until its been fixed 😊

davidpdrsn avatar Oct 17 '20 12:10 davidpdrsn

I've looked into this a bit more and I actually think we're hitting this bug https://github.com/rust-lang/rust/issues/70814. If you replace the call to graphql_schema_from_file! with the exact code it expands into you don't get the warning. Very peculiar.

Afaik there is no good fix other than putting #![allow(unused_braces)] at the top of your module. I've subscribed to https://github.com/rust-lang/rust/issues/70814.

Leaving this issue open for other people who might wonder about the same thing.

davidpdrsn avatar Oct 17 '20 13:10 davidpdrsn