Skip to content

Commit 9315a0c

Browse files
author
hyd-dev
committed
Add tests for #[no_mangle] in impl blocks that looks like generic impl blocks but are actually not
1 parent db13848 commit 9315a0c

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/test/ui/generics/generic-no-mangle.fixed

+27
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ impl<T> Bar<T> {
8989
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
9090
}
9191

92+
impl Bar<i32> {
93+
#[no_mangle]
94+
pub fn qux() {}
95+
}
96+
9297
trait Trait3 {
9398
fn foo();
9499
extern "C" fn bar();
@@ -121,6 +126,14 @@ trait Trait4 {
121126
fn bar<'a>(x: &'a i32) -> &i32;
122127
}
123128

129+
impl Trait4 for Bar<i32> {
130+
#[no_mangle]
131+
fn foo() {}
132+
133+
#[no_mangle]
134+
fn bar<'b>(x: &'b i32) -> &i32 { x }
135+
}
136+
124137
impl<'a> Trait4 for Baz<'a> {
125138
#[no_mangle]
126139
fn foo() {}
@@ -129,4 +142,18 @@ impl<'a> Trait4 for Baz<'a> {
129142
fn bar<'b>(x: &'b i32) -> &i32 { x }
130143
}
131144

145+
trait Trait5<T> {
146+
fn foo();
147+
}
148+
149+
impl Trait5<i32> for Foo {
150+
#[no_mangle]
151+
fn foo() {}
152+
}
153+
154+
impl Trait5<i32> for Bar<i32> {
155+
#[no_mangle]
156+
fn foo() {}
157+
}
158+
132159
fn main() {}

src/test/ui/generics/generic-no-mangle.rs

+27
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ impl<T> Bar<T> {
8989
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
9090
}
9191

92+
impl Bar<i32> {
93+
#[no_mangle]
94+
pub fn qux() {}
95+
}
96+
9297
trait Trait3 {
9398
fn foo();
9499
extern "C" fn bar();
@@ -121,6 +126,14 @@ trait Trait4 {
121126
fn bar<'a>(x: &'a i32) -> &i32;
122127
}
123128

129+
impl Trait4 for Bar<i32> {
130+
#[no_mangle]
131+
fn foo() {}
132+
133+
#[no_mangle]
134+
fn bar<'b>(x: &'b i32) -> &i32 { x }
135+
}
136+
124137
impl<'a> Trait4 for Baz<'a> {
125138
#[no_mangle]
126139
fn foo() {}
@@ -129,4 +142,18 @@ impl<'a> Trait4 for Baz<'a> {
129142
fn bar<'b>(x: &'b i32) -> &i32 { x }
130143
}
131144

145+
trait Trait5<T> {
146+
fn foo();
147+
}
148+
149+
impl Trait5<i32> for Foo {
150+
#[no_mangle]
151+
fn foo() {}
152+
}
153+
154+
impl Trait5<i32> for Bar<i32> {
155+
#[no_mangle]
156+
fn foo() {}
157+
}
158+
132159
fn main() {}

src/test/ui/generics/generic-no-mangle.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,23 @@ LL | pub fn baz<U>() {}
117117
| ^^^^^^^^^^^^^^^^^^
118118

119119
error: functions generic over types or consts must be mangled
120-
--> $DIR/generic-no-mangle.rs:100:5
120+
--> $DIR/generic-no-mangle.rs:105:5
121121
|
122122
LL | #[no_mangle]
123123
| ------------ help: remove this attribute
124124
LL | fn foo() {}
125125
| ^^^^^^^^^^^
126126

127127
error: functions generic over types or consts must be mangled
128-
--> $DIR/generic-no-mangle.rs:103:5
128+
--> $DIR/generic-no-mangle.rs:108:5
129129
|
130130
LL | #[no_mangle]
131131
| ------------ help: remove this attribute
132132
LL | extern "C" fn bar() {}
133133
| ^^^^^^^^^^^^^^^^^^^^^^
134134

135135
error: functions generic over types or consts must be mangled
136-
--> $DIR/generic-no-mangle.rs:106:5
136+
--> $DIR/generic-no-mangle.rs:111:5
137137
|
138138
LL | #[no_mangle]
139139
| ------------ help: remove this attribute

0 commit comments

Comments
 (0)