Skip to content

Collect tokens for inner attributes at crate or outline module root #84163

Open
@Aaron1011

Description

@Aaron1011
Member

Currently, custom inner attributes at the crate or outline module root do not have tokens collected:

if let Annotatable::Item(item_inner) = &item {
if let ItemKind::Mod(_, mod_kind) = &item_inner.kind {
// FIXME: Collect tokens and use them instead of generating
// fake ones. These are unstable, so it needs to be
// fixed prior to stabilization
// Fake tokens when we are invoking an inner attribute, and:
fake_tokens = matches!(attr.style, ast::AttrStyle::Inner) &&
// We are invoking an attribute on the crate root, or an outline
// module
(item_inner.ident.name.is_empty() || !matches!(mod_kind, ast::ModKind::Loaded(_, Inline::Yes, _)));
}

This means that code like:

#![my_attr]

struct Foo {}
fn bar() {}

will cause us to lose spans for the entire crate root / outline module. The token streams in question are never nested 'inside' something else, so we might not need the full logic in collect_tokens_trailing_token to handle this case.

Custom inner attributes are currently unstable, so this needs to be fixed prior to stabilization in the crate root / outline module root position.

Activity

added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
C-bugCategory: This is a bug.
requires-nightlyThis issue requires a nightly compiler in some way.
on Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Aaron1011

        Issue actions

          Collect tokens for inner attributes at crate or outline module root · Issue #84163 · rust-lang/rust