Skip to content

Commit ed18e6b

Browse files
committed
Add regression test for issue 22443.
Fix #22443.
1 parent c3b8125 commit ed18e6b

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-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+
}

0 commit comments

Comments
 (0)