Auto merge of #86492 - hyd-dev:no-mangle-method, r=petrochenkov
Associated functions that contain extern indicator or have `#[rustc_std_internal_symbol]` are reachable
Previously these fails to link with ``undefined reference to `foo'``:
<details>
<summary>Example 1</summary>
```rs
struct AssocFn;
impl AssocFn {
#[no_mangle]
fn foo() {}
}
fn main() {
extern "Rust" {
fn foo();
}
unsafe { foo() }
}
```
([Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f1244afcdd26e2a28445f6e82ca46b50))
</details>
<details>
<summary>Example 2</summary>
```rs
#![crate_name = "lib"]
#![crate_type = "lib"]
struct AssocFn;
impl AssocFn {
#[no_mangle]
fn foo() {}
}
```
```rs
extern crate lib;
fn main() {
extern "Rust" {
fn foo();
}
unsafe { foo() }
}
```
</details>
But I believe they should link successfully, because this works:
<details>
```rs
#[no_mangle]
fn foo() {}
fn main() {
extern "Rust" {
fn foo();
}
unsafe { foo() }
}
```
([Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=789b3f283ee6126f53939429103ed98d))
</details>
This PR fixes the problem, by adding associated functions that have "custom linkage" to `reachable_set`, just like normal functions.
I haven't tested whether #76211 and [Miri](https://github.com/rust-lang/miri/issues/1837) are fixed by this PR yet, but I'm submitting this anyway since this fixes the examples above.
I added a `run-pass` test that combines my two examples above, but I'm not sure if that's the right way to test this. Maybe I should add / modify an existing codegen test (`src/test/codegen/export-no-mangle.rs`?) instead?
This commit is contained in:
commit
5a19ffe1c2
19 changed files with 934 additions and 265 deletions
21
src/test/ui/auxiliary/no-mangle-associated-fn.rs
Normal file
21
src/test/ui/auxiliary/no-mangle-associated-fn.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![crate_type = "lib"]
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Bar {
|
||||
#[no_mangle]
|
||||
fn bar() -> u8 {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
trait Foo {
|
||||
fn baz() -> u8;
|
||||
}
|
||||
|
||||
impl Foo for Bar {
|
||||
#[no_mangle]
|
||||
fn baz() -> u8 {
|
||||
3
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//~ NOTE: not an `extern crate` item
|
||||
//~^ NOTE: not a function or static
|
||||
//~^ NOTE: not a free function, impl method or static
|
||||
//~^^ NOTE: not a function or closure
|
||||
// This is testing whether various builtin attributes signals an
|
||||
// error or warning when put in "weird" places.
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#![no_link]
|
||||
//~^ ERROR: attribute should be applied to an `extern crate` item
|
||||
#![export_name = "2200"]
|
||||
//~^ ERROR: attribute should be applied to a function or static
|
||||
//~^ ERROR: attribute should be applied to a free function, impl method or static
|
||||
#![inline]
|
||||
//~^ ERROR: attribute should be applied to function or closure
|
||||
#[inline]
|
||||
|
|
@ -83,27 +83,37 @@ mod no_link {
|
|||
}
|
||||
|
||||
#[export_name = "2200"]
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
mod export_name {
|
||||
//~^ NOTE not a function or static
|
||||
//~^ NOTE not a free function, impl method or static
|
||||
|
||||
mod inner { #![export_name="2200"] }
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[export_name = "2200"] fn f() { }
|
||||
|
||||
#[export_name = "2200"] struct S;
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[export_name = "2200"] type T = S;
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[export_name = "2200"] impl S { }
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
trait Tr {
|
||||
#[export_name = "2200"] fn foo();
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[export_name = "2200"] fn bar() {}
|
||||
//~^ ERROR attribute should be applied to a free function, impl method or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
}
|
||||
}
|
||||
|
||||
#[start]
|
||||
|
|
|
|||
|
|
@ -17,31 +17,31 @@ LL | #[inline = "2100"] fn f() { }
|
|||
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:1
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119:1
|
||||
|
|
||||
LL | #[start]
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:17
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:122:17
|
||||
|
|
||||
LL | mod inner { #![start] }
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5
|
||||
|
|
||||
LL | #[start] struct S;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:120:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:130:5
|
||||
|
|
||||
LL | #[start] type T = S;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:133:5
|
||||
|
|
||||
LL | #[start] impl S { }
|
||||
| ^^^^^^^^
|
||||
|
|
@ -76,7 +76,7 @@ LL | |
|
|||
LL | | }
|
||||
| |_- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:85:1
|
||||
|
|
||||
LL | #[export_name = "2200"]
|
||||
|
|
@ -87,9 +87,9 @@ LL | |
|
|||
LL | |
|
||||
LL | | mod inner { #![export_name="2200"] }
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_- not a function or static
|
||||
| |_- not a free function, impl method or static
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
|
||||
|
|
@ -97,7 +97,7 @@ error: attribute should be applied to an `extern crate` item
|
|||
LL | #![no_link]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:27:1
|
||||
|
|
||||
LL | #![export_name = "2200"]
|
||||
|
|
@ -199,31 +199,43 @@ error: attribute should be applied to an `extern crate` item
|
|||
LL | #[no_link] impl S { }
|
||||
| ^^^^^^^^^^ ---------- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:90:17
|
||||
|
|
||||
LL | mod inner { #![export_name="2200"] }
|
||||
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
|
||||
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a free function, impl method or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:5
|
||||
|
|
||||
LL | #[export_name = "2200"] struct S;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:100:5
|
||||
|
|
||||
LL | #[export_name = "2200"] type T = S;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:104:5
|
||||
|
|
||||
LL | #[export_name = "2200"] impl S { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a free function, impl method or static
|
||||
|
||||
error: aborting due to 32 previous errors
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:9
|
||||
|
|
||||
LL | #[export_name = "2200"] fn foo();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
|
||||
|
||||
error: attribute should be applied to a free function, impl method or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113:9
|
||||
|
|
||||
LL | #[export_name = "2200"] fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
|
||||
|
||||
error: aborting due to 34 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0518, E0658.
|
||||
For more information about an error, try `rustc --explain E0518`.
|
||||
|
|
|
|||
|
|
@ -295,31 +295,43 @@ mod automatically_derived {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
mod no_mangle {
|
||||
//~^ NOTE not a function or static
|
||||
//~^ NOTE not a free function, impl method or static
|
||||
mod inner { #![no_mangle] }
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[no_mangle] fn f() { }
|
||||
|
||||
#[no_mangle] struct S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[no_mangle] type T = S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[no_mangle] impl S { }
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
trait Tr {
|
||||
#[no_mangle] fn foo();
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a free function, impl method or static
|
||||
|
||||
#[no_mangle] fn bar() {}
|
||||
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a free function, impl method or static
|
||||
}
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -14,4 +14,146 @@ pub fn baz(x: &i32) -> &i32 { x }
|
|||
#[no_mangle]
|
||||
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
|
||||
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub fn baz(x: &i32) -> &i32 { x }
|
||||
|
||||
#[no_mangle]
|
||||
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait1 {
|
||||
fn foo<T>();
|
||||
extern "C" fn bar<T>();
|
||||
fn baz(x: &i32) -> &i32;
|
||||
fn qux<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl Trait1 for Foo {
|
||||
|
||||
fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn baz(x: &i32) -> &i32 { x }
|
||||
|
||||
#[no_mangle]
|
||||
fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait2<T> {
|
||||
fn foo();
|
||||
fn foo2<U>();
|
||||
extern "C" fn bar();
|
||||
fn baz(x: &i32) -> &i32;
|
||||
fn qux<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl<T> Trait2<T> for Foo {
|
||||
|
||||
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
fn foo2<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
pub struct Bar<T>(T);
|
||||
|
||||
impl<T> Bar<T> {
|
||||
|
||||
pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
impl Bar<i32> {
|
||||
#[no_mangle]
|
||||
pub fn qux() {}
|
||||
}
|
||||
|
||||
trait Trait3 {
|
||||
fn foo();
|
||||
extern "C" fn bar();
|
||||
fn baz<U>();
|
||||
}
|
||||
|
||||
impl<T> Trait3 for Bar<T> {
|
||||
|
||||
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
|
||||
fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
pub struct Baz<'a>(&'a i32);
|
||||
|
||||
impl<'a> Baz<'a> {
|
||||
#[no_mangle]
|
||||
pub fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait4 {
|
||||
fn foo();
|
||||
fn bar<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl Trait4 for Bar<i32> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
impl<'a> Trait4 for Baz<'a> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait5<T> {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
impl Trait5<i32> for Foo {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
impl Trait5<i32> for Bar<i32> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -14,4 +14,146 @@ pub fn baz(x: &i32) -> &i32 { x }
|
|||
#[no_mangle]
|
||||
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#[no_mangle]
|
||||
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub fn baz(x: &i32) -> &i32 { x }
|
||||
|
||||
#[no_mangle]
|
||||
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait1 {
|
||||
fn foo<T>();
|
||||
extern "C" fn bar<T>();
|
||||
fn baz(x: &i32) -> &i32;
|
||||
fn qux<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl Trait1 for Foo {
|
||||
#[no_mangle]
|
||||
fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn baz(x: &i32) -> &i32 { x }
|
||||
|
||||
#[no_mangle]
|
||||
fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait2<T> {
|
||||
fn foo();
|
||||
fn foo2<U>();
|
||||
extern "C" fn bar();
|
||||
fn baz(x: &i32) -> &i32;
|
||||
fn qux<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl<T> Trait2<T> for Foo {
|
||||
#[no_mangle]
|
||||
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn foo2<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
pub struct Bar<T>(T);
|
||||
|
||||
impl<T> Bar<T> {
|
||||
#[no_mangle]
|
||||
pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
impl Bar<i32> {
|
||||
#[no_mangle]
|
||||
pub fn qux() {}
|
||||
}
|
||||
|
||||
trait Trait3 {
|
||||
fn foo();
|
||||
extern "C" fn bar();
|
||||
fn baz<U>();
|
||||
}
|
||||
|
||||
impl<T> Trait3 for Bar<T> {
|
||||
#[no_mangle]
|
||||
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
|
||||
#[no_mangle]
|
||||
fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||
}
|
||||
|
||||
pub struct Baz<'a>(&'a i32);
|
||||
|
||||
impl<'a> Baz<'a> {
|
||||
#[no_mangle]
|
||||
pub fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait4 {
|
||||
fn foo();
|
||||
fn bar<'a>(x: &'a i32) -> &i32;
|
||||
}
|
||||
|
||||
impl Trait4 for Bar<i32> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
impl<'a> Trait4 for Baz<'a> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
|
||||
#[no_mangle]
|
||||
fn bar<'b>(x: &'b i32) -> &i32 { x }
|
||||
}
|
||||
|
||||
trait Trait5<T> {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
impl Trait5<i32> for Foo {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
impl Trait5<i32> for Bar<i32> {
|
||||
#[no_mangle]
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -20,5 +20,125 @@ LL | #[no_mangle]
|
|||
LL | pub extern "C" fn bar<T>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:21:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | pub fn foo<T>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:24:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | pub extern "C" fn bar<T>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:42:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn foo<T>() {}
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:45:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | extern "C" fn bar<T>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:64:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:67:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn foo2<U>() {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:70:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | extern "C" fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:73:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn baz(x: &i32) -> &i32 { x }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:76:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn qux<'a>(x: &'a i32) -> &i32 { x }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:83:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | pub fn foo() {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:86:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | pub extern "C" fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:89:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | pub fn baz<U>() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:105:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:108:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | extern "C" fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions generic over types or consts must be mangled
|
||||
--> $DIR/generic-no-mangle.rs:111:5
|
||||
|
|
||||
LL | #[no_mangle]
|
||||
| ------------ help: remove this attribute
|
||||
LL | fn baz<U>() {}
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,11 @@
|
|||
#[no_mangle]
|
||||
pub extern "C" fn SparklingGenerationForeignFunctionInterface() {} // OK
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#[no_mangle]
|
||||
pub extern "C" fn SparklingGenerationForeignFunctionInterface() {} // OK
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -31,9 +31,33 @@ macro_rules! unsafe_in_macro {
|
|||
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function
|
||||
#[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static
|
||||
|
||||
trait AssocFnTrait {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
struct AssocFnFoo;
|
||||
|
||||
impl AssocFnFoo {
|
||||
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` method
|
||||
}
|
||||
|
||||
impl AssocFnTrait for AssocFnFoo {
|
||||
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` method
|
||||
}
|
||||
|
||||
#[export_name = "bar"] fn bar() {} //~ ERROR: declaration of a function with `export_name`
|
||||
#[export_name = "BAR"] static BAR: u32 = 5; //~ ERROR: declaration of a static with `export_name`
|
||||
|
||||
struct AssocFnBar;
|
||||
|
||||
impl AssocFnBar {
|
||||
#[export_name = "bar"] fn bar() {} //~ ERROR: declaration of a method with `export_name`
|
||||
}
|
||||
|
||||
impl AssocFnTrait for AssocFnBar {
|
||||
#[export_name = "bar"] fn foo() {} //~ ERROR: declaration of a method with `export_name`
|
||||
}
|
||||
|
||||
unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function
|
||||
unsafe trait Foo {} //~ ERROR: declaration of an `unsafe` trait
|
||||
unsafe impl Foo for Bar {} //~ ERROR: implementation of an `unsafe` trait
|
||||
|
|
|
|||
|
|
@ -19,8 +19,24 @@ LL | #[no_mangle] static FOO: u32 = 5;
|
|||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a `no_mangle` method
|
||||
--> $DIR/lint-unsafe-code.rs:41:5
|
||||
|
|
||||
LL | #[no_mangle] fn foo() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a `no_mangle` method
|
||||
--> $DIR/lint-unsafe-code.rs:45:5
|
||||
|
|
||||
LL | #[no_mangle] fn foo() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a function with `export_name`
|
||||
--> $DIR/lint-unsafe-code.rs:34:1
|
||||
--> $DIR/lint-unsafe-code.rs:48:1
|
||||
|
|
||||
LL | #[export_name = "bar"] fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -28,61 +44,59 @@ LL | #[export_name = "bar"] fn bar() {}
|
|||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a static with `export_name`
|
||||
--> $DIR/lint-unsafe-code.rs:35:1
|
||||
--> $DIR/lint-unsafe-code.rs:49:1
|
||||
|
|
||||
LL | #[export_name = "BAR"] static BAR: u32 = 5;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a method with `export_name`
|
||||
--> $DIR/lint-unsafe-code.rs:54:5
|
||||
|
|
||||
LL | #[export_name = "bar"] fn bar() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of a method with `export_name`
|
||||
--> $DIR/lint-unsafe-code.rs:58:5
|
||||
|
|
||||
LL | #[export_name = "bar"] fn foo() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
|
||||
|
||||
error: declaration of an `unsafe` function
|
||||
--> $DIR/lint-unsafe-code.rs:37:1
|
||||
--> $DIR/lint-unsafe-code.rs:61:1
|
||||
|
|
||||
LL | unsafe fn baz() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: declaration of an `unsafe` trait
|
||||
--> $DIR/lint-unsafe-code.rs:38:1
|
||||
--> $DIR/lint-unsafe-code.rs:62:1
|
||||
|
|
||||
LL | unsafe trait Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` trait
|
||||
--> $DIR/lint-unsafe-code.rs:39:1
|
||||
--> $DIR/lint-unsafe-code.rs:63:1
|
||||
|
|
||||
LL | unsafe impl Foo for Bar {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: declaration of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:42:5
|
||||
--> $DIR/lint-unsafe-code.rs:66:5
|
||||
|
|
||||
LL | unsafe fn baz(&self);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:43:5
|
||||
--> $DIR/lint-unsafe-code.rs:67:5
|
||||
|
|
||||
LL | unsafe fn provided(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:44:5
|
||||
|
|
||||
LL | unsafe fn provided_override(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:48:5
|
||||
|
|
||||
LL | unsafe fn baz(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:49:5
|
||||
|
|
||||
LL | unsafe fn provided_override(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:68:5
|
||||
|
|
||||
|
|
@ -90,25 +104,43 @@ LL | unsafe fn provided_override(&self) {}
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:79:5
|
||||
--> $DIR/lint-unsafe-code.rs:72:5
|
||||
|
|
||||
LL | unsafe fn baz(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:73:5
|
||||
|
|
||||
LL | unsafe fn provided_override(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:92:5
|
||||
|
|
||||
LL | unsafe fn provided_override(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:103:5
|
||||
|
|
||||
LL | unsafe fn provided(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:85:5
|
||||
--> $DIR/lint-unsafe-code.rs:109:5
|
||||
|
|
||||
LL | unsafe fn provided(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: implementation of an `unsafe` method
|
||||
--> $DIR/lint-unsafe-code.rs:89:5
|
||||
--> $DIR/lint-unsafe-code.rs:113:5
|
||||
|
|
||||
LL | unsafe fn baz(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: usage of an `unsafe` block
|
||||
--> $DIR/lint-unsafe-code.rs:100:5
|
||||
--> $DIR/lint-unsafe-code.rs:124:5
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
|
|
@ -172,5 +204,5 @@ LL | unsafe_in_macro!()
|
|||
|
|
||||
= note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 22 previous errors
|
||||
error: aborting due to 26 previous errors
|
||||
|
||||
|
|
|
|||
37
src/test/ui/no-mangle-associated-fn.rs
Normal file
37
src/test/ui/no-mangle-associated-fn.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// aux-build: no-mangle-associated-fn.rs
|
||||
// run-pass
|
||||
|
||||
extern crate no_mangle_associated_fn;
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#[no_mangle]
|
||||
fn foo() -> u8 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
trait Bar {
|
||||
fn qux() -> u8;
|
||||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
#[no_mangle]
|
||||
fn qux() -> u8 {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
extern "Rust" {
|
||||
fn foo() -> u8;
|
||||
fn bar() -> u8;
|
||||
fn baz() -> u8;
|
||||
fn qux() -> u8;
|
||||
}
|
||||
assert_eq!(unsafe { foo() }, 1);
|
||||
assert_eq!(unsafe { bar() }, 2);
|
||||
assert_eq!(unsafe { baz() }, 3);
|
||||
assert_eq!(unsafe { qux() }, 4);
|
||||
}
|
||||
|
|
@ -1,4 +1,20 @@
|
|||
#[no_mangle]
|
||||
pub fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#[no_mangle]
|
||||
pub fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
|
||||
}
|
||||
|
||||
trait Bar {
|
||||
fn řųśť();
|
||||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
#[no_mangle]
|
||||
fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,18 @@ error[E0754]: `#[no_mangle]` requires ASCII identifier
|
|||
LL | pub fn řųśť() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0754]: `#[no_mangle]` requires ASCII identifier
|
||||
--> $DIR/no_mangle_nonascii_forbidden.rs:8:5
|
||||
|
|
||||
LL | pub fn řųśť() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0754]: `#[no_mangle]` requires ASCII identifier
|
||||
--> $DIR/no_mangle_nonascii_forbidden.rs:17:5
|
||||
|
|
||||
LL | fn řųśť() {}
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0754`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue