Formatting config option: `force_explicit_return`

Đang mở
#7,155 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
tooling

Hướng nghiên cứu

Start by locating the existing force_explicit_abi configuration option and the formatter entry points for function bodies and branches. Done means the new option consistently adds explicit return statements for the shown value-returning and unit-returning examples, with coverage for branching cases.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

C-feature-request P-low

Feature Request

Summary

I'd like the option to force all branches of all functions to use the optional return keyword.

Motivation

I think explicitly stating return rather than relying on the implicit behavior of {} blocks makes code easier to understand at a glance, and especially if there are complicated branching statements inside. (Admittedly, this is mostly a style preference, so I understand that it probably won't be a high-priority change.)

For a toy example, the proposed formatting option should change this:

fn add_one(x: u32) -> u32 {
    x + 1
}

fn foo() -> () {
    println!("This function has no return value!");
}

to this:

fn add_one(x: u32) -> u32 {
    return x + 1;
}

fn foo() -> () {
    println!("This function has no return value!");
    return;
}

This syntax is more familiar to developers with backgrounds in other languages, such as C/C++, and follows the common Rust pattern that explicit is better than implicit.

Related configuration options

I wasn't able to find anything that was directly related to my proposed option, but it would follow in the spirit of options like force_explicit_abi.

Ngôn ngữ chính
Rust
Star
7.1k
Fork
1.2k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rustfmt

Tất cả issue của rust-lang/rustfmt

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.