Skip to content

fix overflow during type inference for tuple struct patterns #12409

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

Merged
merged 1 commit into from
May 29, 2022

Conversation

lowr
Copy link
Contributor

@lowr lowr commented May 29, 2022

The following code causes integer overflow during type inference for (malformed) tuple struct patterns.

struct S(usize);
let S(.., a, b) = S(1);

It has been panicking only in debug builds, and working in a way in release builds but it was inconsistent with type inference for tuple patterns:

struct S(usize);
let S(.., a, b) = S(1); // a -> unknown, b -> usize
let (.., a, b) = (1,);  // a -> usize, b -> unknown

With this PR, the overflow no longer happens by utilizing saturating_sub() like in other places and type inference for tuple struct patterns is in line with that for tuple patterns.

@Veykril
Copy link
Member

Veykril commented May 29, 2022

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented May 29, 2022

📌 Commit be2fa2b has been approved by Veykril

@bors
Copy link
Contributor

bors commented May 29, 2022

⌛ Testing commit be2fa2b with merge f94fa62...

@bors
Copy link
Contributor

bors commented May 29, 2022

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing f94fa62 to master...

@bors bors merged commit f94fa62 into rust-lang:master May 29, 2022
@lowr lowr deleted the fix/usize-overflow branch July 3, 2022 09:53
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

Successfully merging this pull request may close these issues.

3 participants