You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A list comprehension over a Rust-interop iterator typechecks, but emits .iter() on a value that consumes itself, so the generated Rust does not compile.
std::env::Args is an Iterator by value. It has no iter() method. The comprehension lowers as though the source were a collection.
Reproduction steps
from rust::std::env import args
pub def main() -> None:
arguments: list[str] = [argument for argument in args()]
println(f"{len(arguments)}")
A plain for loop over the same value lowers correctly, which is the workaround:
mut arguments: list[str] = []
for argument in args():
arguments.append(argument)
Output / logs
error[E0599]: no method named `iter` found for struct `Args` in the current scope
--> src/main.rs:91:10
|
90 | let arguments: Vec<String> = (args())
| __________________________________-
91 | | .iter()
| |_________-^^^^
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Iterable` defines an item `iter`, perhaps you need to implement it
Environment
Compiler built from 0.6.0-dev.4 at 0a8395835
Stage: emission (comprehension lowering over a rust:: interop iterator)
Impact: blocks incan oven bake for any component whose entrypoint reads process arguments this way, and therefore blocks incan test for that component. The for-loop form above is a semantically identical workaround and is what the affected source now does, marked with a TODO.
Note the asymmetry: for x in args() lowers correctly while [x for x in args()] does not, so the two forms disagree on what an interop iterator is.
Area
Compiler (frontend/backend/codegen)
Summary
A list comprehension over a Rust-interop iterator typechecks, but emits
.iter()on a value that consumes itself, so the generated Rust does not compile.std::env::Argsis anIteratorby value. It has noiter()method. The comprehension lowers as though the source were a collection.Reproduction steps
A plain
forloop over the same value lowers correctly, which is the workaround:Output / logs
Environment
0.6.0-dev.4at0a8395835rust::interop iterator)incan oven bakefor any component whose entrypoint reads process arguments this way, and therefore blocksincan testfor that component. Thefor-loop form above is a semantically identical workaround and is what the affected source now does, marked with aTODO.for x in args()lowers correctly while[x for x in args()]does not, so the two forms disagree on what an interop iterator is.workspaces/ovenwhile making its test suite runnable (feature - RFC 119 native Rust facets and direct-rustc planning #1037, PR chore - retain the Incan-authored Oven control plane (#1037) #1487).