Skip to content

Commit

Permalink
Rename and add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
aDotInTheVoid committed Nov 28, 2023
1 parent 9121a41 commit 0981b7b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions tests/mir-opt/const_prop/overwrite_with_const_with_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// unit-test: ConstProp
// compile-flags: -O
// skip-filecheck

// Regression test for https://github.com/rust-lang/rust/issues/118328

#![allow(unused_assignments)]

struct SizeOfConst<T>(std::marker::PhantomData<T>);
impl<T> SizeOfConst<T> {
const SIZE: usize = std::mem::size_of::<T>();
}

// EMIT_MIR overwrite_with_const_with_params.size_of.ConstProp.diff
fn size_of<T>() -> usize {
// CHECK-LABEL: fn size_of(
// CHECK: _1 = const 0_usize;
// CHECK-NEXT: _1 = const _;
// CHECK-NEXT: _0 = _1;
let mut a = 0;
a = SizeOfConst::<T>::SIZE;
a
}

fn main() {
assert_eq!(size_of::<u32>(), std::mem::size_of::<u32>());
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// unit-test: ConstProp
// compile-flags: -O
// skip-filecheck
// run-pass

// Regression test for https://github.com/rust-lang/rust/issues/118328

#![allow(unused_assignments)]

struct SizeOfConst<T>(std::marker::PhantomData<T>);
impl<T> SizeOfConst<T> {
const SIZE: usize = std::mem::size_of::<T>();
}

// EMIT_MIR issue_118328.size_of.ConstProp.diff
fn size_of<T>() -> usize {
let mut a = 0;
a = SizeOfConst::<T>::SIZE;
Expand Down

0 comments on commit 0981b7b

Please sign in to comment.