Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 42b1406

Browse files
Make allow_internal_unstable work with stmt_expr_attributes
1 parent a395214 commit 42b1406

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

compiler/rustc_expand/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ impl<'a> StripUnconfigured<'a> {
449449
/// If attributes are not allowed on expressions, emit an error for `attr`
450450
#[instrument(level = "trace", skip(self))]
451451
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
452-
if self.features.is_some_and(|features| !features.stmt_expr_attributes) {
452+
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
453+
&& !attr.span.allows_unstable(sym::stmt_expr_attributes)
454+
{
453455
let mut err = feature_err(
454456
&self.sess.parse_sess,
455457
sym::stmt_expr_attributes,

tests/ui/internal/internal-unstable.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ macro_rules! bar {
2828
}}
2929
}
3030

31+
#[allow_internal_unstable(stmt_expr_attributes)]
32+
macro_rules! internal_attr {
33+
($e: expr) => {
34+
#[allow(overflowing_literals)]
35+
$e
36+
}
37+
}
38+
3139
fn main() {
3240
// ok, the instability is contained.
3341
call_unstable_allow!();
@@ -51,4 +59,6 @@ fn main() {
5159
#[allow_internal_unstable]
5260
_ => {}
5361
}
62+
63+
assert_eq!(internal_attr!(1e100_f32), f32::INFINITY);
5464
}

tests/ui/internal/internal-unstable.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0658]: use of unstable library feature 'function'
2-
--> $DIR/internal-unstable.rs:40:25
2+
--> $DIR/internal-unstable.rs:48:25
33
|
44
LL | pass_through_allow!(internal_unstable::unstable());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add `#![feature(function)]` to the crate attributes to enable
88

99
error[E0658]: use of unstable library feature 'function'
10-
--> $DIR/internal-unstable.rs:42:27
10+
--> $DIR/internal-unstable.rs:50:27
1111
|
1212
LL | pass_through_noallow!(internal_unstable::unstable());
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= help: add `#![feature(function)]` to the crate attributes to enable
1616

1717
error[E0658]: use of unstable library feature 'function'
18-
--> $DIR/internal-unstable.rs:46:22
18+
--> $DIR/internal-unstable.rs:54:22
1919
|
2020
LL | println!("{:?}", internal_unstable::unstable());
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222
|
2323
= help: add `#![feature(function)]` to the crate attributes to enable
2424

2525
error[E0658]: use of unstable library feature 'function'
26-
--> $DIR/internal-unstable.rs:48:10
26+
--> $DIR/internal-unstable.rs:56:10
2727
|
2828
LL | bar!(internal_unstable::unstable());
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)