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

size_hint can be malformed from rustc_middle::mir::traversal::Postorder #137919

Closed
scottmcm opened this issue Mar 3, 2025 · 2 comments · Fixed by #138329
Closed

size_hint can be malformed from rustc_middle::mir::traversal::Postorder #137919

scottmcm opened this issue Mar 3, 2025 · 2 comments · Fixed by #138329
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Mar 3, 2025

Spotted with extra checking from 804cf26

size_hint (4, Some(2)) is malformed from iterator rustc_middle::mir::traversal::Postorder collecting into alloc::vec::Vec<rustc_middle::mir::BasicBlock>

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.87 (7a632ba 2025-03-03)

@scottmcm scottmcm added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Mar 3, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2025
@tmiasko tmiasko removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2025
@scottmcm scottmcm self-assigned this Mar 3, 2025
@tmiasko tmiasko added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 3, 2025
@matthiaskrgr
Copy link
Member

should this be a debug assertion? 🤔

@scottmcm
Copy link
Member Author

scottmcm commented Mar 3, 2025

@matthiaskrgr I definitely want to check in some form of checking this!

Probably as debug_assert, like you said. Not sure where would be best in the library; I'm tempted to try putting it in Iterator::collect, for example.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2025
…<try>

Simplify `<Postorder as Iterator>::size_hint`

The current version is sometimes malformed (cc rust-lang#137919); let's see if we can get away with a loose but trivially-correct one.
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 4, 2025
…<try>

Simplify `<Postorder as Iterator>::size_hint`

The current version is sometimes malformed (cc rust-lang#137919); let's see if we can get away with a loose but trivially-correct one.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 4, 2025
…r=tmiasko

Simplify `<Postorder as Iterator>::size_hint`

The current version is sometimes malformed (cc rust-lang#137919); let's see if we can get away with a loose but trivially-correct one.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 5, 2025
…r=tmiasko

Simplify `<Postorder as Iterator>::size_hint`

The current version is sometimes malformed (cc rust-lang#137919); let's see if we can get away with a loose but trivially-correct one.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 5, 2025
Rollup merge of rust-lang#137923 - scottmcm:fix-postorder-size-hint, r=tmiasko

Simplify `<Postorder as Iterator>::size_hint`

The current version is sometimes malformed (cc rust-lang#137919); let's see if we can get away with a loose but trivially-correct one.
@bors bors closed this as completed in 01bc954 Mar 16, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 16, 2025
Rollup merge of rust-lang#138329 - scottmcm:assert-hint, r=Mark-Simulacrum

debug-assert that the size_hint is well-formed in `collect`

Closes rust-lang#137919

In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones rust-lang#137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`.

There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 19, 2025
…acrum

debug-assert that the size_hint is well-formed in `collect`

Closes rust-lang#137919

In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones rust-lang#137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`.

There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants