Skip to content

Commit

Permalink
Use -> ! to test divergence
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jan 22, 2024
1 parent d1f1075 commit c5a4e07
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ enum Void {}

// A never pattern alone diverges.

fn never_arg(!: Void) -> u32 {}
fn never_arg(!: Void) -> ! {}

fn ref_never_arg(&!: &Void) -> u32 {}
fn never_arg_returns_anything<T>(!: Void) -> T {}

fn never_let() -> u32 {
fn ref_never_arg(&!: &Void) -> ! {}

fn never_let() -> ! {
let ptr: *const Void = std::ptr::null();
unsafe {
let ! = *ptr;
}
}

fn never_match() -> u32 {
fn never_match() -> ! {
let ptr: *const Void = std::ptr::null();
unsafe {
match *ptr { ! };
}
println!(); // Ensures this typechecks because of divergence.
// Ensures this typechecks because of divergence and not the type of the match expression.
println!();
}

0 comments on commit c5a4e07

Please sign in to comment.