Skip to content

Commit 7443503

Browse files
committed
Changes per comments - remove comments from code and clarify/split test file
1 parent 4f2febe commit 7443503

13 files changed

+326
-365
lines changed

src/formatting/visitor.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
486486
// For use/extern crate items, skip rewriting attributes but check for a skip attribute.
487487
ast::ItemKind::Use(..) | ast::ItemKind::ExternCrate(_) => {
488488
if contains_skip(attrs) {
489-
// `item.span()` includes the attributes, while `item.span` does not.
490489
self.push_skipped_with_span(attrs.as_slice(), item.span(), item.span);
491490
false
492491
} else {
@@ -496,7 +495,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
496495
// Module is inline, in this case we treat it like any other item.
497496
_ if !is_mod_decl(item) => {
498497
if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {
499-
// `item.span()` includes the attributes, while `item.span` does not.
500498
self.push_skipped_with_span(item.attrs.as_slice(), item.span(), item.span);
501499
false
502500
} else {
@@ -517,7 +515,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
517515
}
518516
_ => {
519517
if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {
520-
// `item.span()` includes the attributes, while `item.span` does not.
521518
self.push_skipped_with_span(item.attrs.as_slice(), item.span(), item.span);
522519
false
523520
} else {
@@ -675,7 +672,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
675672
skip_out_of_file_lines_range_visitor!(self, ti.span);
676673

677674
if self.visit_attrs(&ti.attrs, ast::AttrStyle::Outer) {
678-
// `ti.span()` includes the attributes, while `ti.span` does not.
679675
self.push_skipped_with_span(ti.attrs.as_slice(), ti.span(), ti.span);
680676
return;
681677
}
@@ -736,7 +732,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
736732
skip_out_of_file_lines_range_visitor!(self, ii.span);
737733

738734
if self.visit_attrs(&ii.attrs, ast::AttrStyle::Outer) {
739-
// `ii.span()` includes the attributes, while `ii.span` does not.
740735
self.push_skipped_with_span(ii.attrs.as_slice(), ii.span(), ii.span);
741736
return;
742737
}

tests/source/issue-4499.rs

Lines changed: 0 additions & 180 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// *** Doc comment which is attribute vs one-line comment
2+
// *** All source lines starts with indent by 3 tabls.
3+
impl Struct {
4+
/// Documentation for `foo`
5+
#[rustfmt::skip]
6+
#[allow(non_snake_case)]
7+
pub fn foo(&self) {}
8+
}
9+
10+
impl Struct {
11+
// Comment for `foo`
12+
#[rustfmt::skip]
13+
#[allow(non_snake_case)]
14+
pub fn foo(&self) {}
15+
}
16+
17+
fn main() {
18+
/// Documentation for `foo`
19+
#[rustfmt::skip]
20+
#[allow(non_snake_case)]
21+
pub fn foo(&self) {}
22+
}
23+
24+
fn main() {
25+
// Comment for `foo`
26+
#[rustfmt::skip] // comment on why use a skip here
27+
#[allow(non_snake_case)]
28+
pub fn foo(&self) {}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// *** "rustfmt::skip" and Use/Extern
2+
// *** All source lines starts with indent by 3 tabls.
3+
#[rustfmt::skip]
4+
use rustc_ast::{ast, attr::HasAttrs, token::DelimToken, visit};
5+
use crate::config::{BraceStyle, Config};
6+
use crate::formatting::{
7+
attr::*,
8+
modules::{FileModMap, Module},
9+
};
10+
11+
use rustc_ast::{ast, attr::HasAttrs, token::DelimToken, visit};
12+
#[rustfmt::skip]
13+
use crate::config::{BraceStyle, Config};
14+
use crate::formatting::{
15+
attr::*,
16+
modules::{FileModMap, Module},
17+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// *** "rustfmt::skip" and Trait with Attributes
2+
// *** All source lines starts with indent by 3 tabls.
3+
#[rustfmt::skip]
4+
#[allow(non_snake_case)]
5+
trait Animal1 {
6+
// Static method signature; `Self` refers to the implementor type.
7+
fn new(name: &'static str) -> Self;
8+
9+
// Traits can provide default method definitions.
10+
fn talk(&self) {
11+
println!("{} says {}", self.name(), self.noise());
12+
}
13+
}
14+
15+
trait Animal2 {
16+
// Static method signature; `Self` refers to the implementor type.
17+
fn new(name: &'static str) -> Self;
18+
19+
// Instance method signatures; these will return a string.
20+
fn name(&self) -> &'static str;
21+
#[rustfmt::skip]
22+
#[allow(non_snake_case)]
23+
fn noise(&self) -> &'static str;
24+
25+
fn talk(&self) {
26+
// Traits can provide default method definitions.
27+
#[rustfmt::skip]
28+
#[allow(non_snake_case)]
29+
fn name(&self) -> &'static str;
30+
println!("{} says {}", self.name(), self.noise());
31+
}
32+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// *** "rustfmt::skip" as first line
2+
3+
// *** Original code from issue #4499
4+
#[rustfmt::skip]
5+
/** Comment.
6+
7+
Rustfmt skips this as expected. */
8+
fn main() {
9+
for _ in 1..Foo::getRandomNumber() {
10+
println!("Hello, world!");
11+
}
12+
}
13+
14+
struct Foo;
15+
impl Foo {
16+
#[rustfmt::skip]
17+
/** Comment.
18+
19+
Rustfmt unindents this despite the ::skip above. */
20+
#[allow(non_snake_case)]
21+
pub fn getRandomNumber() -> i32 { 4 }
22+
}
23+
24+
// *** Other test with "rustfmt::skip" as first line;
25+
// *** All source lines starts with indent by 3 tabls.
26+
#[rustfmt::skip]
27+
/** Comment line 1
28+
comment line 2. */
29+
#[allow(non_snake_case)]
30+
impl Foo {
31+
pub fn getRandomNumber() -> i32 { 4 }
32+
}
33+
34+
#[rustfmt::skip]
35+
/** Comment line 1
36+
comment line 2. */
37+
fn main() {
38+
x = y;
39+
}
40+
41+
// *** "rustfmt::skip" as first line inside a module
42+
impl Foo {
43+
#[rustfmt::skip]
44+
/** Comment line 1
45+
comment line 2. */
46+
#[allow(non_snake_case)]
47+
pub fn getRandomNumber() -> i32 { 4 }
48+
}
49+
50+
fn main() {
51+
#[rustfmt::skip]
52+
/** Comment line 1
53+
comment line 2. */
54+
#[allow(non_snake_case)]
55+
x = y;
56+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// *** "rustfmt::skip" whithin a block of attributes
2+
// *** All source lines starts with indent by 3 tabls.
3+
fn main() {
4+
#[rustfmt::skip]
5+
// Comment 1
6+
#[allow(non_snake_case)]
7+
// Comment 2
8+
#[allow(non_snake_case)]
9+
pub fn foo(&self) {}
10+
}
11+
12+
impl Foo {
13+
// Comment 1
14+
#[rustfmt::skip]
15+
#[allow(non_snake_case)]
16+
// Comment 2
17+
#[allow(non_snake_case)]
18+
pub fn foo(&self) {}
19+
}
20+
21+
impl Foo {
22+
// Comment 1
23+
#[allow(non_snake_case)]
24+
// Comment 2
25+
#[allow(non_snake_case)]
26+
#[rustfmt::skip]
27+
#[allow(non_snake_case)]
28+
pub fn foo(&self) {}
29+
}

0 commit comments

Comments
 (0)