Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclassing doesn't work - "the trait bound T: CppPeerConstructor<TCpp> is not satisfied" #1383

Open
Supreeeme opened this issue Jul 19, 2024 · 1 comment

Comments

@Supreeeme
Copy link

Describe the bug
Subclassing does not compile, with the following error:

error[E0277]: the trait bound `Concrete: CppPeerConstructor<ConcreteCpp>` is not satisfied
   --> src/main.rs:12:12
    |
12  | pub struct Concrete {}
    |            ^^^^^^^^ the trait `CppPeerConstructor<ConcreteCpp>` is not implemented for `Concrete`

To Reproduce
Cargo.toml:

[package]
name = "subclass_test"
version = "0.1.0"
edition = "2021"

[dependencies]
autocxx = "0.27.0"
cxx = "1.0.124"

[build-dependencies]
autocxx-build = "0.27.0"

build.rs:

fn main() {
    autocxx_build::Builder::new("src/main.rs", ["src"])
        .build()
        .unwrap()
        .compile("test");

    println!("cargo:rerun-if-changed=src/main.rs");
    println!("cargo:rerun-if-changed=src/abstract.h");
}

main.rs:

use autocxx::prelude::*;
use autocxx::subclass::prelude::*;

include_cpp! {
    #include "abstract.h"
    generate!("Abstract")
    subclass!("Abstract", Concrete)
}

#[subclass]
#[derive(Default)]
pub struct Concrete {}

impl ffi::Abstract_methods for Concrete {
    unsafe fn func(&self) {}
}

abstract.h:

#pragma once

class Abstract {
public:
	virtual void func() const = 0;
};

Expected behavior
Successful compilation

Additional context
I'm not sure what's going on here - I can compile and run the subclassing example in the repo successfully, but trying to do it from a clean project just does not work.

@Supreeeme Supreeeme changed the title Subclassing doesn't work - "the trait bound T: CppPeerConstructor<ConcreteCpp> is not satisfied" Subclassing doesn't work - "the trait bound T: CppPeerConstructor<TCpp> is not satisfied" Jul 19, 2024
@adetaylor
Copy link
Collaborator

adetaylor commented Sep 8, 2024

I'm afraid I'm not going to have a chance to dig into this - please do gradually bisect differences relative to the demo. Subclass support is fairly fragile and the diagnostics aren't great - I'd be pleased to merge PRs to improve diagnostics here. (Perhaps the new #[diagnostic::on_unimplemented] can be used)

You might also be able to get clues by following these instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants