]> 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 111c6ce5a8c579e6a664be46a60bcf5b964faee1..b470a12f7a399a16a22c26c43c6bd7d4fd9d86d9 100644 (file)
@@ -1,10 +1,26 @@
-#![feature(tool_lints)]
-
+// 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::new_without_default_derive, clippy::missing_docs_in_private_items, clippy::needless_pass_by_value,
-    clippy::default_trait_access, clippy::use_self)]
+#![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;
@@ -33,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> {
@@ -343,58 +359,6 @@ enum Enum {
     let _ = stringy.unwrap_or("".to_owned());
 }
 
-/// Checks implementation of the `EXPECT_FUN_CALL` lint
-fn expect_fun_call() {
-    struct Foo;
-
-    impl Foo {
-        fn new() -> Self { Foo }
-
-        fn expect(&self, msg: &str) {
-            panic!("{}", msg)
-        }
-    }
-
-    let with_some = Some("value");
-    with_some.expect("error");
-
-    let with_none: Option<i32> = None;
-    with_none.expect("error");
-
-    let error_code = 123_i32;
-    let with_none_and_format: Option<i32> = None;
-    with_none_and_format.expect(&format!("Error {}: fake error", error_code));
-
-    let with_none_and_as_str: Option<i32> = None;
-    with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
-
-    let with_ok: Result<(), ()> = Ok(());
-    with_ok.expect("error");
-
-    let with_err: Result<(), ()> = Err(());
-    with_err.expect("error");
-
-    let error_code = 123_i32;
-    let with_err_and_format: Result<(), ()> = Err(());
-    with_err_and_format.expect(&format!("Error {}: fake error", error_code));
-
-    let with_err_and_as_str: Result<(), ()> = Err(());
-    with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
-
-    let with_dummy_type = Foo::new();
-    with_dummy_type.expect("another test string");
-
-    let with_dummy_type_and_format = Foo::new();
-    with_dummy_type_and_format.expect(&format!("Error {}: fake error", error_code));
-
-    let with_dummy_type_and_as_str = Foo::new();
-    with_dummy_type_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
-
-    //Issue #2979 - this should not lint
-    let msg = "bar";
-    Some("foo").expect(msg);
-}
-
 /// Checks implementation of `ITER_NTH` lint
 fn iter_nth() {
     let mut some_vec = vec![0, 1, 2, 3];
@@ -426,34 +390,8 @@ 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();
-}
-
 #[allow(clippy::similar_names)]
 fn main() {
     let opt = Some(0);
     let _ = opt.unwrap();
 }
-
-/// Checks implementation of `UNNECESSARY_FILTER_MAP` lint
-fn unnecessary_filter_map() {
-    let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None });
-    let _ = (0..4).filter_map(|x| { if x > 1 { return Some(x); }; None });
-    let _ = (0..4).filter_map(|x| match x {
-        0 | 1 => None,
-        _ => Some(x),
-    });
-
-    let _ = (0..4).filter_map(|x| Some(x + 1));
-
-    let _ = (0..4).filter_map(i32::checked_abs);
-}