Skip to content

Commit 3c3ba37

Browse files
committed
tests: PointeeSized bounds with extern types
These tests necessarily need to change now that `?Sized` is not sufficient to accept extern types and `PointeeSized` is now necessary. In addition, the `size_of_val`/`align_of_val` test can now be changed to expect an error.
1 parent 118d4e6 commit 3c3ba37

20 files changed

+131
-69
lines changed

tests/codegen/dst-offset.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
44

55
#![crate_type = "lib"]
6-
#![feature(extern_types)]
6+
#![feature(extern_types, sized_hierarchy)]
77

8+
use std::marker::PointeeSized;
89
use std::ptr::addr_of;
910

1011
// Hack to get the correct type for usize
1112
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
1213
#[no_mangle]
1314
pub fn helper(_: usize) {}
1415

15-
struct Dst<T: ?Sized> {
16+
struct Dst<T: PointeeSized> {
1617
x: u32,
1718
y: u8,
1819
z: T,

tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ extern "C" {
77
type Opaque;
88
}
99

10-
const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR layout
11-
const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR layout
10+
const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
11+
//~^ ERROR the size for values of type `Opaque` cannot be known
12+
const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
13+
//~^ ERROR the size for values of type `Opaque` cannot be known
1214

1315
fn main() {}
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
error[E0080]: `extern type` does not have known layout
2-
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:31
1+
error[E0277]: the size for values of type `Opaque` cannot be known
2+
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:43
33
|
44
LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_SIZE` failed here
5+
| ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `MetaSized` is not implemented for `Opaque`
10+
note: required by a bound in `std::intrinsics::size_of_val`
11+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
612

7-
error[E0080]: `extern type` does not have known layout
8-
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:32
13+
error[E0277]: the size for values of type `Opaque` cannot be known
14+
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:45
915
|
1016
LL | const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here
17+
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size
18+
| |
19+
| required by a bound introduced by this call
20+
|
21+
= help: the trait `MetaSized` is not implemented for `Opaque`
22+
note: required by a bound in `std::intrinsics::align_of_val`
23+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
1224

1325
error: aborting due to 2 previous errors
1426

15-
For more information about this error, try `rustc --explain E0080`.
27+
For more information about this error, try `rustc --explain E0277`.

tests/ui/extern/extern-type-diag-not-similar.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// Two extern types shouldn't really be considered similar just
44
// because they are both extern types.
55

6-
#![feature(extern_types)]
6+
#![feature(extern_types, sized_hierarchy)]
7+
8+
use std::marker::PointeeSized;
9+
710
extern "C" {
811
type ShouldNotBeMentioned;
912
}
@@ -14,7 +17,7 @@ extern "C" {
1417

1518
unsafe impl Send for ShouldNotBeMentioned {}
1619

17-
fn assert_send<T: Send + ?Sized>() {}
20+
fn assert_send<T: Send + PointeeSized>() {}
1821

1922
fn main() {
2023
assert_send::<Foo>()

tests/ui/extern/extern-type-diag-not-similar.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0277]: `Foo` cannot be sent between threads safely
2-
--> $DIR/extern-type-diag-not-similar.rs:20:19
2+
--> $DIR/extern-type-diag-not-similar.rs:23:19
33
|
44
LL | assert_send::<Foo>()
55
| ^^^ `Foo` cannot be sent between threads safely
66
|
77
= help: the trait `Send` is not implemented for `Foo`
88
note: required by a bound in `assert_send`
9-
--> $DIR/extern-type-diag-not-similar.rs:17:19
9+
--> $DIR/extern-type-diag-not-similar.rs:20:19
1010
|
11-
LL | fn assert_send<T: Send + ?Sized>() {}
11+
LL | fn assert_send<T: Send + PointeeSized>() {}
1212
| ^^^^ required by this bound in `assert_send`
1313

1414
error: aborting due to 1 previous error

tests/ui/extern/extern-types-manual-sync-send.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//@ run-pass
22
// Test that unsafe impl for Sync/Send can be provided for extern types.
33

4-
#![feature(extern_types)]
4+
#![feature(extern_types, sized_hierarchy)]
5+
6+
use std::marker::PointeeSized;
57

68
extern "C" {
79
type A;
@@ -10,8 +12,8 @@ extern "C" {
1012
unsafe impl Sync for A {}
1113
unsafe impl Send for A {}
1214

13-
fn assert_sync<T: ?Sized + Sync>() {}
14-
fn assert_send<T: ?Sized + Send>() {}
15+
fn assert_sync<T: PointeeSized + Sync>() {}
16+
fn assert_send<T: PointeeSized + Send>() {}
1517

1618
fn main() {
1719
assert_sync::<A>();

tests/ui/extern/extern-types-not-sync-send.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Make sure extern types are !Sync and !Send.
22

3-
#![feature(extern_types)]
3+
#![feature(extern_types, sized_hierarchy)]
4+
5+
use std::marker::PointeeSized;
46

57
extern "C" {
68
type A;
79
}
810

9-
fn assert_sync<T: ?Sized + Sync>() {}
10-
fn assert_send<T: ?Sized + Send>() {}
11+
fn assert_sync<T: PointeeSized + Sync>() {}
12+
fn assert_send<T: PointeeSized + Send>() {}
1113

1214
fn main() {
1315
assert_sync::<A>();

tests/ui/extern/extern-types-not-sync-send.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
error[E0277]: `A` cannot be shared between threads safely
2-
--> $DIR/extern-types-not-sync-send.rs:13:19
2+
--> $DIR/extern-types-not-sync-send.rs:15:19
33
|
44
LL | assert_sync::<A>();
55
| ^ `A` cannot be shared between threads safely
66
|
77
= help: the trait `Sync` is not implemented for `A`
88
note: required by a bound in `assert_sync`
9-
--> $DIR/extern-types-not-sync-send.rs:9:28
9+
--> $DIR/extern-types-not-sync-send.rs:11:34
1010
|
11-
LL | fn assert_sync<T: ?Sized + Sync>() {}
12-
| ^^^^ required by this bound in `assert_sync`
11+
LL | fn assert_sync<T: PointeeSized + Sync>() {}
12+
| ^^^^ required by this bound in `assert_sync`
1313

1414
error[E0277]: `A` cannot be sent between threads safely
15-
--> $DIR/extern-types-not-sync-send.rs:16:19
15+
--> $DIR/extern-types-not-sync-send.rs:18:19
1616
|
1717
LL | assert_send::<A>();
1818
| ^ `A` cannot be sent between threads safely
1919
|
2020
= help: the trait `Send` is not implemented for `A`
2121
note: required by a bound in `assert_send`
22-
--> $DIR/extern-types-not-sync-send.rs:10:28
22+
--> $DIR/extern-types-not-sync-send.rs:12:34
2323
|
24-
LL | fn assert_send<T: ?Sized + Send>() {}
25-
| ^^^^ required by this bound in `assert_send`
24+
LL | fn assert_send<T: PointeeSized + Send>() {}
25+
| ^^^^ required by this bound in `assert_send`
2626

2727
error: aborting due to 2 previous errors
2828

tests/ui/extern/extern-types-pointer-cast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#![allow(dead_code)]
33
// Test that pointers to extern types can be cast from/to usize,
44
// despite being !Sized.
5-
#![feature(extern_types)]
5+
#![feature(extern_types, sized_hierarchy)]
6+
use std::marker::PointeeSized;
67

78
extern "C" {
89
type A;
@@ -13,7 +14,7 @@ struct Foo {
1314
tail: A,
1415
}
1516

16-
struct Bar<T: ?Sized> {
17+
struct Bar<T: PointeeSized> {
1718
x: u8,
1819
tail: T,
1920
}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
//@ run-fail
2-
//@ check-run-results
3-
//@ exec-env:RUST_BACKTRACE=0
4-
//@ normalize-stderr: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"
5-
//@ revisions: size align
1+
//@ check-fail
62
#![feature(extern_types)]
73

84
use std::mem::{align_of_val, size_of_val};
@@ -14,10 +10,8 @@ extern "C" {
1410
fn main() {
1511
let x: &A = unsafe { &*(1usize as *const A) };
1612

17-
// These don't have a dynamic size, so this should panic.
18-
if cfg!(size) {
19-
assert_eq!(size_of_val(x), 0);
20-
} else {
21-
assert_eq!(align_of_val(x), 1);
22-
}
13+
size_of_val(x);
14+
//~^ ERROR the size for values of type `A` cannot be known
15+
align_of_val(x);
16+
//~^ ERROR the size for values of type `A` cannot be known
2317
}

0 commit comments

Comments
 (0)