From 27b703dd409c875853394f9c7f8400cd34390088 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 22 Jul 2019 12:09:34 +0300 Subject: [PATCH 1/2] add rustc_private as a proper language feature gate At the moment, `rustc_private` as a (library) feature exists by accident: `char::is_xid_start`, `char::is_xid_continue` methods in libcore define it. --- src/libcore/char/methods.rs | 19 ++++++++++++------- src/libfmt_macros/lib.rs | 1 + src/librustc_lexer/src/lib.rs | 1 - src/librustdoc/lib.rs | 1 + src/libsyntax/feature_gate.rs | 3 +++ src/libsyntax_ext/lib.rs | 1 + src/test/ui/feature-gate/rustc-private.rs | 5 +++++ src/test/ui/feature-gate/rustc-private.stderr | 12 ++++++++++++ 8 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/feature-gate/rustc-private.rs create mode 100644 src/test/ui/feature-gate/rustc-private.stderr diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index e843303380ad0..99f88591eea3e 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -553,10 +553,12 @@ impl char { /// 'XID_Start' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to `ID_Start` but modified for closure under `NFKx`. - #[unstable(feature = "rustc_private", - reason = "mainly needed for compiler internals", - issue = "27812")] - #[inline] + #[cfg_attr(bootstrap, + unstable(feature = "rustc_private", + reason = "mainly needed for compiler internals", + issue = "27812"))] + #[cfg_attr(not(bootstrap), + unstable(feature = "unicode_internals", issue = "0"))] pub fn is_xid_start(self) -> bool { derived_property::XID_Start(self) } @@ -567,9 +569,12 @@ impl char { /// 'XID_Continue' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. - #[unstable(feature = "rustc_private", - reason = "mainly needed for compiler internals", - issue = "27812")] + #[cfg_attr(bootstrap, + unstable(feature = "rustc_private", + reason = "mainly needed for compiler internals", + issue = "27812"))] + #[cfg_attr(not(bootstrap), + unstable(feature = "unicode_internals", issue = "0"))] #[inline] pub fn is_xid_continue(self) -> bool { derived_property::XID_Continue(self) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 39f130b82ed83..f1c2b1fb87133 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -13,6 +13,7 @@ #![feature(nll)] #![feature(rustc_private)] +#![feature(unicode_internals)] pub use Piece::*; pub use Position::*; diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index a21190ec33244..2d10ac8b0241a 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -1,6 +1,5 @@ // We want to be able to build this crate with a stable compiler, so feature // flags should optional. -#![cfg_attr(not(feature = "unicode-xid"), feature(rustc_private))] #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 58777130b7f29..3627ce6a5aa50 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -21,6 +21,7 @@ #![feature(inner_deref)] #![feature(never_type)] #![feature(mem_take)] +#![feature(unicode_internals)] #![recursion_limit="256"] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6a3f58ec89e19..43f0eaae7c97e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -126,6 +126,9 @@ declare_features! ( // no-tracking-issue-start + // Allows using compiler's own crates. + (active, rustc_private, "1.0.0", Some(27812), None), + // Allows using the `rust-intrinsic`'s "ABI". (active, intrinsics, "1.0.0", None, None), diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index da0f8ca6da090..7de90278ed732 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -12,6 +12,7 @@ #![feature(decl_macro)] #![feature(nll)] #![feature(rustc_diagnostic_macros)] +#![feature(unicode_internals)] #![recursion_limit="256"] diff --git a/src/test/ui/feature-gate/rustc-private.rs b/src/test/ui/feature-gate/rustc-private.rs new file mode 100644 index 0000000000000..7b8944bb0a0b8 --- /dev/null +++ b/src/test/ui/feature-gate/rustc-private.rs @@ -0,0 +1,5 @@ +// gate-test-rustc_private + +extern crate libc; //~ ERROR use of unstable library feature 'rustc_private' + +fn main() {} diff --git a/src/test/ui/feature-gate/rustc-private.stderr b/src/test/ui/feature-gate/rustc-private.stderr new file mode 100644 index 0000000000000..be320718145e0 --- /dev/null +++ b/src/test/ui/feature-gate/rustc-private.stderr @@ -0,0 +1,12 @@ +error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? + --> $DIR/rustc-private.rs:3:1 + | +LL | extern crate libc; + | ^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/27812 + = help: add `#![feature(rustc_private)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From 7e612c19bee19b41796e8a4f4fe8a41714d7b3c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jul 2019 10:38:18 +0300 Subject: [PATCH 2/2] Update src/librustc_lexer/src/lib.rs Co-Authored-By: Ralf Jung --- src/librustc_lexer/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index 2d10ac8b0241a..244e837364adb 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -1,5 +1,5 @@ // We want to be able to build this crate with a stable compiler, so feature -// flags should optional. +// flags should be optional. #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor;