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

Lang item invalid code compiles #32033

Closed
GuillaumeGomez opened this issue Mar 4, 2016 · 4 comments
Closed

Lang item invalid code compiles #32033

GuillaumeGomez opened this issue Mar 4, 2016 · 4 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@GuillaumeGomez
Copy link
Member

The following code compiles whereas it shouldn't:

#![feature(lang_items)]

#[lang = "cookie"]
fn cookie() -> ! {
    loop {}
}

#[lang = "cookie"]
fn cookie2() -> ! {
//~^ ERROR: Duplicate lang item found: `cookie`.
//~| NOTE First definition of `cookie` here.
    loop {}
}

fn main() {}

cc @brson
#31957

@GuillaumeGomez
Copy link
Member Author

It seems this issue comes from here. If the lang_item doesn't already exist, the function won't check it.

@nagisa
Copy link
Member

nagisa commented Mar 15, 2016

I’m not sure this is a problem per se. Namely, us not failing hard on unknown lang items allows #![no_std] users to maintain some compatibility between Rust versions. I.e. there’s a few language items that did exist in 1.0 but do not exist anymore. Crate authors can still define these language items unconditionally and enjoy support across more versions.

@GuillaumeGomez
Copy link
Member Author

Hum... At first, I just wanted to check if a local lang item was double defined, but then wondered what was the point to allow them. With this, you can still declare std lang items, but you cannot create new ones. I'm going to wait to have some more opinions before doing anything else.

Thanks @nagisa!

@nagisa nagisa added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 15, 2016
@nagisa
Copy link
Member

nagisa commented Mar 15, 2016

Tagging with T-lang so people won’t miss this.

bors added a commit that referenced this issue Mar 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants