Skip to content

Commit 36e92a5

Browse files
committed
Auto merge of #3795 - mikerite:test-rustfmt, r=phansch
Allow rustfmt to run on more tests
2 parents a5c16e5 + 7a43509 commit 36e92a5

File tree

3 files changed

+127
-75
lines changed

3 files changed

+127
-75
lines changed

ci/base-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
for file in `find tests -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
6363
rustfmt ${file} --check
6464
if [ $? -ne 0 ]; then
6565
echo "${file} needs reformatting!"

tests/ui/methods.rs

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use std::collections::BTreeMap;
2222
use std::collections::HashMap;
2323
use std::collections::HashSet;
2424
use std::collections::VecDeque;
25-
use std::ops::Mul;
2625
use std::iter::FromIterator;
26+
use std::ops::Mul;
2727
use std::rc::{self, Rc};
2828
use std::sync::{self, Arc};
2929

@@ -32,22 +32,51 @@ use option_helpers::IteratorFalsePositives;
3232
pub struct T;
3333

3434
impl T {
35-
pub fn add(self, other: T) -> T { self }
35+
pub fn add(self, other: T) -> T {
36+
self
37+
}
38+
39+
// no error, not public interface
40+
pub(crate) fn drop(&mut self) {}
3641

37-
pub(crate) fn drop(&mut self) { } // no error, not public interfact
38-
fn neg(self) -> Self { self } // no error, private function
39-
fn eq(&self, other: T) -> bool { true } // no error, private function
42+
// no error, private function
43+
fn neg(self) -> Self {
44+
self
45+
}
46+
47+
// no error, private function
48+
fn eq(&self, other: T) -> bool {
49+
true
50+
}
4051

41-
fn sub(&self, other: T) -> &T { self } // no error, self is a ref
42-
fn div(self) -> T { self } // no error, different #arguments
43-
fn rem(self, other: T) { } // no error, wrong return type
52+
// no error, self is a ref
53+
fn sub(&self, other: T) -> &T {
54+
self
55+
}
56+
57+
// no error, different #arguments
58+
fn div(self) -> T {
59+
self
60+
}
61+
62+
fn rem(self, other: T) {} // no error, wrong return type
63+
64+
// fine
65+
fn into_u32(self) -> u32 {
66+
0
67+
}
4468

45-
fn into_u32(self) -> u32 { 0 } // fine
46-
fn into_u16(&self) -> u16 { 0 }
69+
fn into_u16(&self) -> u16 {
70+
0
71+
}
4772

48-
fn to_something(self) -> u32 { 0 }
73+
fn to_something(self) -> u32 {
74+
0
75+
}
4976

50-
fn new(self) -> Self { unimplemented!(); }
77+
fn new(self) -> Self {
78+
unimplemented!();
79+
}
5180
}
5281

5382
struct Lt<'a> {
@@ -57,7 +86,9 @@ struct Lt<'a> {
5786
impl<'a> Lt<'a> {
5887
// The lifetime is different, but that’s irrelevant, see #734
5988
#[allow(clippy::needless_lifetimes)]
60-
pub fn new<'b>(s: &'b str) -> Lt<'b> { unimplemented!() }
89+
pub fn new<'b>(s: &'b str) -> Lt<'b> {
90+
unimplemented!()
91+
}
6192
}
6293

6394
struct Lt2<'a> {
@@ -66,7 +97,9 @@ struct Lt2<'a> {
6697

6798
impl<'a> Lt2<'a> {
6899
// The lifetime is different, but that’s irrelevant, see #734
69-
pub fn new(s: &str) -> Lt2 { unimplemented!() }
100+
pub fn new(s: &str) -> Lt2 {
101+
unimplemented!()
102+
}
70103
}
71104

72105
struct Lt3<'a> {
@@ -75,34 +108,47 @@ struct Lt3<'a> {
75108

76109
impl<'a> Lt3<'a> {
77110
// The lifetime is different, but that’s irrelevant, see #734
78-
pub fn new() -> Lt3<'static> { unimplemented!() }
111+
pub fn new() -> Lt3<'static> {
112+
unimplemented!()
113+
}
79114
}
80115

81-
#[derive(Clone,Copy)]
116+
#[derive(Clone, Copy)]
82117
struct U;
83118

84119
impl U {
85-
fn new() -> Self { U }
86-
fn to_something(self) -> u32 { 0 } // ok because U is Copy
120+
fn new() -> Self {
121+
U
122+
}
123+
// ok because U is Copy
124+
fn to_something(self) -> u32 {
125+
0
126+
}
87127
}
88128

89129
struct V<T> {
90-
_dummy: T
130+
_dummy: T,
91131
}
92132

93133
impl<T> V<T> {
94-
fn new() -> Option<V<T>> { None }
134+
fn new() -> Option<V<T>> {
135+
None
136+
}
95137
}
96138

97139
impl Mul<T> for T {
98140
type Output = T;
99-
fn mul(self, other: T) -> T { self } // no error, obviously
141+
// no error, obviously
142+
fn mul(self, other: T) -> T {
143+
self
144+
}
100145
}
101146

102147
/// Checks implementation of the following lints:
103148
/// * `OPTION_MAP_UNWRAP_OR`
104149
/// * `OPTION_MAP_UNWRAP_OR_ELSE`
105150
/// * `OPTION_MAP_OR_NONE`
151+
#[rustfmt::skip]
106152
fn option_methods() {
107153
let opt = Some(1);
108154

@@ -175,6 +221,7 @@ impl HasIter {
175221
}
176222

177223
/// Checks implementation of `FILTER_NEXT` lint
224+
#[rustfmt::skip]
178225
fn filter_next() {
179226
let v = vec![3, 2, 1, 0, -1, -2, -3];
180227

@@ -193,6 +240,7 @@ fn filter_next() {
193240
}
194241

195242
/// Checks implementation of `SEARCH_IS_SOME` lint
243+
#[rustfmt::skip]
196244
fn search_is_some() {
197245
let v = vec![3, 2, 1, 0, -1, -2, -3];
198246

@@ -235,16 +283,18 @@ fn or_fun_call() {
235283
struct Foo;
236284

237285
impl Foo {
238-
fn new() -> Foo { Foo }
286+
fn new() -> Foo {
287+
Foo
288+
}
239289
}
240290

241291
enum Enum {
242292
A(i32),
243293
}
244294

245-
246-
247-
fn make<T>() -> T { unimplemented!(); }
295+
fn make<T>() -> T {
296+
unimplemented!();
297+
}
248298

249299
let with_enum = Some(Enum::A(1));
250300
with_enum.unwrap_or(Enum::A(5));
@@ -261,10 +311,10 @@ fn or_fun_call() {
261311
let with_const_args = Some(vec![1]);
262312
with_const_args.unwrap_or(Vec::with_capacity(12));
263313

264-
let with_err : Result<_, ()> = Ok(vec![1]);
314+
let with_err: Result<_, ()> = Ok(vec![1]);
265315
with_err.unwrap_or(make());
266316

267-
let with_err_args : Result<_, ()> = Ok(vec![1]);
317+
let with_err_args: Result<_, ()> = Ok(vec![1]);
268318
with_err_args.unwrap_or(Vec::with_capacity(12));
269319

270320
let with_default_trait = Some(1);

0 commit comments

Comments
 (0)