diff options
| author | bors <bors@rust-lang.org> | 2024-12-22 16:09:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-12-22 16:09:16 +0000 |
| commit | 303e8bd768526a5812bb1776e798e829ddb7d3ca (patch) | |
| tree | e27cdc97b78197d1bbd29986dfcc4cd9a7d99cca /compiler/rustc_ast/src | |
| parent | b22856d192567a55a1d2788fbc3084e3f9cb220f (diff) | |
| parent | 7d450bbf31d18e868a0bea103792dd73786f6723 (diff) | |
| download | rust-303e8bd768526a5812bb1776e798e829ddb7d3ca.tar.gz rust-303e8bd768526a5812bb1776e798e829ddb7d3ca.zip | |
Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472
Asserts the maximum value that can be returned from `Vec::len`
Currently, casting `Vec<i32>` to `Vec<u32>` takes O(1) time:
```rust
// See <https://godbolt.org/z/hxq3hnYKG> for assembly output.
pub fn cast(vec: Vec<i32>) -> Vec<u32> {
vec.into_iter().map(|e| e as _).collect()
}
```
But the generated assembly is not the same as the identity function, which prevents us from casting `Vec<Vec<i32>>` to `Vec<Vec<u32>>` within O(1) time:
```rust
// See <https://godbolt.org/z/7n48bxd9f> for assembly output.
pub fn cast(vec: Vec<Vec<i32>>) -> Vec<Vec<u32>> {
vec.into_iter()
.map(|e| e.into_iter().map(|e| e as _).collect())
.collect()
}
```
This change tries to fix the problem. You can see the comparison here: <https://godbolt.org/z/jdManrKvx>.
Diffstat (limited to 'compiler/rustc_ast/src')
0 files changed, 0 insertions, 0 deletions
