Skip to content

Clippy panics on UTF-8 (Chinese) comments in protobuf-generated Rust code #15156

Open
@EMOAIRX

Description

@EMOAIRX

Summary

Clippy panics with a "byte index is not a char boundary" error when running on Rust code generated from .proto files that contain Chinese (UTF-8) comments. The panic occurs during linting, making it impossible to use clippy on projects with such generated code. Removing the Chinese comments resolves the issue.

Reproducer

To Reproduce Steps to reproduce the behavior:

  1. Create a .proto file with Chinese comments, e.g.:
// 发送启动信号
rpc SendStartSignal(StartSignalRequest) returns (StartSignalResponse);
  1. Use tonic_build or prost_build to generate Rust code from the proto.
  2. Run cargo clippy on the project.
    Expected behavior Clippy should not panic, even if the generated Rust code contains UTF-8 doc comments.

Actual behavior Clippy panics with:

thread 'rustc' panicked at compiler/rustc_resolve/src/rustdoc.rs:573:52:
byte index X is not a char boundary; it is inside '发' (bytes Y..Z) of `/// 发送启动信号`

Version

clippy version: (e.g. clippy 0.1.89 (45f256d9d 2025-05-27))
rustc version: (e.g. rustc 1.89.0-nightly (45f256d9d 2025-05-27))
OS: macOS (Apple Silicon)

Additional Labels

Removing the Chinese comments from the proto file or disabling doc generation avoids the panic.
This only happens with non-ASCII (e.g. Chinese) comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions