Skip to content

Commit 3ffc9a2

Browse files
authored
Option::replace instead of std::mem::replace (#746)
1 parent 7a45da9 commit 3ffc9a2

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

components/salsa-macros/src/options.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
131131
let ident: syn::Ident = syn::Ident::parse_any(input)?;
132132
if ident == "return_ref" {
133133
if A::RETURN_REF {
134-
if let Some(old) = std::mem::replace(&mut options.return_ref, Some(ident)) {
134+
if let Some(old) = options.return_ref.replace(ident) {
135135
return Err(syn::Error::new(
136136
old.span(),
137137
"option `return_ref` provided twice",
@@ -145,7 +145,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
145145
}
146146
} else if ident == "no_eq" {
147147
if A::NO_EQ {
148-
if let Some(old) = std::mem::replace(&mut options.no_eq, Some(ident)) {
148+
if let Some(old) = options.no_eq.replace(ident) {
149149
return Err(syn::Error::new(old.span(), "option `no_eq` provided twice"));
150150
}
151151
} else {
@@ -156,7 +156,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
156156
}
157157
} else if ident == "no_debug" {
158158
if A::NO_DEBUG {
159-
if let Some(old) = std::mem::replace(&mut options.no_debug, Some(ident)) {
159+
if let Some(old) = options.no_debug.replace(ident) {
160160
return Err(syn::Error::new(
161161
old.span(),
162162
"option `no_debug` provided twice",
@@ -170,7 +170,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
170170
}
171171
} else if ident == "no_lifetime" {
172172
if A::NO_LIFETIME {
173-
if let Some(old) = std::mem::replace(&mut options.no_lifetime, Some(ident)) {
173+
if let Some(old) = options.no_lifetime.replace(ident) {
174174
return Err(syn::Error::new(
175175
old.span(),
176176
"option `no_lifetime` provided twice",
@@ -184,7 +184,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
184184
}
185185
} else if ident == "no_clone" {
186186
if A::NO_CLONE {
187-
if let Some(old) = std::mem::replace(&mut options.no_clone, Some(ident)) {
187+
if let Some(old) = options.no_clone.replace(ident) {
188188
return Err(syn::Error::new(
189189
old.span(),
190190
"option `no_clone` provided twice",
@@ -198,7 +198,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
198198
}
199199
} else if ident == "singleton" {
200200
if A::SINGLETON {
201-
if let Some(old) = std::mem::replace(&mut options.singleton, Some(ident)) {
201+
if let Some(old) = options.singleton.replace(ident) {
202202
return Err(syn::Error::new(
203203
old.span(),
204204
"option `singleton` provided twice",
@@ -212,7 +212,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
212212
}
213213
} else if ident == "specify" {
214214
if A::SPECIFY {
215-
if let Some(old) = std::mem::replace(&mut options.specify, Some(ident)) {
215+
if let Some(old) = options.specify.replace(ident) {
216216
return Err(syn::Error::new(
217217
old.span(),
218218
"option `specify` provided twice",
@@ -228,7 +228,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
228228
if A::DB {
229229
let _eq = Equals::parse(input)?;
230230
let path = syn::Path::parse(input)?;
231-
if let Some(old) = std::mem::replace(&mut options.db_path, Some(path)) {
231+
if let Some(old) = options.db_path.replace(path) {
232232
return Err(syn::Error::new(old.span(), "option `db` provided twice"));
233233
}
234234
} else {
@@ -241,7 +241,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
241241
if A::RECOVERY_FN {
242242
let _eq = Equals::parse(input)?;
243243
let path = syn::Path::parse(input)?;
244-
if let Some(old) = std::mem::replace(&mut options.recovery_fn, Some(path)) {
244+
if let Some(old) = options.recovery_fn.replace(path) {
245245
return Err(syn::Error::new(
246246
old.span(),
247247
"option `recovery_fn` provided twice",
@@ -257,7 +257,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
257257
if A::DATA {
258258
let _eq = Equals::parse(input)?;
259259
let ident = syn::Ident::parse(input)?;
260-
if let Some(old) = std::mem::replace(&mut options.data, Some(ident)) {
260+
if let Some(old) = options.data.replace(ident) {
261261
return Err(syn::Error::new(old.span(), "option `data` provided twice"));
262262
}
263263
} else {
@@ -271,7 +271,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
271271
let _eq = Equals::parse(input)?;
272272
let lit = syn::LitInt::parse(input)?;
273273
let value = lit.base10_parse::<usize>()?;
274-
if let Some(old) = std::mem::replace(&mut options.lru, Some(value)) {
274+
if let Some(old) = options.lru.replace(value) {
275275
return Err(syn::Error::new(old.span(), "option `lru` provided twice"));
276276
}
277277
} else {
@@ -284,8 +284,7 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
284284
if A::CONSTRUCTOR_NAME {
285285
let _eq = Equals::parse(input)?;
286286
let ident = syn::Ident::parse(input)?;
287-
if let Some(old) = std::mem::replace(&mut options.constructor_name, Some(ident))
288-
{
287+
if let Some(old) = options.constructor_name.replace(ident) {
289288
return Err(syn::Error::new(
290289
old.span(),
291290
"option `constructor` provided twice",

src/table/memo.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,11 @@ impl MemoTable {
135135
if memos.len() < memo_ingredient_index + 1 {
136136
memos.resize_with(memo_ingredient_index + 1, MemoEntry::default);
137137
}
138-
let old_entry = std::mem::replace(
139-
&mut memos[memo_ingredient_index].data,
140-
Some(MemoEntryData {
141-
type_id: TypeId::of::<M>(),
142-
to_dyn_fn: Self::to_dyn_fn::<M>(),
143-
atomic_memo: AtomicPtr::new(Self::to_dummy(memo).as_ptr()),
144-
}),
145-
);
138+
let old_entry = memos[memo_ingredient_index].data.replace(MemoEntryData {
139+
type_id: TypeId::of::<M>(),
140+
to_dyn_fn: Self::to_dyn_fn::<M>(),
141+
atomic_memo: AtomicPtr::new(Self::to_dummy(memo).as_ptr()),
142+
});
146143
old_entry.map(
147144
|MemoEntryData {
148145
type_id: _,

0 commit comments

Comments
 (0)