about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-22 16:09:16 +0000
committerbors <bors@rust-lang.org>2024-12-22 16:09:16 +0000
commit303e8bd768526a5812bb1776e798e829ddb7d3ca (patch)
treee27cdc97b78197d1bbd29986dfcc4cd9a7d99cca /compiler/rustc_ast/src/ast.rs
parentb22856d192567a55a1d2788fbc3084e3f9cb220f (diff)
parent7d450bbf31d18e868a0bea103792dd73786f6723 (diff)
downloadrust-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/ast.rs')
0 files changed, 0 insertions, 0 deletions