Skip to content

Commit 7a43509

Browse files
author
Michael Wright
committed
rustfmt tests/ui/methods.rs
1 parent b96c432 commit 7a43509

File tree

3 files changed

+124
-75
lines changed

3 files changed

+124
-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: 74 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,28 +108,40 @@ 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:
@@ -238,16 +283,18 @@ fn or_fun_call() {
238283
struct Foo;
239284

240285
impl Foo {
241-
fn new() -> Foo { Foo }
286+
fn new() -> Foo {
287+
Foo
288+
}
242289
}
243290

244291
enum Enum {
245292
A(i32),
246293
}
247294

248-
249-
250-
fn make<T>() -> T { unimplemented!(); }
295+
fn make<T>() -> T {
296+
unimplemented!();
297+
}
251298

252299
let with_enum = Some(Enum::A(1));
253300
with_enum.unwrap_or(Enum::A(5));
@@ -264,10 +311,10 @@ fn or_fun_call() {
264311
let with_const_args = Some(vec![1]);
265312
with_const_args.unwrap_or(Vec::with_capacity(12));
266313

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

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

273320
let with_default_trait = Some(1);

0 commit comments

Comments
 (0)