Skip to content

Commit 180ef47

Browse files
committed
Add regression tests for issue 22443.
Fix rust-lang#22443.
1 parent 5ef6182 commit 180ef47

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 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+
// Issue 22443: Reject code using non-regular types that would
12+
// otherwise cause dropck to loop infinitely.
13+
14+
use std::marker::PhantomData;
15+
16+
struct Digit<T> {
17+
elem: T
18+
}
19+
20+
struct Node<T:'static> { m: PhantomData<&'static T> }
21+
22+
23+
enum FingerTree<T:'static> {
24+
Single(T),
25+
// Bug report said Digit after Box would stack overflow (versus
26+
// Digit before Box; see dropck_no_diverge_on_nonregular_2).
27+
Deep(
28+
Box<FingerTree<Node<T>>>,
29+
Digit<T>,
30+
)
31+
}
32+
33+
fn main() {
34+
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree
35+
FingerTree::Single(1);
36+
//~^ ERROR overflow while adding drop-check rules for FingerTree
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 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+
// Issue 22443: Reject code using non-regular types that would
12+
// otherwise cause dropck to loop infinitely.
13+
14+
use std::marker::PhantomData;
15+
16+
struct Digit<T> {
17+
elem: T
18+
}
19+
20+
struct Node<T:'static> { m: PhantomData<&'static T> }
21+
22+
enum FingerTree<T:'static> {
23+
Single(T),
24+
// Bug report said Digit before Box would infinite loop (versus
25+
// Digit after Box; see dropck_no_diverge_on_nonregular_1).
26+
Deep(
27+
Digit<T>,
28+
Box<FingerTree<Node<T>>>,
29+
)
30+
}
31+
32+
fn main() {
33+
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree
34+
FingerTree::Single(1);
35+
//~^ ERROR overflow while adding drop-check rules for FingerTree
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2015 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+
// Issue 22443: Reject code using non-regular types that would
12+
// otherwise cause dropck to loop infinitely.
13+
//
14+
// This version is just checking that we still sanely handle a trivial
15+
// wrapper around the non-regular type. (It also demonstrates how the
16+
// error messages will report different types depending on which type
17+
// dropck is analyzing.)
18+
19+
use std::marker::PhantomData;
20+
21+
struct Digit<T> {
22+
elem: T
23+
}
24+
25+
struct Node<T:'static> { m: PhantomData<&'static T> }
26+
27+
enum FingerTree<T:'static> {
28+
Single(T),
29+
// According to the bug report, Digit before Box would infinite loop.
30+
Deep(
31+
Digit<T>,
32+
Box<FingerTree<Node<T>>>,
33+
)
34+
}
35+
36+
enum Wrapper<T:'static> {
37+
Simple,
38+
Other(FingerTree<T>),
39+
}
40+
41+
fn main() {
42+
let w = //~ ERROR overflow while adding drop-check rules for core::option
43+
Some(Wrapper::Simple::<u32>);
44+
//~^ ERROR overflow while adding drop-check rules for core::option::Option
45+
//~| ERROR overflow while adding drop-check rules for Wrapper
46+
}

src/test/run-pass/issue-22777.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2015 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+
// This test is reduced from libsyntax. It is just checking that we
12+
// can successfully deal with a "deep" structure, which the drop-check
13+
// was hitting a recursion limit on at one point.
14+
15+
#![allow(non_camel_case_types)]
16+
17+
pub fn noop_fold_impl_item() -> SmallVector<ImplItem> {
18+
loop { }
19+
}
20+
21+
pub struct SmallVector<T>(P<T>);
22+
pub struct ImplItem(P<S01_Method>);
23+
24+
struct P<T>(Box<T>);
25+
26+
struct S01_Method(P<S02_Generics>);
27+
struct S02_Generics(P<S03_TyParam>);
28+
struct S03_TyParam(P<S04_TyParamBound>);
29+
struct S04_TyParamBound(S05_PolyTraitRef);
30+
struct S05_PolyTraitRef(S06_TraitRef);
31+
struct S06_TraitRef(S07_Path);
32+
struct S07_Path(Vec<S08_PathSegment>);
33+
struct S08_PathSegment(S09_PathParameters);
34+
struct S09_PathParameters(P<S10_ParenthesizedParameterData>);
35+
struct S10_ParenthesizedParameterData(Option<P<S11_Ty>>);
36+
struct S11_Ty(P<S12_Expr>);
37+
struct S12_Expr(P<S13_Block>);
38+
struct S13_Block(Vec<P<S14_Stmt>>);
39+
struct S14_Stmt(P<S15_Decl>);
40+
struct S15_Decl(P<S16_Local>);
41+
struct S16_Local(P<S17_Pat>);
42+
struct S17_Pat(P<S18_Mac>);
43+
struct S18_Mac(Vec<P<S19_TokenTree>>);
44+
struct S19_TokenTree(P<S20_Token>);
45+
struct S20_Token(P<S21_Nonterminal>);
46+
struct S21_Nonterminal(P<S22_Item>);
47+
struct S22_Item(P<S23_EnumDef>);
48+
struct S23_EnumDef(Vec<P<S24_Variant>>);
49+
struct S24_Variant(P<S25_VariantKind>);
50+
struct S25_VariantKind(P<S26_StructDef>);
51+
struct S26_StructDef(Vec<P<S27_StructField>>);
52+
struct S27_StructField(P<S28_StructFieldKind>);
53+
struct S28_StructFieldKind;
54+
55+
pub fn main() {}

0 commit comments

Comments
 (0)