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

rust_2018_idioms: build warning "hidden lifetime parameters in types are deprecated" #588

Closed
oherrala opened this issue Dec 15, 2021 · 9 comments

Comments

@oherrala
Copy link

I get the following warnings when compiling my code (with 2.25.2):

303 |     fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected named lifetime parameter
    |
    = note: `-W elided-lifetimes-in-paths` implied by `-W rust-2018-idioms`
help: consider using the `'_` lifetime
    |
303 |     fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef<'_> {

Same kind of issue is previously reported in #435.

@stepancheg
Copy link
Owner

Where is this code located?

@oherrala
Copy link
Author

oherrala commented Feb 8, 2022

This is the generated code:

impl ::protobuf::reflect::ProtobufValue for CollectorMessages {
    fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
        ::protobuf::reflect::ReflectValueRef::Message(self)
    }
}

CollectorMessages is defined in protobuf as:

message CollectorMessages {
    oneof message {
        SendObservationRequest send_observation_req = 1;
        SendObservationResponse send_observation_resp = 2;
    }
}

@stepancheg
Copy link
Owner

Did you turn on #[warn(rust_2018_idioms)] explicitly?

Because otherwise I cannot reproduce it.

@oherrala
Copy link
Author

oherrala commented Feb 8, 2022

Yes, apparently so. I just tried turning it on to see the warnings and off to not see them. Sorry I forgot to specify what lints I had turned on (I have quite a few).

export RUSTFLAGS="-W deprecated-in-future -W noop-method-call -W future-incompatible -W nonstandard-style -W rust-2018-compatibility -W rust-2018-idioms -W rust-2021-compatibility -W unused ${RUSTFLAGS}"

@stepancheg
Copy link
Owner

If #[warn(rust_2018_idioms)] was inserted in generated code, would it be enough?

@oherrala
Copy link
Author

oherrala commented Feb 9, 2022

I think the generated code should be modified as described by the linter:

  impl ::protobuf::reflect::ProtobufValue for CollectorMessages {
-     fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
+     fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef<'_> {
          ::protobuf::reflect::ReflectValueRef::Message(self)
      }
  }

@stepancheg
Copy link
Owner

Yes, I think you are right, it would be safer this way.

@stepancheg
Copy link
Owner

Interesting, current version from master does not have this warning (it generate similar code differently).

rust-protobuf v3 will be released in the following weeks. Is it critical to have this warning fixed in rust-protobuf v2?

@oherrala
Copy link
Author

oherrala commented Feb 9, 2022

No, it's not critical. Just annoying.

And can of course be silenced with: #![allow(elided_lifetimes_in_paths)]

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

No branches or pull requests

2 participants