Skip to content

Commit 59aa107

Browse files
Fully qualify std Result type (#1025)
* Fully qualify std Result type The prior macro expansion could produce errors if the macros were called in a context where `Result` is redefined, for example in a crate with its own `Result` type which pre-fills the error type. This replaces existing `Result` uses with `std::result::Result` to avoid the compilation error in that case. Signed-off-by: Andrew Lilley Brinker <[email protected]> * Use qualified names --------- Signed-off-by: Andrew Lilley Brinker <[email protected]> Co-authored-by: Micha Reiser <[email protected]>
1 parent 17bc55d commit 59aa107

File tree

6 files changed

+89
-66
lines changed

6 files changed

+89
-66
lines changed

components/salsa-macro-rules/src/setup_input_struct.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ macro_rules! setup_input_struct {
8181
#[allow(clippy::all)]
8282
#[allow(dead_code)]
8383
const _: () = {
84-
use salsa::plumbing as $zalsa;
84+
use ::salsa::plumbing as $zalsa;
8585
use $zalsa::input as $zalsa_struct;
8686

8787
type $Configuration = $Struct;
@@ -123,7 +123,7 @@ macro_rules! setup_input_struct {
123123
fn serialize<S: $zalsa::serde::Serializer>(
124124
fields: &Self::Fields,
125125
serializer: S,
126-
) -> Result<S::Ok, S::Error> {
126+
) -> ::std::result::Result<S::Ok, S::Error> {
127127
$zalsa::macro_if! {
128128
if $persist {
129129
$($serialize_fn(fields, serializer))?
@@ -135,7 +135,7 @@ macro_rules! setup_input_struct {
135135

136136
fn deserialize<'de, D: $zalsa::serde::Deserializer<'de>>(
137137
deserializer: D,
138-
) -> Result<Self::Fields, D::Error> {
138+
) -> ::std::result::Result<Self::Fields, D::Error> {
139139
$zalsa::macro_if! {
140140
if $persist {
141141
$($deserialize_fn(deserializer))?
@@ -198,8 +198,8 @@ macro_rules! setup_input_struct {
198198
}
199199

200200
$zalsa::macro_if! { $generate_debug_impl =>
201-
impl std::fmt::Debug for $Struct {
202-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201+
impl ::std::fmt::Debug for $Struct {
202+
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
203203
Self::default_debug_fmt(*self, f)
204204
}
205205
}
@@ -241,7 +241,7 @@ macro_rules! setup_input_struct {
241241

242242
$zalsa::macro_if! { $persist =>
243243
impl $zalsa::serde::Serialize for $Struct {
244-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
244+
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
245245
where
246246
S: $zalsa::serde::Serializer,
247247
{
@@ -250,7 +250,7 @@ macro_rules! setup_input_struct {
250250
}
251251

252252
impl<'de> $zalsa::serde::Deserialize<'de> for $Struct {
253-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
253+
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
254254
where
255255
D: $zalsa::serde::Deserializer<'de>,
256256
{
@@ -310,7 +310,7 @@ macro_rules! setup_input_struct {
310310
self,
311311
$field_index,
312312
ingredient,
313-
|fields, f| std::mem::replace(&mut fields.$field_index, f),
313+
|fields, f| ::std::mem::replace(&mut fields.$field_index, f),
314314
)
315315
}
316316
)*
@@ -336,11 +336,11 @@ macro_rules! setup_input_struct {
336336
}
337337

338338
/// Default debug formatting for this struct (may be useful if you define your own `Debug` impl)
339-
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
339+
pub fn default_debug_fmt(this: Self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result
340340
where
341341
// rustc rejects trivial bounds, but it cannot see through higher-ranked bounds
342342
// with its check :^)
343-
$(for<'__trivial_bounds> $field_ty: std::fmt::Debug),*
343+
$(for<'__trivial_bounds> $field_ty: ::std::fmt::Debug),*
344344
{
345345
$zalsa::with_attached_database(|db| {
346346
let zalsa = db.zalsa();
@@ -371,7 +371,7 @@ macro_rules! setup_input_struct {
371371
pub fn new<$Db>(self, db: &$Db) -> $Struct
372372
where
373373
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
374-
$Db: ?Sized + salsa::Database
374+
$Db: ?Sized + ::salsa::Database
375375
{
376376
let (zalsa, zalsa_local) = db.zalsas();
377377
let current_revision = zalsa.current_revision();
@@ -384,15 +384,15 @@ macro_rules! setup_input_struct {
384384
mod builder {
385385
use super::*;
386386

387-
use salsa::plumbing as $zalsa;
387+
use ::salsa::plumbing as $zalsa;
388388
use $zalsa::input as $zalsa_struct;
389389

390390
// These are standalone functions instead of methods on `Builder` to prevent
391391
// that the enclosing module can call them.
392392
pub(super) fn new_builder($($field_id: $field_ty),*) -> $Builder {
393393
$Builder {
394394
fields: ($($field_id,)*),
395-
durabilities: [salsa::Durability::default(); $N],
395+
durabilities: [::salsa::Durability::default(); $N],
396396
}
397397
}
398398

@@ -406,14 +406,14 @@ macro_rules! setup_input_struct {
406406
fields: ($($field_ty,)*),
407407

408408
/// The durabilities per field.
409-
durabilities: [salsa::Durability; $N],
409+
durabilities: [::salsa::Durability; $N],
410410
}
411411

412412
impl $Builder {
413413
/// Sets the durability of all fields.
414414
///
415415
/// Overrides any previously set durabilities.
416-
pub fn durability(mut self, durability: salsa::Durability) -> Self {
416+
pub fn durability(mut self, durability: ::salsa::Durability) -> Self {
417417
self.durabilities = [durability; $N];
418418
self
419419
}
@@ -431,7 +431,7 @@ macro_rules! setup_input_struct {
431431
$(
432432
/// Sets the durability for the field `$field_id`.
433433
#[must_use]
434-
pub fn $field_durability_id(mut self, durability: salsa::Durability) -> Self
434+
pub fn $field_durability_id(mut self, durability: ::salsa::Durability) -> Self
435435
{
436436
self.durabilities[$field_index] = durability;
437437
self

components/salsa-macro-rules/src/setup_interned_struct.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ macro_rules! setup_interned_struct {
9999
#[allow(clippy::all)]
100100
#[allow(dead_code)]
101101
const _: () = {
102-
use salsa::plumbing as $zalsa;
102+
use ::salsa::plumbing as $zalsa;
103103
use $zalsa::interned as $zalsa_struct;
104104

105105
type $Configuration = $StructWithStatic;
@@ -120,7 +120,7 @@ macro_rules! setup_interned_struct {
120120
#[derive(Hash)]
121121
struct StructKey<$db_lt, $($indexed_ty),*>(
122122
$($indexed_ty,)*
123-
std::marker::PhantomData<&$db_lt ()>,
123+
::std::marker::PhantomData<&$db_lt ()>,
124124
);
125125

126126
impl<$db_lt, $($indexed_ty,)*> $zalsa::interned::HashEqLike<StructKey<$db_lt, $($indexed_ty),*>>
@@ -129,7 +129,7 @@ macro_rules! setup_interned_struct {
129129
$($field_ty: $zalsa::interned::HashEqLike<$indexed_ty>),*
130130
{
131131

132-
fn hash<H: std::hash::Hasher>(&self, h: &mut H) {
132+
fn hash<H: ::std::hash::Hasher>(&self, h: &mut H) {
133133
$($zalsa::interned::HashEqLike::<$indexed_ty>::hash(&self.$field_index, &mut *h);)*
134134
}
135135

@@ -147,7 +147,7 @@ macro_rules! setup_interned_struct {
147147
}
148148
}
149149

150-
impl salsa::plumbing::interned::Configuration for $StructWithStatic {
150+
impl $zalsa::interned::Configuration for $StructWithStatic {
151151
const LOCATION: $zalsa::Location = $zalsa::Location {
152152
file: file!(),
153153
line: line!(),
@@ -171,7 +171,7 @@ macro_rules! setup_interned_struct {
171171
fn serialize<S: $zalsa::serde::Serializer>(
172172
fields: &Self::Fields<'_>,
173173
serializer: S,
174-
) -> Result<S::Ok, S::Error> {
174+
) -> ::std::result::Result<S::Ok, S::Error> {
175175
$zalsa::macro_if! {
176176
if $persist {
177177
$($serialize_fn(fields, serializer))?
@@ -183,7 +183,7 @@ macro_rules! setup_interned_struct {
183183

184184
fn deserialize<'de, D: $zalsa::serde::Deserializer<'de>>(
185185
deserializer: D,
186-
) -> Result<Self::Fields<'static>, D::Error> {
186+
) -> ::std::result::Result<Self::Fields<'static>, D::Error> {
187187
$zalsa::macro_if! {
188188
if $persist {
189189
$($deserialize_fn(deserializer))?
@@ -210,14 +210,14 @@ macro_rules! setup_interned_struct {
210210
}
211211

212212
impl< $($db_lt_arg)? > $zalsa::AsId for $Struct< $($db_lt_arg)? > {
213-
fn as_id(&self) -> salsa::Id {
213+
fn as_id(&self) -> ::salsa::Id {
214214
self.0.as_id()
215215
}
216216
}
217217

218218
impl< $($db_lt_arg)? > $zalsa::FromId for $Struct< $($db_lt_arg)? > {
219-
fn from_id(id: salsa::Id) -> Self {
220-
Self(<$Id>::from_id(id), std::marker::PhantomData)
219+
fn from_id(id: ::salsa::Id) -> Self {
220+
Self(<$Id>::from_id(id), ::std::marker::PhantomData)
221221
}
222222
}
223223

@@ -226,8 +226,8 @@ macro_rules! setup_interned_struct {
226226
unsafe impl< $($db_lt_arg)? > Sync for $Struct< $($db_lt_arg)? > {}
227227

228228
$zalsa::macro_if! { $generate_debug_impl =>
229-
impl< $($db_lt_arg)? > std::fmt::Debug for $Struct< $($db_lt_arg)? > {
230-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
229+
impl< $($db_lt_arg)? > ::std::fmt::Debug for $Struct< $($db_lt_arg)? > {
230+
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
231231
Self::default_debug_fmt(*self, f)
232232
}
233233
}
@@ -269,7 +269,7 @@ macro_rules! setup_interned_struct {
269269

270270
$zalsa::macro_if! { $persist =>
271271
impl<$($db_lt_arg)?> $zalsa::serde::Serialize for $Struct<$($db_lt_arg)?> {
272-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
272+
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
273273
where
274274
S: $zalsa::serde::Serializer,
275275
{
@@ -278,7 +278,7 @@ macro_rules! setup_interned_struct {
278278
}
279279

280280
impl<'de, $($db_lt_arg)?> $zalsa::serde::Deserialize<'de> for $Struct<$($db_lt_arg)?> {
281-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
281+
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
282282
where
283283
D: $zalsa::serde::Deserializer<'de>,
284284
{
@@ -301,17 +301,17 @@ macro_rules! setup_interned_struct {
301301
}
302302

303303
impl<$db_lt> $Struct< $($db_lt_arg)? > {
304-
pub fn $new_fn<$Db, $($indexed_ty: $zalsa::interned::Lookup<$field_ty> + std::hash::Hash,)*>(db: &$db_lt $Db, $($field_id: $indexed_ty),*) -> Self
304+
pub fn $new_fn<$Db, $($indexed_ty: $zalsa::interned::Lookup<$field_ty> + ::std::hash::Hash,)*>(db: &$db_lt $Db, $($field_id: $indexed_ty),*) -> Self
305305
where
306306
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
307-
$Db: ?Sized + salsa::Database,
307+
$Db: ?Sized + ::salsa::Database,
308308
$(
309309
$field_ty: $zalsa::interned::HashEqLike<$indexed_ty>,
310310
)*
311311
{
312312
let (zalsa, zalsa_local) = db.zalsas();
313313
$Configuration::ingredient(zalsa).intern(zalsa, zalsa_local,
314-
StructKey::<$db_lt>($($field_id,)* std::marker::PhantomData::default()), |_, data| ($($zalsa::interned::Lookup::into_owned(data.$field_index),)*))
314+
StructKey::<$db_lt>($($field_id,)* ::std::marker::PhantomData::default()), |_, data| ($($zalsa::interned::Lookup::into_owned(data.$field_index),)*))
315315
}
316316

317317
$(
@@ -337,11 +337,11 @@ macro_rules! setup_interned_struct {
337337
iftt ($($db_lt_arg)?) {
338338
impl $Struct<'_> {
339339
/// Default debug formatting for this struct (may be useful if you define your own `Debug` impl)
340-
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
340+
pub fn default_debug_fmt(this: Self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result
341341
where
342342
// rustc rejects trivial bounds, but it cannot see through higher-ranked bounds
343343
// with its check :^)
344-
$(for<$db_lt> $field_ty: std::fmt::Debug),*
344+
$(for<$db_lt> $field_ty: ::std::fmt::Debug),*
345345
{
346346
$zalsa::with_attached_database(|db| {
347347
let zalsa = db.zalsa();
@@ -361,11 +361,11 @@ macro_rules! setup_interned_struct {
361361
} else {
362362
impl $Struct {
363363
/// Default debug formatting for this struct (may be useful if you define your own `Debug` impl)
364-
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
364+
pub fn default_debug_fmt(this: Self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result
365365
where
366366
// rustc rejects trivial bounds, but it cannot see through higher-ranked bounds
367367
// with its check :^)
368-
$(for<$db_lt> $field_ty: std::fmt::Debug),*
368+
$(for<$db_lt> $field_ty: ::std::fmt::Debug),*
369369
{
370370
$zalsa::with_attached_database(|db| {
371371
let zalsa = db.zalsa();

0 commit comments

Comments
 (0)