Skip to content

Bad type resolution on &[T] vs *const T #1235

@philberty

Description

@philberty

I tried this code:

struct FatPtr<T> {
    data: *const T,
    len: usize,
}

pub union Repr<T> {
    rust: *const [T],
    rust_mut: *mut [T],
    raw: FatPtr<T>,
}

impl<T> [T] {
    pub const fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub const fn len(&self) -> usize {
        unsafe { Repr { rust: self }.raw.len }
    }
}

I expected to see this happen: *compile without error

Instead, this happened:

<source>:18:31: error: expected [* const [T=T?]] got [& [T=T REF: 46]]
    7 |     rust: *const [T],
      |           ~                    
......
   18 |         unsafe { Repr { rust: self }.raw.len }
      |                               ^

see https://godbolt.org/z/KGE8qxzWc

Meta

  • What version of Rust GCC were you using, git sha if possible. 74e8365

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions