Skip to content

Commit 7a4f708

Browse files
committed
make eiiid map
1 parent 49b276b commit 7a4f708

File tree

9 files changed

+28
-10
lines changed

9 files changed

+28
-10
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_resolve/src/def_collector.rs

Lines changed: 18 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};
@@ -259,6 +260,22 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
259260

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

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

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::cell::{Cell, RefCell};
2727
use std::collections::BTreeSet;
2828
use std::fmt;
2929
use std::sync::Arc;
30-
use rustc_span::EiiId,
3130

3231
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
3332
use effective_visibilities::EffectiveVisibilitiesVisitor;
@@ -69,7 +68,7 @@ use rustc_query_system::ich::StableHashingContext;
6968
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7069
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
7170
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
72-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
71+
use rustc_span::{DUMMY_SP, EiiId, Ident, Span, Symbol, kw, sym};
7372
use smallvec::{SmallVec, smallvec};
7473
use tracing::debug;
7574

@@ -1238,7 +1237,7 @@ pub struct Resolver<'ra, 'tcx> {
12381237
mods_with_parse_errors: FxHashSet<DefId>,
12391238

12401239
/// Map of defids for all items marked with #[eii(<eii id>)].
1241-
eii: FxHashMap<EiiId, DefId>,
1240+
eii: FxHashMap<EiiId, LocalDefId>,
12421241
}
12431242

12441243
/// This provides memory for the rest of the crate. The `'ra` lifetime that is
@@ -1585,6 +1584,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15851584
impl_binding_keys: Default::default(),
15861585
current_crate_outer_attr_insert_span,
15871586
mods_with_parse_errors: Default::default(),
1587+
eii: Default::default(),
15881588
};
15891589

15901590
let root_parent_scope = ParentScope::module(graph_root, &resolver);

src/doc/book

Submodule book updated 699 files

src/doc/reference

Submodule reference updated 56 files

src/tools/cargo

Submodule cargo updated 62 files

0 commit comments

Comments
 (0)