From patchwork Wed Sep 6 13:53:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 137581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2323072vqo; Wed, 6 Sep 2023 06:51:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEulcRj+/V31EohRfrPWVVUBsUlDKzFTKEkKR8eqg1a2wAt/+9QtA644OTOZ+y4+6kVLUgk X-Received: by 2002:a17:906:1d9:b0:9a5:c7a6:1549 with SMTP id 25-20020a17090601d900b009a5c7a61549mr2406307ejj.39.1694008261454; Wed, 06 Sep 2023 06:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694008261; cv=none; d=google.com; s=arc-20160816; b=xk/1liWjK7Z5vK00KD0CJBxoOzlM+0VfHnUQ+T1Nlxxjdbk6NoopeC8wj2XZ6oXIuS 4vQ9wxyji8A6S34Vi5vU45vB4uJzlJUQC8VJYdTJqHny8vREPBN2HlCkq07hLvyGUNw8 ow+vHf6jnrHGAjDx6BMp5W0ahMyhN6Nc0RToKPOS1Sg4m6j3yKPTw/v/87XM8mbjZwTW Fx87SGDQHvbWKF+Xh3p2OBg6Vcun8yegwT3394wSMDhKd/TW/5lVt1aC5S/3NbsWg54G NWUdYkF5ZMV2b2UCQCo1evhacRLJpFbjHiR2bZmDoDD/MC+oQyPN+jreg/PmSZgltVJ0 vT+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=iZ2/J9wWiX3+Y86nmNymSLSxOFNDt+XfMViaQzFKl+0=; fh=wFq7tT6aDoWtju83L9lDAhBMEFwd5hWtfnM+XVolLD0=; b=O0lZwgPXyeKeBekrrKmNFq5tNKhf77Ajdn6u/iAuw3KHGaekwzQrJxqfAHu5zfjJhm lSIDWtTFBOlnlL2yOYZBxjQP+BzOYqbvSIXVShKaJUQurT30YUXsFt4unc0LeaeBuxWR /HVTV5fak1QWqLrkn4X32y1/Y8WWUc6hIQ5VCutwG76H745Z+PonVcHUPlHHQzlqHRoJ hmgqMCmSHpyyL6LJSRu3ZSETEukJPmwP9clsG5zW2vnpV/vyI2YG6c+SFuXIvNdOS3jI NG2E1SliF+cWUGedY8aSrw+P8iGzL4jIAVo+KxOcjWRyGngwk2zlilCFBn72Sz5Q50Hy 6imQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b=NF2jwLFX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hb8-20020a170906b88800b0099bcae257e3si9288608ejb.832.2023.09.06.06.51.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 06:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b=NF2jwLFX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 805D13855583 for ; Wed, 6 Sep 2023 13:50:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 50224385800C for ; Wed, 6 Sep 2023 13:49:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50224385800C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31c6d17aec4so3102678f8f.1 for ; Wed, 06 Sep 2023 06:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1694008179; x=1694612979; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iZ2/J9wWiX3+Y86nmNymSLSxOFNDt+XfMViaQzFKl+0=; b=NF2jwLFXaSFEz0vmxGtXyqPQNGQ0rpH9hnQGSGL4ty9nwAuqqdJGvpOECH1wVwsLCv 3eYwLchgf3SDHSy2OPgL/7oFJAhVhDdzAqin4evoupiBVb6EsGxnGTEaYSXVaAetfKzk 7LMSfpb8li/Pt3dqDb/7iWHkPFcT/JM+NWTL4A2zD6HNKZnCoWns2ZJLMFT7hOx1fnnD wYBh5bSoLhIyLkl5dic0ahV9wxkLmUSi1Wp09tiKGuk8LxFaSMp4fydXlVVPfgXEng2b 9yJvZptXylDMBXFg3cBlf9ogtI6EtICDeLw133GaBBn7tQ47N9wYuPMk/9rhn29mCguu /WfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694008179; x=1694612979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iZ2/J9wWiX3+Y86nmNymSLSxOFNDt+XfMViaQzFKl+0=; b=Gidtzf5Za7eSML7ii768H2r2+PxclrvGxhFELJjPDzSOEUrwDSiB5lAhYgVgPZOYcS Qw7uCS5DOBsK8tSWsnGBEQQXGNer9o094R4P8RVG1xdosu7PmOoRQfVlnap6EeBoZjCT 3vSOM7ZQkZLhth0W6rd6SbgW9xk814eKBk4yDz2566hOv3oQbGBRTD7ze3cJk25V5Esf bDGAQGHIem4BDTLT3G8ANUjV3v7dI5weNUvodHWDrpyD+Gl0sbN5eAdxBninMyzQMztT yh/J05ew7GBdFsLF5hobjCro08DkDG/noU0cjMezlClrkLuj1J3QrMoUUM9f4lJFZbZR 9/iw== X-Gm-Message-State: AOJu0YwtnBxxGGnqzCNUTP+eiIpm6pAaR5Bmp5vEehix870v0Dx3EOSP knSB1qvqkc/Gdt/hYs2r/TTgWAqK6YA5QxJfQKxC7F8= X-Received: by 2002:a5d:4d8f:0:b0:319:755c:3c1e with SMTP id b15-20020a5d4d8f000000b00319755c3c1emr2137457wru.11.1694008178812; Wed, 06 Sep 2023 06:49:38 -0700 (PDT) Received: from localhost.localdomain ([2001:861:5e4c:3bb0:fa3:84b9:61c0:bf1a]) by smtp.gmail.com with ESMTPSA id k8-20020a5d4288000000b003176aa612b1sm20528505wrq.38.2023.09.06.06.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 06:49:38 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] diagnostics: add error_meta Date: Wed, 6 Sep 2023 15:53:02 +0200 Message-Id: <20230906135303.3643659-2-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230906135303.3643659-1-arthur.cohen@embecosm.com> References: <20230906135303.3643659-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gcc-rust@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776296406575101371 X-GMAIL-MSGID: 1776296406575101371 From: David Malcolm Signed-off-by: David Malcolm --- gcc/diagnostic-core.h | 3 +++ gcc/diagnostic.cc | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h index 7334c79e8e6..c9e27fd2e6e 100644 --- a/gcc/diagnostic-core.h +++ b/gcc/diagnostic-core.h @@ -92,6 +92,9 @@ extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *, extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void error_at (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); +extern void error_meta (rich_location *, const diagnostic_metadata &, + const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3) ATTRIBUTE_NORETURN; /* Pass one of the OPT_W* from options.h as the second parameter. */ diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index c523f215bae..65c0cfbf11a 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -2108,6 +2108,21 @@ error_at (rich_location *richloc, const char *gmsgid, ...) va_end (ap); } +/* Same as above, but with metadata. */ + +void +error_meta (rich_location *richloc, const diagnostic_metadata &metadata, + const char *gmsgid, ...) +{ + gcc_assert (richloc); + + auto_diagnostic_group d; + va_list ap; + va_start (ap, gmsgid); + diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, DK_ERROR); + va_end (ap); +} + /* "Sorry, not implemented." Use for a language feature which is required by the relevant specification but not implemented by GCC. An object file will not be produced. */ From patchwork Wed Sep 6 13:53:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 137582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2323196vqo; Wed, 6 Sep 2023 06:51:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSJRC4rSTxMdwEeRnNW9mevv9cS+U0brWGri7BtlLO2DBzpEs7xX9JZEhF9db2kB92qLHc X-Received: by 2002:a05:6402:12ce:b0:525:d95b:cd4c with SMTP id k14-20020a05640212ce00b00525d95bcd4cmr2304374edx.20.1694008274030; Wed, 06 Sep 2023 06:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694008274; cv=none; d=google.com; s=arc-20160816; b=tBJb7U05kzdof9reYmyOG7whMgBBMCm/xI2i/gU8tr1gLFGWCIvT652jGTKeFBc8sW IDvg5iFe4FDT2a21nfHk9hwKitn7rVU8azaJQzHPU/vRFK62Byuzk9l7u03QhdaWvAx+ 7WT1N2rXqyiXu3CEyigaQ+7SN9Atds/+ZHWz69BDPZrbi3m+3a/CTWh8TlbRj5KLGr+Q PJAtXA8oOJ9X2HBcjQdh9TqTZN1ddeKGJH1Sl5yiSJQWDZx9eSpq85chW5PhqHs7lly+ uSnohVdDY+ef5qsrG/KMtnEkoomh1MEY2I4srTRpLOdz0uYY+pMKSrD7iRyBDxXT8w14 H+Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=hetkGrmeDG13oiHR8aZXsOSfVZui3rbu8np43OAk7+E=; fh=wFq7tT6aDoWtju83L9lDAhBMEFwd5hWtfnM+XVolLD0=; b=co+MkQzGud2cgrHK4l0kQpoiok3Qlx2beN7BYiplOLtfvI+DlF3ddms53Ebx5mGbb5 HRRThFGUlbaz3vCu8eRQSHtxp6F2xgqf1FFg3kaLU/q8m5XAFkSOjcLTP+tJbRLmZS5n po5d2FKOKBtG0TZx3pvb5tIs94Lxef9wibCPRj1MV7qH0Fcg/8LH5eZBWelz3zJ1HcUk lECMCHWtaImNXkhJgX9CP7XyU2nZOBB5bkNu0kV/N/VBVBDUmsbdSJHYzUdmBVrX5BEq mDGIeLtpcKe5z1z5SUbjnX/dshIcJGdVTftK41npyCgEQs4xle1qx6hxkrTUwD5C0p5Z BQ+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b=PBxRcs9O; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l19-20020a056402125300b005254b41f509si9317935edw.329.2023.09.06.06.51.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 06:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@embecosm.com header.s=google header.b=PBxRcs9O; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49F153856243 for ; Wed, 6 Sep 2023 13:50:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 7CA1D3857709 for ; Wed, 6 Sep 2023 13:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CA1D3857709 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31aeee69de0so3095607f8f.2 for ; Wed, 06 Sep 2023 06:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1694008182; x=1694612982; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hetkGrmeDG13oiHR8aZXsOSfVZui3rbu8np43OAk7+E=; b=PBxRcs9OTzDcW1KkRrip0ExFVLzQJGdzVQw1SGXULo+jBxgEDYJaBPojOtAwQH8WCV z9HuQnGykY/DGYlXhf6lxZFb0fhCVqavQunABwkDeVQ6H24XP2uCgDnNPHM4dMP3BkD8 EYXfl6as55RD4vx8BJttRwLRsyejiWPv9mLC20UZSI0IisU0Bb/HBZ0XlJ8+3tWjjbj7 dtx3hLzaE/sWTl1SY6mr+c2FANUv8KHfn3VHkCLNc5xDA0SuqjpjqhlyuCSdXEHchUs2 1WVKYHJfXqiKFwkXEt2kiS5+ci1S/czo/uNB2L1DU8nZo4coSgRhk9Bn6r/6JOX5tUpg sW1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694008182; x=1694612982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hetkGrmeDG13oiHR8aZXsOSfVZui3rbu8np43OAk7+E=; b=R+7r1qISJaGfu6JQaTvIYt7QMGGnzsZeMqg3ckXbk+OcDr1o9cLmNqdP2YngYDNBel 81Nssli4OEjj6E4slewu5Xh8py3axL2wkhmoGuJKDnGbwsMGcD3OcrzOiPOlhrH4ja1B XCzFLE/j3CwqldBrvWLMYC1oFm0j42U8JUw/UoyXTQwtGAajvQ+J6zQ/8+xwEz1a+AH0 NDp9+n7ps5xrB30SN+a6wbx85F09/DpJwyKEAZWdcMCIWBoSRt6wIcfZhdnK4/OfHQQV opX96BLFmM9UNnIoC/BoGCEEtxHJPX5GX8vDmGvp3I7/FAgJltfPNRA86GqXHbtw0Aca sDvQ== X-Gm-Message-State: AOJu0YwxxXRdc3Bz++uB5wuwBJxsa2cnO4K9QR9cK3u4OnhxOPxnP72L KQoyAgl9ezwk76gUx/21G2dUYcWBsv25QrAs5ft4Kuc= X-Received: by 2002:adf:e80b:0:b0:319:6ec3:79c7 with SMTP id o11-20020adfe80b000000b003196ec379c7mr2211950wrm.36.1694008181819; Wed, 06 Sep 2023 06:49:41 -0700 (PDT) Received: from localhost.localdomain ([2001:861:5e4c:3bb0:fa3:84b9:61c0:bf1a]) by smtp.gmail.com with ESMTPSA id k8-20020a5d4288000000b003176aa612b1sm20528505wrq.38.2023.09.06.06.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 06:49:41 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] Experiment with adding an error code to an error Date: Wed, 6 Sep 2023 15:53:03 +0200 Message-Id: <20230906135303.3643659-3-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230906135303.3643659-1-arthur.cohen@embecosm.com> References: <20230906135303.3643659-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gcc-rust@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776296419904305948 X-GMAIL-MSGID: 1776296419904305948 From: David Malcolm Signed-off-by: David Malcolm --- gcc/rust/rust-diagnostics.cc | 11 +++++++ gcc/rust/rust-diagnostics.h | 18 ++++++++++ gcc/rust/rust-gcc-diagnostics.cc | 33 +++++++++++++++++++ gcc/rust/typecheck/rust-casts.cc | 2 +- .../rust/compile/bad_as_bool_char.rs | 4 +-- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc index 4e5c2ececd4..f29aec67652 100644 --- a/gcc/rust/rust-diagnostics.cc +++ b/gcc/rust/rust-diagnostics.cc @@ -166,6 +166,17 @@ rust_error_at (const Location location, const char *fmt, ...) va_end (ap); } +void +rust_error_at (const RichLocation &location, const ErrorCode code, + const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + rust_be_error_at (location, code, expand_message (fmt, ap)); + va_end (ap); +} + void rust_warning_at (const Location location, int opt, const char *fmt, ...) { diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h index 43fee8baf4f..d198bd5736f 100644 --- a/gcc/rust/rust-diagnostics.h +++ b/gcc/rust/rust-diagnostics.h @@ -50,6 +50,18 @@ // clang-format off // simple location + +struct ErrorCode +{ + explicit ErrorCode (const char *str) : m_str (str) + { + gcc_assert (str); + gcc_assert (str[0] == 'E'); + } + + const char *m_str; +}; + extern void rust_internal_error_at (const Location, const char *fmt, ...) RUST_ATTRIBUTE_GCC_DIAG (2, 3) @@ -72,6 +84,9 @@ rust_inform (const Location, const char *fmt, ...) extern void rust_error_at (const RichLocation &, const char *fmt, ...) RUST_ATTRIBUTE_GCC_DIAG (2, 3); +extern void +rust_error_at (const RichLocation &, const ErrorCode, const char *fmt, ...) + RUST_ATTRIBUTE_GCC_DIAG (3, 4); // clang-format on // These interfaces provide a way for the front end to ask for @@ -97,6 +112,9 @@ rust_be_error_at (const Location, const std::string &errmsg); extern void rust_be_error_at (const RichLocation &, const std::string &errmsg); extern void +rust_be_error_at (const RichLocation &, const ErrorCode, + const std::string &errmsg); +extern void rust_be_warning_at (const Location, int opt, const std::string &warningmsg); extern void rust_be_fatal_error (const Location, const std::string &errmsg) diff --git a/gcc/rust/rust-gcc-diagnostics.cc b/gcc/rust/rust-gcc-diagnostics.cc index 72d2c068541..58c0a5654ea 100644 --- a/gcc/rust/rust-gcc-diagnostics.cc +++ b/gcc/rust/rust-gcc-diagnostics.cc @@ -22,6 +22,7 @@ #include "rust-diagnostics.h" #include "options.h" +#include "diagnostic-metadata.h" void rust_be_internal_error_at (const Location location, const std::string &errmsg) @@ -70,6 +71,38 @@ rust_be_error_at (const RichLocation &location, const std::string &errmsg) error_at (&gcc_loc, "%s", errmsg.c_str ()); } +class rust_error_code_rule : public diagnostic_metadata::rule +{ +public: + rust_error_code_rule (const ErrorCode code) : m_code (code) {} + + char *make_description () const final override + { + return xstrdup (m_code.m_str); + } + + char *make_url () const final override + { + return concat ("https://doc.rust-lang.org/error-index.html#", m_code.m_str, + NULL); + } + +private: + const ErrorCode m_code; +}; + +void +rust_be_error_at (const RichLocation &location, const ErrorCode code, + const std::string &errmsg) +{ + /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ + rich_location &gcc_loc = const_cast (location.get ()); + diagnostic_metadata m; + rust_error_code_rule rule (code); + m.add_rule (rule); + error_meta (&gcc_loc, m, "%s", errmsg.c_str ()); +} + void rust_be_get_quotechars (const char **open_qu, const char **close_qu) { diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index e379216b948..987542e59c4 100644 --- a/gcc/rust/typecheck/rust-casts.cc +++ b/gcc/rust/typecheck/rust-casts.cc @@ -283,7 +283,7 @@ TypeCastRules::emit_cast_error () const RichLocation r (locus); r.add_range (from.get_locus ()); r.add_range (to.get_locus ()); - rust_error_at (r, "invalid cast %<%s%> to %<%s%>", + rust_error_at (r, ErrorCode ("E0054"), "invalid cast %<%s%> to %<%s%>", from.get_ty ()->get_name ().c_str (), to.get_ty ()->get_name ().c_str ()); } diff --git a/gcc/testsuite/rust/compile/bad_as_bool_char.rs b/gcc/testsuite/rust/compile/bad_as_bool_char.rs index 91a28eebe00..9652915fe11 100644 --- a/gcc/testsuite/rust/compile/bad_as_bool_char.rs +++ b/gcc/testsuite/rust/compile/bad_as_bool_char.rs @@ -5,13 +5,13 @@ pub fn main () let fone = t as f32; // { dg-error "invalid cast" } let fzero = f as f64; // { dg-error "invalid cast" } - let nb = 0u8 as bool; // { dg-error "invalid cast" } + let nb = 0u8 as bool; // { dg-error "invalid cast .u8. to .bool. \\\[E0054\\\]" } let nc = true as char; // { dg-error "invalid cast" } let a = 'a'; let b = 'b'; let fa = a as f32; // { dg-error "invalid cast" } - let bb = b as bool; // { dg-error "invalid cast" } + let bb = b as bool; // { dg-error "invalid cast .char. to .bool. \\\[E0054\\\]" } let t32: u32 = 33; let ab = t32 as char; // { dg-error "invalid cast" }