]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/rc-loop.rs
Rollup merge of #105216 - GuillaumeGomez:rm-unused-gui-test, r=notriddle
[rust.git] / src / test / ui / nll / rc-loop.rs
1 // run-pass
2
3 // A test for something that NLL enables. It sometimes happens that
4 // the `while let` pattern makes some borrows from a variable (in this
5 // case, `x`) that you need in order to compute the next value for
6 // `x`.  The lexical checker makes this very painful. The NLL checker
7 // does not.
8
9 use std::rc::Rc;
10
11 #[derive(Debug, PartialEq, Eq)]
12 enum Foo {
13     Base(usize),
14     Next(Rc<Foo>),
15 }
16
17 fn find_base(mut x: Rc<Foo>) -> Rc<Foo> {
18     while let Foo::Next(n) = &*x {
19         x = n.clone();
20     }
21     x
22 }
23
24 fn main() {
25     let chain = Rc::new(Foo::Next(Rc::new(Foo::Base(44))));
26     let base = find_base(chain);
27     assert_eq!(&*base, &Foo::Base(44));
28 }