Skip to content

Commit 115b3b0

Browse files
committed
Change span field accesses to method calls
1 parent f43e549 commit 115b3b0

File tree

27 files changed

+264
-202
lines changed

27 files changed

+264
-202
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
@@ -94,15 +94,15 @@ impl<'tcx> AssertModuleSource<'tcx> {
9494
other => {
9595
self.tcx
9696
.dcx()
97-
.emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other });
97+
.emit_fatal(errors::UnknownReuseKind { span: attr.span(), kind: other });
9898
}
9999
}
100100
} else {
101101
return;
102102
};
103103

104104
if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
105-
self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span });
105+
self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span() });
106106
}
107107

108108
if !self.check_config(attr) {
@@ -115,7 +115,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
115115

116116
if !user_path.starts_with(&crate_name) {
117117
self.tcx.dcx().emit_fatal(errors::MalformedCguName {
118-
span: attr.span,
118+
span: attr.span(),
119119
user_path,
120120
crate_name,
121121
});
@@ -145,7 +145,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
145145
let cgu_names: Vec<&str> =
146146
self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
147147
self.tcx.dcx().emit_err(errors::NoModuleNamed {
148-
span: attr.span,
148+
span: attr.span(),
149149
user_path,
150150
cgu_name,
151151
cgu_names: cgu_names.join(", "),
@@ -155,7 +155,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
155155
self.cgu_reuse_tracker.set_expectation(
156156
cgu_name,
157157
user_path,
158-
attr.span,
158+
attr.span(),
159159
expected_reuse,
160160
comp_kind,
161161
);
@@ -175,7 +175,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
175175
}
176176
}
177177

178-
self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span, name });
178+
self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span(), name });
179179
}
180180

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

0 commit comments

Comments
 (0)