1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![allow(clippy::all)]
11 #![warn(clippy::cyclomatic_complexity)]
99 #[clippy::cyclomatic_complexity = "0"]
108 if j == 3 && k == 6 {
124 1 => println!("hai"),
125 2 => println!("hey"),
126 3 => println!("hallo"),
127 4 => println!("hello"),
128 5 => println!("salut"),
129 6 => println!("good morning"),
130 7 => println!("good evening"),
131 8 => println!("good afternoon"),
132 9 => println!("good night"),
133 10 => println!("bonjour"),
134 11 => println!("hej"),
135 12 => println!("hej hej"),
136 13 => println!("greetings earthling"),
137 14 => println!("take us to you leader"),
138 15 | 17 | 19 | 21 | 23 | 25 | 27 | 29 | 31 | 33 => println!("take us to you leader"),
139 35 | 37 | 39 | 41 | 43 | 45 | 47 | 49 | 51 | 53 => println!("there is no undefined behavior"),
140 55 | 57 | 59 | 61 | 63 | 65 | 67 | 69 | 71 | 73 => println!("I know borrow-fu"),
141 _ => println!("bye"),
145 #[clippy::cyclomatic_complexity = "0"]
146 fn lots_of_short_circuits() -> bool {
147 true && false && true && false && true && false && true
150 #[clippy::cyclomatic_complexity = "0"]
151 fn lots_of_short_circuits2() -> bool {
152 true || false || true || false || true || false || true
155 #[clippy::cyclomatic_complexity = "0"]
157 let x = || match 99 {
173 #[clippy::cyclomatic_complexity = "0"]
177 _ => println!("bye"),
182 #[clippy::cyclomatic_complexity = "0"]
183 /// Tests are usually complex but simple at the same time. `clippy::cyclomatic_complexity` used to
184 /// give lots of false-positives in tests.
185 fn dont_warn_on_tests() {
188 _ => println!("bye"),
192 #[clippy::cyclomatic_complexity = "0"]
196 1 => println!("bla"),
197 2 | 3 => println!("blub"),
198 _ => println!("bye"),
202 #[clippy::cyclomatic_complexity = "0"]
206 1 => println!("bla"),
207 2 | 3 => println!("blub"),
208 _ => println!("bye"),
212 1 => println!("bla"),
213 2 | 3 => println!("blub"),
214 _ => println!("bye"),
218 #[clippy::cyclomatic_complexity = "0"]
223 2 | 3 => println!("blub"),
224 _ => println!("bye"),
228 #[clippy::cyclomatic_complexity = "0"]
233 2 | 3 => println!("blub"),
234 _ => println!("bye"),
239 2 | 3 => println!("blub"),
240 _ => println!("bye"),
244 #[clippy::cyclomatic_complexity = "0"]
248 1 => println!("bla"),
249 2 | 3 => panic!("blub"),
250 _ => println!("bye"),
254 #[clippy::cyclomatic_complexity = "0"]
258 1 => println!("bla"),
259 2 | 3 => panic!("blub"),
260 _ => println!("bye"),
264 1 => println!("bla"),
265 2 | 3 => panic!("blub"),
266 _ => println!("bye"),
270 #[clippy::cyclomatic_complexity = "0"]
280 #[clippy::cyclomatic_complexity = "0"]
281 pub fn read_file(input_path: &str) -> String {
283 use std::io::{Read, Write};
285 let mut file = match File::open(&Path::new(input_path)) {
288 panic!("Can't open {}: {}", input_path, err);
292 let mut bytes = Vec::new();
294 match file.read_to_end(&mut bytes) {
297 panic!("Can't read {}", input_path);
301 match String::from_utf8(bytes) {
302 Ok(contents) => contents,
304 panic!("{} is not UTF-8 encoded", input_path);
311 #[clippy::cyclomatic_complexity = "0"]
312 fn void(void: Void) {
318 #[clippy::cyclomatic_complexity = "0"]
319 fn mcarton_sees_all() {
324 #[clippy::cyclomatic_complexity = "0"]
325 fn try() -> Result<i32, &'static str> {
328 _ => return Err("bla"),
332 #[clippy::cyclomatic_complexity = "0"]
333 fn try_again() -> Result<i32, &'static str> {
334 let _ = try!(Ok(42));
335 let _ = try!(Ok(43));
336 let _ = try!(Ok(44));
337 let _ = try!(Ok(45));
338 let _ = try!(Ok(46));
339 let _ = try!(Ok(47));
340 let _ = try!(Ok(48));
341 let _ = try!(Ok(49));
344 _ => return Err("bla"),
348 #[clippy::cyclomatic_complexity = "0"]
349 fn early() -> Result<i32, &'static str> {
362 #[clippy::cyclomatic_complexity = "0"]
363 fn early_ret() -> i32 {
364 let a = if true { 42 } else { return 0; };
365 let a = if a < 99 { 42 } else { return 0; };
366 let a = if a < 99 { 42 } else { return 0; };
367 let a = if a < 99 { 42 } else { return 0; };
368 let a = if a < 99 { 42 } else { return 0; };
369 let a = if a < 99 { 42 } else { return 0; };
370 let a = if a < 99 { 42 } else { return 0; };
371 let a = if a < 99 { 42 } else { return 0; };
372 let a = if a < 99 { 42 } else { return 0; };
373 let a = if a < 99 { 42 } else { return 0; };
374 let a = if a < 99 { 42 } else { return 0; };
375 let a = if a < 99 { 42 } else { return 0; };