Skip to content

Incorrect multi-line comment format. #1853

@Lingxuan-Ye

Description

@Lingxuan-Ye

行文风格约定一节中,Rust 的多行注释有误。当前格式为:

/**
 * 多行
 * 注释
 */

然而,这是外部文档注释的多行注释形式,它是承担语义的,在没有尾随项的情况下,它会抛出硬错误:

error: expected item after doc comment
 --> src/lib.rs:1:1
  |
1 | / /**
2 | |  * 多行
3 | |  * 注释
4 | |  */
  | |___^ this doc comment doesn't document anything

一种解决方案是使用正常的多行注释:

/*
 * 多行
 * 注释
 */

但根据 Rust Style Guide,我更推荐的解决方案是:

// 多行
// 注释

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions