Adds support for immovable generators. Move checking of invalid borrows across suspension points to borrowck. Fixes #44197, #45259 and #45093.
This commit is contained in:
parent
47a8eb7c4e
commit
ccf0d8399e
60 changed files with 863 additions and 213 deletions
58
src/test/ui/generator/auto-trait-regions.rs
Normal file
58
src/test/ui/generator/auto-trait-regions.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
auto trait Foo {}
|
||||
|
||||
struct No;
|
||||
|
||||
impl !Foo for No {}
|
||||
|
||||
struct A<'a, 'b>(&'a mut bool, &'b mut bool, No);
|
||||
|
||||
impl<'a, 'b: 'a> Foo for A<'a, 'b> {}
|
||||
|
||||
struct OnlyFooIfStaticRef(No);
|
||||
impl Foo for &'static OnlyFooIfStaticRef {}
|
||||
|
||||
struct OnlyFooIfRef(No);
|
||||
impl<'a> Foo for &'a OnlyFooIfRef {}
|
||||
|
||||
fn assert_foo<T: Foo>(f: T) {}
|
||||
|
||||
fn main() {
|
||||
// Make sure 'static is erased for generator interiors so we can't match it in trait selection
|
||||
let x: &'static _ = &OnlyFooIfStaticRef(No);
|
||||
let gen = || {
|
||||
let x = x;
|
||||
yield;
|
||||
assert_foo(x);
|
||||
};
|
||||
assert_foo(gen); //~ ERROR the trait bound `No: Foo` is not satisfied
|
||||
|
||||
// Allow impls which matches any lifetime
|
||||
let x = &OnlyFooIfRef(No);
|
||||
let gen = || {
|
||||
let x = x;
|
||||
yield;
|
||||
assert_foo(x);
|
||||
};
|
||||
assert_foo(gen); // ok
|
||||
|
||||
// Disallow impls which relates lifetimes in the generator interior
|
||||
let gen = || {
|
||||
let a = A(&mut true, &mut true, No);
|
||||
yield;
|
||||
assert_foo(a);
|
||||
};
|
||||
assert_foo(gen); //~ ERROR the requirement `for<'r, 's> 'r : 's` is not satisfied
|
||||
}
|
||||
35
src/test/ui/generator/auto-trait-regions.stderr
Normal file
35
src/test/ui/generator/auto-trait-regions.stderr
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
error[E0277]: the trait bound `No: Foo` is not satisfied in `[generator@$DIR/auto-trait-regions.rs:35:15: 39:6 x:&&'static OnlyFooIfStaticRef for<'r> {&'r OnlyFooIfStaticRef, ()}]`
|
||||
--> $DIR/auto-trait-regions.rs:40:5
|
||||
|
|
||||
40 | assert_foo(gen); //~ ERROR the trait bound `No: Foo` is not satisfied
|
||||
| ^^^^^^^^^^ within `[generator@$DIR/auto-trait-regions.rs:35:15: 39:6 x:&&'static OnlyFooIfStaticRef for<'r> {&'r OnlyFooIfStaticRef, ()}]`, the trait `Foo` is not implemented for `No`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<No as Foo>
|
||||
= note: required because it appears within the type `OnlyFooIfStaticRef`
|
||||
= note: required because it appears within the type `&OnlyFooIfStaticRef`
|
||||
= note: required because it appears within the type `for<'r> {&'r OnlyFooIfStaticRef, ()}`
|
||||
= note: required because it appears within the type `[generator@$DIR/auto-trait-regions.rs:35:15: 39:6 x:&&'static OnlyFooIfStaticRef for<'r> {&'r OnlyFooIfStaticRef, ()}]`
|
||||
note: required by `assert_foo`
|
||||
--> $DIR/auto-trait-regions.rs:30:1
|
||||
|
|
||||
30 | fn assert_foo<T: Foo>(f: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0279]: the requirement `for<'r, 's> 'r : 's` is not satisfied (`expected bound lifetime parameter, found concrete lifetime`)
|
||||
--> $DIR/auto-trait-regions.rs:57:5
|
||||
|
|
||||
57 | assert_foo(gen); //~ ERROR the requirement `for<'r, 's> 'r : 's` is not satisfied
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `for<'r, 's> Foo` for `A<'_, '_>`
|
||||
= note: required because it appears within the type `for<'r, 's> {A<'r, 's>, ()}`
|
||||
= note: required because it appears within the type `[generator@$DIR/auto-trait-regions.rs:52:15: 56:6 for<'r, 's> {A<'r, 's>, ()}]`
|
||||
note: required by `assert_foo`
|
||||
--> $DIR/auto-trait-regions.rs:30:1
|
||||
|
|
||||
30 | fn assert_foo<T: Foo>(f: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -13,15 +13,15 @@ note: required by `main::assert_send`
|
|||
17 | fn assert_send<T: Send>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `std::cell::Cell<i32>: std::marker::Sync` is not satisfied in `[generator@$DIR/not-send-sync.rs:19:17: 23:6 (std::cell::Cell<i32>, ())]`
|
||||
error[E0277]: the trait bound `std::cell::Cell<i32>: std::marker::Sync` is not satisfied in `[generator@$DIR/not-send-sync.rs:19:17: 23:6 {std::cell::Cell<i32>, ()}]`
|
||||
--> $DIR/not-send-sync.rs:19:5
|
||||
|
|
||||
19 | assert_sync(|| {
|
||||
| ^^^^^^^^^^^ `std::cell::Cell<i32>` cannot be shared between threads safely
|
||||
|
|
||||
= help: within `[generator@$DIR/not-send-sync.rs:19:17: 23:6 (std::cell::Cell<i32>, ())]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
|
||||
= note: required because it appears within the type `(std::cell::Cell<i32>, ())`
|
||||
= note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:19:17: 23:6 (std::cell::Cell<i32>, ())]`
|
||||
= help: within `[generator@$DIR/not-send-sync.rs:19:17: 23:6 {std::cell::Cell<i32>, ()}]`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<i32>`
|
||||
= note: required because it appears within the type `{std::cell::Cell<i32>, ()}`
|
||||
= note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:19:17: 23:6 {std::cell::Cell<i32>, ()}]`
|
||||
note: required by `main::assert_sync`
|
||||
--> $DIR/not-send-sync.rs:16:5
|
||||
|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue