Change only_local to enum type and change the macros to always require a variant of that enum.
This commit is contained in:
parent
3cdcdaf31b
commit
db48dfcd03
4 changed files with 279 additions and 215 deletions
File diff suppressed because it is too large
Load diff
|
@ -124,7 +124,7 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZero<u
|
||||||
pub use accepted::ACCEPTED_FEATURES;
|
pub use accepted::ACCEPTED_FEATURES;
|
||||||
pub use builtin_attrs::AttributeDuplicates;
|
pub use builtin_attrs::AttributeDuplicates;
|
||||||
pub use builtin_attrs::{
|
pub use builtin_attrs::{
|
||||||
deprecated_attributes, find_gated_cfg, is_builtin_attr_name, is_builtin_only_local,
|
deprecated_attributes, encode_cross_crate, find_gated_cfg, is_builtin_attr_name,
|
||||||
is_valid_for_get_attr, AttributeGate, AttributeTemplate, AttributeType, BuiltinAttribute,
|
is_valid_for_get_attr, AttributeGate, AttributeTemplate, AttributeType, BuiltinAttribute,
|
||||||
GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
|
GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
|
||||||
};
|
};
|
||||||
|
|
|
@ -817,8 +817,8 @@ struct AnalyzeAttrState {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
|
fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
|
||||||
let mut should_encode = false;
|
let mut should_encode = false;
|
||||||
if rustc_feature::is_builtin_only_local(attr.name_or_empty()) {
|
if !rustc_feature::encode_cross_crate(attr.name_or_empty()) {
|
||||||
// Attributes marked local-only don't need to be encoded for downstream crates.
|
// Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.
|
||||||
} else if attr.doc_str().is_some() {
|
} else if attr.doc_str().is_some() {
|
||||||
// We keep all doc comments reachable to rustdoc because they might be "imported" into
|
// We keep all doc comments reachable to rustdoc because they might be "imported" into
|
||||||
// downstream crates if they use `#[doc(inline)]` to copy an item's documentation into
|
// downstream crates if they use `#[doc(inline)]` to copy an item's documentation into
|
||||||
|
|
|
@ -1752,9 +1752,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let filter_fn = move |a: &&ast::Attribute| a.has_name(attr);
|
let filter_fn = move |a: &&ast::Attribute| a.has_name(attr);
|
||||||
if let Some(did) = did.as_local() {
|
if let Some(did) = did.as_local() {
|
||||||
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
|
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
|
||||||
} else if cfg!(debug_assertions) && rustc_feature::is_builtin_only_local(attr) {
|
|
||||||
bug!("tried to access the `only_local` attribute `{}` from an extern crate", attr);
|
|
||||||
} else {
|
} else {
|
||||||
|
debug_assert!(rustc_feature::encode_cross_crate(attr));
|
||||||
self.item_attrs(did).iter().filter(filter_fn)
|
self.item_attrs(did).iter().filter(filter_fn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1786,13 +1785,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
/// Determines whether an item is annotated with an attribute.
|
/// Determines whether an item is annotated with an attribute.
|
||||||
pub fn has_attr(self, did: impl Into<DefId>, attr: Symbol) -> bool {
|
pub fn has_attr(self, did: impl Into<DefId>, attr: Symbol) -> bool {
|
||||||
let did: DefId = did.into();
|
|
||||||
if cfg!(debug_assertions) && !did.is_local() && rustc_feature::is_builtin_only_local(attr) {
|
|
||||||
bug!("tried to access the `only_local` attribute `{}` from an extern crate", attr);
|
|
||||||
} else {
|
|
||||||
self.get_attrs(did, attr).next().is_some()
|
self.get_attrs(did, attr).next().is_some()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this is an `auto trait`.
|
/// Returns `true` if this is an `auto trait`.
|
||||||
pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
|
pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue