2 #![warn(clippy::let_and_return)]
5 let _y = 0; // no warning
10 fn test_inner() -> i32 {
19 fn test_nowarn_1() -> i32 {
25 fn test_nowarn_2() -> i32 {
30 fn test_nowarn_3() -> (i32, i32) {
31 // this should technically warn, but we do not compare complex patterns
36 fn test_nowarn_4() -> i32 {
37 // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type
42 fn test_nowarn_5(x: i16) -> u16 {
43 #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
48 // False positive example
50 fn decode<D: std::io::Read>(d: D) -> Result<Self, ()>
55 macro_rules! tuple_encode {
57 impl<$($x: Decode),*> Decode for ($($x),*) {
59 #[allow(non_snake_case)]
60 fn decode<D: std::io::Read>(mut d: D) -> Result<Self, ()> {
61 // Shouldn't trigger lint
62 Ok(($({let $x = Decode::decode(&mut d)?; $x }),*))
68 tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
70 mod no_lint_if_stmt_borrows {
72 use std::io::{self, BufRead, Stdin};
74 fn read_line() -> String {
75 let stdin = io::stdin();
76 let line = stdin.lock().lines().next().unwrap().unwrap();
82 use std::cell::RefCell;
83 use std::rc::{Rc, Weak};
85 fn test(value: Weak<RefCell<Bar>>) -> u32 {
86 let value = value.upgrade().unwrap();
87 let ret = value.borrow().baz();
97 fn baz(&self) -> u32 {
103 let a = Rc::new(RefCell::new(Bar::new()));
104 let b = Rc::downgrade(&a);
116 impl Drop for Foo<'_> {
117 fn drop(&mut self) {}
121 fn new(inner: &'a Inner) -> Self {
125 fn value(&self) -> i32 {
130 fn some_foo(inner: &Inner) -> Foo<'_> {
136 let value = some_foo(&x).value();
142 let value = Foo::new(&x).value();
154 fn foo_cloned(&self) -> Arc<dyn Foo>;
157 struct FooStorageImpl<T: Foo> {
161 impl<T: Foo + 'static> FooStorage for FooStorageImpl<T> {
162 fn foo_cloned(&self) -> Arc<dyn Foo> {
163 let clone = Arc::clone(&self.foo);