Skip to content

Commit 94aff96

Browse files
committed
add map for eii ids in resolver
1 parent da1e442 commit 94aff96

File tree

15 files changed

+60
-12
lines changed

15 files changed

+60
-12
lines changed

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) mod allow_unstable;
2727
pub(crate) mod cfg;
2828
pub(crate) mod confusables;
2929
pub(crate) mod deprecation;
30+
pub(crate) mod eii;
3031
pub(crate) mod repr;
3132
pub(crate) mod stability;
3233
pub(crate) mod transparency;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1414
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1515
use crate::attributes::confusables::ConfusablesParser;
1616
use crate::attributes::deprecation::DeprecationParser;
17+
use crate::attributes::eii::EiiParser;
1718
use crate::attributes::repr::ReprParser;
1819
use crate::attributes::stability::{
1920
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
@@ -76,6 +77,7 @@ attribute_groups!(
7677
// tidy-alphabetical-start
7778
Single<ConstStabilityIndirectParser>,
7879
Single<DeprecationParser>,
80+
Single<RustcMacroEdition2021Parser>,
7981
Single<TransparencyParser>,
8082
// tidy-alphabetical-end
8183
];
@@ -209,7 +211,6 @@ impl<'sess> AttributeParser<'sess> {
209211
attrs: &'a [ast::Attribute],
210212
target_span: Span,
211213
omit_doc: OmitDoc,
212-
213214
lower_span: impl Copy + Fn(Span) -> Span,
214215
) -> Vec<Attribute> {
215216
let mut attributes = Vec::new();

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use rustc_serialize::{Decodable, Encodable};
5050
use rustc_session::lint::LintBuffer;
5151
pub use rustc_session::lint::RegisteredTools;
5252
use rustc_span::hygiene::MacroKind;
53-
use rustc_span::{DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
53+
use rustc_span::{EiiId, DUMMY_SP, ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
5454
pub use rustc_type_ir::data_structures::{DelayedMap, DelayedSet};
5555
#[allow(
5656
hidden_glob_reexports,
@@ -229,6 +229,9 @@ pub struct ResolverAstLowering {
229229

230230
/// Information about functions signatures for delegation items expansion
231231
pub delegation_fn_sigs: LocalDefIdMap<DelegationFnSig>,
232+
233+
/// Map of defids for all items marked with #[eii(<eii id>)].
234+
pub eii: FxHashMap<EiiId, LocalDefId>,
232235
}
233236

234237
#[derive(Debug)]

compiler/rustc_passes/src/check_attr.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
124124
AttributeKind::Stability { span, .. }
125125
| AttributeKind::ConstStability { span, .. },
126126
) => self.check_stability_promotable(*span, target),
127+
Attribute::Parsed(AttributeKind::Eii(attr_span)) => {
128+
self.check_eii(hir_id, *attr_span, span, target)
129+
}
127130
Attribute::Parsed(AttributeKind::AllowInternalUnstable(syms)) => self
128131
.check_allow_internal_unstable(
129132
hir_id,
@@ -474,6 +477,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
474477
}
475478
}
476479

480+
/// Checks if an `#[inline]` is applied to a function or a closure.
481+
fn check_eii(&self, _hir_id: HirId, _attr_span: Span, _defn_span: Span, target: Target) {
482+
match target {
483+
Target::ForeignFn => {}
484+
target => {
485+
// TODO:
486+
bug!("wrong target for EII: {target:?}");
487+
}
488+
}
489+
}
490+
477491
/// Checks that `#[coverage(..)]` is applied to a function/closure/method,
478492
/// or to an impl block or module.
479493
fn check_coverage(&self, attr: &Attribute, target_span: Span, target: Target) {

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use rustc_expand::expand::AstFragment;
88
use rustc_hir as hir;
99
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
1010
use rustc_hir::def_id::LocalDefId;
11+
use rustc_middle::bug;
1112
use rustc_span::hygiene::LocalExpnId;
12-
use rustc_span::{Span, Symbol, sym};
13+
use rustc_span::{EiiId, Span, Symbol, sym};
1314
use tracing::debug;
1415

1516
use crate::{ImplTraitContext, InvocationParent, Resolver};
@@ -137,6 +138,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
137138
&i.attrs,
138139
i.span,
139140
OmitDoc::Skip,
141+
None,
140142
std::convert::identity,
141143
);
142144

@@ -261,6 +263,22 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
261263

262264
let def = self.create_def(fi.id, Some(ident.name), def_kind, fi.span);
263265

266+
if let ForeignItemKind::Fn(_) = fi.kind {
267+
for attr in &fi.attrs {
268+
if attr.has_name(sym::eii)
269+
&& let Some([arg]) = attr.meta_item_list().as_deref()
270+
&& let Some(lit) = arg.lit()
271+
&& let LitKind::Int(i, _) = lit.kind
272+
&& let Ok(id) = u32::try_from(i.get())
273+
{
274+
let id = EiiId::from(id);
275+
if let Some(other) = self.resolver.eii.insert(id, def) {
276+
bug!("{def:?}: {id:?} used more than once (used first on {other:?})");
277+
}
278+
}
279+
}
280+
}
281+
264282
self.with_parent(def, |this| visit::walk_item(this, fi));
265283
}
266284

compiler/rustc_resolve/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use rustc_query_system::ich::StableHashingContext;
7171
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7272
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
7373
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
74-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
74+
use rustc_span::{DUMMY_SP, EiiId, Ident, Span, Symbol, kw, sym};
7575
use smallvec::{SmallVec, smallvec};
7676
use tracing::debug;
7777

@@ -1225,6 +1225,9 @@ pub struct Resolver<'ra, 'tcx> {
12251225
current_crate_outer_attr_insert_span: Span,
12261226

12271227
mods_with_parse_errors: FxHashSet<DefId>,
1228+
1229+
/// Map of defids for all items marked with #[eii(<eii id>)].
1230+
eii: FxHashMap<EiiId, LocalDefId>,
12281231
}
12291232

12301233
/// This provides memory for the rest of the crate. The `'ra` lifetime that is
@@ -1580,6 +1583,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15801583
impl_binding_keys: Default::default(),
15811584
current_crate_outer_attr_insert_span,
15821585
mods_with_parse_errors: Default::default(),
1586+
eii: Default::default(),
15831587
};
15841588

15851589
let root_parent_scope = ParentScope::module(graph_root, &resolver);
@@ -1694,6 +1698,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16941698
lifetime_elision_allowed: self.lifetime_elision_allowed,
16951699
lint_buffer: Steal::new(self.lint_buffer),
16961700
delegation_fn_sigs: self.delegation_fn_sigs,
1701+
eii: self.eii,
16971702
};
16981703
ResolverOutputs { global_ctxt, ast_lowering }
16991704
}

compiler/rustc_span/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,12 @@ rustc_index::newtype_index! {
11811181
pub struct AttrId {}
11821182
}
11831183

1184+
rustc_index::newtype_index! {
1185+
#[orderable]
1186+
#[debug_format = "EiiId({})"]
1187+
pub struct EiiId {}
1188+
}
1189+
11841190
/// This trait is used to allow encoder specific encodings of certain types.
11851191
/// It is similar to rustc_type_ir's TyEncoder.
11861192
pub trait SpanEncoder: Encoder {

library/stdarch

Submodule stdarch updated 85 files

src/doc/nomicon

0 commit comments

Comments
 (0)