Skip to content

Commit c258e82

Browse files
authored
Rollup merge of #161403 - TimNN:splat-ub, r=fee1-dead
splat-fn-ptr-ptr-tuple.rs: add `let` to avoid UB Fixes #161323. Miri previously reported UB when running this test, and LLVM 24 treated it as UB. r? @teor2345 I'm not sure what _exactly_ is getting tested here, but based on your comment on the issue I assume that moving these to a `let` binding is fine.
2 parents 0ac9bc3 + 9da8a55 commit c258e82

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

tests/ui/splat/splat-fn-ptr-ptr-tuple.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,24 @@ fn main() {
6666
assert_eq!((*fn_pp)(1u32, 2i8), (2i8, 1u32));
6767

6868
// Now with *mut and non-terminal splat
69+
let mut fn_p = splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32);
6970
let fn_pp: *mut fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32)
70-
= ptr::from_mut(
71-
&mut (splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32))
72-
);
71+
= ptr::from_mut(&mut fn_p);
7372
unsafe {
7473
assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1));
7574
assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32));
7675
}
7776

77+
let mut fn_p = splat_non_terminal_arg as _;
7878
let fn_pp: *mut fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32)
79-
= ptr::from_mut(&mut (splat_non_terminal_arg as _));
79+
= ptr::from_mut(&mut fn_p);
8080
unsafe {
8181
assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1));
8282
assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32));
8383
}
8484

85-
let fn_pp = ptr::from_mut(
86-
&mut (splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32))
87-
);
85+
let mut fn_p = splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32);
86+
let fn_pp = ptr::from_mut(&mut fn_p);
8887
unsafe {
8988
assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1));
9089
assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32));

0 commit comments

Comments
 (0)