|
| 1 | +// Different "rustfmt::skip" (not)formatting tests |
| 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 | +// ****** "rustfmt::skip" as first line |
| 25 | + #[rustfmt::skip] |
| 26 | + /** Comment. |
| 27 | +
|
| 28 | + Rustfmt unindents this despite the ::skip above. */ |
| 29 | + #[allow(non_snake_case)] |
| 30 | + impl Foo { |
| 31 | + pub fn getRandomNumber() -> i32 { 4 } |
| 32 | +} |
| 33 | + |
| 34 | + #[rustfmt::skip] |
| 35 | + /** Comment. |
| 36 | +
|
| 37 | +Rustfmt skips this as expected. */ |
| 38 | + fn main() { |
| 39 | + for _ in 1..Foo::getRandomNumber() { |
| 40 | +println!("Hello, world!"); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// ****** "rustfmt::skip" as first line inside a module |
| 45 | + impl Foo { |
| 46 | + #[rustfmt::skip] |
| 47 | + /** Comment. |
| 48 | +
|
| 49 | + Rustfmt unindents this despite the ::skip above. */ |
| 50 | + #[allow(non_snake_case)] |
| 51 | + pub fn getRandomNumber() -> i32 { 4 } |
| 52 | +} |
| 53 | + |
| 54 | + fn main() { |
| 55 | + #[rustfmt::skip] |
| 56 | + /** Comment. |
| 57 | +
|
| 58 | +Rustfmt unindents this despite the ::skip above. */ |
| 59 | + #[allow(non_snake_case)] |
| 60 | + pub fn getRandomNumber() -> i32 { 4 } |
| 61 | +} |
| 62 | + |
| 63 | +// ******** "rustfmt::skip" whithin a block of attributes |
| 64 | +fn main() { |
| 65 | + // Comment 1 |
| 66 | +// Comment 2 |
| 67 | + #[allow(non_snake_case)] |
| 68 | + // Comment 3 |
| 69 | + #[allow(non_snake_case)] |
| 70 | + #[allow(non_snake_case)] |
| 71 | + #[allow(non_snake_case)] |
| 72 | +#[rustfmt::skip] |
| 73 | + #[allow(non_snake_case)] |
| 74 | + #[allow(non_snake_case)] |
| 75 | + #[allow(non_snake_case)] |
| 76 | +pub fn foo(&self) {} |
| 77 | +} |
| 78 | + |
| 79 | +impl Foo { |
| 80 | + // Comment 1 |
| 81 | +// Comment 2 |
| 82 | + #[allow(non_snake_case)] |
| 83 | + // Comment 3 |
| 84 | + #[allow(non_snake_case)] |
| 85 | + #[allow(non_snake_case)] |
| 86 | + #[allow(non_snake_case)] |
| 87 | +#[rustfmt::skip] |
| 88 | + #[allow(non_snake_case)] |
| 89 | + #[allow(non_snake_case)] |
| 90 | + #[allow(non_snake_case)] |
| 91 | +pub fn foo(&self) {} |
| 92 | +} |
| 93 | + |
| 94 | +// ******* Doc comment which is attribute vs one-line comment |
| 95 | +impl Struct { |
| 96 | + /// Documentation for `foo` |
| 97 | + #[rustfmt::skip] |
| 98 | + #[allow(non_snake_case)] |
| 99 | + pub fn foo(&self) {} |
| 100 | +} |
| 101 | + |
| 102 | +impl Struct { |
| 103 | + // Comment for `foo` |
| 104 | + #[rustfmt::skip] |
| 105 | + #[allow(non_snake_case)] |
| 106 | + pub fn foo(&self) {} |
| 107 | +} |
| 108 | + |
| 109 | +fn main() { |
| 110 | + /// Documentation for `foo` |
| 111 | + #[rustfmt::skip] |
| 112 | + #[allow(non_snake_case)] |
| 113 | + pub fn foo(&self) {} |
| 114 | +} |
| 115 | + |
| 116 | +fn main() { |
| 117 | + // Comment for `foo` |
| 118 | + #[rustfmt::skip] // comment on why use a skip here |
| 119 | + #[allow(non_snake_case)] |
| 120 | + pub fn foo(&self) {} |
| 121 | +} |
| 122 | + |
| 123 | +// ******** "rustfmt::skip" and Use/Extern |
| 124 | + #[rustfmt::skip] |
| 125 | + use rustc_ast::{ast, attr::HasAttrs, token::DelimToken, visit}; |
| 126 | + use rustc_span::{symbol, BytePos, Pos, Span, DUMMY_SP}; |
| 127 | + use crate::config::{BraceStyle, Config}; |
| 128 | + use crate::formatting::{ |
| 129 | + attr::*, |
| 130 | + macros::{macro_style, rewrite_macro, rewrite_macro_def, MacroPosition}, |
| 131 | + modules::{FileModMap, Module}, |
| 132 | + }; |
| 133 | + |
| 134 | + use rustc_ast::{ast, attr::HasAttrs, token::DelimToken, visit}; |
| 135 | + use rustc_span::{symbol, BytePos, Pos, Span, DUMMY_SP}; |
| 136 | + #[rustfmt::skip] |
| 137 | + use crate::config::{BraceStyle, Config}; |
| 138 | + use crate::formatting::{ |
| 139 | + attr::*, |
| 140 | + macros::{macro_style, rewrite_macro, rewrite_macro_def, MacroPosition}, |
| 141 | + modules::{FileModMap, Module}, |
| 142 | + }; |
| 143 | + |
| 144 | +// ******** "rustfmt::skip" and `is_mod_decl(item)` ????? |
| 145 | + |
| 146 | +// ******** "rustfmt::skip" and Trait with Attributes ????????? |
| 147 | + #[rustfmt::skip] |
| 148 | + #[allow(non_snake_case)] |
| 149 | + trait Animal1 { |
| 150 | + // Static method signature; `Self` refers to the implementor type. |
| 151 | + fn new(name: &'static str) -> Self; |
| 152 | + |
| 153 | + // Instance method signatures; these will return a string. |
| 154 | + fn name(&self) -> &'static str; |
| 155 | + fn noise(&self) -> &'static str; |
| 156 | + |
| 157 | + // Traits can provide default method definitions. |
| 158 | + fn talk(&self) { |
| 159 | + println!("{} says {}", self.name(), self.noise()); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + trait Animal2 { |
| 164 | + // Static method signature; `Self` refers to the implementor type. |
| 165 | + fn new(name: &'static str) -> Self; |
| 166 | + |
| 167 | + // Instance method signatures; these will return a string. |
| 168 | + fn name(&self) -> &'static str; |
| 169 | + #[rustfmt::skip] |
| 170 | + #[allow(non_snake_case)] |
| 171 | + fn noise(&self) -> &'static str; |
| 172 | + |
| 173 | + fn talk(&self) { |
| 174 | + // Traits can provide default method definitions. |
| 175 | + #[rustfmt::skip] |
| 176 | + #[allow(non_snake_case)] |
| 177 | + fn name(&self) -> &'static str; |
| 178 | + println!("{} says {}", self.name(), self.noise()); |
| 179 | + } |
| 180 | +} |
0 commit comments