Skip to content

Formatting config option: force_explicit_return #7155

Open

Description

@wiegman-miftek

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.

Activity

  1. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Sep 30, 2026
  2. removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: a feature request (not decided/implemented)P-lowLow priority

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions