-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_st…
…ructures
- Loading branch information
1 parent
54bbce2
commit 7179f3b
Showing
103 changed files
with
482 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/rustc_attr/Cargo.toml → ...ler/rustc_attr_data_structures/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "rustc_attr" | ||
name = "rustc_attr_data_structures" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use rustc_abi::Align; | ||
use rustc_ast as ast; | ||
use rustc_macros::{Decodable, Encodable, HashStable_Generic}; | ||
use rustc_span::{Span, Symbol}; | ||
|
||
use crate::RustcVersion; | ||
|
||
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] | ||
pub enum InlineAttr { | ||
None, | ||
Hint, | ||
Always, | ||
Never, | ||
} | ||
|
||
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)] | ||
pub enum InstructionSetAttr { | ||
ArmA32, | ||
ArmT32, | ||
} | ||
|
||
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] | ||
pub enum OptimizeAttr { | ||
None, | ||
Speed, | ||
Size, | ||
} | ||
|
||
#[derive(Clone, Debug, Encodable, Decodable)] | ||
pub enum DiagnosticAttribute { | ||
// tidy-alphabetical-start | ||
DoNotRecommend, | ||
OnUnimplemented, | ||
// tidy-alphabetical-end | ||
} | ||
|
||
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)] | ||
pub enum ReprAttr { | ||
ReprInt(IntType), | ||
ReprRust, | ||
ReprC, | ||
ReprPacked(Align), | ||
ReprSimd, | ||
ReprTransparent, | ||
ReprAlign(Align), | ||
} | ||
pub use ReprAttr::*; | ||
|
||
pub enum TransparencyError { | ||
UnknownTransparency(Symbol, Span), | ||
MultipleTransparencyAttrs(Span, Span), | ||
} | ||
|
||
#[derive(Eq, PartialEq, Debug, Copy, Clone)] | ||
#[derive(Encodable, Decodable)] | ||
pub enum IntType { | ||
SignedInt(ast::IntTy), | ||
UnsignedInt(ast::UintTy), | ||
} | ||
|
||
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)] | ||
pub struct Deprecation { | ||
pub since: DeprecatedSince, | ||
/// The note to issue a reason. | ||
pub note: Option<Symbol>, | ||
/// A text snippet used to completely replace any use of the deprecated item in an expression. | ||
/// | ||
/// This is currently unstable. | ||
pub suggestion: Option<Symbol>, | ||
} | ||
|
||
/// Release in which an API is deprecated. | ||
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)] | ||
pub enum DeprecatedSince { | ||
RustcVersion(RustcVersion), | ||
/// Deprecated in the future ("to be determined"). | ||
Future, | ||
/// `feature(staged_api)` is off. Deprecation versions outside the standard | ||
/// library are allowed to be arbitrary strings, for better or worse. | ||
NonStandard(Symbol), | ||
/// Deprecation version is unspecified but optional. | ||
Unspecified, | ||
/// Failed to parse a deprecation version, or the deprecation version is | ||
/// unspecified and required. An error has already been emitted. | ||
Err, | ||
} | ||
|
||
impl Deprecation { | ||
/// Whether an item marked with #[deprecated(since = "X")] is currently | ||
/// deprecated (i.e., whether X is not greater than the current rustc | ||
/// version). | ||
pub fn is_in_effect(&self) -> bool { | ||
match self.since { | ||
DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT, | ||
DeprecatedSince::Future => false, | ||
// The `since` field doesn't have semantic purpose without `#![staged_api]`. | ||
DeprecatedSince::NonStandard(_) => true, | ||
// Assume deprecation is in effect if "since" field is absent or invalid. | ||
DeprecatedSince::Unspecified | DeprecatedSince::Err => true, | ||
} | ||
} | ||
|
||
pub fn is_since_rustc_version(&self) -> bool { | ||
matches!(self.since, DeprecatedSince::RustcVersion(_)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Centralized logic for parsing and validating all attributes used after HIR. | ||
//! | ||
//! History: Check out [#131229](https://github.com/rust-lang/rust/issues/131229). | ||
//! There used to be only one definition of attributes in the compiler: `ast::Attribute`. | ||
//! These were then parsed or validated or both in places distributed all over the compiler. | ||
//! | ||
//! Attributes are markers on items. Most are actually attribute-like proc-macros, and are expanded | ||
//! but some remain as the built-in attributes to guide compilation. | ||
//! | ||
//! In this crate, syntactical attributes (sequences of tokens that look like | ||
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items. | ||
//! Multiple syntactic attributes might influence a single semantic attribute. For example, | ||
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define | ||
//! a "stability". Stability defines an [`AttributeExtractor`](attributes::AttributeExtractor) | ||
//! that recognizes both `#[stable()]` and `#[unstable()]` syntactic attributes, and at the end | ||
//! produce a single [`ParsedAttributeKind::Stability`]. | ||
//! | ||
//! FIXME(jdonszelmann): update devguide for best practices on attributes | ||
//! FIXME(jdonszelmann): rename to `rustc_attr` in the future, integrating it into this crate. | ||
//! | ||
//! To define a new builtin, first add it | ||
// tidy-alphabetical-start | ||
#![allow(internal_features)] | ||
#![doc(rust_logo)] | ||
#![feature(let_chains)] | ||
#![feature(rustdoc_internals)] | ||
#![warn(unreachable_pub)] | ||
// tidy-alphabetical-end | ||
|
||
mod attributes; | ||
mod stability; | ||
mod version; | ||
|
||
pub use attributes::*; | ||
pub(crate) use rustc_session::HashStableContext; | ||
pub use stability::*; | ||
pub use version::*; |
Oops, something went wrong.