diff options
| author | bors <bors@rust-lang.org> | 2017-11-21 22:52:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-21 22:52:19 +0000 |
| commit | d6d09e0b4dac93ae07dae6206bf95e7cea0124a2 (patch) | |
| tree | 245513cfdfc7bac11b0e7049ea60bf9908b01216 /src/test/compile-fail | |
| parent | 63739ab7b210c1a8c890c2ea5238a3284877daa3 (diff) | |
| parent | 00732a31a0a9b00d4ffb333473ae95e66f8e1dfc (diff) | |
| download | rust-d6d09e0b4dac93ae07dae6206bf95e7cea0124a2.tar.gz rust-d6d09e0b4dac93ae07dae6206bf95e7cea0124a2.zip | |
Auto merge of #45879 - nikomatsakis:nll-kill-cyclic-closures, r=arielb1
move closure kind, signature into `ClosureSubsts`
Instead of using side-tables, store the closure-kind and signature in the substitutions themselves. This has two key effects:
- It means that the closure's type changes as inference finds out more things, which is very nice.
- As a result, it avoids the need for the `freshen_closure_like` code (though we still use it for generators).
- It avoids cyclic closures calls.
- These were never meant to be supported, precisely because they make a lot of the fancy inference that we do much more complicated. However, due to an oversight, it was previously possible -- if challenging -- to create a setup where a closure *directly* called itself (see e.g. #21410).
We have to see what the effect of this change is, though. Needs a crater run. Marking as [WIP] until that has been assessed.
r? @arielb1
Diffstat (limited to 'src/test/compile-fail')
| -rw-r--r-- | src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/generator-yielding-or-returning-itself.rs | 45 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-22638.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-25439.rs | 19 | ||||
| -rw-r--r-- | src/test/compile-fail/occurs-check-2.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/occurs-check.rs | 2 |
6 files changed, 66 insertions, 7 deletions
diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 16ed73e9095..513a17e2ef2 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -13,8 +13,7 @@ fn bar<F>(blk: F) where F: FnOnce() + 'static { fn foo(x: &()) { bar(|| { - //~^ ERROR cannot infer - //~| ERROR does not fulfill + //~^ ERROR does not fulfill let _ = x; }) } diff --git a/src/test/compile-fail/generator-yielding-or-returning-itself.rs b/src/test/compile-fail/generator-yielding-or-returning-itself.rs new file mode 100644 index 00000000000..13abdf616b2 --- /dev/null +++ b/src/test/compile-fail/generator-yielding-or-returning-itself.rs @@ -0,0 +1,45 @@ +// 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. + +#![feature(generator_trait)] +#![feature(generators)] + +// Test that we cannot create a generator that returns a value of its +// own type. + +use std::ops::Generator; + +pub fn want_cyclic_generator_return<T>(_: T) + where T: Generator<Yield = (), Return = T> +{ +} + +fn supply_cyclic_generator_return() { + want_cyclic_generator_return(|| { + //~^ ERROR type mismatch + if false { yield None.unwrap(); } + None.unwrap() + }) +} + +pub fn want_cyclic_generator_yield<T>(_: T) + where T: Generator<Yield = T, Return = ()> +{ +} + +fn supply_cyclic_generator_yield() { + want_cyclic_generator_yield(|| { + //~^ ERROR type mismatch + if false { yield None.unwrap(); } + None.unwrap() + }) +} + +fn main() { } diff --git a/src/test/compile-fail/issue-22638.rs b/src/test/compile-fail/issue-22638.rs index 53b0d9f4e9f..1c534ebbd43 100644 --- a/src/test/compile-fail/issue-22638.rs +++ b/src/test/compile-fail/issue-22638.rs @@ -19,7 +19,6 @@ struct A (B); impl A { pub fn matches<F: Fn()>(&self, f: &F) { - //~^ ERROR reached the recursion limit while instantiating `A::matches::<[closure let &A(ref term) = self; term.matches(f); } @@ -59,6 +58,7 @@ struct D (Box<A>); impl D { pub fn matches<F: Fn()>(&self, f: &F) { + //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure let &D(ref a) = self; a.matches(f) } diff --git a/src/test/compile-fail/issue-25439.rs b/src/test/compile-fail/issue-25439.rs new file mode 100644 index 00000000000..6e33fd5ae71 --- /dev/null +++ b/src/test/compile-fail/issue-25439.rs @@ -0,0 +1,19 @@ +// 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. + +struct Helper<'a, F: 'a>(&'a F); + +fn fix<F>(f: F) -> i32 where F: Fn(Helper<F>, i32) -> i32 { + f(Helper(&f), 8) +} + +fn main() { + fix(|_, x| x); //~ ERROR closure/generator type that references itself [E0644] +} diff --git a/src/test/compile-fail/occurs-check-2.rs b/src/test/compile-fail/occurs-check-2.rs index a276af83dee..5d162fe944e 100644 --- a/src/test/compile-fail/occurs-check-2.rs +++ b/src/test/compile-fail/occurs-check-2.rs @@ -16,7 +16,5 @@ fn main() { g = f; f = box g; //~^ ERROR mismatched types - //~| expected type `_` - //~| found type `std::boxed::Box<_>` //~| cyclic type of infinite size } diff --git a/src/test/compile-fail/occurs-check.rs b/src/test/compile-fail/occurs-check.rs index 5b6a11e58c2..2c784365ea9 100644 --- a/src/test/compile-fail/occurs-check.rs +++ b/src/test/compile-fail/occurs-check.rs @@ -14,7 +14,5 @@ fn main() { let f; f = box f; //~^ ERROR mismatched types - //~| expected type `_` - //~| found type `std::boxed::Box<_>` //~| cyclic type of infinite size } |
