mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Never pattern in let
statement diverges
This commit is contained in:
parent
a9ea07d17c
commit
d1f1075931
@ -1471,6 +1471,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// Type check a `let` statement.
|
||||
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
|
||||
self.check_decl(local.into());
|
||||
if local.pat.is_never_pattern() {
|
||||
self.diverges.set(Diverges::Always {
|
||||
span: local.pat.span,
|
||||
custom_note: Some("any code following a never pattern is unreachable"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||
|
@ -17,13 +17,14 @@ fn ref_never_arg(&!: &Void) -> u32 {
|
||||
//~^ ERROR unreachable statement
|
||||
}
|
||||
|
||||
//fn never_let() -> u32 {
|
||||
// let ptr: *const Void = std::ptr::null();
|
||||
// unsafe {
|
||||
// let ! = *ptr;
|
||||
// }
|
||||
// println!();
|
||||
//}
|
||||
fn never_let() -> u32 {
|
||||
let ptr: *const Void = std::ptr::null();
|
||||
unsafe {
|
||||
let ! = *ptr;
|
||||
}
|
||||
println!();
|
||||
//~^ ERROR unreachable statement
|
||||
}
|
||||
|
||||
fn never_match() -> u32 {
|
||||
let ptr: *const Void = std::ptr::null();
|
||||
|
@ -24,7 +24,18 @@ LL | println!();
|
||||
= note: this error originates in the macro `$crate::print` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/diverge-causes-unreachable-code.rs:33:5
|
||||
--> $DIR/diverge-causes-unreachable-code.rs:25:5
|
||||
|
|
||||
LL | let ! = *ptr;
|
||||
| - any code following a never pattern is unreachable
|
||||
LL | }
|
||||
LL | println!();
|
||||
| ^^^^^^^^^^ unreachable statement
|
||||
|
|
||||
= note: this error originates in the macro `$crate::print` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/diverge-causes-unreachable-code.rs:34:5
|
||||
|
|
||||
LL | match *ptr { ! };
|
||||
| ---------------- any code following this `match` expression is unreachable, as all arms diverge
|
||||
@ -34,5 +45,5 @@ LL | println!();
|
||||
|
|
||||
= note: this error originates in the macro `$crate::print` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -13,12 +13,12 @@ fn never_arg(!: Void) -> u32 {}
|
||||
|
||||
fn ref_never_arg(&!: &Void) -> u32 {}
|
||||
|
||||
// fn never_let() -> u32 {
|
||||
// let ptr: *const Void = std::ptr::null();
|
||||
// unsafe {
|
||||
// let ! = *ptr;
|
||||
// }
|
||||
// }
|
||||
fn never_let() -> u32 {
|
||||
let ptr: *const Void = std::ptr::null();
|
||||
unsafe {
|
||||
let ! = *ptr;
|
||||
}
|
||||
}
|
||||
|
||||
fn never_match() -> u32 {
|
||||
let ptr: *const Void = std::ptr::null();
|
||||
|
Loading…
Reference in New Issue
Block a user