]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/closure-referencing-itself-issue-25954.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / closures / closure-referencing-itself-issue-25954.rs
1 // Regression test for #25954: detect and reject a closure type that
2 // references itself.
3
4 use std::cell::{Cell, RefCell};
5
6 struct A<T: Fn()> {
7     x: RefCell<Option<T>>,
8     b: Cell<i32>,
9 }
10
11 fn main() {
12     let mut p = A{x: RefCell::new(None), b: Cell::new(4i32)};
13
14     // This is an error about types of infinite size:
15     let q = || p.b.set(5i32); //~ ERROR mismatched types
16
17     *(p.x.borrow_mut()) = Some(q);
18 }