Skip to content

Commit 85ce9af

Browse files
committed
rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structures
1 parent eb7d725 commit 85ce9af

File tree

101 files changed

+455
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+455
-341
lines changed

Cargo.lock

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ dependencies = [
33543354
"itertools",
33553355
"rustc_ast",
33563356
"rustc_ast_pretty",
3357-
"rustc_attr",
3357+
"rustc_attr_parsing",
33583358
"rustc_data_structures",
33593359
"rustc_errors",
33603360
"rustc_feature",
@@ -3380,7 +3380,7 @@ dependencies = [
33803380
]
33813381

33823382
[[package]]
3383-
name = "rustc_attr"
3383+
name = "rustc_attr_data_structures"
33843384
version = "0.0.0"
33853385
dependencies = [
33863386
"rustc_abi",
@@ -3397,6 +3397,25 @@ dependencies = [
33973397
"rustc_span",
33983398
]
33993399

3400+
[[package]]
3401+
name = "rustc_attr_parsing"
3402+
version = "0.0.0"
3403+
dependencies = [
3404+
"rustc_abi",
3405+
"rustc_ast",
3406+
"rustc_ast_pretty",
3407+
"rustc_attr_data_structures",
3408+
"rustc_data_structures",
3409+
"rustc_errors",
3410+
"rustc_feature",
3411+
"rustc_fluent_macro",
3412+
"rustc_lexer",
3413+
"rustc_macros",
3414+
"rustc_serialize",
3415+
"rustc_session",
3416+
"rustc_span",
3417+
]
3418+
34003419
[[package]]
34013420
name = "rustc_baked_icu_data"
34023421
version = "0.0.0"
@@ -3441,7 +3460,7 @@ version = "0.0.0"
34413460
dependencies = [
34423461
"rustc_ast",
34433462
"rustc_ast_pretty",
3444-
"rustc_attr",
3463+
"rustc_attr_parsing",
34453464
"rustc_data_structures",
34463465
"rustc_errors",
34473466
"rustc_expand",
@@ -3473,7 +3492,7 @@ dependencies = [
34733492
"rustc-demangle",
34743493
"rustc_abi",
34753494
"rustc_ast",
3476-
"rustc_attr",
3495+
"rustc_attr_parsing",
34773496
"rustc_codegen_ssa",
34783497
"rustc_data_structures",
34793498
"rustc_errors",
@@ -3516,7 +3535,7 @@ dependencies = [
35163535
"rustc_arena",
35173536
"rustc_ast",
35183537
"rustc_ast_pretty",
3519-
"rustc_attr",
3538+
"rustc_attr_parsing",
35203539
"rustc_data_structures",
35213540
"rustc_errors",
35223541
"rustc_fluent_macro",
@@ -3554,7 +3573,7 @@ dependencies = [
35543573
"rustc_abi",
35553574
"rustc_apfloat",
35563575
"rustc_ast",
3557-
"rustc_attr",
3576+
"rustc_attr_parsing",
35583577
"rustc_data_structures",
35593578
"rustc_errors",
35603579
"rustc_fluent_macro",
@@ -3621,7 +3640,7 @@ dependencies = [
36213640
"rustc_ast_lowering",
36223641
"rustc_ast_passes",
36233642
"rustc_ast_pretty",
3624-
"rustc_attr",
3643+
"rustc_attr_parsing",
36253644
"rustc_borrowck",
36263645
"rustc_builtin_macros",
36273646
"rustc_codegen_ssa",
@@ -3725,7 +3744,7 @@ dependencies = [
37253744
"rustc_ast",
37263745
"rustc_ast_passes",
37273746
"rustc_ast_pretty",
3728-
"rustc_attr",
3747+
"rustc_attr_parsing",
37293748
"rustc_data_structures",
37303749
"rustc_errors",
37313750
"rustc_feature",
@@ -3800,7 +3819,7 @@ dependencies = [
38003819
"rustc_abi",
38013820
"rustc_arena",
38023821
"rustc_ast",
3803-
"rustc_attr",
3822+
"rustc_attr_parsing",
38043823
"rustc_data_structures",
38053824
"rustc_errors",
38063825
"rustc_feature",
@@ -3839,7 +3858,7 @@ dependencies = [
38393858
"rustc_abi",
38403859
"rustc_ast",
38413860
"rustc_ast_ir",
3842-
"rustc_attr",
3861+
"rustc_attr_parsing",
38433862
"rustc_data_structures",
38443863
"rustc_errors",
38453864
"rustc_fluent_macro",
@@ -3928,7 +3947,7 @@ dependencies = [
39283947
"rustc_ast_lowering",
39293948
"rustc_ast_passes",
39303949
"rustc_ast_pretty",
3931-
"rustc_attr",
3950+
"rustc_attr_parsing",
39323951
"rustc_borrowck",
39333952
"rustc_builtin_macros",
39343953
"rustc_codegen_llvm",
@@ -3984,7 +4003,7 @@ dependencies = [
39844003
"rustc_abi",
39854004
"rustc_ast",
39864005
"rustc_ast_pretty",
3987-
"rustc_attr",
4006+
"rustc_attr_parsing",
39884007
"rustc_data_structures",
39894008
"rustc_errors",
39904009
"rustc_feature",
@@ -4058,7 +4077,7 @@ dependencies = [
40584077
"odht",
40594078
"rustc_abi",
40604079
"rustc_ast",
4061-
"rustc_attr",
4080+
"rustc_attr_parsing",
40624081
"rustc_data_structures",
40634082
"rustc_errors",
40644083
"rustc_expand",
@@ -4095,7 +4114,7 @@ dependencies = [
40954114
"rustc_arena",
40964115
"rustc_ast",
40974116
"rustc_ast_ir",
4098-
"rustc_attr",
4117+
"rustc_attr_parsing",
40994118
"rustc_data_structures",
41004119
"rustc_error_messages",
41014120
"rustc_errors",
@@ -4174,7 +4193,7 @@ dependencies = [
41744193
"rustc_abi",
41754194
"rustc_arena",
41764195
"rustc_ast",
4177-
"rustc_attr",
4196+
"rustc_attr_parsing",
41784197
"rustc_const_eval",
41794198
"rustc_data_structures",
41804199
"rustc_errors",
@@ -4200,7 +4219,7 @@ name = "rustc_monomorphize"
42004219
version = "0.0.0"
42014220
dependencies = [
42024221
"rustc_abi",
4203-
"rustc_attr",
4222+
"rustc_attr_parsing",
42044223
"rustc_data_structures",
42054224
"rustc_errors",
42064225
"rustc_fluent_macro",
@@ -4268,7 +4287,7 @@ dependencies = [
42684287
"rustc_abi",
42694288
"rustc_ast",
42704289
"rustc_ast_pretty",
4271-
"rustc_attr",
4290+
"rustc_attr_parsing",
42724291
"rustc_data_structures",
42734292
"rustc_errors",
42744293
"rustc_expand",
@@ -4315,7 +4334,7 @@ name = "rustc_privacy"
43154334
version = "0.0.0"
43164335
dependencies = [
43174336
"rustc_ast",
4318-
"rustc_attr",
4337+
"rustc_attr_parsing",
43194338
"rustc_data_structures",
43204339
"rustc_errors",
43214340
"rustc_fluent_macro",
@@ -4379,7 +4398,7 @@ dependencies = [
43794398
"rustc_arena",
43804399
"rustc_ast",
43814400
"rustc_ast_pretty",
4382-
"rustc_attr",
4401+
"rustc_attr_parsing",
43834402
"rustc_data_structures",
43844403
"rustc_errors",
43854404
"rustc_expand",
@@ -4536,7 +4555,7 @@ dependencies = [
45364555
"rustc_abi",
45374556
"rustc_ast",
45384557
"rustc_ast_ir",
4539-
"rustc_attr",
4558+
"rustc_attr_parsing",
45404559
"rustc_data_structures",
45414560
"rustc_errors",
45424561
"rustc_fluent_macro",

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
itertools = "0.12"
99
rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
11-
rustc_attr = { path = "../rustc_attr" }
11+
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_errors = { path = "../rustc_errors" }
1414
rustc_feature = { path = "../rustc_feature" }

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<'a> AstValidator<'a> {
342342
sym::forbid,
343343
sym::warn,
344344
];
345-
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(*attr)
345+
!arr.contains(&attr.name_or_empty()) && rustc_attr_parsing::is_builtin_attr(*attr)
346346
})
347347
.for_each(|attr| {
348348
if attr.is_doc_comment() {

compiler/rustc_attr/Cargo.toml renamed to compiler/rustc_attr_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "rustc_attr"
2+
name = "rustc_attr_data_structures"
33
version = "0.0.0"
44
edition = "2021"
55

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use rustc_abi::Align;
2+
use rustc_ast as ast;
3+
use rustc_macros::{Encodable, Decodable, HashStable_Generic};
4+
use crate::RustcVersion;
5+
use rustc_span::{Span, Symbol};
6+
7+
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
8+
pub enum InlineAttr {
9+
None,
10+
Hint,
11+
Always,
12+
Never,
13+
}
14+
15+
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)]
16+
pub enum InstructionSetAttr {
17+
ArmA32,
18+
ArmT32,
19+
}
20+
21+
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
22+
pub enum OptimizeAttr {
23+
None,
24+
Speed,
25+
Size,
26+
}
27+
28+
#[derive(Clone, Debug, Encodable, Decodable)]
29+
pub enum DiagnosticAttribute {
30+
// tidy-alphabetical-start
31+
DoNotRecommend,
32+
OnUnimplemented,
33+
// tidy-alphabetical-end
34+
}
35+
36+
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)]
37+
pub enum ReprAttr {
38+
ReprInt(IntType),
39+
ReprRust,
40+
ReprC,
41+
ReprPacked(Align),
42+
ReprSimd,
43+
ReprTransparent,
44+
ReprAlign(Align),
45+
}
46+
pub use ReprAttr::*;
47+
48+
pub enum TransparencyError {
49+
UnknownTransparency(Symbol, Span),
50+
MultipleTransparencyAttrs(Span, Span),
51+
}
52+
53+
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
54+
#[derive(Encodable, Decodable)]
55+
pub enum IntType {
56+
SignedInt(ast::IntTy),
57+
UnsignedInt(ast::UintTy),
58+
}
59+
60+
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
61+
pub struct Deprecation {
62+
pub since: DeprecatedSince,
63+
/// The note to issue a reason.
64+
pub note: Option<Symbol>,
65+
/// A text snippet used to completely replace any use of the deprecated item in an expression.
66+
///
67+
/// This is currently unstable.
68+
pub suggestion: Option<Symbol>,
69+
}
70+
71+
/// Release in which an API is deprecated.
72+
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
73+
pub enum DeprecatedSince {
74+
RustcVersion(RustcVersion),
75+
/// Deprecated in the future ("to be determined").
76+
Future,
77+
/// `feature(staged_api)` is off. Deprecation versions outside the standard
78+
/// library are allowed to be arbitrary strings, for better or worse.
79+
NonStandard(Symbol),
80+
/// Deprecation version is unspecified but optional.
81+
Unspecified,
82+
/// Failed to parse a deprecation version, or the deprecation version is
83+
/// unspecified and required. An error has already been emitted.
84+
Err,
85+
}
86+
87+
impl Deprecation {
88+
/// Whether an item marked with #[deprecated(since = "X")] is currently
89+
/// deprecated (i.e., whether X is not greater than the current rustc
90+
/// version).
91+
pub fn is_in_effect(&self) -> bool {
92+
match self.since {
93+
DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
94+
DeprecatedSince::Future => false,
95+
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
96+
DeprecatedSince::NonStandard(_) => true,
97+
// Assume deprecation is in effect if "since" field is absent or invalid.
98+
DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
99+
}
100+
}
101+
102+
pub fn is_since_rustc_version(&self) -> bool {
103+
matches!(self.since, DeprecatedSince::RustcVersion(_))
104+
}
105+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Centralized logic for parsing and validating all attributes used after HIR.
2+
//!
3+
//! History: Check out [#131229](https://github.com/rust-lang/rust/issues/131229).
4+
//! There used to be only one definition of attributes in the compiler: `ast::Attribute`.
5+
//! These were then parsed or validated or both in places distributed all over the compiler.
6+
//!
7+
//! Attributes are markers on items. Most are actually attribute-like proc-macros, and are expanded
8+
//! but some remain as the built-in attributes to guide compilation.
9+
//!
10+
//! In this crate, syntactical attributes (sequences of tokens that look like
11+
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items.
12+
//! Multiple syntactic attributes might influence a single semantic attribute. For example,
13+
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define
14+
//! a "stability". Stability defines an [`AttributeExtractor`](attributes::AttributeExtractor)
15+
//! that recognizes both `#[stable()]` and `#[unstable()]` syntactic attributes, and at the end
16+
//! produce a single [`ParsedAttributeKind::Stability`].
17+
//!
18+
//! FIXME(jdonszelmann): update devguide for best practices on attributes
19+
//! FIXME(jdonszelmann): rename to `rustc_attr` in the future, integrating it into this crate.
20+
//!
21+
//! To define a new builtin, first add it
22+
23+
// tidy-alphabetical-start
24+
#![allow(internal_features)]
25+
#![doc(rust_logo)]
26+
#![feature(let_chains)]
27+
#![feature(rustdoc_internals)]
28+
#![warn(unreachable_pub)]
29+
// tidy-alphabetical-end
30+
31+
mod attributes;
32+
mod stability;
33+
mod version;
34+
35+
pub use attributes::*;
36+
pub use stability::*;
37+
pub use version::*;
38+
39+
pub(crate) use rustc_session::HashStableContext;

0 commit comments

Comments
 (0)