Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,36 @@ mod tests {
};
assert_eq!(x, 3);
}

#[test]
fn magic_deref() {
fn f(y: &'static str) -> (&'static str, bool) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified:

#[test]
fn magic_deref() {
    struct Wrapped<T>(T);
    let s = "hello";
    if_chain! {
        then { Wrapped(s) }
        else { Wrapped(&s) }
    };
}

let b: [&str; 1] = ["a"];
if_chain! {
if false;
if let Some(x) = b.get(1);
then { (x, true) }
else { (y, false) }
}
}
f("foo");
}

#[test]
fn no_move() {
struct NoCopy;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as well:

#[test]
fn no_move() {
    struct NoCopy;
    let x = NoCopy;
    if_chain! {
        then { drop(x); }
        else { drop(x); }
    }
}

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);
}
}