-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #47291 - varkor:unreachable-never-patterns, r=<try>
Eager unreachable blocks for `!` type This change optimises the generation of MIR in the presence of `!`. Blocks are now immediately marked as unreachable if: - A function argument is derived from the value of type `!`. - A match arm binds a value whose type is derived from `!`. - An rvalue is created whose type is derived from `!`. This avoids unnecessary MIR generation and also fixes #43061 and #41446. r? @nikomatsakis
- Loading branch information
Showing
8 changed files
with
197 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// 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(never_type)] | ||
#![allow(dead_code)] | ||
#![allow(path_statements)] | ||
#![allow(unreachable_patterns)] | ||
|
||
fn never_direct(x: !) { | ||
x; | ||
} | ||
|
||
fn never_ref_pat(ref x: !) { | ||
*x; | ||
} | ||
|
||
fn never_ref(x: &!) { | ||
let &y = x; | ||
y; | ||
} | ||
|
||
fn never_slice(x: &[!]) { | ||
x[0]; | ||
} | ||
|
||
fn never_match(x: Result<(), !>) { | ||
match x { | ||
Ok(_) => {}, | ||
Err(_) => {}, | ||
} | ||
} | ||
|
||
fn never_match_disj_patterns() { | ||
let x: Option<!> = None; | ||
match x { | ||
Some(_) | None => {} | ||
} | ||
} | ||
|
||
pub fn main() { } | ||
|
||
// END RUST SOURCE | ||
|
||
// START rustc.never_direct.SimplifyCfg-initial.after.mir | ||
// bb0: { | ||
// unreachable; | ||
// } | ||
// END rustc.never_direct.SimplifyCfg-initial.after.mir | ||
|
||
// START rustc.never_ref_pat.SimplifyCfg-initial.after.mir | ||
// bb0: { | ||
// unreachable; | ||
// } | ||
// END rustc.never_ref_pat.SimplifyCfg-initial.after.mir | ||
|
||
// START rustc.never_ref.SimplifyCfg-initial.after.mir | ||
// bb0: { | ||
// ... | ||
// unreachable; | ||
// } | ||
// END rustc.never_ref.SimplifyCfg-initial.after.mir | ||
|
||
// START rustc.never_slice.SimplifyCfg-initial.after.mir | ||
// bb1: { | ||
// ... | ||
// unreachable; | ||
// } | ||
// END rustc.never_slice.SimplifyCfg-initial.after.mir | ||
|
||
// START rustc.never_match.SimplifyCfg-initial.after.mir | ||
// fn never_match(_1: std::result::Result<(), !>) -> () { | ||
// ... | ||
// bb0: { | ||
// ... | ||
// } | ||
// bb1: { | ||
// _0 = (); | ||
// return; | ||
// } | ||
// bb2: { | ||
// ... | ||
// } | ||
// bb3: { | ||
// unreachable; | ||
// } | ||
// bb4: { | ||
// unreachable; | ||
// } | ||
// } | ||
// END rustc.never_match.SimplifyCfg-initial.after.mir | ||
|
||
// START rustc.never_match_disj_patterns.SimplifyCfg-initial.after.mir | ||
// fn never_match_disj_patterns() -> () { | ||
// ... | ||
// bb0: { | ||
// ... | ||
// } | ||
// bb1: { | ||
// _0 = (); | ||
// StorageDead(_1); | ||
// return; | ||
// } | ||
// bb2: { | ||
// ... | ||
// } | ||
// bb3: { | ||
// unreachable; | ||
// } | ||
// bb4: { | ||
// unreachable; | ||
// } | ||
// } | ||
// END rustc.never_match_disj_patterns.SimplifyCfg-initial.after.mir |