Skip to content

Slice syntax and for loops don't compile in a no_std context #21827

Closed
@sfackler

Description

@sfackler
#![no_std]

extern crate core;

fn foo() {
    [0i32][]
}
test.rs:6:5: 6:8 error: failed to resolve. Maybe a missing `extern crate std`?
test.rs:6     [0i32][]
              ^~~
test.rs:6:5: 6:13 error: `std::ops::RangeFull` does not name a structure
test.rs:6     [0i32][]
              ^~~~~~~~
error: aborting due to 2 previous errors
#![no_std]

extern crate core;

fn foo() {
    let i: &[i32] = &[0i32];
    for _ in i {}
}
test.rs:7:5: 7:8 error: failed to resolve. Maybe a missing `extern crate std`?
test.rs:7     for _ in i {}
              ^~~
test.rs:7:5: 8:2 error: unresolved name `std::iter::IntoIterator::into_iter`
test.rs:7     for _ in i {}
test.rs:8 }
test.rs:7:5: 7:8 error: failed to resolve. Maybe a missing `extern crate std`?
test.rs:7     for _ in i {}
              ^~~
test.rs:7:5: 8:2 error: unresolved name `std::iter::Iterator::next`
test.rs:7     for _ in i {}
test.rs:8 }
test.rs:7:9: 7:12 error: failed to resolve. Maybe a missing `extern crate std`?
test.rs:7     for _ in i {}
                  ^~~
test.rs:7:9: 7:10 error: unresolved enum variant, struct or const `Some`
test.rs:7     for _ in i {}
                  ^
test.rs:7:5: 7:8 error: failed to resolve. Maybe a missing `extern crate std`?
test.rs:7     for _ in i {}
              ^~~
test.rs:7:5: 8:2 error: unresolved enum variant, struct or const `None`
test.rs:7     for _ in i {}
test.rs:8 }
error: aborting due to 8 previous errors

You can work around this by adding a std module to your crate root that reexports things properly, but that's not a great way to get basic language features to work.

Metadata

Metadata

Assignees

Labels

A-syntaxextArea: Syntax extensions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions