Skip to content

Commit 93a8283

Browse files
committed
Move builtin attribute logic to new rustc_attr crate.
For now, this is all the crate contains, but more attribute logic & types will be moved there over time.
1 parent 9be73dc commit 93a8283

File tree

63 files changed

+133
-53
lines changed

Some content is hidden

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

63 files changed

+133
-53
lines changed

Cargo.lock

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,7 @@ dependencies = [
30933093
"rustc-rayon",
30943094
"rustc-rayon-core",
30953095
"rustc_apfloat",
3096+
"rustc_attr",
30963097
"rustc_data_structures",
30973098
"rustc_errors",
30983099
"rustc_feature",
@@ -3374,6 +3375,7 @@ name = "rustc_ast_passes"
33743375
version = "0.0.0"
33753376
dependencies = [
33763377
"log",
3378+
"rustc_attr",
33773379
"rustc_data_structures",
33783380
"rustc_errors",
33793381
"rustc_feature",
@@ -3383,12 +3385,28 @@ dependencies = [
33833385
"syntax",
33843386
]
33853387

3388+
[[package]]
3389+
name = "rustc_attr"
3390+
version = "0.0.0"
3391+
dependencies = [
3392+
"rustc_data_structures",
3393+
"rustc_errors",
3394+
"rustc_feature",
3395+
"rustc_macros",
3396+
"rustc_session",
3397+
"rustc_span",
3398+
"serialize",
3399+
"smallvec 1.0.0",
3400+
"syntax",
3401+
]
3402+
33863403
[[package]]
33873404
name = "rustc_builtin_macros"
33883405
version = "0.0.0"
33893406
dependencies = [
33903407
"fmt_macros",
33913408
"log",
3409+
"rustc_attr",
33923410
"rustc_data_structures",
33933411
"rustc_errors",
33943412
"rustc_expand",
@@ -3411,6 +3429,7 @@ dependencies = [
34113429
"log",
34123430
"rustc",
34133431
"rustc-demangle",
3432+
"rustc_attr",
34143433
"rustc_codegen_ssa",
34153434
"rustc_codegen_utils",
34163435
"rustc_data_structures",
@@ -3442,6 +3461,7 @@ dependencies = [
34423461
"num_cpus",
34433462
"rustc",
34443463
"rustc_apfloat",
3464+
"rustc_attr",
34453465
"rustc_codegen_utils",
34463466
"rustc_data_structures",
34473467
"rustc_errors",
@@ -3552,6 +3572,7 @@ version = "0.0.0"
35523572
dependencies = [
35533573
"log",
35543574
"rustc_ast_passes",
3575+
"rustc_attr",
35553576
"rustc_data_structures",
35563577
"rustc_errors",
35573578
"rustc_feature",
@@ -3628,6 +3649,7 @@ dependencies = [
36283649
"rustc-rayon",
36293650
"rustc_ast_lowering",
36303651
"rustc_ast_passes",
3652+
"rustc_attr",
36313653
"rustc_builtin_macros",
36323654
"rustc_codegen_llvm",
36333655
"rustc_codegen_ssa",
@@ -3672,6 +3694,7 @@ version = "0.0.0"
36723694
dependencies = [
36733695
"log",
36743696
"rustc",
3697+
"rustc_attr",
36753698
"rustc_data_structures",
36763699
"rustc_errors",
36773700
"rustc_feature",
@@ -3712,6 +3735,7 @@ dependencies = [
37123735
"log",
37133736
"memmap",
37143737
"rustc",
3738+
"rustc_attr",
37153739
"rustc_data_structures",
37163740
"rustc_errors",
37173741
"rustc_expand",
@@ -3739,6 +3763,7 @@ dependencies = [
37393763
"polonius-engine",
37403764
"rustc",
37413765
"rustc_apfloat",
3766+
"rustc_attr",
37423767
"rustc_data_structures",
37433768
"rustc_errors",
37443769
"rustc_hir",
@@ -3761,6 +3786,7 @@ dependencies = [
37613786
"log",
37623787
"rustc",
37633788
"rustc_apfloat",
3789+
"rustc_attr",
37643790
"rustc_data_structures",
37653791
"rustc_errors",
37663792
"rustc_hir",
@@ -3780,6 +3806,7 @@ version = "0.0.0"
37803806
dependencies = [
37813807
"bitflags",
37823808
"log",
3809+
"rustc_attr",
37833810
"rustc_data_structures",
37843811
"rustc_errors",
37853812
"rustc_feature",
@@ -3797,6 +3824,7 @@ version = "0.0.0"
37973824
dependencies = [
37983825
"log",
37993826
"rustc",
3827+
"rustc_attr",
38003828
"rustc_data_structures",
38013829
"rustc_errors",
38023830
"rustc_feature",
@@ -3827,6 +3855,7 @@ version = "0.0.0"
38273855
dependencies = [
38283856
"log",
38293857
"rustc",
3858+
"rustc_attr",
38303859
"rustc_data_structures",
38313860
"rustc_errors",
38323861
"rustc_hir",
@@ -3844,6 +3873,7 @@ dependencies = [
38443873
"log",
38453874
"rustc",
38463875
"rustc_ast_lowering",
3876+
"rustc_attr",
38473877
"rustc_data_structures",
38483878
"rustc_errors",
38493879
"rustc_expand",
@@ -3961,6 +3991,7 @@ dependencies = [
39613991
"arena",
39623992
"log",
39633993
"rustc",
3994+
"rustc_attr",
39643995
"rustc_data_structures",
39653996
"rustc_errors",
39663997
"rustc_hir",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rustc-rayon = "0.3.0"
2121
rustc-rayon-core = "0.3.0"
2222
polonius-engine = "0.11.0"
2323
rustc_apfloat = { path = "../librustc_apfloat" }
24+
rustc_attr = { path = "../librustc_attr" }
2425
rustc_feature = { path = "../librustc_feature" }
2526
rustc_hir = { path = "../librustc_hir" }
2627
rustc_target = { path = "../librustc_target" }

src/librustc/ich/impls_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
44
use crate::hir::map::DefPathHash;
55
use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
6+
use rustc_attr as attr;
67
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
78
use rustc_hir as hir;
89
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
910
use smallvec::SmallVec;
1011
use std::mem;
11-
use syntax::attr;
1212

1313
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
1414
#[inline]

src/librustc/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::mir::mono::Linkage;
2+
use rustc_attr::{InlineAttr, OptimizeAttr};
23
use rustc_span::symbol::Symbol;
3-
use syntax::attr::{InlineAttr, OptimizeAttr};
44

55
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
66
pub struct CodegenFnAttrs {

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use self::StabilityLevel::*;
55

66
use crate::session::{DiagnosticMessageId, Session};
77
use crate::ty::{self, TyCtxt};
8+
use rustc_attr::{self as attr, ConstStability, Deprecation, RustcDeprecation, Stability};
89
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
910
use rustc_errors::{Applicability, DiagnosticBuilder};
1011
use rustc_feature::GateIssue;
@@ -16,7 +17,6 @@ use rustc_session::lint::{self, BuiltinLintDiagnostics, Lint, LintBuffer};
1617
use rustc_span::symbol::{sym, Symbol};
1718
use rustc_span::{MultiSpan, Span};
1819
use syntax::ast::CRATE_NODE_ID;
19-
use syntax::attr::{self, ConstStability, Deprecation, RustcDeprecation, Stability};
2020
use syntax::sess::feature_err_issue;
2121

2222
use std::num::NonZeroU32;

src/librustc/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
33
use crate::session::config::OptLevel;
44
use crate::ty::print::obsolete::DefPathBasedNames;
55
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
6+
use rustc_attr::InlineAttr;
67
use rustc_data_structures::base_n;
78
use rustc_data_structures::fx::FxHashMap;
89
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -12,7 +13,6 @@ use rustc_span::source_map::Span;
1213
use rustc_span::symbol::Symbol;
1314
use std::fmt;
1415
use std::hash::Hash;
15-
use syntax::attr::InlineAttr;
1616

1717
/// Describes how a monomorphization will be instantiated in object files.
1818
#[derive(PartialEq)]

src/librustc/traits/on_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use fmt_macros::{Parser, Piece, Position};
33
use crate::ty::{self, GenericParamDefKind, TyCtxt};
44
use crate::util::common::ErrorReported;
55

6+
use rustc_attr as attr;
67
use rustc_data_structures::fx::FxHashMap;
78
use rustc_errors::struct_span_err;
89
use rustc_hir::def_id::DefId;
910
use rustc_span::symbol::{kw, sym, Symbol};
1011
use rustc_span::Span;
1112
use syntax::ast::{MetaItem, NestedMetaItem};
12-
use syntax::attr;
1313

1414
#[derive(Clone, Debug)]
1515
pub struct OnUnimplementedFormatString(Symbol);

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use rustc_session::config::CrateType;
5151
use rustc_session::config::{BorrowckMode, OutputFilenames};
5252
use rustc_session::Session;
5353

54+
use rustc_attr as attr;
5455
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5556
use rustc_data_structures::profiling::SelfProfilerRef;
5657
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
@@ -79,7 +80,6 @@ use std::mem;
7980
use std::ops::{Bound, Deref};
8081
use std::sync::Arc;
8182
use syntax::ast;
82-
use syntax::attr;
8383
use syntax::expand::allocator::AllocatorKind;
8484

8585
type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;

src/librustc/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::session::{self, DataTypeKind};
22
use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable};
33

4+
use rustc_attr as attr;
45
use rustc_span::DUMMY_SP;
56
use syntax::ast::{self, Ident, IntTy, UintTy};
6-
use syntax::attr;
77

88
use std::cmp;
99
use std::fmt;

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::ty::layout::VariantIdx;
2626
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
2727
use crate::ty::util::{Discr, IntTypeExt};
2828
use crate::ty::walk::TypeWalker;
29+
use rustc_attr as attr;
2930
use rustc_data_structures::captures::Captures;
3031
use rustc_data_structures::fx::FxHashMap;
3132
use rustc_data_structures::fx::FxIndexMap;
@@ -53,7 +54,6 @@ use std::ops::Range;
5354
use std::slice;
5455
use std::{mem, ptr};
5556
use syntax::ast::{self, Constness, Ident, Name, NodeId};
56-
use syntax::attr;
5757

5858
pub use self::sty::BoundRegion::*;
5959
pub use self::sty::InferTy::*;

src/librustc/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1111

1212
use rustc_apfloat::ieee::{Double, Single};
1313
use rustc_apfloat::Float;
14+
use rustc_attr::{SignedInt, UnsignedInt};
1415
use rustc_span::symbol::{kw, Symbol};
1516
use rustc_target::spec::abi::Abi;
1617
use syntax::ast;
17-
use syntax::attr::{SignedInt, UnsignedInt};
1818

1919
use std::cell::Cell;
2020
use std::collections::BTreeMap;

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ use rustc_hir::{HirIdSet, ItemLocalId, TraitCandidate};
4949
use rustc_index::vec::IndexVec;
5050
use rustc_target::spec::PanicStrategy;
5151

52+
use rustc_attr as attr;
5253
use rustc_span::symbol::Symbol;
5354
use rustc_span::{Span, DUMMY_SP};
5455
use std::any::type_name;
5556
use std::borrow::Cow;
5657
use std::ops::Deref;
5758
use std::sync::Arc;
5859
use syntax::ast;
59-
use syntax::attr;
6060

6161
#[macro_use]
6262
mod plumbing;

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::ty::TyKind::*;
1010
use crate::ty::{self, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable};
1111
use crate::util::common::ErrorReported;
1212
use rustc_apfloat::Float as _;
13+
use rustc_attr::{self as attr, SignedInt, UnsignedInt};
1314
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1415
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1516
use rustc_hir as hir;
@@ -19,7 +20,6 @@ use rustc_macros::HashStable;
1920
use rustc_span::Span;
2021
use std::{cmp, fmt};
2122
use syntax::ast;
22-
use syntax::attr::{self, SignedInt, UnsignedInt};
2323

2424
#[derive(Copy, Clone, Debug)]
2525
pub struct Discr<'tcx> {

src/librustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010

1111
[dependencies]
1212
log = "0.4"
13+
rustc_attr = { path = "../librustc_attr" }
1314
rustc_data_structures = { path = "../librustc_data_structures" }
1415
rustc_errors = { path = "../librustc_errors" }
1516
rustc_feature = { path = "../librustc_feature" }

src/librustc_ast_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a> AstValidator<'a> {
331331
.flat_map(|i| i.attrs.as_ref())
332332
.filter(|attr| {
333333
let arr = [sym::allow, sym::cfg, sym::cfg_attr, sym::deny, sym::forbid, sym::warn];
334-
!arr.contains(&attr.name_or_empty()) && attr::is_builtin_attr(attr)
334+
!arr.contains(&attr.name_or_empty()) && rustc_attr::is_builtin_attr(attr)
335335
})
336336
.for_each(|attr| {
337337
if attr.is_doc_comment() {

src/librustc_attr/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_attr"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_attr"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
rustc_serialize = { path = "../libserialize", package = "serialize" }
14+
rustc_errors = { path = "../librustc_errors" }
15+
rustc_span = { path = "../librustc_span" }
16+
rustc_data_structures = { path = "../librustc_data_structures" }
17+
rustc_feature = { path = "../librustc_feature" }
18+
rustc_macros = { path = "../librustc_macros" }
19+
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
20+
rustc_session = { path = "../librustc_session" }
21+
syntax = { path = "../libsyntax" }

src/libsyntax/attr/builtin.rs renamed to src/librustc_attr/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//! Parsing and validation of builtin attributes
22
3-
use super::{mark_used, MetaItemKind};
4-
use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
5-
use crate::print::pprust;
6-
use crate::sess::{feature_err, ParseSess};
3+
use super::mark_used;
74

85
use rustc_errors::{struct_span_err, Applicability, Handler};
96
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
107
use rustc_macros::HashStable_Generic;
8+
use rustc_session::parse::{feature_err, ParseSess};
119
use rustc_span::hygiene::Transparency;
1210
use rustc_span::{symbol::sym, symbol::Symbol, Span};
1311
use std::num::NonZeroU32;
12+
use syntax::ast::{self, Attribute, MetaItem, MetaItemKind, NestedMetaItem};
13+
use syntax::print::pprust;
1414

1515
pub fn is_builtin_attr(attr: &Attribute) -> bool {
1616
attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()

src/librustc_attr/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Functions and types dealing with attributes and meta items.
2+
//!
3+
//! FIXME(Centril): For now being, much of the logic is still in `syntax::attr`.
4+
//! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax`
5+
//! to this crate.
6+
7+
mod builtin;
8+
9+
pub use builtin::*;
10+
pub use IntType::*;
11+
pub use ReprAttr::*;
12+
pub use StabilityLevel::*;
13+
14+
pub use syntax::attr::*;
15+
16+
pub(crate) use syntax::HashStableContext;

src/librustc_builtin_macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ doctest = false
1212
[dependencies]
1313
fmt_macros = { path = "../libfmt_macros" }
1414
log = "0.4"
15+
rustc_attr = { path = "../librustc_attr" }
1516
rustc_data_structures = { path = "../librustc_data_structures" }
1617
rustc_errors = { path = "../librustc_errors" }
1718
rustc_feature = { path = "../librustc_feature" }

0 commit comments

Comments
 (0)