diff options
| author | David Wood <david@davidtw.co> | 2018-08-08 14:50:16 +0200 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-08-14 11:12:09 +0200 |
| commit | 3fc7ab237314a4ce85e612b4ce590c27f1425291 (patch) | |
| tree | c775f852e05e1272032cb053ee347315c973c7b5 /src/test/ui/recursion | |
| parent | 3e0a4079884eab5b54489c92f7428cda2797ea5c (diff) | |
Merged migrated compile-fail tests and ui tests. Fixes #46841.
Diffstat (limited to 'src/test/ui/recursion')
| -rw-r--r-- | src/test/ui/recursion/auxiliary/recursive_reexports.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursion.rs | 32 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursion.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-enum.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-enum.stderr | 13 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-reexports.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-reexports.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-requirements.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-requirements.stderr | 15 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-static-definition.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-static-definition.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-types-are-not-uninhabited.rs | 24 | ||||
| -rw-r--r-- | src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr | 9 |
13 files changed, 212 insertions, 0 deletions
diff --git a/src/test/ui/recursion/auxiliary/recursive_reexports.rs b/src/test/ui/recursion/auxiliary/recursive_reexports.rs new file mode 100644 index 00000000000..1186e3d62f7 --- /dev/null +++ b/src/test/ui/recursion/auxiliary/recursive_reexports.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +pub mod foo { + pub use foo; +} diff --git a/src/test/ui/recursion/recursion.rs b/src/test/ui/recursion/recursion.rs new file mode 100644 index 00000000000..3221ae46296 --- /dev/null +++ b/src/test/ui/recursion/recursion.rs @@ -0,0 +1,32 @@ +// Copyright 2012-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. + +enum Nil {NilValue} +struct Cons<T> {head:isize, tail:T} +trait Dot {fn dot(&self, other:Self) -> isize;} +impl Dot for Nil { + fn dot(&self, _:Nil) -> isize {0} +} +impl<T:Dot> Dot for Cons<T> { + fn dot(&self, other:Cons<T>) -> isize { + self.head * other.head + self.tail.dot(other.tail) + } +} +fn test<T:Dot> (n:isize, i:isize, first:T, second:T) ->isize { //~ ERROR recursion limit + match n { 0 => {first.dot(second)} + // FIXME(#4287) Error message should be here. It should be + // a type error to instantiate `test` at a type other than T. + _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} + } +} +pub fn main() { + let n = test(1, 0, Nil::NilValue, Nil::NilValue); + println!("{}", n); +} diff --git a/src/test/ui/recursion/recursion.stderr b/src/test/ui/recursion/recursion.stderr new file mode 100644 index 00000000000..5953e5c4087 --- /dev/null +++ b/src/test/ui/recursion/recursion.stderr @@ -0,0 +1,14 @@ +error: reached the recursion limit while instantiating `test::<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Cons<Nil>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + --> $DIR/recursion.rs:22:1 + | +LL | / fn test<T:Dot> (n:isize, i:isize, first:T, second:T) ->isize { //~ ERROR recursion limit +LL | | match n { 0 => {first.dot(second)} +LL | | // FIXME(#4287) Error message should be here. It should be +LL | | // a type error to instantiate `test` at a type other than T. +LL | | _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} +LL | | } +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/recursion/recursive-enum.rs b/src/test/ui/recursion/recursive-enum.rs new file mode 100644 index 00000000000..555755cdb96 --- /dev/null +++ b/src/test/ui/recursion/recursive-enum.rs @@ -0,0 +1,14 @@ +// Copyright 2012 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. + +enum list<T> { cons(T, list<T>), nil } +//~^ ERROR recursive type `list` has infinite size + +fn main() {} diff --git a/src/test/ui/recursion/recursive-enum.stderr b/src/test/ui/recursion/recursive-enum.stderr new file mode 100644 index 00000000000..c06058b2b59 --- /dev/null +++ b/src/test/ui/recursion/recursive-enum.stderr @@ -0,0 +1,13 @@ +error[E0072]: recursive type `list` has infinite size + --> $DIR/recursive-enum.rs:11:1 + | +LL | enum list<T> { cons(T, list<T>), nil } + | ^^^^^^^^^^^^ ------- recursive without indirection + | | + | recursive type has infinite size + | + = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `list` representable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/ui/recursion/recursive-reexports.rs b/src/test/ui/recursion/recursive-reexports.rs new file mode 100644 index 00000000000..b57b73325c0 --- /dev/null +++ b/src/test/ui/recursion/recursive-reexports.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// aux-build:recursive_reexports.rs + +extern crate recursive_reexports; + +fn f() -> recursive_reexports::S {} //~ ERROR cannot find type `S` in module `recursive_reexports` + +fn main() {} diff --git a/src/test/ui/recursion/recursive-reexports.stderr b/src/test/ui/recursion/recursive-reexports.stderr new file mode 100644 index 00000000000..e6b8647a981 --- /dev/null +++ b/src/test/ui/recursion/recursive-reexports.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `S` in module `recursive_reexports` + --> $DIR/recursive-reexports.rs:15:32 + | +LL | fn f() -> recursive_reexports::S {} //~ ERROR cannot find type `S` in module `recursive_reexports` + | ^ not found in `recursive_reexports` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/src/test/ui/recursion/recursive-requirements.rs b/src/test/ui/recursion/recursive-requirements.rs new file mode 100644 index 00000000000..2c0f0338b2d --- /dev/null +++ b/src/test/ui/recursion/recursive-requirements.rs @@ -0,0 +1,27 @@ +// 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 <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. + +use std::marker::PhantomData; + +struct AssertSync<T: Sync>(PhantomData<T>); + +pub struct Foo { + bar: *const Bar, + phantom: PhantomData<Bar>, +} + +pub struct Bar { + foo: *const Foo, + phantom: PhantomData<Foo>, +} + +fn main() { + let _: AssertSync<Foo> = unimplemented!(); //~ ERROR E0275 +} diff --git a/src/test/ui/recursion/recursive-requirements.stderr b/src/test/ui/recursion/recursive-requirements.stderr new file mode 100644 index 00000000000..d9e08102ab6 --- /dev/null +++ b/src/test/ui/recursion/recursive-requirements.stderr @@ -0,0 +1,15 @@ +error[E0275]: overflow evaluating the requirement `Foo: std::marker::Sync` + --> $DIR/recursive-requirements.rs:26:12 + | +LL | let _: AssertSync<Foo> = unimplemented!(); //~ ERROR E0275 + | ^^^^^^^^^^^^^^^ + | + = help: consider adding a `#![recursion_limit="128"]` attribute to your crate + = note: required because it appears within the type `std::marker::PhantomData<Foo>` + = note: required because it appears within the type `Bar` + = note: required because it appears within the type `std::marker::PhantomData<Bar>` + = note: required because it appears within the type `Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/src/test/ui/recursion/recursive-static-definition.rs b/src/test/ui/recursion/recursive-static-definition.rs new file mode 100644 index 00000000000..62c1859e09d --- /dev/null +++ b/src/test/ui/recursion/recursive-static-definition.rs @@ -0,0 +1,14 @@ +// 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 <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. + +pub static FOO: u32 = FOO; +//~^ ERROR cycle detected when const-evaluating `FOO` + +fn main() {} diff --git a/src/test/ui/recursion/recursive-static-definition.stderr b/src/test/ui/recursion/recursive-static-definition.stderr new file mode 100644 index 00000000000..2ab93bfd685 --- /dev/null +++ b/src/test/ui/recursion/recursive-static-definition.stderr @@ -0,0 +1,11 @@ +error[E0391]: cycle detected when const-evaluating `FOO` + --> $DIR/recursive-static-definition.rs:11:23 + | +LL | pub static FOO: u32 = FOO; + | ^^^ + | + = note: ...which again requires const-evaluating `FOO`, completing the cycle + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/recursion/recursive-types-are-not-uninhabited.rs b/src/test/ui/recursion/recursive-types-are-not-uninhabited.rs new file mode 100644 index 00000000000..fa936697072 --- /dev/null +++ b/src/test/ui/recursion/recursive-types-are-not-uninhabited.rs @@ -0,0 +1,24 @@ +// Copyright 2014 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. + +struct R<'a> { + r: &'a R<'a>, +} + +fn foo(res: Result<u32, &R>) -> u32 { + let Ok(x) = res; + //~^ ERROR refutable pattern + x +} + +fn main() { + foo(Ok(23)); +} + diff --git a/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr new file mode 100644 index 00000000000..c4d40412760 --- /dev/null +++ b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr @@ -0,0 +1,9 @@ +error[E0005]: refutable pattern in local binding: `Err(_)` not covered + --> $DIR/recursive-types-are-not-uninhabited.rs:16:9 + | +LL | let Ok(x) = res; + | ^^^^^ pattern `Err(_)` not covered + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0005`. |
