Skip to content

Commit 0367b5c

Browse files
authored
Rollup merge of #107972 - saethlin:fix-test-ub, r=michaelwoerister
Fix unintentional UB in ui tests ``@matthiaskrgr`` found UB in a bunch of the ui tests. This PR fixes a batch of miscellaneous tests I didn't think needed reviewers from a particular part of the project.
2 parents 2d7e59b + 5925400 commit 0367b5c

File tree

8 files changed

+15
-12
lines changed

8 files changed

+15
-12
lines changed

tests/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn test_send_trait() {
2626
//~| HELP: add a dummy let to cause `fptr` to be fully captured
2727
*fptr.0 = 20;
2828
//~^ NOTE: in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0`
29-
} });
29+
} }).join().unwrap();
3030
}
3131

3232
/* Test Sync Trait Migration */
@@ -47,7 +47,7 @@ fn test_sync_trait() {
4747
//~| HELP: add a dummy let to cause `fptr` to be fully captured
4848
*fptr.0.0 = 20;
4949
//~^ NOTE: in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0.0`
50-
} });
50+
} }).join().unwrap();
5151
}
5252

5353
/* Test Clone Trait Migration */

tests/ui/closures/2229_closure_analysis/migrations/auto_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn test_send_trait() {
2626
//~| HELP: add a dummy let to cause `fptr` to be fully captured
2727
*fptr.0 = 20;
2828
//~^ NOTE: in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0`
29-
});
29+
}).join().unwrap();
3030
}
3131

3232
/* Test Sync Trait Migration */
@@ -47,7 +47,7 @@ fn test_sync_trait() {
4747
//~| HELP: add a dummy let to cause `fptr` to be fully captured
4848
*fptr.0.0 = 20;
4949
//~^ NOTE: in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0.0`
50-
});
50+
}).join().unwrap();
5151
}
5252

5353
/* Test Clone Trait Migration */

tests/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL ~ thread::spawn(move || { let _ = &fptr; unsafe {
1919
LL |
2020
...
2121
LL |
22-
LL ~ } });
22+
LL ~ } }).join().unwrap();
2323
|
2424

2525
error: changes to closure capture in Rust 2021 will affect which traits the closure implements
@@ -41,7 +41,7 @@ LL ~ thread::spawn(move || { let _ = &fptr; unsafe {
4141
LL |
4242
...
4343
LL |
44-
LL ~ } });
44+
LL ~ } }).join().unwrap();
4545
|
4646

4747
error: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements

tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn test_multi_traits_issues() {
145145
//~^ NOTE: in Rust 2018, this closure captures all of `fptr1`, but in Rust 2021, it will only capture `fptr1.0.0`
146146
*fptr2.0 = 20;
147147
//~^ NOTE: in Rust 2018, this closure captures all of `fptr2`, but in Rust 2021, it will only capture `fptr2.0`
148-
} });
148+
} }).join().unwrap();
149149
}
150150

151151
fn main() {

tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn test_multi_traits_issues() {
141141
//~^ NOTE: in Rust 2018, this closure captures all of `fptr1`, but in Rust 2021, it will only capture `fptr1.0.0`
142142
*fptr2.0 = 20;
143143
//~^ NOTE: in Rust 2018, this closure captures all of `fptr2`, but in Rust 2021, it will only capture `fptr2.0`
144-
});
144+
}).join().unwrap();
145145
}
146146

147147
fn main() {

tests/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LL ~ thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe {
111111
LL |
112112
...
113113
LL |
114-
LL ~ } });
114+
LL ~ } }).join().unwrap();
115115
|
116116

117117
error: aborting due to 5 previous errors

tests/ui/consts/const-eval/issue-91827-extern-types.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ pub struct ListImpl<T, const N: usize> {
2828

2929
impl<T> List<T> {
3030
const fn as_slice(&self) -> &[T] {
31-
unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) }
31+
unsafe {
32+
let ptr = (self as *const List<T>).cast::<usize>().add(1).cast::<T>();
33+
std::slice::from_raw_parts(ptr, self.len)
34+
}
3235
}
3336
}
3437

tests/ui/unsized/unsized3-rpass.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn main() {
5959
}
6060

6161
let data: Box<Foo_<i32>> = Box::new(Foo_ { f: [1, 2, 3] });
62-
let x: &Foo<i32> = mem::transmute(slice::from_raw_parts(&*data, 3));
62+
let x: &Foo<i32> = mem::transmute(ptr::slice_from_raw_parts(&*data, 3));
6363
assert_eq!(x.f.len(), 3);
6464
assert_eq!(x.f[0], 1);
6565

@@ -70,7 +70,7 @@ pub fn main() {
7070

7171
let data: Box<_> =
7272
Box::new(Baz_ { f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] });
73-
let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5));
73+
let x: &Baz = mem::transmute(ptr::slice_from_raw_parts(&*data, 5));
7474
assert_eq!(x.f1, 42);
7575
let chs: Vec<char> = x.f2.chars().collect();
7676
assert_eq!(chs.len(), 5);

0 commit comments

Comments
 (0)