tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.69k stars 481 forks source link

include_file does not work if any of the modules does not declare a package #1001

Closed MixusMinimax closed 2 months ago

MixusMinimax commented 4 months ago

a simple .proto file with no package will result in a Module object with an empty vector.

However, the following code is called 1035 in lib.rs of prost-build:

self.write_includes(
    modules.keys().collect(),
    &mut file,
    0,
    if target_is_env { None } else { Some(&target) },
)?;

That function starts at depth 0, meaning it tries to check modules whether module.part(0) is equal to something, which panics, as that vector is empty:

let modident = entries[0].part(depth);
let matching: Vec<&Module> = entries
    .iter()
    .filter(|&v| v.part(depth) == modident)
    .copied()
    .collect();
MixusMinimax commented 4 months ago

I have created a pull request at #1002!