Skip to content

Commit 56d71c2

Browse files
committed
Stabilize underscore_const_names.
1 parent 61a60ce commit 56d71c2

9 files changed

+12
-69
lines changed

src/librustc_data_structures/macros.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// A simple static assertion macro.
22
#[macro_export]
3-
#[allow_internal_unstable(type_ascription, underscore_const_names)]
3+
#[cfg_attr(stage0, allow_internal_unstable(type_ascription, underscore_const_names))]
4+
#[cfg_attr(not(stage0), allow_internal_unstable(type_ascription))]
45
macro_rules! static_assert {
56
($test:expr) => {
67
// Use the bool to access an array such that if the bool is false, the access
@@ -12,7 +13,7 @@ macro_rules! static_assert {
1213

1314
/// Type size assertion. The first argument is a type and the second argument is its expected size.
1415
#[macro_export]
15-
#[allow_internal_unstable(underscore_const_names)]
16+
#[cfg_attr(stage0, allow_internal_unstable(underscore_const_names))]
1617
macro_rules! static_assert_size {
1718
($ty:ty, $size:expr) => {
1819
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];

src/libsyntax/feature_gate.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::source_map::Spanned;
2525
use crate::edition::{ALL_EDITIONS, Edition};
2626
use crate::visit::{self, FnKind, Visitor};
2727
use crate::parse::{token, ParseSess};
28-
use crate::symbol::{Symbol, kw, sym};
28+
use crate::symbol::{Symbol, sym};
2929
use crate::tokenstream::TokenTree;
3030

3131
use errors::{Applicability, DiagnosticBuilder, Handler};
@@ -526,9 +526,6 @@ declare_features! (
526526
// Allows `impl Trait` in bindings (`let`, `const`, `static`).
527527
(active, impl_trait_in_bindings, "1.30.0", Some(34511), None),
528528

529-
// Allows `const _: TYPE = VALUE`.
530-
(active, underscore_const_names, "1.31.0", Some(54912), None),
531-
532529
// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
533530
(active, lint_reasons, "1.31.0", Some(54503), None),
534531

@@ -843,6 +840,8 @@ declare_features! (
843840
// Allows using `#[repr(align(X))]` on enums with equivalent semantics
844841
// to wrapping an enum in a wrapper struct with `#[repr(align(X))]`.
845842
(accepted, repr_align_enum, "1.37.0", Some(57996), None),
843+
// Allows `const _: TYPE = VALUE`.
844+
(accepted, underscore_const_names, "1.37.0", Some(54912), None),
846845

847846
// -------------------------------------------------------------------------
848847
// feature-group-end: accepted features
@@ -1992,13 +1991,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
19921991

19931992
fn visit_item(&mut self, i: &'a ast::Item) {
19941993
match i.node {
1995-
ast::ItemKind::Const(_,_) => {
1996-
if i.ident.name == kw::Underscore {
1997-
gate_feature_post!(&self, underscore_const_names, i.span,
1998-
"naming constants with `_` is unstable");
1999-
}
2000-
}
2001-
20021994
ast::ItemKind::ForeignMod(ref foreign_module) => {
20031995
self.check_abi(foreign_module.abi, i.span);
20041996
}

src/test/ui/consts/const_short_circuit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(underscore_const_names)]
2-
31
const _: bool = false && false;
42
const _: bool = true && false;
53
const _: bool = {

src/test/ui/consts/const_short_circuit.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: new features like let bindings are not permitted in constants which also use short circuiting operators
2-
--> $DIR/const_short_circuit.rs:6:9
2+
--> $DIR/const_short_circuit.rs:4:9
33
|
44
LL | let mut x = true && false;
55
| ^^^^^
66
|
77
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.
8-
--> $DIR/const_short_circuit.rs:6:22
8+
--> $DIR/const_short_circuit.rs:4:22
99
|
1010
LL | let mut x = true && false;
1111
| ^^
1212

1313
error: new features like let bindings are not permitted in constants which also use short circuiting operators
14-
--> $DIR/const_short_circuit.rs:11:9
14+
--> $DIR/const_short_circuit.rs:9:9
1515
|
1616
LL | let x = true && false;
1717
| ^
1818
|
1919
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.
20-
--> $DIR/const_short_circuit.rs:11:18
20+
--> $DIR/const_short_circuit.rs:9:18
2121
|
2222
LL | let x = true && false;
2323
| ^^

src/test/ui/underscore_const_names.rs renamed to src/test/ui/consts/underscore_const_names.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// compile-pass
22

3-
#![feature(underscore_const_names)]
3+
#![deny(unused)]
44

55
trait Trt {}
6-
struct Str {}
6+
pub struct Str {}
77
impl Trt for Str {}
88

99
macro_rules! check_impl {
@@ -17,7 +17,6 @@ macro_rules! check_impl {
1717
}
1818
}
1919

20-
#[deny(unused)]
2120
const _ : () = ();
2221

2322
const _ : i32 = 42;

src/test/ui/feature-gates/feature-gate-underscore_const_names.rs

-14
This file was deleted.

src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr

-18
This file was deleted.

src/test/ui/feature-gates/underscore_const_names_feature_gate.rs

-3
This file was deleted.

src/test/ui/feature-gates/underscore_const_names_feature_gate.stderr

-12
This file was deleted.

0 commit comments

Comments
 (0)