-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #104338 - compiler-errors:pointer-sized, r=eholk
Enforce that `dyn*` coercions are actually pointer-sized Implement a perma-unstable, rudimentary `PointerSized` trait to enforce `dyn*` casts are `usize`-sized for now, at least to prevent ICEs and weird codegen issues from cropping up after monomorphization since currently we enforce *nothing*. This probably can/should be removed in favor of a more sophisticated trait for handling `dyn*` conversions when we decide on one, but I just want to get something up for discussion and experimentation for now. r? ```@eholk``` cc ```@tmandry``` (though feel free to claim/reassign) Fixes #102141 Fixes #102173
- Loading branch information
Showing
13 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/align.rs:4:12 | ||
| | ||
LL | #![feature(dyn_star)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/align.rs:4:12 | ||
| | ||
LL | #![feature(dyn_star)] | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0277]: `AlignedUsize` needs to be a pointer-sized type | ||
--> $DIR/align.rs:15:13 | ||
| | ||
LL | let x = AlignedUsize(12) as dyn* Debug; | ||
| ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-sized type | ||
| | ||
= help: the trait `PointerSized` is not implemented for `AlignedUsize` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// revisions: normal over_aligned | ||
//[normal] check-pass | ||
|
||
#![feature(dyn_star)] | ||
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes | ||
|
||
use std::fmt::Debug; | ||
|
||
#[cfg_attr(over_aligned, repr(C, align(1024)))] | ||
#[cfg_attr(not(over_aligned), repr(C))] | ||
#[derive(Debug)] | ||
struct AlignedUsize(usize); | ||
|
||
fn main() { | ||
let x = AlignedUsize(12) as dyn* Debug; | ||
//[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![feature(dyn_star)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn dyn_debug(_: (dyn* Debug + '_)) { | ||
|
||
} | ||
|
||
fn polymorphic<T: Debug + ?Sized>(t: &T) { | ||
dyn_debug(t); | ||
//~^ ERROR `&T` needs to be a pointer-sized type | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/dyn-star/check-size-at-cast-polymorphic-bad.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0277]: `&T` needs to be a pointer-sized type | ||
--> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15 | ||
| | ||
LL | dyn_debug(t); | ||
| ^ `&T` needs to be a pointer-sized type | ||
| | ||
= help: the trait `PointerSized` is not implemented for `&T` | ||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | ||
| | ||
LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerSized { | ||
| ++++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// check-pass | ||
|
||
#![feature(dyn_star)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn dyn_debug(_: (dyn* Debug + '_)) { | ||
|
||
} | ||
|
||
fn polymorphic<T: Debug>(t: &T) { | ||
dyn_debug(t); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![feature(dyn_star)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() { | ||
let i = [1, 2, 3, 4] as dyn* Debug; | ||
//~^ ERROR `[i32; 4]` needs to be a pointer-sized type | ||
dbg!(i); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0277]: `[i32; 4]` needs to be a pointer-sized type | ||
--> $DIR/check-size-at-cast.rs:7:13 | ||
| | ||
LL | let i = [1, 2, 3, 4] as dyn* Debug; | ||
| ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-sized type | ||
| | ||
= help: the trait `PointerSized` is not implemented for `[i32; 4]` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |