Skip to content

Commit 7a3b7c9

Browse files
alexregtopecongiro
authored andcommitted
Various cosmetic improvements (rust-lang#3403)
1 parent 74755e8 commit 7a3b7c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+198
-603
lines changed

build.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
use std::env;
122
use std::fs::File;
133
use std::io::Write;

src/attr.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
//! Format attributes and meta items.
122
133
use syntax::ast;

src/bin/main.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
use env_logger;
122
#[macro_use]
133
extern crate failure;
@@ -45,7 +35,7 @@ fn main() {
4535

4636
// Exit with given exit code.
4737
//
48-
// NOTE: This immediately terminates the process without doing any cleanup,
38+
// NOTE: this immediately terminates the process without doing any cleanup,
4939
// so make sure to finish all necessary cleanup before this is called.
5040
std::process::exit(exit_code);
5141
}

src/cargo-fmt/main.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
// Copyright 2015-2016 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
11-
// Inspired by Paul Woolcock's cargo-fmt (https://github.com/pwoolcoc/cargo-fmt/)
1+
// Inspired by Paul Woolcock's cargo-fmt (https://github.com/pwoolcoc/cargo-fmt/).
122

133
#![cfg(not(test))]
144
#![deny(warnings)]
@@ -146,12 +136,12 @@ fn format_crate(verbosity: Verbosity, strategy: &CargoFmtStrategy) -> Result<i32
146136
get_targets(strategy)?
147137
};
148138

149-
// Currently only bin and lib files get formatted
139+
// Currently only bin and lib files get formatted.
150140
run_rustfmt(&targets, &rustfmt_args, verbosity)
151141
}
152142

153143
fn get_fmt_args() -> Vec<String> {
154-
// All arguments after -- are passed to rustfmt
144+
// All arguments after -- are passed to rustfmt.
155145
env::args().skip_while(|a| a != "--").skip(1).collect()
156146
}
157147

