Allow explicit #[repr(Rust)]

This commit is contained in:
Catherine Flores 2023-07-29 06:58:29 +00:00
parent 8771282d4e
commit f42d361a22
7 changed files with 24 additions and 8 deletions

View File

@ -940,6 +940,7 @@ fn find_deprecation_generic<'a, I>(sess: &Session, attrs_iter: I) -> Option<(Dep
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)] #[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)]
pub enum ReprAttr { pub enum ReprAttr {
ReprInt(IntType), ReprInt(IntType),
ReprRust,
ReprC, ReprC,
ReprPacked(u32), ReprPacked(u32),
ReprSimd, ReprSimd,
@ -988,6 +989,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
let mut recognised = false; let mut recognised = false;
if item.is_word() { if item.is_word() {
let hint = match item.name_or_empty() { let hint = match item.name_or_empty() {
sym::Rust => Some(ReprRust),
sym::C => Some(ReprC), sym::C => Some(ReprC),
sym::packed => Some(ReprPacked(1)), sym::packed => Some(ReprPacked(1)),
sym::simd => Some(ReprSimd), sym::simd => Some(ReprSimd),

View File

@ -2257,6 +2257,7 @@ pub fn repr_options_of_def(self, did: DefId) -> ReprOptions {
for attr in self.get_attrs(did, sym::repr) { for attr in self.get_attrs(did, sym::repr) {
for r in attr::parse_repr_attr(&self.sess, attr) { for r in attr::parse_repr_attr(&self.sess, attr) {
flags.insert(match r { flags.insert(match r {
attr::ReprRust => ReprFlags::empty(),
attr::ReprC => ReprFlags::IS_C, attr::ReprC => ReprFlags::IS_C,
attr::ReprPacked(pack) => { attr::ReprPacked(pack) => {
let pack = Align::from_bytes(pack as u64).unwrap(); let pack = Align::from_bytes(pack as u64).unwrap();

View File

@ -706,7 +706,7 @@ passes_unrecognized_field =
passes_unrecognized_repr_hint = passes_unrecognized_repr_hint =
unrecognized representation hint unrecognized representation hint
.help = valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` .help = valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
passes_unused = passes_unused =
unused attribute unused attribute

View File

@ -1683,6 +1683,7 @@ fn check_repr(
} }
match hint.name_or_empty() { match hint.name_or_empty() {
sym::Rust => {}
sym::C => { sym::C => {
is_c = true; is_c = true;
match target { match target {

View File

@ -0,0 +1,12 @@
// check-pass
#[repr(Rust)]
struct A;
#[repr(Rust, align(16))]
struct B;
#[repr(Rust, packed)]
struct C;
fn main() {}

View File

@ -32,7 +32,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(nothing)] LL | #[repr(nothing)]
| ^^^^^^^ | ^^^^^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error[E0552]: unrecognized representation hint error[E0552]: unrecognized representation hint
--> $DIR/issue-43988.rs:18:12 --> $DIR/issue-43988.rs:18:12
@ -40,7 +40,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(something_not_real)] LL | #[repr(something_not_real)]
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error[E0518]: attribute should be applied to function or closure error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43988.rs:30:5 --> $DIR/issue-43988.rs:30:5

View File

@ -4,7 +4,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(uwu)] LL | #[repr(uwu)]
| ^^^ | ^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error[E0552]: unrecognized representation hint error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:6:8 --> $DIR/invalid_repr_list_help.rs:6:8
@ -12,7 +12,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(uwu = "a")] LL | #[repr(uwu = "a")]
| ^^^^^^^^^ | ^^^^^^^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error[E0552]: unrecognized representation hint error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:9:8 --> $DIR/invalid_repr_list_help.rs:9:8
@ -20,7 +20,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(uwu(4))] LL | #[repr(uwu(4))]
| ^^^^^^ | ^^^^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error[E0552]: unrecognized representation hint error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:14:8 --> $DIR/invalid_repr_list_help.rs:14:8
@ -28,7 +28,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(uwu, u8)] LL | #[repr(uwu, u8)]
| ^^^ | ^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
warning: unknown `doc` attribute `owo` warning: unknown `doc` attribute `owo`
--> $DIR/invalid_repr_list_help.rs:20:7 --> $DIR/invalid_repr_list_help.rs:20:7
@ -46,7 +46,7 @@ error[E0552]: unrecognized representation hint
LL | #[repr(uwu)] LL | #[repr(uwu)]
| ^^^ | ^^^
| |
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` = help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
error: aborting due to 5 previous errors; 1 warning emitted error: aborting due to 5 previous errors; 1 warning emitted