Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize #[cfg_eval] and feature(macro_attributes_in_derive_output) #83824

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ declare_features! (
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668), None),
/// Allows the use of or-patterns (e.g., `0 | 1`).
(accepted, or_patterns, "1.53.0", Some(54883), None),
/// Allows macro attributes to observe output of `#[derive]`.
(accepted, macro_attributes_in_derive_output, "1.53.0", Some(81119), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,6 @@ declare_features! (
/// Lessens the requirements for structs to implement `Unsize`.
(active, relaxed_struct_unsize, "1.51.0", Some(81793), None),

/// Allows macro attributes to observe output of `#[derive]`.
(active, macro_attributes_in_derive_output, "1.51.0", Some(81119), None),

/// Allows `pub` on `macro_rules` items.
(active, pub_macro_rules, "1.52.0", Some(78855), None),

Expand Down
30 changes: 0 additions & 30 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,36 +303,6 @@ impl<'a> ResolverExpand for Resolver<'a> {
if let Res::Def(_, _) = res {
let normal_module_def_id = self.macro_def_scope(invoc_id).nearest_parent_mod;
self.definitions.add_parent_module_of_macro_def(invoc_id, normal_module_def_id);

// Gate macro attributes in `#[derive]` output.
if !self.session.features_untracked().macro_attributes_in_derive_output
&& kind == MacroKind::Attr
&& ext.builtin_name != Some(sym::derive)
{
let mut expn_id = parent_scope.expansion;
loop {
// Helper attr table is a quick way to determine whether the attr is `derive`.
if self.helper_attrs.contains_key(&expn_id) {
feature_err(
&self.session.parse_sess,
sym::macro_attributes_in_derive_output,
path.span,
"macro attributes in `#[derive]` output are unstable",
)
.emit();
break;
} else {
let expn_data = expn_id.expn_data();
match expn_data.kind {
ExpnKind::Root
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
break;
}
_ => expn_id = expn_data.parent,
}
}
}
}
}

Ok(ext)
Expand Down
6 changes: 1 addition & 5 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,11 +1454,7 @@ pub(crate) mod builtin {

/// Expands all `#[cfg]` and `#[cfg_attr]` attributes in the code fragment it's applied to.
#[cfg(not(bootstrap))]
#[unstable(
feature = "cfg_eval",
issue = "82679",
reason = "`cfg_eval` is a recently implemented feature"
)]
#[stable(feature = "cfg_eval", since = "1.53.0")]
#[rustc_builtin_macro]
pub macro cfg_eval($($tt:tt)*) {
/* compiler built-in */
Expand Down
6 changes: 1 addition & 5 deletions library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ pub use crate::macros::builtin::derive;
pub use crate::macros::builtin::cfg_accessible;

#[cfg(not(bootstrap))]
#[unstable(
feature = "cfg_eval",
issue = "82679",
reason = "`cfg_eval` is a recently implemented feature"
)]
#[stable(feature = "cfg_eval", since = "1.53.0")]
#[doc(no_inline)]
pub use crate::macros::builtin::cfg_eval;
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
#![feature(box_syntax)]
#![feature(c_variadic)]
#![feature(cfg_accessible)]
#![cfg_attr(not(bootstrap), feature(cfg_eval))]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_thread_local)]
#![feature(char_error_internals)]
Expand Down
6 changes: 1 addition & 5 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ pub use core::prelude::v1::derive;
pub use core::prelude::v1::cfg_accessible;

#[cfg(not(bootstrap))]
#[unstable(
feature = "cfg_eval",
issue = "82679",
reason = "`cfg_eval` is a recently implemented feature"
)]
#[stable(feature = "cfg_eval", since = "1.53.0")]
#[doc(hidden)]
pub use core::prelude::v1::cfg_eval;

Expand Down
37 changes: 0 additions & 37 deletions src/test/ui/proc-macro/attribute-after-derive-feature-gate.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/ui/proc-macro/attribute-after-derive-feature-gate.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/ui/proc-macro/attribute-after-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// compile-flags: -Z span-debug
// aux-build: test-macros.rs

#![feature(macro_attributes_in_derive_output)]

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

Expand Down
58 changes: 29 additions & 29 deletions src/test/ui/proc-macro/attribute-after-derive.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,146 +3,146 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:17:1: 17:2 (#0),
span: $DIR/attribute-after-derive.rs:15:1: 15:2 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "derive",
span: $DIR/attribute-after-derive.rs:17:3: 17:9 (#0),
span: $DIR/attribute-after-derive.rs:15:3: 15:9 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "Print",
span: $DIR/attribute-after-derive.rs:17:10: 17:15 (#0),
span: $DIR/attribute-after-derive.rs:15:10: 15:15 (#0),
},
],
span: $DIR/attribute-after-derive.rs:17:9: 17:16 (#0),
span: $DIR/attribute-after-derive.rs:15:9: 15:16 (#0),
},
],
span: $DIR/attribute-after-derive.rs:17:2: 17:17 (#0),
span: $DIR/attribute-after-derive.rs:15:2: 15:17 (#0),
},
Ident {
ident: "struct",
span: $DIR/attribute-after-derive.rs:18:1: 18:7 (#0),
span: $DIR/attribute-after-derive.rs:16:1: 16:7 (#0),
},
Ident {
ident: "AttributeDerive",
span: $DIR/attribute-after-derive.rs:18:8: 18:23 (#0),
span: $DIR/attribute-after-derive.rs:16:8: 16:23 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:19:5: 19:6 (#0),
span: $DIR/attribute-after-derive.rs:17:5: 17:6 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "cfg",
span: $DIR/attribute-after-derive.rs:19:7: 19:10 (#0),
span: $DIR/attribute-after-derive.rs:17:7: 17:10 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "FALSE",
span: $DIR/attribute-after-derive.rs:19:11: 19:16 (#0),
span: $DIR/attribute-after-derive.rs:17:11: 17:16 (#0),
},
],
span: $DIR/attribute-after-derive.rs:19:10: 19:17 (#0),
span: $DIR/attribute-after-derive.rs:17:10: 17:17 (#0),
},
],
span: $DIR/attribute-after-derive.rs:19:6: 19:18 (#0),
span: $DIR/attribute-after-derive.rs:17:6: 17:18 (#0),
},
Ident {
ident: "field",
span: $DIR/attribute-after-derive.rs:20:5: 20:10 (#0),
span: $DIR/attribute-after-derive.rs:18:5: 18:10 (#0),
},
Punct {
ch: ':',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:20:10: 20:11 (#0),
span: $DIR/attribute-after-derive.rs:18:10: 18:11 (#0),
},
Ident {
ident: "u8",
span: $DIR/attribute-after-derive.rs:20:12: 20:14 (#0),
span: $DIR/attribute-after-derive.rs:18:12: 18:14 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:20:14: 20:15 (#0),
span: $DIR/attribute-after-derive.rs:18:14: 18:15 (#0),
},
],
span: $DIR/attribute-after-derive.rs:18:24: 21:2 (#0),
span: $DIR/attribute-after-derive.rs:16:24: 19:2 (#0),
},
]
PRINT-DERIVE INPUT (DISPLAY): struct AttributeDerive { }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: $DIR/attribute-after-derive.rs:18:1: 21:2 (#0),
span: $DIR/attribute-after-derive.rs:16:1: 19:2 (#0),
},
Ident {
ident: "AttributeDerive",
span: $DIR/attribute-after-derive.rs:18:1: 21:2 (#0),
span: $DIR/attribute-after-derive.rs:16:1: 19:2 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/attribute-after-derive.rs:18:1: 21:2 (#0),
span: $DIR/attribute-after-derive.rs:16:1: 19:2 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Ident {
ident: "DeriveAttribute",
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
]
PRINT-DERIVE INPUT (DISPLAY): #[print_attr] struct DeriveAttribute { }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_attr",
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
],
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Ident {
ident: "struct",
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Ident {
ident: "DeriveAttribute",
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/attribute-after-derive.rs:25:1: 28:2 (#0),
span: $DIR/attribute-after-derive.rs:23:1: 26:2 (#0),
},
]
1 change: 0 additions & 1 deletion src/test/ui/proc-macro/cfg-eval-fail.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(cfg_eval)]
#![feature(stmt_expr_attributes)]

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/proc-macro/cfg-eval-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: removing an expression is not supported in this position
--> $DIR/cfg-eval-fail.rs:5:25
--> $DIR/cfg-eval-fail.rs:4:25
|
LL | let _ = #[cfg_eval] #[cfg(FALSE)] 0;
| ^^^^^^^^^^^^^

error: removing an expression is not supported in this position
--> $DIR/cfg-eval-fail.rs:5:25
--> $DIR/cfg-eval-fail.rs:4:25
|
LL | let _ = #[cfg_eval] #[cfg(FALSE)] 0;
| ^^^^^^^^^^^^^

error: removing an expression is not supported in this position
--> $DIR/cfg-eval-fail.rs:5:25
--> $DIR/cfg-eval-fail.rs:4:25
|
LL | let _ = #[cfg_eval] #[cfg(FALSE)] 0;
| ^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/proc-macro/cfg-eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// compile-flags: -Z span-debug
// aux-build:test-macros.rs

#![feature(cfg_eval)]
#![feature(proc_macro_hygiene)]
#![feature(stmt_expr_attributes)]

Expand Down
Loading