@@ -160,7 +150,7 @@ fn get_fmt_args() -> Vec<String> {
160150
pub struct Target {
161151
/// A path to the main source file of the target.
162152
path: PathBuf,
163-
/// A kind of target (e.g. lib, bin, example, ...).
153+
/// A kind of target (e.g., lib, bin, example, ...).
164154
kind: String,
165155
/// Rust edition for this target.
166156
edition: String,

src/chains.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
11-
//! Formatting of chained expressions, i.e. expressions which are chained by
12-
//! dots: struct and enum field access, method calls, and try shorthand (?).
1+
//! Formatting of chained expressions, i.e., expressions that are chained by
2+
//! dots: struct and enum field access, method calls, and try shorthand (`?`).
133
//!
144
//! Instead of walking these subexpressions one-by-one, as is our usual strategy
155
//! for expression formatting, we collect maximal sequences of these expressions
@@ -534,7 +524,7 @@ impl<'a> ChainFormatterShared<'a> {
534524
// ```
535525
//
536526
// In particular, overflowing is effective when the last child is a method with a multi-lined
537-
// block-like argument (e.g. closure):
527+
// block-like argument (e.g., closure):
538528
// ```ignore
539529
// parent.child1.child2.last_child(|a, b, c| {
540530
// let x = foo(a, b, c);
@@ -853,7 +843,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
853843
}
854844
}
855845

856-
/// Remove try operators (`?`s) that appear in the given string. If removing
846+
/// Removes try operators (`?`s) that appear in the given string. If removing
857847
/// them leaves an empty line, remove that line as well unless it is the first
858848
/// line (we need the first newline for detecting pre/post comment).
859849
fn trim_tries(s: &str) -> String {

src/checkstyle.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
use std::io::{self, Write};
122
use std::path::Path;
133

src/closures.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
use syntax::parse::classify;
122
use syntax::source_map::Span;
133
use syntax::{ast, ptr};
@@ -360,7 +350,7 @@ pub fn rewrite_last_closure(
360350
None
361351
}
362352

363-
/// Returns true if the given vector of arguments has more than one `ast::ExprKind::Closure`.
353+
/// Returns `true` if the given vector of arguments has more than one `ast::ExprKind::Closure`.
364354
pub fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
365355
args.iter()
366356
.filter_map(|arg| arg.to_expr())

src/comment.rs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
111
// Formatting and tools for comments.
122

133
use std::{self, borrow::Cow, iter};
@@ -54,7 +44,7 @@ fn custom_opener(s: &str) -> &str {
5444
}
5545

5646
impl<'a> CommentStyle<'a> {
57-
/// Returns true if the commenting style covers a line only.
47+
/// Returns `true` if the commenting style covers a line only.
5848
pub fn is_line_comment(&self) -> bool {
5949
match *self {
6050
CommentStyle::DoubleSlash
@@ -65,7 +55,7 @@ impl<'a> CommentStyle<'a> {
6555
}
6656
}
6757

68-
/// Returns true if the commenting style can span over multiple lines.
58+
/// Returns `true` if the commenting style can span over multiple lines.
6959
pub fn is_block_comment(&self) -> bool {
7060
match *self {
7161
CommentStyle::SingleBullet | CommentStyle::DoubleBullet | CommentStyle::Exclamation => {
@@ -75,7 +65,7 @@ impl<'a> CommentStyle<'a> {
7565
}
7666
}
7767

78-
/// Returns true if the commenting style is for documentation.
68+
/// Returns `true` if the commenting style is for documentation.
7969
pub fn is_doc_comment(&self) -> bool {
8070
match *self {
8171
CommentStyle::TripleSlash | CommentStyle::Doc => true,
@@ -439,7 +429,7 @@ struct ItemizedBlock {
439429
}
440430

441431
impl ItemizedBlock {
442-
/// Returns true if the line is formatted as an item
432+
/// Returns `true` if the line is formatted as an item
443433
fn is_itemized_line(line: &str) -> bool {
444434
let trimmed = line.trim_start();
445435
trimmed.starts_with("* ") || trimmed.starts_with("- ")
@@ -458,7 +448,7 @@ impl ItemizedBlock {
458448
}
459449
}
460450

461-
/// Returns a `StringFormat` used for formatting the content of an item
451+
/// Returns a `StringFormat` used for formatting the content of an item.
462452
fn create_string_format<'a>(&'a self, fmt: &'a StringFormat<'_>) -> StringFormat<'a> {
463453
StringFormat {
464454
opener: "",
@@ -471,8 +461,8 @@ impl ItemizedBlock {
471461
}
472462
}
473463

474-
/// Returns true if the line is part of the current itemized block.
475-
/// If it is, then it is added to the internal lines vec.
464+
/// Returns `true` if the line is part of the current itemized block.
465+
/// If it is, then it is added to the internal lines list.
476466
fn add_line(&mut self, line: &str) -> bool {
477467
if !ItemizedBlock::is_itemized_line(line)
478468
&& self.indent <= line.chars().take_while(|c| c.is_whitespace()).count()
@@ -491,7 +481,7 @@ impl ItemizedBlock {
491481
.collect::<String>()
492482
}
493483

494-
/// Returns the block as a string under its original form
484+
/// Returns the block as a string under its original form.
495485
fn original_block_as_string(&self) -> String {
496486
self.lines.join("\n")
497487
}
@@ -842,7 +832,7 @@ fn trim_custom_comment_prefix(s: &str) -> String {
842832
.join("\n")
843833
}
844834

845-
/// Returns true if the given string MAY include URLs or alike.
835+
/// Returns `true` if the given string MAY include URLs or alike.
846836
fn has_url(s: &str) -> bool {
847837
// This function may return false positive, but should get its job done in most cases.
848838
s.contains("https://") || s.contains("http://") || s.contains("ftp://") || s.contains("file://")
@@ -1000,8 +990,8 @@ impl FindUncommented for str {
1000990

1001991
// Returns the first byte position after the first comment. The given string
1002992
// is expected to be prefixed by a comment, including delimiters.
1003-
// Good: "/* /* inner */ outer */ code();"
1004-
// Bad: "code(); // hello\n world!"
993+
// Good: `/* /* inner */ outer */ code();`
994+
// Bad: `code(); // hello\n world!`
1005995
pub fn find_comment_end(s: &str) -> Option<usize> {
1006996
let mut iter = CharClasses::new(s.char_indices());
1007997
for (kind, (i, _c)) in &mut iter {
@@ -1010,15 +1000,15 @@ pub fn find_comment_end(s: &str) -> Option<usize> {
10101000
}
10111001
}
10121002

1013-
// Handle case where the comment ends at the end of s.
1003+
// Handle case where the comment ends at the end of `s`.
10141004
if iter.status == CharClassesStatus::Normal {
10151005
Some(s.len())
10161006
} else {
10171007
None
10181008
}
10191009
}
10201010

1021-
/// Returns true if text contains any comment.
1011+
/// Returns `true` if text contains any comment.
10221012
pub fn contains_comment(text: &str) -> bool {
10231013
CharClasses::new(text.chars()).any(|(kind, _)| kind.is_comment())
10241014
}
@@ -1540,7 +1530,7 @@ impl<'a> Iterator for CommentCodeSlices<'a> {
15401530
}
15411531

15421532
/// Checks is `new` didn't miss any comment from `span`, if it removed any, return previous text
1543-
/// (if it fits in the width/offset, else return None), else return `new`
1533+
/// (if it fits in the width/offset, else return `None`), else return `new`
15441534
pub fn recover_comment_removed(
15451535
new: String,
15461536
span: Span,
@@ -1583,14 +1573,14 @@ pub fn filter_normal_code(code: &str) -> String {
15831573
buffer
15841574
}
15851575

1586-
/// Return true if the two strings of code have the same payload of comments.
1576+
/// Returns `true` if the two strings of code have the same payload of comments.
15871577
/// The payload of comments is everything in the string except:
1588-
/// - actual code (not comments)
1589-
/// - comment start/end marks
1590-
/// - whitespace
1591-
/// - '*' at the beginning of lines in block comments
1578+
/// - actual code (not comments),
1579+
/// - comment start/end marks,
1580+
/// - whitespace,
1581+
/// - '*' at the beginning of lines in block comments.
15921582
fn changed_comment_content(orig: &str, new: &str) -> bool {
1593-
// Cannot write this as a fn since we cannot return types containing closures
1583+
// Cannot write this as a fn since we cannot return types containing closures.
15941584
let code_comment_content = |code| {
15951585
let slices = UngroupedCommentCodeSlices::new(code);
15961586
slices
@@ -1625,7 +1615,8 @@ impl<'a> CommentReducer<'a> {
16251615
let comment = remove_comment_header(comment);
16261616
CommentReducer {
16271617
is_block,
1628-
at_start_line: false, // There are no supplementary '*' on the first line
1618+
// There are no supplementary '*' on the first line.
1619+
at_start_line: false,
16291620
iter: comment.chars(),
16301621
}
16311622
}
@@ -1641,7 +1632,7 @@ impl<'a> Iterator for CommentReducer<'a> {
16411632
while c.is_whitespace() {
16421633
c = self.iter.next()?;
16431634
}
1644-
// Ignore leading '*'
1635+
// Ignore leading '*'.
16451636
if c == '*' {
16461637
c = self.iter.next()?;
16471638
}
@@ -1777,7 +1768,7 @@ mod test {
17771768
&wrap_normalize_config).unwrap();
17781769
assert_eq!("/* trimmed */", comment);
17791770

1780-
// check that different comment style are properly recognised
1771+
// Check that different comment style are properly recognised.
17811772
let comment = rewrite_comment(r#"/// test1
17821773
/// test2
17831774
/*
@@ -1788,7 +1779,7 @@ mod test {
17881779
&wrap_normalize_config).unwrap();
17891780
assert_eq!("/// test1\n/// test2\n// test3", comment);
17901781

1791-
// check that the blank line marks the end of a commented paragraph
1782+
// Check that the blank line marks the end of a commented paragraph.
17921783
let comment = rewrite_comment(r#"// test1
17931784
17941785
// test2"#,
@@ -1797,7 +1788,7 @@ mod test {
17971788
&wrap_normalize_config).unwrap();
17981789
assert_eq!("// test1\n\n// test2", comment);
17991790

1800-
// check that the blank line marks the end of a custom-commented paragraph
1791+
// Check that the blank line marks the end of a custom-commented paragraph.
18011792
let comment = rewrite_comment(r#"//@ test1
18021793
18031794
//@ test2"#,
@@ -1806,7 +1797,7 @@ mod test {
18061797
&wrap_normalize_config).unwrap();
18071798
assert_eq!("//@ test1\n\n//@ test2", comment);
18081799

1809-
// check that bare lines are just indented but left unchanged otherwise
1800+
// Check that bare lines are just indented but otherwise left unchanged.
18101801
let comment = rewrite_comment(r#"// test1
18111802
/*
18121803
a bare line!
@@ -1819,8 +1810,8 @@ mod test {
18191810
assert_eq!("// test1\n/*\n a bare line!\n\n another bare line!\n*/", comment);
18201811
}
18211812

1822-
// This is probably intended to be a non-test fn, but it is not used. I'm
1823-
// keeping it around unless it helps us test stuff.
1813+
// This is probably intended to be a non-test fn, but it is not used.
1814+
// We should keep this around unless it helps us test stuff to remove it.
18241815
fn uncommented(text: &str) -> String {
18251816
CharClasses::new(text.chars())
18261817
.filter_map(|(s, c)| match s {

0 commit comments

Comments
 (0)