Skip to content

encounter an invalid pointer error on build script while using -Zhint-mostly-unused with opt-level=N>0 #144413

@TypeLevelConsoli

Description

@TypeLevelConsoli

When I enable -Zhint-mostly-unused and opt-level=N>0 in .cargo/config.toml on a project using utoipa-swagger-ui, the project fails to compile with a free(): invalid pointer while attempting to download the UI package during the build script.

Interestingly, if I remove opt-level or set it to 0, the project compiles normally. But when I set it to 1, 2, or 3, it fails with the same error (I have [profile.dev.package."*"] opt-level = 3 on ~/.cargo/config.toml as many Rust devs do).

If I remove -Zhint-mostly-unused, the project also compiles as expected.

The error only occurs when the two settings are enabled, as I described.


I tried this code:

A simple hello world with utoipa-swagger-ui as dep and a minimal .cargo/config.toml:

https://github.com/TypeLevelConsoli/mostly-unused-vs-swagger--cargo-error

I expected to see this happen:

compilation success

Instead, this happened:

I received an error while running the build script.

error: failed to run custom build command for `utoipa-swagger-ui v9.0.2`

Caused by:
  process didn't exit successfully: `/tmp/mostly-unused-vs-swagger--cargo-error/target/debug/build/utoipa-swagger-ui-85f8212ea4e4aaa6/build-script-build` (signal: 6, SIGABRT: process abort signal)
  --- stdout
  OUT_DIR: /tmp/mostly-unused-vs-swagger--cargo-error/target/debug/build/utoipa-swagger-ui-7a7fd1f5154fde51/out
  SWAGGER_UI_DOWNLOAD_URL: https://github.com/swagger-api/swagger-ui/archive/refs/tags/v5.17.14.zip
  cargo:rerun-if-env-changed=SWAGGER_UI_DOWNLOAD_URL
  start download to : "/tmp/mostly-unused-vs-swagger--cargo-error/target/debug/build/utoipa-swagger-ui-7a7fd1f5154fde51/out/v5.17.14.zip"
  reqwest feature: Err(NotPresent)
  trying to download using `curl` system package

  --- stderr
  free(): invalid pointer

Meta

$ rustc --version --verbose
rustc --version --verbose
rustc 1.90.0-nightly (ace633090 2025-07-23)
binary: rustc
commit-hash: ace633090349fc5075b5b0d56294de985e7d1191
commit-date: 2025-07-23
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8
$ cargo --version --verbose
cargo 1.90.0-nightly (6833aa715 2025-07-13)
release: 1.90.0-nightly
commit-hash: 6833aa715d724437dc1247d0166afe314ab6854e
commit-date: 2025-07-13
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.14.1-DEV (sys:0.4.82+curl-8.14.1 vendored ssl:OpenSSL/3.5.0)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: Fedora 41.0.0 [64-bit]

I first reported this on rust-lang/cargo#15644 (comment), and @saethlin asked to also create an issue here :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zhint-mostly-unusedUnstable flag: -Z hint-mostly-unusedC-external-bugCategory: issue that is caused by bugs in software beyond our control

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions