tokio-rs / prost

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

Use of "Self" in stripped enum variants #997

Closed MixusMinimax closed 5 months ago

MixusMinimax commented 6 months ago

Version: 0.12.3

Problem:

Generated enum variants are only sanitized for "Self", if prefix-stripping is not used, or does not apply.

Minimal reproducable protobuf defininition:

enum Feeding {
  FEEDING_UNSPECIFIED = 0;
  FEEDING_ASSISTED = 1;
  // Careful: code generation resulted in "Self".
  FEEDING_SELF = 2;
}

Reason:

The existing code does this:

  1. convert FEEDING_SELF into FeedingSelf
  2. sanitize if that equals Self to replace with Self_
  3. if prefix stripping is enabled:
    1. Extracts the type name, in this case Feeding
    2. convert Feeding to Feeding
    3. sanitize if that equals Self to replace with Self_
    4. Remove the prefix Feeding from FeedingSelf, resulting in Self

The final result is Self, which is not sanitized after.

MixusMinimax commented 6 months ago

The logic is already described in #179, the only missing cases are enum variants after prefix stripping.

MixusMinimax commented 6 months ago

I have created a pull request at #998!