Skip to content

Outer attribute spans on items are never lowered correctly #150400

Description

@JonathanBrouwer

In the following rust file:

#[cfg(true)]
pub fn main() {
}

The function main has a different HIR stable hash than in the following rust file

// Whitespace here
#[cfg(true)]
pub fn main() {
}

This is because in the HIR, during attribute lowering, attributes are hashed relative to their parents definition's span. For outer attributes, their parent definition is the definition they're placed on. However, their parent definition's span does not actually include outer attributes.

This causes the following check to fail:

if def_span.contains(span) {

Meaning the attribute is not hashed relative to its parent. This could potentially have very significant performance implications for incremental.

cc @jdonszelmann as a person who knows about attributes
cc @cjgillot as the author of #84373, what do you think is a good fix for this?

The easiest fix is probably to allow for negative numbers in relative encoding. I'll try to make a PR for this later,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-incr-compArea: Incremental compilation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions