fix unsafety checking for generators

Fixes #45729
This commit is contained in:
Ariel Ben-Yehuda 2017-11-05 16:48:22 +02:00
parent 19402f11e1
commit a6b1a81750
2 changed files with 31 additions and 7 deletions

View File

@ -75,7 +75,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
TerminatorKind::Return |
TerminatorKind::Unreachable |
TerminatorKind::FalseEdges { .. } => {
// safe (at least as emitted during MIR construction)
// safe (at least as emitted during MIR construction)
}
TerminatorKind::Call { ref func, .. } => {
@ -117,12 +117,17 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
rvalue: &Rvalue<'tcx>,
location: Location)
{
if let &Rvalue::Aggregate(
box AggregateKind::Closure(def_id, _),
_
) = rvalue {
let unsafety_violations = self.tcx.unsafety_violations(def_id);
self.register_violations(&unsafety_violations);
if let &Rvalue::Aggregate(box ref aggregate, _) = rvalue {
match aggregate {
&AggregateKind::Array(..) |
&AggregateKind::Tuple |
&AggregateKind::Adt(..) => {}
&AggregateKind::Closure(def_id, _) |
&AggregateKind::Generator(def_id, _, _) => {
let unsafety_violations = self.tcx.unsafety_violations(def_id);
self.register_violations(&unsafety_violations);
}
}
}
self.super_rvalue(rvalue, location);
}

View File

@ -0,0 +1,19 @@
// 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() {
let _ = || {
*(1 as *mut u32) = 42;
//~^ ERROR dereference of raw pointer requires unsafe
yield;
};
}