-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #47111 - rkruppe:repr-transparent, r=estebank
Check all repr hints together when checking for mis-applied attributes Fixes #47094 Besides fixing that bug, this change has a user-visible effect on the spans in the "incompatible repr hints" warning and another error: they now point at `foo` and/or `bar` in `repr(foo, bar)` instead of the whole attribute. This is sometimes more precise (e.g., `#[repr(C, packed)]` on an enum points at the `packed`) but sometimes not. I moved a compile-fail test to a ui test to illustrate how it now looks in the common case of only one attribute.
- Loading branch information
Showing
7 changed files
with
130 additions
and
44 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,42 @@ | ||
error[E0517]: attribute should be applied to struct, enum or union | ||
--> $DIR/attr-usage-repr.rs:14:8 | ||
| | ||
14 | #[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union | ||
| ^ | ||
15 | fn f() {} | ||
| --------- not a struct, enum or union | ||
|
||
error[E0517]: attribute should be applied to enum | ||
--> $DIR/attr-usage-repr.rs:26:8 | ||
| | ||
26 | #[repr(i8)] //~ ERROR: attribute should be applied to enum | ||
| ^^ | ||
27 | struct SInt(f64, f64); | ||
| ---------------------- not an enum | ||
|
||
error[E0517]: attribute should be applied to struct or union | ||
--> $DIR/attr-usage-repr.rs:32:8 | ||
| | ||
32 | #[repr(align(8))] //~ ERROR: attribute should be applied to struct | ||
| ^^^^^^^^ | ||
33 | enum EAlign { A, B } | ||
| -------------------- not a struct or union | ||
|
||
error[E0517]: attribute should be applied to struct or union | ||
--> $DIR/attr-usage-repr.rs:35:8 | ||
| | ||
35 | #[repr(packed)] //~ ERROR: attribute should be applied to struct | ||
| ^^^^^^ | ||
36 | enum EPacked { A, B } | ||
| --------------------- not a struct or union | ||
|
||
error[E0517]: attribute should be applied to struct | ||
--> $DIR/attr-usage-repr.rs:38:8 | ||
| | ||
38 | #[repr(simd)] //~ ERROR: attribute should be applied to struct | ||
| ^^^^ | ||
39 | enum ESimd { A, B } | ||
| ------------------- not a struct | ||
|
||
error: aborting due to 5 previous errors | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
struct LocalSimd(u8, u8); | ||
|
||
extern { | ||
|
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,26 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// must-compile-successfully | ||
|
||
#[repr(C,u8)] | ||
enum Foo { | ||
A, | ||
B, | ||
} | ||
|
||
#[repr(C)] | ||
#[repr(u8)] | ||
enum Bar { | ||
A, | ||
B, | ||
} | ||
|
||
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,14 @@ | ||
warning[E0566]: conflicting representation hints | ||
--> $DIR/issue-47094.rs:13:8 | ||
| | ||
13 | #[repr(C,u8)] | ||
| ^ ^^ | ||
|
||
warning[E0566]: conflicting representation hints | ||
--> $DIR/issue-47094.rs:19:8 | ||
| | ||
19 | #[repr(C)] | ||
| ^ | ||
20 | #[repr(u8)] | ||
| ^^ | ||
|