Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,3 +1211,12 @@ impl<S: Stage> SingleAttributeParser<S> for RustcReservationImplParser {
Some(AttributeKind::RustcReservationImpl(cx.attr_span, value_str))
}
}

pub(crate) struct PreludeImportParser;

impl<S: Stage> NoArgsAttributeParser<S> for PreludeImportParser {
const PATH: &[Symbol] = &[sym::prelude_import];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Use)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PreludeImport;
}
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ attribute_parsers!(
Single<WithoutArgs<PassByValueParser>>,
Single<WithoutArgs<PinV2Parser>>,
Single<WithoutArgs<PointeeParser>>,
Single<WithoutArgs<PreludeImportParser>>,
Single<WithoutArgs<ProcMacroAttributeParser>>,
Single<WithoutArgs<ProcMacroParser>>,
Single<WithoutArgs<ProfilerRuntimeParser>>,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,9 @@ pub enum AttributeKind {
/// Represents `#[pointee]`
Pointee(Span),

/// Represents `#[prelude_import]`
PreludeImport,

/// Represents `#[proc_macro]`
ProcMacro(Span),

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/attrs/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl AttributeKind {
PatternComplexityLimit { .. } => No,
PinV2(..) => Yes,
Pointee(..) => No,
PreludeImport => No,
ProcMacro(..) => No,
ProcMacroAttribute(..) => No,
ProcMacroDerive { .. } => No,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::PatternComplexityLimit { .. }
| AttributeKind::PinV2(..)
| AttributeKind::Pointee(..)
| AttributeKind::PreludeImport
| AttributeKind::ProfilerRuntime
| AttributeKind::RecursionLimit { .. }
| AttributeKind::ReexportTestHarnessMain(..)
Expand Down Expand Up @@ -394,7 +395,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// need to be fixed
| sym::deprecated_safe // FIXME(deprecated_safe)
// internal
| sym::prelude_import
| sym::panic_handler
| sym::lang
| sym::default_lib_allocator
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/delegation-inherit-attributes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![allow(incomplete_features)]
#![feature(fn_delegation)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the pretty printing change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsed attribute don't pretty print into valid syntax, this is fine because the hir-pretty is only meant to be developer readable and does not need to be valid Rust.

We can make pretty printers for parsed attributes, but we don't when we don't have a reason to

use std::prelude::rust_2021::*;

extern crate to_reuse_functions;
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/delegation-inline-attribute.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(incomplete_features)]
#![feature(fn_delegation)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

mod to_reuse {
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-delegation.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(incomplete_features)]
#![feature(fn_delegation)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

fn b<C>(e: C) { }
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-fn-params.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-fn-variadic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![feature(c_variadic)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-if-else.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-lifetimes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![allow(unused)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

struct Foo<'a> {
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-pretty-attr.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-pretty-loop.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/hir-struct-expr.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/issue-4264.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ pretty-compare-only
//@ pretty-mode:hir,typed
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/issue-85089.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
// Test to print lifetimes on HIR pretty-printing.

Expand Down
2 changes: 1 addition & 1 deletion tests/pretty/pin-ergonomics-hir.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(pin_ergonomics)]
#![allow(dead_code, incomplete_features)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

use std::pin::Pin;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-block-items/hir.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![feature(const_block_items)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

const _: () =
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/genercs-in-path-with-prettry-hir.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ edition: 2015
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/match/issue-82392.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
// https://github.com/rust-lang/rust/issues/82329
//@ compile-flags: -Zunpretty=hir,typed
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/type-alias-impl-trait/issue-60662.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![feature(type_alias_impl_trait)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

trait Animal { }
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/bad-literal.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-fail
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/debug-fmt-hir.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/deprecated-attr.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/diagnostic-attr.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/exhaustive-asm.hir.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use std::prelude::rust_2024::*;
//@ revisions: expanded hir
//@[expanded]compile-flags: -Zunpretty=expanded
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/unpretty/exhaustive.hir.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#![feature(yeet_expr)]
#![allow(incomplete_features)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use std::prelude::rust_2024::*;

mod prelude {
Expand All @@ -46,7 +46,7 @@ mod prelude {
}
}

#[prelude_import]
#[attr = PreludeImport]
use self::prelude::*;

/// inner single-line doc comment
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/flattened-format-args.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir -Zflatten-format-args=yes
//@ check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/let-else-hir.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-pass
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/self-hir.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;
//@ compile-flags: -Zunpretty=hir
//@ check-pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![expect(incomplete_features)]
#![allow(dead_code)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

use std::marker::ConstParamTy;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unpretty/unpretty-expr-fn-arg.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//@ edition: 2015
#![allow(dead_code)]
extern crate std;
#[prelude_import]
#[attr = PreludeImport]
use ::std::prelude::rust_2015::*;

fn main() ({ } as ())
Expand Down
Loading