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 fails with "hidden lifetime parameters in types are deprecated" #435

Closed
nickbp opened this issue Jul 31, 2019 · 4 comments · Fixed by #436
Closed

Comments

@nickbp
Copy link
Contributor

nickbp commented Jul 31, 2019

Problem

When project code configures #[deny(rust_2018_idioms)], the generated rust-protobuf code has compilation errors like the following for both 2.8.0 and master/d2a9ddb:

$ cargo build
   Compiling protobuf-busted-example v0.1.0 (/Users/nick/code/protobuf-busted-example)
error: hidden lifetime parameters in types are deprecated
  --> src/sample.rs:55:39
   |
55 |     fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> {
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
   |
note: lint level defined here
  --> src/main.rs:1:19
   |
1  | #![deny(warnings, rust_2018_idioms)]
   |                   ^^^^^^^^^^^^^^^^
   = note: #[deny(elided_lifetimes_in_paths)] implied by #[deny(rust_2018_idioms)]

error: hidden lifetime parameters in types are deprecated
   --> src/sample.rs:100:51
    |
100 |     fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> {
    |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

error: hidden lifetime parameters in types are deprecated
   --> src/sample.rs:177:27
    |
177 |     fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
    |                           ^^^^^^^^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

error: aborting due to 3 previous errors

error: Could not compile `protobuf-busted-example`.

To learn more, run the command again with --verbose.

Environment

$ rustc --version
rustc 1.36.0 (a53f9df32 2019-07-03)

Minimal sample

Cargo.toml

Note: This sample shows master:d2a9ddb, however 2.8.0 produces the same errors.

[package]
name = "protobuf-failure-sample"
version = "0.1.0"
build = "build.rs"

[dependencies]
protobuf = { git="https://github.com/stepancheg/rust-protobuf", rev="d2a9ddb" }

[build-dependencies]
protobuf-codegen-pure = { git="https://github.com/stepancheg/rust-protobuf", rev="d2a9ddb" }

src/main.rs

#![deny(warnings, rust_2018_idioms)]
// If this is not added, the protobuf code will fail to compile:
// #![allow(elided_lifetimes_in_paths)]

use sample::SampleEnum;
mod sample;
extern crate protobuf;

fn main() {
    let foo = SampleEnum::FOO;
    println!("hello world: {:?}", foo);
}

build.rs

extern crate protobuf_codegen_pure;

fn main() {
    protobuf_codegen_pure::Args::new()
        .out_dir("src/")
        .input("proto/sample.proto")
        .include("proto")
        .run()
        .expect("protoc");
}

proto/sample.proto

syntax = "proto3";

enum SampleEnum {
  FOO = 0;
  BAR = 1;
}

message SampleMessage {
  string foo = 1;
  uint32 bar = 2;
  SampleEnum baz = 3;
}

Workarounds

  1. If the generated output is manually updated to include the requested lifetime parameters, the errors go away. For example:
    fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
  1. Alternatively, if my main.rs specifies #![allow(elided_lifetimes_in_paths)] then that also gets rid of the errors. However, just adding #![allow(elided_lifetimes_in_paths)] directly to the generated sample.rs output doesn't seem to do anything.
@stepancheg
Copy link
Owner

If the generated output is manually updated to include the requested lifetime parameters, the errors go away

Yes, I think this is the right way since this is official Rust recommendation.

AFAIU, '_ is stable since Rust 1.26 and minimum supported rust version is 1.27.

Context: this is where rust_2018_idioms specified: rust-lang/rust#52047

Patch welcome.

stepancheg pushed a commit that referenced this issue Aug 1, 2019
Fixes #435: "hidden lifetime parameters in types are deprecated" against generated code when `rust_2018_idioms` is enabled in a project.
@stepancheg stepancheg reopened this Aug 1, 2019
@stepancheg
Copy link
Owner

Reopening since it's not yet merged into stable branch.

@nickbp
Copy link
Contributor Author

nickbp commented Aug 10, 2019

#439 above should do it for stable, assuming that v2.8 is the correct branch for stable. Let me know if it should go to a different branch instead.

stepancheg pushed a commit that referenced this issue Sep 6, 2019
Fixes #435: "hidden lifetime parameters in types are deprecated" against generated code when `rust_2018_idioms` is enabled in a project.
stepancheg pushed a commit that referenced this issue Sep 6, 2019
Fixes #435: "hidden lifetime parameters in types are deprecated" against generated code when `rust_2018_idioms` is enabled in a project.
@stepancheg
Copy link
Owner

In 2.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants