Skip to content

Commit f053d9e

Browse files
committed
revert: rust-lang#144016 - MetaSized does not always hold
1 parent f8f6997 commit f053d9e

19 files changed

+263
-33
lines changed

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,6 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
379379
_ => return false,
380380
};
381381

382-
// FIXME(sized_hierarchy): this temporarily reverts the `sized_hierarchy` feature
383-
// while a proper fix for `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs`
384-
// is pending a proper fix
385-
if !tcx.features().sized_hierarchy() && matches!(sizedness, SizedTraitKind::MetaSized) {
386-
return true;
387-
}
388-
389382
if trait_pred.self_ty().has_trivial_sizedness(tcx, sizedness) {
390383
debug!("fast path -- trivial sizedness");
391384
return true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ extern "C" {
88
}
99

1010
const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
11-
//~^ ERROR `extern type` does not have known layout
11+
//~^ ERROR: the size for values of type `Opaque` cannot be known
1212
const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
13-
//~^ ERROR `extern type` does not have known layout
13+
//~^ ERROR: the size for values of type `Opaque` cannot be known
1414

1515
fn main() {}
Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
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+
| ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Opaque`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= note: the trait bound `Opaque: MetaSized` is not satisfied
10+
note: required by a bound in `std::intrinsics::size_of_val`
11+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
12+
help: consider borrowing here
13+
|
14+
LL | const _SIZE: usize = unsafe { size_of_val(&(&4 as *const i32 as *const Opaque)) };
15+
| ++ +
16+
LL | const _SIZE: usize = unsafe { size_of_val(&mut (&4 as *const i32 as *const Opaque)) };
17+
| ++++++ +
618

7-
error[E0080]: `extern type` does not have known layout
8-
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32
19+
error[E0277]: the size for values of type `Opaque` cannot be known
20+
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:45
921
|
1022
LL | const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here
23+
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Opaque`
24+
| |
25+
| required by a bound introduced by this call
26+
|
27+
= note: the trait bound `Opaque: MetaSized` is not satisfied
28+
note: required by a bound in `std::intrinsics::align_of_val`
29+
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
30+
help: consider borrowing here
31+
|
32+
LL | const _ALIGN: usize = unsafe { align_of_val(&(&4 as *const i32 as *const Opaque)) };
33+
| ++ +
34+
LL | const _ALIGN: usize = unsafe { align_of_val(&mut (&4 as *const i32 as *const Opaque)) };
35+
| ++++++ +
1236

1337
error: aborting due to 2 previous errors
1438

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

tests/ui/extern/extern-types-size_of_val.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ check-pass
21
#![feature(extern_types)]
32

43
use std::mem::{align_of_val, size_of_val};
@@ -11,5 +10,7 @@ fn main() {
1110
let x: &A = unsafe { &*(1usize as *const A) };
1211

1312
size_of_val(x);
13+
//~^ ERROR: the size for values of type `A` cannot be known
1414
align_of_val(x);
15+
//~^ ERROR: the size for values of type `A` cannot be known
1516
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0277]: the size for values of type `A` cannot be known
2+
--> $DIR/extern-types-size_of_val.rs:12:17
3+
|
4+
LL | size_of_val(x);
5+
| ----------- ^ the trait `MetaSized` is not implemented for `A`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= note: the trait bound `A: MetaSized` is not satisfied
10+
note: required by a bound in `std::mem::size_of_val`
11+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
12+
help: consider borrowing here
13+
|
14+
LL | size_of_val(&x);
15+
| +
16+
LL | size_of_val(&mut x);
17+
| ++++
18+
19+
error[E0277]: the size for values of type `A` cannot be known
20+
--> $DIR/extern-types-size_of_val.rs:14:18
21+
|
22+
LL | align_of_val(x);
23+
| ------------ ^ the trait `MetaSized` is not implemented for `A`
24+
| |
25+
| required by a bound introduced by this call
26+
|
27+
= note: the trait bound `A: MetaSized` is not satisfied
28+
note: required by a bound in `std::mem::align_of_val`
29+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
30+
help: consider borrowing here
31+
|
32+
LL | align_of_val(&x);
33+
| +
34+
LL | align_of_val(&mut x);
35+
| ++++
36+
37+
error: aborting due to 2 previous errors
38+
39+
For more information about this error, try `rustc --explain E0277`.

tests/ui/extern/extern-types-unsized.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ fn main() {
2727

2828
assert_sized::<Bar<A>>();
2929
//~^ ERROR the size for values of type
30+
//~| ERROR the size for values of type `A` cannot be known
3031

3132
assert_sized::<Bar<Bar<A>>>();
3233
//~^ ERROR the size for values of type
34+
//~| ERROR the size for values of type `A` cannot be known
3335
}

tests/ui/extern/extern-types-unsized.stderr

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,21 @@ help: consider relaxing the implicit `Sized` restriction
5959
LL | fn assert_sized<T: ?Sized>() {}
6060
| ++++++++
6161

62+
error[E0277]: the size for values of type `A` cannot be known
63+
--> $DIR/extern-types-unsized.rs:28:20
64+
|
65+
LL | assert_sized::<Bar<A>>();
66+
| ^^^^^^ doesn't have a known size
67+
|
68+
= help: the trait `MetaSized` is not implemented for `A`
69+
note: required by a bound in `Bar`
70+
--> $DIR/extern-types-unsized.rs:14:12
71+
|
72+
LL | struct Bar<T: ?Sized> {
73+
| ^ required by this bound in `Bar`
74+
6275
error[E0277]: the size for values of type `A` cannot be known at compilation time
63-
--> $DIR/extern-types-unsized.rs:31:20
76+
--> $DIR/extern-types-unsized.rs:32:20
6477
|
6578
LL | assert_sized::<Bar<Bar<A>>>();
6679
| ^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -81,6 +94,19 @@ help: consider relaxing the implicit `Sized` restriction
8194
LL | fn assert_sized<T: ?Sized>() {}
8295
| ++++++++
8396

84-
error: aborting due to 4 previous errors
97+
error[E0277]: the size for values of type `A` cannot be known
98+
--> $DIR/extern-types-unsized.rs:32:20
99+
|
100+
LL | assert_sized::<Bar<Bar<A>>>();
101+
| ^^^^^^^^^^^ doesn't have a known size
102+
|
103+
= help: the trait `MetaSized` is not implemented for `A`
104+
note: required by a bound in `Bar`
105+
--> $DIR/extern-types-unsized.rs:14:12
106+
|
107+
LL | struct Bar<T: ?Sized> {
108+
| ^ required by this bound in `Bar`
109+
110+
error: aborting due to 6 previous errors
85111

86112
For more information about this error, try `rustc --explain E0277`.

tests/ui/extern/unsized-extern-derefmove.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ extern "C" {
77
}
88

99
unsafe fn make_device() -> Box<Device> {
10+
//~^ ERROR the size for values of type `Device` cannot be known
1011
Box::from_raw(0 as *mut _)
12+
//~^ ERROR the size for values of type `Device` cannot be known
13+
//~| ERROR the size for values of type `Device` cannot be known
1114
}
1215

1316
fn main() {
1417
let d: Device = unsafe { *make_device() };
1518
//~^ ERROR the size for values of type `Device` cannot be known
19+
//~| ERROR the size for values of type `Device` cannot be known
1620
}

tests/ui/extern/unsized-extern-derefmove.stderr

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
1+
error[E0277]: the size for values of type `Device` cannot be known
2+
--> $DIR/unsized-extern-derefmove.rs:9:28
3+
|
4+
LL | unsafe fn make_device() -> Box<Device> {
5+
| ^^^^^^^^^^^ doesn't have a known size
6+
|
7+
= help: the trait `MetaSized` is not implemented for `Device`
8+
note: required by a bound in `Box`
9+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
10+
11+
error[E0277]: the size for values of type `Device` cannot be known
12+
--> $DIR/unsized-extern-derefmove.rs:11:19
13+
|
14+
LL | Box::from_raw(0 as *mut _)
15+
| ------------- ^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Device`
16+
| |
17+
| required by a bound introduced by this call
18+
|
19+
= note: the trait bound `Device: MetaSized` is not satisfied
20+
note: required by a bound in `Box::<T>::from_raw`
21+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
22+
help: consider borrowing here
23+
|
24+
LL | Box::from_raw(&(0 as *mut _))
25+
| ++ +
26+
LL | Box::from_raw(&mut (0 as *mut _))
27+
| ++++++ +
28+
29+
error[E0277]: the size for values of type `Device` cannot be known
30+
--> $DIR/unsized-extern-derefmove.rs:11:5
31+
|
32+
LL | Box::from_raw(0 as *mut _)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size
34+
|
35+
= help: the trait `MetaSized` is not implemented for `Device`
36+
note: required by a bound in `Box`
37+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
38+
139
error[E0277]: the size for values of type `Device` cannot be known at compilation time
2-
--> $DIR/unsized-extern-derefmove.rs:14:9
40+
--> $DIR/unsized-extern-derefmove.rs:17:9
341
|
442
LL | let d: Device = unsafe { *make_device() };
543
| ^ doesn't have a size known at compile-time
@@ -11,6 +49,16 @@ help: consider borrowing here
1149
LL | let d: &Device = unsafe { *make_device() };
1250
| +
1351

14-
error: aborting due to 1 previous error
52+
error[E0277]: the size for values of type `Device` cannot be known
53+
--> $DIR/unsized-extern-derefmove.rs:17:31
54+
|
55+
LL | let d: Device = unsafe { *make_device() };
56+
| ^^^^^^^^^^^^^ doesn't have a known size
57+
|
58+
= help: the trait `MetaSized` is not implemented for `Device`
59+
note: required by a bound in `Box`
60+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
61+
62+
error: aborting due to 5 previous errors
1563

1664
For more information about this error, try `rustc --explain E0277`.

tests/ui/layout/unconstrained-param-ice-137308.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ impl<C: ?Sized> A for u8 { //~ ERROR: the type parameter `C` is not constrained
1717
#[rustc_layout(debug)]
1818
struct S([u8; <u8 as A>::B]);
1919
//~^ ERROR: the type has an unknown layout
20+
//~| ERROR: type annotations needed

0 commit comments

Comments
 (0)