Skip to content

Commit

Permalink
This code fails to compile with an error
Browse files Browse the repository at this point in the history
```
error: macros that expand to items must be delimited with braces or followed by a semicolon
   --> 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 | | );
    | |_^
    |
    = note: this error originates in the macro `$crate::try_migrate_link` which comes from the expansion of the macro `try_migrate_deserializer_chain` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Or with nightly:

```
$ RUSTFLAGS="-Zmacro-backtrace" cargo build 
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
```

I'm committing it because I want to figure out how to write a test case for this failure mode in the `magic_migrate` library.
  • Loading branch information
schneems committed Dec 12, 2024
1 parent b28174c commit 1f9119d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn handle(

pub(crate) type Metadata = MetadataV2;
try_migrate_deserializer_chain!(
chain: [MetadataV1, MetadataV2],
chain: [MetadataV1, MetadataV2, MetadataV3],
error: MetadataMigrateError,
deserializer: toml::Deserializer::new,
);
Expand Down Expand Up @@ -176,6 +176,15 @@ pub(crate) struct MetadataV2 {
pub(crate) cpu_architecture: String,
pub(crate) ruby_version: ResolvedRubyVersion,
pub(crate) force_bundle_install_key: String,
pub(crate) digest: MetadataDigest, // Must be last for serde to be happy https://github.com/toml-rs/toml-rs/issues/142
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
pub(crate) struct MetadataV3 {
pub(crate) os_distribution: String,
pub(crate) cpu_architecture: String,
pub(crate) ruby_version: ResolvedRubyVersion,
pub(crate) force_bundle_install_key: String,

/// A struct that holds the cryptographic hash of components that can
/// affect the result of `bundle install`. When these values do not
Expand Down Expand Up @@ -217,6 +226,20 @@ impl TryFrom<MetadataV1> for MetadataV2 {
}
}

impl TryFrom<MetadataV2> for MetadataV3 {
type Error = Infallible;

fn try_from(v2: MetadataV2) -> Result<Self, Self::Error> {
Ok(Self {
os_distribution: format!("{} {}", v2.distro_name, v2.distro_version),
cpu_architecture: v2.cpu_architecture,
ruby_version: v2.ruby_version,
force_bundle_install_key: v2.force_bundle_install_key,
digest: v2.digest,
})
}
}

#[derive(Debug)]
enum InstallState {
/// Holds message indicating the reason why we want to run 'bundle install'
Expand Down

0 comments on commit 1f9119d

Please sign in to comment.