Skip to content

Bug nesting const generics  #761

@jorendorff

Description

@jorendorff

The test case below generates broken C code.

// Propagating const arguments through generics that use generics.

#[repr(C)]
struct Inner<N: usize> {
    bytes: [u8; N],
}

#[repr(C)]
struct Outer<N: usize> {
    inner: Inner<N>, // don't declare two different structs named `Inner_N`
}

#[no_mangle]
pub extern "C" fn one() -> Outer<1> {
    Outer { inner: Inner { bytes: [0] } }
}

#[no_mangle]
pub extern "C" fn two() -> Outer<2> {
    Outer { inner: Inner { bytes: [0, 0] } }
}

cargo run -- --lang c --style tag $FILE produces this:

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct Inner_N {
  uint8_t bytes[N];
};

struct Outer_1 {
  struct Inner_N inner;
};

struct Outer_2 {
  struct Inner_N inner;
};

struct Outer_1 one(void);

struct Outer_2 two(void);

The corresponding thing works fine with type parameters, so there must be something I failed to hook up in #759, or maybe we aren't modeling the value namespace at all. Filing the bug because I don't have time to look right now. I should have time in the next few days, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions