Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco

don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
This commit is contained in:
bors 2022-05-12 12:48:30 +00:00
commit 481db40311
55 changed files with 455 additions and 467 deletions

View file

@ -551,7 +551,7 @@ impl MissingDoc {
}
}
let attrs = cx.tcx.get_attrs(def_id.to_def_id());
let attrs = cx.tcx.hir().attrs(cx.tcx.hir().local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.struct_span_lint(
@ -2738,11 +2738,7 @@ impl ClashingExternDeclarations {
// bottleneck, this does just fine.
(
overridden_link_name,
tcx.get_attrs(fi.def_id.to_def_id())
.iter()
.find(|at| at.has_name(sym::link_name))
.unwrap()
.span,
tcx.get_attr(fi.def_id.to_def_id(), sym::link_name).unwrap().span,
)
})
{