Skip to content

Commit 7a265c6

Browse files
committed
Feature gate repr(packed).
There are some correctness issues due to unaligned internal fields and references. cc rust-lang#27060.
1 parent c85ba3e commit 7a265c6

20 files changed

+60
-0
lines changed

src/libsyntax/feature_gate.rs

+14
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
158158

159159
// Allows using #[prelude_import] on glob `use` items.
160160
("prelude_import", "1.2.0", Active),
161+
162+
// Allows use of repr(packed)
163+
("repr_packed", "1.3.0", Active),
161164
];
162165
// (changing above list without updating src/doc/reference.md makes @cmr sad)
163166

@@ -564,6 +567,17 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
564567
self.gate_feature("simd", i.span,
565568
"SIMD types are experimental and possibly buggy");
566569
}
570+
571+
for attr in &i.attrs {
572+
if attr.name() == "repr" {
573+
for item in attr.meta_item_list().unwrap_or(&[]) {
574+
if item.name() == "packed" {
575+
self.gate_feature("repr_packed", item.span,
576+
"packed types are experimental and buggy");
577+
}
578+
}
579+
}
580+
}
567581
}
568582

569583
ast::ItemDefaultImpl(..) => {

src/test/auxiliary/packed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
12+
1113
#[repr(packed)]
1214
pub struct S {
1315
a: u8,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#[repr(packed)] //~ ERROR packed types are experimental
13+
struct Foo { x: u8 }
14+
#[repr(packed, C)] //~ ERROR packed types are experimental
15+
struct Bar { x: u8 }
16+
#[repr(C, packed)] //~ ERROR packed types are experimental
17+
struct Baz { x: u8 }
18+
19+
fn main() {}

src/test/compile-fail/issue-14309.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
1112
#![deny(improper_ctypes)]
1213
#![allow(dead_code)]
1314

src/test/compile-fail/packed-struct-generic-transmute.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
// error-pattern: transmute called on types with different size
1717

18+
#![feature(repr_packed)]
19+
1820
use std::mem;
1921

2022
#[repr(packed)]

src/test/compile-fail/packed-struct-transmute.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
// error-pattern: transmute called on types with different size
1717

18+
#![feature(repr_packed)]
19+
1820
use std::mem;
1921

2022
#[repr(packed)]

src/test/debuginfo/c-style-enum-in-composite.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
#![allow(unused_variables)]
6767
#![omit_gdb_pretty_printer_section]
68+
#![feature(repr_packed)]
6869

6970
use self::AnEnum::{OneHundred, OneThousand, OneMillion};
7071
use self::AnotherEnum::{MountainView, Toronto, Vienna};

src/test/debuginfo/packed-struct-with-destructor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
#![allow(unused_variables)]
7676
#![omit_gdb_pretty_printer_section]
77+
#![feature(repr_packed)]
7778

7879
#[repr(packed)]
7980
struct Packed {

src/test/debuginfo/packed-struct.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
#![allow(unused_variables)]
6262
#![omit_gdb_pretty_printer_section]
63+
#![feature(repr_packed)]
6364

6465
#[repr(packed)]
6566
struct Packed {

src/test/run-make/extern-fn-with-packed-struct/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
12+
1113
#[repr(packed)]
1214
#[derive(Copy, Clone, PartialEq, Debug)]
1315
struct Foo {

src/test/run-pass/issue-26646.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
1112
#![deny(unused_attributes)]
1213

1314
#[repr(C)]

src/test/run-pass/packed-struct-borrow-element.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// except according to those terms.
1010

1111

12+
#![feature(repr_packed)]
13+
1214
#[repr(packed)]
1315
struct Foo {
1416
bar: u8,

src/test/run-pass/packed-struct-generic-layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// except according to those terms.
1010

1111

12+
#![feature(repr_packed)]
13+
1214
use std::mem;
1315

1416
#[repr(packed)]

src/test/run-pass/packed-struct-generic-size.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
1112

1213
use std::mem;
1314

src/test/run-pass/packed-struct-layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
1112

1213
use std::mem;
1314

src/test/run-pass/packed-struct-match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
1112

1213
#[repr(packed)]
1314
struct Foo {

src/test/run-pass/packed-struct-size.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111

12+
#![feature(repr_packed)]
1213

1314
use std::mem;
1415

src/test/run-pass/packed-struct-vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(repr_packed)]
12+
1113
use std::mem;
1214

1315
#[repr(packed)]

src/test/run-pass/packed-tuple-struct-layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// except according to those terms.
1010

1111

12+
#![feature(repr_packed)]
13+
1214
use std::mem;
1315

1416
#[repr(packed)]

src/test/run-pass/packed-tuple-struct-size.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212

13+
#![feature(repr_packed)]
14+
1315
use std::mem;
1416

1517
#[repr(packed)]

0 commit comments

Comments
 (0)