Skip to content

Commit

Permalink
Feature gate repr(packed).
Browse files Browse the repository at this point in the history
There are some correctness issues due to unaligned internal fields and
references. cc rust-lang#27060.
  • Loading branch information
huonw committed Jul 24, 2015
1 parent c85ba3e commit 7a265c6
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[

// Allows using #[prelude_import] on glob `use` items.
("prelude_import", "1.2.0", Active),

// Allows use of repr(packed)
("repr_packed", "1.3.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down Expand Up @@ -564,6 +567,17 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
self.gate_feature("simd", i.span,
"SIMD types are experimental and possibly buggy");
}

for attr in &i.attrs {
if attr.name() == "repr" {
for item in attr.meta_item_list().unwrap_or(&[]) {
if item.name() == "packed" {
self.gate_feature("repr_packed", item.span,
"packed types are experimental and buggy");
}
}
}
}
}

ast::ItemDefaultImpl(..) => {
Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

#[repr(packed)]
pub struct S {
a: u8,
Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/feature-gate-repr-packed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015 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.


#[repr(packed)] //~ ERROR packed types are experimental
struct Foo { x: u8 }
#[repr(packed, C)] //~ ERROR packed types are experimental
struct Bar { x: u8 }
#[repr(C, packed)] //~ ERROR packed types are experimental
struct Baz { x: u8 }

fn main() {}
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-14309.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]
#![deny(improper_ctypes)]
#![allow(dead_code)]

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/packed-struct-generic-transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/packed-struct-transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down
1 change: 1 addition & 0 deletions src/test/debuginfo/c-style-enum-in-composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

#![allow(unused_variables)]
#![omit_gdb_pretty_printer_section]
#![feature(repr_packed)]

use self::AnEnum::{OneHundred, OneThousand, OneMillion};
use self::AnotherEnum::{MountainView, Toronto, Vienna};
Expand Down
1 change: 1 addition & 0 deletions src/test/debuginfo/packed-struct-with-destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

#![allow(unused_variables)]
#![omit_gdb_pretty_printer_section]
#![feature(repr_packed)]

#[repr(packed)]
struct Packed {
Expand Down
1 change: 1 addition & 0 deletions src/test/debuginfo/packed-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

#![allow(unused_variables)]
#![omit_gdb_pretty_printer_section]
#![feature(repr_packed)]

#[repr(packed)]
struct Packed {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-make/extern-fn-with-packed-struct/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

#[repr(packed)]
#[derive(Copy, Clone, PartialEq, Debug)]
struct Foo {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-26646.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]
#![deny(unused_attributes)]

#[repr(C)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/packed-struct-borrow-element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.


#![feature(repr_packed)]

#[repr(packed)]
struct Foo {
bar: u8,
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/packed-struct-generic-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.


#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/packed-struct-generic-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

use std::mem;

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/packed-struct-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

use std::mem;

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/packed-struct-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

#[repr(packed)]
struct Foo {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/packed-struct-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.


#![feature(repr_packed)]

use std::mem;

Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/packed-struct-vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/packed-tuple-struct-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.


#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/packed-tuple-struct-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@



#![feature(repr_packed)]

use std::mem;

#[repr(packed)]
Expand Down

0 comments on commit 7a265c6

Please sign in to comment.