Skip to content

Commit a850a42

Browse files
committed
Auto merge of #60133 - phansch:deny_rust_2018_idioms, r=Centril
Deny rust_2018_idioms globally cc #58099 (comment)
2 parents 8f06188 + 8e55559 commit a850a42

File tree

10 files changed

+56
-52
lines changed

10 files changed

+56
-52
lines changed

src/bootstrap/bin/rustc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ fn main() {
308308
{
309309
cmd.arg("-Dwarnings");
310310
cmd.arg("-Dbare_trait_objects");
311+
cmd.arg("-Drust_2018_idioms");
311312
}
312313

313314
if verbose > 1 {

src/liballoc/tests/cow_str.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ fn check_cow_add_cow() {
77
let borrowed2 = Cow::Borrowed("World!");
88
let borrow_empty = Cow::Borrowed("");
99

10-
let owned1: Cow<str> = Cow::Owned(String::from("Hi, "));
11-
let owned2: Cow<str> = Cow::Owned(String::from("Rustaceans!"));
12-
let owned_empty: Cow<str> = Cow::Owned(String::new());
10+
let owned1: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
11+
let owned2: Cow<'_, str> = Cow::Owned(String::from("Rustaceans!"));
12+
let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
1313

1414
assert_eq!("Hello, World!", borrowed1.clone() + borrowed2.clone());
1515
assert_eq!("Hello, Rustaceans!", borrowed1.clone() + owned2.clone());
@@ -36,8 +36,8 @@ fn check_cow_add_str() {
3636
let borrowed = Cow::Borrowed("Hello, ");
3737
let borrow_empty = Cow::Borrowed("");
3838

39-
let owned: Cow<str> = Cow::Owned(String::from("Hi, "));
40-
let owned_empty: Cow<str> = Cow::Owned(String::new());
39+
let owned: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
40+
let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
4141

4242
assert_eq!("Hello, World!", borrowed.clone() + "World!");
4343

@@ -60,9 +60,9 @@ fn check_cow_add_assign_cow() {
6060
let borrowed2 = Cow::Borrowed("World!");
6161
let borrow_empty = Cow::Borrowed("");
6262

63-
let mut owned1: Cow<str> = Cow::Owned(String::from("Hi, "));
64-
let owned2: Cow<str> = Cow::Owned(String::from("Rustaceans!"));
65-
let owned_empty: Cow<str> = Cow::Owned(String::new());
63+
let mut owned1: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
64+
let owned2: Cow<'_, str> = Cow::Owned(String::from("Rustaceans!"));
65+
let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
6666

6767
let mut s = borrowed1.clone();
6868
s += borrow_empty.clone();
@@ -101,8 +101,8 @@ fn check_cow_add_assign_str() {
101101
let mut borrowed = Cow::Borrowed("Hello, ");
102102
let borrow_empty = Cow::Borrowed("");
103103

104-
let mut owned: Cow<str> = Cow::Owned(String::from("Hi, "));
105-
let owned_empty: Cow<str> = Cow::Owned(String::new());
104+
let mut owned: Cow<'_, str> = Cow::Owned(String::from("Hi, "));
105+
let owned_empty: Cow<'_, str> = Cow::Owned(String::new());
106106

107107
let mut s = borrowed.clone();
108108
s += "";
@@ -132,10 +132,10 @@ fn check_cow_add_assign_str() {
132132

133133
#[test]
134134
fn check_cow_clone_from() {
135-
let mut c1: Cow<str> = Cow::Owned(String::with_capacity(25));
135+
let mut c1: Cow<'_, str> = Cow::Owned(String::with_capacity(25));
136136
let s: String = "hi".to_string();
137137
assert!(s.capacity() < 25);
138-
let c2: Cow<str> = Cow::Owned(s);
138+
let c2: Cow<'_, str> = Cow::Owned(s);
139139
c1.clone_from(&c2);
140140
assert!(c1.into_owned().capacity() >= 25);
141141
}

src/liballoc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(try_reserve)]
88
#![feature(unboxed_closures)]
99
#![feature(vecdeque_rotate)]
10+
#![deny(rust_2018_idioms)]
1011

1112
use std::hash::{Hash, Hasher};
1213
use std::collections::hash_map::DefaultHasher;

src/liballoc/tests/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ fn test_from_utf8() {
5454
#[test]
5555
fn test_from_utf8_lossy() {
5656
let xs = b"hello";
57-
let ys: Cow<str> = "hello".into_cow();
57+
let ys: Cow<'_, str> = "hello".into_cow();
5858
assert_eq!(String::from_utf8_lossy(xs), ys);
5959

6060
let xs = "ศไทย中华Việt Nam".as_bytes();
61-
let ys: Cow<str> = "ศไทย中华Việt Nam".into_cow();
61+
let ys: Cow<'_, str> = "ศไทย中华Việt Nam".into_cow();
6262
assert_eq!(String::from_utf8_lossy(xs), ys);
6363

6464
let xs = b"Hello\xC2 There\xFF Goodbye";

src/libcore/tests/cell.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ fn ref_clone_updates_flag() {
139139
fn ref_map_does_not_update_flag() {
140140
let x = RefCell::new(Some(5));
141141
{
142-
let b1: Ref<Option<u32>> = x.borrow();
142+
let b1: Ref<'_, Option<u32>> = x.borrow();
143143
assert!(x.try_borrow().is_ok());
144144
assert!(x.try_borrow_mut().is_err());
145145
{
146-
let b2: Ref<u32> = Ref::map(b1, |o| o.as_ref().unwrap());
146+
let b2: Ref<'_, u32> = Ref::map(b1, |o| o.as_ref().unwrap());
147147
assert_eq!(*b2, 5);
148148
assert!(x.try_borrow().is_ok());
149149
assert!(x.try_borrow_mut().is_err());
@@ -217,26 +217,26 @@ fn ref_mut_map_split() {
217217
fn ref_map_accessor() {
218218
struct X(RefCell<(u32, char)>);
219219
impl X {
220-
fn accessor(&self) -> Ref<u32> {
220+
fn accessor(&self) -> Ref<'_, u32> {
221221
Ref::map(self.0.borrow(), |tuple| &tuple.0)
222222
}
223223
}
224224
let x = X(RefCell::new((7, 'z')));
225-
let d: Ref<u32> = x.accessor();
225+
let d: Ref<'_, u32> = x.accessor();
226226
assert_eq!(*d, 7);
227227
}
228228

229229
#[test]
230230
fn ref_mut_map_accessor() {
231231
struct X(RefCell<(u32, char)>);
232232
impl X {
233-
fn accessor(&self) -> RefMut<u32> {
233+
fn accessor(&self) -> RefMut<'_, u32> {
234234
RefMut::map(self.0.borrow_mut(), |tuple| &mut tuple.0)
235235
}
236236
}
237237
let x = X(RefCell::new((7, 'z')));
238238
{
239-
let mut d: RefMut<u32> = x.accessor();
239+
let mut d: RefMut<'_ ,u32> = x.accessor();
240240
assert_eq!(*d, 7);
241241
*d += 1;
242242
}
@@ -333,16 +333,16 @@ fn refcell_unsized() {
333333
fn refcell_ref_coercion() {
334334
let cell: RefCell<[i32; 3]> = RefCell::new([1, 2, 3]);
335335
{
336-
let mut cellref: RefMut<[i32; 3]> = cell.borrow_mut();
336+
let mut cellref: RefMut<'_, [i32; 3]> = cell.borrow_mut();
337337
cellref[0] = 4;
338-
let mut coerced: RefMut<[i32]> = cellref;
338+
let mut coerced: RefMut<'_, [i32]> = cellref;
339339
coerced[2] = 5;
340340
}
341341
{
342342
let comp: &mut [i32] = &mut [4, 2, 5];
343-
let cellref: Ref<[i32; 3]> = cell.borrow();
343+
let cellref: Ref<'_, [i32; 3]> = cell.borrow();
344344
assert_eq!(&*cellref, comp);
345-
let coerced: Ref<[i32]> = cellref;
345+
let coerced: Ref<'_, [i32]> = cellref;
346346
assert_eq!(&*coerced, comp);
347347
}
348348
}

src/libcore/tests/fmt/builders.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod debug_struct {
66
struct Foo;
77

88
impl fmt::Debug for Foo {
9-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
9+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1010
fmt.debug_struct("Foo").finish()
1111
}
1212
}
@@ -20,7 +20,7 @@ mod debug_struct {
2020
struct Foo;
2121

2222
impl fmt::Debug for Foo {
23-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
23+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2424
fmt.debug_struct("Foo")
2525
.field("bar", &true)
2626
.finish()
@@ -40,7 +40,7 @@ mod debug_struct {
4040
struct Foo;
4141

4242
impl fmt::Debug for Foo {
43-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
43+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4444
fmt.debug_struct("Foo")
4545
.field("bar", &true)
4646
.field("baz", &format_args!("{}/{}", 10, 20))
@@ -62,7 +62,7 @@ mod debug_struct {
6262
struct Foo;
6363

6464
impl fmt::Debug for Foo {
65-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
65+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6666
fmt.debug_struct("Foo")
6767
.field("bar", &true)
6868
.field("baz", &format_args!("{}/{}", 10, 20))
@@ -73,7 +73,7 @@ mod debug_struct {
7373
struct Bar;
7474

7575
impl fmt::Debug for Bar {
76-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
76+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
7777
fmt.debug_struct("Bar")
7878
.field("foo", &Foo)
7979
.field("hello", &"world")
@@ -103,7 +103,7 @@ mod debug_tuple {
103103
struct Foo;
104104

105105
impl fmt::Debug for Foo {
106-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
106+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
107107
fmt.debug_tuple("Foo").finish()
108108
}
109109
}
@@ -117,7 +117,7 @@ mod debug_tuple {
117117
struct Foo;
118118

119119
impl fmt::Debug for Foo {
120-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
120+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
121121
fmt.debug_tuple("Foo")
122122
.field(&true)
123123
.finish()
@@ -137,7 +137,7 @@ mod debug_tuple {
137137
struct Foo;
138138

139139
impl fmt::Debug for Foo {
140-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
140+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
141141
fmt.debug_tuple("Foo")
142142
.field(&true)
143143
.field(&format_args!("{}/{}", 10, 20))
@@ -159,7 +159,7 @@ mod debug_tuple {
159159
struct Foo;
160160

161161
impl fmt::Debug for Foo {
162-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
162+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
163163
fmt.debug_tuple("Foo")
164164
.field(&true)
165165
.field(&format_args!("{}/{}", 10, 20))
@@ -170,7 +170,7 @@ mod debug_tuple {
170170
struct Bar;
171171

172172
impl fmt::Debug for Bar {
173-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
173+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
174174
fmt.debug_tuple("Bar")
175175
.field(&Foo)
176176
.field(&"world")
@@ -200,7 +200,7 @@ mod debug_map {
200200
struct Foo;
201201

202202
impl fmt::Debug for Foo {
203-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
203+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
204204
fmt.debug_map().finish()
205205
}
206206
}
@@ -214,7 +214,7 @@ mod debug_map {
214214
struct Foo;
215215

216216
impl fmt::Debug for Foo {
217-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
217+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
218218
fmt.debug_map()
219219
.entry(&"bar", &true)
220220
.finish()
@@ -234,7 +234,7 @@ mod debug_map {
234234
struct Foo;
235235

236236
impl fmt::Debug for Foo {
237-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
237+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
238238
fmt.debug_map()
239239
.entry(&"bar", &true)
240240
.entry(&10, &format_args!("{}/{}", 10, 20))
@@ -256,7 +256,7 @@ mod debug_map {
256256
struct Foo;
257257

258258
impl fmt::Debug for Foo {
259-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
259+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
260260
fmt.debug_map()
261261
.entry(&"bar", &true)
262262
.entry(&10, &format_args!("{}/{}", 10, 20))
@@ -267,7 +267,7 @@ mod debug_map {
267267
struct Bar;
268268

269269
impl fmt::Debug for Bar {
270-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
270+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
271271
fmt.debug_map()
272272
.entry(&"foo", &Foo)
273273
.entry(&Foo, &"world")
@@ -301,7 +301,7 @@ mod debug_set {
301301
struct Foo;
302302

303303
impl fmt::Debug for Foo {
304-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
304+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
305305
fmt.debug_set().finish()
306306
}
307307
}
@@ -315,7 +315,7 @@ mod debug_set {
315315
struct Foo;
316316

317317
impl fmt::Debug for Foo {
318-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
318+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
319319
fmt.debug_set()
320320
.entry(&true)
321321
.finish()
@@ -335,7 +335,7 @@ mod debug_set {
335335
struct Foo;
336336

337337
impl fmt::Debug for Foo {
338-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
338+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
339339
fmt.debug_set()
340340
.entry(&true)
341341
.entry(&format_args!("{}/{}", 10, 20))
@@ -357,7 +357,7 @@ mod debug_set {
357357
struct Foo;
358358

359359
impl fmt::Debug for Foo {
360-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
360+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
361361
fmt.debug_set()
362362
.entry(&true)
363363
.entry(&format_args!("{}/{}", 10, 20))
@@ -368,7 +368,7 @@ mod debug_set {
368368
struct Bar;
369369

370370
impl fmt::Debug for Bar {
371-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
371+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
372372
fmt.debug_set()
373373
.entry(&Foo)
374374
.entry(&"world")
@@ -398,7 +398,7 @@ mod debug_list {
398398
struct Foo;
399399

400400
impl fmt::Debug for Foo {
401-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
401+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
402402
fmt.debug_list().finish()
403403
}
404404
}
@@ -412,7 +412,7 @@ mod debug_list {
412412
struct Foo;
413413

414414
impl fmt::Debug for Foo {
415-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
415+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
416416
fmt.debug_list()
417417
.entry(&true)
418418
.finish()
@@ -432,7 +432,7 @@ mod debug_list {
432432
struct Foo;
433433

434434
impl fmt::Debug for Foo {
435-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
435+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
436436
fmt.debug_list()
437437
.entry(&true)
438438
.entry(&format_args!("{}/{}", 10, 20))
@@ -454,7 +454,7 @@ mod debug_list {
454454
struct Foo;
455455

456456
impl fmt::Debug for Foo {
457-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
457+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
458458
fmt.debug_list()
459459
.entry(&true)
460460
.entry(&format_args!("{}/{}", 10, 20))
@@ -465,7 +465,7 @@ mod debug_list {
465465
struct Bar;
466466

467467
impl fmt::Debug for Bar {
468-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
468+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
469469
fmt.debug_list()
470470
.entry(&Foo)
471471
.entry(&"world")

src/libcore/tests/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,12 @@ fn test_iterator_peekable_fold() {
567567
/// This is an iterator that follows the Iterator contract,
568568
/// but it is not fused. After having returned None once, it will start
569569
/// producing elements if .next() is called again.
570-
pub struct CycleIter<'a, T: 'a> {
570+
pub struct CycleIter<'a, T> {
571571
index: usize,
572572
data: &'a [T],
573573
}
574574

575-
pub fn cycle<T>(data: &[T]) -> CycleIter<T> {
575+
pub fn cycle<T>(data: &[T]) -> CycleIter<'_, T> {
576576
CycleIter {
577577
index: 0,
578578
data,

0 commit comments

Comments
 (0)