From 72219483b5fe6bff23760a778b9f1cfbb1de4aad Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 23 Mar 2021 19:05:58 +0000 Subject: [PATCH 1/2] test case for autoderef Signed-off-by: Ian Jackson --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 39177fa..9f11f59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -311,4 +311,18 @@ mod tests { }; assert_eq!(x, 3); } + + #[test] + fn magic_deref() { + fn f(y: &'static str) -> (&'static str, bool) { + let b: [&str; 1] = ["a"]; + if_chain! { + if false; + if let Some(x) = b.get(1); + then { (x, true) } + else { (y, false) } + } + } + f("foo"); + } } From 1b72eac63f5b18ef006a37031e200de8863f362d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 23 Mar 2021 19:32:57 +0000 Subject: [PATCH 2/2] test case for no Copy then/else Signed-off-by: Ian Jackson --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9f11f59..05816ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -325,4 +325,22 @@ mod tests { } f("foo"); } + + #[test] + fn no_move() { + struct NoCopy; + let new_record = NoCopy; + let mut store = None; + let returned = if_chain!{ + if true; + then { + store = Some(new_record); + None + } else { + Some(new_record) + } + }; + drop(returned); + drop(store); + } }