Add tests for #[no_mangle] in impl blocks that looks like generic impl blocks but are actually not

This commit is contained in:
hyd-dev 2021-08-13 00:11:44 +08:00
parent db138485b1
commit 9315a0cd4c
No known key found for this signature in database
GPG key ID: 74FA7FD5B8DA14B8
3 changed files with 57 additions and 3 deletions

View file

@ -89,6 +89,11 @@ impl<T> Bar<T> {
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();
@ -121,6 +126,14 @@ trait Trait4 {
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() {}
@ -129,4 +142,18 @@ impl<'a> Trait4 for Baz<'a> {
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() {}

View file

@ -89,6 +89,11 @@ impl<T> Bar<T> {
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();
@ -121,6 +126,14 @@ trait Trait4 {
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() {}
@ -129,4 +142,18 @@ impl<'a> Trait4 for Baz<'a> {
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() {}

View file

@ -117,7 +117,7 @@ LL | pub fn baz<U>() {}
| ^^^^^^^^^^^^^^^^^^
error: functions generic over types or consts must be mangled
--> $DIR/generic-no-mangle.rs:100:5
--> $DIR/generic-no-mangle.rs:105:5
|
LL | #[no_mangle]
| ------------ help: remove this attribute
@ -125,7 +125,7 @@ LL | fn foo() {}
| ^^^^^^^^^^^
error: functions generic over types or consts must be mangled
--> $DIR/generic-no-mangle.rs:103:5
--> $DIR/generic-no-mangle.rs:108:5
|
LL | #[no_mangle]
| ------------ help: remove this attribute
@ -133,7 +133,7 @@ LL | extern "C" fn bar() {}
| ^^^^^^^^^^^^^^^^^^^^^^
error: functions generic over types or consts must be mangled
--> $DIR/generic-no-mangle.rs:106:5
--> $DIR/generic-no-mangle.rs:111:5
|
LL | #[no_mangle]
| ------------ help: remove this attribute