Skip to content

Weird error span for a mix of proc macro attributes #59013

Closed as not planned
Closed as not planned
@nox

Description

@nox

In Servo, we have a proc_macro_attribute named dom_struct which emits a bunch of other attributes on the types it adorns, among which a derive attribute. Node, being itself a DOM struct, obviously uses it.

In the process of making use of inert, I added an #[inert::neutralize] attribute on Node but I put it after #[dom_struct], so rustc emitted an "macro attributes must be placed before #[derive]" error as it should, so far so good.

#[dom_struct]
#[inert::neutralize(as pub unsafe InertNode)] // ERROR: macro attributes must be placed before `#[derive]`
pub struct Node {
    ...
}

The problem is that the span itself of the error is completely wrong:

error: macro attributes must be placed before `#[derive]`
  --> components/script/lib.rs:1:1
   |
1  | / /* This Source Code Form is subject to the terms of the Mozilla Public
2  | |  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  | |  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4  | |
...  |
97 | | use crate::dom::bindings::proxyhandler;
98 | | use crate::serviceworker_manager::ServiceWorkerManager;
   | |_____________^

Most notably, use crate::serviceworker_manager::ServiceWorkerManager; is line 56 in that file.

Things that should be kept in mind while trying to debug that is that I don't use quote_spanned! for this specific kind of inert::neutralize attribute, but dom_struct itself does weird things because of #46489, but I really don't know if the wrong span is related to that bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-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