&AggregateKind::Array(..) |
&AggregateKind::Tuple |
&AggregateKind::Adt(..) => {}
- &AggregateKind::Closure(def_id, _) |
- &AggregateKind::Generator(def_id, _, _) => {
+ &AggregateKind::Closure(def_id, _) => {
let UnsafetyCheckResult {
violations, unsafe_blocks
} = self.tcx.unsafety_check_result(def_id);
self.register_violations(&violations, &unsafe_blocks);
}
+ &AggregateKind::Generator(def_id, _, interior) => {
+ let UnsafetyCheckResult {
+ violations, unsafe_blocks
+ } = self.tcx.unsafety_check_result(def_id);
+ self.register_violations(&violations, &unsafe_blocks);
+ if !interior.movable {
+ self.require_unsafe("construction of immovable generator")
+ }
+ }
}
}
self.super_rvalue(rvalue, location);
use std::ops::{Generator, GeneratorState};
fn main() {
- let mut generator = static || {
- let a = true;
- let b = &a;
- yield;
- assert_eq!(b as *const _, &a as *const _);
+ let mut generator = unsafe {
+ static || {
+ let a = true;
+ let b = &a;
+ yield;
+ assert_eq!(b as *const _, &a as *const _);
+ }
};
assert_eq!(generator.resume(), GeneratorState::Yielded(()));
assert_eq!(generator.resume(), GeneratorState::Complete(()));
-}
\ No newline at end of file
+}
--- /dev/null
+// 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)]
+
+fn main() {
+ static || { //~ ERROR: construction of immovable generator requires unsafe
+ yield;
+ };
+}
--- /dev/null
+error[E0133]: construction of immovable generator requires unsafe function or block
+ --> $DIR/unsafe-immovable.rs:14:5
+ |
+14 | / static || { //~ ERROR: construction of immovable generator requires unsafe
+15 | | yield;
+16 | | };
+ | |_____^ construction of immovable generator
+
+error: aborting due to previous error
+