Skip to content

Support Index lang item #975

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

Closed
philberty opened this issue Feb 24, 2022 · 0 comments · Fixed by #974
Closed

Support Index lang item #975

philberty opened this issue Feb 24, 2022 · 0 comments · Fixed by #974
Assignees

Comments

@philberty
Copy link
Member

Index lang items are required before we can implement slices support properly.

[lang = "index"]
trait Index<Idx> {
    type Output;

    fn index(&self, index: Idx) -> &Self::Output;
}

struct Foo(i32, i32);
impl Index<isize> for Foo {
    type Output = i32;

    fn index(&self, index: isize) -> &i32 {
        if index == 0 {
            &self.0
        } else {
            &self.1
        }
    }
}

fn main() -> i32 {
    let a = Foo(1, 2);
    let b = a[0];
    let c = a[1];

    c - b - 1
}
@philberty philberty added this to the Macro Expansion milestone Feb 24, 2022
@philberty philberty self-assigned this Feb 24, 2022
bors bot added a commit that referenced this issue Feb 25, 2022
974: Add support for  ranges and index lang items  along with the TyTy::SliceType r=philberty a=philberty

This PR contains more code to begin supporting Slices which requires support
for more intrinsic, range and index lang items. More work is needed to support
slices such as the const_ptr lang item and the offset intrinsic but this is a big
PR already and adds support for more lang items along the way.

Fixes #975
Addresses #849 

Co-authored-by: Philip Herron <[email protected]>
@bors bors bot closed this as completed in 22c6bca Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant