Skip to content

Commit 9e0a05b

Browse files
authored
Rollup merge of #152550 - Ozzy1423:rustc-attrs, r=JonathanBrouwer
Port #[prelude_import] to the attribute parser Tracking issue: #131229 r? @JonathanBrouwer Didn't change any use-sites of it in the compiler
2 parents 5266800 + dd8a98a commit 9e0a05b

33 files changed

Lines changed: 44 additions & 30 deletions

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,3 +1211,12 @@ impl<S: Stage> SingleAttributeParser<S> for RustcReservationImplParser {
12111211
Some(AttributeKind::RustcReservationImpl(cx.attr_span, value_str))
12121212
}
12131213
}
1214+
1215+
pub(crate) struct PreludeImportParser;
1216+
1217+
impl<S: Stage> NoArgsAttributeParser<S> for PreludeImportParser {
1218+
const PATH: &[Symbol] = &[sym::prelude_import];
1219+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
1220+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Use)]);
1221+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PreludeImport;
1222+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ attribute_parsers!(
258258
Single<WithoutArgs<PassByValueParser>>,
259259
Single<WithoutArgs<PinV2Parser>>,
260260
Single<WithoutArgs<PointeeParser>>,
261+
Single<WithoutArgs<PreludeImportParser>>,
261262
Single<WithoutArgs<ProcMacroAttributeParser>>,
262263
Single<WithoutArgs<ProcMacroParser>>,
263264
Single<WithoutArgs<ProfilerRuntimeParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,9 @@ pub enum AttributeKind {
10531053
/// Represents `#[pointee]`
10541054
Pointee(Span),
10551055

1056+
/// Represents `#[prelude_import]`
1057+
PreludeImport,
1058+
10561059
/// Represents `#[proc_macro]`
10571060
ProcMacro(Span),
10581061

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl AttributeKind {
8282
PatternComplexityLimit { .. } => No,
8383
PinV2(..) => Yes,
8484
Pointee(..) => No,
85+
PreludeImport => No,
8586
ProcMacro(..) => No,
8687
ProcMacroAttribute(..) => No,
8788
ProcMacroDerive { .. } => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
282282
| AttributeKind::PatternComplexityLimit { .. }
283283
| AttributeKind::PinV2(..)
284284
| AttributeKind::Pointee(..)
285+
| AttributeKind::PreludeImport
285286
| AttributeKind::ProfilerRuntime
286287
| AttributeKind::RecursionLimit { .. }
287288
| AttributeKind::ReexportTestHarnessMain(..)
@@ -394,7 +395,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
394395
// need to be fixed
395396
| sym::deprecated_safe // FIXME(deprecated_safe)
396397
// internal
397-
| sym::prelude_import
398398
| sym::panic_handler
399399
| sym::lang
400400
| sym::default_lib_allocator

tests/pretty/delegation-inherit-attributes.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![allow(incomplete_features)]
88
#![feature(fn_delegation)]
99
extern crate std;
10-
#[prelude_import]
10+
#[attr = PreludeImport]
1111
use std::prelude::rust_2021::*;
1212

1313
extern crate to_reuse_functions;

tests/pretty/delegation-inline-attribute.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![allow(incomplete_features)]
66
#![feature(fn_delegation)]
77
extern crate std;
8-
#[prelude_import]
8+
#[attr = PreludeImport]
99
use ::std::prelude::rust_2015::*;
1010

1111
mod to_reuse {

tests/pretty/hir-delegation.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![allow(incomplete_features)]
66
#![feature(fn_delegation)]
77
extern crate std;
8-
#[prelude_import]
8+
#[attr = PreludeImport]
99
use ::std::prelude::rust_2015::*;
1010

1111
fn b<C>(e: C) { }

tests/pretty/hir-fn-params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate std;
2-
#[prelude_import]
2+
#[attr = PreludeImport]
33
use ::std::prelude::rust_2015::*;
44
//@ pretty-compare-only
55
//@ pretty-mode:hir

tests/pretty/hir-fn-variadic.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#![feature(c_variadic)]
66
extern crate std;
7-
#[prelude_import]
7+
#[attr = PreludeImport]
88
use ::std::prelude::rust_2015::*;
99

1010
extern "C" {

0 commit comments

Comments
 (0)