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

False positive with usize cast from &mut [T; n] to &mut [T] #717

Open
nilehmann opened this issue Aug 15, 2024 · 1 comment
Open

False positive with usize cast from &mut [T; n] to &mut [T] #717

nilehmann opened this issue Aug 15, 2024 · 1 comment

Comments

@nilehmann
Copy link
Member

nilehmann commented Aug 15, 2024

The following code fails to verify

pub fn test() -> [u8; 4] {
    let mut b = [1, 2, 3, 4];
    b.reverse();
    b
}

The problem is that the default signature we generate for reverse is fn(&mut ∃v. [T][v]) which cannot guarantee the length of the slice doesn't change (the length of a slice cannot change but the type can't guarantee it). Since we are casting &mut [T; n] to &mut [T][n] the call to reverse fails because &mut [T][n] is not a subtype of &mut ∃v. [T][v].

@ranjitjhala ranjitjhala changed the title False negative with usize cast from &mut [T; n] to &mut [T] False positive with usize cast from &mut [T; n] to &mut [T] Aug 17, 2024
@ranjitjhala
Copy link
Contributor

ranjitjhala commented Aug 17, 2024

(editing title as FP is more commonly used for things that are safe but reported as unsafe; FN would be if we missed a bug...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants