Skip to content

Commit 79d8734

Browse files
authored
Unrolled build for #155789
Rollup merge of #155789 - JonathanBrouwer:attribute-ext, r=mejrs Cleanups to `AttributeExt` r? @mejrs - Makes some functions take `ast::Attribute` instead of `impl AttributeExt` - Remove `deprecation_note` from `AttributeExt`, since the two implementations are basically seperate
2 parents d4f7856 + e3b0e9d commit 79d8734

5 files changed

Lines changed: 37 additions & 56 deletions

File tree

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -235,34 +235,6 @@ impl AttributeExt for Attribute {
235235
}
236236
}
237237

238-
fn deprecation_note(&self) -> Option<Ident> {
239-
match &self.kind {
240-
AttrKind::Normal(normal) if normal.item.path == sym::deprecated => {
241-
let meta = &normal.item;
242-
243-
// #[deprecated = "..."]
244-
if let Some(s) = meta.value_str() {
245-
return Some(Ident { name: s, span: meta.span() });
246-
}
247-
248-
// #[deprecated(note = "...")]
249-
if let Some(list) = meta.meta_item_list() {
250-
for nested in list {
251-
if let Some(mi) = nested.meta_item()
252-
&& mi.path == sym::note
253-
&& let Some(s) = mi.value_str()
254-
{
255-
return Some(Ident { name: s, span: mi.span });
256-
}
257-
}
258-
}
259-
260-
None
261-
}
262-
_ => None,
263-
}
264-
}
265-
266238
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
267239
match &self.kind {
268240
AttrKind::DocComment(..) => Some(self.style),
@@ -341,6 +313,34 @@ impl Attribute {
341313
)],
342314
}
343315
}
316+
317+
pub fn deprecation_note(&self) -> Option<Ident> {
318+
match &self.kind {
319+
AttrKind::Normal(normal) if normal.item.path == sym::deprecated => {
320+
let meta = &normal.item;
321+
322+
// #[deprecated = "..."]
323+
if let Some(s) = meta.value_str() {
324+
return Some(Ident { name: s, span: meta.span() });
325+
}
326+
327+
// #[deprecated(note = "...")]
328+
if let Some(list) = meta.meta_item_list() {
329+
for nested in list {
330+
if let Some(mi) = nested.meta_item()
331+
&& mi.path == sym::note
332+
&& let Some(s) = mi.value_str()
333+
{
334+
return Some(Ident { name: s, span: mi.span });
335+
}
336+
}
337+
}
338+
339+
None
340+
}
341+
_ => None,
342+
}
343+
}
344344
}
345345

346346
impl AttrItem {
@@ -824,19 +824,19 @@ pub fn mk_attr_name_value_str(
824824
mk_attr(g, style, unsafety, path, args, span)
825825
}
826826

827-
pub fn filter_by_name<A: AttributeExt>(attrs: &[A], name: Symbol) -> impl Iterator<Item = &A> {
827+
pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {
828828
attrs.iter().filter(move |attr| attr.has_name(name))
829829
}
830830

831-
pub fn find_by_name<A: AttributeExt>(attrs: &[A], name: Symbol) -> Option<&A> {
831+
pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
832832
filter_by_name(attrs, name).next()
833833
}
834834

835-
pub fn first_attr_value_str_by_name(attrs: &[impl AttributeExt], name: Symbol) -> Option<Symbol> {
835+
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: Symbol) -> Option<Symbol> {
836836
find_by_name(attrs, name).and_then(|attr| attr.value_str())
837837
}
838838

839-
pub fn contains_name(attrs: &[impl AttributeExt], name: Symbol) -> bool {
839+
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
840840
find_by_name(attrs, name).is_some()
841841
}
842842

@@ -911,11 +911,6 @@ pub trait AttributeExt: Debug {
911911
/// * `#[doc(...)]` returns `None`.
912912
fn doc_str(&self) -> Option<Symbol>;
913913

914-
/// Returns the deprecation note if this is deprecation attribute.
915-
/// * `#[deprecated = "note"]` returns `Some("note")`.
916-
/// * `#[deprecated(note = "note", ...)]` returns `Some("note")`.
917-
fn deprecation_note(&self) -> Option<Ident>;
918-
919914
/// Returns whether this attribute is any of the proc macro attributes.
920915
/// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`.
921916
fn is_proc_macro_attr(&self) -> bool {

compiler/rustc_attr_parsing/src/attributes/util.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::num::IntErrorKind;
22

3-
use rustc_ast::LitKind;
4-
use rustc_ast::attr::AttributeExt;
3+
use rustc_ast::{LitKind, ast};
54
use rustc_feature::is_builtin_attr_name;
65
use rustc_hir::RustcVersion;
76
use rustc_hir::limit::Limit;
@@ -27,8 +26,8 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
2726
Some(RustcVersion { major, minor, patch })
2827
}
2928

30-
pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool {
31-
attr.is_doc_comment().is_some() || attr.name().is_some_and(|name| is_builtin_attr_name(name))
29+
pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
30+
attr.is_doc_comment() || attr.name().is_some_and(|name| is_builtin_attr_name(name))
3231
}
3332

3433
/// Parse a single integer.

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,6 @@ impl AttributeExt for Attribute {
14241424
}
14251425
}
14261426

1427-
#[inline]
1428-
fn deprecation_note(&self) -> Option<Ident> {
1429-
match &self {
1430-
Attribute::Parsed(AttributeKind::Deprecated { deprecation, .. }) => deprecation.note,
1431-
_ => None,
1432-
}
1433-
}
1434-
14351427
fn is_automatically_derived_attr(&self) -> bool {
14361428
matches!(self, Attribute::Parsed(AttributeKind::AutomaticallyDerived(..)))
14371429
}

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub fn may_be_doc_link(link_type: LinkType) -> bool {
409409

410410
/// Simplified version of `preprocessed_markdown_links` from rustdoc.
411411
/// Must return at least the same links as it, but may add some more links on top of that.
412-
pub(crate) fn attrs_to_preprocessed_links<A: AttributeExt + Clone>(attrs: &[A]) -> Vec<Box<str>> {
412+
pub(crate) fn attrs_to_preprocessed_links(attrs: &[ast::Attribute]) -> Vec<Box<str>> {
413413
let (doc_fragments, other_attrs) =
414414
attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), false);
415415
let mut doc =

src/librustdoc/clean/types.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use arrayvec::ArrayVec;
88
use itertools::Either;
99
use rustc_abi::{ExternAbi, VariantIdx};
1010
use rustc_ast as ast;
11-
use rustc_ast::attr::AttributeExt;
1211
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1312
use rustc_data_structures::thin_vec::ThinVec;
1413
use rustc_hir as hir;
@@ -501,11 +500,7 @@ impl Item {
501500
}
502501

503502
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
504-
let deprecation_notes = self
505-
.attrs
506-
.other_attrs
507-
.iter()
508-
.filter_map(|attr| attr.deprecation_note().map(|note| note.span));
503+
let deprecation_notes = find_attr!(&self.attrs.other_attrs, Deprecated { deprecation, .. } => deprecation.note.map(|note| note.span)).flatten();
509504

510505
span_of_fragments(&self.attrs.doc_strings)
511506
.into_iter()

0 commit comments

Comments
 (0)