rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.85k stars 860 forks source link

Feature Request: Top-level comment for license notice in .rs files #6179

Closed psandana closed 1 month ago

psandana commented 1 month ago

 I want to request/propose an optional feature that will be handy for some projects. Often, projects would like to state their license in the top-level part of every source file. This includes private and public licenses.

It would be handy a formatting option that, if enabled and configured,:

Example:

use something;

fn main() {
something::do_sth();
}

to

// Licensed under the MIT License.
use something;

fn main() {
something::do_sth();
}

This could be a single-line, or multi-line comment, acknowledging that some projects may have 2 or more licenses.

ytmimi commented 1 month ago

There was a time when rustfmt did something like this, but we dropped support for it because we felt that rustfmt wasn't the right tool. You can read more at https://github.com/rust-lang/rustfmt/issues/5103