]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/methods.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / methods.rs
index f7a4b39c7a6f205c090aa0882e64ea21a427fe08..b470a12f7a399a16a22c26c43c6bd7d4fd9d86d9 100644 (file)
@@ -1,9 +1,26 @@
-
-#![feature(const_fn)]
-
-#![warn(clippy, clippy_pedantic)]
-#![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default,
-    new_without_default_derive, missing_docs_in_private_items, needless_pass_by_value)]
+// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![warn(clippy::all, clippy::pedantic, clippy::option_unwrap_used)]
+#![allow(
+    clippy::blacklisted_name,
+    unused,
+    clippy::print_stdout,
+    clippy::non_ascii_literal,
+    clippy::new_without_default,
+    clippy::missing_docs_in_private_items,
+    clippy::needless_pass_by_value,
+    clippy::default_trait_access,
+    clippy::use_self,
+    clippy::new_ret_no_self,
+    clippy::useless_format
+)]
 
 use std::collections::BTreeMap;
 use std::collections::HashMap;
@@ -32,7 +49,7 @@ fn into_u16(&self) -> u16 { 0 }
 
     fn to_something(self) -> u32 { 0 }
 
-    fn new(self) {}
+    fn new(self) -> Self { unimplemented!(); }
 }
 
 struct Lt<'a> {
@@ -41,7 +58,7 @@ struct Lt<'a> {
 
 impl<'a> Lt<'a> {
     // The lifetime is different, but that’s irrelevant, see #734
-    #[allow(needless_lifetimes)]
+    #[allow(clippy::needless_lifetimes)]
     pub fn new<'b>(s: &'b str) -> Lt<'b> { unimplemented!() }
 }
 
@@ -293,15 +310,15 @@ enum Enum {
         A(i32),
     }
 
-    const fn make_const(i: i32) -> i32 { i }
+
 
     fn make<T>() -> T { unimplemented!(); }
 
     let with_enum = Some(Enum::A(1));
     with_enum.unwrap_or(Enum::A(5));
 
-    let with_const_fn = Some(1);
-    with_const_fn.unwrap_or(make_const(5));
+    let with_const_fn = Some(::std::time::Duration::from_secs(1));
+    with_const_fn.unwrap_or(::std::time::Duration::from_secs(5));
 
     let with_constructor = Some(vec![1]);
     with_constructor.unwrap_or(make());
@@ -373,55 +390,7 @@ fn iter_nth() {
     let ok_mut = false_positive.iter_mut().nth(3);
 }
 
-/// Checks implementation of `ITER_SKIP_NEXT` lint
-fn iter_skip_next() {
-    let mut some_vec = vec![0, 1, 2, 3];
-    let _ = some_vec.iter().skip(42).next();
-    let _ = some_vec.iter().cycle().skip(42).next();
-    let _ = (1..10).skip(10).next();
-    let _ = &some_vec[..].iter().skip(3).next();
-    let foo = IteratorFalsePositives { foo : 0 };
-    let _ = foo.skip(42).next();
-    let _ = foo.filter().skip(42).next();
-}
-
-/// Calls which should trigger the `UNNECESSARY_FOLD` lint
-fn unnecessary_fold() {
-    // Can be replaced by .any
-    let _ = (0..3).fold(false, |acc, x| acc || x > 2);
-    // Can be replaced by .all
-    let _ = (0..3).fold(true, |acc, x| acc && x > 2);
-    // Can be replaced by .sum
-    let _ = (0..3).fold(0, |acc, x| acc + x);
-    // Can be replaced by .product
-    let _ = (0..3).fold(1, |acc, x| acc * x);
-}
-
-/// Should trigger the `UNNECESSARY_FOLD` lint, with an error span including exactly `.fold(...)`
-fn unnecessary_fold_span_for_multi_element_chain() {
-    let _ = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
-}
-
-/// Calls which should not trigger the `UNNECESSARY_FOLD` lint
-fn unnecessary_fold_should_ignore() {
-    let _ = (0..3).fold(true, |acc, x| acc || x > 2);
-    let _ = (0..3).fold(false, |acc, x| acc && x > 2);
-    let _ = (0..3).fold(1, |acc, x| acc + x);
-    let _ = (0..3).fold(0, |acc, x| acc * x);
-    let _ = (0..3).fold(0, |acc, x| 1 + acc + x);
-
-    // We only match against an accumulator on the left
-    // hand side. We could lint for .sum and .product when
-    // it's on the right, but don't for now (and this wouldn't
-    // be valid if we extended the lint to cover arbitrary numeric
-    // types).
-    let _ = (0..3).fold(false, |acc, x| x > 2 || acc);
-    let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
-    let _ = (0..3).fold(0, |acc, x| x + acc);
-    let _ = (0..3).fold(1, |acc, x| x * acc);
-}
-
-#[allow(similar_names)]
+#[allow(clippy::similar_names)]
 fn main() {
     let opt = Some(0);
     let _ = opt.unwrap();