Skip to content

Commit

Permalink
Add missing semicolons after macro calls
Browse files Browse the repository at this point in the history
Otherwise I was getting this error:

```
error: macros that expand to items must be delimited with braces or followed by a semicolon
   --> /Users/rschneeman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/magic_migrate-0.2.0/src/lib.rs:437:34
    |
419 |   macro_rules! try_migrate_link {
    |   ----------------------------- in this expansion of `$crate::try_migrate_link!` (#3)
...
437 |           $crate::try_migrate_link!($b, $($rest),*)
    |                                    ^^^^^^^^^^^^^^^^
...
714 |   macro_rules! try_migrate_deserializer_chain {
    |   -------------------------------------------
    |   |
    |   in this expansion of `try_migrate_deserializer_chain!` (#1)
    |   in this expansion of `$crate::try_migrate_deserializer_chain!` (#2)
...
737 |           $crate::try_migrate_link!($a, $($rest),+);
    |           ----------------------------------------- in this macro invocation (#3)
...
764 |           $crate::try_migrate_deserializer_chain!(error: $err, deserializer: $deser, chain: [$a, $($rest),+]);
    |           --------------------------------------------------------------------------------------------------- in this macro invocation (#2)
    |
   ::: buildpacks/ruby/src/layers/bundle_install_layer.rs:120:1
    |
120 | / try_migrate_deserializer_chain!(
121 | |     chain: [MetadataV1, MetadataV2, MetadataV3],
122 | |     error: MetadataMigrateError,
123 | |     deserializer: toml::Deserializer::new,
124 | | );
    | |_- in this macro invocation (#1)

error: could not compile `heroku-ruby-buildpack` (bin "heroku-ruby-buildpack") due to 1 previous error
⛄️ 3.3.1 🚀 /Users/rschneeman/Documents/projects/work/buildpacks-ruby/buildpacks/ruby (schneems/pub-traits)
$ RUSTFLAGS="-Zmacro-backtrace" cargo build 
   Compiling heroku-ruby-buildpack v0.0.0 (/Users/rschneeman/Documents/projects/work/buildpacks-ruby/buildpacks/ruby)
error: macros that expand to items must be delimited with braces or followed by a semicolon
   --> /Users/rschneeman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/magic_migrate-0.2.0/src/lib.rs:437:34
    |
419 |   macro_rules! try_migrate_link {
    |   ----------------------------- in this expansion of `$crate::try_migrate_link!` (#3)
...
437 |           $crate::try_migrate_link!($b, $($rest),*)
    |                                    ^^^^^^^^^^^^^^^^
...
714 |   macro_rules! try_migrate_deserializer_chain {
    |   -------------------------------------------
    |   |
    |   in this expansion of `try_migrate_deserializer_chain!` (#1)
    |   in this expansion of `$crate::try_migrate_deserializer_chain!` (#2)
...
737 |           $crate::try_migrate_link!($a, $($rest),+);
    |           ----------------------------------------- in this macro invocation (#3)
...
764 |           $crate::try_migrate_deserializer_chain!(error: $err, deserializer: $deser, chain: [$a, $($rest),+]);
    |           --------------------------------------------------------------------------------------------------- in this macro invocation (#2)
    |
   ::: buildpacks/ruby/src/layers/bundle_install_layer.rs:120:1
    |
120 | / try_migrate_deserializer_chain!(
121 | |     chain: [MetadataV1, MetadataV2, MetadataV3],
122 | |     error: MetadataMigrateError,
123 | |     deserializer: toml::Deserializer::new,
124 | | );
    | |_- in this macro invocation (#1)
```

From this code:

```
try_migrate_deserializer_chain!(
    chain: [MetadataV1, MetadataV2, MetadataV3],
    error: MetadataMigrateError,
    deserializer: toml::Deserializer::new,
);
```

Presumably because I was using 3 values instead of just 2.
  • Loading branch information
schneems committed Dec 12, 2024
1 parent bb4ee6f commit aac74b7
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub trait Migrate: From<Self::From> + Any + DeserializeOwned + Debug {
/// // support `From<Infallible>`
/// impl From<Infallible> for PersonMigrationError {
/// fn from(_value: Infallible) -> Self {
/// unreachable!()
/// unreachable!();
/// }
/// }
///
Expand Down Expand Up @@ -335,8 +335,8 @@ macro_rules! migrate_link {
$crate::migrate_link!($a, $b);

// Link B => C, and the rest
$crate::migrate_link!($b, $($rest),*)
)
$crate::migrate_link!($b, $($rest),*);
);
}

/// Links each struct passed in to each other to build a [`Migrate`] link chain.
Expand All @@ -361,15 +361,15 @@ macro_rules! migrate_link {
/// # struct UserV2;
/// # impl From<UserV1> for UserV2 {
/// # fn from(value: UserV1) -> Self {
/// # unimplemented!()
/// # unimplemented!();
/// # }
/// # }
/// #
/// # #[derive(Deserialize, Serialize, Debug)]
/// # struct UserV3;
/// # impl From<UserV2> for UserV3 {
/// # fn from(value: UserV2) -> Self {
/// # unimplemented!()
/// # unimplemented!();
/// # }
/// # }
///
Expand Down Expand Up @@ -397,7 +397,7 @@ macro_rules! migrate_toml_chain {
deserializer: toml::Deserializer::new,
chain: [$a, $($rest),+]
);
)
);
}

/// Macro for linking structs together in an infallible [`TryMigrate`] migration chain
Expand Down Expand Up @@ -434,8 +434,8 @@ macro_rules! try_migrate_link {
$crate::try_migrate_link!($a, $b);

// Link B => C, and the rest
$crate::try_migrate_link!($b, $($rest),*)
)
$crate::try_migrate_link!($b, $($rest),*);
);
}

/// A macro to help define [`TryMigrate`] based migrations
Expand Down Expand Up @@ -521,7 +521,7 @@ macro_rules! try_migrate_link {
macro_rules! try_migrate_toml_chain {
// Base case
(error: $err:ident, chain: [$a:ident] $(,)?) => {
$crate::try_migrate_deserializer_chain!(error: $err, deserializer: toml::Deserializer::new, chain: [$a])
$crate::try_migrate_deserializer_chain!(error: $err, deserializer: toml::Deserializer::new, chain: [$a]);
};
// Position variant
(chain: [$a:ident], error: $err:ident $(,)?) => {
Expand All @@ -537,7 +537,7 @@ macro_rules! try_migrate_toml_chain {
);
// Position variant
(chain: [$a:ident, $($rest:ident),+], error: $err:ident $(,)?) => (
$crate::try_migrate_toml_chain!(error: $err, chain: [$a, $($rest),+])
$crate::try_migrate_toml_chain!(error: $err, chain: [$a, $($rest),+]);
);
}

Expand Down Expand Up @@ -657,6 +657,13 @@ macro_rules! migrate_deserializer_chain {
/// updated_at: DateTime<Utc>
/// }
///
/// #[derive(Deserialize, Serialize, Debug)]
/// #[serde(deny_unknown_fields)]
/// struct PersonV3 {
/// full_name: String,
/// updated_at: DateTime<Utc>
/// }
///
/// // First define how to map from one struct to another
/// impl TryFrom<PersonV1> for PersonV2 {
/// type Error = NotRichard;
Expand All @@ -673,6 +680,17 @@ macro_rules! migrate_deserializer_chain {
/// }
/// }
///
/// impl TryFrom<PersonV2> for PersonV3 {
/// type Error = NotRichard;
///
/// fn try_from(value: PersonV2) -> Result<Self, NotRichard> {
/// Ok(PersonV3 {
/// full_name: value.name.clone(),
/// updated_at: value.updated_at
/// })
/// }
/// }
///
/// #[derive(Debug, Eq, PartialEq)]
/// struct NotRichard {
/// name: String
Expand All @@ -690,9 +708,9 @@ macro_rules! migrate_deserializer_chain {
/// }
///
/// try_migrate_deserializer_chain!(
/// deserializer: toml::Deserializer::new,
/// chain: [PersonV1, PersonV2, PersonV3],
/// error: PersonMigrationError,
/// chain: [PersonV1, PersonV2],
/// deserializer: toml::Deserializer::new,
/// );
///
/// // Now, given a serialized struct
Expand Down Expand Up @@ -724,7 +742,7 @@ macro_rules! try_migrate_deserializer_chain {
}
impl From<Infallible> for $err {
fn from(_value: Infallible) -> Self {
unreachable!()
unreachable!();
}
}
};
Expand Down

0 comments on commit aac74b7

Please sign in to comment.