graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

Generated code fails the `clippy::str_to_string` lint #1146

Closed dnbln closed 1 year ago

dnbln commented 1 year ago

Describe the bug The generated code fails the clippy::str_to_string lint.

To Reproduce

src/main.rs ```rs #![deny(clippy::str_to_string)] struct A; #[juniper::graphql_object] impl A { fn f() -> &'static str { "a" } } fn main() { } ```
Cargo.toml ```toml # Cargo.toml [package] name = "x" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] juniper = "0.15.10" ```
cargo clippy output ``` Checking x v0.1.0 (C:\Users\Dinu\proj\x) error: `to_string()` called on a `&str` --> src\main.rs:5:1 | 5 | #[juniper::graphql_object] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `.to_owned()` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string note: the lint level is defined here --> src\main.rs:1:9 | 1 | #![deny(clippy::str_to_string)] | ^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the attribute macro `juniper::graphql_object` (in Nightly builds, run with -Z macro-backtrace for more info) error: could not compile `x` due to previous error ```

Expected behavior The generated code to pass the lint, or at least ignore it.

Additional context Add any other context about the problem here.

juniper and juniper_codegen in Cargo.lock ```toml # Cargo.lock [[package]] name = "juniper" version = "0.15.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52adf17d43d0b526eed31fac15d9312941c5c2558ffbfb105811690b96d6e2f1" dependencies = [ "async-trait", "bson", "chrono", "fnv", "futures", "futures-enum", "graphql-parser", "indexmap", "juniper_codegen", "serde", "smartstring", "static_assertions", "url", "uuid", ] [[package]] name = "juniper_codegen" version = "0.15.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aee97671061ad50301ba077d054d295e01d31a1868fbd07902db651f987e71db" dependencies = [ "proc-macro-error", "proc-macro2", "quote", "syn", ] ```
ShadowWalker98 commented 1 year ago

Can I try this issue? I am new to Rust though.

LegNeato commented 1 year ago

Of course!

tyranron commented 1 year ago

This is already fixed on master and will be released in 0.16.