Skip to content

Commit

Permalink
Auto merge of #60133 - phansch:deny_rust_2018_idioms, r=Centril
Browse files Browse the repository at this point in the history
Deny rust_2018_idioms globally

cc #58099 (comment)
  • Loading branch information
bors committed Apr 22, 2019
2 parents 8f06188 + 8e55559 commit a850a42
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ fn main() {
{
cmd.arg("-Dwarnings");
cmd.arg("-Dbare_trait_objects");
cmd.arg("-Drust_2018_idioms");
}

if verbose > 1 {
Expand Down
24 changes: 12 additions & 12 deletions src/liballoc/tests/cow_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ fn check_cow_add_cow() {
let borrowed2 = Cow::Borrowed("World!");
let borrow_empty = Cow::Borrowed("");

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

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

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

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

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

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

let mut s = borrowed1.clone();
s += borrow_empty.clone();
Expand Down Expand Up @@ -101,8 +101,8 @@ fn check_cow_add_assign_str() {
let mut borrowed = Cow::Borrowed("Hello, ");
let borrow_empty = Cow::Borrowed("");

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

let mut s = borrowed.clone();
s += "";
Expand Down Expand Up @@ -132,10 +132,10 @@ fn check_cow_add_assign_str() {

#[test]
fn check_cow_clone_from() {
let mut c1: Cow<str> = Cow::Owned(String::with_capacity(25));
let mut c1: Cow<'_, str> = Cow::Owned(String::with_capacity(25));
let s: String = "hi".to_string();
assert!(s.capacity() < 25);
let c2: Cow<str> = Cow::Owned(s);
let c2: Cow<'_, str> = Cow::Owned(s);
c1.clone_from(&c2);
assert!(c1.into_owned().capacity() >= 25);
}
1 change: 1 addition & 0 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![feature(try_reserve)]
#![feature(unboxed_closures)]
#![feature(vecdeque_rotate)]
#![deny(rust_2018_idioms)]

use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ fn test_from_utf8() {
#[test]
fn test_from_utf8_lossy() {
let xs = b"hello";
let ys: Cow<str> = "hello".into_cow();
let ys: Cow<'_, str> = "hello".into_cow();
assert_eq!(String::from_utf8_lossy(xs), ys);

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

let xs = b"Hello\xC2 There\xFF Goodbye";
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/tests/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ fn ref_clone_updates_flag() {
fn ref_map_does_not_update_flag() {
let x = RefCell::new(Some(5));
{
let b1: Ref<Option<u32>> = x.borrow();
let b1: Ref<'_, Option<u32>> = x.borrow();
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
{
let b2: Ref<u32> = Ref::map(b1, |o| o.as_ref().unwrap());
let b2: Ref<'_, u32> = Ref::map(b1, |o| o.as_ref().unwrap());
assert_eq!(*b2, 5);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
Expand Down Expand Up @@ -217,26 +217,26 @@ fn ref_mut_map_split() {
fn ref_map_accessor() {
struct X(RefCell<(u32, char)>);
impl X {
fn accessor(&self) -> Ref<u32> {
fn accessor(&self) -> Ref<'_, u32> {
Ref::map(self.0.borrow(), |tuple| &tuple.0)
}
}
let x = X(RefCell::new((7, 'z')));
let d: Ref<u32> = x.accessor();
let d: Ref<'_, u32> = x.accessor();
assert_eq!(*d, 7);
}

#[test]
fn ref_mut_map_accessor() {
struct X(RefCell<(u32, char)>);
impl X {
fn accessor(&self) -> RefMut<u32> {
fn accessor(&self) -> RefMut<'_, u32> {
RefMut::map(self.0.borrow_mut(), |tuple| &mut tuple.0)
}
}
let x = X(RefCell::new((7, 'z')));
{
let mut d: RefMut<u32> = x.accessor();
let mut d: RefMut<'_ ,u32> = x.accessor();
assert_eq!(*d, 7);
*d += 1;
}
Expand Down Expand Up @@ -333,16 +333,16 @@ fn refcell_unsized() {
fn refcell_ref_coercion() {
let cell: RefCell<[i32; 3]> = RefCell::new([1, 2, 3]);
{
let mut cellref: RefMut<[i32; 3]> = cell.borrow_mut();
let mut cellref: RefMut<'_, [i32; 3]> = cell.borrow_mut();
cellref[0] = 4;
let mut coerced: RefMut<[i32]> = cellref;
let mut coerced: RefMut<'_, [i32]> = cellref;
coerced[2] = 5;
}
{
let comp: &mut [i32] = &mut [4, 2, 5];
let cellref: Ref<[i32; 3]> = cell.borrow();
let cellref: Ref<'_, [i32; 3]> = cell.borrow();
assert_eq!(&*cellref, comp);
let coerced: Ref<[i32]> = cellref;
let coerced: Ref<'_, [i32]> = cellref;
assert_eq!(&*coerced, comp);
}
}
Expand Down
50 changes: 25 additions & 25 deletions src/libcore/tests/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod debug_struct {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Foo").finish()
}
}
Expand All @@ -20,7 +20,7 @@ mod debug_struct {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Foo")
.field("bar", &true)
.finish()
Expand All @@ -40,7 +40,7 @@ mod debug_struct {
struct Foo;

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

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

impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Bar")
.field("foo", &Foo)
.field("hello", &"world")
Expand Down Expand Up @@ -103,7 +103,7 @@ mod debug_tuple {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("Foo").finish()
}
}
Expand All @@ -117,7 +117,7 @@ mod debug_tuple {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("Foo")
.field(&true)
.finish()
Expand All @@ -137,7 +137,7 @@ mod debug_tuple {
struct Foo;

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

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

impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("Bar")
.field(&Foo)
.field(&"world")
Expand Down Expand Up @@ -200,7 +200,7 @@ mod debug_map {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map().finish()
}
}
Expand All @@ -214,7 +214,7 @@ mod debug_map {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map()
.entry(&"bar", &true)
.finish()
Expand All @@ -234,7 +234,7 @@ mod debug_map {
struct Foo;

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

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

impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map()
.entry(&"foo", &Foo)
.entry(&Foo, &"world")
Expand Down Expand Up @@ -301,7 +301,7 @@ mod debug_set {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set().finish()
}
}
Expand All @@ -315,7 +315,7 @@ mod debug_set {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set()
.entry(&true)
.finish()
Expand All @@ -335,7 +335,7 @@ mod debug_set {
struct Foo;

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

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

impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set()
.entry(&Foo)
.entry(&"world")
Expand Down Expand Up @@ -398,7 +398,7 @@ mod debug_list {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list().finish()
}
}
Expand All @@ -412,7 +412,7 @@ mod debug_list {
struct Foo;

impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list()
.entry(&true)
.finish()
Expand All @@ -432,7 +432,7 @@ mod debug_list {
struct Foo;

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

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

impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list()
.entry(&Foo)
.entry(&"world")
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ fn test_iterator_peekable_fold() {
/// This is an iterator that follows the Iterator contract,
/// but it is not fused. After having returned None once, it will start
/// producing elements if .next() is called again.
pub struct CycleIter<'a, T: 'a> {
pub struct CycleIter<'a, T> {
index: usize,
data: &'a [T],
}

pub fn cycle<T>(data: &[T]) -> CycleIter<T> {
pub fn cycle<T>(data: &[T]) -> CycleIter<'_, T> {
CycleIter {
index: 0,
data,
Expand Down
Loading

0 comments on commit a850a42

Please # to comment.