Skip to content

rust_2018_idioms: build fails with "hidden lifetime parameters in types are deprecated" #435

Closed
@nickbp

Description

@nickbp

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions