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

Attribute to set edition: #![edition = "2018"] #52817

Closed
dtolnay opened this issue Jul 29, 2018 · 2 comments
Closed

Attribute to set edition: #![edition = "2018"] #52817

dtolnay opened this issue Jul 29, 2018 · 2 comments
Labels
A-rust-2018-preview Area: The 2018 edition preview

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 29, 2018

In bitflags/bitflags#166 working on testing bitflags's support for 2018-style macro imports, I found that it would be very helpful to be able to control the choice of edition at the granularity of individual test files. My understanding is that top-level test files are compiled totally independently so I should be able to use different editions across different files. Cargo's edition setting does not provide the granularity needed.

One possible way to do this would be an #![edition = "..."] attribute, similar to the existing #![crate_type = "..."] attribute which also controls something that would ordinarily be passed in the compiler invocation.

#![edition = "2018"]
#![feature(use_extern_macros)]

use bitflags::bitflags;

bitflags! {
    struct Flags: u32 {
        const A = 0b00000001;
        const B = 0b00000010;
        const C = 0b00000100;
        const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
    }
}

@Manishearth as the implementor of #48014 and #48801 may know whether this is feasible. Are there parsing differences between the editions that would absolutely require passing edition in the compiler invocation rather than picking it up from an attribute?

@Mark-Simulacrum Mark-Simulacrum added the A-rust-2018-preview Area: The 2018 edition preview label Jul 29, 2018
@Mark-Simulacrum
Copy link
Member

I believe we're against #![edition] because it makes parsing etc more complicated; I think the way to do this would be to have Cargo have target-level configuration of editions.

It's worth noting that we'll probably want something similar for rustdoc eventually as well (per-test edition settings).

@dtolnay
Copy link
Member Author

dtolnay commented Jul 29, 2018

Thanks Mark! I'll follow up in Cargo -- rust-lang/cargo#5661.

@dtolnay dtolnay closed this as completed Jul 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust-2018-preview Area: The 2018 edition preview
Projects
None yet
Development

No branches or pull requests

2 participants