Stabilize underscore_const_names.
This commit is contained in:
parent
61a60ce7d3
commit
56d71c2910
9 changed files with 12 additions and 69 deletions
|
@ -1,6 +1,7 @@
|
||||||
/// A simple static assertion macro.
|
/// A simple static assertion macro.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[allow_internal_unstable(type_ascription, underscore_const_names)]
|
#[cfg_attr(stage0, allow_internal_unstable(type_ascription, underscore_const_names))]
|
||||||
|
#[cfg_attr(not(stage0), allow_internal_unstable(type_ascription))]
|
||||||
macro_rules! static_assert {
|
macro_rules! static_assert {
|
||||||
($test:expr) => {
|
($test:expr) => {
|
||||||
// Use the bool to access an array such that if the bool is false, the access
|
// Use the bool to access an array such that if the bool is false, the access
|
||||||
|
@ -12,7 +13,7 @@ macro_rules! static_assert {
|
||||||
|
|
||||||
/// Type size assertion. The first argument is a type and the second argument is its expected size.
|
/// Type size assertion. The first argument is a type and the second argument is its expected size.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[allow_internal_unstable(underscore_const_names)]
|
#[cfg_attr(stage0, allow_internal_unstable(underscore_const_names))]
|
||||||
macro_rules! static_assert_size {
|
macro_rules! static_assert_size {
|
||||||
($ty:ty, $size:expr) => {
|
($ty:ty, $size:expr) => {
|
||||||
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
|
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::source_map::Spanned;
|
||||||
use crate::edition::{ALL_EDITIONS, Edition};
|
use crate::edition::{ALL_EDITIONS, Edition};
|
||||||
use crate::visit::{self, FnKind, Visitor};
|
use crate::visit::{self, FnKind, Visitor};
|
||||||
use crate::parse::{token, ParseSess};
|
use crate::parse::{token, ParseSess};
|
||||||
use crate::symbol::{Symbol, kw, sym};
|
use crate::symbol::{Symbol, sym};
|
||||||
use crate::tokenstream::TokenTree;
|
use crate::tokenstream::TokenTree;
|
||||||
|
|
||||||
use errors::{Applicability, DiagnosticBuilder, Handler};
|
use errors::{Applicability, DiagnosticBuilder, Handler};
|
||||||
|
@ -526,9 +526,6 @@ declare_features! (
|
||||||
// Allows `impl Trait` in bindings (`let`, `const`, `static`).
|
// Allows `impl Trait` in bindings (`let`, `const`, `static`).
|
||||||
(active, impl_trait_in_bindings, "1.30.0", Some(34511), None),
|
(active, impl_trait_in_bindings, "1.30.0", Some(34511), None),
|
||||||
|
|
||||||
// Allows `const _: TYPE = VALUE`.
|
|
||||||
(active, underscore_const_names, "1.31.0", Some(54912), None),
|
|
||||||
|
|
||||||
// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
|
// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
|
||||||
(active, lint_reasons, "1.31.0", Some(54503), None),
|
(active, lint_reasons, "1.31.0", Some(54503), None),
|
||||||
|
|
||||||
|
@ -843,6 +840,8 @@ declare_features! (
|
||||||
// Allows using `#[repr(align(X))]` on enums with equivalent semantics
|
// Allows using `#[repr(align(X))]` on enums with equivalent semantics
|
||||||
// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`.
|
// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`.
|
||||||
(accepted, repr_align_enum, "1.37.0", Some(57996), None),
|
(accepted, repr_align_enum, "1.37.0", Some(57996), None),
|
||||||
|
// Allows `const _: TYPE = VALUE`.
|
||||||
|
(accepted, underscore_const_names, "1.37.0", Some(54912), None),
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// feature-group-end: accepted features
|
// feature-group-end: accepted features
|
||||||
|
@ -1992,13 +1991,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
|
|
||||||
fn visit_item(&mut self, i: &'a ast::Item) {
|
fn visit_item(&mut self, i: &'a ast::Item) {
|
||||||
match i.node {
|
match i.node {
|
||||||
ast::ItemKind::Const(_,_) => {
|
|
||||||
if i.ident.name == kw::Underscore {
|
|
||||||
gate_feature_post!(&self, underscore_const_names, i.span,
|
|
||||||
"naming constants with `_` is unstable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ast::ItemKind::ForeignMod(ref foreign_module) => {
|
ast::ItemKind::ForeignMod(ref foreign_module) => {
|
||||||
self.check_abi(foreign_module.abi, i.span);
|
self.check_abi(foreign_module.abi, i.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#![feature(underscore_const_names)]
|
|
||||||
|
|
||||||
const _: bool = false && false;
|
const _: bool = false && false;
|
||||||
const _: bool = true && false;
|
const _: bool = true && false;
|
||||||
const _: bool = {
|
const _: bool = {
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
error: new features like let bindings are not permitted in constants which also use short circuiting operators
|
error: new features like let bindings are not permitted in constants which also use short circuiting operators
|
||||||
--> $DIR/const_short_circuit.rs:6:9
|
--> $DIR/const_short_circuit.rs:4:9
|
||||||
|
|
|
|
||||||
LL | let mut x = true && false;
|
LL | let mut x = true && false;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: use of `&&` operator here does not actually short circuit due to the const evaluator presently not being able to do control flow. See https://github.com/rust-lang/rust/issues/49146 for more information.
|
note: use of `&&` operator here does not actually short circuit due to the const evaluator presently not being able to do control flow. See https://github.com/rust-lang/rust/issues/49146 for more information.
|
||||||
--> $DIR/const_short_circuit.rs:6:22
|
--> $DIR/const_short_circuit.rs:4:22
|
||||||
|
|
|
|
||||||
LL | let mut x = true && false;
|
LL | let mut x = true && false;
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: new features like let bindings are not permitted in constants which also use short circuiting operators
|
error: new features like let bindings are not permitted in constants which also use short circuiting operators
|
||||||
--> $DIR/const_short_circuit.rs:11:9
|
--> $DIR/const_short_circuit.rs:9:9
|
||||||
|
|
|
|
||||||
LL | let x = true && false;
|
LL | let x = true && false;
|
||||||
| ^
|
| ^
|
||||||
|
|
|
|
||||||
note: use of `&&` operator here does not actually short circuit due to the const evaluator presently not being able to do control flow. See https://github.com/rust-lang/rust/issues/49146 for more information.
|
note: use of `&&` operator here does not actually short circuit due to the const evaluator presently not being able to do control flow. See https://github.com/rust-lang/rust/issues/49146 for more information.
|
||||||
--> $DIR/const_short_circuit.rs:11:18
|
--> $DIR/const_short_circuit.rs:9:18
|
||||||
|
|
|
|
||||||
LL | let x = true && false;
|
LL | let x = true && false;
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// compile-pass
|
// compile-pass
|
||||||
|
|
||||||
#![feature(underscore_const_names)]
|
#![deny(unused)]
|
||||||
|
|
||||||
trait Trt {}
|
trait Trt {}
|
||||||
struct Str {}
|
pub struct Str {}
|
||||||
impl Trt for Str {}
|
impl Trt for Str {}
|
||||||
|
|
||||||
macro_rules! check_impl {
|
macro_rules! check_impl {
|
||||||
|
@ -17,7 +17,6 @@ macro_rules! check_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deny(unused)]
|
|
||||||
const _ : () = ();
|
const _ : () = ();
|
||||||
|
|
||||||
const _ : i32 = 42;
|
const _ : i32 = 42;
|
|
@ -1,14 +0,0 @@
|
||||||
trait Trt {}
|
|
||||||
struct Str {}
|
|
||||||
|
|
||||||
impl Trt for Str {}
|
|
||||||
|
|
||||||
const _ : () = {
|
|
||||||
//~^ ERROR is unstable
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
struct ImplementsTrait<T: Trt>(PhantomData<T>);
|
|
||||||
let _ = ImplementsTrait::<Str>(PhantomData);
|
|
||||||
()
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,18 +0,0 @@
|
||||||
error[E0658]: naming constants with `_` is unstable
|
|
||||||
--> $DIR/feature-gate-underscore_const_names.rs:6:1
|
|
||||||
|
|
|
||||||
LL | / const _ : () = {
|
|
||||||
LL | |
|
|
||||||
LL | | use std::marker::PhantomData;
|
|
||||||
LL | | struct ImplementsTrait<T: Trt>(PhantomData<T>);
|
|
||||||
LL | | let _ = ImplementsTrait::<Str>(PhantomData);
|
|
||||||
LL | | ()
|
|
||||||
LL | | };
|
|
||||||
| |__^
|
|
||||||
|
|
|
||||||
= note: for more information, see https://github.com/rust-lang/rust/issues/54912
|
|
||||||
= help: add #![feature(underscore_const_names)] to the crate attributes to enable
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
|
|
@ -1,3 +0,0 @@
|
||||||
const _: () = (); //~ ERROR is unstable
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -1,12 +0,0 @@
|
||||||
error[E0658]: naming constants with `_` is unstable
|
|
||||||
--> $DIR/underscore_const_names_feature_gate.rs:1:1
|
|
||||||
|
|
|
||||||
LL | const _: () = ();
|
|
||||||
| ^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: for more information, see https://github.com/rust-lang/rust/issues/54912
|
|
||||||
= help: add #![feature(underscore_const_names)] to the crate attributes to enable
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
|
Loading…
Add table
Add a link
Reference in a new issue