From 5718229882a23828cc4d9c866d0e19de397f2141 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Wed, 12 Apr 2023 13:36:17 +0200 Subject: [PATCH 1/2] Change the constructor of `salsa::Id` to const fn --- components/salsa-2022/src/id.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/salsa-2022/src/id.rs b/components/salsa-2022/src/id.rs index 9ea1db25..c1db29b3 100644 --- a/components/salsa-2022/src/id.rs +++ b/components/salsa-2022/src/id.rs @@ -26,14 +26,16 @@ impl Id { /// but it can be useful if you are using the type as a general /// purpose "identifier" internally. #[track_caller] - pub fn from_u32(x: u32) -> Self { - assert!(x < Self::MAX_U32); + pub const fn from_u32(x: u32) -> Self { Id { - value: NonZeroU32::new(x + 1).unwrap(), + value: match NonZeroU32::new(x + 1) { + Some(v) => v, + None => panic!("given value is too large to be a `salsa::Id`"), + }, } } - pub fn as_u32(self) -> u32 { + pub const fn as_u32(self) -> u32 { self.value.get() - 1 } } From cbafc307fc50157b6894f3c2930cb4157c182e2a Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sat, 22 Apr 2023 11:16:51 +0200 Subject: [PATCH 2/2] Fix trybuild ui test to adapt the change of rustc error message --- .../compile-fail/get-set-on-private-field.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/salsa-2022-tests/tests/compile-fail/get-set-on-private-field.stderr b/salsa-2022-tests/tests/compile-fail/get-set-on-private-field.stderr index 8d547292..a037885a 100644 --- a/salsa-2022-tests/tests/compile-fail/get-set-on-private-field.stderr +++ b/salsa-2022-tests/tests/compile-fail/get-set-on-private-field.stderr @@ -1,17 +1,17 @@ -error[E0624]: associated function `field` is private +error[E0624]: method `field` is private --> tests/compile-fail/get-set-on-private-field.rs:29:11 | 7 | #[salsa::input(jar = Jar)] - | -------------------------- private associated function defined here + | -------------------------- private method defined here ... 29 | input.field(&db); - | ^^^^^ private associated function + | ^^^^^ private method -error[E0624]: associated function `set_field` is private +error[E0624]: method `set_field` is private --> tests/compile-fail/get-set-on-private-field.rs:30:11 | 7 | #[salsa::input(jar = Jar)] - | -------------------------- private associated function defined here + | -------------------------- private method defined here ... 30 | input.set_field(&mut db).to(23); - | ^^^^^^^^^ private associated function + | ^^^^^^^^^ private method