Auto merge of #52445 - alexcrichton:wasm-import-module, r=eddyb

rustc: Stabilize #[wasm_import_module] as #[link(...)]

This commit stabilizes the `#[wasm_import_module]` attribute as
`#[link(wasm_import_module = "...")]`. Tracked by #52090 this new directive in
the `#[link]` attribute is used to configured the module name that the imports
are listed with. The WebAssembly specification indicates two utf-8 names are
associated with all imported items, one for the module the item comes from and
one for the item itself. The item itself is configurable in Rust via its
identifier or `#[link_name = "..."]`, but the module name was previously not
configurable and defaulted to `"env"`. This commit ensures that this is also
configurable.

Closes #52090
This commit is contained in:
bors 2018-07-20 06:40:10 +00:00
commit a5097f3d68
16 changed files with 167 additions and 162 deletions

View file

@ -9,12 +9,11 @@
// except according to those terms.
#![crate_type = "cdylib"]
#![feature(wasm_import_module)]
#![deny(warnings)]
extern crate foo;
#[wasm_import_module = "./me"]
#[link(wasm_import_module = "./me")]
extern {
#[link_name = "me_in_dep"]
fn dep();

View file

@ -9,10 +9,9 @@
// except according to those terms.
#![crate_type = "rlib"]
#![feature(wasm_import_module)]
#![deny(warnings)]
#[wasm_import_module = "./dep"]
#[link(wasm_import_module = "./dep")]
extern {
pub fn dep();
}

View file

@ -2,7 +2,9 @@ error[E0458]: unknown kind: `wonderful_unicorn`
--> $DIR/E0458.rs:11:1
|
LL | #[link(kind = "wonderful_unicorn")] extern {} //~ ERROR E0458
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown kind
| ^^^^^^^--------------------------^^
| |
| unknown kind
error[E0459]: #[link(...)] specified without `name = "foo"`
--> $DIR/E0458.rs:11:1

View file

@ -1,15 +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_import_module = "test"] //~ ERROR: experimental
extern {
}
fn main() {}

View file

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

View file

@ -1,8 +1,8 @@
error: `cfg()` must have an argument
--> $DIR/issue-43926.rs:11:1
--> $DIR/issue-43926.rs:11:20
|
LL | #[link(name="foo", cfg())] //~ ERROR `cfg()` must have an argument
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
error: aborting due to previous error

View file

@ -8,13 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(wasm_import_module)]
#[wasm_import_module] //~ ERROR: must be of the form
#[link(name = "...", wasm_import_module)] //~ ERROR: must be of the form
extern {}
#[wasm_import_module = "foo"] //~ ERROR: must only be attached to
fn foo() {}
#[link(name = "...", wasm_import_module(x))] //~ ERROR: must be of the form
extern {}
#[link(name = "...", wasm_import_module())] //~ ERROR: must be of the form
extern {}
fn main() {}

View file

@ -1,14 +1,20 @@
error: must be of the form #[wasm_import_module = "..."]
--> $DIR/wasm-import-module.rs:13:1
error: must be of the form #[link(wasm_import_module = "...")]
--> $DIR/wasm-import-module.rs:11:22
|
LL | #[wasm_import_module] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^^^^
LL | #[link(name = "...", wasm_import_module)] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^
error: must only be attached to foreign modules
--> $DIR/wasm-import-module.rs:16:1
error: must be of the form #[link(wasm_import_module = "...")]
--> $DIR/wasm-import-module.rs:14:22
|
LL | #[wasm_import_module = "foo"] //~ ERROR: must only be attached to
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #[link(name = "...", wasm_import_module(x))] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: must be of the form #[link(wasm_import_module = "...")]
--> $DIR/wasm-import-module.rs:17:22
|
LL | #[link(name = "...", wasm_import_module())] //~ ERROR: must be of the form
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors