Auto merge of #44700 - arielb1:mir-effectck, r=nikomatsakis

Move effect-checking to MIR

This allows emitting lints from MIR and moves the effect-checking pass to work on it.

I'll make `repr(packed)` misuse unsafe in a separate PR.

r? @eddyb
This commit is contained in:
bors 2017-09-25 00:52:15 +00:00
commit 7a9cdc4c2a
37 changed files with 908 additions and 432 deletions

View file

@ -9,8 +9,8 @@
// except according to those terms.
fn foo(x: *const Box<isize>) -> Box<isize> {
let y = *x; //~ ERROR dereference of raw pointer requires unsafe function or block
unsafe fn foo(x: *const Box<isize>) -> Box<isize> {
let y = *x; //~ ERROR cannot move out of dereference of raw pointer
return y;
}

View file

@ -9,11 +9,13 @@
// except according to those terms.
#![feature(const_fn)]
#![feature(thread_local)]
#![feature(cfg_target_thread_local, thread_local_internals)]
type Foo = std::cell::RefCell<String>;
#[cfg(target_thread_local)]
#[thread_local]
static __KEY: std::thread::__FastLocalKeyInner<Foo> =
std::thread::__FastLocalKeyInner::new();
@ -25,7 +27,7 @@ fn __getit() -> std::option::Option<
&'static std::cell::UnsafeCell<
std::option::Option<Foo>>>
{
__KEY.get() //~ ERROR invocation of unsafe method requires unsafe
__KEY.get() //~ ERROR call to unsafe function requires unsafe
}
static FOO: std::thread::LocalKey<Foo> =

View file

@ -42,8 +42,8 @@ fn main() {
let mut u1 = U1 { a: 10 }; // OK
let a = u1.a; //~ ERROR access to union field requires unsafe
u1.a = 11; // OK
let U1 { a } = u1; //~ ERROR matching on union field requires unsafe
if let U1 { a: 12 } = u1 {} //~ ERROR matching on union field requires unsafe
let U1 { a } = u1; //~ ERROR access to union field requires unsafe
if let U1 { a: 12 } = u1 {} //~ ERROR access to union field requires unsafe
// let U1 { .. } = u1; // OK
let mut u2 = U2 { a: String::from("old") }; // OK

View file

@ -1,3 +1,4 @@
// 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.
@ -9,7 +10,7 @@
// except according to those terms.
fn f(p: *const u8) {
fn f(p: *mut u8) {
*p = 0; //~ ERROR dereference of raw pointer requires unsafe function or block
return;
}

View file

@ -0,0 +1,20 @@
// 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(core_intrinsics)]
use std::intrinsics;
// `move_val_init` has an odd desugaring, check that it is still treated
// as unsafe.
fn main() {
intrinsics::move_val_init(1 as *mut u32, 1);
//~^ ERROR dereference of raw pointer requires unsafe function or block
}