Skip to content

Commit

Permalink
Fix borrow error on pre-NLL compilers
Browse files Browse the repository at this point in the history
    error[E0506]: cannot assign to `missing_content` because it is borrowed
        --> serde_derive/src/de.rs:1414:9
         |
    1388 |           .filter_map(|(i, variant)| {
         |                       -------------- borrow of `missing_content` occurs here
    ...
    1414 | /         missing_content = quote! {
    1415 | |             match __field {
    1416 | |                 #(#missing_content_arms)*
    1417 | |                 #missing_content_fallthrough
    1418 | |             }
    1419 | |         };
         | |_________^ assignment to borrowed `missing_content` occurs here

    error[E0502]: cannot borrow `missing_content_fallthrough` as immutable because it is also borrowed as mutable
        --> serde_derive/src/de.rs:1414:27
         |
    1388 |           .filter_map(|(i, variant)| {
         |                       -------------- mutable borrow occurs here
    ...
    1404 |                       missing_content_fallthrough = quote!(_ => #missing_content);
         |                       --------------------------- previous borrow occurs due to use of `missing_content_fallthrough` in closure
    ...
    1414 |           missing_content = quote! {
         |  ___________________________^
    1415 | |             match __field {
    1416 | |                 #(#missing_content_arms)*
    1417 | |                 #missing_content_fallthrough
    1418 | |             }
    1419 | |         };
         | |_________^ immutable borrow occurs here
    ...
    1622 |   }
         |   - mutable borrow ends here
         |
         = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
  • Loading branch information
dtolnay committed May 10, 2020
1 parent b97a183 commit dda070f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions serde_derive/src/de.rs
Expand Up @@ -1381,7 +1381,7 @@ fn deserialize_adjacently_tagged_enum(
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
};
let mut missing_content_fallthrough = quote!();
let mut missing_content_arms = variants
let missing_content_arms = variants
.iter()
.enumerate()
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
Expand Down Expand Up @@ -1409,8 +1409,8 @@ fn deserialize_adjacently_tagged_enum(
__Field::#variant_index => #arm,
})
})
.peekable();
if missing_content_arms.peek().is_some() {
.collect::<Vec<_>>();
if !missing_content_arms.is_empty() {
missing_content = quote! {
match __field {
#(#missing_content_arms)*
Expand Down

0 comments on commit dda070f

Please sign in to comment.