Skip to main content

rustc_unicode/
lib.rs

1//! Unified crate for re-exporting Unicode crates for the compiler.
2//! Used to avoid having multiple different Unicode versions in use.
3
4// If this changes, update https://github.com/rust-lang/reference/blob/HEAD/src/identifiers.md.
5// At time of writing, updating this requires a T-lang FCP.
6const UNICODE_VERSION: (u8, u8, u8) = (18, 0, 0);
7
8const _: () = {
9    let (major, minor, patch) = UNICODE_VERSION;
10    let (major_, minor_, patch_) = char::UNICODE_VERSION;
11    if major != major_ || minor != minor_ || patch != patch_ {
12        // For now, upgrades for the Unicode version used by core and the compiler are independent.
13        // Until this changes, the Unicode version in this crate and `char` may diverge by
14        // 1 major version.
15        // Update this const to make this explicit.
16        const VERSIONS_DIFFER: bool = false;
17        if !VERSIONS_DIFFER || major + 1 != major_ {
18            {
    ::core::panicking::panic_fmt(format_args!("rustc_unicode::UNICODE_VERSION does not match char::UNICODE_VERSION"));
}panic!("rustc_unicode::UNICODE_VERSION does not match char::UNICODE_VERSION",)
19        }
20    }
21};
22
23macro_rules! reexport_and_check {
24    ($($krate:ident),+ $(,)?) => {
25        $(
26            pub use $krate;
27            const _: () = {
28                let (major, minor, patch) = UNICODE_VERSION;
29                let (major_, minor_, patch_) = $krate::UNICODE_VERSION;
30                if (
31                    major as u64 != major_ as u64 ||
32                    minor as u64 != minor_ as u64 ||
33                    patch as u64 != patch_ as u64
34                ) {
35                    panic!(
36                        concat!(
37                            stringify!($krate),
38                            " does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"
39                        )
40                    )
41                }
42            };
43        )+
44    }
45}
46
47pub use unicode_ident;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_ident::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_ident does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };
pub use unicode_normalization;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_normalization::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_normalization does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };
pub use unicode_properties;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_properties::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_properties does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };
pub use unicode_script;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_script::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_script does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };
pub use unicode_security;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_security::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_security does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };
pub use unicode_width;
const _: () =
    {
        let (major, minor, patch) = UNICODE_VERSION;
        let (major_, minor_, patch_) = unicode_width::UNICODE_VERSION;
        if (major as u64 != major_ as u64 || minor as u64 != minor_ as u64 ||
                    patch as u64 != patch_ as u64) {
            {
                ::core::panicking::panic_fmt(format_args!("unicode_width does not have the correct Unicode version (`rustc_unicode::UNICODE_VERSION`)"));
            }
        }
    };reexport_and_check!(
48    // tidy-alphabetical-start
49    unicode_ident,
50    unicode_normalization,
51    unicode_properties,
52    unicode_script,
53    unicode_security,
54    unicode_width,
55    // tidy-alphabetical-end
56);