rust-lang / rust-lang/rust-clippy
std-instead-of-alloc: there is no `alloc::collections::VecDeque`
Open
Nobody has claimed this yet.
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Using the following flags
--force-warn clippy::std-instead-of-alloc
this code:
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)]
#![allow(clippy::missing_docs_in_private_items, clippy::blanket_clippy_restriction_lints)]
use std::collections::VecDeque;
fn main() {
let mut c: VecDeque<u8> = VecDeque::new();
c.swap(0, 1);
c.push_back(1);
let _ = c[0]; // clippy::indexing_slicing correctly detects possible panic
c.swap(0, 1); // Could cause panic; clippy ignores this line
// c.swap(1, 2); // Example swap panic
}
caused the following diagnostics:
Checking _b4e4b49c96533ac40e3e725c4362a6857c3af18f v0.1.0 (/tmp/icemaker_global_tempdir.gPgWiqot4T9Z/icemaker_clippyfix_tempdir.yqcDcwegV0PK/_b4e4b49c96533ac40e3e725c4362a6857c3af18f)
warning: used import from `std` instead of `alloc`
--> src/main.rs:3:5
|
3 | use std::collections::VecDeque;
| ^^^ help: consider importing the item from `alloc`: `alloc`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc
= note: requested on the command line with `--force-warn clippy::std-instead-of-alloc`
warning: `_b4e4b49c96533ac40e3e725c4362a6857c3af18f` (bin "_b4e4b49c96533ac40e3e725c4362a6857c3af18f") generated 1 warning (run `cargo clippy --fix --bin "_b4e4b49c96533ac40e3e725c4362a6857c3af18f" -p _b4e4b49c96533ac40e3e725c4362a6857c3af18f -- -Aclippy::all -Awarnings --force-warn clippy::std-instead-of-alloc --cap-lints warn` to apply 1 suggestion)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
However after applying these diagnostics, the resulting code:
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)]
#![allow(clippy::missing_docs_in_private_items, clippy::blanket_clippy_restriction_lints)]
use alloc::collections::VecDeque;
fn main() {
let mut c: VecDeque<u8> = VecDeque::new();
c.swap(0, 1);
c.push_back(1);
let _ = c[0]; // clippy::indexing_slicing correctly detects possible panic
c.swap(0, 1); // Could cause panic; clippy ignores this line
// c.swap(1, 2); // Example swap panic
}
no longer compiled:
Checking _b4e4b49c96533ac40e3e725c4362a6857c3af18f v0.1.0 (/tmp/icemaker_global_tempdir.gPgWiqot4T9Z/icemaker_clippyfix_tempdir.yqcDcwegV0PK/_b4e4b49c96533ac40e3e725c4362a6857c3af18f)
error[E0433]: cannot find module or crate `alloc` in this scope
--> src/main.rs:3:5
|
3 | use alloc::collections::VecDeque;
| ^^^^^ use of unresolved module or unlinked crate `alloc`
|
= help: add `extern crate alloc` to use the `alloc` crate
For more information about this error, try `rustc --explain E0433`.
error: could not compile `_b4e4b49c96533ac40e3e725c4362a6857c3af18f` (bin "_b4e4b49c96533ac40e3e725c4362a6857c3af18f") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_b4e4b49c96533ac40e3e725c4362a6857c3af18f` (bin "_b4e4b49c96533ac40e3e725c4362a6857c3af18f" test) due to 1 previous error
Version:
rustc 1.96.0-nightly (e3d66fe39 2026-03-07)
binary: rustc
commit-hash: e3d66fe39ae70380fa2365c008e2927479114844
commit-date: 2026-03-07
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Rust example and the clippy::std-instead-of-alloc lint, then trace the lint's suggestion handling in the Clippy source. Check how the generated import is validated for standard binary crates, and add or update a regression test for the reported VecDeque case. Done means the suggestion does not leave the example uncompilable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100