Skip to content

Commit 0db2eb7

Browse files
committed
port #[no_std] to the new attribute parsing infrastructure
1 parent b262cae commit 0db2eb7

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,14 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoCoreParser {
188188
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
189189
const TYPE: AttributeType = AttributeType::CrateLevel;
190190
}
191+
192+
pub(crate) struct NoStdParser;
193+
impl<S: Stage> NoArgsAttributeParser<S> for NoStdParser {
194+
const PATH: &[Symbol] = &[sym::no_std];
195+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
196+
// FIXME: recursion limit is allowed on all targets and ignored,
197+
// even though it should only be valid on crates of course
198+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
199+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
200+
const TYPE: AttributeType = AttributeType::CrateLevel;
201+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::attributes::codegen_attrs::{
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
2727
use crate::attributes::crate_level::{
28-
CrateNameParser, MoveSizeLimitParser, NoCoreParser, PatternComplexityLimitParser,
28+
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoStdParser, PatternComplexityLimitParser,
2929
RecursionLimitParser, TypeLengthLimitParser,
3030
};
3131
use crate::attributes::deprecation::DeprecationParser;
@@ -225,6 +225,7 @@ attribute_parsers!(
225225
Single<WithoutArgs<NoCoreParser>>,
226226
Single<WithoutArgs<NoImplicitPreludeParser>>,
227227
Single<WithoutArgs<NoMangleParser>>,
228+
Single<WithoutArgs<NoStdParser>>,
228229
Single<WithoutArgs<NonExhaustiveParser>>,
229230
Single<WithoutArgs<ParenSugarParser>>,
230231
Single<WithoutArgs<PassByValueParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ pub enum AttributeKind {
588588
/// Represents `#[no_mangle]`
589589
NoMangle(Span),
590590

591+
/// Represents `#[no_std]`
592+
NoStd(Span),
593+
591594
/// Represents `#[non_exhaustive]`
592595
NonExhaustive(Span),
593596

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ impl AttributeKind {
6666
Naked(..) => No,
6767
NoCore(..) => No,
6868
NoImplicitPrelude(..) => No,
69-
NoMangle(..) => Yes, // Needed for rustdoc
69+
NoMangle(..) => Yes, // Needed for rustdoc
70+
NoStd(..) => No,
7071
NonExhaustive(..) => Yes, // Needed for rustdoc
7172
Optimize(..) => No,
7273
ParenSugar(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
275275
| AttributeKind::TypeLengthLimit { .. }
276276
| AttributeKind::PatternComplexityLimit { .. }
277277
| AttributeKind::NoCore { .. }
278+
| AttributeKind::NoStd { .. }
278279
) => { /* do nothing */ }
279280
Attribute::Unparsed(attr_item) => {
280281
style = Some(attr_item.style);

0 commit comments

Comments
 (0)