File: casts.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (25 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//@ unit-test: InstSimplify
//@ compile-flags: -Zinline-mir
#![crate_type = "lib"]

#[inline(always)]
fn generic_cast<T, U>(x: *const T) -> *const U {
    x as *const U
}

// EMIT_MIR casts.redundant.InstSimplify.diff
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
    // CHECK-LABEL: fn redundant(
    // CHECK: inlined generic_cast
    // CHECK-NOT: as
    generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
}

// EMIT_MIR casts.roundtrip.InstSimplify.diff
pub fn roundtrip(x: *const u8) -> *const u8 {
    // CHECK-LABEL: fn roundtrip(
    // CHECK: _4 = _1;
    // CHECK: _3 = move _4 as *mut u8 (PtrToPtr);
    // CHECK: _2 = move _3 as *const u8 (PointerCoercion(MutToConstPointer));
    x as *mut u8 as *const u8
}