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

Struct is not considered as "used" despite being passed as a generic when constructing another type. #6172

Open
TomAFrench opened this issue Sep 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@TomAFrench
Copy link
Member

Noticed this in noir-bignum but will add a smaller repro later.

The Test2048Params struct is never constructed within the library and should not be exposed as public:
https://github.com/noir-lang/noir-bignum/blob/910dcbb8c2f07efb45416d267e75fdb3361b5b01/src/bignum_test.nr#L12

However, I would consider the below line as a usage of this struct:
https://github.com/noir-lang/noir-bignum/blob/910dcbb8c2f07efb45416d267e75fdb3361b5b01/src/bignum_test.nr#L366

We should also check to see whether this type is passed as a generic parameter when constructing another type. I imagine that passing it as a generic to a function should also satisfy this check.

@TomAFrench TomAFrench added the bug Something isn't working label Sep 30, 2024
@TomAFrench
Copy link
Member Author

A couple of examples where the LSP doesn't realise that a struct has been constructed:

Usage of std::mem::zeroed() is not considered to construct the Foo struct.

struct Foo {}

fn main() {
    let _: Foo = std::mem::zeroed();
}

This is the case exhibited in noir-bignum. The construction of a Bar doesn't imply the usage of Foo.

struct Foo {}

struct Bar<T>{
    inner: Field
}

fn main() {
    let _: Bar<Foo> = Bar { inner: 0 };
}

Something to note is that Rust disallows this case and requires the usage of the PhantomData type. We could do the same which would ensure that the type is used but would cause annoyances around abi encoding for these types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant