Auto merge of #79519 - cjgillot:noattr, r=wesleywiser
Store HIR attributes in a side table Same idea as #72015 but for attributes. The objective is to reduce incr-comp invalidations due to modified attributes. Notably, those due to modified doc comments. Implementation: - collect attributes during AST->HIR lowering, in `LocalDefId -> ItemLocalId -> &[Attributes]` nested tables; - access the attributes through a `hir_owner_attrs` query; - local refactorings to use this access; - remove `attrs` from HIR data structures one-by-one. Change in behaviour: - the HIR visitor traverses all attributes at once instead of parent-by-parent; - attribute arrays are sometimes duplicated: for statements and variant constructors; - as a consequence, attributes are marked as used after unused-attribute lint emission to avoid duplicate lints. ~~Current bug: the lint level is not correctly applied in `std::backtrace_rs`, triggering an unused attribute warning on `#![no_std]`. I welcome suggestions.~~
This commit is contained in:
commit
dff1edf919
88 changed files with 936 additions and 920 deletions
|
@ -1466,11 +1466,12 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
|
|||
if self.span.map_or(true, |span| item.span < span) {
|
||||
if !item.span.from_expansion() {
|
||||
// Don't insert between attributes and an item.
|
||||
if item.attrs.is_empty() {
|
||||
let attrs = self.tcx.hir().attrs(item.hir_id());
|
||||
if attrs.is_empty() {
|
||||
self.span = Some(item.span.shrink_to_lo());
|
||||
} else {
|
||||
// Find the first attribute on the item.
|
||||
for attr in item.attrs {
|
||||
for attr in attrs {
|
||||
if self.span.map_or(true, |span| attr.span < span) {
|
||||
self.span = Some(attr.span.shrink_to_lo());
|
||||
}
|
||||
|
|
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
|
|||
hir_id: hir::HirId,
|
||||
) {
|
||||
assert!(
|
||||
matches!(fk, intravisit::FnKind::Closure(..)),
|
||||
matches!(fk, intravisit::FnKind::Closure),
|
||||
"visit_fn invoked for something other than a closure"
|
||||
);
|
||||
|
||||
|
|
|
@ -201,7 +201,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
|
|||
error = true;
|
||||
}
|
||||
|
||||
for attr in it.attrs {
|
||||
let attrs = tcx.hir().attrs(main_id);
|
||||
for attr in attrs {
|
||||
if tcx.sess.check_name(attr, sym::track_caller) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
|
@ -300,7 +301,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
|
|||
error = true;
|
||||
}
|
||||
|
||||
for attr in it.attrs {
|
||||
let attrs = tcx.hir().attrs(start_id);
|
||||
for attr in attrs {
|
||||
if tcx.sess.check_name(attr, sym::track_caller) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue