Skip to content

&[!] should have zero size #2754

Closed
Closed
@ssbr

Description

@ssbr

I'm not sure how reasonable this is, but since &[!] can only ever be the empty slice, I was hoping it would be represented the same way as &[!; 0] and (), with zero size and knowledge that it must be empty.

e.g. I was hoping this would become a function taking a parameter of zero size and executing xor eax, eax:

pub fn length_never_slice(x: &[!]) -> usize { x.len() }

I have no real use case except showing off cool tricks with !. Maybe this would be useful in generic code, although at least for simple cases where the actual value can get threaded through, it already optimizes fine. (e.g. a call of length_never_slice(&vec![]) will become a hardcoded constant as one expects.)

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