Skip to content

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

Closed
@dtolnay

Description

@dtolnay

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions