DioxusLabs/dioxus · error

Use `this: &Self` instead of `self`

Error message

Use `this: &Self` instead of `self`

What it means

`from_foreign_fn` requires the receiver-like first argument of a foreign method to be written `this: &SomeType`; this compile error fires when the parameter is named `self` instead. FFI bridges can't use Rust's implicit self, so the first argument must be an explicit `this` reference.

Solutions

  1. Replace the `self` receiver with an explicit `this: &Self` parameter in the FFI function signature.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/manganis/manganis-macro/src/ffi.rs:231 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/a6470593f03c880b. Report an issue: GitHub.

Appendix: source

Thrown at packages/manganis/manganis-macro/src/ffi.rs:231

                    let arg_ty = ForeignType::from_type(&pat_type.ty)?;

                    // Check if first arg is `this: &SomeType`
                    if i == 0
                        && arg_name == "this"
                        && let ForeignType::OpaqueRef(type_name) = &arg_ty
                    {
                        receiver = Some(type_name.clone());
                        continue; // Don't add to args
                    }

                    args.push(ForeignArg {
                        name: arg_name,
                        ty: arg_ty,
                    });
                }
                syn::FnArg::Receiver(_) => {
                    return Err(syn::Error::new(
                        input.span(),
                        "Use `this: &Self` instead of `self`",
                    ));
                }
            }
        }

        let return_type = match &func.sig.output {
            ReturnType::Default => ForeignType::Unit,
            ReturnType::Type(_, ty) => ForeignType::from_type(ty)?,
        };

        Ok(Self {
            name,
            receiver,
            args,
            return_type,
        })

View on GitHub (pinned to 24f6a829df)