rust/tests/ui/reachable/expr_assign.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
605 B
Rust
Raw Normal View History

#![feature(never_type)]
#![allow(unused_variables)]
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
fn foo() {
// No error here.
let x;
2017-11-20 12:13:27 +00:00
x = return; //~ ERROR unreachable
}
fn bar() {
use std::ptr;
let p: *mut ! = ptr::null_mut::<!>();
unsafe {
// Here we consider the `return` unreachable because
// "evaluating" the `*p` has type `!`. This is somewhat
// dubious, I suppose.
2017-11-20 12:13:27 +00:00
*p = return; //~ ERROR unreachable
}
}
fn baz() {
let mut i = 0;
2017-11-20 12:13:27 +00:00
*{return; &mut i} = 22; //~ ERROR unreachable
}
fn main() { }