Auto merge of #52353 - alexcrichton:wasm-custom-section, r=eddyb

rustc: Use link_section, not wasm_custom_section

This commit transitions definitions of custom sections on the wasm target from
the unstable `#[wasm_custom_section]` attribute to the
already-stable-for-other-targets `#[link_section]` attribute. Mostly the same
restrictions apply as before, except that this now applies only to statics.

Closes #51088
This commit is contained in:
bors 2018-07-18 03:05:27 +00:00
commit cd5f5a129f
26 changed files with 148 additions and 329 deletions

View file

@ -15,7 +15,7 @@
#![feature(rustc_attrs)]
#![crate_type = "rlib"]
#![rustc_partition_codegened(module="issue_49595-tests", cfg="cfail2")]
#![rustc_partition_codegened(module="issue_49595-__test", cfg="cfail2")]
#![rustc_partition_codegened(module="issue_49595-lit_test", cfg="cfail3")]
mod tests {

View file

@ -14,11 +14,11 @@
extern crate foo;
#[wasm_custom_section = "foo"]
const A: [u8; 2] = [5, 6];
#[link_section = "foo"]
pub static A: [u8; 2] = [5, 6];
#[wasm_custom_section = "baz"]
const B: [u8; 2] = [7, 8];
#[link_section = "baz"]
pub static B: [u8; 2] = [7, 8];
#[no_mangle]
pub extern fn foo() {}

View file

@ -12,8 +12,8 @@
#![feature(wasm_custom_section)]
#![deny(warnings)]
#[wasm_custom_section = "foo"]
const A: [u8; 2] = [1, 2];
#[link_section = "foo"]
pub static A: [u8; 2] = [1, 2];
#[wasm_custom_section = "bar"]
const B: [u8; 2] = [3, 4];
#[link_section = "bar"]
pub static B: [u8; 2] = [3, 4];

View file

@ -1,14 +0,0 @@
// Copyright 2018 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.
#[wasm_custom_section = "foo"] //~ ERROR: attribute is currently unstable
const A: [u8; 2] = [1, 2];
fn main() {}

View file

@ -1,11 +0,0 @@
error[E0658]: attribute is currently unstable (see issue #51088)
--> $DIR/feature-gate-wasm_custom_section.rs:11:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: attribute is currently unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(wasm_custom_section)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -8,12 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(wasm_custom_section)]
// only-wasm32
#[wasm_custom_section] //~ ERROR: must be of the form
const A: [u8; 1] = [0];
#[link_section = "test"]
pub static A: &[u8] = &[1]; //~ ERROR: no extra levels of indirection
#[wasm_custom_section(foo)] //~ ERROR: must be of the form
const B: [u8; 1] = [0];
#[link_section = "test"]
pub static B: [u8; 3] = [1, 2, 3];
fn main() {}
#[link_section = "test"]
pub static C: usize = 3;
#[link_section = "test"]
pub static D: &usize = &C; //~ ERROR: no extra levels of indirection

View file

@ -0,0 +1,19 @@
error[E0601]: `main` function not found in crate `wasm_custom_section_relocations`
|
= note: consider adding a `main` function to `$DIR/wasm-custom-section-relocations.rs`
error: statics with a custom `#[link_section]` must be a simple list of bytes on the wasm target with no extra levels of indirection such as references
--> $DIR/wasm-custom-section-relocations.rs:14:1
|
LL | pub static A: &[u8] = &[1]; //~ ERROR: no extra levels of indirection
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: statics with a custom `#[link_section]` must be a simple list of bytes on the wasm target with no extra levels of indirection such as references
--> $DIR/wasm-custom-section-relocations.rs:23:1
|
LL | pub static D: &usize = &C; //~ ERROR: no extra levels of indirection
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0601`.

View file

@ -1,14 +0,0 @@
error: must be of the form #[wasm_custom_section = "foo"]
--> $DIR/malformed.rs:13:1
|
LL | #[wasm_custom_section] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^^^^^
error: must be of the form #[wasm_custom_section = "foo"]
--> $DIR/malformed.rs:16:1
|
LL | #[wasm_custom_section(foo)] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -1,29 +0,0 @@
// Copyright 2018 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.
#![feature(wasm_custom_section)]
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
static A: [u8; 2] = [1, 2];
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
struct B {}
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
enum C {}
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
impl B {}
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
mod d {}
#[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
fn main() {}

View file

@ -1,38 +0,0 @@
error: only allowed on consts
--> $DIR/not-const.rs:13:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: only allowed on consts
--> $DIR/not-const.rs:16:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: only allowed on consts
--> $DIR/not-const.rs:19:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: only allowed on consts
--> $DIR/not-const.rs:22:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: only allowed on consts
--> $DIR/not-const.rs:25:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: only allowed on consts
--> $DIR/not-const.rs:28:1
|
LL | #[wasm_custom_section = "foo"] //~ ERROR: only allowed on consts
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 6 previous errors

View file

@ -1,22 +0,0 @@
// Copyright 2018 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.
#![feature(wasm_custom_section)]
#[wasm_custom_section = "foo"]
const A: u8 = 0; //~ ERROR: must be an array of bytes
#[wasm_custom_section = "foo"]
const B: &[u8] = &[0]; //~ ERROR: must be an array of bytes
#[wasm_custom_section = "foo"]
const C: &[u8; 1] = &[0]; //~ ERROR: must be an array of bytes
fn main() {}

View file

@ -1,20 +0,0 @@
error: must be an array of bytes like `[u8; N]`
--> $DIR/not-slice.rs:14:1
|
LL | const A: u8 = 0; //~ ERROR: must be an array of bytes
| ^^^^^^^^^^^^^^^^
error: must be an array of bytes like `[u8; N]`
--> $DIR/not-slice.rs:17:1
|
LL | const B: &[u8] = &[0]; //~ ERROR: must be an array of bytes
| ^^^^^^^^^^^^^^^^^^^^^^
error: must be an array of bytes like `[u8; N]`
--> $DIR/not-slice.rs:20:1
|
LL | const C: &[u8; 1] = &[0]; //~ ERROR: must be an array of bytes
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors