]> git.lizzy.rs Git - rust.git/blobdiff - src/test/ui/generics/generic-no-mangle.rs
Adjust `#[no_mangle]`-related checks and lints for `impl` items
[rust.git] / src / test / ui / generics / generic-no-mangle.rs
index 146896cdc3d024f66fb42f17352800de86a4a897..83fd4564e91d3ec1800e0d8dbb00c886c57705b4 100644 (file)
@@ -14,4 +14,119 @@ 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
+}
+
+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<'a> Trait4 for Baz<'a> {
+    #[no_mangle]
+    fn foo() {}
+
+    #[no_mangle]
+    fn bar<'b>(x: &'b i32) -> &i32 { x }
+}
+
 fn main() {}