Code compiles on playground but fails when passed via stdin to rustc
Rust Internals [Unofficial]
June 11, 2026
I've run into the following very strange behaviour and am unsure whether it's some kind of weird bug that I should report or a subtle mistake on my part.
The following code compiles and runs fine on playground (as does an equivalent test locally)
#![allow(stable_features)]
#![allow(unused)]
#![feature(iterator_try_collect)]
fn main() {
let foo: Option<Vec<_>> = [Some(1)].into_iter().try_collect();
assert_eq!(foo.unwrap().len(), 1);
}
but when passed via stdin to rustc --crate-name flurb --crate-type=lib --out-dir target/flurb --emit=llvm-ir - it fails with
error[E0277]: the trait bound `&Option<{integer}>: Try` is not satisfied
--> <anon>:5:53
|
5 | let foo: Option<Vec<_>> = [Some(1)].into_iter().try_collect();
| ^^^^^^^^^^^ the nightly-only, unstable trait `Try` is not implemented for `&Option<{integer}>`
|
help: the trait `Try` is implemented for `Option<T>`
--> /opt/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:2767:1
|
2767 | impl<T> const ops::Try for Option<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
Is there a reason for the difference in output from a direct rustc invocation vs a cargo/playground based compilation?
Discussion in the ATmosphere