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

Use an anonymous const rather than a dummy name #65

Merged

Conversation

CodingAnarchy
Copy link
Contributor

@CodingAnarchy CodingAnarchy commented May 17, 2024

Running on the nightly compiler produced this warning for us:

warning: non-local `impl` definition, they should be avoided as they go against expectation
    --> /Users/mtanous/src/github.com/Shopify/shopify-cdp/grpc/target/debug/build/shopify-cdp-grpc-663ae16d1a1bc1bf/out/shopify.cdp.v1.rs:6495:1347
     |
6495 | ...st IMPL_MESSAGE_SERDE_FOR_NODE : () = { use :: prost_wkt :: typetag ; # [typetag :: serde (name = "type.googleapis.com/shopify.cdp.v1.Node")] impl :: prost_wkt :: MessageSerde for Node { fn package_name (& self) -> & 'static str { "shopify.cdp.v1" } fn message_name (& self) -> & 'static str { "Node" } fn type_url (& self) -> & 'static str { "type.googleapis.com/shopify.cdp.v1.Node" } fn new_instance (& self , data : Vec < u8 >) -> :: std :: result :: Result < Box < dyn :: prost_wkt :: MessageSerde > , :: prost :: DecodeError > { let mut target = Self :: default () ; :: prost :: Message :: merge (& mut target , data . as_slice ()) ? ; let erased : :: std :: boxed :: Box < dyn :: prost_wkt :: MessageSerde > = :: std :: boxed :: Box :: new (target) ; Ok (erased) } fn try_encoded (& self) -> :: std :: result :: Result < :: std :: vec :: Vec < u8 > , :: prost :: EncodeError > { let mut buf = :: std :: vec :: Vec :: with_capacity (:: prost :: Message :: encoded_len (self)) ; :: prost :: Message :: encode (self , & mut buf) ? ; Ok (buf) } } :: prost_wkt :: inventory :: submit ! { :: prost_wkt :: MessageSerdeDecoderEntry { type_url : "type.googleapis.com/shopify.cdp.v1.Node" , decoder : | buf : & [u8] | { let msg : Node = :: prost :: Message :: decode (buf) ? ; Ok (:: std :: boxed :: Box :: new (msg)) } } } impl :: prost :: Name for Node { const PACKAGE : & 'static str = "shopify.cdp.v1" ; const NAME : & 'static str = "Node" ; fn type_url () -> String { "type.googleapis.com/shopify.cdp.v1.Node" . to_string () } } ...
     |       --------------------------- help: use a const-anon item to suppress this lint: `_`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: move this `impl` block outside the of the current constant `IMPL_MESSAGE_SERDE_FOR_NODE`
     = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
     = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
     = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

As noted in the linter warning, the exception to the rule on this lint is an anon-const. This small PR updates from using IMPL_MESSAGE_SERDE_FOR_{} to just the anon-const _ for the const block that defines the impl.

I've validated that this still works in our codebase and does not throw the linter warning. The impetus here is to pave the way for this lint may become deny-by-default in the edition 2024 so when we (and other folks) transition, we don't get errors.

@fdeantoni
Copy link
Owner

Many thanks for putting this together! I will try to cut a new release by next week which will include this one.

@fdeantoni fdeantoni merged commit ec5a74e into fdeantoni:master Jun 3, 2024
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants