Skip to content

Commit

Permalink
fixup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Nov 4, 2024
1 parent 7885fc0 commit 23fb500
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 67 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ pub enum AttrStyle {
}

/// A list of attributes.
pub type AttrVec<A = Attribute> = ThinVec<A>;
pub type AttrVec = ThinVec<Attribute>;

/// A syntax-level representation of an attribute.
#[derive(Clone, Encodable, Decodable, Debug)]
Expand Down Expand Up @@ -3051,8 +3051,8 @@ impl VariantData {

/// An item definition.
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Item<K = ItemKind, A = Attribute> {
pub attrs: AttrVec<A>,
pub struct Item<K = ItemKind> {
pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
Expand Down
58 changes: 29 additions & 29 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,10 @@ impl AttrIdGenerator {
}

impl AttributeExt for Attribute {
fn id(&self) -> AttrId {
self.id
}

fn value_str(&self) -> Option<Symbol> {
match &self.kind {
AttrKind::Normal(normal) => normal.item.value_str(),
AttrKind::DocComment(..) => None,
}
}

fn value_span(&self) -> Option<Span> {
match &self.kind {
AttrKind::Normal(normal) => match &normal.item.args {
AttrArgs::Eq { eq_span: _, value } => Some(value.span),
_ => None,
},
AttrKind::DocComment(..) => None,
fn is_doc_comment(&self) -> bool {
match self.kind {
AttrKind::Normal(..) => false,
AttrKind::DocComment(..) => true,
}
}

Expand Down Expand Up @@ -106,17 +92,6 @@ impl AttributeExt for Attribute {
}
}

fn is_doc_comment(&self) -> bool {
match self.kind {
AttrKind::Normal(..) => false,
AttrKind::DocComment(..) => true,
}
}

fn span(&self) -> Span {
self.span
}

fn is_word(&self) -> bool {
if let AttrKind::Normal(normal) = &self.kind {
matches!(normal.item.args, AttrArgs::Empty)
Expand All @@ -132,6 +107,13 @@ impl AttributeExt for Attribute {
}
}

fn value_str(&self) -> Option<Symbol> {
match &self.kind {
AttrKind::Normal(normal) => normal.item.value_str(),
AttrKind::DocComment(..) => None,
}
}

/// Returns the documentation if this is a doc comment or a sugared doc comment.
/// * `///doc` returns `Some("doc")`.
/// * `#[doc = "doc"]` returns `Some("doc")`.
Expand All @@ -154,6 +136,20 @@ impl AttributeExt for Attribute {
}
}

fn value_span(&self) -> Option<Span> {
match &self.kind {
AttrKind::Normal(normal) => match &normal.item.args {
AttrArgs::Eq { eq_span: _, value } => Some(value.span),
_ => None,
},
AttrKind::DocComment(..) => None,
}
}

fn span(&self) -> Span {
self.span
}

fn style(&self) -> AttrStyle {
self.style
}
Expand All @@ -164,6 +160,10 @@ impl AttributeExt for Attribute {
AttrKind::DocComment(_, _) => None,
}
}

fn id(&self) -> AttrId {
self.id
}
}

impl Attribute {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_ast::attr::AttributeExt;
use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_session::lint::builtin::UNEXPECTED_CFGS;
use rustc_session::parse::feature_err;
use rustc_session::{RustcVersion, Session};
use rustc_span::hygiene::Transparency;
use rustc_span::symbol::{Ident, Symbol, Symbol, kw, kw, sym, sym};
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, Span};

use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
Expand Down Expand Up @@ -288,7 +288,7 @@ pub fn find_const_stability(
for attr in attrs {
match attr.name_or_empty() {
sym::rustc_promotable => promotable = true,
sym::rustc_const_stable_indirect => const_stable_indirect = Some(attr.span),
sym::rustc_const_stable_indirect => const_stable_indirect = Some(attr.span()),
sym::rustc_const_unstable => {
if const_stab.is_some() {
sess.dcx().emit_err(session_diagnostics::MultipleStabilityLevels {
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ use crate::mbe::macro_parser::NamedMatch::*;
use crate::mbe::macro_parser::{Error, ErrorReported, Failure, MatcherLoc, Success, TtParser};
use crate::mbe::transcribe::transcribe;

type Item<A> = ast::Item<ast::ItemKind, A>;

pub(crate) struct ParserAnyMacro<'a> {
parser: Parser<'a>,

Expand Down Expand Up @@ -368,12 +366,12 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
// Holy self-referential!

/// Converts a macro item into a syntax extension.
pub fn compile_declarative_macro<A: AttributeExt>(
pub fn compile_declarative_macro(
sess: &Session,
features: &Features,
macro_def: &ast::MacroDef,
ident: Ident,
attrs: &[ast::Attribute],
attrs: &[impl AttributeExt],
span: Span,
node_id: NodeId,
edition: Edition,
Expand Down Expand Up @@ -596,7 +594,7 @@ pub fn compile_declarative_macro<A: AttributeExt>(
(mk_syn_ext(expander), rule_spans)
}

fn check_lhs_nt_follows<A: AttributeExt>(
fn check_lhs_nt_follows(
sess: &Session,
node_id: NodeId,
lhs: &mbe::TokenTree,
Expand Down Expand Up @@ -674,7 +672,7 @@ fn check_rhs(sess: &Session, rhs: &mbe::TokenTree) -> Result<(), ErrorGuaranteed
}
}

fn check_matcher<A: AttributeExt>(
fn check_matcher(
sess: &Session,
node_id: NodeId,
matcher: &[mbe::TokenTree],
Expand Down Expand Up @@ -1016,7 +1014,7 @@ impl<'tt> TokenSet<'tt> {
//
// Requires that `first_sets` is pre-computed for `matcher`;
// see `FirstSets::new`.
fn check_matcher_core<'tt, A: AttributeExt>(
fn check_matcher_core<'tt>(
sess: &Session,
node_id: NodeId,
first_sets: &FirstSets<'tt>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_hir::{
};
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{Ident, Symbol, kw};
use rustc_span::{FileName, Span};
use {rustc_ast as ast, rustc_hir as hir};

pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {

/// FIXME(blyxyas): In a future revision, we should also graph #![allow]s,
/// but that is handled with more care
fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) {
fn visit_attribute(&mut self, attribute: &'tcx hir::Attribute) {
if matches!(
Level::from_attr(attribute),
Some(
Expand All @@ -382,10 +382,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
)
) {
let store = unerased_lint_store(self.tcx.sess);
let Some(meta) = attribute.meta() else { return };
// Lint attributes are always a metalist inside a
// metalist (even with just one lint).
let Some(meta_item_list) = meta.meta_item_list() else { return };
let Some(meta_item_list) = attribute.meta_item_list() else { return };

for meta_list in meta_item_list {
// Convert Path to String
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
}

pub enum LoadedMacro {
MacroDef { def: MacroDef, ident: Ident, attrs: AttrVec, span: Span, edition: Edition },
MacroDef {
def: MacroDef,
ident: Ident,
attrs: Vec<hir::Attribute>,
span: Span,
edition: Edition,
},
ProcMacro(SyntaxExtension),
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ impl<'a> CrateMetadataRef<'a> {
};

let sess = tcx.sess;
let attrs: Vec<_> = self.get_hir_attrs_for_def(id, sess).collect();
let attrs: Vec<_> = self.item_attrs(id, sess).collect();
SyntaxExtension::new(
sess,
tcx.features(),
Expand Down Expand Up @@ -1353,7 +1353,7 @@ impl<'a> CrateMetadataRef<'a> {
}
}

fn get_hir_attrs_for_def(
fn item_attrs(
self,
id: DefIndex,
sess: &'a Session,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ provide! { tcx, def_id, other, cdata,
}
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
hir_attrs_for_def => { tcx.arena.alloc_from_iter(cdata.get_hir_attrs_for_def(def_id.index, tcx.sess)) }
item_attrs => { tcx.arena.alloc_from_iter(cdata.item_attrs(def_id.index, tcx.sess)) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
cross_crate_inlinable => { table_direct }
Expand Down Expand Up @@ -593,7 +593,7 @@ impl CStore {
LoadedMacro::MacroDef {
def: data.get_macro(id.index, sess),
ident: data.item_ident(id.index, sess),
attrs: data.get_item_attrs(id.index, sess).collect(),
attrs: data.item_attrs(id.index, sess).collect(),
span: data.get_span(id.index, sess),
edition: data.root.edition,
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use rustc_middle::hir::nested_filter;
use rustc_span::def_id::StableCrateId;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{ErrorGuaranteed, Span};
use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};
use rustc_target::spec::abi::Abi;

use crate::hir::ModuleItems;
use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ rustc_queries! {
/// Returns the attributes on the item at `def_id`.
///
/// Do not use this directly, use `tcx.get_attrs` instead.
query hir_attrs_for_def(def_id: DefId) -> &'tcx [hir::Attribute] {
query item_attrs(def_id: DefId) -> &'tcx [hir::Attribute] {
desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::ops::{Bound, Deref};
use std::{fmt, iter, mem};

use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
use rustc_abi::{FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
use rustc_ast as ast;
use rustc_ast::attr::AttributeExt;
use rustc_data_structures::defer;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(did) = did.as_local() {
self.hir().attrs(self.local_def_id_to_hir_id(did))
} else {
self.hir_attrs_for_def(did)
self.item_attrs(did)
}
}

Expand All @@ -1765,7 +1765,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
} else {
debug_assert!(rustc_feature::encode_cross_crate(attr));
self.hir_attrs_for_def(did).iter().filter(filter_fn)
self.item_attrs(did).iter().filter(filter_fn)
}
}

Expand Down Expand Up @@ -1794,7 +1794,7 @@ impl<'tcx> TyCtxt<'tcx> {
// we filter out unstable diagnostic attributes before
// encoding attributes
debug_assert!(rustc_feature::encode_cross_crate(attr));
self.hir_attrs_for_def(did)
self.item_attrs(did)
.iter()
.find(|a| matches!(a.path().as_ref(), [sym::diagnostic, a] if *a == attr))
}
Expand All @@ -1812,7 +1812,7 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(did) = did.as_local() {
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
} else {
self.hir_attrs_for_def(did).iter().filter(filter_fn)
self.item_attrs(did).iter().filter(filter_fn)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/hir_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_assoc_item_constraint(self, constraint)
}

fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
fn visit_attribute(&mut self, attr: &'v hir::Attribute) {
self.record("Attribute", None, attr);
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/layout_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_abi::{HasDataLayout, TargetDataLayout};
use rustc_ast::attr::AttributeExt;
use rustc_hir::Attribute;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&mut self,
macro_def: &ast::MacroDef,
ident: Ident,
attrs: &[ast::Attribute],
attrs: &[impl AttributeExt],
span: Span,
node_id: NodeId,
edition: Edition,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
attrs: impl Iterator<Item = (&'a A, Option<DefId>)>,
doc_only: bool,
) -> (Vec<DocFragment>, ast::AttrVec<A>) {
) -> (Vec<DocFragment>, Vec<A>) {
let mut doc_fragments = Vec::new();
let mut other_attrs = ast::AttrVec::<A>::new();
let mut other_attrs = Vec::new();
for (attr, item_id) in attrs {
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
let doc = beautify_doc_string(doc_str, comment_kind);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
let attrs_iter = if let Some(did) = did.as_local() {
tcx.hir().attrs(tcx.local_def_id_to_hir_id(did)).iter().filter(filter_fn)
} else {
tcx.hir_attrs_for_def(did).iter().filter(filter_fn)
tcx.item_attrs(did).iter().filter(filter_fn)
};
attrs_iter
.map(|attribute| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::iter::once;
use std::sync::Arc;

use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::Mutability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId};
Expand All @@ -15,7 +16,6 @@ use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Symbol, sym};
use thin_vec::{ThinVec, thin_vec};
use tracing::{debug, trace};
use {rustc_ast as ast, rustc_hir as hir};

use super::Item;
use crate::clean::{
Expand Down
Loading

0 comments on commit 23fb500

Please sign in to comment.