]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/nll/rc-loop.rs
2b746fac4d42610121168999c01e38a199b5f3e1
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // A test for something that NLL enables. It sometimes happens that
12 // the `while let` pattern makes some borrows from a variable (in this
13 // case, `x`) that you need in order to compute the next value for
14 // `x`. The lexical checker makes this very painful. The NLL checker
17 #![feature(match_default_bindings)]
22 #[derive(Debug, PartialEq, Eq)]
28 fn find_base(mut x
: Rc
<Foo
>) -> Rc
<Foo
> {
29 while let Foo
::Next(n
) = &*x
{
36 let chain
= Rc
::new(Foo
::Next(Rc
::new(Foo
::Base(44))));
37 let base
= find_base(chain
);
38 assert_eq
!(&*base
, &Foo
::Base(44));