Skip to content

Commit

Permalink
Add tests for #[no_mangle] in impl blocks that looks like generic…
Browse files Browse the repository at this point in the history
… `impl` blocks but are actually not
  • Loading branch information
hyd-dev committed Aug 12, 2021
1 parent db13848 commit 9315a0c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/test/ui/generics/generic-no-mangle.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {}
Expand All @@ -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() {}
27 changes: 27 additions & 0 deletions src/test/ui/generics/generic-no-mangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {}
Expand All @@ -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() {}
6 changes: 3 additions & 3 deletions src/test/ui/generics/generic-no-mangle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,23 @@ 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
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
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
Expand Down

0 comments on commit 9315a0c

Please sign in to comment.