7

fix overflow during type inference for tuple struct patterns by lowr · Pull Requ...

 2 years ago
source link: https://github.com/rust-lang/rust-analyzer/pull/12409
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Contributor

@lowr lowr commented 4 days ago

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK