From 469d6a819d3d7348fdd54d8c7ec1e694f2f43051 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 30 Jul 2018 15:38:18 +0200 Subject: [PATCH] Test for (previously uncaught) infinite loop identified by matthewjasper. --- .../ui/issue-45696-no-variant-box-recur.rs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/test/ui/issue-45696-no-variant-box-recur.rs diff --git a/src/test/ui/issue-45696-no-variant-box-recur.rs b/src/test/ui/issue-45696-no-variant-box-recur.rs new file mode 100644 index 0000000000000..740e99c82a556 --- /dev/null +++ b/src/test/ui/issue-45696-no-variant-box-recur.rs @@ -0,0 +1,66 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// rust-lang/rust#45696: This test checks the compiler won't infinite +// loop when you declare a variable of type `struct A(Box, ...);` +// (which is impossible to construct but *is* possible to declare; see +// also issues #4287, #44933, and #52852). +// +// We will explicitly test AST-borrowck, NLL, and migration modes; +// thus we will also skip the automated compare-mode=nll. + +// revisions: ast nll migrate +// ignore-compare-mode-nll + +#![cfg_attr(nll, feature(nll))] +//[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// run-pass + +// This test has structs and functions that are by definiton unusable +// all over the place, so just go ahead and allow dead_code +#![allow(dead_code)] + +// direct regular recursion with indirect ownership via box +struct C { field: Box } + +// direct non-regular recursion with indirect ownership via box +struct D { field: Box<(D, D)> } + +// indirect regular recursion with indirect ownership via box. +struct E { field: F } +struct F { field: Box } + +// indirect non-regular recursion with indirect ownership via box. +struct G { field: (F, F) } +struct H { field: Box } + +// These enums are cases that are not currently hit by the +// `visit_terminator_drop` recursion down a type's structural +// definition. +// +// But it seems prudent to include them in this test as variants on +// the above, in that they are similarly non-constructable data types +// with destructors that would diverge. +enum I { One(Box) } +enum J { One(Box), Two(Box) } + +fn impossible_to_call_c(_c: C) { } +fn impossible_to_call_d(_d: D) { } +fn impossible_to_call_e(_e: E) { } +fn impossible_to_call_f(_f: F) { } +fn impossible_to_call_g(_g: G) { } +fn impossible_to_call_h(_h: H) { } +fn impossible_to_call_i(_i: I) { } +fn impossible_to_call_j(_j: J) { } + +fn main() { + +}