From nobody Sun Feb 8 02:21:19 2026 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2625D1643B for ; Tue, 13 Jan 2026 20:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768335704; cv=none; b=raoJqmvaTKvu9Kf7VODZv4nGmjrc40v+Rkc3ElXA82xFFZzlKZ+G33/74l5jRfrJ0/k81waiiMfLm1I4Ton4PFOTeJmkbn8lyudjxwgZwT4AiUa7f611pUwlREJkBkaq6LvWXtbzYH1xj6VwspXccm1ZoGd1/bpkEByXg3DLAWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768335704; c=relaxed/simple; bh=mTlU51QifGosjYNSBQR8uTI8bCZuwmnmwF7aa30HUQM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZPylXWOkZA6Qknf2zpwz+HjmFudfX6zORwzrpYb/Ax7DOpe4W2egBuwCU59EIfb3M9KtYxQhaPh3ONjbSlESHJQREbfOUj8oXqfWFaOASbmqfcDe88hb40D6NrCyit9RQA6M8ybmIhiewvNj+FOtp6czCFscBVRhkjI4af67kiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MAMxserv; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MAMxserv" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c4464dfeae8so5236086a12.3 for ; Tue, 13 Jan 2026 12:21:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768335702; x=1768940502; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LXuCzUKqWnjN6/8ck3FY/TEw/wJBfBn1Ef6/teMp+ws=; b=MAMxservcGcln+6cJpWvKviKZyzwunUJ36Zc7FX6fhtZ7vTrF7owdZiLcBlywyOnRt C6NwqFioyhZd/wgaxFRNtf7u7nO0cHq+DB+n2a15ml5t/7jmYBLj0jwPGSDzsZw9TETS keFBsh0xKO2J0jl3t0IdP3x6QeniYeYYlTTXb9fx8qsOvIeydCGws4iI1YFcP1vWSqOo lsC+YmHF66tcBMdz5QHX3FcmdvWiMFjewq97Vlc8S519snsULYHoJpuBJseS7gUyd7VE jbdUneK1D36cjiL46RzkDoYrMbk0bdoZin+CG4zo2U5LRLL+rZ9J4HMlGXSfj2q9ZPps P8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768335702; x=1768940502; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LXuCzUKqWnjN6/8ck3FY/TEw/wJBfBn1Ef6/teMp+ws=; b=G7+ApSXIocDyzRzo3fm5IWfzsJM0oLzj0jE+H8BxQ52liqLov0dOzcssDoG/ofLx70 7uHfmdkqCjOwSiOqp3PkEiRtAhfzLhsgTvNHqoxhZ2Rf9ITH4kyvrpl0KXrmH1LVYYVd 6fhHVZRCiZFXb8uFYMyLBu6YTFnCGJ8XTeabi5yk9ZtUuOzVzi4kNyFrAnq9cp3eFeo4 kvZdAN2q/zBJ0EmRsQnCM1cuWxoTj1Y8ECXxXMdPeARQOpXsd88iqZUdiQ9lnkodVhgk SqC/1i3yDcns1n5VSxizAwMRrtjKN8peVNPfkYsLLVxhDvopiv7vSc8/bz7I15VpJmTH G9Pw== X-Gm-Message-State: AOJu0Yxl0O4Dp2RC+/8+eBdR55JHk7kfXqruBDtB/B6Xg8TUzki80QaX slCdQMepQazc6WIxG2stgLjrGu8zdcnoIJRdKM0QNZYM2zQ+WNVD14LRi3ophb2U X-Gm-Gg: AY/fxX4rl2x5Qv1Ft64dkuoRi5LnFt/zHtptBdWbCtJiFEpM4rJ2DYJWKQQG//4kJxZ +tYBBPeoTBegA6l6517YDFArH6Qg5Dpirch0p/uoS6W6oI9l4S7ufnd3SnZdQGEjZPmzEtPJn/E qhUT8SQpNFQDFcmaxG2KkG0ZF5LyR1z1TMHwEX62nruyGHHCA3HclqEt2EHoAO/E/clucxHitc/ YMfLOATX8nykibmIt8hi0xbQK1EVw++L2KSBcihL0j+enueYrF7dBvvT5tZB6tKljWpT8YrkPSp RHPHo+r7IgpeM8O0nLfCnX21+ifBGBRkE29ZAP8lAZVxVh1Wt9PMt9hcjS5rvWQI7yapiezn6ll fAvy9QWvct/WTZSE2p2Ws1qKc+hdkDsJGfCssEi1Q+tPZ5SxvcXGZDzSmcRJcVhHXfF80FcvWHF yRvXj9vbLrggKmdOzwo7XBen6dj+Daqy6wbu2sN+7MYGdsfCvTNUQ= X-Received: by 2002:a17:902:d4c5:b0:29d:7b9b:515b with SMTP id d9443c01a7336-2a599d89aa6mr2393305ad.20.1768335701825; Tue, 13 Jan 2026 12:21:41 -0800 (PST) Received: from kailas.hsd1.or.comcast.net ([2601:1c2:1803:3ab0::73b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cd2b3asm206034115ad.88.2026.01.13.12.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 12:21:41 -0800 (PST) From: Ryan Foster To: linux-kernel@vger.kernel.org Cc: rust-for-linux@vger.kernel.org, joe@perches.com, ojeda@kernel.org, Ryan Foster Subject: [PATCH] checkpatch: warn on Rust comments with rustdoc links above items Date: Tue, 13 Jan 2026 12:21:38 -0800 Message-ID: <20260113202138.565332-1-foster.ryan.r@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a check to emit a warning when a `//` comment containing rustdoc link patterns (like [`Foo`]) appears directly above a Rust item declaration. This likely indicates the comment should use `///` documentation syntax instead. The check uses heuristics to reduce false positives: - Only triggers on comments with rustdoc link syntax [`...`] - Excludes special comments (SAFETY:, TODO:, FIXME:, etc.) - Only warns when directly above a Rust item (fn, struct, enum, etc.) Examples that trigger the warning: // Returns a reference to the underlying [`Table`]. fn table(&self) -> &Table { } Examples that do NOT trigger: // SAFETY: The `ptr` is guaranteed by the C code to be valid. unsafe fn foo() { } // TODO: fix this later fn bar() { } // Regular comment without rustdoc links fn baz() { } Link: https://github.com/Rust-for-Linux/linux/issues/1157 Suggested-by: Miguel Ojeda Signed-off-by: Ryan Foster --- scripts/checkpatch.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c0250244cf7a..1b09b9194c94 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3922,6 +3922,26 @@ sub process { "Avoid using '.L' prefixed local symbol names for denoting a range= of code via 'SYM_*_START/END' annotations; see Documentation/core-api/asm-= annotations.rst\n" . $herecurr); } =20 +# check for Rust comments that should likely be doc comments +# Warn when a // comment that looks like documentation (contains rustdoc +# link patterns like [`Foo`]) appears directly above a Rust item. + if ($realfile =3D~ /\.rs$/ && + $rawline =3D~ /^\+(\s*)\/\/\s+(.*)$/) { + my $comment_text =3D $2; + # Check if this looks like a doc comment (contains rustdoc link pattern= s) + # and is NOT a special comment like SAFETY:, TODO:, FIXME:, etc. + if ($comment_text =3D~ /\[`[^\]]+`\]/ && + $comment_text !~ /^\s*(?:SAFETY|TODO|FIXME|NOTE|XXX|HACK|BUG|INVARI= ANT):/) { + # Check if next line starts a Rust item + my $nextline =3D $rawlines[$linenr]; + if (defined($nextline) && + $nextline =3D~ /^\+\s*(?:pub(?:\s*\([^)]*\))?\s+)?(?:unsafe\s+)?(?= :async\s+)?(?:fn|struct|enum|impl|trait|const|static|type|mod|use)\b/) { + WARN("RUST_COMMENT_NOT_DOC", + "Comment with rustdoc link pattern may need '///' instead of '//= '\n" . $herecurr); + } + } + } + # check we are in a valid source file C or perl if not then ignore this hu= nk next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); =20 --=20 2.52.0