forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#121198 - clubby789:unnamed-fields-hir-check…
…s, r=compiler-errors Add more checks for `unnamed_fields` during HIR analysis Fixes rust-lang#121151 I also found that we don't prevent enums here so ```rs #[repr(C)] #[derive(Debug)] enum A { #[default] B, C, } #[repr(C)] #[derive(Debug)] struct D { _: A, } ``` leads to an ICE on an `self.is_struct() || self.is_union()` assertion, so fixed that too.
- Loading branch information
Showing
8 changed files
with
161 additions
and
11 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,18 @@ | ||
#[repr(C)] | ||
pub struct GoodStruct(()); | ||
|
||
pub struct BadStruct(()); | ||
|
||
pub enum BadEnum { | ||
A, | ||
B, | ||
} | ||
|
||
#[repr(C)] | ||
pub enum BadEnum2 { | ||
A, | ||
B, | ||
} | ||
|
||
pub type GoodAlias = GoodStruct; | ||
pub type BadAlias = i32; |
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,44 @@ | ||
// aux-build:dep.rs | ||
|
||
// test for #121151 | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(unnamed_fields)] | ||
|
||
extern crate dep; | ||
|
||
#[repr(C)] | ||
struct A { | ||
a: u8, | ||
} | ||
|
||
enum BadEnum { | ||
A, | ||
B, | ||
} | ||
|
||
#[repr(C)] | ||
enum BadEnum2 { | ||
A, | ||
B, | ||
} | ||
|
||
type MyStruct = A; | ||
type MyI32 = i32; | ||
|
||
#[repr(C)] | ||
struct L { | ||
_: i32, //~ ERROR unnamed fields can only have struct or union types | ||
_: MyI32, //~ ERROR unnamed fields can only have struct or union types | ||
_: BadEnum, //~ ERROR unnamed fields can only have struct or union types | ||
_: BadEnum2, //~ ERROR unnamed fields can only have struct or union types | ||
_: MyStruct, | ||
_: dep::BadStruct, //~ ERROR named type of unnamed field must have `#[repr(C)]` representation | ||
_: dep::BadEnum, //~ ERROR unnamed fields can only have struct or union types | ||
_: dep::BadEnum2, //~ ERROR unnamed fields can only have struct or union types | ||
_: dep::BadAlias, //~ ERROR unnamed fields can only have struct or union types | ||
_: dep::GoodAlias, | ||
_: dep::GoodStruct, | ||
} | ||
|
||
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,62 @@ | ||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:31:5 | ||
| | ||
LL | _: i32, | ||
| ^^^^^^ | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:32:5 | ||
| | ||
LL | _: MyI32, | ||
| ^^^^^^^^ | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:33:5 | ||
| | ||
LL | _: BadEnum, | ||
| ^^^^^^^^^^ | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:34:5 | ||
| | ||
LL | _: BadEnum2, | ||
| ^^^^^^^^^^^ | ||
|
||
error: named type of unnamed field must have `#[repr(C)]` representation | ||
--> $DIR/restrict_type_hir.rs:36:5 | ||
| | ||
LL | _: dep::BadStruct, | ||
| ^^^^^^^^^^^^^^^^^ unnamed field defined here | ||
| | ||
::: $DIR/auxiliary/dep.rs:4:1 | ||
| | ||
LL | pub struct BadStruct(()); | ||
| -------------------- `BadStruct` defined here | ||
| | ||
help: add `#[repr(C)]` to this struct | ||
--> $DIR/auxiliary/dep.rs:4:1 | ||
| | ||
LL + #[repr(C)] | ||
LL | pub struct BadStruct(()); | ||
| | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:37:5 | ||
| | ||
LL | _: dep::BadEnum, | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:38:5 | ||
| | ||
LL | _: dep::BadEnum2, | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: unnamed fields can only have struct or union types | ||
--> $DIR/restrict_type_hir.rs:39:5 | ||
| | ||
LL | _: dep::BadAlias, | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 8 previous errors | ||
|