Skip to content

Commit 5775331

Browse files
committed
Change span field accesses to method calls
1 parent b5741a3 commit 5775331

File tree

26 files changed

+274
-209
lines changed

26 files changed

+274
-209
lines changed

compiler/rustc_attr_parsing/src/attributes/mod.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
mod allow_unstable;
2-
mod cfg;
3-
mod confusables;
4-
mod deprecation;
5-
mod repr;
6-
mod stability;
7-
mod transparency;
1+
//! You can find more docs on what groups are on [`AttributeParser`] itself.
2+
//! However, for many types of attributes, implementing [`AttributeParser`] is not necessary.
3+
//! It allows for a lot of flexibility you might not want.
4+
//!
5+
//! Specifically, you might not care about managing the state of your [`AttributeParser`]
6+
//! state machine yourself. In this case you can choose to implement:
7+
//!
8+
//! - [`SingleAttributeParser`]: makes it easy to implement an attribute which should error if it
9+
//! appears more than once in a list of attributes
10+
//! - [`CombineAttributeParser`]: makes it easy to implement an attribute which should combine the
11+
//! contents of attributes, if an attribute appear multiple times in a list
12+
//!
13+
//! Attributes should be added to [`ATTRIBUTE_GROUP_MAPPING`](crate::context::ATTRIBUTE_GROUP_MAPPING) to be parsed.
814
9-
pub mod util;
15+
pub(crate) mod allow_unstable;
16+
pub(crate) mod cfg;
17+
pub(crate) mod confusables;
18+
pub(crate) mod deprecation;
19+
pub(crate) mod repr;
20+
pub(crate) mod stability;
21+
pub(crate) mod transparency;
22+
pub(crate) mod util;
1023

1124
pub use allow_unstable::*;
1225
pub use cfg::*;

compiler/rustc_attr_parsing/src/lib.rs

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1-
//! Functions and types dealing with attributes and meta items.
1+
//! Centralized logic for parsing and attributes.
22
//!
3-
//! FIXME(Centril): For now being, much of the logic is still in `rustc_ast::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.
3+
//! Part of a series of crates:
4+
//! - rustc_attr_data_structures: contains types that the parsers parse into
5+
//! - rustc_attr_parsing: this crate
6+
//! - (in the future): rustc_attr_validation
7+
//!
8+
//! History: Check out [#131229](https://github.com/rust-lang/rust/issues/131229).
9+
//! There used to be only one definition of attributes in the compiler: `ast::Attribute`.
10+
//! These were then parsed or validated or both in places distributed all over the compiler.
11+
//! This was a mess...
12+
//!
13+
//! Attributes are markers on items. Most are actually attribute-like proc-macros, and are expanded
14+
//! but some remain as the so-called built-in attributes. These are not macros at all, and really
15+
//! are just markers to guide the compilation process. An example is `#[inline(...)]` which changes
16+
//! how code for functions is generated. Built-in attributes aren't macros because there's no rust
17+
//! syntax they could expand to.
18+
//!
19+
//! In this crate, syntactical attributes (sequences of tokens that look like
20+
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items.
21+
//! Multiple syntactic attributes might influence a single semantic attribute. For example,
22+
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define
23+
//! a "stability" of an item. So, the stability attribute has an
24+
//! [`AttributeParser`](attributes::AttributeParser) that recognizes both the `#[stable()]`
25+
//! and `#[unstable()]` syntactic attributes, and at the end produce a single [`AttributeKind::Stability`].
26+
//!
27+
//! As a rule of thumb, when a syntactical attribute can be applied more than once, they should be
28+
//! combined into a single semantic attribute. For example:
29+
//!
30+
//! ```
31+
//! #[repr(C)]
32+
//! #[repr(packed)]
33+
//! struct Meow {}
34+
//! ```
35+
//!
36+
//! should result in a single `AttributeKind::Repr` containing a list of repr annotations, in this
37+
//! case `C` and `packed`. This is equivalent to writing `#[repr(C, packed)]` in a single
38+
//! syntactical annotation.
639
740
// tidy-alphabetical-start
841
#![allow(internal_features)]

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ impl<'tcx> AssertModuleSource<'tcx> {
9090
other => {
9191
self.tcx
9292
.dcx()
93-
.emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other });
93+
.emit_fatal(errors::UnknownReuseKind { span: attr.span(), kind: other });
9494
}
9595
}
9696
} else {
9797
return;
9898
};
9999

100100
if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
101-
self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span });
101+
self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span() });
102102
}
103103

104104
if !self.check_config(attr) {
@@ -111,7 +111,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
111111

112112
if !user_path.starts_with(&crate_name) {
113113
self.tcx.dcx().emit_fatal(errors::MalformedCguName {
114-
span: attr.span,
114+
span: attr.span(),
115115
user_path,
116116
crate_name,
117117
});
@@ -141,7 +141,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
141141
let cgu_names: Vec<&str> =
142142
self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
143143
self.tcx.dcx().emit_err(errors::NoModuleNamed {
144-
span: attr.span,
144+
span: attr.span(),
145145
user_path,
146146
cgu_name,
147147
cgu_names: cgu_names.join(", "),
@@ -151,7 +151,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
151151
self.cgu_reuse_tracker.set_expectation(
152152
cgu_name,
153153
user_path,
154-
attr.span,
154+
attr.span(),
155155
expected_reuse,
156156
comp_kind,
157157
);
@@ -171,7 +171,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
171171
}
172172
}
173173

174-
self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span, name });
174+
self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span(), name });
175175
}
176176

177177
/// Scan for a `cfg="foo"` attribute and check whether we have a

0 commit comments

Comments
 (0)