Skip to content

Commit 469d6a8

Browse files
committed
Test for (previously uncaught) infinite loop identified by matthewjasper.
1 parent 08b3a8e commit 469d6a8

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2018 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.
4+
//
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.
10+
11+
// rust-lang/rust#45696: This test checks the compiler won't infinite
12+
// loop when you declare a variable of type `struct A(Box<A>, ...);`
13+
// (which is impossible to construct but *is* possible to declare; see
14+
// also issues #4287, #44933, and #52852).
15+
//
16+
// We will explicitly test AST-borrowck, NLL, and migration modes;
17+
// thus we will also skip the automated compare-mode=nll.
18+
19+
// revisions: ast nll migrate
20+
// ignore-compare-mode-nll
21+
22+
#![cfg_attr(nll, feature(nll))]
23+
//[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
24+
25+
// run-pass
26+
27+
// This test has structs and functions that are by definiton unusable
28+
// all over the place, so just go ahead and allow dead_code
29+
#![allow(dead_code)]
30+
31+
// direct regular recursion with indirect ownership via box
32+
struct C { field: Box<C> }
33+
34+
// direct non-regular recursion with indirect ownership via box
35+
struct D { field: Box<(D, D)> }
36+
37+
// indirect regular recursion with indirect ownership via box.
38+
struct E { field: F }
39+
struct F { field: Box<E> }
40+
41+
// indirect non-regular recursion with indirect ownership via box.
42+
struct G { field: (F, F) }
43+
struct H { field: Box<E> }
44+
45+
// These enums are cases that are not currently hit by the
46+
// `visit_terminator_drop` recursion down a type's structural
47+
// definition.
48+
//
49+
// But it seems prudent to include them in this test as variants on
50+
// the above, in that they are similarly non-constructable data types
51+
// with destructors that would diverge.
52+
enum I { One(Box<I>) }
53+
enum J { One(Box<J>), Two(Box<J>) }
54+
55+
fn impossible_to_call_c(_c: C) { }
56+
fn impossible_to_call_d(_d: D) { }
57+
fn impossible_to_call_e(_e: E) { }
58+
fn impossible_to_call_f(_f: F) { }
59+
fn impossible_to_call_g(_g: G) { }
60+
fn impossible_to_call_h(_h: H) { }
61+
fn impossible_to_call_i(_i: I) { }
62+
fn impossible_to_call_j(_j: J) { }
63+
64+
fn main() {
65+
66+
}

0 commit comments

Comments
 (0)