-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that we get a hard error on generic ZST constants if their bod…
…y causes an error during evaluation
- Loading branch information
Showing
4 changed files
with
44 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 @@ | ||
#![allow(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>()]; | ||
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,8 @@ | ||
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 | ||
|