forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#67134 - oli-obk:const_prop_zst, r=wesleywiser
Ensure that we get a hard error on generic ZST constants if their bod… …y causes an error during evaluation cc rust-lang#67083 (does not fix because we still need the beta backport) r? @wesleywiser cc @RalfJung
- Loading branch information
Showing
4 changed files
with
58 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![warn(const_err)] | ||
|
||
trait ZeroSized: Sized { | ||
const I_AM_ZERO_SIZED: (); | ||
fn requires_zero_size(self); | ||
} | ||
|
||
impl<T: Sized> ZeroSized for T { | ||
const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; //~ WARN any use of this value | ||
fn requires_zero_size(self) { | ||
let () = Self::I_AM_ZERO_SIZED; //~ ERROR erroneous constant encountered | ||
println!("requires_zero_size called"); | ||
} | ||
} | ||
|
||
fn main() { | ||
().requires_zero_size(); | ||
42_u32.requires_zero_size(); | ||
} |
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,22 @@ | ||
warning: any use of this value will cause an error | ||
--> $DIR/assoc_const_generic_impl.rs:9:34 | ||
| | ||
LL | const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; | ||
| -----------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- | ||
| | | ||
| index out of bounds: the len is 1 but the index is 4 | ||
| | ||
note: lint level defined here | ||
--> $DIR/assoc_const_generic_impl.rs:1:9 | ||
| | ||
LL | #![warn(const_err)] | ||
| ^^^^^^^^^ | ||
|
||
error: erroneous constant encountered | ||
--> $DIR/assoc_const_generic_impl.rs:11:18 | ||
| | ||
LL | let () = Self::I_AM_ZERO_SIZED; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|