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#72331 - oddg:forbid-cast-of-cenum-implement…
…ing-drop, r=matthewjasper,nikomatsakis Report error when casting an C-like enum implementing Drop Following approach described in rust-lang#35941
- Loading branch information
Showing
4 changed files
with
72 additions
and
3 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,18 @@ | ||
#![deny(cenum_impl_drop_cast)] | ||
|
||
enum E { | ||
A = 0, | ||
} | ||
|
||
impl Drop for E { | ||
fn drop(&mut self) { | ||
println!("Drop"); | ||
} | ||
} | ||
|
||
fn main() { | ||
let e = E::A; | ||
let i = e as u32; | ||
//~^ ERROR cannot cast enum `E` into integer `u32` because it implements `Drop` | ||
//~| WARN this was previously accepted | ||
} |
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 @@ | ||
error: cannot cast enum `E` into integer `u32` because it implements `Drop` | ||
--> $DIR/cenum_impl_drop_cast.rs:15:13 | ||
| | ||
LL | let i = e as u32; | ||
| ^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/cenum_impl_drop_cast.rs:1:9 | ||
| | ||
LL | #![deny(cenum_impl_drop_cast)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333> | ||
|
||
error: aborting due to previous error | ||
|