Repository: dtolnay/cxx (language: rust)

Issue:
Outdated error on signature returning reference without reference arguments
The message *"functions that return a reference must take exactly one input reference"* was accurate only until #608. Now that a signature can be annotated with explicit lifetimes, either a 'static output lifetime would also be fine, or multiple input lifetimes would also be fine.

Current behavior:

```rust
#[cxx::bridge]
mod ffi {
    extern "C++" {
        unsafe fn f() -> &i32;
    }
}
```

```console
error[cxxbridge]: functions that return a reference must take exactly one input reference
  ┌─ src/main.rs:4:16
  │
4 │         unsafe fn f() -> &i32;
  │                ^^^^^^^^^^^^^^^ functions that return a reference must take exactly one input reference
```


Discussion / hints:

Fix patch:
diff --git a/syntax/check.rs b/syntax/check.rs
index 591e53da9..5d02fa82e 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -469,8 +469,6 @@ fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
     if efn.lang == Lang::Cxx {
         check_mut_return_restriction(cx, efn);
     }
-
-    check_multiple_arg_lifetimes(cx, efn);
 }
 
 fn check_api_type_alias(cx: &mut Check, alias: &TypeAlias) {
@@ -564,35 +562,6 @@ fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
     );
 }
 
-fn check_multiple_arg_lifetimes(cx: &mut Check, efn: &ExternFn) {
-    if efn.lang == Lang::Cxx && efn.trusted {
-        return;
-    }
-
-    match &efn.ret {
-        Some(Type::Ref(_)) => {}
-        _ => return,
-    }
-
-    let mut reference_args = 0;
-    for arg in &efn.args {
-        if let Type::Ref(_) = &arg.ty {
-            reference_args += 1;
-        }
-    }
-
-    if efn.receiver.is_some() {
-        reference_args += 1;
-    }
-
-    if reference_args != 1 {
-        cx.error(
-            efn,
-            "functions that return a reference must take exactly one input reference",
-        );
-    }
-}
-
 fn check_reserved_name(cx: &mut Check, ident: &Ident) {
     if ident == "Box"
         || ident == "UniquePtr"


Test patch: