Skip to content

Commit f42d361

Browse files
committed
Allow explicit #[repr(Rust)]
1 parent 8771282 commit f42d361

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

compiler/rustc_attr/src/builtin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ where
940940
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)]
941941
pub enum ReprAttr {
942942
ReprInt(IntType),
943+
ReprRust,
943944
ReprC,
944945
ReprPacked(u32),
945946
ReprSimd,
@@ -988,6 +989,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
988989
let mut recognised = false;
989990
if item.is_word() {
990991
let hint = match item.name_or_empty() {
992+
sym::Rust => Some(ReprRust),
991993
sym::C => Some(ReprC),
992994
sym::packed => Some(ReprPacked(1)),
993995
sym::simd => Some(ReprSimd),

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,7 @@ impl<'tcx> TyCtxt<'tcx> {
22572257
for attr in self.get_attrs(did, sym::repr) {
22582258
for r in attr::parse_repr_attr(&self.sess, attr) {
22592259
flags.insert(match r {
2260+
attr::ReprRust => ReprFlags::empty(),
22602261
attr::ReprC => ReprFlags::IS_C,
22612262
attr::ReprPacked(pack) => {
22622263
let pack = Align::from_bytes(pack as u64).unwrap();

compiler/rustc_passes/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ passes_unrecognized_field =
706706
707707
passes_unrecognized_repr_hint =
708708
unrecognized representation hint
709-
.help = valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
709+
.help = valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
710710
711711
passes_unused =
712712
unused attribute

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ impl CheckAttrVisitor<'_> {
16831683
}
16841684

16851685
match hint.name_or_empty() {
1686+
sym::Rust => {}
16861687
sym::C => {
16871688
is_c = true;
16881689
match target {

tests/ui/abi/explicit_repr_rust.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
3+
#[repr(Rust)]
4+
struct A;
5+
6+
#[repr(Rust, align(16))]
7+
struct B;
8+
9+
#[repr(Rust, packed)]
10+
struct C;
11+
12+
fn main() {}

tests/ui/issues/issue-43988.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ error[E0552]: unrecognized representation hint
3232
LL | #[repr(nothing)]
3333
| ^^^^^^^
3434
|
35-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
35+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
3636

3737
error[E0552]: unrecognized representation hint
3838
--> $DIR/issue-43988.rs:18:12
3939
|
4040
LL | #[repr(something_not_real)]
4141
| ^^^^^^^^^^^^^^^^^^
4242
|
43-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
43+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
4444

4545
error[E0518]: attribute should be applied to function or closure
4646
--> $DIR/issue-43988.rs:30:5

tests/ui/repr/invalid_repr_list_help.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ error[E0552]: unrecognized representation hint
44
LL | #[repr(uwu)]
55
| ^^^
66
|
7-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
7+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
88

99
error[E0552]: unrecognized representation hint
1010
--> $DIR/invalid_repr_list_help.rs:6:8
1111
|
1212
LL | #[repr(uwu = "a")]
1313
| ^^^^^^^^^
1414
|
15-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
15+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
1616

1717
error[E0552]: unrecognized representation hint
1818
--> $DIR/invalid_repr_list_help.rs:9:8
1919
|
2020
LL | #[repr(uwu(4))]
2121
| ^^^^^^
2222
|
23-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
23+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
2424

2525
error[E0552]: unrecognized representation hint
2626
--> $DIR/invalid_repr_list_help.rs:14:8
2727
|
2828
LL | #[repr(uwu, u8)]
2929
| ^^^
3030
|
31-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
31+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
3232

3333
warning: unknown `doc` attribute `owo`
3434
--> $DIR/invalid_repr_list_help.rs:20:7
@@ -46,7 +46,7 @@ error[E0552]: unrecognized representation hint
4646
LL | #[repr(uwu)]
4747
| ^^^
4848
|
49-
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
49+
= help: valid reprs are `Rust`, `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
5050

5151
error: aborting due to 5 previous errors; 1 warning emitted
5252

0 commit comments

Comments
 (0)