Formatting config option: `force_explicit_return`

オープン
#7,155 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
7.1k
フォーク
1.2k
平均マージ
1日 4時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rustfmt のほかの issue

rust-lang/rustfmt の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。