get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2218017/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2218017,
    "url": "http://patchwork.ozlabs.org/api/patches/2218017/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260331094037.3408-2-gerris.rs@gmail.com/",
    "project": {
        "id": 17,
        "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api",
        "name": "GNU Compiler Collection",
        "link_name": "gcc",
        "list_id": "gcc-patches.gcc.gnu.org",
        "list_email": "gcc-patches@gcc.gnu.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260331094037.3408-2-gerris.rs@gmail.com>",
    "list_archive_url": null,
    "date": "2026-03-31T09:40:28",
    "name": "[gccrs,COMMIT,02/10] Move builtin attribute checking to its own pass",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "b00d88da20ddfc835590484615275cbc48fdcf3c",
    "submitter": {
        "id": 92092,
        "url": "http://patchwork.ozlabs.org/api/people/92092/?format=api",
        "name": null,
        "email": "gerris.rs@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260331094037.3408-2-gerris.rs@gmail.com/mbox/",
    "series": [
        {
            "id": 498158,
            "url": "http://patchwork.ozlabs.org/api/series/498158/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=498158",
            "date": "2026-03-31T09:40:27",
            "name": "[gccrs,COMMIT,01/10] Remove AttrInputMacro attribute input kind",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/498158/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2218017/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2218017/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@legolas.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=U+gF6WTV;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)",
            "sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=U+gF6WTV",
            "sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com",
            "sourceware.org; spf=pass smtp.mailfrom=gmail.com",
            "server2.sourceware.org;\n arc=none smtp.remote-ip=74.125.82.175"
        ],
        "Received": [
            "from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4flNSP5m2Pz1yGH\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 31 Mar 2026 20:42:13 +1100 (AEDT)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id C41FC4BAD17F\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 31 Mar 2026 09:42:11 +0000 (GMT)",
            "from mail-dy1-f175.google.com (mail-dy1-f175.google.com\n [74.125.82.175])\n by sourceware.org (Postfix) with ESMTPS id D88804BA23E5\n for <gcc-patches@gcc.gnu.org>; Tue, 31 Mar 2026 09:40:42 +0000 (GMT)",
            "by mail-dy1-f175.google.com with SMTP id\n 5a478bee46e88-2c66eafc1easo3249176eec.1\n for <gcc-patches@gcc.gnu.org>; Tue, 31 Mar 2026 02:40:42 -0700 (PDT)",
            "from\n runnervmrg6be.i0fnop2thlderixbsj2qpy22md.yx.internal.cloudapp.net\n ([57.151.128.242]) by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2c3c796d895sm9175510eec.28.2026.03.31.02.40.39\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 31 Mar 2026 02:40:39 -0700 (PDT)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org C41FC4BAD17F",
            "OpenDKIM Filter v2.11.0 sourceware.org D88804BA23E5"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org D88804BA23E5",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org D88804BA23E5",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774950043; cv=none;\n b=M2dqvGZ0be/PMw8HPtqQ1o0qzlEIwy7w7TXeD4uaL+ed3MeW4VptpVkLOU4Bqe01DZ7yG5oMxgdJXWXgfpsw6wZv/rbsyQo/+NRM50MjIa/IgQdNF8qc2mdPJ191rfJ4VBNjjRTWsc59h2ZgzNDnbU9A2isQgnpw621m6GGTWsw=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1774950043; c=relaxed/simple;\n bh=+goQ2pLkhVupz0RA7HlM/dvEssOLX3HeR2ybQj4ilf8=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=gqZVnc5kAZmSLmaq3vMk/aP9/zd3TxVLAZvxVzdXzP8DOGbNtKru1wufOK2zkfv86zyVMRZJMIxGFEd6kcYBy4hRUFH7Tqmcy3IxN7npMszw63wh6vauRt9vZx5rSm1i7BNv77gBYX/hnpNZtzLCuJJViAKROwEPtoXGINnKmdw=",
        "ARC-Authentication-Results": "i=1; server2.sourceware.org",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1774950042; x=1775554842; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=HrBvQmDyGZj9z1M3faYlhgvJ0SN+z2mfhljX+vfHDfc=;\n b=U+gF6WTVi3k9L/8xZUzC7DU+OgT0kmwvJDwNM2om/WTlJ28l2Tbd4a5gvD19jTh6d2\n oCPdOyeCa1MU0rPHuvy0IUeuh/3XwLL6SLdoUd1K+lHq8Hu9FInR6XajnrCzaeZK4Dy3\n PYFAcwQERuO/sFux2FSoye7f1HT+rEI0IOvhyjEceaVgEgZKqRTU+sBXHaHx8HAuDY2y\n dsQ22su7UeH7ceIQK7ol9tTtlw0HPX9o40G6Fc90qGiKvKY81fy94OoAEfJa5tTAzW5a\n x6C5vdV0OyE1ZqfG2JHyQT/QtCblDLU/GoqgCGaR8uflhYVYQe9NQLj+fpwSITcpFZNZ\n 7Q1g==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1774950042; x=1775554842;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=HrBvQmDyGZj9z1M3faYlhgvJ0SN+z2mfhljX+vfHDfc=;\n b=s4onXDLuky0jdi1oHUr0cIX+8KChKb+rvUr5QWRjuhRm1/LKs8fhje+8pEVw5CT6R2\n vbPoeqRMtNvBM+8Be+ED/FYZ0NNdlMyJlF2XLowfFXeFC78ZB8kR9x9oVYbotU7o5VgA\n ZAW/WCsx/Tr4n5qPichgp/vP6SaD4zCdLkgsDIehLc1Cdli9XuBik1NbiIs3nZ5TNQwj\n hXJzTRXa6+EZJ7X7SGcukXtco6bUYfT4u8ZebOlgxYR4Yvm5KEdiXRBPNy6ye6f73CQ4\n M2maSNWVeSQm9kkSJoQZUKYe6gkqqlWSMdhmHKYSVZXUZtbiDDxtsLnl4OH3NWlzUkDJ\n 8l8Q==",
        "X-Gm-Message-State": "AOJu0YzrnApjgg5ewVjUe4QN0HwzKEa94otozhlJBS7kuyEOJ7ruo+mF\n wqSz8250kqdlvJV5VRxPmV6wWTN5qtjw7oHiH319l04ybsY6/TRIvODFwjboww==",
        "X-Gm-Gg": "ATEYQzyq8/sByv4EweDSBOJBlI8bSGWonzg7xQtL4LoR/sWVO9/vX3MPKJa5U+dtqHY\n eIIGMcefGVPDdovt8KToKMPJql+AORGjgwVVe/Y9aJgz8WB9q8A5IcbwWx8ARcvqdl0DE55buPZ\n s7dabN/7WsBQTOo+PukA4zrYIh0gsHC1snBDSIdvCb3ibv7n2rAi5ZZ6aUeZkq0FJl+Mamf0vMn\n QwDWKX6gVWLwyfWXutRgPngO4b2kJkrmu18aoR27sSLJW3+pbWN1vmY9CEPezdKfS0kEO/T9efw\n Px6K+1ySXZ8Q6KwVrSgn3EXkIPkeDLTe88thnuwpDn3meo4oO/RK6bb6j5EU6B0+Vpffv4FaKfI\n wJ9HD/HAegAwTAMOAPbNLjvQJjhrx+uWN6pITrli1v/LX5TjqrIp7CXsA72WQnaRe9NTigAAjFL\n f80jli6G7ld3FxDVVyfjr8CsZHRsg5R9GxQYrHoiZpcgJFPQ1ucx5OEfntLsTMd9K703NdVSMMn\n yp8JXk0Xf1r+oCQ8p7F68k=",
        "X-Received": "by 2002:a05:693c:3008:b0:2c1:7b61:8731 with SMTP id\n 5a478bee46e88-2c185cbf44dmr9388729eec.10.1774950041476;\n Tue, 31 Mar 2026 02:40:41 -0700 (PDT)",
        "From": "gerris.rs@gmail.com",
        "To": "gcc-patches@gcc.gnu.org,\n\tgcc-rust@gcc.gnu.org",
        "Cc": "pierre-emmanuel.patry@embecosm.com, arthur.cohen@embecosm.com,\n dkm+gccrs@kataplop.net",
        "Subject": "[gccrs COMMIT 02/10] Move builtin attribute checking to its own pass",
        "Date": "Tue, 31 Mar 2026 09:40:28 +0000",
        "Message-ID": "<20260331094037.3408-2-gerris.rs@gmail.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20260331094037.3408-1-gerris.rs@gmail.com>",
        "References": "<20260331094037.3408-1-gerris.rs@gmail.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "gcc-patches@gcc.gnu.org",
        "X-Mailman-Version": "2.1.30",
        "Precedence": "list",
        "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>",
        "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>",
        "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>",
        "List-Post": "<mailto:gcc-patches@gcc.gnu.org>",
        "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>",
        "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>",
        "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"
    },
    "content": "From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>\n\nBuiltin attribute checking should be done after macro expansion because\nwe want to support macros within attributes.\n\ngcc/rust/ChangeLog:\n\n\t* Make-lang.in: Add file for builtin attribute checking.\n\t* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_doc_item_attribute):\n\tRemove error emission and replace it with an assert. The error message\n\twill now be emitted from the builtin attribute checking pass.\n\t* rust-session-manager.cc (Session::compile_crate): Add builtin\n\tattribute checking step after expansion.\n\t* util/rust-attributes.cc (Attributes::is_known): Move down.\n\t(Attributes::extract_string_literal): Likewise.\n\t(Attributes::valid_outer_attribute): Add a function to retrieve outer/\n\tinner status for a given builtin attribute value.\n\t(AttributeChecker::visit): Move some checking to builtin attribute\n\tchecker.\n\t(identify_builtin): Rename function from here ...\n\t(lookup_builtin): ... to here.\n\t(check_doc_alias): Move to builtin attribute checker.\n\t(check_doc_attribute): Likewise.\n\t(check_deprecated_attribute): Likewise.\n\t(check_valid_attribute_for_item): Likewise.\n\t(AttributeChecker::check_inner_attribute): Likewise.\n\t(check_link_section_attribute): Likewise.\n\t(check_export_name_attribute): Likewise.\n\t(check_lint_attribute): Likewise.\n\t(check_no_mangle_function): Likewise.\n\t(is_proc_macro_type): Update function call name.\n\t* util/rust-attributes.h (identify_builtin): Update prototype.\n\t(lookup_builtin): Likewise.\n\t* checks/errors/rust-builtin-attribute-checker.cc: New file.\n\t* checks/errors/rust-builtin-attribute-checker.h: New file.\n\ngcc/testsuite/ChangeLog:\n\n\t* rust/compile/issue-4226.rs: Update text to match error message from\n\tattribute checking pass that was not triggered before.\n\nSigned-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>\n---\nThis change was merged into the gccrs repository and is posted here for\nupstream visibility and potential drive-by review, as requested by GCC\nrelease managers.\nEach commit email contains a link to its details on github from where you can\nfind the Pull-Request and associated discussions.\n\n\nCommit on github: https://github.com/Rust-GCC/gccrs/commit/4e5c43e411a64ed4fded38ec1add0317dafcdba3\n\nThe commit has been mentioned in the following pull-request(s):\n - https://github.com/Rust-GCC/gccrs/pull/4505\n\n gcc/rust/Make-lang.in                         |   1 +\n .../errors/rust-builtin-attribute-checker.cc  | 602 ++++++++++++++++++\n .../errors/rust-builtin-attribute-checker.h   |  58 ++\n gcc/rust/hir/rust-ast-lower-base.cc           |   8 +-\n gcc/rust/rust-session-manager.cc              |   3 +\n gcc/rust/util/rust-attributes.cc              | 571 ++---------------\n gcc/rust/util/rust-attributes.h               |   4 +-\n gcc/testsuite/rust/compile/issue-4226.rs      |   4 +-\n 8 files changed, 725 insertions(+), 526 deletions(-)\n create mode 100644 gcc/rust/checks/errors/rust-builtin-attribute-checker.cc\n create mode 100644 gcc/rust/checks/errors/rust-builtin-attribute-checker.h",
    "diff": "diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in\nindex 4c394d39c..fc11abf1f 100644\n--- a/gcc/rust/Make-lang.in\n+++ b/gcc/rust/Make-lang.in\n@@ -126,6 +126,7 @@ GRS_OBJS = \\\n     rust/rust-hir.o \\\n     rust/rust-hir-map.o \\\n     rust/rust-attributes.o \\\n+    rust/rust-builtin-attribute-checker.o \\\n     rust/rust-keyword-values.o \\\n     rust/rust-abi.o \\\n     rust/rust-token-converter.o \\\ndiff --git a/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc\nnew file mode 100644\nindex 000000000..8cb251f76\n--- /dev/null\n+++ b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc\n@@ -0,0 +1,602 @@\n+// Copyright (C) 2026 Free Software Foundation, Inc.\n+\n+// This file is part of GCC.\n+\n+// GCC is free software; you can redistribute it and/or modify it under\n+// the terms of the GNU General Public License as published by the Free\n+// Software Foundation; either version 3, or (at your option) any later\n+// version.\n+\n+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n+// WARRANTY; without even the implied warranty of MERCHANTABILITY or\n+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n+// for more details.\n+\n+// You should have received a copy of the GNU General Public License\n+// along with GCC; see the file COPYING3.  If not see\n+// <http://www.gnu.org/licenses/>.\n+\n+#include \"rust-builtin-attribute-checker.h\"\n+#include \"optional.h\"\n+#include \"rust-attributes.h\"\n+#include \"rust-attribute-values.h\"\n+#include \"rust-session-manager.h\"\n+\n+namespace Rust {\n+namespace Analysis {\n+\n+using Attrs = Values::Attributes;\n+\n+void\n+check_inner_attribute (const AST::Attribute &attribute)\n+{\n+  auto result_opt = lookup_builtin (attribute);\n+  if (!result_opt.has_value ())\n+    return;\n+  auto result = result_opt.value ();\n+\n+  if (Attributes::valid_outer_attribute (result.name))\n+    rust_error_at (attribute.get_locus (),\n+\t\t   \"attribute cannot be used at crate level\");\n+}\n+\n+/**\n+ * Check that the string given to #[doc(alias = ...)] or #[doc(alias(...))] is\n+ * valid.\n+ *\n+ * This means no whitespace characters other than spaces and no quoting\n+ * characters.\n+ */\n+static void\n+check_doc_alias (const std::string &alias_input, const location_t locus)\n+{\n+  // FIXME: The locus here is for the whole attribute. Can we get the locus\n+  // of the alias input instead?\n+  for (auto c : alias_input)\n+    if ((ISSPACE (c) && c != ' ') || c == '\\'' || c == '\\\"')\n+      {\n+\tauto to_print = std::string (1, c);\n+\tswitch (c)\n+\t  {\n+\t  case '\\n':\n+\t    to_print = \"\\\\n\";\n+\t    break;\n+\t  case '\\t':\n+\t    to_print = \"\\\\t\";\n+\t    break;\n+\t  default:\n+\t    break;\n+\t  }\n+\trust_error_at (locus,\n+\t\t       \"invalid character used in %<#[doc(alias)]%> input: %qs\",\n+\t\t       to_print.c_str ());\n+      }\n+\n+  if (alias_input.empty ())\n+    return;\n+\n+  if (alias_input.front () == ' ' || alias_input.back () == ' ')\n+    rust_error_at (locus,\n+\t\t   \"%<#[doc(alias)]%> input cannot start or end with a space\");\n+}\n+\n+static void\n+check_doc_attribute (const AST::Attribute &attribute)\n+{\n+  if (!attribute.has_attr_input ())\n+    {\n+      rust_error_at (\n+\tattribute.get_locus (),\n+\t\"valid forms for the attribute are \"\n+\t\"%<#[doc(hidden|inline|...)]%> and %<#[doc = \\\" string \\\"]%>\");\n+      return;\n+    }\n+\n+  switch (attribute.get_attr_input ().get_attr_input_type ())\n+    {\n+    case AST::AttrInput::LITERAL:\n+    case AST::AttrInput::META_ITEM:\n+    case AST::AttrInput::EXPR:\n+      break;\n+      // FIXME: Handle them as well\n+\n+    case AST::AttrInput::TOKEN_TREE:\n+      {\n+\t// FIXME: This doesn't check for #[doc(alias(...))]\n+\tconst auto &option = static_cast<const AST::DelimTokenTree &> (\n+\t  attribute.get_attr_input ());\n+\tauto *meta_item = option.parse_to_meta_item ();\n+\n+\tfor (auto &item : meta_item->get_items ())\n+\t  {\n+\t    if (item->is_key_value_pair ())\n+\t      {\n+\t\tauto name_value\n+\t\t  = static_cast<AST::MetaNameValueStr *> (item.get ())\n+\t\t      ->get_name_value_pair ();\n+\n+\t\t// FIXME: Check for other stuff than #[doc(alias = ...)]\n+\t\tif (name_value.first.as_string () == \"alias\")\n+\t\t  check_doc_alias (name_value.second, attribute.get_locus ());\n+\t      }\n+\t  }\n+\tbreak;\n+      }\n+    }\n+}\n+\n+static void\n+check_deprecated_attribute (const AST::Attribute &attribute)\n+{\n+  if (!attribute.has_attr_input ())\n+    return;\n+\n+  const auto &input = attribute.get_attr_input ();\n+\n+  if (input.get_attr_input_type () != AST::AttrInput::META_ITEM)\n+    return;\n+\n+  auto &meta = static_cast<const AST::AttrInputMetaItemContainer &> (input);\n+\n+  for (auto &current : meta.get_items ())\n+    {\n+      switch (current->get_kind ())\n+\t{\n+\tcase AST::MetaItemInner::Kind::MetaItem:\n+\t  {\n+\t    auto *meta_item = static_cast<AST::MetaItem *> (current.get ());\n+\n+\t    switch (meta_item->get_item_kind ())\n+\t      {\n+\t      case AST::MetaItem::ItemKind::NameValueStr:\n+\t\t{\n+\t\t  auto *nv = static_cast<AST::MetaNameValueStr *> (meta_item);\n+\n+\t\t  const std::string key = nv->get_name ().as_string ();\n+\n+\t\t  if (key != \"since\" && key != \"note\")\n+\t\t    {\n+\t\t      rust_error_at (nv->get_locus (), \"unknown meta item %qs\",\n+\t\t\t\t     key.c_str ());\n+\t\t      rust_inform (nv->get_locus (),\n+\t\t\t\t   \"expected one of %<since%>, %<note%>\");\n+\t\t    }\n+\t\t}\n+\t\tbreak;\n+\n+\t      case AST::MetaItem::ItemKind::Path:\n+\t\t{\n+\t\t  // #[deprecated(a,a)]\n+\t\t  auto *p = static_cast<AST::MetaItemPath *> (meta_item);\n+\n+\t\t  std::string ident = p->get_path ().as_string ();\n+\n+\t\t  rust_error_at (p->get_locus (), \"unknown meta item %qs\",\n+\t\t\t\t ident.c_str ());\n+\t\t  rust_inform (p->get_locus (),\n+\t\t\t       \"expected one of %<since%>, %<note%>\");\n+\t\t}\n+\t\tbreak;\n+\n+\t      case AST::MetaItem::ItemKind::Word:\n+\t\t{\n+\t\t  // #[deprecated(\"a\")]\n+\t\t  auto *w = static_cast<AST::MetaWord *> (meta_item);\n+\n+\t\t  rust_error_at (\n+\t\t    w->get_locus (),\n+\t\t    \"item in %<deprecated%> must be a key/value pair\");\n+\t\t}\n+\t\tbreak;\n+\n+\t      case AST::MetaItem::ItemKind::PathExpr:\n+\t\t{\n+\t\t  // #[deprecated(since=a)]\n+\t\t  auto *px = static_cast<AST::MetaItemPathExpr *> (meta_item);\n+\n+\t\t  rust_error_at (\n+\t\t    px->get_locus (),\n+\t\t    \"expected unsuffixed literal or identifier, found %qs\",\n+\t\t    px->get_expr ().as_string ().c_str ());\n+\t\t}\n+\t\tbreak;\n+\n+\t      case AST::MetaItem::ItemKind::Seq:\n+\t      case AST::MetaItem::ItemKind::ListPaths:\n+\t      case AST::MetaItem::ItemKind::ListNameValueStr:\n+\t      default:\n+\t\tgcc_unreachable ();\n+\t\tbreak;\n+\t      }\n+\t  }\n+\t  break;\n+\n+\tcase AST::MetaItemInner::Kind::LitExpr:\n+\tdefault:\n+\t  gcc_unreachable ();\n+\t  break;\n+\t}\n+    }\n+}\n+\n+static void\n+check_link_section_attribute (const AST::Attribute &attribute)\n+{\n+  if (!attribute.has_attr_input ())\n+    {\n+      rust_error_at (attribute.get_locus (),\n+\t\t     \"malformed %<link_section%> attribute input\");\n+      rust_inform (attribute.get_locus (),\n+\t\t   \"must be of the form: %<#[link_section = \\\"name\\\"]%>\");\n+    }\n+}\n+\n+static void\n+check_export_name_attribute (const AST::Attribute &attribute)\n+{\n+  if (!attribute.has_attr_input ())\n+    {\n+      rust_error_at (attribute.get_locus (),\n+\t\t     \"malformed %<export_name%> attribute input\");\n+      rust_inform (attribute.get_locus (),\n+\t\t   \"must be of the form: %<#[export_name = \\\"name\\\"]%>\");\n+      return;\n+    }\n+\n+  auto &attr_input = attribute.get_attr_input ();\n+  if (attr_input.get_attr_input_type ()\n+      == AST::AttrInput::AttrInputType::LITERAL)\n+    {\n+      auto &literal_expr\n+\t= static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();\n+      auto lit_type = literal_expr.get_lit_type ();\n+      switch (lit_type)\n+\t{\n+\tcase AST::Literal::LitType::STRING:\n+\tcase AST::Literal::LitType::RAW_STRING:\n+\tcase AST::Literal::LitType::BYTE_STRING:\n+\t  return;\n+\tdefault:\n+\t  break;\n+\t}\n+    }\n+\n+  rust_error_at (attribute.get_locus (), \"attribute must be a string literal\");\n+}\n+\n+static void\n+check_no_mangle_function (const AST::Attribute &attribute,\n+\t\t\t  const AST::Function &fun)\n+{\n+  if (attribute.has_attr_input ())\n+    {\n+      rust_error_at (attribute.get_locus (), ErrorCode::E0754,\n+\t\t     \"malformed %<no_mangle%> attribute input\");\n+      rust_inform (attribute.get_locus (),\n+\t\t   \"must be of the form: %<#[no_mangle]%>\");\n+    }\n+  if (!is_ascii_only (fun.get_function_name ().as_string ()))\n+    rust_error_at (fun.get_function_name ().get_locus (),\n+\t\t   \"the %<#[no_mangle]%> attribute requires ASCII identifier\");\n+}\n+\n+static void\n+check_lint_attribute (const AST::Attribute &attribute, const char *name)\n+{\n+  if (!attribute.has_attr_input ())\n+    {\n+      rust_error_at (attribute.get_locus (), \"malformed %qs attribute input\",\n+\t\t     name);\n+      rust_inform (attribute.get_locus (),\n+\t\t   \"must be of the form: %<#[%s(lint1, lint2, ...)]%>\", name);\n+    }\n+}\n+\n+/**\n+ * Emit an error when an attribute is attached\n+ * to an incompatable item type. e.g.:\n+ *\n+ * #[cold]\n+ * struct A(u8, u8);\n+ *\n+ * Note that \"#[derive]\" is handled\n+ * explicitly in rust-derive.cc\n+ */\n+static void\n+check_valid_attribute_for_item (const AST::Attribute &attr,\n+\t\t\t\tconst AST::Item &item)\n+{\n+  if (item.get_item_kind () != AST::Item::Kind::Function\n+      && (attr.get_path () == Values::Attributes::TARGET_FEATURE\n+\t  || attr.get_path () == Values::Attributes::COLD\n+\t  || attr.get_path () == Values::Attributes::INLINE))\n+    {\n+      rust_error_at (attr.get_locus (),\n+\t\t     \"the %<#[%s]%> attribute may only be applied to functions\",\n+\t\t     attr.get_path ().as_string ().c_str ());\n+    }\n+  else if (attr.get_path () == Values::Attributes::REPR\n+\t   && item.get_item_kind () != AST::Item::Kind::Enum\n+\t   && item.get_item_kind () != AST::Item::Kind::Union\n+\t   && item.get_item_kind () != AST::Item::Kind::Struct)\n+    {\n+      rust_error_at (attr.get_locus (),\n+\t\t     \"the %<#[%s]%> attribute may only be applied \"\n+\t\t     \"to structs, enums and unions\",\n+\t\t     attr.get_path ().as_string ().c_str ());\n+    }\n+}\n+\n+BuiltinAttributeChecker::BuiltinAttributeChecker () {}\n+\n+void\n+BuiltinAttributeChecker::go (AST::Crate &crate)\n+{\n+  visit (crate);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Crate &crate)\n+{\n+  for (auto &attr : crate.get_inner_attrs ())\n+    {\n+      check_inner_attribute (attr);\n+    }\n+\n+  AST::DefaultASTVisitor::visit (crate);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Attribute &attribute)\n+{\n+  if (auto builtin = lookup_builtin (attribute))\n+    {\n+      auto result = builtin.value ();\n+      // TODO: Add checks here for each builtin attribute\n+      // TODO: Have an enum of builtins as well, switching on strings is\n+      // annoying and costly\n+      if (result.name == Attrs::DOC)\n+\tcheck_doc_attribute (attribute);\n+      else if (result.name == Attrs::DEPRECATED)\n+\tcheck_deprecated_attribute (attribute);\n+    }\n+\n+  AST::DefaultASTVisitor::visit (attribute);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Module &module)\n+{\n+  for (auto &attr : module.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, module);\n+\n+  AST::DefaultASTVisitor::visit (module);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::ExternCrate &crate)\n+{\n+  for (auto &attr : crate.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, crate);\n+\n+  AST::DefaultASTVisitor::visit (crate);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::UseDeclaration &declaration)\n+{\n+  for (auto &attr : declaration.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, declaration);\n+\n+  AST::DefaultASTVisitor::visit (declaration);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Function &function)\n+{\n+  auto check_crate_type = [] (const char *name, AST::Attribute &attribute) {\n+    if (!Session::get_instance ().options.is_proc_macro ())\n+      rust_error_at (attribute.get_locus (),\n+\t\t     \"the %<#[%s]%> attribute is only usable with crates of \"\n+\t\t     \"the %<proc-macro%> crate type\",\n+\t\t     name);\n+  };\n+\n+  BuiltinAttrDefinition result;\n+  for (auto &attribute : function.get_outer_attrs ())\n+    {\n+      check_valid_attribute_for_item (attribute, function);\n+\n+      auto result = lookup_builtin (attribute);\n+      if (!result)\n+\treturn;\n+\n+      auto name = result->name.c_str ();\n+\n+      if (result->name == Attrs::PROC_MACRO_DERIVE)\n+\t{\n+\t  if (!attribute.has_attr_input ())\n+\t    {\n+\t      rust_error_at (attribute.get_locus (),\n+\t\t\t     \"malformed %qs attribute input\", name);\n+\t      rust_inform (\n+\t\tattribute.get_locus (),\n+\t\t\"must be of the form: %<#[proc_macro_derive(TraitName, \"\n+\t\t\"/*opt*/ attributes(name1, name2, ...))]%>\");\n+\t    }\n+\t  check_crate_type (name, attribute);\n+\t}\n+      else if (result->name == Attrs::PROC_MACRO\n+\t       || result->name == Attrs::PROC_MACRO_ATTRIBUTE)\n+\t{\n+\t  check_crate_type (name, attribute);\n+\t}\n+      else if (result->name == Attrs::TARGET_FEATURE)\n+\t{\n+\t  if (!attribute.has_attr_input ())\n+\t    {\n+\t      rust_error_at (attribute.get_locus (),\n+\t\t\t     \"malformed %<target_feature%> attribute input\");\n+\t      rust_inform (attribute.get_locus (),\n+\t\t\t   \"must be of the form: %<#[target_feature(enable = \"\n+\t\t\t   \"\\\"name\\\")]%>\");\n+\t    }\n+\t  else if (!function.get_qualifiers ().is_unsafe ())\n+\t    {\n+\t      rust_error_at (\n+\t\tattribute.get_locus (),\n+\t\t\"the %<#[target_feature]%> attribute can only be applied \"\n+\t\t\"to %<unsafe%> functions\");\n+\t    }\n+\t}\n+      else if (result->name == Attrs::NO_MANGLE)\n+\t{\n+\t  if (attribute.has_attr_input ())\n+\t    {\n+\t      rust_error_at (attribute.get_locus (),\n+\t\t\t     \"malformed %<no_mangle%> attribute input\");\n+\t      rust_inform (attribute.get_locus (),\n+\t\t\t   \"must be of the form: %<#[no_mangle]%>\");\n+\t    }\n+\t  else\n+\t    check_no_mangle_function (attribute, function);\n+\t}\n+      else if (result->name == Attrs::EXPORT_NAME)\n+\t{\n+\t  check_export_name_attribute (attribute);\n+\t}\n+      else if (result->name == Attrs::ALLOW || result->name == \"deny\"\n+\t       || result->name == \"warn\" || result->name == \"forbid\")\n+\t{\n+\t  check_lint_attribute (attribute, name);\n+\t}\n+      else if (result->name == Attrs::LINK_NAME)\n+\t{\n+\t  if (!attribute.has_attr_input ())\n+\t    {\n+\t      rust_error_at (attribute.get_locus (),\n+\t\t\t     \"malformed %<link_name%> attribute input\");\n+\t      rust_inform (attribute.get_locus (),\n+\t\t\t   \"must be of the form: %<#[link_name = \\\"name\\\"]%>\");\n+\t    }\n+\t}\n+      else if (result->name == Attrs::LINK_SECTION)\n+\t{\n+\t  check_link_section_attribute (attribute);\n+\t}\n+    }\n+\n+  AST::DefaultASTVisitor::visit (function);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::TypeAlias &alias)\n+{\n+  for (auto &attr : alias.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, alias);\n+\n+  AST::DefaultASTVisitor::visit (alias);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::StructStruct &struct_item)\n+{\n+  for (auto &attr : struct_item.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, struct_item);\n+\n+  AST::DefaultASTVisitor::visit (struct_item);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::TupleStruct &tuple_struct)\n+{\n+  for (auto &attr : tuple_struct.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, tuple_struct);\n+\n+  AST::DefaultASTVisitor::visit (tuple_struct);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Enum &enumeration)\n+{\n+  for (auto &attr : enumeration.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, enumeration);\n+\n+  AST::DefaultASTVisitor::visit (enumeration);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Union &u)\n+{\n+  for (auto &attr : u.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, u);\n+\n+  AST::DefaultASTVisitor::visit (u);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::ConstantItem &item)\n+{\n+  for (auto &attr : item.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, item);\n+\n+  AST::DefaultASTVisitor::visit (item);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::StaticItem &item)\n+{\n+  for (auto &attr : item.get_outer_attrs ())\n+    {\n+      check_valid_attribute_for_item (attr, item);\n+\n+      if (auto result = lookup_builtin (attr))\n+\t{\n+\t  if (result->name == Attrs::LINK_SECTION)\n+\t    check_link_section_attribute (attr);\n+\t  else if (result->name == Attrs::EXPORT_NAME)\n+\t    check_export_name_attribute (attr);\n+\t}\n+    }\n+\n+  AST::DefaultASTVisitor::visit (item);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::Trait &trait)\n+{\n+  for (auto &attr : trait.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, trait);\n+\n+  AST::DefaultASTVisitor::visit (trait);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::InherentImpl &impl)\n+{\n+  for (auto &attr : impl.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, impl);\n+\n+  AST::DefaultASTVisitor::visit (impl);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::TraitImpl &impl)\n+{\n+  for (auto &attr : impl.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, impl);\n+\n+  AST::DefaultASTVisitor::visit (impl);\n+}\n+\n+void\n+BuiltinAttributeChecker::visit (AST::ExternBlock &block)\n+{\n+  for (auto &attr : block.get_outer_attrs ())\n+    check_valid_attribute_for_item (attr, block);\n+\n+  AST::DefaultASTVisitor::visit (block);\n+}\n+\n+} // namespace Analysis\n+} // namespace Rust\ndiff --git a/gcc/rust/checks/errors/rust-builtin-attribute-checker.h b/gcc/rust/checks/errors/rust-builtin-attribute-checker.h\nnew file mode 100644\nindex 000000000..6717de8ab\n--- /dev/null\n+++ b/gcc/rust/checks/errors/rust-builtin-attribute-checker.h\n@@ -0,0 +1,58 @@\n+// Copyright (C) 2026 Free Software Foundation, Inc.\n+\n+// This file is part of GCC.\n+\n+// GCC is free software; you can redistribute it and/or modify it under\n+// the terms of the GNU General Public License as published by the Free\n+// Software Foundation; either version 3, or (at your option) any later\n+// version.\n+\n+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY\n+// WARRANTY; without even the implied warranty of MERCHANTABILITY or\n+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n+// for more details.\n+\n+// You should have received a copy of the GNU General Public License\n+// along with GCC; see the file COPYING3.  If not see\n+// <http://www.gnu.org/licenses/>.\n+\n+#ifndef RUST_BUILTIN_ATTRIBUTE_CHECKER_H\n+#define RUST_BUILTIN_ATTRIBUTE_CHECKER_H\n+\n+#include \"rust-ast-visitor.h\"\n+\n+namespace Rust {\n+namespace Analysis {\n+\n+class BuiltinAttributeChecker : public AST::DefaultASTVisitor\n+{\n+  using AST::DefaultASTVisitor::visit;\n+\n+public:\n+  BuiltinAttributeChecker ();\n+  void go (AST::Crate &crate);\n+  void visit (AST::Crate &crate) override;\n+  void visit (AST::Attribute &attribute) override;\n+\n+  // Items\n+  void visit (AST::Module &module) override;\n+  void visit (AST::ExternCrate &crate) override;\n+  void visit (AST::UseDeclaration &use_decl) override;\n+  void visit (AST::Function &function) override;\n+  void visit (AST::TypeAlias &type_alias) override;\n+  void visit (AST::StructStruct &struct_item) override;\n+  void visit (AST::TupleStruct &tuple_struct) override;\n+  void visit (AST::Enum &enum_item) override;\n+  void visit (AST::Union &union_item) override;\n+  void visit (AST::ConstantItem &const_item) override;\n+  void visit (AST::StaticItem &static_item) override;\n+  void visit (AST::Trait &trait) override;\n+  void visit (AST::InherentImpl &impl) override;\n+  void visit (AST::TraitImpl &impl) override;\n+  void visit (AST::ExternBlock &block) override;\n+};\n+\n+} // namespace Analysis\n+} // namespace Rust\n+\n+#endif /* ! RUST_BUILTIN_ATTRIBUTE_CHECKER_H */\ndiff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc\nindex 8b2fa5a2f..6fc4463a9 100644\n--- a/gcc/rust/hir/rust-ast-lower-base.cc\n+++ b/gcc/rust/hir/rust-ast-lower-base.cc\n@@ -832,13 +832,7 @@ void\n ASTLoweringBase::handle_doc_item_attribute (const ItemWrapper &,\n \t\t\t\t\t    const AST::Attribute &attr)\n {\n-  if (!attr.has_attr_input ())\n-    {\n-      rust_error_at (attr.get_locus (),\n-\t\t     \"attribute must be of the form %qs or %qs\",\n-\t\t     \"#[doc(hidden|inline|...)]\", \"#[doc = string]\");\n-      return;\n-    }\n+  rust_assert (attr.has_attr_input ());\n \n   auto simple_doc_comment = attr.get_attr_input ().get_attr_input_type ()\n \t\t\t    == AST::AttrInput::AttrInputType::LITERAL;\ndiff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc\nindex 12e076d1d..364ca0811 100644\n--- a/gcc/rust/rust-session-manager.cc\n+++ b/gcc/rust/rust-session-manager.cc\n@@ -60,6 +60,7 @@\n #include \"rust-borrow-checker.h\"\n #include \"rust-ast-validation.h\"\n #include \"rust-tyty-variance-analysis.h\"\n+#include \"rust-builtin-attribute-checker.h\"\n \n #include \"input.h\"\n #include \"selftest.h\"\n@@ -735,6 +736,8 @@ Session::compile_crate (const char *filename)\n \n   expansion (parsed_crate, name_resolution_ctx);\n \n+  Analysis::BuiltinAttributeChecker ().go (parsed_crate);\n+\n   AST::CollectLangItems ().go (parsed_crate);\n \n   rust_debug (\"\\033[0;31mSUCCESSFULLY FINISHED EXPANSION \\033[0m\");\ndiff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc\nindex 3b6587ffd..f03fa90d9 100644\n--- a/gcc/rust/util/rust-attributes.cc\n+++ b/gcc/rust/util/rust-attributes.cc\n@@ -29,40 +29,6 @@\n namespace Rust {\n namespace Analysis {\n \n-bool\n-Attributes::is_known (const std::string &attribute_path)\n-{\n-  const auto &lookup\n-    = BuiltinAttributeMappings::get ()->lookup_builtin (attribute_path);\n-\n-  return !lookup.is_error ();\n-}\n-\n-tl::optional<std::string>\n-Attributes::extract_string_literal (const AST::Attribute &attr)\n-{\n-  if (!attr.has_attr_input ())\n-    return tl::nullopt;\n-\n-  auto &attr_input = attr.get_attr_input ();\n-\n-  if (attr_input.get_attr_input_type ()\n-      != AST::AttrInput::AttrInputType::LITERAL)\n-    return tl::nullopt;\n-\n-  auto &literal_expr\n-    = static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();\n-\n-  auto lit_type = literal_expr.get_lit_type ();\n-\n-  // TODO: bring escape sequence handling out of lexing?\n-  if (lit_type != AST::Literal::LitType::STRING\n-      && lit_type != AST::Literal::LitType::RAW_STRING)\n-    return tl::nullopt;\n-\n-  return literal_expr.as_string ();\n-}\n-\n using Attrs = Values::Attributes;\n \n // https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248\n@@ -151,6 +117,45 @@ static const std::set<std::string> __outer_attributes\n      Attrs::LINK_NAME,\n      Attrs::LINK_SECTION};\n \n+bool\n+Attributes::is_known (const std::string &attribute_path)\n+{\n+  const auto &lookup\n+    = BuiltinAttributeMappings::get ()->lookup_builtin (attribute_path);\n+\n+  return !lookup.is_error ();\n+}\n+\n+bool\n+Attributes::valid_outer_attribute (const std::string &attribute_path)\n+{\n+  return __outer_attributes.find (attribute_path) != __outer_attributes.cend ();\n+}\n+\n+tl::optional<std::string>\n+Attributes::extract_string_literal (const AST::Attribute &attr)\n+{\n+  if (!attr.has_attr_input ())\n+    return tl::nullopt;\n+\n+  auto &attr_input = attr.get_attr_input ();\n+\n+  if (attr_input.get_attr_input_type ()\n+      != AST::AttrInput::AttrInputType::LITERAL)\n+    return tl::nullopt;\n+\n+  auto &literal_expr\n+    = static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();\n+\n+  auto lit_type = literal_expr.get_lit_type ();\n+\n+  // TODO: bring escape sequence handling out of lexing?\n+  if (lit_type != AST::Literal::LitType::STRING\n+      && lit_type != AST::Literal::LitType::RAW_STRING)\n+    return tl::nullopt;\n+\n+  return literal_expr.as_string ();\n+}\n BuiltinAttributeMappings *\n BuiltinAttributeMappings::get ()\n {\n@@ -189,20 +194,8 @@ AttributeChecker::go (AST::Crate &crate)\n   visit (crate);\n }\n \n-void\n-AttributeChecker::visit (AST::Crate &crate)\n-{\n-  for (auto &attr : crate.get_inner_attrs ())\n-    {\n-      check_inner_attribute (attr);\n-    }\n-\n-  for (auto &item : crate.items)\n-    item->accept_vis (*this);\n-}\n-\n tl::optional<BuiltinAttrDefinition>\n-identify_builtin (const AST::Attribute &attribute)\n+lookup_builtin (const AST::Attribute &attribute)\n {\n   auto &segments = attribute.get_path ().get_segments ();\n \n@@ -216,224 +209,10 @@ identify_builtin (const AST::Attribute &attribute)\n     segments.at (0).get_segment_name ());\n }\n \n-/**\n- * Check that the string given to #[doc(alias = ...)] or #[doc(alias(...))] is\n- * valid.\n- *\n- * This means no whitespace characters other than spaces and no quoting\n- * characters.\n- */\n-static void\n-check_doc_alias (const std::string &alias_input, const location_t locus)\n-{\n-  // FIXME: The locus here is for the whole attribute. Can we get the locus\n-  // of the alias input instead?\n-  for (auto c : alias_input)\n-    if ((ISSPACE (c) && c != ' ') || c == '\\'' || c == '\\\"')\n-      {\n-\tauto to_print = std::string (1, c);\n-\tswitch (c)\n-\t  {\n-\t  case '\\n':\n-\t    to_print = \"\\\\n\";\n-\t    break;\n-\t  case '\\t':\n-\t    to_print = \"\\\\t\";\n-\t    break;\n-\t  default:\n-\t    break;\n-\t  }\n-\trust_error_at (locus,\n-\t\t       \"invalid character used in %<#[doc(alias)]%> input: %qs\",\n-\t\t       to_print.c_str ());\n-      }\n-\n-  if (alias_input.empty ())\n-    return;\n-\n-  if (alias_input.front () == ' ' || alias_input.back () == ' ')\n-    rust_error_at (locus,\n-\t\t   \"%<#[doc(alias)]%> input cannot start or end with a space\");\n-}\n-\n-static void\n-check_doc_attribute (const AST::Attribute &attribute)\n-{\n-  if (!attribute.has_attr_input ())\n-    {\n-      rust_error_at (\n-\tattribute.get_locus (),\n-\t\"valid forms for the attribute are \"\n-\t\"%<#[doc(hidden|inline|...)]%> and %<#[doc = \\\" string \\\"]%>\");\n-      return;\n-    }\n-\n-  switch (attribute.get_attr_input ().get_attr_input_type ())\n-    {\n-    case AST::AttrInput::LITERAL:\n-    case AST::AttrInput::META_ITEM:\n-    case AST::AttrInput::EXPR:\n-      break;\n-      // FIXME: Handle them as well\n-\n-    case AST::AttrInput::TOKEN_TREE:\n-      {\n-\t// FIXME: This doesn't check for #[doc(alias(...))]\n-\tconst auto &option = static_cast<const AST::DelimTokenTree &> (\n-\t  attribute.get_attr_input ());\n-\tauto *meta_item = option.parse_to_meta_item ();\n-\n-\tfor (auto &item : meta_item->get_items ())\n-\t  {\n-\t    if (item->is_key_value_pair ())\n-\t      {\n-\t\tauto name_value\n-\t\t  = static_cast<AST::MetaNameValueStr *> (item.get ())\n-\t\t      ->get_name_value_pair ();\n-\n-\t\t// FIXME: Check for other stuff than #[doc(alias = ...)]\n-\t\tif (name_value.first.as_string () == \"alias\")\n-\t\t  check_doc_alias (name_value.second, attribute.get_locus ());\n-\t      }\n-\t  }\n-\tbreak;\n-      }\n-    }\n-}\n-\n-static void\n-check_deprecated_attribute (const AST::Attribute &attribute)\n-{\n-  if (!attribute.has_attr_input ())\n-    return;\n-\n-  const auto &input = attribute.get_attr_input ();\n-\n-  if (input.get_attr_input_type () != AST::AttrInput::META_ITEM)\n-    return;\n-\n-  auto &meta = static_cast<const AST::AttrInputMetaItemContainer &> (input);\n-\n-  for (auto &current : meta.get_items ())\n-    {\n-      switch (current->get_kind ())\n-\t{\n-\tcase AST::MetaItemInner::Kind::MetaItem:\n-\t  {\n-\t    auto *meta_item = static_cast<AST::MetaItem *> (current.get ());\n-\n-\t    switch (meta_item->get_item_kind ())\n-\t      {\n-\t      case AST::MetaItem::ItemKind::NameValueStr:\n-\t\t{\n-\t\t  auto *nv = static_cast<AST::MetaNameValueStr *> (meta_item);\n-\n-\t\t  const std::string key = nv->get_name ().as_string ();\n-\n-\t\t  if (key != \"since\" && key != \"note\")\n-\t\t    {\n-\t\t      rust_error_at (nv->get_locus (), \"unknown meta item %qs\",\n-\t\t\t\t     key.c_str ());\n-\t\t      rust_inform (nv->get_locus (),\n-\t\t\t\t   \"expected one of %<since%>, %<note%>\");\n-\t\t    }\n-\t\t}\n-\t\tbreak;\n-\n-\t      case AST::MetaItem::ItemKind::Path:\n-\t\t{\n-\t\t  // #[deprecated(a,a)]\n-\t\t  auto *p = static_cast<AST::MetaItemPath *> (meta_item);\n-\n-\t\t  std::string ident = p->get_path ().as_string ();\n-\n-\t\t  rust_error_at (p->get_locus (), \"unknown meta item %qs\",\n-\t\t\t\t ident.c_str ());\n-\t\t  rust_inform (p->get_locus (),\n-\t\t\t       \"expected one of %<since%>, %<note%>\");\n-\t\t}\n-\t\tbreak;\n-\n-\t      case AST::MetaItem::ItemKind::Word:\n-\t\t{\n-\t\t  // #[deprecated(\"a\")]\n-\t\t  auto *w = static_cast<AST::MetaWord *> (meta_item);\n-\n-\t\t  rust_error_at (\n-\t\t    w->get_locus (),\n-\t\t    \"item in %<deprecated%> must be a key/value pair\");\n-\t\t}\n-\t\tbreak;\n-\n-\t      case AST::MetaItem::ItemKind::PathExpr:\n-\t\t{\n-\t\t  // #[deprecated(since=a)]\n-\t\t  auto *px = static_cast<AST::MetaItemPathExpr *> (meta_item);\n-\n-\t\t  rust_error_at (\n-\t\t    px->get_locus (),\n-\t\t    \"expected unsuffixed literal or identifier, found %qs\",\n-\t\t    px->get_expr ().as_string ().c_str ());\n-\t\t}\n-\t\tbreak;\n-\n-\t      case AST::MetaItem::ItemKind::Seq:\n-\t      case AST::MetaItem::ItemKind::ListPaths:\n-\t      case AST::MetaItem::ItemKind::ListNameValueStr:\n-\t      default:\n-\t\tgcc_unreachable ();\n-\t\tbreak;\n-\t      }\n-\t  }\n-\t  break;\n-\n-\tcase AST::MetaItemInner::Kind::LitExpr:\n-\tdefault:\n-\t  gcc_unreachable ();\n-\t  break;\n-\t}\n-    }\n-}\n-\n-/**\n- * Emit an error when an attribute is attached\n- * to an incompatable item type. e.g.:\n- *\n- * #[cold]\n- * struct A(u8, u8);\n- *\n- * Note that \"#[derive]\" is handled\n- * explicitly in rust-derive.cc\n- */\n-static void\n-check_valid_attribute_for_item (const AST::Attribute &attr,\n-\t\t\t\tconst AST::Item &item)\n-{\n-  if (item.get_item_kind () != AST::Item::Kind::Function\n-      && (attr.get_path () == Values::Attributes::TARGET_FEATURE\n-\t  || attr.get_path () == Values::Attributes::COLD\n-\t  || attr.get_path () == Values::Attributes::INLINE))\n-    {\n-      rust_error_at (attr.get_locus (),\n-\t\t     \"the %<#[%s]%> attribute may only be applied to functions\",\n-\t\t     attr.get_path ().as_string ().c_str ());\n-    }\n-  else if (attr.get_path () == Values::Attributes::REPR\n-\t   && item.get_item_kind () != AST::Item::Kind::Enum\n-\t   && item.get_item_kind () != AST::Item::Kind::Union\n-\t   && item.get_item_kind () != AST::Item::Kind::Struct)\n-    {\n-      rust_error_at (attr.get_locus (),\n-\t\t     \"the %<#[%s]%> attribute may only be applied \"\n-\t\t     \"to structs, enums and unions\",\n-\t\t     attr.get_path ().as_string ().c_str ());\n-    }\n-}\n-\n static bool\n is_proc_macro_type (const AST::Attribute &attribute)\n {\n-  auto result_opt = identify_builtin (attribute);\n+  auto result_opt = lookup_builtin (attribute);\n   if (!result_opt.has_value ())\n     return false;\n   auto result = result_opt.value ();\n@@ -469,77 +248,6 @@ check_proc_macro_non_root (const AST::Attribute &attr, location_t loc)\n     }\n }\n \n-void\n-AttributeChecker::check_inner_attribute (const AST::Attribute &attribute)\n-{\n-  auto result_opt = identify_builtin (attribute);\n-  if (!result_opt.has_value ())\n-    return;\n-  auto result = result_opt.value ();\n-\n-  if (__outer_attributes.find (result.name) != __outer_attributes.end ())\n-    rust_error_at (attribute.get_locus (),\n-\t\t   \"attribute cannot be used at crate level\");\n-}\n-\n-static void\n-check_link_section_attribute (const AST::Attribute &attribute)\n-{\n-  if (!attribute.has_attr_input ())\n-    {\n-      rust_error_at (attribute.get_locus (),\n-\t\t     \"malformed %<link_section%> attribute input\");\n-      rust_inform (attribute.get_locus (),\n-\t\t   \"must be of the form: %<#[link_section = \\\"name\\\"]%>\");\n-    }\n-}\n-\n-static void\n-check_export_name_attribute (const AST::Attribute &attribute)\n-{\n-  if (!attribute.has_attr_input ())\n-    {\n-      rust_error_at (attribute.get_locus (),\n-\t\t     \"malformed %<export_name%> attribute input\");\n-      rust_inform (attribute.get_locus (),\n-\t\t   \"must be of the form: %<#[export_name = \\\"name\\\"]%>\");\n-      return;\n-    }\n-\n-  if (attribute.has_attr_input ())\n-    {\n-      auto &attr_input = attribute.get_attr_input ();\n-      if (attr_input.get_attr_input_type ()\n-\t  == AST::AttrInput::AttrInputType::LITERAL)\n-\t{\n-\t  auto &literal_expr\n-\t    = static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();\n-\t  auto lit_type = literal_expr.get_lit_type ();\n-\t  switch (lit_type)\n-\t    {\n-\t    case AST::Literal::LitType::STRING:\n-\t    case AST::Literal::LitType::RAW_STRING:\n-\t    case AST::Literal::LitType::BYTE_STRING:\n-\t      return;\n-\t    default:\n-\t      break;\n-\t    }\n-\t}\n-    }\n-}\n-\n-static void\n-check_lint_attribute (const AST::Attribute &attribute, const char *name)\n-{\n-  if (!attribute.has_attr_input ())\n-    {\n-      rust_error_at (attribute.get_locus (), \"malformed %qs attribute input\",\n-\t\t     name);\n-      rust_inform (attribute.get_locus (),\n-\t\t   \"must be of the form: %<#[%s(lint1, lint2, ...)]%>\", name);\n-    }\n-}\n-\n void\n AttributeChecker::visit (AST::Attribute &attribute)\n {\n@@ -552,18 +260,6 @@ AttributeChecker::visit (AST::Attribute &attribute)\n \treturn; // Do not emit errors for attribute that'll get stripped.\n     }\n \n-  if (auto builtin = identify_builtin (attribute))\n-    {\n-      auto result = builtin.value ();\n-      // TODO: Add checks here for each builtin attribute\n-      // TODO: Have an enum of builtins as well, switching on strings is\n-      // annoying and costly\n-      if (result.name == Attrs::DOC)\n-\tcheck_doc_attribute (attribute);\n-      else if (result.name == Attrs::DEPRECATED)\n-\tcheck_deprecated_attribute (attribute);\n-    }\n-\n   AST::DefaultASTVisitor::visit (attribute);\n }\n \n@@ -870,10 +566,7 @@ void\n AttributeChecker::visit (AST::Module &module)\n {\n   for (auto &attr : module.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, module);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n \n   for (auto &item : module.get_items ())\n     for (auto &attr : item->get_outer_attrs ())\n@@ -886,10 +579,7 @@ void\n AttributeChecker::visit (AST::ExternCrate &crate)\n {\n   for (auto &attr : crate.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, crate);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n@@ -908,124 +598,12 @@ void\n AttributeChecker::visit (AST::UseDeclaration &declaration)\n {\n   for (auto &attr : declaration.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, declaration);\n-      check_proc_macro_non_function (attr);\n-    }\n-}\n-\n-static void\n-check_no_mangle_function (const AST::Attribute &attribute,\n-\t\t\t  const AST::Function &fun)\n-{\n-  if (attribute.has_attr_input ())\n-    {\n-      rust_error_at (attribute.get_locus (), ErrorCode::E0754,\n-\t\t     \"malformed %<no_mangle%> attribute input\");\n-      rust_inform (attribute.get_locus (),\n-\t\t   \"must be of the form: %<#[no_mangle]%>\");\n-    }\n-  if (!is_ascii_only (fun.get_function_name ().as_string ()))\n-    rust_error_at (fun.get_function_name ().get_locus (),\n-\t\t   \"the %<#[no_mangle]%> attribute requires ASCII identifier\");\n+    check_proc_macro_non_function (attr);\n }\n \n void\n AttributeChecker::visit (AST::Function &fun)\n {\n-  for (auto &attr : fun.get_outer_attrs ())\n-    check_valid_attribute_for_item (attr, fun);\n-\n-  auto check_crate_type = [] (const char *name, AST::Attribute &attribute) {\n-    if (!Session::get_instance ().options.is_proc_macro ())\n-      rust_error_at (attribute.get_locus (),\n-\t\t     \"the %<#[%s]%> attribute is only usable with crates of \"\n-\t\t     \"the %<proc-macro%> crate type\",\n-\t\t     name);\n-  };\n-\n-  BuiltinAttrDefinition result;\n-  for (auto &attribute : fun.get_outer_attrs ())\n-    {\n-      auto result = identify_builtin (attribute);\n-      if (!result)\n-\treturn;\n-\n-      auto name = result->name.c_str ();\n-\n-      if (result->name == Attrs::PROC_MACRO_DERIVE)\n-\t{\n-\t  if (!attribute.has_attr_input ())\n-\t    {\n-\t      rust_error_at (attribute.get_locus (),\n-\t\t\t     \"malformed %qs attribute input\", name);\n-\t      rust_inform (\n-\t\tattribute.get_locus (),\n-\t\t\"must be of the form: %<#[proc_macro_derive(TraitName, \"\n-\t\t\"/*opt*/ attributes(name1, name2, ...))]%>\");\n-\t    }\n-\t  check_crate_type (name, attribute);\n-\t}\n-      else if (result->name == Attrs::PROC_MACRO\n-\t       || result->name == Attrs::PROC_MACRO_ATTRIBUTE)\n-\t{\n-\t  check_crate_type (name, attribute);\n-\t}\n-      else if (result->name == Attrs::TARGET_FEATURE)\n-\t{\n-\t  if (!attribute.has_attr_input ())\n-\t    {\n-\t      rust_error_at (attribute.get_locus (),\n-\t\t\t     \"malformed %<target_feature%> attribute input\");\n-\t      rust_inform (attribute.get_locus (),\n-\t\t\t   \"must be of the form: %<#[target_feature(enable = \"\n-\t\t\t   \"\\\"name\\\")]%>\");\n-\t    }\n-\t  else if (!fun.get_qualifiers ().is_unsafe ())\n-\t    {\n-\t      rust_error_at (\n-\t\tattribute.get_locus (),\n-\t\t\"the %<#[target_feature]%> attribute can only be applied \"\n-\t\t\"to %<unsafe%> functions\");\n-\t    }\n-\t}\n-      else if (result->name == Attrs::NO_MANGLE)\n-\t{\n-\t  if (attribute.has_attr_input ())\n-\t    {\n-\t      rust_error_at (attribute.get_locus (),\n-\t\t\t     \"malformed %<no_mangle%> attribute input\");\n-\t      rust_inform (attribute.get_locus (),\n-\t\t\t   \"must be of the form: %<#[no_mangle]%>\");\n-\t    }\n-\t  else\n-\t    check_no_mangle_function (attribute, fun);\n-\t}\n-      else if (result->name == Attrs::EXPORT_NAME)\n-\t{\n-\t  check_export_name_attribute (attribute);\n-\t}\n-      else if (result->name == Attrs::ALLOW || result->name == \"deny\"\n-\t       || result->name == \"warn\" || result->name == \"forbid\")\n-\t{\n-\t  check_lint_attribute (attribute, name);\n-\t}\n-      else if (result->name == Attrs::LINK_NAME)\n-\t{\n-\t  if (!attribute.has_attr_input ())\n-\t    {\n-\t      rust_error_at (attribute.get_locus (),\n-\t\t\t     \"malformed %<link_name%> attribute input\");\n-\t      rust_inform (attribute.get_locus (),\n-\t\t\t   \"must be of the form: %<#[link_name = \\\"name\\\"]%>\");\n-\t    }\n-\t}\n-      else if (result->name == Attrs::LINK_SECTION)\n-\t{\n-\t  check_link_section_attribute (attribute);\n-\t}\n-    }\n-\n   if (fun.has_body ())\n     fun.get_definition ().value ()->accept_vis (*this);\n }\n@@ -1034,10 +612,7 @@ void\n AttributeChecker::visit (AST::TypeAlias &alias)\n {\n   for (auto &attr : alias.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, alias);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n@@ -1045,7 +620,6 @@ AttributeChecker::visit (AST::StructStruct &struct_item)\n {\n   for (auto &attr : struct_item.get_outer_attrs ())\n     {\n-      check_valid_attribute_for_item (attr, struct_item);\n       check_proc_macro_non_function (attr);\n     }\n \n@@ -1056,10 +630,7 @@ void\n AttributeChecker::visit (AST::TupleStruct &tuplestruct)\n {\n   for (auto &attr : tuplestruct.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, tuplestruct);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n@@ -1082,48 +653,28 @@ void\n AttributeChecker::visit (AST::Enum &enumeration)\n {\n   for (auto &attr : enumeration.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, enumeration);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n AttributeChecker::visit (AST::Union &u)\n {\n   for (auto &attr : u.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, u);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n AttributeChecker::visit (AST::ConstantItem &item)\n {\n   for (auto &attr : item.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, item);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n AttributeChecker::visit (AST::StaticItem &item)\n {\n   for (auto &attr : item.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, item);\n-      check_proc_macro_non_function (attr);\n-\n-      if (auto result = identify_builtin (attr))\n-\t{\n-\t  if (result->name == Attrs::LINK_SECTION)\n-\t    check_link_section_attribute (attr);\n-\t  else if (result->name == Attrs::EXPORT_NAME)\n-\t    check_export_name_attribute (attr);\n-\t}\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n void\n@@ -1134,10 +685,8 @@ void\n AttributeChecker::visit (AST::Trait &trait)\n {\n   for (auto &attr : trait.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, trait);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n+\n   AST::DefaultASTVisitor::visit (trait);\n }\n \n@@ -1145,10 +694,7 @@ void\n AttributeChecker::visit (AST::InherentImpl &impl)\n {\n   for (auto &attr : impl.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, impl);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n \n   AST::DefaultASTVisitor::visit (impl);\n }\n@@ -1157,10 +703,8 @@ void\n AttributeChecker::visit (AST::TraitImpl &impl)\n {\n   for (auto &attr : impl.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, impl);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n+\n   AST::DefaultASTVisitor::visit (impl);\n }\n \n@@ -1176,10 +720,7 @@ void\n AttributeChecker::visit (AST::ExternBlock &block)\n {\n   for (auto &attr : block.get_outer_attrs ())\n-    {\n-      check_valid_attribute_for_item (attr, block);\n-      check_proc_macro_non_function (attr);\n-    }\n+    check_proc_macro_non_function (attr);\n }\n \n // rust-macro.h\ndiff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h\nindex 4bac82012..3e5aea815 100644\n--- a/gcc/rust/util/rust-attributes.h\n+++ b/gcc/rust/util/rust-attributes.h\n@@ -29,6 +29,7 @@ class Attributes\n {\n public:\n   static bool is_known (const std::string &attribute_path);\n+  static bool valid_outer_attribute (const std::string &attribute_path);\n   static tl::optional<std::string>\n   extract_string_literal (const AST::Attribute &attr);\n };\n@@ -109,7 +110,6 @@ private:\n \n   // rust-ast.h\n   void visit (AST::Attribute &attribute) override;\n-  void visit (AST::Crate &crate) override;\n   void visit (AST::Token &tok) override;\n   void visit (AST::DelimTokenTree &delim_tok_tree) override;\n   void visit (AST::IdentifierExpr &ident_expr) override;\n@@ -277,7 +277,7 @@ private:\n };\n \n tl::optional<BuiltinAttrDefinition>\n-identify_builtin (const AST::Attribute &attribute);\n+lookup_builtin (const AST::Attribute &attribute);\n \n } // namespace Analysis\n } // namespace Rust\ndiff --git a/gcc/testsuite/rust/compile/issue-4226.rs b/gcc/testsuite/rust/compile/issue-4226.rs\nindex ec49606cf..e0763eca0 100644\n--- a/gcc/testsuite/rust/compile/issue-4226.rs\n+++ b/gcc/testsuite/rust/compile/issue-4226.rs\n@@ -1,6 +1,6 @@\n #![feature(no_core)]\n #![no_core]\n \n+// { dg-error \"valid forms for the attribute are ...doc.hidden.inline....... and ...doc ... string ...\" \"\" { target *-*-* } .+1 }\n #[doc]\n-// { dg-error \"attribute must be of the form ...doc.hidden.inline....... or ...doc = string..\" \"\" { target *-*-* } .-1 }\n-pub fn a(){}\n+pub fn a() {}\n",
    "prefixes": [
        "gccrs",
        "COMMIT",
        "02/10"
    ]
}