forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#22777 - pnkfelix:issue-22443, r=nikomatsakis
Check for unbounded recursion during dropck. Such recursion can be introduced by the erroneous use of non-regular types (aka types employing polymorphic recursion), which Rust does not support. Fix rust-lang#22443
- Loading branch information
Showing
5 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/compile-fail/dropck_no_diverge_on_nonregular_1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue 22443: Reject code using non-regular types that would | ||
// otherwise cause dropck to loop infinitely. | ||
|
||
use std::marker::PhantomData; | ||
|
||
struct Digit<T> { | ||
elem: T | ||
} | ||
|
||
struct Node<T:'static> { m: PhantomData<&'static T> } | ||
|
||
|
||
enum FingerTree<T:'static> { | ||
Single(T), | ||
// Bug report said Digit after Box would stack overflow (versus | ||
// Digit before Box; see dropck_no_diverge_on_nonregular_2). | ||
Deep( | ||
Box<FingerTree<Node<T>>>, | ||
Digit<T>, | ||
) | ||
} | ||
|
||
fn main() { | ||
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree | ||
FingerTree::Single(1); | ||
//~^ ERROR overflow while adding drop-check rules for FingerTree | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/compile-fail/dropck_no_diverge_on_nonregular_2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue 22443: Reject code using non-regular types that would | ||
// otherwise cause dropck to loop infinitely. | ||
|
||
use std::marker::PhantomData; | ||
|
||
struct Digit<T> { | ||
elem: T | ||
} | ||
|
||
struct Node<T:'static> { m: PhantomData<&'static T> } | ||
|
||
enum FingerTree<T:'static> { | ||
Single(T), | ||
// Bug report said Digit before Box would infinite loop (versus | ||
// Digit after Box; see dropck_no_diverge_on_nonregular_1). | ||
Deep( | ||
Digit<T>, | ||
Box<FingerTree<Node<T>>>, | ||
) | ||
} | ||
|
||
fn main() { | ||
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree | ||
FingerTree::Single(1); | ||
//~^ ERROR overflow while adding drop-check rules for FingerTree | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/compile-fail/dropck_no_diverge_on_nonregular_3.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue 22443: Reject code using non-regular types that would | ||
// otherwise cause dropck to loop infinitely. | ||
// | ||
// This version is just checking that we still sanely handle a trivial | ||
// wrapper around the non-regular type. (It also demonstrates how the | ||
// error messages will report different types depending on which type | ||
// dropck is analyzing.) | ||
|
||
use std::marker::PhantomData; | ||
|
||
struct Digit<T> { | ||
elem: T | ||
} | ||
|
||
struct Node<T:'static> { m: PhantomData<&'static T> } | ||
|
||
enum FingerTree<T:'static> { | ||
Single(T), | ||
// According to the bug report, Digit before Box would infinite loop. | ||
Deep( | ||
Digit<T>, | ||
Box<FingerTree<Node<T>>>, | ||
) | ||
} | ||
|
||
enum Wrapper<T:'static> { | ||
Simple, | ||
Other(FingerTree<T>), | ||
} | ||
|
||
fn main() { | ||
let w = //~ ERROR overflow while adding drop-check rules for core::option | ||
Some(Wrapper::Simple::<u32>); | ||
//~^ ERROR overflow while adding drop-check rules for core::option::Option | ||
//~| ERROR overflow while adding drop-check rules for Wrapper | ||
} |