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

Iterator is needlessly a language item #30803

Closed
nagisa opened this issue Jan 9, 2016 · 8 comments
Closed

Iterator is needlessly a language item #30803

nagisa opened this issue Jan 9, 2016 · 8 comments

Comments

@nagisa
Copy link
Member

nagisa commented Jan 9, 2016

Iterator language item has been removed a year ago, but trait Iterator still has #[lang = "iterator"] on it. That’s not necessary and can be removed.

@apasel422
Copy link
Contributor

Shouldn't both IntoIterator and Iterator be language items?

@GuillaumeGomez
Copy link
Member

@apasel422: Seems more logical to remove it if it's not needed anymore than the contrary.

@apasel422
Copy link
Contributor

My reasoning is that for depends on both traits (plus Option). Compiling this:

#![feature(lang_items)]
#![feature(no_core)]

#![crate_type = "lib"]

#![no_std]
#![no_core]

#[lang = "sized"]
trait Sized {}

pub fn foo() {
    for _ in () {
    }
}

yields

foo.rs:13:5: 13:9 error: failed to resolve. Maybe a missing `extern crate iter`? [E0433]
foo.rs:13     for _ in () {
              ^~~~
foo.rs:13:5: 13:9 help: run `rustc --explain E0433` to see a detailed explanation
foo.rs:13:5: 14:6 error: unresolved name `iter::IntoIterator::into_iter` [E0425]
foo.rs:13     for _ in () {
foo.rs:14     }
foo.rs:13:5: 14:6 help: run `rustc --explain E0425` to see a detailed explanation
foo.rs:13:5: 13:9 error: failed to resolve. Maybe a missing `extern crate iter`? [E0433]
foo.rs:13     for _ in () {
              ^~~~
foo.rs:13:5: 13:9 help: run `rustc --explain E0433` to see a detailed explanation
foo.rs:13:5: 14:6 error: unresolved name `iter::Iterator::next` [E0425]
foo.rs:13     for _ in () {
foo.rs:14     }
foo.rs:13:5: 14:6 help: run `rustc --explain E0425` to see a detailed explanation
foo.rs:13:5: 14:6 error: unresolved enum variant, struct or const `Some` [E0419]
foo.rs:13     for _ in () {
foo.rs:14     }
foo.rs:13:5: 14:6 help: run `rustc --explain E0419` to see a detailed explanation
foo.rs:13:5: 14:6 error: unresolved enum variant, struct or const `None` [E0419]
foo.rs:13     for _ in () {
foo.rs:14     }

@GuillaumeGomez
Copy link
Member

Then why IntoIterator has been removed from language items?

@durka
Copy link
Contributor

durka commented Jan 10, 2016

I think I agree with @apasel422... when for loops are desugared the absolute path to IntoIterator is used by name, but it seems like it would be more robust to use a lang item (cc #30809).

@nagisa
Copy link
Member Author

nagisa commented Jan 10, 2016

Shouldn't both IntoIterator and Iterator be language items?

I generally would agree, but making them language items would be a breaking change of sorts and discussion towards that effect should be through a RFC. Removing the #[lang="iterator"] attribute now (i.e. cleanup of the libcore) and (re-)introducing Iterator and IntoIterator language items later (so the for-loop desugaring is more resilient) are not mutually exclusive goals and the former can easily land today, without waiting for the RFC or its outcome.

@apasel422
Copy link
Contributor

@nagisa Proposed in rust-lang/rfcs#1457.

@alexcrichton
Copy link
Member

I think it'd be fine to add these as language items to improve error messages, but in the meantime it seems fine to remove the annotation if they're not used in the compiler currently (e.g. we can add it back very easily at any point in the future)

nagisa added a commit to nagisa/rust that referenced this issue Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants