Skip to content

Bad span in suggestion for unsafe_attr_outside_unsafe in macro expansion with cfg_attr #132908

Closed
@ehuss

Description

@ehuss

The following code:

#![warn(unsafe_attr_outside_unsafe)]

macro_rules! m {
    () => {
        #[cfg_attr(all(), link_section = ".text.startup")]
        unsafe extern "C" fn __ctor() {}
    };
}

m! {}

generates a suggestion which when applied looks like:

#[cfg_attr(all(), liunsafe(nk_section = ".text.startup)")]

Somehow the span is off by two bytes on both the start and end.

This doesn't happen outside of a macro expansion, and it seems to also require the cfg_attr.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (143ce0920 2024-11-10)
binary: rustc
commit-hash: 143ce0920a2307b19831160a01f06f107610f1b2
commit-date: 2024-11-10
host: aarch64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-unsafe_attr_outside_unsafeLint: unsafe_attr_outside_unsafeP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions