From patchwork Thu May 29 13:14:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 893220 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 E525C2253F7; Thu, 29 May 2025 13:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748524504; cv=none; b=PpOofkRDVFkjKCnCLlJPyT3RZ/8BuOAvqouum5RnZMfN1uUSaVMgKNBudPFdM2fZcF00wfxQ3f4SKw6wHA2MbPKDJ00TNUixJA6NUqajwLx3kFFXxWaFSd1rKcrNZUw9mBO04wa9DA4PRcx/rtU+oDHxyhmkaExI8z7MRMOeHK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748524504; c=relaxed/simple; bh=0UGHp7jfAc0Ku2jl5ePFDVyN+3ieU31F+io2vpu3t8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XSBsqkYE3yNRS+uEoJagcFHykeaLHwUjVVeavovJHcPGOz7ctz5bcdjznJGFfyvC3/N2Cw0GNh6qHiMH9qX4hpLEtYotZqPzaqZeuiCJrh8489YV354ajMhypeuTApNRkRFrlGXVc3wjAmvRFDmcEObBSOXXF/88/NxDhhvENiY= 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=DPAegats; arc=none smtp.client-ip=209.85.219.49 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="DPAegats" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6f8b2682d61so20013456d6.0; Thu, 29 May 2025 06:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748524501; x=1749129301; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=falrcJggJ2+8U8zphNs4lD118xsCQzXc3zARnKFg7Do=; b=DPAegatsFzXU4j09hxGNLGcIfRgRCzQGuA55B92YMMv2zJbtuGYHM1bdogjeUa7IQ8 oc7pK/ekZFULqCpLgkKHT7NynXoBeLWmwJD3TKOzRaMPHH33XD2MZbRFnHLmZ9BW3Xk8 036jbAkPJ4VZWnijCJjEJClIOZ+YuWQsJ+3Vil92Sh+KenVw0Ir80syAwLB7wwJc5TAW bavWBg/JcoTJA5pS1R1vPUjPulw7AD5BcoK/BdUhEVSrjsl7B2wzuEu3/jlra9eGdyV+ YgXpGM9i8/ivnLyrNBk81RSpdci+lqpgrUv4xaDDAefsfsgpI/rII0iDSp5mT+gR+83x ZkAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748524501; x=1749129301; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=falrcJggJ2+8U8zphNs4lD118xsCQzXc3zARnKFg7Do=; b=ajCa/3jP4oamhC14IyFErNE2Kq3rkn2qchN5eCQ0gsocFP+2xm2mAezqWdkOGNUXDT jxAObwplgIQSWeZSIjiJ4SLzuQaVR9LUPi80QHu+SD3yg33eqg/zkx/Aw2pp0YjGv4x3 q6zxndhPOlHGkRM/gZwIaudpFc9ugUw5ntq93aD9to2v8feGqqDVkck3BcOirl8A0HVn BQyjWNJSp9Z1ZpNoVt/ioCyl/qR9yttUZ+QOFrSF276+9DQN4HN2VbPIMqzOvI3MUg7w +QI9gSswn4szITbFjMGGeYODTjcCvSLGQoSv5KdKgQdUxW9IIAY7bstdtYqBaHddKpW9 EhqQ== X-Forwarded-Encrypted: i=1; AJvYcCU/P1xAtKazmJAQNpsUKkJApKeWuOmyEsJ97qg1ZLaom7QmI3CWGB+qYvHs6mxJr499DWcVwuTxKupUZe6r/Jg=@vger.kernel.org, AJvYcCVOEwve/zqP3ihlX0vQOfLNiNXrErHty9KSrd4Ne5LUjXXLEsc+BKWj6Ld7GaWuSoc1nLiiHZGT3XJg8iI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+D2+2g4ucRh2ngkpd4tJpZoJ8cgvOhuHU8H4v9zDcRrcDlPLZ Q07eoDf192rktrTs6G8WmzZWFb/6jIoZ/rO5iO6lhok41w4eVLQwZijp X-Gm-Gg: ASbGncsQQXtUhJD1gJk75ln0HF7bQmiiZ38sIRzO3c9vUE+J/N8rcYGerst1IaRRuZt QYSP7behpEd2uTP96hFV/avNuHHxaYUf5slIL/E2kQN+WwDzSD2MrCCmR3tILgYTz3j0kVkC4Xi xz21qvxJRxb/PjMFm67PSUa3RN+OZdlYVeTVGa6Fk1rfNAftvtx/yY/hkMwKj2KouynrmMjjQHt Z/ELAGLUmiEkGPS+2dOP6k6/CmVUFUl5I6sowVcuwwo4HbkvK6e3jZ0ciau0kWAXzkrIciTdzBo lvFA3PH6V8A+Nv/URoU1y5BiUk11QQdZvnumH6uTconxjI8oWdyWd/9U9Ekd6JV8ejyTCPM7zSi Evz0= X-Google-Smtp-Source: AGHT+IFidKN7BhBHdfTtVQh3V/cGxBjfsgeVT0N78UQrKLFG1VdlQw07H8YFDtFPz5RLtsN3nyBGKQ== X-Received: by 2002:a05:6214:500f:b0:6f5:4dfa:6944 with SMTP id 6a1803df08f44-6fac5d12b7emr58898776d6.3.1748524501531; Thu, 29 May 2025 06:15:01 -0700 (PDT) Received: from tamird-mac.local ([2600:4041:5be7:7c00:da0:d9ee:5c71:a02a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d09a0f7d96sm91528285a.30.2025.05.29.06.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 May 2025 06:15:01 -0700 (PDT) From: Tamir Duberstein Date: Thu, 29 May 2025 09:14:58 -0400 Subject: [PATCH v2 1/2] rust: replace length checks with match Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250529-idiomatic-match-slice-v2-1-4925ca2f1550@gmail.com> References: <20250529-idiomatic-match-slice-v2-0-4925ca2f1550@gmail.com> In-Reply-To: <20250529-idiomatic-match-slice-v2-0-4925ca2f1550@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Brendan Higgins , David Gow , Rae Moar Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Use a match expression with slice patterns instead of length checks and indexing. The result is more idiomatic, which is a better example for future Rust code authors. Reviewed-by: Alice Ryhl Signed-off-by: Tamir Duberstein --- scripts/rustdoc_test_gen.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs index 1ca253594d38..d796481f4359 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -85,24 +85,23 @@ fn find_candidates( } } - assert!( - valid_paths.len() > 0, - "No path candidates found for `{file}`. This is likely a bug in the build system, or some \ - files went away while compiling." - ); - - if valid_paths.len() > 1 { - eprintln!("Several path candidates found:"); - for path in valid_paths { - eprintln!(" {path:?}"); + match valid_paths.as_slice() { + [] => panic!( + "No path candidates found for `{file}`. This is likely a bug in the build system, or \ + some files went away while compiling." + ), + [valid_path] => valid_path.to_str().unwrap(), + valid_paths => { + eprintln!("Several path candidates found:"); + for path in valid_paths { + eprintln!(" {path:?}"); + } + panic!( + "Several path candidates found for `{file}`, please resolve the ambiguity by \ + renaming a file or folder." + ); } - panic!( - "Several path candidates found for `{file}`, please resolve the ambiguity by renaming \ - a file or folder." - ); } - - valid_paths[0].to_str().unwrap() } fn main() { From patchwork Thu May 29 13:14:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamir Duberstein X-Patchwork-Id: 893967 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 A0C7519ABB6; Thu, 29 May 2025 13:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748524515; cv=none; b=gCU1/wS8VURYiucZ0+ppxUHbMCHexXYy80HlR1STbwusnjTUjwLz14nuH5cKRrizNRXQaKEM/PaZWfMlpzlPyLNRWr1QBS5rJFewnCtX59zIYKq0inaJ+CKQZWs2OPrevl/DV15shIoSYozzVWXYpTwvpN60AfdStNSBavcXgzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748524515; c=relaxed/simple; bh=izTBMmwweAGuAnXHJtubgKrUDiBkjD0FY51OCVbyMBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bDdwOpbguNMQUwygZcbxk0J8juANZObXdZfgHczgNhEYCc2FnDS9unU+HECy4z/XCFIwjRvpmu8AGWygNDwaC5KA1uUh47XCVl+FJdGT2vrIIBLTZUX7xdraNggU4fMvHfpro+uu3AUCNRQXmEdfxksgWiDRc5vHi6y3u+7tVgU= 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=HTOFfuSB; arc=none smtp.client-ip=209.85.210.182 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="HTOFfuSB" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-7376dd56f8fso1000876b3a.2; Thu, 29 May 2025 06:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748524513; x=1749129313; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yDjprSXjpWj7IN/c9BrZgUvfGIdrnvmdvSk6h2l12/E=; b=HTOFfuSBFocmpqb3FmcErkXaD9FaN0+X2HtlYB9TLwgEfuFnv6wIo3SnVru9208Rg7 LvS369+mX8kZQfIritMPDjZ0tLRo+U/DGtNPCqOM+Qy5O1GRwhMdAWZlVI7n7dJSmV8L Qmg3YcG9gEsmdIGEflGwaTP/Jvb6rgiF9tGetxOb2E15v0iRIbWFind5m0NvLsoQUFAe wXjevlqhvb2VPw7byGpaCKZ3hOeA/WAP5E9Lg/SEp4/2ds17oMSt5s/Ik+K5DMLhuPWl 01JcmZqrc/J9VDA83mXm+rw6bcEKIHnzPW7lv0fpvGRmQlrl6dskumrTV6yQSbtVz9/M ntGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748524513; x=1749129313; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yDjprSXjpWj7IN/c9BrZgUvfGIdrnvmdvSk6h2l12/E=; b=w3X4wXpRKF1267XH8BlvjK5Bdm5EGcVMyzRtraS+qjl9JEEINqcX3XDVIWjIIslkz5 8CpIeWwa3e9eq08vKTbzV/ai8FVwofL0BJPQFktKOkd7OwhdSOHhrFvbZ5td4isw3GKB w30/pkvTQvzIqt3LE6WCEcNNdIVVvJB6NX8UPsPClsdzS8ROL9jn1vYQj5AngMA7M9n+ UzhvMU6KX1ATb5yb1hBrqcgo6RPDUlBVFADaPkT5FikQn9UB7OXLj/1FsgkEQXxTL3na 2EVkQAwMWX4J5Z92LrdDEIJFnSU4yCTUefg9wZ+qL1gKhzJuDgv8nALD4hEIlPQPRNj0 QdRQ== X-Forwarded-Encrypted: i=1; AJvYcCX1qA8M+7jtKtgItw3t9nHV1EeaW8SfzY9zMEFEru31DmQMGkl0KWE2+iZswlvXytdioXeMH6k6UyL0D08=@vger.kernel.org, AJvYcCX2ar1PYiiuWPEtX1THb1mTh/qXX58uF2nIrTzupxt7Iy8r7zHBvtNry1k16YlQhuGlN2Z8+uBjKiwlZEncG6o=@vger.kernel.org X-Gm-Message-State: AOJu0YxYe3BNaY4nuKJUi788/GXkYVK1mJVvqJVp+ywfbRCt6e1w07Q0 Z26cyZHDmKuOmqjPFvznbSbMCNr5jEwpjl7HLzuVrsQHWlUAYJDhC2ywYf+69/B/TZI= X-Gm-Gg: ASbGnctC3rBMvbdVEPunTIpUzZtrgBd5ebMlpVzVuwXJwT/M1sBFhT/2VjBGZ9b8fiw TMd2cwPwCoOb7Pqtm1vuEgYRFO4Zgfgh0rJLt54D0Jhx6dbUvDI4HPLjFxNcqi0bUG0rVHGjDE7 I0tOqQmAtnZGWzzpc5qOCB7J7P1ZAlm4IehP0/5KzZGwd3+dfoIB7LrRlzP9dE0jhHSXr2XZmYx wuwqsuzBKmeAJnTXGYNayFdfthRCtBiYQT3uO1HLUNbim3HbJOHOcXTP00K/iM/37plSumEO40c VUrEqZOboNbKHy+nm78/dnBl87aVmwswQLHS0MxmwwSguOq14rwmnXygsT92UZ5pcTRAhMJ3NIX oq1fKbsUfzNhD9Q== X-Google-Smtp-Source: AGHT+IFZS4//fV7KzceypZuAS7jRaNoJwp5bqwCgeHwzNmiDtrX7cm9iZXd/41HxrzX2+eLp4Tw1Yg== X-Received: by 2002:a05:620a:4550:b0:7ca:ef12:966d with SMTP id af79cd13be357-7d09aba561dmr374330585a.56.1748524502690; Thu, 29 May 2025 06:15:02 -0700 (PDT) Received: from tamird-mac.local ([2600:4041:5be7:7c00:da0:d9ee:5c71:a02a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d09a0f7d96sm91528285a.30.2025.05.29.06.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 May 2025 06:15:02 -0700 (PDT) From: Tamir Duberstein Date: Thu, 29 May 2025 09:14:59 -0400 Subject: [PATCH v2 2/2] rust: emit path candidates in panic message Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250529-idiomatic-match-slice-v2-2-4925ca2f1550@gmail.com> References: <20250529-idiomatic-match-slice-v2-0-4925ca2f1550@gmail.com> In-Reply-To: <20250529-idiomatic-match-slice-v2-0-4925ca2f1550@gmail.com> To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Brendan Higgins , David Gow , Rae Moar Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.15-dev Include all information in the panic message rather than emit fragments to stderr. Signed-off-by: Tamir Duberstein --- scripts/rustdoc_test_gen.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs index d796481f4359..f95129b03cd8 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -92,13 +92,15 @@ fn find_candidates( ), [valid_path] => valid_path.to_str().unwrap(), valid_paths => { - eprintln!("Several path candidates found:"); + use std::fmt::Write; + + let mut candidates = String::new(); for path in valid_paths { - eprintln!(" {path:?}"); + write!(&mut candidates, " {path:?}").unwrap(); } panic!( "Several path candidates found for `{file}`, please resolve the ambiguity by \ - renaming a file or folder." + renaming a file or folder. Candidates:\n{candidates}", ); } }