diff options
| author | Eduardo Broto <ebroto@tutanota.com> | 2020-06-07 00:30:39 +0200 |
|---|---|---|
| committer | Eduardo Broto <ebroto@tutanota.com> | 2020-06-07 20:53:38 +0200 |
| commit | dac8a3c1ca19d2b5934ecbe2ed79ae6c156fd885 (patch) | |
| tree | 26697ecac71b095e186ce0b6b6590ee525bc015e /tests | |
| parent | 9c205d7b1baa982ae7063d57b18088ecf28df83b (diff) | |
let_and_return: do not lint if last statement borrows
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/let_and_return.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 23645d48fe7..09614b8c1ad 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -67,4 +67,72 @@ macro_rules! tuple_encode { tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); +mod no_lint_if_stmt_borrows { + mod issue_3792 { + use std::io::{self, BufRead, Stdin}; + + fn read_line() -> String { + let stdin = io::stdin(); + let line = stdin.lock().lines().next().unwrap().unwrap(); + line + } + } + + mod issue_3324 { + use std::cell::RefCell; + use std::rc::{Rc, Weak}; + + fn test(value: Weak<RefCell<Bar>>) -> u32 { + let value = value.upgrade().unwrap(); + let ret = value.borrow().baz(); + ret + } + + struct Bar {} + + impl Bar { + fn new() -> Self { + Bar {} + } + fn baz(&self) -> u32 { + 0 + } + } + + fn main() { + let a = Rc::new(RefCell::new(Bar::new())); + let b = Rc::downgrade(&a); + test(b); + } + } + + mod free_function { + struct Inner; + + struct Foo<'a> { + inner: &'a Inner, + } + + impl Drop for Foo<'_> { + fn drop(&mut self) {} + } + + impl Foo<'_> { + fn value(&self) -> i32 { + 42 + } + } + + fn some_foo(inner: &Inner) -> Foo<'_> { + Foo { inner } + } + + fn test() -> i32 { + let x = Inner {}; + let value = some_foo(&x).value(); + value + } + } +} + fn main() {} |
