Skip to content
Merged
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
6 changes: 5 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4168,6 +4168,7 @@ dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_hir",
"rustc_span",
]
Expand Down Expand Up @@ -4732,6 +4733,7 @@ dependencies = [
"rustc_arena",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr_ir",
"rustc_attr_parsing",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -4848,6 +4850,7 @@ dependencies = [
"punycode",
"rustc-demangle",
"rustc_abi",
"rustc_attr_ir",
"rustc_data_structures",
"rustc_hashes",
"rustc_hir",
Expand Down Expand Up @@ -4947,8 +4950,8 @@ version = "0.0.0"
dependencies = [
"itertools",
"rustc_abi",
"rustc_attr_ir",
"rustc_data_structures",
"rustc_hir",
"rustc_middle",
"rustc_span",
"smallvec",
Expand All @@ -4961,6 +4964,7 @@ version = "0.0.0"
dependencies = [
"itertools",
"rustc_abi",
"rustc_attr_ir",
"rustc_data_structures",
"rustc_errors",
"rustc_hashes",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind};
use rustc_attr_ir::target::Target;
use rustc_hir as hir;
use rustc_hir::Target;
use rustc_span::sym;
use smallvec::SmallVec;

Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_ast_lowering/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use rustc_hir::attrs::lang_items::LangItem;
use rustc_attr_ir::lang_items::LangItem;
use rustc_attr_ir::target::Target;
use thin_vec::thin_vec;

use crate::LoweringContext;
Expand Down Expand Up @@ -209,15 +210,15 @@ impl<'hir> LoweringContext<'_, 'hir> {

let postcond_checker = self.arena.alloc(self.expr_enum_variant_lang_item(
postcond_checker.span,
rustc_hir::attrs::lang_items::LangItem::OptionSome,
LangItem::OptionSome,
&*arena_vec![self; *postcond_checker],
));
let then_block_stmts = self.block_all(span, stmts, Some(postcond_checker));
let then_block = self.arena.alloc(self.expr_block(&then_block_stmts));

let none_expr = self.arena.alloc(self.expr_enum_variant_lang_item(
postcond_checker.span,
rustc_hir::attrs::lang_items::LangItem::OptionNone,
LangItem::OptionNone,
Default::default(),
));
let else_block = self.block_expr(none_expr);
Expand Down Expand Up @@ -350,7 +351,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
));

let attrs: rustc_ast::AttrVec = thin_vec![self.unreachable_code_attr(span)];
self.lower_attrs(contract_check.hir_id, &attrs, span, rustc_hir::Target::Expression);
self.lower_attrs(contract_check.hir_id, &attrs, span, Target::Expression);

let ret_block = self.block_all(span, arena_vec![self; ret_stmt], Some(contract_check));
self.arena.alloc(self.expr_block(self.arena.alloc(ret_block)))
Expand Down
26 changes: 15 additions & 11 deletions compiler/rustc_ast_lowering/src/delegation/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
use rustc_attr_ir::{AttributeKind, InlineAttr};
use rustc_hir as hir;
use rustc_hir::attrs::{AttributeKind, InlineAttr};
use rustc_span::Span;
use rustc_span::def_id::DefId;

use crate::LoweringContext;
use crate::delegation::DelegationResolution;

struct AdditionInfo {
pub equals: fn(&hir::Attribute) -> bool,
pub equals: fn(&rustc_attr_ir::Attribute) -> bool,
pub kind: AdditionKind,
}

enum AdditionKind {
Default { factory: fn(Span) -> hir::Attribute },
Inherit { factory: fn(Span, &hir::Attribute) -> hir::Attribute },
Default { factory: fn(Span) -> rustc_attr_ir::Attribute },
Inherit { factory: fn(Span, &rustc_attr_ir::Attribute) -> rustc_attr_ir::Attribute },
}

static ADDITIONS: &[AdditionInfo] = &[
AdditionInfo {
equals: |a| matches!(a, hir::Attribute::Parsed(AttributeKind::MustUse { .. })),
equals: |a| matches!(a, rustc_attr_ir::Attribute::Parsed(AttributeKind::MustUse { .. })),
kind: AdditionKind::Inherit {
factory: |span, original_attr| {
let reason = match original_attr {
hir::Attribute::Parsed(AttributeKind::MustUse { reason, .. }) => *reason,
rustc_attr_ir::Attribute::Parsed(AttributeKind::MustUse { reason, .. }) => {
*reason
}
_ => None,
};

hir::Attribute::Parsed(AttributeKind::MustUse { span, reason })
rustc_attr_ir::Attribute::Parsed(AttributeKind::MustUse { span, reason })
},
},
},
AdditionInfo {
equals: |a| matches!(a, hir::Attribute::Parsed(AttributeKind::Inline(..))),
equals: |a| matches!(a, rustc_attr_ir::Attribute::Parsed(AttributeKind::Inline(..))),
kind: AdditionKind::Default {
factory: |span| hir::Attribute::Parsed(AttributeKind::Inline(InlineAttr::Hint, span)),
factory: |span| {
rustc_attr_ir::Attribute::Parsed(AttributeKind::Inline(InlineAttr::Hint, span))
},
},
},
];
Expand Down Expand Up @@ -61,8 +65,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
&self,
span: Span,
sig_id: DefId,
existing: Option<&&[hir::Attribute]>,
) -> Vec<hir::Attribute> {
existing: Option<&&[rustc_attr_ir::Attribute]>,
) -> Vec<rustc_attr_ir::Attribute> {
ADDITIONS
.iter()
.filter_map(|addition| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/delegation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use hir::def::Res;
use rustc_abi::ExternAbi;
use rustc_ast as ast;
use rustc_ast::*;
use rustc_hir::attrs::lang_items::LangItem;
use rustc_attr_ir::lang_items::LangItem;
use rustc_hir::def::DefKind;
use rustc_hir::{self as hir, FnDeclFlags, QPath};
use rustc_middle::ty::Asyncness;
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_ast_lowering/src/expr/closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use rustc_ast::*;
use rustc_attr_ir::find_attr;
use rustc_attr_ir::target::Target;
use rustc_hir as hir;
use rustc_hir::{HirId, Target, find_attr};
use rustc_hir::HirId;
use rustc_span::{Span, span_bug};

use super::{LoweringContext, MoveExprState};
Expand Down Expand Up @@ -55,7 +57,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_coroutine_closure_with_move_exprs(
&mut self,
expr_hir_id: HirId,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
binder: &ClosureBinder,
capture_clause: CaptureBy,
closure_id: NodeId,
Expand Down Expand Up @@ -114,7 +116,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_plain_closure_with_move_exprs(
&mut self,
expr_hir_id: HirId,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
binder: &ClosureBinder,
capture_clause: CaptureBy,
closure_id: NodeId,
Expand Down Expand Up @@ -153,7 +155,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// local uses and the caller can later add the matching initializers.
fn lower_expr_closure(
&mut self,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
binder: &ClosureBinder,
capture_clause: CaptureBy,
closure_id: NodeId,
Expand Down Expand Up @@ -283,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: &Expr,
fn_decl_span: Span,
fn_arg_span: Span,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
) -> hir::ExprKind<'hir> {
let closure_def_id = self.local_def_id(closure_id);
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::borrow::Cow;

use rustc_ast::*;
use rustc_attr_ir::lang_items::LangItem;
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir;
use rustc_hir::attrs::lang_items::LangItem;
use rustc_session::config::FmtDebug;
use rustc_span::{ByteSymbol, DesugaringKind, Ident, Span, Symbol, sym};

Expand Down
39 changes: 22 additions & 17 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use rustc_abi::ExternAbi;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
use rustc_attr_ir::target::Target;
use rustc_attr_ir::{AttributeKind, EiiImplResolution, find_attr};
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
use rustc_hir::attrs::{AttributeKind, EiiImplResolution};
use rustc_hir::def::{DefKind, PerNS, Res};
use rustc_hir::{
self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
};
use rustc_hir::{self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin};
use rustc_middle::ty::data_structures::IndexMap;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::edit_distance::find_best_match_for_name;
Expand Down Expand Up @@ -68,8 +67,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId,
name: Ident,
EiiDecl { foreign_item, impl_unsafe }: &EiiDecl,
) -> Option<hir::attrs::EiiDecl> {
self.lower_path_simple_eii(id, foreign_item).map(|did| hir::attrs::EiiDecl {
) -> Option<rustc_attr_ir::EiiDecl> {
self.lower_path_simple_eii(id, foreign_item).map(|did| rustc_attr_ir::EiiDecl {
foreign_item: did,
impl_unsafe: *impl_unsafe,
name,
Expand All @@ -87,7 +86,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
is_default,
known_eii_macro_resolution,
}: &EiiImpl,
) -> hir::attrs::EiiImpl {
) -> rustc_attr_ir::EiiImpl {
let resolution = if let Some(target) = known_eii_macro_resolution
&& let Some(foreign_item_did) = self.lower_path_simple_eii(*node_id, target)
{
Expand All @@ -100,7 +99,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
};

hir::attrs::EiiImpl {
rustc_attr_ir::EiiImpl {
span: self.lower_span(*span),
inner_span: self.lower_span(*inner_span),
impl_unsafe_span: match *impl_safety {
Expand All @@ -116,19 +115,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self,
id: NodeId,
i: &ItemKind,
) -> Vec<hir::Attribute> {
) -> Vec<rustc_attr_ir::Attribute> {
match i {
ItemKind::Fn(Fn { eii_impl: None, .. })
| ItemKind::Static(StaticItem { eii_impl: None, .. }) => Vec::new(),
ItemKind::Fn(Fn { eii_impl: Some(eii_impl), .. })
| ItemKind::Static(StaticItem { eii_impl: Some(eii_impl), .. }) => {
vec![hir::Attribute::Parsed(AttributeKind::EiiImpl(Box::new(
vec![rustc_attr_ir::Attribute::Parsed(AttributeKind::EiiImpl(Box::new(
self.lower_eii_impl(eii_impl),
)))]
}
ItemKind::MacroDef(name, MacroDef { eii_declaration: Some(target), .. }) => self
.lower_eii_decl(id, *name, target)
.map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiDeclaration(decl))])
.map(|decl| {
vec![rustc_attr_ir::Attribute::Parsed(AttributeKind::EiiDeclaration(decl))]
})
.unwrap_or_default(),

ItemKind::ExternCrate(..)
Expand Down Expand Up @@ -184,7 +185,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: Span,
id: NodeId,
hir_id: hir::HirId,
attrs: &'hir [hir::Attribute],
attrs: &'hir [rustc_attr_ir::Attribute],
vis_span: Span,
i: &ItemKind,
) -> hir::ItemKind<'hir> {
Expand Down Expand Up @@ -551,7 +552,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
prefix: &Path,
id: NodeId,
vis_span: Span,
attrs: &'hir [hir::Attribute],
attrs: &'hir [rustc_attr_ir::Attribute],
) -> hir::ItemKind<'hir> {
let path = &tree.prefix;
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
Expand Down Expand Up @@ -1351,7 +1352,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
decl: &FnDecl,
coroutine_marker: Option<CoroutineMarker>,
body: Option<&Block>,
attrs: &'hir [hir::Attribute],
attrs: &'hir [rustc_attr_ir::Attribute],
contract: Option<&FnContract>,
) -> hir::BodyId {
let Some(body) = body else {
Expand Down Expand Up @@ -1612,7 +1613,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId,
kind: FnDeclKind,
coroutine_marker: Option<CoroutineMarker>,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
let header = self.lower_fn_header(sig.header, hir::Safety::Safe, attrs);
let itctx = ImplTraitContext::Universal;
Expand All @@ -1626,7 +1627,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self,
h: FnHeader,
default_safety: hir::Safety,
attrs: &[hir::Attribute],
attrs: &[rustc_attr_ir::Attribute],
) -> hir::FnHeader {
let asyncness = if let Some(coroutine_marker) = h.coroutine_marker
&& let CoroutineKind::Async = coroutine_marker.kind
Expand Down Expand Up @@ -1713,7 +1714,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// Lowers constness or comptime attribute.
/// Whether `const` is allowed here is checked by ast validation.
/// Whether `comptime` is allowed here is checked by the `comptime` attribute parser.
pub(super) fn lower_constness(&mut self, attrs: &[hir::Attribute], c: Const) -> hir::Constness {
pub(super) fn lower_constness(
&mut self,
attrs: &[rustc_attr_ir::Attribute],
c: Const,
) -> hir::Constness {
let mut constness = match c {
Const::Yes(_) => hir::Constness::Const { always: false },
Const::No => hir::Constness::NotConst,
Expand Down
Loading
Loading