diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 8faa4988ec0124741cec63b46e5a5dc43a078fec..7e9c254e832d041193c865ea05218aca3075c1a3 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -7,64 +7,98 @@ on: pull_request: branches: - main + merge_group: + branches: + - main jobs: rustfmt-clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal # TODO: Should ideally be stable, but we use some nightly-only # features. toolchain: nightly - override: true components: rustfmt, clippy - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: cargo fmt -- --check - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --tests + run: cargo clippy --tests msrv: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install msrv for lib + uses: dtolnay/rust-toolchain@master + with: + # MSRV below is documented in Cargo.toml and README.md, please update those if you + # change this. + toolchain: 1.70.0 - - name: Install msrv - uses: actions-rs/toolchain@v1 + - name: Test lib with msrv + run: cargo +1.70.0 test --package bindgen + + - name: Install msrv for cli + uses: dtolnay/rust-toolchain@master with: - profile: minimal # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.60.0 - override: true + toolchain: 1.70.0 + + - name: Test cli with msrv + run: cargo +1.70.0 build --package bindgen-cli + + minimal: + runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v4 + + - name: Install stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + + - name: Check without default features + run: cargo check -p bindgen --no-default-features --features=runtime + + docs: + runs-on: ubuntu-latest + env: + RUSTDOCFLAGS: -D warnings + steps: + - uses: actions/checkout@v4 + + - name: Install stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - - name: Build with msrv - run: rm Cargo.lock && cargo +1.60.0 build --lib + - name: Generate documentation for `bindgen` + run: cargo doc --document-private-items --no-deps -p bindgen + + - name: Generate documentation for `bindgen-cli` + run: cargo doc --document-private-items --no-deps -p bindgen-cli quickchecking: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true # TODO: Actually run quickchecks once `bindgen` is reliable enough. - name: Build quickcheck tests @@ -74,18 +108,14 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - # TODO(#1954): These should be run on mac too, but turns out they're - # broken. - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-12] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test @@ -99,7 +129,7 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["5.0", "9.0"] + llvm_version: ["9.0", "16.0"] main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] @@ -107,17 +137,15 @@ jobs: # `static` feature is not testable atm. feature_runtime: [0, 1] feature_extra_asserts: [0] - feature_testing_only_docs: [0] include: # Test with extra asserts + docs just with latest llvm versions to # prevent explosion - os: ubuntu-latest - llvm_version: "9.0" + llvm_version: "16.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 1 - feature_testing_only_docs: 1 # FIXME: Seems installing multiarch packages fails: # @@ -128,21 +156,22 @@ jobs: # debian: arm64 # cross: aarch64-linux-gnu # rust: aarch64-unknown-linux-gnu - # llvm_version: "9.0" + # llvm_version: "16.0" # main_tests: 0 # release_build: 0 # feature_extra_asserts: 0 - # feature_testing_only_docs: 0 # Ensure stuff works on macos too - - os: macos-latest + # FIXME: Ideally should use the latest llvm version, but llvm doesn't + # provide releases for x86-64 macOS anymore which is what the runner uses. + # + - os: macos-12 llvm_version: "9.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 0 - feature_testing_only_docs: 0 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install multiarch packages if: matrix.target.debian @@ -160,12 +189,10 @@ jobs: sudo apt-get install libc6:${{matrix.target.debian}} libstdc++6:${{matrix.target.debian}} - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable target: ${{matrix.target.rust}} - override: true - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | @@ -181,21 +208,28 @@ jobs: BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} - BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh - test-book: + check-cfg: runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings steps: - - uses: actions/checkout@v3 - - - name: Install stable - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + + - name: Install nightly + uses: dtolnay/rust-toolchain@master with: - profile: minimal - toolchain: stable - override: true + toolchain: nightly + + - name: Check cfg + run: cargo check -Z unstable-options -Z check-cfg + + test-book: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 # NOTE(emilio): Change deploy-book as well if you change this. - name: Test book @@ -203,3 +237,18 @@ jobs: curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz ./mdbook build book ./mdbook test book + + # One job that "summarizes" the success state of this pipeline. This can then + # be added to branch protection, rather than having to add each job + # separately. + success: + runs-on: ubuntu-latest + needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book] + # GitHub branch protection is exceedingly silly and treats "jobs skipped + # because a dependency failed" as success. So we have to do some + # contortions to ensure the job fails if any of its dependencies fails. + if: always() # make sure this is never "skipped" + steps: + # Manually check the status of all dependencies. `if: failure()` does not work. + - name: check if any dependency failed + run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000000000000000000000000000000000000..56a264f7f7ed546e8f245a9664de58b508c7cf00 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,68 @@ +name: Bump version for release + +on: + workflow_dispatch: + inputs: + level: + description: | + Select the level of the release + required: true + type: choice + options: + - minor + - patch + +jobs: + bump-version: + permissions: + id-token: write + pull-requests: write + contents: write + + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure gitsign + uses: chainguard-dev/actions/setup-gitsign@main + + - name: Install cargo-release + uses: taiki-e/install-action@v1 + with: + tool: cargo-release + + - name: Install sd + uses: taiki-e/install-action@v1 + with: + tool: sd + + - name: Install npm + uses: actions/setup-node@v4 + + - name: Install doctoc + run: npm install doctoc + + - name: Bump version + run: | + cargo release version ${{ inputs.level }} --execute --no-confirm + + - name: Extract version + run: | + echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV + + - name: Update changelog + run: | + sd "# Unreleased" "# Unreleased\n## Added\n## Changed\n## Removed\n## Fixed\n## Security\n\n# ${{ env.version }} ($(date -I))" CHANGELOG.md + ./node_modules/doctoc/doctoc.js CHANGELOG.md + + - name: Create PR + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: bump-version/${{ env.version }} + base: main + commit-message: "Bump crates version to ${{ env.version }}" + title: "Bump crates version to ${{ env.version }}" + body: | + This pull request was created automatically by GitHub Actions. diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 0000000000000000000000000000000000000000..27dcbb574100a7deeebd8dce995c618278481784 --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -0,0 +1,27 @@ +name: Create tag for release + +on: + pull_request: + types: + - closed + +jobs: + create-tag: + if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && startsWith(github.event.pull_request.head.ref, 'bump-version') + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Extract version + run: | + echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV + + - name: Create tag + run: | + TAG_NAME="v${{ env.version }}" + git tag $TAG_NAME + git push origin $TAG_NAME diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index a0d87a2094cfe657e8bd41f03f12edaf65c9799d..5eaeed58395eb97fd7606036f032a8f7b35cc57f 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -9,17 +9,10 @@ jobs: deploy-book: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Test book run: | curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000000000000000000000000000000000000..352199d7d7b63d3354f654bd99ae71e110af412a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,24 @@ +# This is triggered after the Release workflow successfully completes its run +on: + workflow_run: + workflows: + - Release + types: + - completed +env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} +jobs: + cargo-publish: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Publish bindgen (lib) + run: cargo publish --package bindgen --token ${CARGO_REGISTRY_TOKEN} + - name: Publish bindgen-cli + run: cargo publish --package bindgen-cli --token ${CARGO_REGISTRY_TOKEN} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000000000000000000000000000000000..502a5ff8da507434a2424c6931f49345357dc582 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,266 @@ +# Copyright 2022-2023, axodotdev +# SPDX-License-Identifier: MIT or Apache-2.0 +# +# CI that: +# +# * checks for a Git Tag that looks like a release +# * builds artifacts with cargo-dist (archives, installers, hashes) +# * uploads those artifacts to temporary workflow zip +# * on success, uploads the artifacts to a Github Release +# +# Note that the Github Release will be created with a generated +# title/body based on your changelogs. + +name: Release + +permissions: + contents: write + +# This task will run whenever you push a git tag that looks like a version +# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. +# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where +# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION +# must be a Cargo-style SemVer Version (must have at least major.minor.patch). +# +# If PACKAGE_NAME is specified, then the announcement will be for that +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). +# +# If PACKAGE_NAME isn't specified, then the announcement will be for all +# (cargo-dist-able) packages in the workspace with that version (this mode is +# intended for workspaces with only one dist-able package, or with all dist-able +# packages versioned/released in lockstep). +# +# If you push multiple tags at once, separate instances of this workflow will +# spin up, creating an independent announcement for each one. However Github +# will hard limit this to 3 tags per commit, as it will assume more tags is a +# mistake. +# +# If there's a prerelease-style suffix to the version, then the release(s) +# will be marked as a prerelease. +on: + push: + tags: + - '**[0-9]+.[0-9]+.[0-9]+*' + pull_request: + +jobs: + # Run 'cargo dist plan' (or host) to determine what tasks we need to do + plan: + runs-on: ubuntu-latest + outputs: + val: ${{ steps.plan.outputs.manifest }} + tag: ${{ !github.event.pull_request && github.ref_name || '' }} + tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} + publishing: ${{ !github.event.pull_request }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install cargo-dist + # we specify bash to get pipefail; it guards against the `curl` command + # failing. otherwise `sh` won't catch that `curl` returned non-0 + shell: bash + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + # sure would be cool if github gave us proper conditionals... + # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible + # functionality based on whether this is a pull_request, and whether it's from a fork. + # (PRs run on the *source* but secrets are usually on the *target* -- that's *good* + # but also really annoying to build CI around when it needs secrets to work right.) + - id: plan + run: | + cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "cargo dist ran successfully" + cat plan-dist-manifest.json + echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" + - name: "Upload dist-manifest.json" + uses: actions/upload-artifact@v4 + with: + name: artifacts-plan-dist-manifest + path: plan-dist-manifest.json + + # Build and packages all the platform-specific things + build-local-artifacts: + name: build-local-artifacts (${{ join(matrix.targets, ', ') }}) + # Let the initial task tell us to not run (currently very blunt) + needs: + - plan + if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} + strategy: + fail-fast: false + # Target platforms/runners are computed by cargo-dist in create-release. + # Each member of the matrix has the following arguments: + # + # - runner: the github runner + # - dist-args: cli flags to pass to cargo dist + # - install-dist: expression to run to install cargo-dist on the runner + # + # Typically there will be: + # - 1 "global" task that builds universal installers + # - N "local" tasks that build each platform's binaries and platform-specific installers + matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} + runs-on: ${{ matrix.runner }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: swatinem/rust-cache@v2 + - name: Install cargo-dist + run: ${{ matrix.install_dist }} + # Get the dist-manifest + - name: Fetch local artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: target/distrib/ + merge-multiple: true + - name: Install dependencies + run: | + ${{ matrix.packages_install }} + - name: Build artifacts + run: | + # Actually do builds and make zips and whatnot + cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "cargo dist ran successfully" + - id: cargo-dist + name: Post-build + # We force bash here just because github makes it really hard to get values up + # to "real" actions without writing to env-vars, and writing to env-vars has + # inconsistent syntax between shell and powershell. + shell: bash + run: | + # Parse out what we just built and upload it to scratch storage + echo "paths<> "$GITHUB_OUTPUT" + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + + cp dist-manifest.json "$BUILD_MANIFEST_NAME" + - name: "Upload artifacts" + uses: actions/upload-artifact@v4 + with: + name: artifacts-build-local-${{ join(matrix.targets, '_') }} + path: | + ${{ steps.cargo-dist.outputs.paths }} + ${{ env.BUILD_MANIFEST_NAME }} + + # Build and package all the platform-agnostic(ish) things + build-global-artifacts: + needs: + - plan + - build-local-artifacts + runs-on: "ubuntu-20.04" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install cargo-dist + shell: bash + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + # Get all the local artifacts for the global tasks to use (for e.g. checksums) + - name: Fetch local artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: target/distrib/ + merge-multiple: true + - id: cargo-dist + shell: bash + run: | + cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "cargo dist ran successfully" + + # Parse out what we just built and upload it to scratch storage + echo "paths<> "$GITHUB_OUTPUT" + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + + cp dist-manifest.json "$BUILD_MANIFEST_NAME" + - name: "Upload artifacts" + uses: actions/upload-artifact@v4 + with: + name: artifacts-build-global + path: | + ${{ steps.cargo-dist.outputs.paths }} + ${{ env.BUILD_MANIFEST_NAME }} + # Determines if we should publish/announce + host: + needs: + - plan + - build-local-artifacts + - build-global-artifacts + # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine) + if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: "ubuntu-20.04" + outputs: + val: ${{ steps.host.outputs.manifest }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + # Fetch artifacts from scratch-storage + - name: Fetch artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: target/distrib/ + merge-multiple: true + # This is a harmless no-op for Github Releases, hosting for that happens in "announce" + - id: host + shell: bash + run: | + cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + echo "artifacts uploaded and released successfully" + cat dist-manifest.json + echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" + - name: "Upload dist-manifest.json" + uses: actions/upload-artifact@v4 + with: + # Overwrite the previous copy + name: artifacts-dist-manifest + path: dist-manifest.json + + # Create a Github Release while uploading all files to it + announce: + needs: + - plan + - host + # use "always() && ..." to allow us to wait for all publish jobs while + # still allowing individual publish jobs to skip themselves (for prereleases). + # "host" however must run to completion, no skipping allowed! + if: ${{ always() && needs.host.result == 'success' }} + runs-on: "ubuntu-20.04" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: "Download Github Artifacts" + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: artifacts + merge-multiple: true + - name: Cleanup + run: | + # Remove the granular manifests + rm -f artifacts/*-dist-manifest.json + - name: Create Github Release + uses: ncipollo/release-action@v1 + with: + tag: ${{ needs.plan.outputs.tag }} + name: ${{ fromJson(needs.host.outputs.val).announcement_title }} + body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }} + prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }} + artifacts: "artifacts/*" diff --git a/.gitignore b/.gitignore index a924030cc9617ab5bd6a56aff5c098b182607731..a610640e5ed652a904b947e91cce68c0bcc0d338 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,8 @@ csmith-fuzzing/platform.info # Backups of test cases from C-Reduce **/*.orig + +# node.js files +node_modules +package-lock.json +package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d901bab1e5f49b788a079349bd126fc2a586b17f..76e18d5c1ba3f40c6052b7ae11b726e47928b4fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,170 +7,456 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.64.0](#0640) +- [0.70.1 (2024-08-20)](#0701-2024-08-20) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - [Security](#security-1) -- [0.63.0](#0630) +- [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) -- [0.62.0](#0620) + - [Fixed](#fixed-2) + - [Security](#security-2) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-3) - [Changed](#changed-3) - - [Fixed](#fixed-2) -- [0.61.0](#0610) + - [Removed](#removed-3) + - [Fixed](#fixed-3) + - [Security](#security-3) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-4) - [Changed](#changed-4) - - [Fixed](#fixed-3) -- [0.60.1](#0601) + - [Removed](#removed-4) - [Fixed](#fixed-4) -- [0.60.0](#0600) + - [Security](#security-4) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-5) - - [Fixed](#fixed-5) - [Changed](#changed-5) - - [Removed](#removed-3) -- [0.59.2](#0592) -- [0.59.1](#0591) + - [Removed](#removed-5) + - [Fixed](#fixed-5) + - [Security](#security-5) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) - [Fixed](#fixed-6) -- [0.59.0](#0590) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-6) - - [Fixed](#fixed-7) - [Changed](#changed-6) -- [0.58.1](#0581) - - [Added](#added-7) -- [0.58.0](#0580) - - [Added](#added-8) + - [Removed](#removed-6) + - [Fixed](#fixed-7) + - [Security](#security-6) +- [0.68.1](#0681) - [Fixed](#fixed-8) +- [0.68.0](#0680) + - [Added](#added-7) - [Changed](#changed-7) - - [Deprecated](#deprecated) - - [Removed](#removed-4) + - [Removed](#removed-7) - [Fixed](#fixed-9) - - [Security](#security-2) -- [0.57.0](#0570) - - [Added](#added-9) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-8) +- [0.66.0](#0660) + - [Added](#added-8) + - [Changed](#changed-8) + - [Removed](#removed-9) +- [0.65.1](#0651) - [Fixed](#fixed-10) -- [0.56.0](#0560) +- [0.65.0](#0650) + - [Added](#added-9) + - [Changed](#changed-9) + - [Removed](#removed-10) +- [0.64.0](#0640) - [Added](#added-10) - - [Changed](#changed-8) + - [Changed](#changed-10) +- [0.63.0](#0630) + - [Added](#added-11) + - [Changed](#changed-11) + - [Removed](#removed-11) +- [0.62.0](#0620) + - [Added](#added-12) + - [Changed](#changed-12) - [Fixed](#fixed-11) -- [0.55.1](#0551) +- [0.61.0](#0610) + - [Added](#added-13) + - [Changed](#changed-13) - [Fixed](#fixed-12) -- [0.55.0](#0550) - - [Removed](#removed-5) - - [Added](#added-11) - - [Changed](#changed-9) +- [0.60.1](#0601) - [Fixed](#fixed-13) -- [0.54.1](#0541) - - [Added](#added-12) - - [Changed](#changed-10) +- [0.60.0](#0600) + - [Added](#added-14) - [Fixed](#fixed-14) -- [0.54.0](#0540) - - [Added](#added-13) - - [Changed](#changed-11) + - [Changed](#changed-14) + - [Removed](#removed-12) +- [0.59.2](#0592) +- [0.59.1](#0591) - [Fixed](#fixed-15) -- [0.53.3](#0533) - - [Added](#added-14) - - [Fixed](#fixed-16) -- [0.53.2](#0532) - - [Changed](#changed-12) -- [0.53.1](#0531) +- [0.59.0](#0590) - [Added](#added-15) -- [0.53.0](#0530) + - [Fixed](#fixed-16) + - [Changed](#changed-15) +- [0.58.1](#0581) - [Added](#added-16) - - [Changed](#changed-13) - - [Fixed](#fixed-17) -- [0.52.0](#0520) +- [0.58.0](#0580) - [Added](#added-17) - - [Changed](#changed-14) - - [Fixed](#fixed-18) -- [0.51.1](#0511) - - [Fixed](#fixed-19) - - [Changed](#changed-15) -- [0.51.0](#0510) - - [Fixed](#fixed-20) + - [Fixed](#fixed-17) - [Changed](#changed-16) + - [Deprecated](#deprecated) + - [Removed](#removed-13) + - [Fixed](#fixed-18) + - [Security](#security-7) +- [0.57.0](#0570) - [Added](#added-18) -- [0.50.0](#0500) + - [Fixed](#fixed-19) +- [0.56.0](#0560) - [Added](#added-19) -- [0.49.3](#0493) - - [Added](#added-20) -- [0.49.2](#0492) - [Changed](#changed-17) -- [0.49.1](#0491) + - [Fixed](#fixed-20) +- [0.55.1](#0551) - [Fixed](#fixed-21) +- [0.55.0](#0550) + - [Removed](#removed-14) + - [Added](#added-20) - [Changed](#changed-18) -- [0.49.0](#0490) - - [Added](#added-21) - [Fixed](#fixed-22) +- [0.54.1](#0541) + - [Added](#added-21) - [Changed](#changed-19) -- [0.48.1](#0481) - [Fixed](#fixed-23) -- [0.48.0](#0480) +- [0.54.0](#0540) + - [Added](#added-22) - [Changed](#changed-20) - [Fixed](#fixed-24) -- [0.47.4](#0474) - - [Added](#added-22) -- [0.47.3](#0473) - - [Changed](#changed-21) -- [0.47.2](#0472) +- [0.53.3](#0533) + - [Added](#added-23) - [Fixed](#fixed-25) -- [0.47.1](#0471) +- [0.53.2](#0532) + - [Changed](#changed-21) +- [0.53.1](#0531) + - [Added](#added-24) +- [0.53.0](#0530) + - [Added](#added-25) - [Changed](#changed-22) - [Fixed](#fixed-26) -- [0.47.0](#0470) +- [0.52.0](#0520) + - [Added](#added-26) - [Changed](#changed-23) - [Fixed](#fixed-27) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-23) - - [Removed](#removed-6) - - [Changed](#changed-24) +- [0.51.1](#0511) - [Fixed](#fixed-28) -- [0.33.1](#0331) + - [Changed](#changed-24) +- [0.51.0](#0510) - [Fixed](#fixed-29) + - [Changed](#changed-25) + - [Added](#added-27) +- [0.50.0](#0500) + - [Added](#added-28) +- [0.49.3](#0493) + - [Added](#added-29) +- [0.49.2](#0492) + - [Changed](#changed-26) +- [0.49.1](#0491) + - [Fixed](#fixed-30) + - [Changed](#changed-27) +- [0.49.0](#0490) + - [Added](#added-30) + - [Fixed](#fixed-31) + - [Changed](#changed-28) +- [0.48.1](#0481) + - [Fixed](#fixed-32) +- [0.48.0](#0480) + - [Changed](#changed-29) + - [Fixed](#fixed-33) +- [0.47.4](#0474) + - [Added](#added-31) +- [0.47.3](#0473) + - [Changed](#changed-30) +- [0.47.2](#0472) + - [Fixed](#fixed-34) +- [0.47.1](#0471) + - [Changed](#changed-31) + - [Fixed](#fixed-35) +- [0.47.0](#0470) + - [Changed](#changed-32) + - [Fixed](#fixed-36) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-32) + - [Removed](#removed-15) + - [Changed](#changed-33) + - [Fixed](#fixed-37) +- [0.33.1](#0331) + - [Fixed](#fixed-38) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-30) + - [Fixed](#fixed-39) - [0.32.1](#0321) - - [Fixed](#fixed-31) + - [Fixed](#fixed-40) - [0.32.0](#0320) - - [Added](#added-24) - - [Changed](#changed-25) - - [Fixed](#fixed-32) + - [Added](#added-33) + - [Changed](#changed-34) + - [Fixed](#fixed-41) - [0.31.0](#0310) - - [Added](#added-25) - - [Changed](#changed-26) + - [Added](#added-34) + - [Changed](#changed-35) - [Deprecated](#deprecated-1) - - [Removed](#removed-7) - - [Fixed](#fixed-33) + - [Removed](#removed-16) + - [Fixed](#fixed-42) - [0.30.0](#0300) - - [Added](#added-26) - - [Changed](#changed-27) + - [Added](#added-35) + - [Changed](#changed-36) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-34) + - [Fixed](#fixed-43) - [0.29.0](#0290) - - [Added](#added-27) - - [Changed](#changed-28) - - [Fixed](#fixed-35) + - [Added](#added-36) + - [Changed](#changed-37) + - [Fixed](#fixed-44) -------------------------------------------------------------------------------- - # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.70.1 (2024-08-20) +## Added +## Changed +## Removed +## Fixed +- Fix regression where the `const` layout tests were triggering the `unnecessary_operation` and `identity_op` clippy warnings. +## Security + +# 0.70.0 (2024-08-16) +## Added +- Add target mappings for riscv64imac and riscv32imafc. +- Add a complex macro fallback API (#2779). +- Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). +- Add option to dynamically load variables (#2812). +- Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847). +## Changed +- Remove which and lazy-static dependencies (#2809, #2817). +- Generate compile-time layout tests (#2787). +- Print `bindgen-cli` errors to stderr instead of stdout (#2840) +## Removed +## Fixed +- Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and + enabling it by default for `bindgen-cli` (#2789) . +- Fix `--allowlist-item` so anonymous enums are no longer ignored (#2827). +- Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824). +- Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` (#2854). +## Security +- Update `tempfile` and `rustix` due to [GHSA-c827-hfw6-qwvm](https://github.com/advisories/GHSA-c827-hfw6-qwvm). +# 0.69.4 (2024-02-04) ## Added +## Changed +- Allow older itertools. (#2745) +## Removed +## Fixed +## Security + +# 0.69.3 (2024-02-04) +## Added + +- Added blocklist_var (#2731) +- Stabilized thiscall_abi (#2661) ## Changed +- Use CR consistently on windows (#2698) +- Replaced peeking_take_while by itertools (#2724) + ## Removed +## Fixed +- Try to avoid repr(packed) for explicitly aligned types when not needed (#2734) +- Improved destructor handling on Windows (#2663) +- Support Float16 (#2667) +- Fix alignment contribution from bitfields (#2680) +- Fixed msrv build. + +## Security + +- Updated shlex dependency (RUSTSEC-2024-0006) + +# 0.69.2 (2024-01-13) +## Added +## Changed +## Removed ## Fixed +- Fixed generation of extern "C" blocks with llvm 18+. See #2689. +## Security +# 0.69.1 (2023-11-02) + +## Fixed +- Allow to run `bindgen -v` without an input header argument. + +# 0.69.0 (2023-11-01) + +## Added +- Added the `ParseCallbacks::header_file` callback which runs on every filename passed to `Builder::header`. +- Added the `CargoCallbacks::new` constructor which emits a cargo-rerun line + for every input header file by default. +- Added the `CargoCallbacks::rerun_on_header_files` method to configure whether + a cargo-rerun line should be emitted for every input header file. +## Changed +- The `--wrap-static-fns` feature was updated so function types that has no + argument use `void` as its sole argument. +- `CargoCallbacks` is no longer a [unit-like + struct](https://doc.rust-lang.org/reference/items/structs.html) and the + `CargoCallbacks` constant was added to mitigate the breaking nature of this + change. This constant has been marked as deprecated and users will have to + use the new `CargoCallbacks::new` method in the future. +## Removed +## Fixed +- Allow compiling `bindgen-cli` with a static libclang. +- Emit an opaque integer type for pointer types that don't have the same size + as the target's pointer size. +- Avoid escaping Objective-C method names unless they are `Self`, `self`, + `crate` or `super`. ## Security +# 0.68.1 + +## Fixed +- Fixed errors on the windows artifact build process. + +# 0.68.0 + +## Added +- The `system` ABI is now supported as an option for the `--override-abi` flag. +- The `allowlist_item` method and the `--allowlist-item` flag have been + included to filter items regardless or their kind. +- Include installers as release artifacts on Github. +## Changed +- The `Clone` implementation for `_BindgenUnionField` has been changed to pass + the `incorrect_clone_impl_on_copy_type` Clippy lint. +- The `c_unwind` ABI can be used without a feature gate for any Rust target version + equal to or greater than 1.71. + This comes as a result of the ABI being stabilised (in Rust 1.71). +- Formatting changes when using prettyplease as a formatter due to a new + prettyplease version. +- Avoid generating invalid `CStr` constants when using the `--generate-cstr` + option. +## Removed +- The `extra_assert` and `extra_assert_eq` macros are no longer exported. +## Fixed +- Bindgen no longer panics when parsing an objective-C header that includes a + Rust keyword that cannot be a raw identifier, such as: `self`, `crate`, + `super` or `Self`. + +# 0.67.0 + +This version was skipped due to some problems on the release workflow. + +# 0.66.1 + +## Removed +* Revert source order sorting (#2543) due to correctness regressions #2558. + +# 0.66.0 + +## Added + +* Added the `--generate-cstr` CLI flag to generate string constants as `&CStr` + instead of `&[u8]`. (Requires Rust 1.59 or higher.) +* Added the `--generate-shell-completions` CLI flag to generate completions for + different shells. +* The `--wrap-static-fns` option can now wrap `va_list` functions as variadic functions + with the experimental `ParseCallbacks::wrap_as_variadic_fn` method. +* Add target mappings for riscv32imc and riscv32imac. +* Add the `ParseCallbacks::field_visibility` method to modify field visibility. + +## Changed + +* Non-UTF-8 string constants are now generated as references (`&[u8; SIZE]`) + instead of arrays (`[u8; SIZE]`) to match UTF-8 strings. +* Wrappers for static functions that return `void` no longer contain a `return` + statement and only call the static function instead. +* The `--wrap-static-fns` option no longer emits wrappers for static variadic + functions. +* Depfiles generated with `--depfile` or `Builder::depfile` will now properly + generate module names and paths that include spaces by escaping them. To make + the escaping clear and consistent, backslashes are also escaped. +* Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. +* Prettyplease formatting is gated by an optional, enabled by default Cargo + feature when depending on `bindgen` as a library. +* Items are now parsed in the order they appear in source files. This may result in + auto-generated `_bindgen_*` names having a different index. +* Use default visibility for padding fields: Previously, padding fields were + always public. Now, they follow the default visibility for the type they are + in. +* Compute visibility of bitfield unit based on actual field visibility: A + bitfield unit field and its related functions now have their visibility + determined based on the most private between the default visibility and the + actual visibility of the bitfields within the unit. + +## Removed +* Remove redundant Cargo features, which were all implicit: + - bindgen-cli: `env_logger` and `log` removed in favor of `logging` + - bindgen (lib): + + `log` removed in favor of `logging` + + `which` removed in favor of `which-logging` + + `annotate-snippets` removed in favor of `experimental` + +* Prettyplease is available as a `Formatter` variant now. + +# 0.65.1 + +## Fixed + +* The `Builder::rustfmt_bindings` method was added back and tagged as + deprecated instead of being removed. +* Broken documentation links were fixed. + +# 0.65.0 + +## Added + * Added the `Builder::default_visibility` method and the + `--default-visibility` flag to set the default visibility of fields. (#2338) + * Added the `--formatter` CLI flag with the values `none`, `rustfmt` and + `prettyplease` to select which tool will be used to format the bindings. The + default value is `rustfmt`. (#2453) + * Added the `Builder::formatter` method and the `Formatter` type to select + which tool will be used to format the bindings. (#2453) + * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` + flag to enable emission of diagnostic messages under the `experimental` + feature. (#2436) + * Added support for the `"efiapi"` calling convention (#2490). + * Added the `ParseCallbacks::read_env_var` method which runs everytime + `bindgen` reads and environment variable. (#2400) + * Added the `ParseCallbacks::generated_link_name_override` method which allow + overriding the link name of items. (#2425) + * Add support for C `enum`s when generating code while using the + `--wrap-static-fns` feature. (#2415) + +## Changed + * Static functions with no arguments use `void` as their single argument + instead of having no arguments when the `--wrap-static-fns` flag is used. + (#2443) + * The source file generated when the `--wrap-static-fns` flag is enabled now + contains `#include` directives with all the input headers and all the source + code added with the `header_contents` method. (#2447) + * The source file generated when the `--wrap-static-fns` flag no longer uses + `asm` labeling and the link name of static wrapper functions is allowed to + be mangled. (#2448) + * The documentation of the generated `type` aliases now matches the comments + of their `typedef` counterparts instead of using the comments of the aliased + types. (#2463) + * The `Builder::rustfmt_bindings` methods and the `--no-rustfmt-bindings` flag + are now deprecated in favor of the formatter API. (#2453) + +## Removed + * The following deprecated flags were removed: `--use-msvc-mangling`, + `--rustfmt-bindings` and `--size_t-is-usize`. (#2408) + * The `Bindings::emit_warnings` and `Bindings::warnings` methods were removed + in favor of `--emit-diagnostics`. (#2436) + * Bindgen no longer generates C string constants that cannot be represented as + byte slices. (#2487) + # 0.64.0 ## Added @@ -191,19 +477,13 @@ * The `ParseCallbacks::generated_name_override` method now receives `ItemInfo<'_>` as argument instead of a `&str`. * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. - * The return type is now ommited in signatures of functions returning `void`. + * The return type is now omitted in signatures of functions returning `void`. * Updated the `clap` dependency for `bindgen-cli` to 4. * Rewrote the `bindgen-cli` argument parser which could introduce unexpected - behavior changes. + behavior changes. * The `ParseCallbacks::add_derives` method now receives `DeriveInfo<'_>` as argument instead of a `&str`. This type also includes the kind of target type. -## Removed - -## Fixed - -## Security - # 0.63.0 ## Added @@ -1234,7 +1514,7 @@ Released 2017/10/27 We <3 folks who [help us find and fix issues via fuzzing][fuzzing]! *hint hint* -* Added experimental support for the `thiscall` ABI when targetting Rust +* Added experimental support for the `thiscall` ABI when targeting Rust nightly. [#1065][] ## Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6189619da80a40b7ebf52c06ad11447852f496c1..ff48cf1df7c66e1eb047d6df459707968b67c583 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,8 @@ and introduce yourself. - [Code of Conduct](#code-of-conduct) - [Filing an Issue](#filing-an-issue) - [Looking to Start Contributing to `bindgen`?](#looking-to-start-contributing-to-bindgen) +- [Prerequisites](#prerequisites) + - [`rustfmt` / `cargo fmt`](#rustfmt--cargo-fmt) - [Building](#building) - [Testing](#testing) - [Overview](#overview) @@ -33,9 +35,11 @@ and introduce yourself. - [Writing a Predicate Script](#writing-a-predicate-script) - [Cutting a new bindgen release](#cutting-a-new-bindgen-release) - [Updating the changelog](#updating-the-changelog) - - [Bumping the version numbers.](#bumping-the-version-numbers) - [Merge to `main`](#merge-to-main) - - [Publish and add a git tag for the right commit](#publish-and-add-a-git-tag-for-the-right-commit) + - [Tag and publish](#tag-and-publish) + - [Create a new release on Github](#create-a-new-release-on-github) + - [What to do if a Github release fails](#what-to-do-if-a-github-release-fails) + - [Create a new crates.io release](#create-a-new-cratesio-release) @@ -43,7 +47,7 @@ and introduce yourself. We abide by the [Rust Code of Conduct][coc] and ask that you do as well. -[coc]: https://www.rust-lang.org/en-US/conduct.html +[coc]: https://www.rust-lang.org/policies/code-of-conduct ## Filing an Issue @@ -54,7 +58,7 @@ issue, provide us with: * The `bindgen` flags used to reproduce the issue with the header file * The expected `bindgen` output * The actual `bindgen` output -* The [debugging logs](#logs) generated when running `bindgen` on this testcase +* The [debugging logs](#debug-logging) generated when running `bindgen` on this testcase ## Looking to Start Contributing to `bindgen`? @@ -63,6 +67,17 @@ issue, provide us with: * [Issues labeled "help wanted"](https://github.com/rust-lang/rust-bindgen/labels/help%20wanted) * Still can't find something to work on? [Drop a comment here](https://github.com/rust-lang/rust-bindgen/issues/747) +## Prerequisites + +### `rustfmt` / `cargo fmt` + +We use `nightly` channel for `rustfmt`, +so please set the appropriate setting in your editor/IDE for that. + +For rust-analyzer, you can set `rustfmt.extraArgs = ['+nightly']`. + +To check via command line, you can run `cargo +nightly fmt --check`. + ## Building To build the `bindgen` library and the `bindgen` executable: @@ -79,14 +94,6 @@ versions of llvm, or specify the path of the desired libclang explicitly: $ export LIBCLANG_PATH=path/to/clang-9.0/lib ``` -Additionally, you may want to build and test with the `testing_only_docs` -feature to ensure that you aren't forgetting to document types and functions. CI -will catch it if you forget, but the turn around will be a lot slower ;) - -``` -$ cargo build --features testing_only_docs -``` - ## Testing ### Overview @@ -100,18 +107,18 @@ There are also some integration tests in the `./bindgen-integration` crate, whic generate bindings to some C++ code, and then uses the bindings, asserting that values are what we expect them to be, both on the Rust and C++ side. -The generated and expected bindings are run through `rustfmt` before they are -compared. Make sure you have `rustfmt` up to date: - -``` -$ rustup update nightly -$ rustup component add rustfmt --toolchain nightly -``` +The generated and expected bindings are formatted with [prettyplease] before they are +compared. It is a default (but optional) dependency of `bindgen`, +so be sure to keep that in mind +(if you built `bindgen` with the `--no-default-features` option of Cargo). +Note also that `rustfmt` formatting is disabled for the `bindgen-tests/tests/expectations/` +directory tree, which helps avoid failing ui tests. Note: running `cargo test` from the root directory of `bindgen`'s repository does not automatically test the generated bindings or run the integration tests. These steps must be performed manually when needed. + ### Testing Bindings Generation To regenerate bindings from the corpus of test headers in `bindgen-tests/tests/headers` and @@ -157,10 +164,10 @@ $ cargo test ### Testing a Single Header's Bindings Generation and Compiling its Bindings -Note: You will to need to install [Graphviz](https://graphviz.org/) since that +Note: You will need to install [Graphviz](https://graphviz.org/) since that is a dependency for running `test-one.sh`. -Sometimes its useful to work with one test header from start (generating +Sometimes it's useful to work with one test header from start (generating bindings for it) to finish (compiling the bindings and running their layout tests). This can be done with the `bindgen-tests/tests/test-one.sh` script. It supports fuzzy searching for test headers. For example, to test @@ -203,13 +210,13 @@ can add multiple test expectations, one for each supported `libclang` version. Instead of having a single `bindgen-tests/tests/expectations/tests/my_test.rs` file, add each of: +* `bindgen-tests/tests/expectations/tests/libclang-16/my_test.rs` * `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` -* `bindgen-tests/tests/expectations/tests/libclang-5/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have -many version of `libclang` installed locally. Just make a work-in-progress pull -request, and then when Travis CI fails, it will log a diff of the +many versions of `libclang` installed locally. Just make a work-in-progress pull +request, and then when CI fails, it will log a diff of the expectations. Use the diff to patch the appropriate expectation file locally and then update your pull request. @@ -218,15 +225,9 @@ have. If for some reason it can't, you can force a specific `libclang` version to check the bindings against with a cargo feature: ``` -$ cargo test --features testing_only_libclang_$VERSION +$ cargo test --features __testing_only_libclang_$VERSION ``` -Where `$VERSION` is one of: - -* `4` -* `3_9` -* `3_8` - depending on which version of `libclang` you have installed. ### Integration Tests @@ -351,7 +352,7 @@ changes should be squashed into the original commit. Unsure who to ask for review? Ask any of: * `@emilio` -* `@fitzgen` +* `@pvdrz` More resources: @@ -424,7 +425,7 @@ $ brew install creduce $ # Etc... ``` -Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/main/INSTALL.md) for building and/or installing `creduce`. +Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/master/INSTALL.md) for building and/or installing `creduce`. Running `creduce` requires two things: @@ -489,10 +490,11 @@ to fail to compile `bindgen`'s emitted bindings, you can invoke `predicate.py` like this: ```bash +# the rustc-grep argument expects a regex, thus escape where necessary path/to/rust-bindgen/csmith-fuzzing/predicate.py \ --bindings-grep NameOfTheStructThatIsErroneouslyDerivingEq \ --expect-compile-fail \ - --rustc-grep 'error[E0277]: the trait bound `f64: std::cmp::Eq` is not satisfied' \ + --rustc-grep 'error\[E0277\]: the trait bound `f64: std::cmp::Eq` is not satisfied' \ ./isolated-test-case.h ``` @@ -537,35 +539,85 @@ like the following is a useful way to check what has landed: $ git log --oneline v0.62.0..HEAD ``` -Also worth checking the [next-release tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). +Also worth checking the [next-release +tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). +It is very important that you do not rename the `Unreleased` section of the +changelog as this will be done automatically using `cargo release` on a further +step. + +### Merge to `main` + +For regular releases, the changes above should end up in `main` before +publishing. For dot-releases of an old version (e.g., cherry-picking an +important fix) you can skip this. -Once that's done and the changelog is up-to-date, run `doctoc` on it. +### Tag and publish -If needed, install it locally by running: +Once you're in `main`. Remember to install `doctoc` by running: +``` +npm install doctoc +``` +And then run: ``` -$ npm install doctoc -$ ./node_modules/doctoc/doctoc.js CHANGELOG.md +cargo release [patch|minor] --no-publish --execute ``` -### Bumping the version numbers. +This does the following: -Bump version numbers as needed. Run tests just to ensure everything is working -as expected. +- Bump the version. +- Turn the `Unreleased` section of the changelog into the section for the version being released. +- Update the table of contents of the changelog using `doctoc`. +- Tag (`git tag`) the HEAD commit +- Push (`git push`) to GitHub -### Merge to `main` +The `patch` and `minor` refer to semver concepts: -For regular releases, the changes above should end up in `main` before -publishing. For dot-releases of an old version (e.g., cherry-picking an -important fix) you can skip this. +- `patch` would bump __v0.68.1__ to __v0.68.2__ +- `minor` would bump __v0.68.2__ to __v0.69.0__ + +> NOTE: +> We use the `--no-publish` so that the crates are only published after the release is complete. +> This is automatic, provided the release CI job is successful. + +### Create a new release on Github -### Publish and add a git tag for the right commit +The release is automated with the help of `.github/workflows/release.yml`, +and will only be created... -Once you're in the right commit, do: +- when a Git tag is pushed +- when all tests succeed + +While the tests are still running, +a draft GitHub release will be created, +to avoid notifying watchers of the repo should a CI step fail. + +If everything succeeds, +tarballs containing bindgen cli executables for Linux and MacOS +(both for x86 and Arm) will be created. +See `[workspace.metadata.dist]` section in Cargo.toml for the configuration. + +To update the release configuration, +when a new cargo-dist is available: ``` -$ git tag -a v0.62.1 # With the right version of course -$ pushd bindgen && cargo publish && popd -$ pushd bindgen-cli && cargo publish && popd -$ git push --tags upstream # To publish the tag +cargo dist init # from "cargo install cargo-dist" ``` + +### What to do if a Github release fails + +If the release process fails after you run `cargo release`, you can manually +delete the tag and release from Github. Also remember to delete the tag locally +by running `git tag -d`. Once all the extra changes are in the `main` branch, +you can trigger a release by creating a new tag using `git tag` and push it +using `git push --tag`. + +### Create a new crates.io release + +Go to [the Publish +workflow](https://github.com/rust-lang/rust-bindgen/actions/workflows/publish.yml) +and run a new workflow using the "Run Workflow" button. + +Remember that crates.io releases cannot be deleted! + +[prettyplease]: https://github.com/dtolnay/prettyplease diff --git a/Cargo.lock b/Cargo.lock index 5517f93dfa31c2d66d6d311fcec8b625f564846b..8fea3f5b5e0da683a8fc28a50e108e9dea3c87b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,72 +2,53 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" -dependencies = [ - "memchr 0.1.11", -] - [[package]] name = "aho-corasick" version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ - "memchr 2.5.0", + "memchr", ] [[package]] -name = "ansi_term" -version = "0.12.1" +name = "annotate-snippets" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +checksum = "c3b9d411ecbaf79885c6df4d75fff75858d5995ff25385657a28af47e82f9c36" dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi 0.3.9", + "unicode-width", + "yansi-term", ] [[package]] name = "bindgen" -version = "0.64.0" +version = "0.70.1" dependencies = [ - "bitflags", + "annotate-snippets", + "bitflags 2.2.1", "cexpr", "clang-sys", - "lazy_static", - "lazycell", - "log 0.4.17", - "peeking_take_while", + "itertools", + "log", + "prettyplease", "proc-macro2", "quote", - "regex 1.7.1", + "regex", "rustc-hash", "shlex", - "syn", - "which", + "syn 2.0.18", ] [[package]] name = "bindgen-cli" -version = "0.64.0" +version = "0.70.1" dependencies = [ "bindgen", - "clap 4.1.4", - "env_logger 0.9.3", - "log 0.4.17", + "clap", + "clap_complete", + "env_logger 0.10.0", + "log", "shlex", ] @@ -84,9 +65,13 @@ name = "bindgen-tests" version = "0.1.0" dependencies = [ "bindgen", - "clap 4.1.4", - "diff", + "clap", + "clap_complete", + "owo-colors", + "prettyplease", "shlex", + "similar", + "syn 2.0.18", "tempfile", ] @@ -96,6 +81,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" + [[package]] name = "block" version = "0.1.6" @@ -131,22 +122,7 @@ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", - "libloading 0.7.4", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", + "libloading", ] [[package]] @@ -155,15 +131,24 @@ version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "is-terminal", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", ] +[[package]] +name = "clap_complete" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.1.0" @@ -174,7 +159,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -186,12 +171,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "either" version = "1.8.1" @@ -200,36 +179,36 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "env_logger" -version = "0.3.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ - "log 0.3.9", - "regex 0.1.80", + "log", + "regex", ] [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", - "log 0.4.17", - "regex 1.7.1", + "is-terminal", + "log", + "regex", "termcolor", ] [[package]] name = "errno" -version = "0.2.8" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "winapi 0.3.9", + "windows-sys 0.48.0", ] [[package]] @@ -252,10 +231,15 @@ dependencies = [ ] [[package]] -name = "fuchsia-cprng" -version = "0.1.1" +name = "getrandom" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] [[package]] name = "glob" @@ -271,21 +255,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "humantime" @@ -309,58 +281,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "is-terminal" -version = "0.4.2" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "itertools" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "either", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" -version = "0.2.139" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "libloading" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" -dependencies = [ - "cfg-if", - "winapi 0.3.9", -] +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libloading" @@ -369,23 +318,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", - "winapi 0.3.9", + "winapi", ] [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.17", -] +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "log" @@ -405,15 +345,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memchr" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" -dependencies = [ - "libc", -] - [[package]] name = "memchr" version = "2.5.0" @@ -432,7 +363,7 @@ version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "memchr 2.5.0", + "memchr", "minimal-lexical", ] @@ -458,10 +389,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] -name = "peeking_take_while" -version = "0.1.2" +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "prettyplease" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +checksum = "43ded2b5b204571f065ab8540367d738dfe1b3606ab9eb669dcfb5e7a3a07501" +dependencies = [ + "proc-macro2", + "syn 2.0.18", +] [[package]] name = "proc-macro-error" @@ -472,7 +413,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "version_check", ] @@ -489,111 +430,67 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" dependencies = [ "unicode-ident", ] [[package]] name = "quickcheck" -version = "0.4.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c2411d418cea2364325b18a205664f9ef8252e06b2e911db97c0b0d98b1406" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ - "env_logger 0.3.5", - "log 0.3.9", - "rand 0.3.23", + "env_logger 0.8.4", + "log", + "rand", ] [[package]] name = "quickchecking" -version = "0.1.0" +version = "0.0.0" dependencies = [ - "clap 2.34.0", - "lazy_static", + "clap", "quickcheck", - "rand 0.3.23", - "tempdir", + "tempfile", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.3.23" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", + "rand_core", ] [[package]] name = "rand_core" -version = "0.3.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "getrandom", ] [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "0.1.80" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "aho-corasick 0.5.3", - "memchr 0.1.11", - "regex-syntax 0.3.9", - "thread_local", - "utf8-ranges", + "bitflags 1.3.2", ] [[package]] @@ -602,32 +499,17 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ - "aho-corasick 0.7.20", - "memchr 2.5.0", - "regex-syntax 0.6.28", + "aho-corasick", + "memchr", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" - [[package]] name = "regex-syntax" version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "rustc-hash" version = "1.1.0" @@ -636,29 +518,29 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.7" +version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] name = "shlex" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] -name = "strsim" -version = "0.8.0" +name = "similar" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" [[package]] name = "strsim" @@ -678,27 +560,27 @@ dependencies = [ ] [[package]] -name = "tempdir" -version = "0.3.7" +name = "syn" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ - "rand 0.4.6", - "remove_dir_all", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] name = "tempfile" -version = "3.3.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi 0.3.9", + "rustix", + "windows-sys 0.45.0", ] [[package]] @@ -712,41 +594,13 @@ dependencies = [ [[package]] name = "tests_expectations" -version = "0.1.0" +version = "0.0.0" dependencies = [ "block", - "libloading 0.6.7", + "libloading", "objc", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -dependencies = [ - "kernel32-sys", - "libc", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" -dependencies = [ - "thread-id", -] - [[package]] name = "unicode-ident" version = "1.0.6" @@ -759,18 +613,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -778,21 +620,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "which" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" -dependencies = [ - "either", - "libc", - "once_cell", -] - -[[package]] -name = "winapi" -version = "0.2.8" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" @@ -804,12 +635,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -822,7 +647,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -837,53 +662,152 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.1", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "yansi-term" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml index a9d9d41ee673ced024e25e07bdb174dbc8b0056c..bc9a80555d7760226099d4c1cd018ca7566267d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,32 @@ default-members = [ "bindgen-cli", "bindgen-tests", ] + +# Config for 'cargo dist' +[workspace.metadata.dist] +# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.12.0" +# CI backends to support +ci = ["github"] +# The installers to generate for each app +installers = ["shell", "powershell"] +# Target platforms to build apps for (Rust target-triple syntax) +targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] +# Whether to consider the binaries in a package for distribution (defaults true) +dist = false +# Publish jobs to run in CI +pr-run-mode = "plan" +# Whether to install an updater program +install-updater = false + +# Config for 'cargo release' +[workspace.metadata.release] +shared-version = true # ensures published packages share the same version +tag-name = "v{{version}}" +# Don't release any crate unless its manifest has `release = true` +release = false + +# The profile that 'cargo dist' will build with +[profile.dist] +inherits = "release" +lto = "thin" diff --git a/OAT.xml b/OAT.xml index f046f3454cad6d71f96b57bde1cfcbd60fc7ff19..f20b6e826c3ee8e8879b7ed7f156955e2f6d568f 100644 --- a/OAT.xml +++ b/OAT.xml @@ -60,6 +60,7 @@ Note:If the text contains special characters|please escape them according to the + diff --git a/README.md b/README.md index 67f227c4fa56c98154d64978f14028bfc79c93a1..b35dee3bef41f778b35978d2549ce19414b0b8ed 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,15 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.60.0**. +The `bindgen` minimum supported Rust version is **1.70.0**. + +The `bindgen-cli` minimum supported Rust version is **1.70.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. -The MSRV is the minimum Rust version that can be used to *compile* `bindgen`. However, `bindgen` can generate bindings that are compatible with Rust versions below the current MSRV. +The MSRV is the minimum Rust version that can be used to *compile* each crate. However, `bindgen` and `bindgen-cli` can generate bindings that are compatible with Rust versions below the current MSRV. + +Most of the time, the `bindgen-cli` crate will have a more recent MSRV than `bindgen` as crates such as `clap` require it. ## API Reference diff --git a/appveyor.yml b/appveyor.yml index 741c59fda4cac37601d318c9786b7d08953471c0..ffb74eedc6491a3f9c1d18b0505b3d16c4b02296 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,18 +2,18 @@ environment: RUST_BACKTRACE: 1 RUST_CHANNEL: "%Configuration%" matrix: - - TARGET: gnu - LLVM_VERSION: 5.0.0-1 - BINDGEN_FEATURES: testing_only_libclang_5 - TARGET: gnu LLVM_VERSION: 9.0.0-1 - BINDGEN_FEATURES: testing_only_libclang_9 - - TARGET: msvc - LLVM_VERSION: 5.0.0 - BINDGEN_FEATURES: testing_only_libclang_5 + BINDGEN_FEATURES: __testing_only_libclang_9 + - TARGET: gnu + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 - TARGET: msvc LLVM_VERSION: 9.0.0 - BINDGEN_FEATURES: testing_only_libclang_9 + BINDGEN_FEATURES: __testing_only_libclang_9 + - TARGET: msvc + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 configuration: - stable diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 139945695edc9ac5d394adcf0ab56b36e96d856c..6fc02f3a55b94e952babeb9492c8b6b7535e1312 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,26 +11,38 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.64.0" +version = "0.70.1" edition = "2018" -# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.60.0" +rust-version = "1.70.0" [[bin]] path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] } -shlex = "1" +bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, features = ["__cli", "experimental", "prettyplease"] } clap = { version = "4", features = ["derive"] } -env_logger = { version = "0.9.0", optional = true } +clap_complete = "4" +env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } +shlex = "1" [features] -default = ["logging", "runtime", "which-rustfmt"] -logging = ["bindgen/logging", "env_logger", "log"] +default = ["logging", "runtime"] +logging = ["bindgen/logging", "dep:env_logger", "dep:log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] -# Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["bindgen/which-rustfmt"] +prettyplease = ["bindgen/prettyplease"] + +## The following features are for internal use and they shouldn't be used if +## you're not hacking on bindgen +# Features used for CI testing +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] + +[package.metadata.release] +release = true + +[package.metadata.dist] +dist = true diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a3b3612694f738d8f952970606a032fbb28695dc..caa47c62687d088cfbb382a2aca2c617b45e1329 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -1,10 +1,3 @@ -extern crate bindgen; -extern crate clap; -#[cfg(feature = "logging")] -extern crate env_logger; -#[cfg(feature = "logging")] -extern crate log; - use std::env; mod options; @@ -13,10 +6,10 @@ use crate::options::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { let version = bindgen::clang_version(); - let expected_version = if cfg!(feature = "testing_only_libclang_9") { + let expected_version = if cfg!(feature = "__testing_only_libclang_16") { + Some((16, 0)) + } else if cfg!(feature = "__testing_only_libclang_9") { Some((9, 0)) - } else if cfg!(feature = "testing_only_libclang_5") { - Some((5, 0)) } else { None }; @@ -45,7 +38,7 @@ pub fn main() { if verbose { print_verbose_err() } - println!("{}", info); + eprintln!("{}", info); })); let bindings = @@ -56,21 +49,21 @@ pub fn main() { bindings.write(output).expect("Unable to write output"); } Err(error) => { - println!("{}", error); + eprintln!("{}", error); std::process::exit(1); } }; } fn print_verbose_err() { - println!("Bindgen unexpectedly panicked"); - println!( + eprintln!("Bindgen unexpectedly panicked"); + eprintln!( "This may be caused by one of the known-unsupported \ things (https://rust-lang.github.io/rust-bindgen/cpp.html), \ please modify the bindgen flags to work around it as \ described in https://rust-lang.github.io/rust-bindgen/cpp.html" ); - println!( + eprintln!( "Otherwise, please file an issue at \ https://github.com/rust-lang/rust-bindgen/issues/new" ); diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 458c7bab1f9fd246e26b7ecb72c36c5ca4cd828c..acb18de0db0e8d7abc7126a65c9b5d8fe69b57e9 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1,23 +1,27 @@ use bindgen::callbacks::TypeKind; use bindgen::{ - builder, AliasVariation, Builder, CodegenConfig, EnumVariation, - MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, - DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + builder, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, + FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, + RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; -use clap::Parser; +use clap::error::{Error, ErrorKind}; +use clap::{CommandFactory, Parser}; use std::fs::File; -use std::io::{self, Error, ErrorKind}; -use std::path::PathBuf; +use std::io; +use std::path::{Path, PathBuf}; +use std::process::exit; fn rust_target_help() -> String { format!( - "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {:?}.", + "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {}.", RUST_TARGET_STRINGS, - String::from(RustTarget::default()) + RustTarget::default() ) } -fn parse_codegen_config(what_to_generate: &str) -> io::Result { +fn parse_codegen_config( + what_to_generate: &str, +) -> Result { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(',') { match what { @@ -28,9 +32,9 @@ fn parse_codegen_config(what_to_generate: &str) -> io::Result { "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), "destructors" => config.insert(CodegenConfig::DESTRUCTORS), otherwise => { - return Err(Error::new( - ErrorKind::Other, - format!("Unknown generate item: {}", otherwise), + return Err(Error::raw( + ErrorKind::InvalidValue, + format!("Unknown codegen item kind: {}", otherwise), )); } } @@ -39,10 +43,54 @@ fn parse_codegen_config(what_to_generate: &str) -> io::Result { Ok(config) } +fn parse_rustfmt_config_path(path_str: &str) -> Result { + let path = Path::new(path_str); + + if !path.is_absolute() { + return Err(Error::raw( + ErrorKind::InvalidValue, + "--rustfmt-configuration-file needs to be an absolute path!", + )); + } + + if path.to_str().is_none() { + return Err(Error::raw( + ErrorKind::InvalidUtf8, + "--rustfmt-configuration-file contains non-valid UTF8 characters.", + )); + } + + Ok(path.to_path_buf()) +} + +fn parse_abi_override(abi_override: &str) -> Result<(Abi, String), Error> { + let (regex, abi_str) = abi_override + .rsplit_once('=') + .ok_or_else(|| Error::raw(ErrorKind::InvalidValue, "Missing `=`"))?; + + let abi = abi_str + .parse() + .map_err(|err| Error::raw(ErrorKind::InvalidValue, err))?; + + Ok((abi, regex.to_owned())) +} + +fn parse_custom_derive( + custom_derive: &str, +) -> Result<(Vec, String), Error> { + let (regex, derives) = custom_derive + .rsplit_once('=') + .ok_or_else(|| Error::raw(ErrorKind::InvalidValue, "Missing `=`"))?; + + let derives = derives.split(',').map(|s| s.to_owned()).collect(); + + Ok((derives, regex.to_owned())) +} + #[derive(Parser, Debug)] #[clap( about = "Generates Rust bindings from C/C++ headers.", - override_usage = "bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...", + override_usage = "bindgen
-- ...", trailing_var_arg = true )] struct BindgenCommand { @@ -51,63 +99,69 @@ struct BindgenCommand { /// Path to write depfile to. #[arg(long)] depfile: Option, - /// The default style of code used to generate enums. - #[arg(long, value_name = "VARIANT")] + /// The default STYLE of code used to generate enums. + #[arg(long, value_name = "STYLE")] default_enum_style: Option, - /// Mark any enum whose name matches as a set of bitfield flags. + /// Mark any enum whose name matches REGEX as a set of bitfield flags. #[arg(long, value_name = "REGEX")] bitfield_enum: Vec, - /// Mark any enum whose name matches as a newtype. + /// Mark any enum whose name matches REGEX as a newtype. #[arg(long, value_name = "REGEX")] newtype_enum: Vec, - /// Mark any enum whose name matches as a global newtype. + /// Mark any enum whose name matches REGEX as a global newtype. #[arg(long, value_name = "REGEX")] newtype_global_enum: Vec, - /// Mark any enum whose name matches as a Rust enum. + /// Mark any enum whose name matches REGEX as a Rust enum. #[arg(long, value_name = "REGEX")] rustified_enum: Vec, - /// Mark any enum whose name matches as a series of constants. + /// Mark any enum whose name matches REGEX as a non-exhaustive Rust enum. + #[arg(long, value_name = "REGEX")] + rustified_non_exhaustive_enum: Vec, + /// Mark any enum whose name matches REGEX as a series of constants. #[arg(long, value_name = "REGEX")] constified_enum: Vec, - /// Mark any enum whose name matches as a module of constants. + /// Mark any enum whose name matches REGEX as a module of constants. #[arg(long, value_name = "REGEX")] constified_enum_module: Vec, - /// The default signed/unsigned type for C macro constants. - #[arg(long, value_name = "VARIANT")] + /// The default signed/unsigned TYPE for C macro constants. + #[arg(long, value_name = "TYPE")] default_macro_constant_type: Option, - /// The default style of code used to generate typedefs. - #[arg(long, value_name = "VARIANT")] + /// The default STYLE of code used to generate typedefs. + #[arg(long, value_name = "STYLE")] default_alias_style: Option, - /// Mark any typedef alias whose name matches to use normal type aliasing. + /// Mark any typedef alias whose name matches REGEX to use normal type aliasing. #[arg(long, value_name = "REGEX")] normal_alias: Vec, - /// Mark any typedef alias whose name matches to have a new type generated for it. + /// Mark any typedef alias whose name matches REGEX to have a new type generated for it. #[arg(long, value_name = "REGEX")] new_type_alias: Vec, - /// Mark any typedef alias whose name matches to have a new type with Deref and DerefMut to the inner type. + /// Mark any typedef alias whose name matches REGEX to have a new type with Deref and DerefMut to the inner type. #[arg(long, value_name = "REGEX")] new_type_alias_deref: Vec, - /// The default style of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. + /// The default STYLE of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. #[arg(long, value_name = "STYLE")] default_non_copy_union_style: Option, - /// Mark any union whose name matches and who has a non-Copy member to use a bindgen-generated wrapper for fields. + /// Mark any union whose name matches REGEX and who has a non-Copy member to use a bindgen-generated wrapper for fields. #[arg(long, value_name = "REGEX")] bindgen_wrapper_union: Vec, - /// Mark any union whose name matches and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. + /// Mark any union whose name matches REGEX and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. #[arg(long, value_name = "REGEX")] manually_drop_union: Vec, - /// Mark as hidden. + /// Mark TYPE as hidden. #[arg(long, value_name = "TYPE")] blocklist_type: Vec, - /// Mark as hidden. + /// Mark FUNCTION as hidden. #[arg(long, value_name = "FUNCTION")] blocklist_function: Vec, - /// Mark as hidden. + /// Mark ITEM as hidden. #[arg(long, value_name = "ITEM")] blocklist_item: Vec, - /// Mark as hidden. + /// Mark FILE as hidden. #[arg(long, value_name = "FILE")] blocklist_file: Vec, + /// Mark VAR as hidden. + #[arg(long, value_name = "VAR")] + blocklist_var: Vec, /// Avoid generating layout tests for any type. #[arg(long)] no_layout_tests: bool, @@ -129,7 +183,7 @@ struct BindgenCommand { /// Derive Default on any type. #[arg(long)] with_derive_default: bool, - /// Derive Hash on any type.docstring + /// Derive Hash on any type. #[arg(long)] with_derive_hash: bool, /// Derive PartialEq on any type. @@ -144,7 +198,7 @@ struct BindgenCommand { /// Derive Ord on any type. #[arg(long)] with_derive_ord: bool, - /// Avoid including doc comments in the output, see: https://github.com/rust-lang/rust-bindgen/issues/426 + /// Avoid including doc comments in the output, see: #[arg(long)] no_doc_comments: bool, /// Disable allowlisting types recursively. This will cause bindgen to emit Rust code that won't compile! See the `bindgen::Builder::allowlist_recursively` method's documentation for details. @@ -156,6 +210,9 @@ struct BindgenCommand { /// Generate block signatures instead of void pointers. #[arg(long)] generate_block: bool, + /// Generate string constants as `&CStr` instead of `&[u8]`. + #[arg(long)] + generate_cstr: bool, /// Use extern crate instead of use for block. #[arg(long)] block_extern_crate: bool, @@ -165,10 +222,10 @@ struct BindgenCommand { /// Output bindings for builtin definitions, e.g. __builtin_va_list. #[arg(long)] builtins: bool, - /// Use the given prefix before raw types instead of ::std::os::raw. + /// Use the given PREFIX before raw types instead of ::std::os::raw. #[arg(long, value_name = "PREFIX")] ctypes_prefix: Option, - /// Use the given prefix for anonymous fields. + /// Use the given PREFIX for anonymous fields. #[arg(long, default_value = DEFAULT_ANON_FIELDS_PREFIX, value_name = "PREFIX")] anon_fields_prefix: String, /// Time the different bindgen phases and print to stderr @@ -180,7 +237,7 @@ struct BindgenCommand { /// Output our internal IR for debugging purposes. #[arg(long)] emit_ir: bool, - /// Dump graphviz dot file. + /// Dump a graphviz dot file to PATH. #[arg(long, value_name = "PATH")] emit_ir_graphviz: Option, /// Enable support for C++ namespaces. @@ -198,7 +255,7 @@ struct BindgenCommand { /// Suppress insertion of bindgen's version identifier into generated bindings. #[arg(long)] disable_header_comment: bool, - /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts.docstring + /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts. #[arg(long)] ignore_functions: bool, /// Generate only given items, split by commas. Valid values are `functions`,`types`, `vars`, `methods`, `constructors` and `destructors`. @@ -219,17 +276,17 @@ struct BindgenCommand { /// Try to fit macro constants into types smaller than u32/i32 #[arg(long)] fit_macro_constant_types: bool, - /// Mark as opaque. + /// Mark TYPE as opaque. #[arg(long, value_name = "TYPE")] opaque_type: Vec, - /// Write Rust bindings to . + /// Write Rust bindings to OUTPUT. #[arg(long, short, value_name = "OUTPUT")] output: Option, /// Add a raw line of Rust code at the beginning of output. #[arg(long)] raw_line: Vec, - /// Add a raw line of Rust code to a given module. - #[arg(long, number_of_values = 2, value_names = ["MODULE-NAME", "RAW-LINE"])] + /// Add a RAW_LINE of Rust code to a given module with name MODULE_NAME. + #[arg(long, number_of_values = 2, value_names = ["MODULE_NAME", "RAW_LINE"])] module_raw_line: Vec, #[arg(long, help = rust_target_help())] rust_target: Option, @@ -239,24 +296,24 @@ struct BindgenCommand { /// Conservatively generate inline namespaces to avoid name conflicts. #[arg(long)] conservative_inline_namespaces: bool, - /// MSVC C++ ABI mangling. DEPRECATED: Has no effect. - #[arg(long)] - use_msvc_mangling: bool, - /// Allowlist all the free-standing functions matching . Other non-allowlisted functions will not be generated. + /// Allowlist all the free-standing functions matching REGEX. Other non-allowlisted functions will not be generated. #[arg(long, value_name = "REGEX")] allowlist_function: Vec, /// Generate inline functions. #[arg(long)] generate_inline_functions: bool, - /// Only generate types matching . Other non-allowlisted types will not be generated. + /// Only generate types matching REGEX. Other non-allowlisted types will not be generated. #[arg(long, value_name = "REGEX")] allowlist_type: Vec, - /// Allowlist all the free-standing variables matching . Other non-allowlisted variables will not be generated. + /// Allowlist all the free-standing variables matching REGEX. Other non-allowlisted variables will not be generated. #[arg(long, value_name = "REGEX")] allowlist_var: Vec, - /// Allowlist all contents of . + /// Allowlist all contents of PATH. #[arg(long, value_name = "PATH")] allowlist_file: Vec, + /// Allowlist all items matching REGEX. Other non-allowlisted items will not be generated. + #[arg(long, value_name = "REGEX")] + allowlist_item: Vec, /// Print verbose error messages. #[arg(long)] verbose: bool, @@ -266,55 +323,60 @@ struct BindgenCommand { /// Do not record matching items in the regex sets. This disables reporting of unused items. #[arg(long)] no_record_matches: bool, - /// Ignored - this is enabled by default. - #[arg(long = "size_t-is-usize")] - size_t_is_usize: bool, /// Do not bind size_t as usize (useful on platforms where those types are incompatible). #[arg(long = "no-size_t-is-usize")] no_size_t_is_usize: bool, - /// Do not format the generated bindings with rustfmt. + /// Do not format the generated bindings with rustfmt. This option is deprecated, please use + /// `--formatter=none` instead. #[arg(long)] no_rustfmt_bindings: bool, - /// Format the generated bindings with rustfmt. DEPRECATED: --rustfmt-bindings is now enabled by default. Disable with --no-rustfmt-bindings. - #[arg(long)] - rustfmt_bindings: bool, - /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter is incompatible with --no-rustfmt-bindings. - #[arg(long, value_name = "PATH")] - rustfmt_configuration_file: Option, - /// Avoid deriving PartialEq for types matching . + /// Which FORMATTER should be used for the bindings + #[arg( + long, + value_name = "FORMATTER", + conflicts_with = "no_rustfmt_bindings" + )] + formatter: Option, + /// The absolute PATH to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. + #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings", value_parser=parse_rustfmt_config_path)] + rustfmt_configuration_file: Option, + /// Avoid deriving PartialEq for types matching REGEX. #[arg(long, value_name = "REGEX")] no_partialeq: Vec, - /// Avoid deriving Copy for types matching . + /// Avoid deriving Copy and Clone for types matching REGEX. #[arg(long, value_name = "REGEX")] no_copy: Vec, - /// Avoid deriving Debug for types matching . + /// Avoid deriving Debug for types matching REGEX. #[arg(long, value_name = "REGEX")] no_debug: Vec, - /// Avoid deriving/implementing Default for types matching . + /// Avoid deriving/implementing Default for types matching REGEX. #[arg(long, value_name = "REGEX")] no_default: Vec, - /// Avoid deriving Hash for types matching . + /// Avoid deriving Hash for types matching REGEX. #[arg(long, value_name = "REGEX")] no_hash: Vec, - /// Add #[must_use] annotation to types matching . + /// Add `#[must_use]` annotation to types matching REGEX. #[arg(long, value_name = "REGEX")] must_use_type: Vec, - /// Enables detecting unexposed attributes in functions (slow). Used to generate #[must_use] annotations. + /// Enables detecting unexposed attributes in functions (slow). Used to generate `#[must_use]` annotations. #[arg(long)] enable_function_attribute_detection: bool, /// Use `*const [T; size]` instead of `*const T` for C arrays #[arg(long)] use_array_pointers_in_arguments: bool, - /// The name to be used in a #[link(wasm_import_module = ...)] statement + /// The NAME to be used in a #[link(wasm_import_module = ...)] statement #[arg(long, value_name = "NAME")] wasm_import_module_name: Option, - /// Use dynamic loading mode with the given library name. + /// Use dynamic loading mode with the given library NAME. #[arg(long, value_name = "NAME")] dynamic_loading: Option, /// Require successful linkage to all functions in the library. #[arg(long)] dynamic_link_require_all: bool, - /// Makes generated bindings `pub` only for items if the items are publically accessible in C++. + /// Prefix the name of exported symbols. + #[arg(long)] + prefix_link_name: Option, + /// Makes generated bindings `pub` only for items if the items are publicly accessible in C++. #[arg(long)] respect_cxx_access_specs: bool, /// Always translate enum integer types to native Rust integer types. @@ -335,35 +397,54 @@ struct BindgenCommand { /// Deduplicates extern blocks. #[arg(long)] merge_extern_blocks: bool, - /// Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind. - #[arg(long, value_name = "OVERRIDE")] - override_abi: Vec, + /// Overrides the ABI of functions matching REGEX. The OVERRIDE value must be of the shape REGEX=ABI where ABI can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind<.> + #[arg(long, value_name = "OVERRIDE", value_parser = parse_abi_override)] + override_abi: Vec<(Abi, String)>, /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, - /// Derive custom traits on any kind of type. The value must be of the shape = where is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom: Vec, - /// Derive custom traits on a `struct`. The value must be of the shape = where is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_struct: Vec, - /// Derive custom traits on an `enum. The value must be of the shape = where is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_enum: Vec, - /// Derive custom traits on a `union`. The value must be of the shape = where is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_union: Vec, + /// Enable fallback for clang macro parsing. + #[arg(long)] + clang_macro_fallback: bool, + /// Set path for temporary files generated by fallback for clang macro parsing. + #[arg(long)] + clang_macro_fallback_build_dir: Option, + /// Use DSTs to represent structures with flexible array members. + #[arg(long)] + flexarray_dst: bool, + /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom: Vec<(Vec, String)>, + /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_struct: Vec<(Vec, String)>, + /// Derive custom traits on an `enum. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_enum: Vec<(Vec, String)>, + /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_union: Vec<(Vec, String)>, /// Generate wrappers for `static` and `static inline` functions. #[arg(long, requires = "experimental")] wrap_static_fns: bool, - /// Sets the path for the source file that must be created due to the presence of `static` and + /// Sets the PATH for the source file that must be created due to the presence of `static` and /// `static inline` functions. #[arg(long, requires = "experimental", value_name = "PATH")] wrap_static_fns_path: Option, - /// Sets the suffix added to the extern wrapper functions generated for `static` and `static + /// Sets the SUFFIX added to the extern wrapper functions generated for `static` and `static /// inline` functions. #[arg(long, requires = "experimental", value_name = "SUFFIX")] wrap_static_fns_suffix: Option, + /// Set the default VISIBILITY of fields, including bitfields and accessor methods for + /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. + #[arg(long, value_name = "VISIBILITY")] + default_visibility: Option, + /// Whether to emit diagnostics or not. + #[arg(long, requires = "experimental")] + emit_diagnostics: bool, + /// Generates completions for the specified SHELL, sends them to `stdout` and exits. + #[arg(long, value_name = "SHELL")] + // generate_shell_completions: Option, /// Enables experimental features. #[arg(long)] experimental: bool, @@ -391,6 +472,7 @@ where newtype_enum, newtype_global_enum, rustified_enum, + rustified_non_exhaustive_enum, constified_enum, constified_enum_module, default_macro_constant_type, @@ -405,6 +487,7 @@ where blocklist_function, blocklist_item, blocklist_file, + blocklist_var, no_layout_tests, no_derive_copy, no_derive_debug, @@ -421,6 +504,7 @@ where no_recursive_allowlist, objc_extern_crate, generate_block, + generate_cstr, block_extern_crate, distrust_clang_mangling, builtins, @@ -449,19 +533,18 @@ where rust_target, use_core, conservative_inline_namespaces, - use_msvc_mangling: _, allowlist_function, generate_inline_functions, allowlist_type, allowlist_var, allowlist_file, + allowlist_item, verbose, dump_preprocessed_input, no_record_matches, - size_t_is_usize: _, no_size_t_is_usize, no_rustfmt_bindings, - rustfmt_bindings: _, + formatter, rustfmt_configuration_file, no_partialeq, no_copy, @@ -474,6 +557,7 @@ where wasm_import_module_name, dynamic_loading, dynamic_link_require_all, + prefix_link_name, respect_cxx_access_specs, translate_enum_integer_types, c_naming, @@ -483,6 +567,9 @@ where merge_extern_blocks, override_abi, wrap_unsafe_ops, + clang_macro_fallback, + clang_macro_fallback_build_dir, + flexarray_dst, with_derive_custom, with_derive_custom_struct, with_derive_custom_enum, @@ -490,11 +577,25 @@ where wrap_static_fns, wrap_static_fns_path, wrap_static_fns_suffix, + default_visibility, + emit_diagnostics, + // generate_shell_completions, experimental: _, version, clang_args, } = command; + // if let Some(shell) = generate_shell_completions { + // clap_complete::generate( + // shell, + // &mut BindgenCommand::command(), + // "bindgen", + // &mut std::io::stdout(), + // ); + + // exit(0); + // } + if version { println!( "bindgen {}", @@ -511,7 +612,7 @@ where if let Some(header) = header { builder = builder.header(header); } else { - return Err(Error::new(ErrorKind::Other, "Header not found")); + return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); } if let Some(rust_target) = rust_target { @@ -538,6 +639,10 @@ where builder = builder.rustified_enum(regex); } + for regex in rustified_non_exhaustive_enum { + builder = builder.rustified_non_exhaustive_enum(regex); + } + for regex in constified_enum { builder = builder.constified_enum(regex); } @@ -595,6 +700,10 @@ where builder = builder.blocklist_file(file); } + for var in blocklist_var { + builder = builder.blocklist_var(var); + } + if builtins { builder = builder.emit_builtins(); } @@ -745,6 +854,10 @@ where builder = builder.generate_block(true); } + if generate_cstr { + builder = builder.generate_cstr(true); + } + if block_extern_crate { builder = builder.block_extern_crate(true); } @@ -795,6 +908,10 @@ where builder = builder.allowlist_file(file); } + for item in allowlist_item { + builder = builder.allowlist_item(item); + } + for arg in clang_args { builder = builder.clang_arg(arg); } @@ -825,33 +942,14 @@ where } if no_rustfmt_bindings { - builder = builder.rustfmt_bindings(false); + builder = builder.formatter(Formatter::None); } - if let Some(path_str) = rustfmt_configuration_file { - let path = PathBuf::from(path_str); - - if no_rustfmt_bindings { - return Err(Error::new( - ErrorKind::Other, - "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings", - )); - } - - if !path.is_absolute() { - return Err(Error::new( - ErrorKind::Other, - "--rustfmt-configuration--file needs to be an absolute path!", - )); - } - - if path.to_str().is_none() { - return Err(Error::new( - ErrorKind::Other, - "--rustfmt-configuration-file contains non-valid UTF8 characters.", - )); - } + if let Some(formatter) = formatter { + builder = builder.formatter(formatter); + } + if let Some(path) = rustfmt_configuration_file { builder = builder.rustfmt_configuration_file(Some(path)); } @@ -887,6 +985,28 @@ where builder = builder.dynamic_link_require_all(true); } + if let Some(prefix_link_name) = prefix_link_name { + #[derive(Debug)] + struct PrefixLinkNameCallback { + prefix: String, + } + + impl bindgen::callbacks::ParseCallbacks for PrefixLinkNameCallback { + fn generated_link_name_override( + &self, + item_info: bindgen::callbacks::ItemInfo<'_>, + ) -> Option { + let mut prefix = self.prefix.clone(); + prefix.push_str(item_info.name); + Some(prefix) + } + } + + builder = builder.parse_callbacks(Box::new(PrefixLinkNameCallback { + prefix: prefix_link_name, + })) + } + if respect_cxx_access_specs { builder = builder.respect_cxx_access_specs(true); } @@ -915,13 +1035,7 @@ where builder = builder.merge_extern_blocks(true); } - for abi_override in override_abi { - let (regex, abi_str) = abi_override - .rsplit_once('=') - .expect("Invalid ABI override: Missing `=`"); - let abi = abi_str - .parse() - .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); + for (abi, regex) in override_abi { builder = builder.override_abi(abi, regex); } @@ -929,6 +1043,18 @@ where builder = builder.wrap_unsafe_ops(true); } + if clang_macro_fallback { + builder = builder.clang_macro_fallback(); + } + + if let Some(path) = clang_macro_fallback_build_dir { + builder = builder.clang_macro_fallback_build_dir(path); + } + + if flexarray_dst { + builder = builder.flexarray_dst(true); + } + #[derive(Debug)] struct CustomDeriveCallback { derives: Vec, @@ -972,21 +1098,29 @@ where } } - for (custom_derives, kind) in [ - (with_derive_custom, None), - (with_derive_custom_struct, Some(TypeKind::Struct)), - (with_derive_custom_enum, Some(TypeKind::Enum)), - (with_derive_custom_union, Some(TypeKind::Union)), + for (custom_derives, kind, name) in [ + (with_derive_custom, None, "--with-derive-custom"), + ( + with_derive_custom_struct, + Some(TypeKind::Struct), + "--with-derive-custom-struct", + ), + ( + with_derive_custom_enum, + Some(TypeKind::Enum), + "--with-derive-custom-enum", + ), + ( + with_derive_custom_union, + Some(TypeKind::Union), + "--with-derive-custom-union", + ), ] { - for custom_derive in custom_derives { - let (regex, derives) = custom_derive - .rsplit_once('=') - .expect("Invalid custom derive argument: Missing `=`"); - let derives = derives.split(',').map(|s| s.to_owned()).collect(); - + let name = emit_diagnostics.then_some(name); + for (derives, regex) in custom_derives { let mut regex_set = RegexSet::new(); regex_set.insert(regex); - regex_set.build(false); + regex_set.build_with_diagnostics(false, name); builder = builder.parse_callbacks(Box::new(CustomDeriveCallback { derives, @@ -1008,5 +1142,13 @@ where builder = builder.wrap_static_fns_suffix(suffix); } + if let Some(visibility) = default_visibility { + builder = builder.default_visibility(visibility); + } + + if emit_diagnostics { + builder = builder.emit_diagnostics(); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 60f0426a76b4e566557eda5448d79931f1c87a93..ccdd1467dff8be970a4c8fd230596a698a0f2c29 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -14,7 +14,6 @@ cc = "1.0" static = ["bindgen/static"] runtime = ["bindgen/runtime"] -testing_only_docs = ["bindgen/testing_only_docs"] -testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] -testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] -testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 3cc0edb99b36f927f200e0293d5c7f373ee2fe2e..6b06c91bc3d3aa32df4d9d8cbcc9eef68700fa55 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,10 +1,9 @@ extern crate bindgen; -extern crate cc; use bindgen::callbacks::{ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, }; -use bindgen::{Builder, CargoCallbacks, EnumVariation}; +use bindgen::{Builder, EnumVariation, Formatter}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -128,6 +127,8 @@ impl ParseCallbacks for MacroCallback { vec!["PartialEq".into()] } else if info.name == "MyOrderedEnum" { vec!["std::cmp::PartialOrd".into()] + } else if info.name == "TestDeriveOnAlias" { + vec!["std::cmp::PartialEq".into(), "std::cmp::PartialOrd".into()] } else { vec![] } @@ -149,6 +150,15 @@ impl Drop for MacroCallback { } } +#[derive(Debug)] +struct WrappedVaListCallback; + +impl ParseCallbacks for WrappedVaListCallback { + fn wrap_as_variadic_fn(&self, name: &str) -> Option { + Some(name.to_owned() + "_wrapped") + } +} + fn setup_macro_test() { cc::Build::new() .cpp(true) @@ -166,7 +176,7 @@ fn setup_macro_test() { let out_dep_file = out_path.join("test.d"); let bindings = Builder::default() - .rustfmt_bindings(false) + .formatter(Formatter::None) .enable_cxx_namespaces() .default_enum_style(EnumVariation::Rust { non_exhaustive: false, @@ -184,6 +194,7 @@ fn setup_macro_test() { .blocklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") + .new_type_alias("TestDeriveOnAlias") .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) .generate() .expect("Unable to generate bindings"); @@ -222,11 +233,15 @@ fn setup_wrap_static_fns_test() { // generate external bindings with the external .c and .h files let bindings = Builder::default() .header(input_header_file_path_str) - .parse_callbacks(Box::new(CargoCallbacks)) + .parse_callbacks(Box::new( + bindgen::CargoCallbacks::new().rerun_on_header_files(true), + )) + .parse_callbacks(Box::new(WrappedVaListCallback)) .wrap_static_fns(true) .wrap_static_fns_path( out_path.join("wrap_static_fns").display().to_string(), ) + .clang_arg("-DUSE_VA_HEADER") .generate() .expect("Unable to generate bindings"); @@ -242,8 +257,7 @@ fn setup_wrap_static_fns_test() { .arg("-o") .arg(&obj_path) .arg(out_path.join("wrap_static_fns.c")) - .arg("-include") - .arg(input_header_file_path) + .arg("-DUSE_VA_HEADER") .output() .expect("`clang` command error"); if !clang_output.status.success() { @@ -269,7 +283,7 @@ fn setup_wrap_static_fns_test() { bindings .write_to_file(out_rust_file) - .expect("Cound not write bindings to the Rust file"); + .expect("Could not write bindings to the Rust file"); } fn main() { diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index eee1974cbc0245ad187fae1bb7cf795138721b94..81a921b5f82446f9ee8b02084d41d42e5b99f352 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -241,3 +241,6 @@ enum MyOrderedEnum { METER, LIGHTYEAR, }; + +// Used to test custom derives on new-type alias. See `test_custom_derive`. +typedef int TestDeriveOnAlias; diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index e89351c3b35f27efe581014b81b8303a64d4b72f..c37055ee7d995e9f71a89f881f6b765efa910294 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -12,7 +12,6 @@ use std::ffi::CStr; use std::mem; use std::os::raw::c_int; -#[allow(unused)] use bindings::testing::Bar; // This type is generated from module_raw_line. type MacroInteger = isize; @@ -289,6 +288,13 @@ fn test_custom_derive() { assert!(meter < lightyear); assert!(meter > micron); + + // The `add_derives` callback should have added `#[derive(PartialEq, PartialOrd)]` + // to the `TestDeriveOnAlias` new-type alias. If it didn't, this will fail to compile. + let test1 = unsafe { bindings::TestDeriveOnAlias(5) }; + let test2 = unsafe { bindings::TestDeriveOnAlias(6) }; + assert!(test1 < test2); + assert!(!(test1 > test2)); } #[test] @@ -320,5 +326,13 @@ fn test_wrap_static_fns() { let tq = extern_bindings::takes_qualified(&(&5 as *const _) as *const _); assert_eq!(5, tq); + + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(0); + assert_eq!(0, wv1); + + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(2, 5, 3); + assert_eq!(8, wv1); + + extern_bindings::wrap_as_variadic_fn2_wrapped(1, 2); } } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 6df84e8e9bec58f5b7edecf5bc4195c27b31c034..a253b349b9ccc15d2ef93e6ef47660e5ef521aa6 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -5,19 +5,21 @@ version = "0.1.0" publish = false [dev-dependencies] -bindgen = { path = "../bindgen", features = ["cli", "experimental"] } -diff = "0.1" -shlex = "1" +bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } +clap_complete = "4" +shlex = "1" +prettyplease = { version = "0.2.7", features = ["verbatim"] } +syn = { version = "2.0" } tempfile = "3" +similar = { version = "2.2.1", features = ["inline"] } +owo-colors = "3.5.0" [features] logging = ["bindgen/logging"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] -which-rustfmt = ["bindgen/which-rustfmt"] -testing_only_docs = ["bindgen/testing_only_docs"] -testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] -testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] -testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index f8006afeab895b7d2f4cc1d30687dfd11d3d7024..adb95d56d2d6750a82ff33f4451eaa19f66d0d57 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "tests_expectations" description = "bindgen results when ran on ../headers/*" -version = "0.1.0" +version = "0.0.0" authors = [ "Jyun-Yan You ", "Emilio Cobos Álvarez ", "The Servo project developers", ] edition = "2018" +publish = false [dependencies] -objc = "0.2" block = "0.1" -libloading = "0.6.2" +libloading = "0.7" +objc = "0.2" diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index 2111185384fd8c9126f4a2d72b6e7d901acc8871..6136823e212063fdc81e431640bb57f9999c3182 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,7 +8,7 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"]; +const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); diff --git a/bindgen-tests/tests/expectations/rustfmt.toml b/bindgen-tests/tests/expectations/rustfmt.toml new file mode 100644 index 0000000000000000000000000000000000000000..85a717359951f4d4749efc666a0780957efd54fd --- /dev/null +++ b/bindgen-tests/tests/expectations/rustfmt.toml @@ -0,0 +1,2 @@ +# disable rustfmt for this crate so running `cargo fmt` doesn't affect the expected binding files +disable_all_formatting = true diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs index a60a63aa3bfaef670fecccaae19b081221363c14..c55d0b075b644fee4c0f660a0e6d4dcf016cd307 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_ipv4_tuple { @@ -24,77 +18,35 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); -} -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::dport", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, dport) + - 0usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::sport", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, sport) + - 2usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_ipv4_tuple__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv4_tuple__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1::sctp_tag", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1, sctp_tag) - 0usize]; +}; impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -104,46 +56,17 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ipv4_tuple"][::std::mem::size_of::() - 12usize]; + ["Alignment of rte_ipv4_tuple"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv4_tuple::src_addr", + ][::std::mem::offset_of!(rte_ipv4_tuple, src_addr) - 0usize]; + [ + "Offset of field: rte_ipv4_tuple::dst_addr", + ][::std::mem::offset_of!(rte_ipv4_tuple, dst_addr) - 4usize]; +}; impl Default for rte_ipv4_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -172,77 +95,35 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); -} -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::dport", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, dport) + - 0usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::sport", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, sport) + - 2usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_ipv6_tuple__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv6_tuple__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1::sctp_tag", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1, sctp_tag) - 0usize]; +}; impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -252,46 +133,17 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ipv6_tuple"][::std::mem::size_of::() - 36usize]; + ["Alignment of rte_ipv6_tuple"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv6_tuple::src_addr", + ][::std::mem::offset_of!(rte_ipv6_tuple, src_addr) - 0usize]; + [ + "Offset of field: rte_ipv6_tuple::dst_addr", + ][::std::mem::offset_of!(rte_ipv6_tuple, dst_addr) - 16usize]; +}; impl Default for rte_ipv6_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -308,42 +160,19 @@ pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, } -#[test] -fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(rte_thash_tuple)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_thash_tuple"][::std::mem::size_of::() - 48usize]; + [ + "Alignment of rte_thash_tuple", + ][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: rte_thash_tuple::v4", + ][::std::mem::offset_of!(rte_thash_tuple, v4) - 0usize]; + [ + "Offset of field: rte_thash_tuple::v6", + ][::std::mem::offset_of!(rte_thash_tuple, v6) - 0usize]; +}; impl Default for rte_thash_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index 369e2c75eac5bbfaa6d9f3587d34f70e8b9db70d..06d008982ce112daa23f0bf2ac8e8484a8eaa4b2 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -58,8 +52,9 @@ pub struct rte_ipv4_tuple { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_ipv4_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } @@ -71,45 +66,27 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + "Alignment of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::dport", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::sport", ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -119,30 +96,22 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + "Size of rte_ipv4_tuple__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + "Alignment of rte_ipv4_tuple__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + "Offset of field: rte_ipv4_tuple__bindgen_ty_1::sctp_tag", ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { @@ -152,42 +121,27 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)) + "Size of rte_ipv4_tuple", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)) + "Alignment of rte_ipv4_tuple", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) + "Offset of field: rte_ipv4_tuple::src_addr", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) + "Offset of field: rte_ipv4_tuple::dst_addr", ); } impl Clone for rte_ipv4_tuple { @@ -205,8 +159,9 @@ pub struct rte_ipv6_tuple { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_ipv6_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } @@ -218,45 +173,27 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + "Alignment of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::dport", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::sport", ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -266,30 +203,22 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + "Size of rte_ipv6_tuple__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + "Alignment of rte_ipv6_tuple__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + "Offset of field: rte_ipv6_tuple__bindgen_ty_1::sctp_tag", ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { @@ -299,42 +228,27 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)) + "Size of rte_ipv6_tuple", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)) + "Alignment of rte_ipv6_tuple", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) + "Offset of field: rte_ipv6_tuple::src_addr", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) + "Offset of field: rte_ipv6_tuple::dst_addr", ); } impl Clone for rte_ipv6_tuple { @@ -351,33 +265,22 @@ pub struct rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)) + "Size of rte_thash_tuple", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) + "Offset of field: rte_thash_tuple::v4", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) + "Offset of field: rte_thash_tuple::v6", ); } impl Clone for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs b/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs index f4312a115a8b1021fad47d09fdd2d4faebec8cd0..ed893c21dfaba2867c208796134a82251591bfcb 100644 --- a/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs +++ b/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct std_allocator_traits { diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 49693692e49e026136998a6cc080b32931cedabf..13132f9c4553f4d8f5cafb1e80dbc77ed90afe2d 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "fastcall" { pub fn foo(); } @@ -14,3 +8,8 @@ extern "stdcall" { extern "C" { pub fn baz(); } +extern "system" { + pub fn qux(); +} +pub type boo = ::std::option::Option; +pub type foobar = ::std::option::Option; diff --git a/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs new file mode 100644 index 0000000000000000000000000000000000000000..3cb7248c93f265c442863d1d5825f54d2128ac31 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs @@ -0,0 +1,5 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + #[link_name = "\u{1}_Z1bcz"] + pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; +} diff --git a/bindgen-tests/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs index 05fdaf4ca5944146f29aabe4d2cf84cb45c13a25..586edf2d791f6bf840bd4bf5fdceafb768eda140 100644 --- a/bindgen-tests/tests/expectations/tests/accessors.rs +++ b/bindgen-tests/tests/expectations/tests/accessors.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct SomeAccessors { @@ -16,72 +10,23 @@ pub struct SomeAccessors { ///
pub mImmutableAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_SomeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(SomeAccessors)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SomeAccessors)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mNoAccessor) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of SomeAccessors"][::std::mem::size_of::() - 16usize]; + ["Alignment of SomeAccessors"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: SomeAccessors::mNoAccessor", + ][::std::mem::offset_of!(SomeAccessors, mNoAccessor) - 0usize]; + [ + "Offset of field: SomeAccessors::mBothAccessors", + ][::std::mem::offset_of!(SomeAccessors, mBothAccessors) - 4usize]; + [ + "Offset of field: SomeAccessors::mUnsafeAccessors", + ][::std::mem::offset_of!(SomeAccessors, mUnsafeAccessors) - 8usize]; + [ + "Offset of field: SomeAccessors::mImmutableAccessor", + ][::std::mem::offset_of!(SomeAccessors, mImmutableAccessor) - 12usize]; +}; impl SomeAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -96,9 +41,7 @@ impl SomeAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -113,47 +56,17 @@ pub struct AllAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllAccessors)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllAccessors)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllAccessors"][::std::mem::size_of::() - 8usize]; + ["Alignment of AllAccessors"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllAccessors::mBothAccessors", + ][::std::mem::offset_of!(AllAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: AllAccessors::mAlsoBothAccessors", + ][::std::mem::offset_of!(AllAccessors, mAlsoBothAccessors) - 4usize]; +}; impl AllAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -179,56 +92,26 @@ pub struct AllUnsafeAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllUnsafeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllUnsafeAccessors)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllUnsafeAccessors)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllUnsafeAccessors"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of AllUnsafeAccessors", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllUnsafeAccessors::mBothAccessors", + ][::std::mem::offset_of!(AllUnsafeAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: AllUnsafeAccessors::mAlsoBothAccessors", + ][::std::mem::offset_of!(AllUnsafeAccessors, mAlsoBothAccessors) - 4usize]; +}; impl AllUnsafeAccessors { #[inline] pub unsafe fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { &self.mBothAccessors } #[inline] - pub unsafe fn get_mBothAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mBothAccessors } #[inline] @@ -236,9 +119,7 @@ impl AllUnsafeAccessors { &self.mAlsoBothAccessors } #[inline] - pub unsafe fn get_mAlsoBothAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mAlsoBothAccessors } } @@ -254,72 +135,27 @@ pub struct ContradictAccessors { ///
pub mImmutableAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContradictAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ContradictAccessors)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContradictAccessors)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mNoAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContradictAccessors", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of ContradictAccessors", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContradictAccessors::mBothAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: ContradictAccessors::mNoAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mNoAccessors) - 4usize]; + [ + "Offset of field: ContradictAccessors::mUnsafeAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mUnsafeAccessors) - 8usize]; + [ + "Offset of field: ContradictAccessors::mImmutableAccessor", + ][::std::mem::offset_of!(ContradictAccessors, mImmutableAccessor) - 12usize]; +}; impl ContradictAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -334,9 +170,7 @@ impl ContradictAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -350,34 +184,14 @@ impl ContradictAccessors { pub struct Replaced { pub mAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Replaced() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Replaced)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Replaced)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Replaced), - "::", - stringify!(mAccessor) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Replaced"][::std::mem::size_of::() - 4usize]; + ["Alignment of Replaced"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Replaced::mAccessor", + ][::std::mem::offset_of!(Replaced, mAccessor) - 0usize]; +}; impl Replaced { #[inline] pub fn get_mAccessor(&self) -> &::std::os::raw::c_int { @@ -394,34 +208,14 @@ impl Replaced { pub struct Wrapper { pub mReplaced: Replaced, } -#[test] -fn bindgen_test_layout_Wrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Wrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Wrapper)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Wrapper), - "::", - stringify!(mReplaced) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Wrapper"][::std::mem::size_of::() - 4usize]; + ["Alignment of Wrapper"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Wrapper::mReplaced", + ][::std::mem::offset_of!(Wrapper, mReplaced) - 0usize]; +}; impl Wrapper { #[inline] pub fn get_mReplaced(&self) -> &Replaced { diff --git a/bindgen-tests/tests/expectations/tests/alias_comments.rs b/bindgen-tests/tests/expectations/tests/alias_comments.rs new file mode 100644 index 0000000000000000000000000000000000000000..31ff72b2c6a5d3c17e84f7fb8c4dadb945525e20 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/alias_comments.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/// This is Struct +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Struct { + /// This is field + pub field: ::std::os::raw::c_int, +} +/// This is AliasToStruct +pub type AliasToStruct = Struct; +/// This is AliasToInt +pub type AliasToInt = ::std::os::raw::c_int; +/// This is AliasToAliasToInt +pub type AliasToAliasToInt = AliasToInt; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 3b72fb75ebf9d426d76b7fd909e2147a23b4651f..a0053653f3c1cebe3713370800d6f19435df0746 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const SOME_DEFUN: u32 = 123; extern "C" { #[link_name = "\u{1}_Z12SomeFunctionv"] @@ -18,25 +12,14 @@ extern "C" { pub struct someClass { pub _address: u8, } -#[test] -fn bindgen_test_layout_someClass() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(someClass)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(someClass)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of someClass"][::std::mem::size_of::() - 1usize]; + ["Alignment of someClass"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"] - pub fn someClass_somePublicMethod( - this: *mut someClass, - foo: ::std::os::raw::c_int, - ); + pub fn someClass_somePublicMethod(this: *mut someClass, foo: ::std::os::raw::c_int); } impl someClass { #[inline] @@ -56,32 +39,18 @@ extern "C" { pub struct StructWithAllowlistedDefinition { pub other: *mut StructWithAllowlistedFwdDecl, } -#[test] -fn bindgen_test_layout_StructWithAllowlistedDefinition() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedDefinition), - "::", - stringify!(other) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of StructWithAllowlistedDefinition", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of StructWithAllowlistedDefinition", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: StructWithAllowlistedDefinition::other", + ][::std::mem::offset_of!(StructWithAllowlistedDefinition, other) - 0usize]; +}; impl Default for StructWithAllowlistedDefinition { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -96,60 +65,28 @@ impl Default for StructWithAllowlistedDefinition { pub struct StructWithAllowlistedFwdDecl { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedFwdDecl), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of StructWithAllowlistedFwdDecl", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of StructWithAllowlistedFwdDecl", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: StructWithAllowlistedFwdDecl::b", + ][::std::mem::offset_of!(StructWithAllowlistedFwdDecl, b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub foo: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistMe)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistMe)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(foo) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistMe::foo", + ][::std::mem::offset_of!(AllowlistMe, foo) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs index 36d03fefb5abb0db281539d8feb39fa8ee762754..151d03f4a4cc6f0bb3b8375ef15161ef9e1564d4 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -20,19 +14,11 @@ pub mod root { pub struct Helper { pub _address: u8, } - #[test] - fn bindgen_test_layout_Helper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Helper)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Helper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; + }; } } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs index ee9fe4283c71d28ce898fbec49b5339f598b7964..563c97ca1d8e6767e0238414b6941863566e75b1 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -20,52 +14,24 @@ pub mod root { pub struct Helper { pub _address: u8, } - #[test] - fn bindgen_test_layout_Helper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Helper)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Helper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; + }; } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub helper: root::outer::inner::Helper, } - #[test] - fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(helper) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Test::helper", + ][::std::mem::offset_of!(Test, helper) - 0usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs index 5bfe42e8707a08dd5f0f29c680a6e78e32d48a4c..a1c6919739dcd7982f8ec45759eb7b865e0e7aa3 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs @@ -1,22 +1,16 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct AllowlistMe { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: ::std::os::raw::c_int, pub bar: AllowlistMe_Inner, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct AllowlistMe_Inner { - pub bar: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub bar: T, } impl Default for AllowlistMe_Inner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs index 9cff795bd658475ffb0dc86267da11e1e7ccb10b..e3ce7bc100ac5bddd6d184d1a227700e89beabb6 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub enum Test {} - extern "C" { pub fn Servo_Test(a: *mut Test); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_item.rs b/bindgen-tests/tests/expectations/tests/allowlist_item.rs new file mode 100644 index 0000000000000000000000000000000000000000..e5aa4b21723bfff49d6f3a529c91168ea4a0e822 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/allowlist_item.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FooDefault: u32 = 0; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub field: ::std::os::raw::c_int, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::field"][::std::mem::offset_of!(Foo, field) - 0usize]; +}; +extern "C" { + pub fn FooNew(value: ::std::os::raw::c_int) -> Foo; +} diff --git a/bindgen-tests/tests/expectations/tests/allowlist_vars.rs b/bindgen-tests/tests/expectations/tests/allowlist_vars.rs index 590cbafcfa0a2365415718298776d4ad6bc7bec5..342d904a7361519b74c11b1ac750175500e172c1 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_vars.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_vars.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NONE: u32 = 0; pub const FOO: u32 = 5; pub const FOOB: i32 = -2; diff --git a/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs b/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs index 56dc5bce30516347e400c308485a6ff44e1f1aca..6c1d13a837a3550b18b5e1d750fd87a6d58bcffc 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -1,56 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoHash() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoHash)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoHash)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub a: NoHash, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 36cdda0e8fe369b97a8125fa81c364919cce467b..b969727dbbfa28181bed6e749a237cc088f21d85 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -1,56 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoPartialEq)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoPartialEq)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub a: NoPartialEq, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 625e0ce6fd0e481251baf8b2cb12e3eab8e79eaa..8c671b4e84384468c4dd8a7ac0e185dfe339c9ea 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -1,56 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct NoCopy { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoCopy() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoCopy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoCopy)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct AllowlistMe { pub a: NoCopy, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs index a90c4261e8cfd005d1a5318599609791d67de385..e79c88214db529a0f0583acd0c5b5c80ab1d9fbd 100644 --- a/bindgen-tests/tests/expectations/tests/annotation_hide.rs +++ b/bindgen-tests/tests/expectations/tests/annotation_hide.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[repr(align(4))] @@ -12,47 +6,21 @@ pub struct D { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_D() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of D"][::std::mem::size_of::() - 4usize]; + ["Alignment of D"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotAnnotated { pub f: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NotAnnotated() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NotAnnotated)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NotAnnotated)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotAnnotated), - "::", - stringify!(f) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NotAnnotated"][::std::mem::size_of::() - 4usize]; + ["Alignment of NotAnnotated"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NotAnnotated::f", + ][::std::mem::offset_of!(NotAnnotated, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs index d09cab4044869c87f6ea5654c10d6fdc2ac7149c..2b96804c9b05299ea6204d4139aa934815d0a69e 100644 --- a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union color { @@ -19,52 +13,24 @@ pub struct color__bindgen_ty_1 { pub g: ::std::os::raw::c_uchar, pub b: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_color__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of color__bindgen_ty_1", + ][::std::mem::size_of::() - 3usize]; + [ + "Alignment of color__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: color__bindgen_ty_1::r", + ][::std::mem::offset_of!(color__bindgen_ty_1, r) - 0usize]; + [ + "Offset of field: color__bindgen_ty_1::g", + ][::std::mem::offset_of!(color__bindgen_ty_1, g) - 1usize]; + [ + "Offset of field: color__bindgen_ty_1::b", + ][::std::mem::offset_of!(color__bindgen_ty_1, b) - 2usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct color__bindgen_ty_2 { @@ -72,73 +38,30 @@ pub struct color__bindgen_ty_2 { pub u: ::std::os::raw::c_uchar, pub v: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_color__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(y) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(u) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(v) - ) - ); -} -#[test] -fn bindgen_test_layout_color() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of color__bindgen_ty_2", + ][::std::mem::size_of::() - 3usize]; + [ + "Alignment of color__bindgen_ty_2", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: color__bindgen_ty_2::y", + ][::std::mem::offset_of!(color__bindgen_ty_2, y) - 0usize]; + [ + "Offset of field: color__bindgen_ty_2::u", + ][::std::mem::offset_of!(color__bindgen_ty_2, u) - 1usize]; + [ + "Offset of field: color__bindgen_ty_2::v", + ][::std::mem::offset_of!(color__bindgen_ty_2, v) - 2usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of color"][::std::mem::size_of::() - 3usize]; + ["Alignment of color"][::std::mem::align_of::() - 1usize]; + ["Offset of field: color::v3"][::std::mem::offset_of!(color, v3) - 0usize]; +}; impl Default for color { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index 429f94cedbd30fa8e7ed19533aa56ed5fae53ada..c3790a2a248006f008a9da4a8e0ccd0fd5a10275 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct Test { @@ -17,32 +11,13 @@ pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; pub enum Test__bindgen_ty_1 { T_NONE = 0, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 8usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; + ["Offset of field: Test::bar"][::std::mem::offset_of!(Test, bar) - 4usize]; +}; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Baz { diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs index f0c06c5634c194bd385ed7fc3ef690deeac8c5fb..4b172d7aeb0a5881fc6624c91f8870145bfbb34d 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs new file mode 100644 index 0000000000000000000000000000000000000000..4d28c3abc79f7b6da8718ae407c0562a15cb9730 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const NODE_FLAG_FOO: _bindgen_ty_1 = 0; +pub const NODE_FLAG_BAR: _bindgen_ty_1 = 1; +pub type _bindgen_ty_1 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs new file mode 100644 index 0000000000000000000000000000000000000000..28ab3ad7864c93a7f7432c76ec58a9aac339616e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FLAG_Z: _bindgen_ty_2 = 0; +pub const FLAG_W: _bindgen_ty_2 = 1; +pub type _bindgen_ty_2 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index 9d6b8f574ad6be1a15932436fb5e4cda99e28361..cfd4d032007abb5c922a1cf40ca28af2bb373418 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct DataType { @@ -14,16 +8,11 @@ pub type DataType_value_type<_Tp> = _Tp; pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>; -pub const DataType_generic_type: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_depth: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_channels: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_fmt: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_type_: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; +pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum DataType__bindgen_ty_1 { @@ -41,16 +30,8 @@ pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub enum Foo__bindgen_ty_1 { Bar = 0, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs index f32b057b271785c30e69dc159bd82fee1cd6f6ab..dceca1adf343de33fafbb5f7d3645be963735c9c 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct s { @@ -20,58 +14,26 @@ pub union s__bindgen_ty_1 { pub struct s__bindgen_ty_1_inner { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of s__bindgen_ty_1_inner", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of s__bindgen_ty_1_inner", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: s__bindgen_ty_1_inner::b", + ][::std::mem::offset_of!(s__bindgen_ty_1_inner, b) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of s__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + ["Alignment of s__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: s__bindgen_ty_1::field", + ][::std::mem::offset_of!(s__bindgen_ty_1, field) - 0usize]; +}; impl Default for s__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -81,27 +43,12 @@ impl Default for s__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_s() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of s"][::std::mem::size_of::() - 4usize]; + ["Alignment of s"][::std::mem::align_of::() - 4usize]; + ["Offset of field: s::u"][::std::mem::offset_of!(s, u) - 0usize]; +}; impl Default for s { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index cbc5ac9b3f6825f337ebcc320cc8b4afb9921907..5a6e3ca47736d747b60f045a30583cbeb7c7f968 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -66,28 +60,22 @@ pub struct s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)) + "Size of s__bindgen_ty_1_inner", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) + "Alignment of s__bindgen_ty_1_inner", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) + "Offset of field: s__bindgen_ty_1_inner::b", ); } impl Clone for s__bindgen_ty_1_inner { @@ -97,28 +85,22 @@ impl Clone for s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)) + "Size of s__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)) + "Alignment of s__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) + "Offset of field: s__bindgen_ty_1::field", ); } impl Clone for s__bindgen_ty_1 { @@ -128,23 +110,14 @@ impl Clone for s__bindgen_ty_1 { } #[test] fn bindgen_test_layout_s() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of s"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of s"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + "Offset of field: s::u", ); } impl Clone for s { diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index 8caf7d110d5abc709fb4528d7f5d68391466c812..d9bf3cf18356a87ca437ac05797e79e776051eb6 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, @@ -13,8 +7,7 @@ pub struct TErrorResult { pub mUnionState: TErrorResult_UnionState, } impl TErrorResult_UnionState { - pub const HasException: TErrorResult_UnionState = - TErrorResult_UnionState::HasMessage; + pub const HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -58,19 +51,11 @@ impl Default for TErrorResult { pub struct ErrorResult { pub _base: TErrorResult, } -#[test] -fn bindgen_test_layout_ErrorResult() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ErrorResult)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ErrorResult"][::std::mem::size_of::() - 24usize]; + ["Alignment of ErrorResult"][::std::mem::align_of::() - 8usize]; +}; impl Default for ErrorResult { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -80,22 +65,12 @@ impl Default for ErrorResult { } } } -#[test] -fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(TErrorResult) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(TErrorResult) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: TErrorResult_open0_int_close0", + ][::std::mem::size_of::() - 24usize]; + [ + "Align of template specialization: TErrorResult_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 63273e608f6017849ffa52820196706a2d2e5245..29b13d010d4883ad1d6802f61a41aefe327158c1 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -56,8 +50,7 @@ pub struct TErrorResult { pub mMightHaveUnreported: bool, pub mUnionState: TErrorResult_UnionState, } -pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = - TErrorResult_UnionState::HasMessage; +pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { @@ -77,8 +70,7 @@ pub struct TErrorResult_DOMExceptionInfo { #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: - __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, } impl Default for TErrorResult { @@ -97,15 +89,11 @@ pub struct ErrorResult { } #[test] fn bindgen_test_layout_ErrorResult() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)) - ); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of ErrorResult"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ErrorResult)) + "Alignment of ErrorResult", ); } impl Clone for ErrorResult { @@ -127,17 +115,11 @@ fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( ::std::mem::size_of::(), 24usize, - concat!( - "Size of template specialization: ", - stringify!(TErrorResult) - ) + "Size of template specialization: TErrorResult_open0_int_close0", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(TErrorResult) - ) + "Align of template specialization: TErrorResult_open0_int_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs index 14afd6b3160d75f0a3d3973c6614e93b67de8f5b..f6c894d8b55f429dac5f894a6fb1b2cc21f083f2 100644 --- a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs +++ b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { - pub t_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t_member: T, } impl Default for Foo { fn default() -> Self { @@ -28,8 +22,8 @@ pub struct Bar { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Quux { - pub v_member: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub v_member: V, } impl Default for Quux { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/arg_keyword.rs b/bindgen-tests/tests/expectations/tests/arg_keyword.rs index 43ff58313d00f2ce5044bc55ad16a26023a0d13c..e7dd10b0488ed60924ce98bea36081aecc4c8d40 100644 --- a/bindgen-tests/tests/expectations/tests/arg_keyword.rs +++ b/bindgen-tests/tests/expectations/tests/arg_keyword.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooPKc"] pub fn foo(type_: *const ::std::os::raw::c_char); diff --git a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs index ad1f22ed1fccfc07ac1b0ba6b18d7c7c949168cb..4630abd275ca65c5bd325c025a6f7b4d5ab74203 100644 --- a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs @@ -1,59 +1,27 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This should get an `_address` byte. #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)) - ); -} -/// This should not get an `_address` byte, since each `Empty` gets one, meaning -/// that this object is addressable. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; +}; +/** This should not get an `_address` byte, since each `Empty` gets one, meaning + that this object is addressable.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasArrayOfEmpty { pub empties: [Empty; 10usize], } -#[test] -fn bindgen_test_layout_HasArrayOfEmpty() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(HasArrayOfEmpty)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(HasArrayOfEmpty)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasArrayOfEmpty), - "::", - stringify!(empties) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of HasArrayOfEmpty"][::std::mem::size_of::() - 10usize]; + ["Alignment of HasArrayOfEmpty"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: HasArrayOfEmpty::empties", + ][::std::mem::offset_of!(HasArrayOfEmpty, empties) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs index 12d5eab04b4e6bc69de3774bde30688328c7bdc0..07eb7a80f61cd2ca181e0b9e03cdcebf0c4c07fc 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -12,32 +6,18 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } extern "C" { #[must_use] #[link_name = "\u{1}_ZN3Foo3fooEi"] - pub fn Foo_foo( - this: *mut Foo, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] #[must_use] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index d860acd1b48a7fb0ec4bd214e70acfbbf2c5fa88..aa01540b0e11f50909421fe91e55809930e8358f 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -12,30 +6,16 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEi"] - pub fn Foo_foo( - this: *mut Foo, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index d860acd1b48a7fb0ec4bd214e70acfbbf2c5fa88..f545f9e6bb88a31b96f895494661d690101c88c2 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -1,41 +1,21 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEi"] - pub fn Foo_foo( - this: *mut Foo, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } diff --git a/bindgen-tests/tests/expectations/tests/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs new file mode 100644 index 0000000000000000000000000000000000000000..0173f0409f72ba10625062d76ced8210b9c9b6ac --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/auto.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +pub const Foo_kFoo: bool = true; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_Z5Test2v"] + pub fn Test2() -> ::std::os::raw::c_uint; +} diff --git a/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 4d0d6bcd18ba6da90f75b75c83e34e6b6c96de6c..9ad8429e3cfd5b627df5325757fe0d3eab84911e 100644 --- a/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct std_char_traits { diff --git a/bindgen-tests/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs index 97830cd4fb95c2d2d3ac56058c591352c4772a22..22ef4fdb081085e96e4687cd95a3b3110aac5c30 100644 --- a/bindgen-tests/tests/expectations/tests/base-to-derived.rs +++ b/bindgen-tests/tests/expectations/tests/base-to-derived.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct false_type { pub _address: u8, } -#[test] -fn bindgen_test_layout_false_type() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(false_type)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(false_type)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of false_type"][::std::mem::size_of::() - 1usize]; + ["Alignment of false_type"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs index 8a091cb5e2c60228091e11c0a1b8d4b642d772db..70f9216a68b4c6178910c201adf84697fa1f2c5f 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[repr(C)] @@ -32,15 +26,12 @@ pub mod root { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt( - &self, - fmt: &mut ::std::fmt::Formatter<'_>, - ) -> ::std::fmt::Result { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } @@ -67,42 +58,19 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Bar"); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) + "Offset of field: Bar::foo", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bar) - ) + "Offset of field: Bar::bar", ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 680b25d8fdb9a9e110e937c9a1d7883f11501e75..475cbae83771607512ead0a81afbf3a93e008c81 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,31 +83,21 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct MuchBitfield { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, } -#[test] -fn bindgen_test_layout_MuchBitfield() { - assert_eq!( - ::std::mem::size_of::(), - 5usize, - concat!("Size of: ", stringify!(MuchBitfield)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MuchBitfield)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of MuchBitfield"][::std::mem::size_of::() - 5usize]; + ["Alignment of MuchBitfield"][::std::mem::align_of::() - 1usize]; +}; impl MuchBitfield { #[inline] pub fn m0(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_m0(&mut self, val: ::std::os::raw::c_char) { @@ -126,9 +108,7 @@ impl MuchBitfield { } #[inline] pub fn m1(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_m1(&mut self, val: ::std::os::raw::c_char) { @@ -139,9 +119,7 @@ impl MuchBitfield { } #[inline] pub fn m2(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_m2(&mut self, val: ::std::os::raw::c_char) { @@ -152,9 +130,7 @@ impl MuchBitfield { } #[inline] pub fn m3(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u8) } } #[inline] pub fn set_m3(&mut self, val: ::std::os::raw::c_char) { @@ -165,9 +141,7 @@ impl MuchBitfield { } #[inline] pub fn m4(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u8) } } #[inline] pub fn set_m4(&mut self, val: ::std::os::raw::c_char) { @@ -178,9 +152,7 @@ impl MuchBitfield { } #[inline] pub fn m5(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u8) } } #[inline] pub fn set_m5(&mut self, val: ::std::os::raw::c_char) { @@ -191,9 +163,7 @@ impl MuchBitfield { } #[inline] pub fn m6(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u8) } } #[inline] pub fn set_m6(&mut self, val: ::std::os::raw::c_char) { @@ -204,9 +174,7 @@ impl MuchBitfield { } #[inline] pub fn m7(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u8) } } #[inline] pub fn set_m7(&mut self, val: ::std::os::raw::c_char) { @@ -217,9 +185,7 @@ impl MuchBitfield { } #[inline] pub fn m8(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u8) } } #[inline] pub fn set_m8(&mut self, val: ::std::os::raw::c_char) { @@ -230,9 +196,7 @@ impl MuchBitfield { } #[inline] pub fn m9(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u8) } } #[inline] pub fn set_m9(&mut self, val: ::std::os::raw::c_char) { @@ -243,9 +207,7 @@ impl MuchBitfield { } #[inline] pub fn m10(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u8) } } #[inline] pub fn set_m10(&mut self, val: ::std::os::raw::c_char) { @@ -256,9 +218,7 @@ impl MuchBitfield { } #[inline] pub fn m11(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) } } #[inline] pub fn set_m11(&mut self, val: ::std::os::raw::c_char) { @@ -269,9 +229,7 @@ impl MuchBitfield { } #[inline] pub fn m12(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u8) } } #[inline] pub fn set_m12(&mut self, val: ::std::os::raw::c_char) { @@ -282,9 +240,7 @@ impl MuchBitfield { } #[inline] pub fn m13(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u8) } } #[inline] pub fn set_m13(&mut self, val: ::std::os::raw::c_char) { @@ -295,9 +251,7 @@ impl MuchBitfield { } #[inline] pub fn m14(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) } } #[inline] pub fn set_m14(&mut self, val: ::std::os::raw::c_char) { @@ -308,9 +262,7 @@ impl MuchBitfield { } #[inline] pub fn m15(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) } } #[inline] pub fn set_m15(&mut self, val: ::std::os::raw::c_char) { @@ -321,9 +273,7 @@ impl MuchBitfield { } #[inline] pub fn m16(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u8) } } #[inline] pub fn set_m16(&mut self, val: ::std::os::raw::c_char) { @@ -334,9 +284,7 @@ impl MuchBitfield { } #[inline] pub fn m17(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u8) } } #[inline] pub fn set_m17(&mut self, val: ::std::os::raw::c_char) { @@ -347,9 +295,7 @@ impl MuchBitfield { } #[inline] pub fn m18(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u8) } } #[inline] pub fn set_m18(&mut self, val: ::std::os::raw::c_char) { @@ -360,9 +306,7 @@ impl MuchBitfield { } #[inline] pub fn m19(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u8) } } #[inline] pub fn set_m19(&mut self, val: ::std::os::raw::c_char) { @@ -373,9 +317,7 @@ impl MuchBitfield { } #[inline] pub fn m20(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u8) } } #[inline] pub fn set_m20(&mut self, val: ::std::os::raw::c_char) { @@ -386,9 +328,7 @@ impl MuchBitfield { } #[inline] pub fn m21(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u8) } } #[inline] pub fn set_m21(&mut self, val: ::std::os::raw::c_char) { @@ -399,9 +339,7 @@ impl MuchBitfield { } #[inline] pub fn m22(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u8) } } #[inline] pub fn set_m22(&mut self, val: ::std::os::raw::c_char) { @@ -412,9 +350,7 @@ impl MuchBitfield { } #[inline] pub fn m23(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u8) } } #[inline] pub fn set_m23(&mut self, val: ::std::os::raw::c_char) { @@ -425,9 +361,7 @@ impl MuchBitfield { } #[inline] pub fn m24(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u8) } } #[inline] pub fn set_m24(&mut self, val: ::std::os::raw::c_char) { @@ -438,9 +372,7 @@ impl MuchBitfield { } #[inline] pub fn m25(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u8) } } #[inline] pub fn set_m25(&mut self, val: ::std::os::raw::c_char) { @@ -451,9 +383,7 @@ impl MuchBitfield { } #[inline] pub fn m26(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u8) } } #[inline] pub fn set_m26(&mut self, val: ::std::os::raw::c_char) { @@ -464,9 +394,7 @@ impl MuchBitfield { } #[inline] pub fn m27(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u8) } } #[inline] pub fn set_m27(&mut self, val: ::std::os::raw::c_char) { @@ -477,9 +405,7 @@ impl MuchBitfield { } #[inline] pub fn m28(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u8) } } #[inline] pub fn set_m28(&mut self, val: ::std::os::raw::c_char) { @@ -490,9 +416,7 @@ impl MuchBitfield { } #[inline] pub fn m29(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u8) } } #[inline] pub fn set_m29(&mut self, val: ::std::os::raw::c_char) { @@ -503,9 +427,7 @@ impl MuchBitfield { } #[inline] pub fn m30(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u8) } } #[inline] pub fn set_m30(&mut self, val: ::std::os::raw::c_char) { @@ -516,9 +438,7 @@ impl MuchBitfield { } #[inline] pub fn m31(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_m31(&mut self, val: ::std::os::raw::c_char) { @@ -529,9 +449,7 @@ impl MuchBitfield { } #[inline] pub fn m32(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u8) } } #[inline] pub fn set_m32(&mut self, val: ::std::os::raw::c_char) { @@ -576,140 +494,304 @@ impl MuchBitfield { m31: ::std::os::raw::c_char, m32: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 5usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let m0: u8 = unsafe { ::std::mem::transmute(m0) }; - m0 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let m1: u8 = unsafe { ::std::mem::transmute(m1) }; - m1 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let m2: u8 = unsafe { ::std::mem::transmute(m2) }; - m2 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let m3: u8 = unsafe { ::std::mem::transmute(m3) }; - m3 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let m4: u8 = unsafe { ::std::mem::transmute(m4) }; - m4 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let m5: u8 = unsafe { ::std::mem::transmute(m5) }; - m5 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let m6: u8 = unsafe { ::std::mem::transmute(m6) }; - m6 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let m7: u8 = unsafe { ::std::mem::transmute(m7) }; - m7 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let m8: u8 = unsafe { ::std::mem::transmute(m8) }; - m8 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let m9: u8 = unsafe { ::std::mem::transmute(m9) }; - m9 as u64 - }); - __bindgen_bitfield_unit.set(10usize, 1u8, { - let m10: u8 = unsafe { ::std::mem::transmute(m10) }; - m10 as u64 - }); - __bindgen_bitfield_unit.set(11usize, 1u8, { - let m11: u8 = unsafe { ::std::mem::transmute(m11) }; - m11 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 1u8, { - let m12: u8 = unsafe { ::std::mem::transmute(m12) }; - m12 as u64 - }); - __bindgen_bitfield_unit.set(13usize, 1u8, { - let m13: u8 = unsafe { ::std::mem::transmute(m13) }; - m13 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 1u8, { - let m14: u8 = unsafe { ::std::mem::transmute(m14) }; - m14 as u64 - }); - __bindgen_bitfield_unit.set(15usize, 1u8, { - let m15: u8 = unsafe { ::std::mem::transmute(m15) }; - m15 as u64 - }); - __bindgen_bitfield_unit.set(16usize, 1u8, { - let m16: u8 = unsafe { ::std::mem::transmute(m16) }; - m16 as u64 - }); - __bindgen_bitfield_unit.set(17usize, 1u8, { - let m17: u8 = unsafe { ::std::mem::transmute(m17) }; - m17 as u64 - }); - __bindgen_bitfield_unit.set(18usize, 1u8, { - let m18: u8 = unsafe { ::std::mem::transmute(m18) }; - m18 as u64 - }); - __bindgen_bitfield_unit.set(19usize, 1u8, { - let m19: u8 = unsafe { ::std::mem::transmute(m19) }; - m19 as u64 - }); - __bindgen_bitfield_unit.set(20usize, 1u8, { - let m20: u8 = unsafe { ::std::mem::transmute(m20) }; - m20 as u64 - }); - __bindgen_bitfield_unit.set(21usize, 1u8, { - let m21: u8 = unsafe { ::std::mem::transmute(m21) }; - m21 as u64 - }); - __bindgen_bitfield_unit.set(22usize, 1u8, { - let m22: u8 = unsafe { ::std::mem::transmute(m22) }; - m22 as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let m23: u8 = unsafe { ::std::mem::transmute(m23) }; - m23 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 1u8, { - let m24: u8 = unsafe { ::std::mem::transmute(m24) }; - m24 as u64 - }); - __bindgen_bitfield_unit.set(25usize, 1u8, { - let m25: u8 = unsafe { ::std::mem::transmute(m25) }; - m25 as u64 - }); - __bindgen_bitfield_unit.set(26usize, 1u8, { - let m26: u8 = unsafe { ::std::mem::transmute(m26) }; - m26 as u64 - }); - __bindgen_bitfield_unit.set(27usize, 1u8, { - let m27: u8 = unsafe { ::std::mem::transmute(m27) }; - m27 as u64 - }); - __bindgen_bitfield_unit.set(28usize, 1u8, { - let m28: u8 = unsafe { ::std::mem::transmute(m28) }; - m28 as u64 - }); - __bindgen_bitfield_unit.set(29usize, 1u8, { - let m29: u8 = unsafe { ::std::mem::transmute(m29) }; - m29 as u64 - }); - __bindgen_bitfield_unit.set(30usize, 1u8, { - let m30: u8 = unsafe { ::std::mem::transmute(m30) }; - m30 as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let m31: u8 = unsafe { ::std::mem::transmute(m31) }; - m31 as u64 - }); - __bindgen_bitfield_unit.set(32usize, 1u8, { - let m32: u8 = unsafe { ::std::mem::transmute(m32) }; - m32 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let m0: u8 = unsafe { ::std::mem::transmute(m0) }; + m0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let m1: u8 = unsafe { ::std::mem::transmute(m1) }; + m1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let m2: u8 = unsafe { ::std::mem::transmute(m2) }; + m2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let m3: u8 = unsafe { ::std::mem::transmute(m3) }; + m3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let m4: u8 = unsafe { ::std::mem::transmute(m4) }; + m4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let m5: u8 = unsafe { ::std::mem::transmute(m5) }; + m5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let m6: u8 = unsafe { ::std::mem::transmute(m6) }; + m6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let m7: u8 = unsafe { ::std::mem::transmute(m7) }; + m7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let m8: u8 = unsafe { ::std::mem::transmute(m8) }; + m8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let m9: u8 = unsafe { ::std::mem::transmute(m9) }; + m9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 1u8, + { + let m10: u8 = unsafe { ::std::mem::transmute(m10) }; + m10 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 11usize, + 1u8, + { + let m11: u8 = unsafe { ::std::mem::transmute(m11) }; + m11 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 1u8, + { + let m12: u8 = unsafe { ::std::mem::transmute(m12) }; + m12 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 13usize, + 1u8, + { + let m13: u8 = unsafe { ::std::mem::transmute(m13) }; + m13 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 1u8, + { + let m14: u8 = unsafe { ::std::mem::transmute(m14) }; + m14 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 15usize, + 1u8, + { + let m15: u8 = unsafe { ::std::mem::transmute(m15) }; + m15 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 1u8, + { + let m16: u8 = unsafe { ::std::mem::transmute(m16) }; + m16 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 17usize, + 1u8, + { + let m17: u8 = unsafe { ::std::mem::transmute(m17) }; + m17 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 18usize, + 1u8, + { + let m18: u8 = unsafe { ::std::mem::transmute(m18) }; + m18 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 19usize, + 1u8, + { + let m19: u8 = unsafe { ::std::mem::transmute(m19) }; + m19 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 1u8, + { + let m20: u8 = unsafe { ::std::mem::transmute(m20) }; + m20 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 21usize, + 1u8, + { + let m21: u8 = unsafe { ::std::mem::transmute(m21) }; + m21 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 22usize, + 1u8, + { + let m22: u8 = unsafe { ::std::mem::transmute(m22) }; + m22 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let m23: u8 = unsafe { ::std::mem::transmute(m23) }; + m23 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 1u8, + { + let m24: u8 = unsafe { ::std::mem::transmute(m24) }; + m24 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 25usize, + 1u8, + { + let m25: u8 = unsafe { ::std::mem::transmute(m25) }; + m25 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 26usize, + 1u8, + { + let m26: u8 = unsafe { ::std::mem::transmute(m26) }; + m26 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 27usize, + 1u8, + { + let m27: u8 = unsafe { ::std::mem::transmute(m27) }; + m27 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 28usize, + 1u8, + { + let m28: u8 = unsafe { ::std::mem::transmute(m28) }; + m28 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 29usize, + 1u8, + { + let m29: u8 = unsafe { ::std::mem::transmute(m29) }; + m29 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 30usize, + 1u8, + { + let m30: u8 = unsafe { ::std::mem::transmute(m30) }; + m30 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let m31: u8 = unsafe { ::std::mem::transmute(m31) }; + m31 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 1u8, + { + let m32: u8 = unsafe { ::std::mem::transmute(m32) }; + m32 as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index b6c25870b00ba6822fa99456c66198e358a455c2..adc4690c86e4d08c092e2b23e8aaa7e11cab5b25 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } @@ -154,16 +148,8 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); -#[test] -fn bindgen_test_layout_Dummy() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Dummy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Dummy)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Dummy"][::std::mem::size_of::() - 1usize]; + ["Alignment of Dummy"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs index 1f0228e8e644c78313c7d6bda3c8c13cfd8ed665..0403e844e2b798f27f5486e46bba927b3960f3c8 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 53e113ed5e4edb3e12eadb5f22953ec1591c21e7..0b5202dfe3358c98e1c606900a05aadf241f7be9 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index b2c353a2212f87446f3fe7b143cea7d799b87edc..27118083d54f982168848c6028a46762633f7229 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,25 +90,15 @@ pub struct HasBigBitfield { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_HasBigBitfield() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(HasBigBitfield)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of HasBigBitfield"][::std::mem::size_of::() - 16usize]; + ["Alignment of HasBigBitfield"][::std::mem::align_of::() - 16usize]; +}; impl HasBigBitfield { #[inline] pub fn x(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) } } #[inline] pub fn set_x(&mut self, val: i128) { @@ -127,12 +109,16 @@ impl HasBigBitfield { } #[inline] pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 128u8, { - let x: u128 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 128u8, + { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); __bindgen_bitfield_unit } } @@ -143,25 +129,19 @@ pub struct HasTwoBigBitfields { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_HasTwoBigBitfields() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasTwoBigBitfields)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(HasTwoBigBitfields)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of HasTwoBigBitfields", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of HasTwoBigBitfields", + ][::std::mem::align_of::() - 16usize]; +}; impl HasTwoBigBitfields { #[inline] pub fn x(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) } } #[inline] pub fn set_x(&mut self, val: i128) { @@ -172,9 +152,7 @@ impl HasTwoBigBitfields { } #[inline] pub fn y(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) } } #[inline] pub fn set_y(&mut self, val: i128) { @@ -184,20 +162,26 @@ impl HasTwoBigBitfields { } } #[inline] - pub fn new_bitfield_1( - x: i128, - y: i128, - ) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 80u8, { - let x: u128 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); - __bindgen_bitfield_unit.set(80usize, 48u8, { - let y: u128 = unsafe { ::std::mem::transmute(y) }; - y as u64 - }); + pub fn new_bitfield_1(x: i128, y: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 80u8, + { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 80usize, + 48u8, + { + let y: u128 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 44c686265f06f4908f4e245c02f59a1ac1028e13..9e69bf9de592d59af38fd3eef7b6234703672066 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,33 +90,16 @@ pub struct Test { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 16usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; +}; impl Test { #[inline] pub fn x(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) } } #[inline] pub fn set_x(&mut self, val: u64) { @@ -135,9 +110,7 @@ impl Test { } #[inline] pub fn y(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) } } #[inline] pub fn set_y(&mut self, val: u64) { @@ -147,20 +120,26 @@ impl Test { } } #[inline] - pub fn new_bitfield_1( - x: u64, - y: u64, - ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 56u8, { - let x: u64 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); - __bindgen_bitfield_unit.set(56usize, 8u8, { - let y: u64 = unsafe { ::std::mem::transmute(y) }; - y as u64 - }); + pub fn new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 56u8, + { + let x: u64 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 56usize, + 8u8, + { + let y: u64 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index e9c1a76d1ceba55c8772f4c3c0fdec5c9827f9b4..dd4286496ca4927a76ac3b21f40769128e614d32 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,25 +83,17 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char; @@ -125,9 +109,7 @@ extern "C" { impl Foo { #[inline] pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } } #[inline] pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) { @@ -140,13 +122,18 @@ impl Foo { pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let type__bindgen_bitfield: u8 = unsafe { + ::std::mem::transmute(type__bindgen_bitfield) + }; + type__bindgen_bitfield as u64 + }, + ); __bindgen_bitfield_unit } #[inline] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 4baca11214318569f9312f85aef726d230a3aafe..828f176de9d8e889c86bbd656a29deb884518456 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,38 +92,17 @@ pub struct A { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub y: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::x"][::std::mem::offset_of!(A, x) - 0usize]; + ["Offset of field: A::y"][::std::mem::offset_of!(A, y) - 3usize]; +}; impl A { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { @@ -142,9 +113,7 @@ impl A { } #[inline] pub fn b2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { @@ -155,9 +124,7 @@ impl A { } #[inline] pub fn b3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } #[inline] pub fn set_b3(&mut self, val: ::std::os::raw::c_uint) { @@ -168,9 +135,7 @@ impl A { } #[inline] pub fn b4(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } #[inline] pub fn set_b4(&mut self, val: ::std::os::raw::c_uint) { @@ -181,9 +146,7 @@ impl A { } #[inline] pub fn b5(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } #[inline] pub fn set_b5(&mut self, val: ::std::os::raw::c_uint) { @@ -194,9 +157,7 @@ impl A { } #[inline] pub fn b6(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } #[inline] pub fn set_b6(&mut self, val: ::std::os::raw::c_uint) { @@ -207,9 +168,7 @@ impl A { } #[inline] pub fn b7(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } #[inline] pub fn set_b7(&mut self, val: ::std::os::raw::c_uint) { @@ -220,9 +179,7 @@ impl A { } #[inline] pub fn b8(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } #[inline] pub fn set_b8(&mut self, val: ::std::os::raw::c_uint) { @@ -233,9 +190,7 @@ impl A { } #[inline] pub fn b9(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } #[inline] pub fn set_b9(&mut self, val: ::std::os::raw::c_uint) { @@ -246,9 +201,7 @@ impl A { } #[inline] pub fn b10(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } #[inline] pub fn set_b10(&mut self, val: ::std::os::raw::c_uint) { @@ -270,77 +223,115 @@ impl A { b9: ::std::os::raw::c_uint, b10: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let b1: u32 = unsafe { ::std::mem::transmute(b1) }; - b1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b2: u32 = unsafe { ::std::mem::transmute(b2) }; - b2 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let b3: u32 = unsafe { ::std::mem::transmute(b3) }; - b3 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let b4: u32 = unsafe { ::std::mem::transmute(b4) }; - b4 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let b5: u32 = unsafe { ::std::mem::transmute(b5) }; - b5 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let b6: u32 = unsafe { ::std::mem::transmute(b6) }; - b6 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let b7: u32 = unsafe { ::std::mem::transmute(b7) }; - b7 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let b8: u32 = unsafe { ::std::mem::transmute(b8) }; - b8 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let b9: u32 = unsafe { ::std::mem::transmute(b9) }; - b9 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let b10: u32 = unsafe { ::std::mem::transmute(b10) }; - b10 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b3: u32 = unsafe { ::std::mem::transmute(b3) }; + b3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let b4: u32 = unsafe { ::std::mem::transmute(b4) }; + b4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let b5: u32 = unsafe { ::std::mem::transmute(b5) }; + b5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let b6: u32 = unsafe { ::std::mem::transmute(b6) }; + b6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let b7: u32 = unsafe { ::std::mem::transmute(b7) }; + b7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let b8: u32 = unsafe { ::std::mem::transmute(b8) }; + b8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let b9: u32 = unsafe { ::std::mem::transmute(b9) }; + b9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let b10: u32 = unsafe { ::std::mem::transmute(b10) }; + b10 as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; +}; impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) { @@ -351,9 +342,7 @@ impl B { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { @@ -367,16 +356,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } @@ -388,38 +386,17 @@ pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::x"][::std::mem::offset_of!(C, x) - 0usize]; + ["Offset of field: C::baz"][::std::mem::offset_of!(C, baz) - 4usize]; +}; impl C { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { @@ -430,9 +407,7 @@ impl C { } #[inline] pub fn b2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { @@ -446,16 +421,25 @@ impl C { b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let b1: u32 = unsafe { ::std::mem::transmute(b1) }; - b1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b2: u32 = unsafe { ::std::mem::transmute(b2) }; - b2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); __bindgen_bitfield_unit } } @@ -467,25 +451,15 @@ pub struct Date1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub __bindgen_padding_0: u8, } -#[test] -fn bindgen_test_layout_Date1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Date1"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date1"][::std::mem::align_of::() - 2usize]; +}; impl Date1 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -496,9 +470,7 @@ impl Date1 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -509,9 +481,7 @@ impl Date1 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -522,9 +492,7 @@ impl Date1 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -540,24 +508,43 @@ impl Date1 { nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); __bindgen_bitfield_unit } } @@ -568,25 +555,15 @@ pub struct Date2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_Date2() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date2)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Date2"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date2"][::std::mem::align_of::() - 2usize]; +}; impl Date2 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -597,9 +574,7 @@ impl Date2 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -610,9 +585,7 @@ impl Date2 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -623,9 +596,7 @@ impl Date2 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -636,9 +607,7 @@ impl Date2 { } #[inline] pub fn byte(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } #[inline] pub fn set_byte(&mut self, val: ::std::os::raw::c_uchar) { @@ -655,28 +624,52 @@ impl Date2 { nYear: ::std::os::raw::c_ushort, byte: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let byte: u8 = unsafe { ::std::mem::transmute(byte) }; - byte as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let byte: u8 = unsafe { ::std::mem::transmute(byte) }; + byte as u64 + }, + ); __bindgen_bitfield_unit } } @@ -688,38 +681,16 @@ pub struct Date3 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub byte: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_Date3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date3)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date3)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Date3), - "::", - stringify!(byte) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Date3"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date3"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Date3::byte"][::std::mem::offset_of!(Date3, byte) - 3usize]; +}; impl Date3 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -730,9 +701,7 @@ impl Date3 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -743,9 +712,7 @@ impl Date3 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -756,9 +723,7 @@ impl Date3 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -774,24 +739,43 @@ impl Date3 { nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index aa11f80c51d798e715023f52e6b12c98cf9f1834..b87af0c99c3e77994efa11d5e183272bf24744ae 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -56,8 +50,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -77,8 +70,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,25 +93,16 @@ pub enum MyEnum { FOUR = 3, } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Copy, Clone)] pub struct TaggedPtr { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_TaggedPtr() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TaggedPtr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TaggedPtr)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TaggedPtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TaggedPtr"][::std::mem::align_of::() - 8usize]; +}; impl Default for TaggedPtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -132,9 +115,7 @@ impl Default for TaggedPtr { impl TaggedPtr { #[inline] pub fn tag(&self) -> MyEnum { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 2u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 2u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: MyEnum) { @@ -145,9 +126,7 @@ impl TaggedPtr { } #[inline] pub fn ptr(&self) -> ::std::os::raw::c_long { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 62u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 62u8) as u64) } } #[inline] pub fn set_ptr(&mut self, val: ::std::os::raw::c_long) { @@ -161,16 +140,25 @@ impl TaggedPtr { tag: MyEnum, ptr: ::std::os::raw::c_long, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 2u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); - __bindgen_bitfield_unit.set(2usize, 62u8, { - let ptr: u64 = unsafe { ::std::mem::transmute(ptr) }; - ptr as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 2u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 62u8, + { + let ptr: u64 = unsafe { ::std::mem::transmute(ptr) }; + ptr as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 4ee1f598444cd2cb50eac39664eca2df85dcffa2..8967bb98569bd5c89ceb9057d9b6e15ba75e8d33 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,29 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { pub _bindgen_opaque_blob: [u64; 10usize], } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 80usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 80usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; +}; extern "C" { pub static mut a: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 42fa3c4cb4b7c9ad8f3b6cb4c6a39ed32941dbd2..b6fe8a5257ce3904e27bf7ac9e421bd9e21f66c0 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,31 +84,24 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_mach_msg_type_descriptor_t() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(mach_msg_type_descriptor_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of mach_msg_type_descriptor_t", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of mach_msg_type_descriptor_t", + ][::std::mem::align_of::() - 4usize]; +}; impl mach_msg_type_descriptor_t { #[inline] pub fn pad3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) } } #[inline] pub fn set_pad3(&mut self, val: ::std::os::raw::c_uint) { @@ -127,9 +112,7 @@ impl mach_msg_type_descriptor_t { } #[inline] pub fn type_(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u32) } } #[inline] pub fn set_type(&mut self, val: ::std::os::raw::c_uint) { @@ -143,16 +126,25 @@ impl mach_msg_type_descriptor_t { pad3: ::std::os::raw::c_uint, type_: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 24u8, { - let pad3: u32 = unsafe { ::std::mem::transmute(pad3) }; - pad3 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let type_: u32 = unsafe { ::std::mem::transmute(type_) }; - type_ as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 24u8, + { + let pad3: u32 = unsafe { ::std::mem::transmute(pad3) }; + pad3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let type_: u32 = unsafe { ::std::mem::transmute(type_) }; + type_ as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 27cd90f14076c3b5da8e665c3b0bc9403fe61f69..60cf6b8056c6f0b2847c92e7c69c814bf5d40c8a 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,31 +83,21 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Struct { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_Struct() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 4usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; +}; impl Struct { #[inline] pub fn a(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_uchar) { @@ -126,9 +108,7 @@ impl Struct { } #[inline] pub fn b(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_uchar) { @@ -139,9 +119,7 @@ impl Struct { } #[inline] pub fn c(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_uchar) { @@ -152,9 +130,7 @@ impl Struct { } #[inline] pub fn d(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) { @@ -165,9 +141,7 @@ impl Struct { } #[inline] pub fn e(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } #[inline] pub fn set_e(&mut self, val: ::std::os::raw::c_uchar) { @@ -184,28 +158,124 @@ impl Struct { d: ::std::os::raw::c_ushort, e: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(2usize, 6u8, { - let c: u8 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); - __bindgen_bitfield_unit.set(8usize, 16u8, { - let d: u16 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let e: u8 = unsafe { ::std::mem::transmute(e) }; - e as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 6u8, + { + let c: u8 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 16u8, + { + let d: u16 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let e: u8 = unsafe { ::std::mem::transmute(e) }; + e as u64 + }, + ); __bindgen_bitfield_unit } } +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Inner { + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Inner"][::std::mem::size_of::() - 4usize]; + ["Alignment of Inner"][::std::mem::align_of::() - 2usize]; +}; +impl Inner { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u16) } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 16u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 16u8) as u16) } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(16usize, 16u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_ushort, + b: ::std::os::raw::c_ushort, + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 16u8, + { + let a: u16 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 16u8, + { + let b: u16 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Outer { + pub inner: Inner, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Outer"][::std::mem::size_of::() - 4usize]; + ["Alignment of Outer"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Outer::inner"][::std::mem::offset_of!(Outer, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/block_return_type.rs b/bindgen-tests/tests/expectations/tests/block_return_type.rs index bc4347335ec0bade2011ffd7f826c6469bd963f0..fa6c0ac67cf72867e975f890ecf9d7b393fc4b95 100644 --- a/bindgen-tests/tests/expectations/tests/block_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/block_return_type.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern crate block; extern "C" { pub fn func() -> _bindgen_ty_id_4; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs index 788cb30c4c6c5b757e8bf015f1d9aafefd9db86b..43e645bfc3e5347e706587ea49aea6321a61ee2a 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -1,43 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Debug. #[repr(C)] pub struct ShouldManuallyImplDebug { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldManuallyImplDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldManuallyImplDebug)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldManuallyImplDebug), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ShouldManuallyImplDebug", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldManuallyImplDebug", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldManuallyImplDebug::a", + ][::std::mem::offset_of!(ShouldManuallyImplDebug, a) - 0usize]; +}; impl Default for ShouldManuallyImplDebug { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs index 4d2b67129ac4c6afc379bbd142ef24ca15d2eb71..4056ef4d2c58801d03bf76d995aa63240b13e976 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-file.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-file.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct SizedIntegers { @@ -12,80 +6,34 @@ pub struct SizedIntegers { pub y: u16, pub z: u32, } -#[test] -fn bindgen_test_layout_SizedIntegers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(SizedIntegers)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SizedIntegers)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(y) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(z) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of SizedIntegers"][::std::mem::size_of::() - 8usize]; + ["Alignment of SizedIntegers"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: SizedIntegers::x", + ][::std::mem::offset_of!(SizedIntegers, x) - 0usize]; + [ + "Offset of field: SizedIntegers::y", + ][::std::mem::offset_of!(SizedIntegers, y) - 2usize]; + [ + "Offset of field: SizedIntegers::z", + ][::std::mem::offset_of!(SizedIntegers, z) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StructWithBlocklistedFwdDecl { pub b: u8, } -#[test] -fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithBlocklistedFwdDecl), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of StructWithBlocklistedFwdDecl", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of StructWithBlocklistedFwdDecl", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: StructWithBlocklistedFwdDecl::b", + ][::std::mem::offset_of!(StructWithBlocklistedFwdDecl, b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 5299b1517ec35cd74f59c9d0d0f6348ba97a0e35..2e12a01e9ed6e74c1b917fd7038b5a0eba8cd5e8 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -26,17 +20,9 @@ pub mod root { pub struct C { pub _address: u8, } - #[test] - fn bindgen_test_layout_C() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-item.rs b/bindgen-tests/tests/expectations/tests/blocklist-item.rs index 0edee9ec3253ddc46053fb63ff6c5d8d1a8533aa..39de8002b3f55b17b1c3bf1cdb9d6ec48194a980 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-item.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-item.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index eadc0694ed618eed65038a996ad350f58dca3c05..37bb95492d033e738ca523e6864a684ac1b65248 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEv"] pub fn Foo_foo(this: *mut Foo) -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-var.rs b/bindgen-tests/tests/expectations/tests/blocklist-var.rs new file mode 100644 index 0000000000000000000000000000000000000000..fe64295a689cfab8aaff286fcf9c73b18247d1b3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/blocklist-var.rs @@ -0,0 +1 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs new file mode 100644 index 0000000000000000000000000000000000000000..b5737a8d9929a0aeee254465d59952580cb41aa4 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs @@ -0,0 +1,69 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[path = "./struct_with_bitfields.rs"] +mod bitfields; +use bitfields::*; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub x: ::std::os::raw::c_uchar, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub baz: ::std::os::raw::c_uint, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::x"][::std::mem::offset_of!(C, x) - 0usize]; + ["Offset of field: C::baz"][::std::mem::offset_of!(C, baz) - 4usize]; +}; +impl C { + #[inline] + pub fn b1(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn b2(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } + } + #[inline] + pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + b1: ::std::os::raw::c_uint, + b2: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index ff7114a7d4b58722d3eac80c108add683a335737..b1615839ca03cbdc7117450df92289a131f59646 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern crate block; extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] @@ -34,42 +28,21 @@ pub struct contains_block_pointers { pub val: contains_block_pointers__bindgen_ty_id_61, pub ptr_val: *mut _bindgen_ty_id_68, } -#[test] -fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of contains_block_pointers", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of contains_block_pointers", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: contains_block_pointers::val", + ][::std::mem::offset_of!(contains_block_pointers, val) - 0usize]; + [ + "Offset of field: contains_block_pointers::ptr_val", + ][::std::mem::offset_of!(contains_block_pointers, ptr_val) - 8usize]; +}; impl Default for contains_block_pointers { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -86,7 +59,8 @@ pub type _bindgen_ty_id_40 = *const ::block::Block< >; pub type _bindgen_ty_id_50 = *const ::block::Block<(usize,), ()>; pub type _bindgen_ty_id_56 = *const ::block::Block<(usize,), ()>; -pub type contains_block_pointers__bindgen_ty_id_61 = - *const ::block::Block<(::std::os::raw::c_int,), ()>; -pub type _bindgen_ty_id_68 = - *const ::block::Block<(::std::os::raw::c_int,), ()>; +pub type contains_block_pointers__bindgen_ty_id_61 = *const ::block::Block< + (::std::os::raw::c_int,), + (), +>; +pub type _bindgen_ty_id_68 = *const ::block::Block<(::std::os::raw::c_int,), ()>; diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index 6f242989b6f85d2919c3e7fa156e71c46b765d90..ea15d22464e5de8b4d3e826cf03f12c1144f8a98 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: *mut ::std::os::raw::c_void); @@ -33,42 +27,21 @@ pub struct contains_block_pointers { pub val: *mut ::std::os::raw::c_void, pub ptr_val: *mut *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of contains_block_pointers", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of contains_block_pointers", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: contains_block_pointers::val", + ][::std::mem::offset_of!(contains_block_pointers, val) - 0usize]; + [ + "Offset of field: contains_block_pointers::ptr_val", + ][::std::mem::offset_of!(contains_block_pointers, ptr_val) - 8usize]; +}; impl Default for contains_block_pointers { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs index 6a0f5e134a8fd440d377042b4b897e3657731d4b..bd59c1971fcca15ac6380d64b8e5494d7f2489c3 100644 --- a/bindgen-tests/tests/expectations/tests/bug-1529681.rs +++ b/bindgen-tests/tests/expectations/tests/bug-1529681.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BrowsingContext { pub _address: u8, } -#[test] -fn bindgen_test_layout_BrowsingContext() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BrowsingContext)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BrowsingContext)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of BrowsingContext"][::std::mem::size_of::() - 1usize]; + ["Alignment of BrowsingContext"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/builtin-template.rs b/bindgen-tests/tests/expectations/tests/builtin-template.rs index 112b76700839a24f288633dc2c586297e6c8ad5d..53e3fbf9bf3f1bfa1b756bd7d18ec4c45fea96d4 100644 --- a/bindgen-tests/tests/expectations/tests/builtin-template.rs +++ b/bindgen-tests/tests/expectations/tests/builtin-template.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type std_make_integer_sequence = u8; diff --git a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs index ebef2b6d82aed8d728616634f4f71f516e8735f6..709a9a59d80c38d7967f9b94a743eb18f1eee31f 100644 --- a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs @@ -1,23 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo {} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 0usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs new file mode 100644 index 0000000000000000000000000000000000000000..25fd333ceabd3145856efeccd9581fdef67ca1fb --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs @@ -0,0 +1,10 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C-unwind" { + pub fn foo(); +} +extern "C-unwind" { + pub fn bar(); +} +extern "C" { + pub fn baz(); +} diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index 3e56b1d60ae7bd2495179753503d5fcfb344c9a9..502c4486eb2c9143e00e0c8df765d81012519787 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -1,41 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct struct_a { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_struct_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(struct_a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(struct_a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(struct_a), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of struct_a"][::std::mem::size_of::() - 4usize]; + ["Alignment of struct_a"][::std::mem::align_of::() - 4usize]; + ["Offset of field: struct_a::a"][::std::mem::offset_of!(struct_a, a) - 0usize]; +}; pub type a = *const struct_a; #[repr(C)] #[derive(Copy, Clone)] @@ -43,42 +17,13 @@ pub union union_b { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_union_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(union_b)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(union_b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of union_b"][::std::mem::size_of::() - 4usize]; + ["Alignment of union_b"][::std::mem::align_of::() - 4usize]; + ["Offset of field: union_b::a"][::std::mem::offset_of!(union_b, a) - 0usize]; + ["Offset of field: union_b::b"][::std::mem::offset_of!(union_b, b) - 0usize]; +}; impl Default for union_b { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs new file mode 100644 index 0000000000000000000000000000000000000000..089b34b134dcff591fb4f08297c68fe8e1bc5ac1 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/call-conv-field.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(not(test))] +#[repr(C)] +#[derive(Default, Copy, Clone)] +pub struct JNINativeInterface_ { + pub GetVersion: ::std::option::Option< + unsafe extern "stdcall" fn( + env: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub __hack: ::std::os::raw::c_ulonglong, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of JNINativeInterface_", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of JNINativeInterface_", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: JNINativeInterface_::GetVersion", + ][::std::mem::offset_of!(JNINativeInterface_, GetVersion) - 0usize]; + [ + "Offset of field: JNINativeInterface_::__hack", + ][::std::mem::offset_of!(JNINativeInterface_, __hack) - 8usize]; +}; +extern "stdcall" { + pub fn bar(); +} diff --git a/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs b/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs index 6eabb1f6ad6f5390f87e308c7c2b6baedd2ccafb..c62756f364ad3398cb4262a8c731f210285bbcfd 100644 --- a/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(test))] - pub type void_fn = ::std::option::Option; pub type fn_ = ::std::option::Option< unsafe extern "stdcall" fn(id: ::std::os::raw::c_int) -> void_fn, diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index a68e14244ab456142b33bad537d1a99781a002d4..81d2e488a20ec85e22fb08b23d4fc1d5c85fa832 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ClassA { @@ -13,8 +7,8 @@ pub struct ClassA { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassA_ClassAInner { - pub x: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub x: *mut T, } impl Default for ClassA_ClassAInner { fn default() -> Self { @@ -82,19 +76,11 @@ impl Default for ClassC_ClassCInnerCRTP { pub struct ClassD { pub _address: u8, } -#[test] -fn bindgen_test_layout_ClassD() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassD)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassD)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ClassD"][::std::mem::size_of::() - 1usize]; + ["Alignment of ClassD"][::std::mem::align_of::() - 1usize]; +}; impl Default for ClassD { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -104,38 +90,25 @@ impl Default for ClassD { } } } -#[test] -fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation( -) { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: ClassB_open0_ClassD_ClassCInnerCRTP_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: ClassB_open0_ClassD_ClassCInnerCRTP_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassCInnerCRTP { pub _address: u8, } -#[test] -fn bindgen_test_layout_ClassCInnerCRTP() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassCInnerCRTP)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassCInnerCRTP)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ClassCInnerCRTP"][::std::mem::size_of::() - 1usize]; + ["Alignment of ClassCInnerCRTP"][::std::mem::align_of::() - 1usize]; +}; impl Default for ClassCInnerCRTP { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -145,51 +118,26 @@ impl Default for ClassCInnerCRTP { } } } -#[test] -fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation( -) { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: ClassB_open0_ClassCInnerCRTP_ClassAInner_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: ClassB_open0_ClassCInnerCRTP_ClassAInner_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassAInner { pub x: *mut ClassCInnerA, } -#[test] -fn bindgen_test_layout_ClassAInner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassAInner)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassAInner)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassAInner), - "::", - stringify!(x) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ClassAInner"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassAInner"][::std::mem::align_of::() - 8usize]; + ["Offset of field: ClassAInner::x"][::std::mem::offset_of!(ClassAInner, x) - 0usize]; +}; impl Default for ClassAInner { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -204,32 +152,14 @@ impl Default for ClassAInner { pub struct ClassCInnerA { pub member: *mut ClassCInnerB, } -#[test] -fn bindgen_test_layout_ClassCInnerA() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerA)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerA)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerA), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ClassCInnerA"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassCInnerA"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ClassCInnerA::member", + ][::std::mem::offset_of!(ClassCInnerA, member) - 0usize]; +}; impl Default for ClassCInnerA { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -244,32 +174,14 @@ impl Default for ClassCInnerA { pub struct ClassCInnerB { pub cache: *mut ClassCInnerA, } -#[test] -fn bindgen_test_layout_ClassCInnerB() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerB)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerB)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerB), - "::", - stringify!(cache) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ClassCInnerB"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassCInnerB"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ClassCInnerB::cache", + ][::std::mem::offset_of!(ClassCInnerB, cache) - 0usize]; +}; impl Default for ClassCInnerB { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index 12f10a8873d7426f662fbf72dc1d9a339ce04f51..d07751a8db1ac7c8ecf07cae7f02056dd62e897c 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_Z3bazPN3foo3BarE"] pub fn baz(arg1: *mut Bar); diff --git a/bindgen-tests/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs index 960a681f6cb8a773d7c2023e6714e2d64e2df2e5..61a81269d7f7781d08b31aefbe13cb442b8a6566 100644 --- a/bindgen-tests/tests/expectations/tests/char.rs +++ b/bindgen-tests/tests/expectations/tests/char.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Char = ::std::os::raw::c_char; pub type SChar = ::std::os::raw::c_schar; pub type UChar = ::std::os::raw::c_uchar; @@ -24,84 +18,20 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 8542135b078f446ea37a6fb4d2790eab580a58a5..69591d1bcea376ce80eb8be1773e5b0806ea6f2d 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,35 +37,19 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + "Offset of field: C::a", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + "Offset of field: C::big_array", ); } impl Default for C { @@ -91,53 +69,34 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + "Size of C_with_zero_length_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + "Alignment of C_with_zero_length_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + "Offset of field: C_with_zero_length_array::a", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + "Offset of field: C_with_zero_length_array::big_array", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + "Offset of field: C_with_zero_length_array::zero_length_array", ); } impl Default for C_with_zero_length_array { @@ -157,41 +116,29 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + "Size of C_with_zero_length_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + "Alignment of C_with_zero_length_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + "Offset of field: C_with_zero_length_array_2::a", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + "Offset of field: C_with_zero_length_array_2::zero_length_array", ); } #[repr(C)] @@ -202,15 +149,32 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + "Size of C_with_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + "Alignment of C_with_incomplete_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_incomplete_array::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_incomplete_array::big_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + "Offset of field: C_with_incomplete_array::incomplete_array", ); } impl Default for C_with_incomplete_array { @@ -230,15 +194,27 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + "Size of C_with_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + "Alignment of C_with_incomplete_array_2", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_incomplete_array_2::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -250,21 +226,41 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + "Size of C_with_zero_length_array_and_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + "Alignment of C_with_zero_length_array_and_incomplete_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::big_array", + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::zero_length_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -285,23 +281,36 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array_2, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::( - ), + ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + "Size of C_with_zero_length_array_and_incomplete_array_2", ); assert_eq!( - ::std::mem::align_of::( - ), + ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + "Alignment of C_with_zero_length_array_and_incomplete_array_2", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::a", + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::zero_length_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -311,28 +320,14 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithDtor"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithDtor"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + "Offset of field: WithDtor::b", ); } #[repr(C)] @@ -342,15 +337,27 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + "Size of IncompleteArrayNonCopiable", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + "Alignment of IncompleteArrayNonCopiable", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + "Offset of field: IncompleteArrayNonCopiable::whatever", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + "Offset of field: IncompleteArrayNonCopiable::incomplete_array", ); } impl Default for IncompleteArrayNonCopiable { @@ -370,28 +377,19 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of Union"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Union"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + "Offset of field: Union::d", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + "Offset of field: Union::i", ); } impl Default for Union { @@ -410,28 +408,14 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithUnion"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithUnion"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + "Offset of field: WithUnion::data", ); } impl Default for WithUnion { @@ -453,15 +437,12 @@ fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + "Size of RealAbstractionWithTonsOfMethods", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + "Alignment of RealAbstractionWithTonsOfMethods", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index f6c3021eb3673ab17ff5a1796a2423b9587ac059..9db5b3a338d6fe3acb42d5fa6a5afa894565566d 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -60,7 +54,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -86,35 +80,19 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + "Offset of field: C::a", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + "Offset of field: C::big_array", ); } impl Clone for C { @@ -144,53 +122,34 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + "Size of C_with_zero_length_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + "Alignment of C_with_zero_length_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + "Offset of field: C_with_zero_length_array::a", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + "Offset of field: C_with_zero_length_array::big_array", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + "Offset of field: C_with_zero_length_array::zero_length_array", ); } impl Default for C_with_zero_length_array { @@ -210,41 +169,29 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + "Size of C_with_zero_length_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + "Alignment of C_with_zero_length_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + "Offset of field: C_with_zero_length_array_2::a", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + "Offset of field: C_with_zero_length_array_2::zero_length_array", ); } #[repr(C)] @@ -255,15 +202,32 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + "Size of C_with_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + "Alignment of C_with_incomplete_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_incomplete_array::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_incomplete_array::big_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + "Offset of field: C_with_incomplete_array::incomplete_array", ); } impl Default for C_with_incomplete_array { @@ -283,15 +247,27 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + "Size of C_with_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + "Alignment of C_with_incomplete_array_2", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_incomplete_array_2::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -303,21 +279,41 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + "Size of C_with_zero_length_array_and_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + "Alignment of C_with_zero_length_array_and_incomplete_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::a", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::big_array", + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::zero_length_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -338,23 +334,36 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit< + C_with_zero_length_array_and_incomplete_array_2, + > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::( - ), + ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + "Size of C_with_zero_length_array_and_incomplete_array_2", ); assert_eq!( - ::std::mem::align_of::( - ), + ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + "Alignment of C_with_zero_length_array_and_incomplete_array_2", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::a", + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::zero_length_array", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -364,28 +373,14 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithDtor"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithDtor"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + "Offset of field: WithDtor::b", ); } #[repr(C)] @@ -395,15 +390,27 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + "Size of IncompleteArrayNonCopiable", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + "Alignment of IncompleteArrayNonCopiable", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + "Offset of field: IncompleteArrayNonCopiable::whatever", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + "Offset of field: IncompleteArrayNonCopiable::incomplete_array", ); } impl Default for IncompleteArrayNonCopiable { @@ -424,28 +431,19 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of Union"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Union"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + "Offset of field: Union::d", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + "Offset of field: Union::i", ); } impl Clone for Union { @@ -460,28 +458,14 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of WithUnion"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of WithUnion"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + "Offset of field: WithUnion::data", ); } impl Clone for WithUnion { @@ -499,15 +483,12 @@ fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + "Size of RealAbstractionWithTonsOfMethods", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + "Alignment of RealAbstractionWithTonsOfMethods", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index f2cc8326f923fcc9802af4cb1a87b143e0d137fd..881a95fd938b87f7bd3ee6302df7c068a889e588 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { @@ -15,39 +9,17 @@ pub struct A { pub struct A_B { pub member_b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_B)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_B), - "::", - stringify!(member_b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A_B"][::std::mem::size_of::() - 4usize]; + ["Alignment of A_B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A_B::member_b"][::std::mem::offset_of!(A_B, member_b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_D { - pub foo: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub foo: T, } impl Default for A_D { fn default() -> Self { @@ -58,82 +30,35 @@ impl Default for A_D { } } } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(member_a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::member_a"][::std::mem::offset_of!(A, member_a) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_C { pub baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A_C"][::std::mem::size_of::() - 4usize]; + ["Alignment of A_C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A_C::baz"][::std::mem::offset_of!(A_C, baz) - 0usize]; +}; extern "C" { pub static mut var: A_B; } -#[test] -fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(A_D<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(A_D<::std::os::raw::c_int>) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: A_D_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: A_D_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; extern "C" { pub static mut baz: A_D<::std::os::raw::c_int>; } @@ -142,38 +67,23 @@ extern "C" { pub struct D { pub member: A_B, } -#[test] -fn bindgen_test_layout_D() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of D"][::std::mem::size_of::() - 4usize]; + ["Alignment of D"][::std::mem::align_of::() - 4usize]; + ["Offset of field: D::member"][::std::mem::offset_of!(D, member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated_Templated_inner { - pub member_ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member_ptr: *mut T, } impl Default for Templated_Templated_inner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs index 676590c8298aee8538f315f34d627f139353868d..c50da6a02db61571ae894515936da7619e4c70fe 100644 --- a/bindgen-tests/tests/expectations/tests/class_no_members.rs +++ b/bindgen-tests/tests/expectations/tests/class_no_members.rs @@ -1,76 +1,38 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { pub _address: u8, } -#[test] -fn bindgen_test_layout_whatever() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of whatever"][::std::mem::size_of::() - 1usize]; + ["Alignment of whatever"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child { pub _address: u8, } -#[test] -fn bindgen_test_layout_whatever_child() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever_child)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever_child)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of whatever_child"][::std::mem::size_of::() - 1usize]; + ["Alignment of whatever_child"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_whatever_child_with_member() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(whatever_child_with_member)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(whatever_child_with_member)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever_child_with_member), - "::", - stringify!(m_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of whatever_child_with_member", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of whatever_child_with_member", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: whatever_child_with_member::m_member", + ][::std::mem::offset_of!(whatever_child_with_member, m_member) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index 2388f3b3a4a5e3d602d5898e74a32ef809dfac49..c93968fa0cfdcd7ce30e30687fd9ea4f75a480e2 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct MyClass { @@ -16,22 +10,13 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] - pub static mut MyClass_example_check_no_collision: - *const ::std::os::raw::c_int; -} -#[test] -fn bindgen_test_layout_MyClass() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(MyClass)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MyClass)) - ); + pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of MyClass"][::std::mem::size_of::() - 1usize]; + ["Alignment of MyClass"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZL26example_check_no_collision"] pub static mut example_check_no_collision: *const ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs index 812d78e1abc9d477b410c8b2b8d3ffa98091549a..d628239c4c8eb08269b4cc685190d45b173a43df 100644 --- a/bindgen-tests/tests/expectations/tests/class_static_const.rs +++ b/bindgen-tests/tests/expectations/tests/class_static_const.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { @@ -13,16 +7,8 @@ pub struct A { pub const A_a: ::std::os::raw::c_int = 0; pub const A_b: i32 = 63; pub const A_c: u32 = 255; -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs index ef130c16c6466dc2bfcc674f5820d8bbca706701..ec898ff7eb301d2106e5052f1fa613c03831b731 100644 --- a/bindgen-tests/tests/expectations/tests/class_use_as.rs +++ b/bindgen-tests/tests/expectations/tests/class_use_as.rs @@ -1,72 +1,26 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { pub replacement: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_whatever() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(whatever)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(whatever)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever), - "::", - stringify!(replacement) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of whatever"][::std::mem::size_of::() - 4usize]; + ["Alignment of whatever"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: whatever::replacement", + ][::std::mem::offset_of!(whatever, replacement) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub c: whatever, } -#[test] -fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(c) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of container"][::std::mem::size_of::() - 4usize]; + ["Alignment of container"][::std::mem::align_of::() - 4usize]; + ["Offset of field: container::c"][::std::mem::offset_of!(container, c) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 86d2a576db4770753e952f1033c819c2813bbd7b..aa99f424684cd0e2db647aa21debbc7930da33dc 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct HandleWithDtor { - pub ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: *mut T, } impl Default for HandleWithDtor { fn default() -> Self { @@ -26,35 +20,14 @@ pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; pub struct WithoutDtor { pub shouldBeWithDtor: HandleValue, } -#[test] -fn bindgen_test_layout_WithoutDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithoutDtor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithoutDtor)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithoutDtor), - "::", - stringify!(shouldBeWithDtor) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithoutDtor"][::std::mem::size_of::() - 8usize]; + ["Alignment of WithoutDtor"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: WithoutDtor::shouldBeWithDtor", + ][::std::mem::offset_of!(WithoutDtor, shouldBeWithDtor) - 0usize]; +}; impl Default for WithoutDtor { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -64,22 +37,12 @@ impl Default for WithoutDtor { } } } -#[test] -fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(HandleWithDtor<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(HandleWithDtor<::std::os::raw::c_int>) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: HandleWithDtor_open0_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: HandleWithDtor_open0_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index eab9d59825ff53baba1d02a9f31562eec9230941..710026c72f0e53044661e13e960138f7c70d5a1c 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct A { @@ -18,73 +12,28 @@ pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of A_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A_Segment::begin", + ][::std::mem::offset_of!(A_Segment, begin) - 0usize]; + ["Offset of field: A_Segment::end"][::std::mem::offset_of!(A_Segment, end) - 4usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + ["Alignment of A__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A__bindgen_ty_1::f", + ][::std::mem::offset_of!(A__bindgen_ty_1, f) - 0usize]; +}; impl Default for A__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -99,32 +48,14 @@ impl Default for A__bindgen_ty_1 { pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A__bindgen_ty_2"][::std::mem::size_of::() - 4usize]; + ["Alignment of A__bindgen_ty_2"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A__bindgen_ty_2::d", + ][::std::mem::offset_of!(A__bindgen_ty_2, d) - 0usize]; +}; impl Default for A__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -134,39 +65,13 @@ impl Default for A__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 12usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::c"][::std::mem::offset_of!(A, c) - 0usize]; + ["Offset of field: A::named_union"][::std::mem::offset_of!(A, named_union) - 4usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -187,63 +92,21 @@ pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) - ); -} -#[test] -fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of B_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: B_Segment::begin", + ][::std::mem::offset_of!(B_Segment, begin) - 0usize]; + ["Offset of field: B_Segment::end"][::std::mem::offset_of!(B_Segment, end) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: B::d"][::std::mem::offset_of!(B, d) - 0usize]; +}; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { @@ -272,106 +135,48 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX2: f32, pub mY2: f32, } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of C__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of C__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX1", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mX1) - 0usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY1", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mY1) - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX2", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mX2) - 8usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY2", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mY2) - 12usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of C__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of C__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mStepSyntax", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_2, mStepSyntax) - 0usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mSteps", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_2, mSteps) - 4usize]; +}; impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -381,32 +186,14 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C__bindgen_ty_1"][::std::mem::size_of::() - 16usize]; + ["Alignment of C__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1::mFunc", + ][::std::mem::offset_of!(C__bindgen_ty_1, mFunc) - 0usize]; +}; impl Default for C__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -422,63 +209,21 @@ pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) - ); -} -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of C_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C_Segment::begin", + ][::std::mem::offset_of!(C_Segment, begin) - 0usize]; + ["Offset of field: C_Segment::end"][::std::mem::offset_of!(C_Segment, end) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 20usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::d"][::std::mem::offset_of!(C, d) - 0usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index 42656079dfe985a32809a77bd442882d8481a7e0..23afad6319b5da3075631c9c6bdf75eb0fbc0eea 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -63,38 +57,19 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of A_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) + "Offset of field: A_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) + "Offset of field: A_Segment::end", ); } impl Clone for A_Segment { @@ -110,28 +85,22 @@ pub struct A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)) + "Size of A__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)) + "Alignment of A__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) + "Offset of field: A__bindgen_ty_1::f", ); } impl Clone for A__bindgen_ty_1 { @@ -147,28 +116,22 @@ pub struct A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)) + "Size of A__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)) + "Alignment of A__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) + "Offset of field: A__bindgen_ty_2::d", ); } impl Clone for A__bindgen_ty_2 { @@ -178,35 +141,19 @@ impl Clone for A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); + assert_eq!(::std::mem::size_of::(), 12usize, "Size of A"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) + "Offset of field: A::c", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) + "Offset of field: A::named_union", ); } impl Clone for A { @@ -227,38 +174,19 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of B_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) + "Offset of field: B_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) + "Offset of field: B_Segment::end", ); } impl Clone for B_Segment { @@ -268,23 +196,14 @@ impl Clone for B_Segment { } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of B"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + "Offset of field: B::d", ); } impl Clone for B { @@ -323,58 +242,37 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + "Size of C__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + "Alignment of C__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY2", ); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { @@ -390,40 +288,27 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + "Size of C__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + "Alignment of C__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mStepSyntax", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mSteps", ); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { @@ -442,28 +327,22 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)) + "Size of C__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)) + "Alignment of C__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) + "Offset of field: C__bindgen_ty_1::mFunc", ); } impl Clone for C__bindgen_ty_1 { @@ -479,38 +358,19 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of C_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) + "Offset of field: C_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) + "Offset of field: C_Segment::end", ); } impl Clone for C_Segment { @@ -520,23 +380,14 @@ impl Clone for C_Segment { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); + assert_eq!(::std::mem::size_of::(), 20usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + "Offset of field: C::d", ); } impl Clone for C { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 65e86b27096cd585ba467440061979a3991cc6c9..9a89732036ba2dd17363881d5317681fa7d198ba 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type AnotherInt = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -17,54 +11,16 @@ pub struct C { } pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 72usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(other_ptr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 72usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::c"][::std::mem::offset_of!(C, c) - 0usize]; + ["Offset of field: C::ptr"][::std::mem::offset_of!(C, ptr) - 8usize]; + ["Offset of field: C::arr"][::std::mem::offset_of!(C, arr) - 16usize]; + ["Offset of field: C::d"][::std::mem::offset_of!(C, d) - 56usize]; + ["Offset of field: C::other_ptr"][::std::mem::offset_of!(C, other_ptr) - 64usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] pub fn C_method(this: *mut C, c: C_MyInt); @@ -114,27 +70,12 @@ pub struct D { pub _base: C, pub ptr: *mut C_MyInt, } -#[test] -fn bindgen_test_layout_D() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 80usize, - concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(D)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 72usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of D"][::std::mem::size_of::() - 80usize]; + ["Alignment of D"][::std::mem::align_of::() - 8usize]; + ["Offset of field: D::ptr"][::std::mem::offset_of!(D, ptr) - 72usize]; +}; impl Default for D { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs index 3ad221aa3da7b550e9fe55da6bb2ee8f91506f1b..72b167d00c902ce4d2ad65b9ac0ea6d4622fd466 100644 --- a/bindgen-tests/tests/expectations/tests/comment-indent.rs +++ b/bindgen-tests/tests/expectations/tests/comment-indent.rs @@ -1,139 +1,81 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; - /// This is a multi-line doc comment. - /// - /// This class is really really interesting, look! + /** This is a multi-line doc comment. + + This class is really really interesting, look!*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } - /// This nested class is also a multi-line doc comment. - /// - /// This class is not so interesting, but worth a bit of docs too! + /** This nested class is also a multi-line doc comment. + + This class is not so interesting, but worth a bit of docs too!*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { pub _address: u8, } - #[test] - fn bindgen_test_layout_Foo_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_Bar)) - ); - } - #[test] - fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Foo_Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo_Bar"][::std::mem::align_of::() - 1usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; + }; pub mod test { #[allow(unused_imports)] use self::super::super::root; - /// I'm in a namespace, and thus I may be on a rust module, most of the time. - /// My documentation is pretty extensive, I guess. + /** I'm in a namespace, and thus I may be on a rust module, most of the time. + My documentation is pretty extensive, I guess.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { - /// This member is plain awesome, just amazing. - /// - /// It also has super-extensive docs, with even a nice ascii-art diagram. - /// - /// +------+ +-------+ - /// | foo | ----> | bar | - /// +------+ +-------+ + /** This member is plain awesome, just amazing. + + It also has super-extensive docs, with even a nice ascii-art diagram. + + +------+ +-------+ + | foo | ----> | bar | + +------+ +-------+*/ pub member: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member) - ) - ); - } - /// I'm in an inline namespace, and as such I shouldn't get generated inside - /// a rust module, except when the relevant option is specified. Also, this - /// comment shouldn't be misaligned. + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Baz::member", + ][::std::mem::offset_of!(Baz, member) - 0usize]; + }; + /** I'm in an inline namespace, and as such I shouldn't get generated inside + a rust module, except when the relevant option is specified. Also, this + comment shouldn't be misaligned.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InInlineNS { pub _address: u8, } - #[test] - fn bindgen_test_layout_InInlineNS() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InInlineNS)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InInlineNS)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of InInlineNS"][::std::mem::size_of::() - 1usize]; + ["Alignment of InInlineNS"][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bazz { pub _address: u8, } - #[test] - fn bindgen_test_layout_Bazz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bazz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bazz)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bazz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bazz"][::std::mem::align_of::() - 1usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs index e9c4be9d443d908e7427dd3cbb2713d4cdc03cce..233b86ea360fec221e2d55bc9772eaf2cfb77765 100644 --- a/bindgen-tests/tests/expectations/tests/complex.rs +++ b/bindgen-tests/tests/expectations/tests/complex.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { @@ -16,63 +10,27 @@ pub struct __BindgenComplex { pub struct TestDouble { pub mMember: __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestDouble() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(TestDouble)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDouble)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDouble), - "::", - stringify!(mMember) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestDouble"][::std::mem::size_of::() - 16usize]; + ["Alignment of TestDouble"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestDouble::mMember", + ][::std::mem::offset_of!(TestDouble, mMember) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestDoublePtr { pub mMember: *mut __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestDoublePtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestDoublePtr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDoublePtr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDoublePtr), - "::", - stringify!(mMember) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestDoublePtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestDoublePtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestDoublePtr::mMember", + ][::std::mem::offset_of!(TestDoublePtr, mMember) - 0usize]; +}; impl Default for TestDoublePtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -87,63 +45,27 @@ impl Default for TestDoublePtr { pub struct TestFloat { pub mMember: __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestFloat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloat)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(TestFloat)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloat), - "::", - stringify!(mMember) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestFloat"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestFloat"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: TestFloat::mMember", + ][::std::mem::offset_of!(TestFloat, mMember) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestFloatPtr { pub mMember: *mut __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestFloatPtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloatPtr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestFloatPtr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloatPtr), - "::", - stringify!(mMember) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestFloatPtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestFloatPtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestFloatPtr::mMember", + ][::std::mem::offset_of!(TestFloatPtr, mMember) - 0usize]; +}; impl Default for TestFloatPtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/complex_global.rs b/bindgen-tests/tests/expectations/tests/complex_global.rs index f21735da53b0e38aa43e72a2f56995b98893cb72..101ad0f49f704fad266edae1d6589cb27675f99c 100644 --- a/bindgen-tests/tests/expectations/tests/complex_global.rs +++ b/bindgen-tests/tests/expectations/tests/complex_global.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { diff --git a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs index e8f13dff82833dd00c7164f75e75d760c8c07155..72a34da105eef202fc682acb37660d3c66145bf2 100644 --- a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { pub bar: *const *const *mut *const ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/const_array.rs b/bindgen-tests/tests/expectations/tests/const_array.rs index 191bac9c3f6028d114ceb245da170a32874380b6..8dae42d1166f64e660682427e6d8cacaef5539d7 100644 --- a/bindgen-tests/tests/expectations/tests/const_array.rs +++ b/bindgen-tests/tests/expectations/tests/const_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static foo: [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs index 3286dce1be94bc943e7c5001d983a5b5cbdeb8eb..035a56fa7820c843d73101627718b4e3bb523274 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: *const ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs new file mode 100644 index 0000000000000000000000000000000000000000..a9ddc0c85ead82f4dd3a2f232249af600dc77852 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct strct { + pub field: ::std::os::raw::c_int, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of strct"][::std::mem::size_of::() - 4usize]; + ["Alignment of strct"][::std::mem::align_of::() - 4usize]; + ["Offset of field: strct::field"][::std::mem::offset_of!(strct, field) - 0usize]; +}; +pub type typ = [strct; 1usize]; +extern "C" { + pub static mut w: typ; +} +extern "C" { + pub static mut x: *mut strct; +} +extern "C" { + pub static y: typ; +} +extern "C" { + pub static mut z: *const strct; +} +extern "C" { + pub fn function(a: *const strct, b: *const strct); +} diff --git a/bindgen-tests/tests/expectations/tests/const_bool.rs b/bindgen-tests/tests/expectations/tests/const_bool.rs new file mode 100644 index 0000000000000000000000000000000000000000..2cbab47390e737f5fd0d9b557204b7e09ac3471f --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/const_bool.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const k: bool = true; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _address: u8, +} +pub const A_k: bool = false; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; +pub type foo = bool; +pub const k2: foo = true; diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index da0ec2b82db0a7fa43fde88a641c6942c4eab2ad..f49d825224dee5ff339c9da3029e95ea23398682 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] @@ -24,16 +18,8 @@ pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs index 11ae184d852a0f6bc31a87eae46b0c77770829f9..0c4670b0ed23b2b1541eaeddedfa13bac213c4af 100644 --- a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: *const [::std::os::raw::c_int; 1usize]); } diff --git a/bindgen-tests/tests/expectations/tests/const_ptr.rs b/bindgen-tests/tests/expectations/tests/const_ptr.rs index 0087aa99eef9fc3a8d61f1dfd9aac41c594a8604..c08aa73d7e9e2b4f51c3187f4097c2fe9aa8691c 100644 --- a/bindgen-tests/tests/expectations/tests/const_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const_ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(bar: *const ::std::os::raw::c_void); } diff --git a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs index 66939ef932e9339b23e6797e25ea4106e9082bad..20a124b474b69c15ef526a0c01b22d667583b02b 100644 --- a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs +++ b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(foo: *const u8); } diff --git a/bindgen-tests/tests/expectations/tests/const_tparam.rs b/bindgen-tests/tests/expectations/tests/const_tparam.rs index ec256872dfff6496e03152583aef6dc251c10b4e..c6b16a89592f5ad49743a3dd5b821daf3f587d87 100644 --- a/bindgen-tests/tests/expectations/tests/const_tparam.rs +++ b/bindgen-tests/tests/expectations/tests/const_tparam.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: *const T, pub bar: *const T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for C { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs new file mode 100644 index 0000000000000000000000000000000000000000..bbcf6d5450213ede87c346f84e89ff31283e44c3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; +pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum _bindgen_ty_1 { + foo = 4, + bar = 8, +} +pub type EasyToOverflow = ::std::os::raw::c_ulonglong; +pub const k: EasyToOverflow = 2147483648; +pub const k_expr: EasyToOverflow = 1152921504606846976; +pub const wow: EasyToOverflow = 2147483648; +pub const BAZ: ::std::os::raw::c_longlong = 24; +pub const fuzz: f64 = 51.0; +pub const BAZZ: ::std::os::raw::c_char = 53; +pub const WAT: ::std::os::raw::c_char = 0; +pub const bytestring: &[u8; 4] = b"Foo\0"; +pub const NOT_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs b/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs index 6c1e3d382a1e5b9ad57f44885bced7f6a910494a..968ec350aaeee30f151cbb8646b2674a268fc724 100644 --- a/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index d47338f1420eae200b143ffbf73e208e0c60d23a..e5eada9abc66b5a91cb598c46951272a4debdf19 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { @@ -19,39 +13,29 @@ pub type C_U = B; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { - pub u: u8, -} -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) - ); -} -#[test] -fn __bindgen_test_layout_C_open0_A_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(C)) - ); + pub u: B, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; + ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: C_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: C_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: B_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs index e3c82156f5c32cfdb7ca84126712d42b4775552c..7913454b568d188a35c5b7aa44418b6cc53ec0a3 100644 --- a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs +++ b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo_THIS: foo = 0; pub const foo_SHOULD_BE: foo = 1; pub const foo_A_CONSTANT: foo = 2; @@ -14,35 +8,14 @@ pub type foo = ::std::os::raw::c_uint; pub struct bar { pub this_should_work: foo, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-enum.rs b/bindgen-tests/tests/expectations/tests/constify-enum.rs index 091743e9456c6507749718836eea81ba8a2e81e6..67d2749c51f9539f56f8151c0ee09554b2854e41 100644 --- a/bindgen-tests/tests/expectations/tests/constify-enum.rs +++ b/bindgen-tests/tests/expectations/tests/constify-enum.rs @@ -1,16 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: - nsCSSPropertyID = - nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID = nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue; impl nsCSSPropertyID { - pub const eCSSProperty_COUNT: nsCSSPropertyID = - nsCSSPropertyID::eCSSPropertyAlias_aa; + pub const eCSSProperty_COUNT: nsCSSPropertyID = nsCSSPropertyID::eCSSPropertyAlias_aa; } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index c5c32983b0e3ed8618c19a40b11455be8b566a2c..ec0e51c49ea73e08d400a3ede5f5b6058b8f6676 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; @@ -18,35 +12,14 @@ pub use self::foo_alias1 as foo_alias2; pub struct bar { pub this_should_work: foo::Type, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index 0b8eec1eabfde200fea5ddd7e5ac5093dce278af..883478a824e9b54874c3bb36bf64a053f3fa6041 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -30,35 +24,14 @@ pub mod root { pub struct bar { pub this_should_work: root::ns1::ns2::foo::Type, } - #[test] - fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; + }; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index 44643d0fffeebb7a09debd2717e5d8127e3fe39d..b5e4243c94e3a3d9ee2ebe134b8d1023ec2cff55 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const Type: Type = 0; @@ -17,32 +11,12 @@ pub mod foo { pub struct bar { pub member: foo::Type, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::member"][::std::mem::offset_of!(bar, member) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 0262b128e4600d3cc34a4e10306dc9482a13d97d..63d48ef7957429aa4e50a03bc8f0f182ec4a6e56 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; @@ -26,90 +20,19 @@ pub struct Bar { pub baz_ptr3: *mut Foo_alias2, pub baz_ptr4: *mut Foo_alias3, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr1) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr2) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr3) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr4) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 48usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz1"][::std::mem::offset_of!(Bar, baz1) - 0usize]; + ["Offset of field: Bar::baz2"][::std::mem::offset_of!(Bar, baz2) - 4usize]; + ["Offset of field: Bar::baz3"][::std::mem::offset_of!(Bar, baz3) - 8usize]; + ["Offset of field: Bar::baz4"][::std::mem::offset_of!(Bar, baz4) - 12usize]; + ["Offset of field: Bar::baz_ptr1"][::std::mem::offset_of!(Bar, baz_ptr1) - 16usize]; + ["Offset of field: Bar::baz_ptr2"][::std::mem::offset_of!(Bar, baz_ptr2) - 24usize]; + ["Offset of field: Bar::baz_ptr3"][::std::mem::offset_of!(Bar, baz_ptr3) - 32usize]; + ["Offset of field: Bar::baz_ptr4"][::std::mem::offset_of!(Bar, baz_ptr4) - 40usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 75ebf48acf9018de70079d337f6e3cab43359937..80fa0734dafca94be06c40d634df9a7833162b86 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod one_Foo { pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; @@ -16,32 +10,13 @@ pub struct Bar { pub baz1: one_Foo::Type, pub baz2: *mut one_Foo::Type, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz1"][::std::mem::offset_of!(Bar, baz1) - 0usize]; + ["Offset of field: Bar::baz2"][::std::mem::offset_of!(Bar, baz2) - 8usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index c3c6d3ca009565527d0814a30ef8e9f050e045f4..754f6ceedbd9d26ab59b23d149168a57a6d91ef6 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; @@ -31,12 +25,12 @@ pub mod ns2_Foo { pub const Variant1: Type = 0; pub const Variant2: Type = 1; } -pub use self::anon_enum::Type as anon_enum_alias1; -pub use self::anon_enum_alias1 as anon_enum_alias2; -pub use self::anon_enum_alias2 as anon_enum_alias3; pub use self::foo::Type as foo_alias1; pub use self::foo_alias1 as foo_alias2; pub use self::foo_alias2 as foo_alias3; +pub use self::anon_enum::Type as anon_enum_alias1; +pub use self::anon_enum_alias1 as anon_enum_alias2; +pub use self::anon_enum_alias2 as anon_enum_alias3; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bar { @@ -51,124 +45,21 @@ pub struct bar { pub member9: anon_enum_alias2, pub member10: anon_enum_alias3, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member3) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member4) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member5) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member6) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member7) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member8) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member9) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member10) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 48usize]; + ["Alignment of bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: bar::member1"][::std::mem::offset_of!(bar, member1) - 0usize]; + ["Offset of field: bar::member2"][::std::mem::offset_of!(bar, member2) - 4usize]; + ["Offset of field: bar::member3"][::std::mem::offset_of!(bar, member3) - 8usize]; + ["Offset of field: bar::member4"][::std::mem::offset_of!(bar, member4) - 12usize]; + ["Offset of field: bar::member5"][::std::mem::offset_of!(bar, member5) - 16usize]; + ["Offset of field: bar::member6"][::std::mem::offset_of!(bar, member6) - 24usize]; + ["Offset of field: bar::member7"][::std::mem::offset_of!(bar, member7) - 32usize]; + ["Offset of field: bar::member8"][::std::mem::offset_of!(bar, member8) - 36usize]; + ["Offset of field: bar::member9"][::std::mem::offset_of!(bar, member9) - 40usize]; + ["Offset of field: bar::member10"][::std::mem::offset_of!(bar, member10) - 44usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -183,32 +74,12 @@ impl Default for bar { pub struct Baz { pub member1: ns2_Foo::Type, } -#[test] -fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member1) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz::member1"][::std::mem::offset_of!(Baz, member1) - 0usize]; +}; impl Default for Baz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -228,27 +99,12 @@ pub mod one_Foo { pub struct Bar { pub baz: *mut one_Foo::Type, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -277,8 +133,8 @@ extern "C" { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing { - pub thing: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub thing: T, } impl Default for Thing { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 4b339dc3c44e89d1edabe043072d9fd190fcd219..1a6e9c40dc9631a1a5adaabf5077293e5d22031d 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -15,19 +9,11 @@ pub struct Foo { pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3BarC1Ev"] pub fn Bar_Bar(this: *mut Bar); diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 2f13effbefdc54a1097046460544c1776d9cd1c1..9da761e40a4ded1541a2c97b3d526600963e65b2 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TestOverload { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestOverload() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestOverload)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestOverload"][::std::mem::size_of::() - 1usize]; + ["Alignment of TestOverload"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ei"] pub fn TestOverload_TestOverload( @@ -53,19 +39,13 @@ impl TestOverload { pub struct TestPublicNoArgs { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestPublicNoArgs() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TestPublicNoArgs"][::std::mem::size_of::() - 1usize]; + [ + "Alignment of TestPublicNoArgs", + ][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"] pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs); diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index b5d333325b52c65baceb41ab313c1e5de60d0318..0563b4e65dd9dd4dcb030c7093f1c53caa4795bd 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TestOverload { @@ -12,15 +6,11 @@ pub struct TestOverload { } #[test] fn bindgen_test_layout_TestOverload() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)) - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of TestOverload"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(TestOverload)) + "Alignment of TestOverload", ); } extern "C" { @@ -60,12 +50,12 @@ fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)) + "Size of TestPublicNoArgs", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)) + "Alignment of TestPublicNoArgs", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 62fc3749462cd14efb56e03956bcfe2929a6a383..336228084356329067d5adbd1b9e7c3fca978d68 100644 --- a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -1,103 +1,42 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This should get an `_address` byte. #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)) - ); -} -/// This should not get an `_address` byte, so `sizeof(Inherits)` should be -/// `1`. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; +}; +/** This should not get an `_address` byte, so `sizeof(Inherits)` should be + `1`.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Inherits { pub b: bool, } -#[test] -fn bindgen_test_layout_Inherits() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Inherits)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Inherits)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Inherits), - "::", - stringify!(b) - ) - ); -} -/// This should not get an `_address` byte, but contains `Empty` which *does* get -/// one, so `sizeof(Contains)` should be `1 + 1`. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Inherits"][::std::mem::size_of::() - 1usize]; + ["Alignment of Inherits"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Inherits::b"][::std::mem::offset_of!(Inherits, b) - 0usize]; +}; +/** This should not get an `_address` byte, but contains `Empty` which *does* get + one, so `sizeof(Contains)` should be `1 + 1`.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Contains { pub empty: Empty, pub b: bool, } -#[test] -fn bindgen_test_layout_Contains() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(Contains)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Contains)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(empty) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Contains"][::std::mem::size_of::() - 2usize]; + ["Alignment of Contains"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Contains::empty", + ][::std::mem::offset_of!(Contains, empty) - 0usize]; + ["Offset of field: Contains::b"][::std::mem::offset_of!(Contains, b) - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 09a22c4f6599b035697ec283bef94f8b46426b27..96f9e6fd2a019cc52812827c1feaf1b8196f5750 100644 --- a/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type mbedtls_mpi_uint = ::std::os::raw::c_uint; /// \brief MPI structure #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs index e710a442e2fcbfd726623b65298801f363ce26ed..9ca939f7c532ab3ccfe9de982f7d6cd1b97af24f 100644 --- a/bindgen-tests/tests/expectations/tests/convert-floats.rs +++ b/bindgen-tests/tests/expectations/tests/convert-floats.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { @@ -21,71 +15,21 @@ pub struct foo { pub complexFloat: __BindgenComplex<::std::os::raw::c_float>, pub complexDouble: __BindgenComplex<::std::os::raw::c_double>, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bazzz) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexFloat) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexDouble) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 48usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; + ["Offset of field: foo::baz"][::std::mem::offset_of!(foo, baz) - 4usize]; + ["Offset of field: foo::bazz"][::std::mem::offset_of!(foo, bazz) - 8usize]; + ["Offset of field: foo::bazzz"][::std::mem::offset_of!(foo, bazzz) - 16usize]; + [ + "Offset of field: foo::complexFloat", + ][::std::mem::offset_of!(foo, complexFloat) - 24usize]; + [ + "Offset of field: foo::complexDouble", + ][::std::mem::offset_of!(foo, complexDouble) - 32usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/core_ffi_c.rs b/bindgen-tests/tests/expectations/tests/core_ffi_c.rs index 7e138a894f6294c16de48c6a40ffbd359304a550..42c92720345fd8b5877dbd254477ae16a7490611 100644 --- a/bindgen-tests/tests/expectations/tests/core_ffi_c.rs +++ b/bindgen-tests/tests/expectations/tests/core_ffi_c.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type c_char = ::core::ffi::c_char; pub type c_double = ::core::ffi::c_double; pub type c_float = ::core::ffi::c_float; diff --git a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs index f5ba025a25a0697bb796d28c00ac4be4b6f5b0ff..551dff82cfb9e323724af19dbf5e8991f42ec22a 100644 --- a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs index 2372e21153f14574b5ea31211d33d3a986e2521a..68397041b7aaba413e2d152839ceb022ef673155 100644 --- a/bindgen-tests/tests/expectations/tests/crtp.rs +++ b/bindgen-tests/tests/expectations/tests/crtp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Base { @@ -15,19 +9,11 @@ pub struct Base { pub struct Derived { pub _address: u8, } -#[test] -fn bindgen_test_layout_Derived() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Derived)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Derived)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Derived"][::std::mem::size_of::() - 1usize]; + ["Alignment of Derived"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct BaseWithDestructor { @@ -38,49 +24,30 @@ pub struct BaseWithDestructor { pub struct DerivedFromBaseWithDestructor { pub _address: u8, } -#[test] -fn bindgen_test_layout_DerivedFromBaseWithDestructor() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)) - ); -} -#[test] -fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Base)) - ); -} -#[test] -fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation( -) { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithDestructor) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithDestructor) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of DerivedFromBaseWithDestructor", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of DerivedFromBaseWithDestructor", + ][::std::mem::align_of::() - 1usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Base_open0_Derived_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Base_open0_Derived_close0", + ][::std::mem::align_of::() - 1usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs index 5b3d186a33fb60da2a69193fe9c3033c2981db1b..5f947f9cea1ec46988618b5f1d53a34b0f67f0c5 100644 --- a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs +++ b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs @@ -1,9 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![no_std] mod libc { pub mod foo { @@ -11,7 +6,6 @@ mod libc { pub enum c_void {} } } - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -19,37 +13,14 @@ pub struct foo { pub b: libc::foo::c_int, pub bar: *mut libc::foo::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/dash_language.rs b/bindgen-tests/tests/expectations/tests/dash_language.rs index eb2bbc768948a5357eb6ecbbab57dee9ceb5ed2e..f405a35604035a912b4787443cac892f52d73b05 100644 --- a/bindgen-tests/tests/expectations/tests/dash_language.rs +++ b/bindgen-tests/tests/expectations/tests/dash_language.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs index d812b03238253f4710ecf598dde6f110ebc9a0a8..8be0ea58e9efc0bf7bb580e6a433ebcf70eaa281 100644 --- a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs +++ b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs index b520f1e0337bda238e06983f4f25625cad85dfef..08cf113a4ccc7da93dc080ff4734ba71cdef97de 100644 --- a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs +++ b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: *mut [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs index 5e225e3db6c84b7b866c045c18379672c7c880bd..c9897de70be93af46c101a0d36dbc43b03c7a9bc 100644 --- a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { pub type Type = ::std::os::raw::c_uint; pub const bar: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs index 38ebc531b3ab6ec8e3688a2d5561fb510ebef8cf..db4eaa99bd4122916b91f7119f19800d09549d6f 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: i32 = 0; pub const N1: i32 = 1; pub const N2: i32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs index 5571563bcdcec51cc9c53882d244339ed464ce0a..bc122e981f5f34027f98584f8c64effb4509fac7 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u32 = 0; pub const N1: u32 = 1; pub const N2: u32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs index 5571563bcdcec51cc9c53882d244339ed464ce0a..bc122e981f5f34027f98584f8c64effb4509fac7 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u32 = 0; pub const N1: u32 = 1; pub const N2: u32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index 2cbe463cd9136eb3ede0743df8911ce9a5606fb7..797fc03253b7be3ad028f9a6d327eaea7c5b07f8 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { - pub t: T, - pub u: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, + pub u: U, } impl Default for Foo { fn default() -> Self { @@ -22,25 +16,15 @@ impl Default for Foo { } } } -#[test] -fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Foo_open0_bool__int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: Foo_open0_bool__int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; extern "C" { #[link_name = "\u{1}_ZL3bar"] pub static mut bar: Foo; diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs new file mode 100644 index 0000000000000000000000000000000000000000..aef1a61a08f9b73e6db2df2ed298158adaaeaea3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -0,0 +1,168 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub(crate) x: ::std::os::raw::c_int, + pub(crate) y: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + pub(crate) _bitfield_align_1: [u8; 0], + pub(crate) _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + pub(crate) fn r(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub(crate) fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn g(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } + } + #[inline] + pub(crate) fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn b(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } + } + #[inline] + pub(crate) fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs new file mode 100644 index 0000000000000000000000000000000000000000..8b3099c0d8e4625bb3c0acf8b824cbe8c1dcfc8d --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -0,0 +1,168 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + fn r(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn g(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } + } + #[inline] + fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + fn b(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } + } + #[inline] + fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs new file mode 100644 index 0000000000000000000000000000000000000000..29fbb3a8936abd8ab11421bc6f84173faa80c557 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -0,0 +1,168 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + pub fn r(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn g(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } + } + #[inline] + pub fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 96967bb46109fdaa8729c6225a132d6a19704477..913e2d4b4a5b59c59813e277fb794a4cd787875a 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A17inline_definitionEv"] pub fn A_inline_definition(this: *mut A); @@ -46,37 +32,21 @@ impl A { pub struct B { pub _address: u8, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub _address: u8, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1CC1ERS_"] pub fn C_C(this: *mut C, arg1: *mut C); diff --git a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index ea6621dd1c3788b946638ed4a8320b14dcc855ad..feded416f72a976ea753bafd4c561eff81539a01 100644 --- a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,9 +83,9 @@ where } } } -/// Because this struct have array larger than 32 items -/// and --with-derive-partialeq --impl-partialeq --impl-debug is provided, -/// this struct should manually implement `Debug` and `PartialEq`. +/** Because this struct have array larger than 32 items + and --with-derive-partialeq --impl-partialeq --impl-debug is provided, + this struct should manually implement `Debug` and `PartialEq`.*/ #[repr(C)] #[derive(Copy, Clone)] pub struct Foo { @@ -104,28 +96,14 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 136usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); + assert_eq!(::std::mem::size_of::(), 136usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(large) - ) + "Offset of field: Foo::large", ); } extern "C" { @@ -154,31 +132,26 @@ impl ::std::fmt::Debug for Foo { write!( f, "Foo {{ large: [{}], type_ : {:?}, }}", - self.large + self + .large .iter() .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) .collect::(), - self.type__bindgen_bitfield() + self.type__bindgen_bitfield(), ) } } impl ::std::cmp::PartialEq for Foo { fn eq(&self, other: &Foo) -> bool { - &self.large[..] == &other.large[..] && - self.type__bindgen_bitfield() == other.type__bindgen_bitfield() + &self.large[..] == &other.large[..] + && self.type__bindgen_bitfield() == other.type__bindgen_bitfield() } } impl Foo { #[inline] pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } } #[inline] pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) { @@ -191,13 +164,18 @@ impl Foo { pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let type__bindgen_bitfield: u8 = unsafe { + ::std::mem::transmute(type__bindgen_bitfield) + }; + type__bindgen_bitfield as u64 + }, + ); __bindgen_bitfield_unit } #[inline] diff --git a/bindgen-tests/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs index 19c28b697f05c460d3cb3c0239f093b41db7a004..d903afa06f9ee2ce6cdca2bdc228968c9c244403 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This struct should derive `Clone`. #[repr(C)] #[derive(Copy, Clone)] @@ -13,28 +7,22 @@ pub struct ShouldDeriveClone { } #[test] fn bindgen_test_layout_ShouldDeriveClone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldDeriveClone)) + "Size of ShouldDeriveClone", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDeriveClone)) + "Alignment of ShouldDeriveClone", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveClone), - "::", - stringify!(large) - ) + "Offset of field: ShouldDeriveClone::large", ); } impl Default for ShouldDeriveClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs index 3d72db2f8939283dd4764b2fd5a8661183ff8d16..7b3a00738cc54c5083274839020988d082e085fe 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct -/// should impl `Clone` "manually". +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** Since builtin `Clone` impls were introduced in Rust 1.21 this struct + should impl `Clone` "manually".*/ #[repr(C)] #[derive(Copy)] pub struct ShouldImplClone { @@ -14,28 +8,22 @@ pub struct ShouldImplClone { } #[test] fn bindgen_test_layout_ShouldImplClone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldImplClone)) + "Size of ShouldImplClone", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldImplClone)) + "Alignment of ShouldImplClone", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldImplClone), - "::", - stringify!(large) - ) + "Offset of field: ShouldImplClone::large", ); } impl Clone for ShouldImplClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 36f84c7d9338c35ddb022bc4201c0904e0a0925f..59a3a765715f0a4e26b6c70f5d73ec628a2fb735 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -1,41 +1,17 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Clone, Default)] pub struct foo_struct { pub inner: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_struct), - "::", - stringify!(inner) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo_struct"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_struct"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo_struct::inner", + ][::std::mem::offset_of!(foo_struct, inner) - 0usize]; +}; #[repr(u32)] #[derive(Clone, Hash, PartialEq, Eq, Copy)] pub enum foo_enum { @@ -47,69 +23,22 @@ pub union foo_union { pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, pub snd: ::std::mem::ManuallyDrop, } -#[test] -fn bindgen_test_layout_foo_union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_union)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_union)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_union), - "::", - stringify!(fst) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_union), - "::", - stringify!(snd) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo_union"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_union"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo_union::fst"][::std::mem::offset_of!(foo_union, fst) - 0usize]; + ["Offset of field: foo_union::snd"][::std::mem::offset_of!(foo_union, snd) - 0usize]; +}; #[repr(C)] pub struct non_matching { pub inner: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_non_matching() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(non_matching)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(non_matching)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(non_matching), - "::", - stringify!(inner) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of non_matching"][::std::mem::size_of::() - 4usize]; + ["Alignment of non_matching"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: non_matching::inner", + ][::std::mem::offset_of!(non_matching, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-custom.rs b/bindgen-tests/tests/expectations/tests/derive-custom.rs index 542b6bb25f752e6e9e092e96d82efe94a4c2c377..9a69ebbb7358bb5e6d04cfe6f6a2a0d46f6a0e9a 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom.rs @@ -1,18 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Default, Debug)] pub struct my_type { pub a: ::std::os::raw::c_int, } -///
-///
+/**
+
*/ #[repr(C)] #[derive(Default, Debug, Clone)] pub struct my_type2 { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs index 2a78e93050246a380dfadedf7af60b2d5c9955e2..64c20f91bab60625634dc5749aa5887faf966008 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -57,8 +50,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -78,8 +70,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,30 +93,14 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::core::mem::size_of::(), 204usize, "Size of C"); + assert_eq!(::core::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( - ::core::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + "Offset of field: C::large_array", ); } impl Default for C { @@ -139,20 +114,13 @@ impl Default for C { } impl ::core::fmt::Debug for C { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - write!( - f, - "C {{ a : {:?}, b : {:?}, large_array: [...] }}", - self.a(), - self.b() - ) + write!(f, "C {{ a : {:?}, b : {:?}, large_array: [...] }}", self.a(), self.b()) } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -163,9 +131,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -175,20 +141,26 @@ impl C { } } #[inline] - pub fn new_bitfield_1( - a: bool, - b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::core::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::core::mem::transmute(b) }; - b as u64 - }); + pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::core::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::core::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index 0ae8f329681b512b891dcf0867e176214bb15386..0471b48bfaff604d9ad758ba40f46ec57fef0e54 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,30 +92,14 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 204usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( - ::std::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + "Offset of field: C::large_array", ); } impl Default for C { @@ -142,24 +118,19 @@ impl ::std::fmt::Debug for C { "C {{ a : {:?}, b : {:?}, large_array: [{}] }}", self.a(), self.b(), - self.large_array + self + .large_array .iter() .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) - .collect::() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::(), ) } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -170,9 +141,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -182,20 +151,26 @@ impl C { } } #[inline] - pub fn new_bitfield_1( - a: bool, - b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs index 16b127bf14384aed9cd4f5afc8deb08c40b9aab6..9077201a77d5f7c408918cc10a30f0958affb3bb 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -1,54 +1,28 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct Nice { pub pointer: Nice_Function, pub large_array: [::std::os::raw::c_int; 34usize], } -pub type Nice_Function = - ::std::option::Option; +pub type Nice_Function = ::std::option::Option< + unsafe extern "C" fn(data: ::std::os::raw::c_int), +>; #[test] fn bindgen_test_layout_Nice() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 144usize, - concat!("Size of: ", stringify!(Nice)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Nice)) - ); + assert_eq!(::std::mem::size_of::(), 144usize, "Size of Nice"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Nice"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(pointer) - ) + "Offset of field: Nice::pointer", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(large_array) - ) + "Offset of field: Nice::large_array", ); } impl Default for Nice { @@ -66,15 +40,12 @@ impl ::std::fmt::Debug for Nice { f, "Nice {{ pointer: {:?}, large_array: [{}] }}", self.pointer, - self.large_array + self + .large_array .iter() .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) - .collect::() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::(), ) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs index 49d4e9b89e23848b255e88f15f28f6277615d3b8..de6ce385acf95e768c615f633c671f3e8514533c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs @@ -1,14 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs index a757d679b09cd3d45ea73049e0ddcbce750f42ba..34b4a87d65efff2e5bf7ce5dbab6ef52d882c247 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct perf_event_attr { @@ -18,42 +12,21 @@ pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of perf_event_attr__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of perf_event_attr__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: perf_event_attr__bindgen_ty_1::b", + ][::std::mem::offset_of!(perf_event_attr__bindgen_ty_1, b) - 0usize]; + [ + "Offset of field: perf_event_attr__bindgen_ty_1::c", + ][::std::mem::offset_of!(perf_event_attr__bindgen_ty_1, c) - 0usize]; +}; impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -68,42 +41,17 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { write!(f, "perf_event_attr__bindgen_ty_1 {{ union }}") } } -#[test] -fn bindgen_test_layout_perf_event_attr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(perf_event_attr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(perf_event_attr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of perf_event_attr"][::std::mem::size_of::() - 12usize]; + ["Alignment of perf_event_attr"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: perf_event_attr::type_", + ][::std::mem::offset_of!(perf_event_attr, type_) - 0usize]; + [ + "Offset of field: perf_event_attr::a", + ][::std::mem::offset_of!(perf_event_attr, a) - 4usize]; +}; impl Default for perf_event_attr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -118,7 +66,9 @@ impl ::std::fmt::Debug for perf_event_attr { write!( f, "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", - self.type_, self.a, self.__bindgen_anon_1 + self.type_, + self.a, + self.__bindgen_anon_1, ) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index a0cc87ff2c62533d89e69ab787e3c5fd5fcaa249..d58627861494fcf8dfefab50a2adec6df5b9fe95 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -1,38 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Instance { pub val: [u32; 50usize], } #[test] fn bindgen_test_layout_Instance() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 200usize, - concat!("Size of: ", stringify!(Instance)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Instance)) - ); + assert_eq!(::std::mem::size_of::(), 200usize, "Size of Instance"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Instance"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Instance), - "::", - stringify!(val) - ) + "Offset of field: Instance::val", ); } impl Default for Instance { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index 5cebc9b8e68b00fd691a718ec2dbe590bf1f879b..13ddfd5adac04fde08777aba2740b5ad9f49be4c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] pub struct Opaque { @@ -12,16 +6,8 @@ pub struct Opaque { } #[test] fn bindgen_test_layout_Opaque() { - assert_eq!( - ::std::mem::size_of::(), - 164usize, - concat!("Size of: ", stringify!(Opaque)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Opaque)) - ); + assert_eq!(::std::mem::size_of::(), 164usize, "Size of Opaque"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Opaque"); } impl Default for Opaque { fn default() -> Self { @@ -43,28 +29,14 @@ pub struct OpaqueUser { } #[test] fn bindgen_test_layout_OpaqueUser() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 164usize, - concat!("Size of: ", stringify!(OpaqueUser)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OpaqueUser)) - ); + assert_eq!(::std::mem::size_of::(), 164usize, "Size of OpaqueUser"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of OpaqueUser"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(OpaqueUser), - "::", - stringify!(opaque) - ) + "Offset of field: OpaqueUser::opaque", ); } impl Default for OpaqueUser { diff --git a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs index fe3790c2e0e06b676f1d9305b24079a6b5190911..6ce99e509319bf8fa1534daaba972cd9e9870699 100644 --- a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs @@ -1,44 +1,23 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - -/// Because this type contains a blocklisted type, it should not derive -/// Default. Instead, we should emit a `mem::zeroed` implementation. +/** Because this type contains a blocklisted type, it should not derive + Default. Instead, we should emit a `mem::zeroed` implementation.*/ #[repr(C)] pub struct ShouldNotDeriveDefault { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDeriveDefault() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveDefault)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveDefault), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ShouldNotDeriveDefault", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDeriveDefault", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDeriveDefault::a", + ][::std::mem::offset_of!(ShouldNotDeriveDefault, a) - 0usize]; +}; impl Default for ShouldNotDeriveDefault { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs index 9da0a40ae6cbc006ea71ffd13646b84e155db789..f4b09474aedbe48d7ada826d27cf403ddb47f6f9 100644 --- a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type my_fun_t = ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_int, @@ -30,34 +24,12 @@ pub type my_fun_t = ::std::option::Option< pub struct Foo { pub callback: my_fun_t, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(callback) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::callback"][::std::mem::offset_of!(Foo, callback) - 0usize]; +}; pub type my_fun2_t = ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_int, @@ -79,31 +51,9 @@ pub type my_fun2_t = ::std::option::Option< pub struct Bar { pub callback: my_fun2_t, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(callback) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::callback"][::std::mem::offset_of!(Bar, callback) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs index c677b15e49b7ad05749c122cf931b5b1027ace2f..c52047e8b839d180c2d2e8f8c82e5c7212cadc5f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -1,43 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Hash. #[repr(C)] pub struct ShouldNotDeriveHash { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDeriveHash() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveHash)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveHash), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ShouldNotDeriveHash", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDeriveHash", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDeriveHash::a", + ][::std::mem::offset_of!(ShouldNotDeriveHash, a) - 0usize]; +}; impl Default for ShouldNotDeriveHash { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs index 868bf9f2a9362bc3e07292ed84bd4301d726421b..e3223f08d75bcf7ce6c3f692e5a1a5ace9dd61d7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs @@ -1,49 +1,24 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blocklisted { t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } - -/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, -/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it. +/** This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, + causing us to conservatively avoid deriving hash/Eq/PartialEq for it.*/ #[repr(C)] pub struct AllowlistedOne { pub a: Blocklisted<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_AllowlistedOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedOne)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedOne)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedOne), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistedOne"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistedOne"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistedOne::a", + ][::std::mem::offset_of!(AllowlistedOne, a) - 0usize]; +}; impl Default for AllowlistedOne { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -58,32 +33,14 @@ impl Default for AllowlistedOne { pub struct AllowlistedTwo { pub b: Blocklisted, } -#[test] -fn bindgen_test_layout_AllowlistedTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedTwo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedTwo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedTwo), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AllowlistedTwo"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistedTwo"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistedTwo::b", + ][::std::mem::offset_of!(AllowlistedTwo, b) - 0usize]; +}; impl Default for AllowlistedTwo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 78c8449b58df26243048d1a5eaae7e365d0218dd..2d66015fe72d19fc1bb3ee5401df03ef13e54788 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] @@ -17,60 +11,22 @@ pub struct foo__bindgen_ty_1 { pub a: f32, pub b: f32, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs index a3f6013b2ab082a1d74a6588ce7dae4611d0abf2..254a50b3e32aeed853ae1ad462e255dc53945206 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -1,34 +1,13 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { pub bar: [f32; 3usize], } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 12usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 06c8da1bada3f84aa65a7e0e4c2cbfacb34b16c0..2588a49eed9aa517bd2045d269d34a8196bafb94 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -41,59 +35,30 @@ pub struct test { pub a: ::std::os::raw::c_int, pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of test"][::std::mem::size_of::() - 4usize]; + ["Alignment of test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test::a"][::std::mem::offset_of!(test, a) - 0usize]; + [ + "Offset of field: test::zero_length_array", + ][::std::mem::offset_of!(test, zero_length_array) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct test2 { pub a: ::std::os::raw::c_int, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test2() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of test2"][::std::mem::size_of::() - 4usize]; + ["Alignment of test2"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test2::a"][::std::mem::offset_of!(test2, a) - 0usize]; + [ + "Offset of field: test2::incomplete_array", + ][::std::mem::offset_of!(test2, incomplete_array) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct test3 { @@ -101,16 +66,15 @@ pub struct test3 { pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test3() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of test3"][::std::mem::size_of::() - 4usize]; + ["Alignment of test3"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test3::a"][::std::mem::offset_of!(test3, a) - 0usize]; + [ + "Offset of field: test3::zero_length_array", + ][::std::mem::offset_of!(test3, zero_length_array) - 4usize]; + [ + "Offset of field: test3::incomplete_array", + ][::std::mem::offset_of!(test3, incomplete_array) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 3efd55c9d219f9596ab9697eba828fe1bbe4ab8e..5240d969dbe3b26ea4cbb7957fb02daa0526cf2c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -1,42 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct ConstPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ConstPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrMutObj)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrMutObj)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrMutObj), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ConstPtrMutObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of ConstPtrMutObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ConstPtrMutObj::bar", + ][::std::mem::offset_of!(ConstPtrMutObj, bar) - 0usize]; +}; impl Default for ConstPtrMutObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -51,32 +27,14 @@ impl Default for ConstPtrMutObj { pub struct MutPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_MutPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrMutObj)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrMutObj)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrMutObj), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of MutPtrMutObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of MutPtrMutObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: MutPtrMutObj::bar", + ][::std::mem::offset_of!(MutPtrMutObj, bar) - 0usize]; +}; impl Default for MutPtrMutObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -91,32 +49,14 @@ impl Default for MutPtrMutObj { pub struct MutPtrConstObj { pub bar: *const ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_MutPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrConstObj)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrConstObj)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrConstObj), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of MutPtrConstObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of MutPtrConstObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: MutPtrConstObj::bar", + ][::std::mem::offset_of!(MutPtrConstObj, bar) - 0usize]; +}; impl Default for MutPtrConstObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -131,32 +71,16 @@ impl Default for MutPtrConstObj { pub struct ConstPtrConstObj { pub bar: *const ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ConstPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrConstObj)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrConstObj)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrConstObj), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ConstPtrConstObj"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ConstPtrConstObj", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ConstPtrConstObj::bar", + ][::std::mem::offset_of!(ConstPtrConstObj, bar) - 0usize]; +}; impl Default for ConstPtrConstObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs index 5e07a6111548442e0ff81f2719de2428bfef3fdc..af09533cca21d8dafc353cd327b9fa97d1fe441b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd. #[repr(C)] #[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub data: T, pub b: f32, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index b2e2d8d088995e43dc30443c975ad77eca6a152e..10ed002e6e35ad0375046a8575054d7e32505fff 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Template definition that doesn't contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct foo { - pub data: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub data: T, } impl Default for foo { fn default() -> Self { @@ -27,27 +21,12 @@ impl Default for foo { pub struct IntStr { pub a: foo<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_IntStr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(IntStr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(IntStr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of IntStr"][::std::mem::size_of::() - 4usize]; + ["Alignment of IntStr"][::std::mem::align_of::() - 4usize]; + ["Offset of field: IntStr::a"][::std::mem::offset_of!(IntStr, a) - 0usize]; +}; impl Default for IntStr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -63,32 +42,12 @@ impl Default for IntStr { pub struct FloatStr { pub a: foo, } -#[test] -fn bindgen_test_layout_FloatStr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(FloatStr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(FloatStr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FloatStr), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of FloatStr"][::std::mem::size_of::() - 4usize]; + ["Alignment of FloatStr"][::std::mem::align_of::() - 4usize]; + ["Offset of field: FloatStr::a"][::std::mem::offset_of!(FloatStr, a) - 0usize]; +}; impl Default for FloatStr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -98,38 +57,21 @@ impl Default for FloatStr { } } } -#[test] -fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(foo<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(foo<::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!("Size of template specialization: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(foo) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: foo_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: foo_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: foo_open0_float_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: foo_open0_float_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs index c772c0b90e3ce7ac31f7f867760d48281e40a465..d24981061c31983766de348995b837eeef6148e1 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -1,44 +1,23 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - -/// Because this type contains a blocklisted type, it should not derive -/// PartialEq. +/** Because this type contains a blocklisted type, it should not derive + PartialEq.*/ #[repr(C)] pub struct ShouldNotDerivePartialEq { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ShouldNotDerivePartialEq", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDerivePartialEq", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::a", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, a) - 0usize]; +}; impl Default for ShouldNotDerivePartialEq { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs index 16d4381f86e127a4798b2784d07b215b5675b156..c4eb08df6018c06a66541c428f6fa5b61cbfca8b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -17,19 +11,15 @@ pub struct rte_mbuf { pub struct rte_mbuf__bindgen_ty_1 { pub bindgen_union_field: [u8; 0usize], } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_1", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; +}; impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -39,19 +29,11 @@ impl Default for rte_mbuf__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf)) - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_mbuf"][::std::mem::size_of::() - 0usize]; + ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; +}; impl Default for rte_mbuf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs index 840720f28d11de50a802e39ae26f58a604b6ffc3..d0768416ec8fbda0fd8fa03c7ac446c22cc3b39e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct Base { @@ -12,28 +6,14 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(Base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)) - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of Base"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Base"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(large) - ) + "Offset of field: Base::large", ); } impl Default for Base { @@ -60,12 +40,12 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)) + "Size of ShouldDerivePartialEq", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) + "Alignment of ShouldDerivePartialEq", ); } impl Default for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index cb9781dea6c7f8e95d6394f37ea9be79730edae0..7c325620cf0ecdf71fd1555f691d4e9f2b350f1c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,30 +92,14 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 204usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( - ::std::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + "Offset of field: C::large_array", ); } impl Default for C { @@ -137,17 +113,14 @@ impl Default for C { } impl ::std::cmp::PartialEq for C { fn eq(&self, other: &C) -> bool { - self.a() == other.a() && - self.b() == other.b() && - &self.large_array[..] == &other.large_array[..] + self.a() == other.a() && self.b() == other.b() + && &self.large_array[..] == &other.large_array[..] } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -158,9 +131,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -170,20 +141,26 @@ impl C { } } #[inline] - pub fn new_bitfield_1( - a: bool, - b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs index 620b40faf9b560b0b43442e54f3b6e87affe00bf..3a7639f9de47960ec5ac71133a2e2c38011c4901 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] #[derive(Copy, Clone)] pub struct C { @@ -14,30 +7,14 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::core::mem::size_of::(), 1680usize, "Size of C"); + assert_eq!(::core::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( - ::core::mem::size_of::(), - 1680usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + "Offset of field: C::large_array", ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs index e0d3c0629e4ffa032f55c4546ac23e1dddead419..3e48e5d8cea22938c95bbb08e9946aa658af6139 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub b: *mut a, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::b"][::std::mem::offset_of!(Bar, b) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -50,19 +29,11 @@ pub struct c { pub union c__bindgen_ty_1 { pub _address: u8, } -#[test] -fn bindgen_test_layout_c__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of c__bindgen_ty_1"][::std::mem::size_of::() - 1usize]; + ["Alignment of c__bindgen_ty_1"][::std::mem::align_of::() - 1usize]; +}; impl Default for c__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -72,19 +43,11 @@ impl Default for c__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_c() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of c"][::std::mem::size_of::() - 1usize]; + ["Alignment of c"][::std::mem::align_of::() - 1usize]; +}; impl Default for c { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -99,27 +62,12 @@ impl Default for c { pub struct a { pub d: c, } -#[test] -fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of a"][::std::mem::size_of::() - 1usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::d"][::std::mem::offset_of!(a, d) - 0usize]; +}; impl Default for a { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs index 5ffd0bcd3ba409341e32fb46cd09accc38a5f73c..0365c765eb56660365a080987565f17177a47e9e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Deriving PartialEq for rust unions is not supported. #[repr(C)] #[derive(Copy, Clone)] @@ -12,42 +6,21 @@ pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ShouldNotDerivePartialEq", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ShouldNotDerivePartialEq", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::a", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, a) - 0usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::b", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, b) - 0usize]; +}; impl Default for ShouldNotDerivePartialEq { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index a53b9ba8e63f2ee7c4e0dd853089d625a79d7eee..f120f4fc12976be4b28ac254b2bd48e98e8a672c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -58,38 +52,27 @@ pub struct ShouldDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 152usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)) + "Size of ShouldDerivePartialEq", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) + "Alignment of ShouldDerivePartialEq", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a) - ) + "Offset of field: ShouldDerivePartialEq::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b) - ) + "Offset of field: ShouldDerivePartialEq::b", ); } impl Clone for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/disable-namespacing.rs b/bindgen-tests/tests/expectations/tests/disable-namespacing.rs index 626bb060c57d1359f7964fa00f9ccc3840f62aee..4d9b6a082d0389aab00fcf212e95cc9d11f54e91 100644 --- a/bindgen-tests/tests/expectations/tests/disable-namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/disable-namespacing.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Baz = ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index ce8a01ada3954555784cddcdbef814ffdd12cba8..68c729b735f767968910855c5ab61f6ffa19aa6d 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { @@ -33,149 +27,55 @@ pub struct bar1__bindgen_ty_1__bindgen_ty_1 { pub struct bar4 { pub x4: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_bar4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar4)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) - ); -} -#[test] -fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(x3) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b4) - ) - ); -} -#[test] -fn bindgen_test_layout_bar1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(x2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(b3) - ) - ); -} -#[test] -fn bindgen_test_layout_bar1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bar1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar4"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar4"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar4::x4"][::std::mem::offset_of!(bar4, x4) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of bar1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of bar1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar1__bindgen_ty_1__bindgen_ty_1::x3", + ][::std::mem::offset_of!(bar1__bindgen_ty_1__bindgen_ty_1, x3) - 0usize]; + [ + "Offset of field: bar1__bindgen_ty_1__bindgen_ty_1::b4", + ][::std::mem::offset_of!(bar1__bindgen_ty_1__bindgen_ty_1, b4) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of bar1__bindgen_ty_1", + ][::std::mem::size_of::() - 12usize]; + [ + "Alignment of bar1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar1__bindgen_ty_1::x2", + ][::std::mem::offset_of!(bar1__bindgen_ty_1, x2) - 0usize]; + [ + "Offset of field: bar1__bindgen_ty_1::b3", + ][::std::mem::offset_of!(bar1__bindgen_ty_1, b3) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar1"][::std::mem::size_of::() - 16usize]; + ["Alignment of bar1"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar1::x1"][::std::mem::offset_of!(bar1, x1) - 0usize]; + ["Offset of field: bar1::b2"][::std::mem::offset_of!(bar1, b2) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 16usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::b1"][::std::mem::offset_of!(foo, b1) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { @@ -191,79 +91,32 @@ pub struct _bindgen_ty_1__bindgen_ty_1 { pub struct baz { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) - ); -} -#[test] -fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(anon2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: baz::x"][::std::mem::offset_of!(baz, x) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of _bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>() - 4usize]; + [ + "Alignment of _bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1__bindgen_ty_1::b", + ][::std::mem::offset_of!(_bindgen_ty_1__bindgen_ty_1, b) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1::anon2", + ][::std::mem::offset_of!(_bindgen_ty_1, anon2) - 0usize]; +}; extern "C" { pub static mut anon1: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 515f496b8703f6d5e263ab8553ae021682047d1b..60636280e41e646faf036051ba5f3facd9e90f88 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -55,29 +49,10 @@ pub struct Foo { pub baz: __BindgenUnionField<::std::os::raw::c_uint>, pub bindgen_union_field: u32, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; + ["Offset of field: Foo::baz"][::std::mem::offset_of!(Foo, baz) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 721d71e259db74e2d95fa055acabfb376c400feb..707c2d56bc22ede7ba11d1f441d919518dcfb444 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,8 +93,7 @@ pub struct WithBitfield { impl WithBitfield { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } @@ -116,8 +107,7 @@ pub struct WithBitfieldAndAttrPacked { impl WithBitfieldAndAttrPacked { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } @@ -131,8 +121,7 @@ pub struct WithBitfieldAndPacked { impl WithBitfieldAndPacked { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs index 4f9081adf4ed1d16cfcc1e518c7fd59a9140d89b..29ca6d6acf6534bc71b57f57eaffdcf06176399a 100644 --- a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs +++ b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs @@ -1,41 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct WouldBeCopyButWeAreNotDerivingCopy { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", - stringify!(x) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of WouldBeCopyButWeAreNotDerivingCopy", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WouldBeCopyButWeAreNotDerivingCopy", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WouldBeCopyButWeAreNotDerivingCopy::x", + ][::std::mem::offset_of!(WouldBeCopyButWeAreNotDerivingCopy, x) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs index 90287159580baba1a45af4f3ffacd62ec74c6aa4..972da871d3128f75b492b02713b5de7c44087c95 100644 --- a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs +++ b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs @@ -1,79 +1,42 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Doggo { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Doggo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Doggo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Doggo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Doggo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Doggo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Doggo::x"][::std::mem::offset_of!(Doggo, x) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Null { pub _address: u8, } -#[test] -fn bindgen_test_layout_Null() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Null)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Null)) - ); -} -/// This type is an opaque union. Unions can't derive anything interesting like -/// Debug or Default, even if their layout can, because it would require knowing -/// which variant is in use. Opaque unions still end up as a `union` in the Rust -/// bindings, but they just have one variant. Even so, can't derive. We should -/// probably emit an opaque struct for opaque unions... but until then, we have -/// this test to make sure that opaque unions don't derive and still compile. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Null"][::std::mem::size_of::() - 1usize]; + ["Alignment of Null"][::std::mem::align_of::() - 1usize]; +}; +/** This type is an opaque union. Unions can't derive anything interesting like + Debug or Default, even if their layout can, because it would require knowing + which variant is in use. Opaque unions still end up as a `union` in the Rust + bindings, but they just have one variant. Even so, can't derive. We should + probably emit an opaque struct for opaque unions... but until then, we have + this test to make sure that opaque unions don't derive and still compile.*/ #[repr(C)] #[repr(align(4))] #[derive(Copy, Clone)] pub union DoggoOrNull { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_DoggoOrNull() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(DoggoOrNull)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(DoggoOrNull)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of DoggoOrNull"][::std::mem::size_of::() - 4usize]; + ["Alignment of DoggoOrNull"][::std::mem::align_of::() - 4usize]; +}; impl Default for DoggoOrNull { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs index 85e45392530b489e60fdc84e3d65738fb0d898e0..d521bcc17b5710500f4a2bd728e71b9e24a66f1d 100644 --- a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 829022a279d385e7f249c2d0986eec27cc9992e9..85f28dcca6de57f4b85471070fd7afcc652753ba 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BitStream { pub _address: u8, } -#[test] -fn bindgen_test_layout_BitStream() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BitStream)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BitStream)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of BitStream"][::std::mem::size_of::() - 1usize]; + ["Alignment of BitStream"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN9BitStream5WriteEPKcj"] pub fn BitStream_Write( diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs index 8e7c895bf0bcd48246b014c25b20e2e469b69072..775a21ac30f3de56a7ac10ca706cb198642cc06b 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -18,46 +12,13 @@ pub mod root { pub foo: ::std::os::raw::c_int, pub baz: bool, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::foo"][::std::mem::offset_of!(Bar, foo) - 0usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 4usize]; + }; } pub mod bar { #[allow(unused_imports)] @@ -67,34 +28,12 @@ pub mod root { pub struct Foo { pub ptr: *mut root::foo::Bar, } - #[test] - fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(ptr) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::ptr"][::std::mem::offset_of!(Foo, ptr) - 0usize]; + }; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs index 0bbceac8e27bf45992b3c97c93d920cc3937caf5..c652d151b892ad7db75a960435c2a16b2a23c05c 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs b/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs index 3b3405db5cb788483960fb84b7ca4476b317590c..2f676374ae882e411bef1edbe53840a640f859c8 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index c834752e3c7eec4343cf9fe89b5344310cdb4911..a1fb1b0cc18f65a95da876f224e413b04adb4137 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -1,11 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: unsafe extern "C" fn( @@ -22,27 +15,21 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym)?; let baz = __library.get(b"baz\0").map(|sym| *sym)?; - Ok(TestLib { - __library, - foo, - baz, - }) + Ok(TestLib { __library, foo, baz }) } #[must_use] - /// @brief A function - /// - /// @param x - /// @param y - /// @return int + /** @brief A function + + @param x + @param y + @return int*/ pub unsafe fn foo( &self, x: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index e46ffd49e0d49408e7f40bc038862f83784589ee..5c929ffc3df37f76fe9048b97324f21568d0137f 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -1,11 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: unsafe extern "C" fn( @@ -25,9 +18,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -49,10 +40,7 @@ impl TestLib { ) -> ::std::os::raw::c_int { (self.foo)(x, y) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar)(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index cae5bd6937e3a6ae7f896db363aa6bbd3f34c193..9a4cfaf570bbbff5a7621f85a1a95e9342900dd4 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -1,11 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: Result< @@ -16,9 +9,7 @@ pub struct TestLib { ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< @@ -34,9 +25,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -58,10 +47,7 @@ impl TestLib { ) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x, y) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 06e67ed7910543fe5f0697ce2b37aaca6f7d4855..65f079bedecc17b2ac66575dd554f435e74fbf71 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -1,11 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: Result< @@ -22,25 +15,16 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let foo1 = __library.get(b"foo1\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - foo1, - }) + Ok(TestLib { __library, foo, foo1 }) } - pub unsafe fn foo( - &self, - x: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: ::std::os::raw::c_int) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn foo1(&self, x: f32) -> f32 { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs new file mode 100644 index 0000000000000000000000000000000000000000..a96efbe54628c3c6591119ab72b8004cfc4d4b93 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: *mut ::std::os::raw::c_int, + pub baz: *mut *mut ::std::os::raw::c_int, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym)?; + let baz = __library + .get::<*mut *mut ::std::os::raw::c_int>(b"baz\0") + .map(|sym| *sym)?; + Ok(TestLib { __library, foo, baz }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + self.foo + } + pub unsafe fn baz(&self) -> *mut *mut ::std::os::raw::c_int { + self.baz + } +} diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs new file mode 100644 index 0000000000000000000000000000000000000000..ced70dbdbabe214d4d46633b15f46cf3a49c64c8 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, + pub baz: Result<*mut *mut ::std::os::raw::c_int, ::libloading::Error>, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym); + let baz = __library + .get::<*mut *mut ::std::os::raw::c_int>(b"baz\0") + .map(|sym| *sym); + Ok(TestLib { __library, foo, baz }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + *self.foo.as_ref().expect("Expected variable, got error.") + } + pub unsafe fn baz(&self) -> *mut *mut ::std::os::raw::c_int { + *self.baz.as_ref().expect("Expected variable, got error.") + } +} diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs new file mode 100644 index 0000000000000000000000000000000000000000..3f29e73814678805149f351c95d325f85b6443c9 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, + pub bar: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym); + let bar = __library.get::<*mut ::std::os::raw::c_int>(b"bar\0").map(|sym| *sym); + Ok(TestLib { __library, foo, bar }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + *self.foo.as_ref().expect("Expected variable, got error.") + } + pub unsafe fn bar(&self) -> *mut ::std::os::raw::c_int { + *self.bar.as_ref().expect("Expected variable, got error.") + } +} diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 97bb67abdcaf9f7ee792ada0ea5983480018a38b..e65176b863600cdc3347a9f444c4889928f7a755 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -1,30 +1,16 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bazz: Result< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ... - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int, ::libloading::Error, >, } @@ -36,9 +22,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -53,16 +37,10 @@ impl TestLib { bazz, }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } - pub unsafe fn baz( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn baz(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.baz.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index af482ad93805bc5c430e76d67a909880124fa8ff..776da1ca5febe524475f7191a4544cc9ca8945f5 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct X { pub _x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_X() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(X)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(X)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of X"][::std::mem::size_of::() - 4usize]; + ["Alignment of X"][::std::mem::align_of::() - 4usize]; + ["Offset of field: X::_x"][::std::mem::offset_of!(X, _x) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1X13some_functionEv"] pub fn X_some_function(this: *mut X); @@ -59,19 +38,14 @@ impl X { __bindgen_tmp.assume_init() } } -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, } @@ -83,31 +57,19 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - bar, - }) + Ok(TestLib { __library, foo, bar }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 098ffa24ce5849d6afdcd0ec2a58688e300abacd..93c636ebff01042f5e2904b8b91eb7ca0e3189d2 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub _x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::_x"][::std::mem::offset_of!(A, _x) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A13some_functionEv"] pub fn A_some_function(this: *mut A); @@ -59,13 +38,10 @@ impl A { __bindgen_tmp.assume_init() } } -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bar: Result, @@ -78,25 +54,16 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - bar, - }) + Ok(TestLib { __library, foo, bar }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar(&self) { diff --git a/bindgen-tests/tests/expectations/tests/elaborated.rs b/bindgen-tests/tests/expectations/tests/elaborated.rs index 4741601640f0c5bb8fa3c26d55e857bf2256bef4..80bf30f89af7246ee06e3744cb5a30eb6fa6f053 100644 --- a/bindgen-tests/tests/expectations/tests/elaborated.rs +++ b/bindgen-tests/tests/expectations/tests/elaborated.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type whatever_whatever_t = ::std::os::raw::c_int; extern "C" { #[link_name = "\u{1}_Z9somethingPKi"] diff --git a/bindgen-tests/tests/expectations/tests/empty-enum.rs b/bindgen-tests/tests/expectations/tests/empty-enum.rs index fe188b3e3e3c9fc1ec6b330843af825e4f16ea12..fda6f581df3bdba41261ff572706ef3956564695 100644 --- a/bindgen-tests/tests/expectations/tests/empty-enum.rs +++ b/bindgen-tests/tests/expectations/tests/empty-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type EmptyConstified = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/empty-union.rs b/bindgen-tests/tests/expectations/tests/empty-union.rs index c21ae2f01fb9904e45ac91a064b23407e2784a2b..de0f806eb527fe041e5447b9961a5bda46f8f5ca 100644 --- a/bindgen-tests/tests/expectations/tests/empty-union.rs +++ b/bindgen-tests/tests/expectations/tests/empty-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union a__bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs b/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs index aa751f77e68b3288a31c65083c84d272336bb9c7..db5764ab2569145a5e53be0b6cbd77ce8602785b 100644 --- a/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs +++ b/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type __void_t = ::std::os::raw::c_void; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 4c0757667e184f34a55fa6f18223bac5a860de23..58b8bf092f61c5052ee8a133d520e84f10cc7f64 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -41,32 +35,12 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index ddce26c20a87dd09b10d93e66a108e26faa8e645..af51864c2c5ad3774873ad3000d83d57fdd86158 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -13,32 +7,12 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index ae026d8bca139dd3f1397a8fc919fe289610ceda..cc09d49425c4a40c270e96cf6387a938b298506b 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -15,32 +9,12 @@ pub mod foo__bindgen_ty_1 { pub const FOO_A: Type = 0; pub const FOO_B: Type = 1; } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index c3b728f826d93c0563c7f985e1d20c11f877d3e5..f9a99166de63401bff8684e43370a7d4f9966ae8 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -18,32 +12,12 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs index 3be0438e5b3731ee639e17ae8212d4274c03a4f3..ba73a8ea3eceefebd69a3332bc583645cb657f65 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs @@ -1,20 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl B { /// Document field with three slashes pub const VAR_A: B = B(0); } impl B { - /// Document field with preceeding star + /// Document field with preceding star pub const VAR_B: B = B(1); } impl B { - /// Document field with preceeding exclamation + /// Document field with preceding exclamation pub const VAR_C: B = B(2); } impl B { @@ -26,10 +20,10 @@ impl B { pub const VAR_E: B = B(4); } impl B { - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const VAR_F: B = B(5); } impl ::std::ops::BitOr for B { diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs index 60d6b9f4d95525d6220c2d1ee0121aa139740cc4..2b18b35df053e678697db3e11da35253d186cde5 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs @@ -1,26 +1,20 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod B { /// Document enum pub type Type = ::std::os::raw::c_uint; /// Document field with three slashes pub const VAR_A: Type = 0; - /// Document field with preceeding star + /// Document field with preceding star pub const VAR_B: Type = 1; - /// Document field with preceeding exclamation + /// Document field with preceding exclamation pub const VAR_C: Type = 2; ///< Document field with following star pub const VAR_D: Type = 3; ///< Document field with following exclamation pub const VAR_E: Type = 4; - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const VAR_F: Type = 5; } diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs index e7208a9db6ff0fbf909dc03b5fa2b796810558f7..3eec0759c5a9f20499c8fad4bbb94df7749a62aa 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs @@ -1,27 +1,21 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] /// Document enum #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum B { /// Document field with three slashes VAR_A = 0, - /// Document field with preceeding star + /// Document field with preceding star VAR_B = 1, - /// Document field with preceeding exclamation + /// Document field with preceding exclamation VAR_C = 2, ///< Document field with following star VAR_D = 3, ///< Document field with following exclamation VAR_E = 4, - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ VAR_F = 5, } diff --git a/bindgen-tests/tests/expectations/tests/enum-doc.rs b/bindgen-tests/tests/expectations/tests/enum-doc.rs index b5d14b3cf0788978b71e509c6303a6b9c85fb6ae..98a7eed8f8eb72f8e891f10a91dfbb29156d1e28 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc.rs @@ -1,24 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Document field with three slashes pub const B_VAR_A: B = 0; -/// Document field with preceeding star +/// Document field with preceding star pub const B_VAR_B: B = 1; -/// Document field with preceeding exclamation +/// Document field with preceding exclamation pub const B_VAR_C: B = 2; ///< Document field with following star pub const B_VAR_D: B = 3; ///< Document field with following exclamation pub const B_VAR_E: B = 4; -/// Document field with preceeding star, with a loong long multiline -/// comment. -/// -/// Very interesting documentation, definitely. +/** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const B_VAR_F: B = 5; /// Document enum pub type B = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index 33c7b5c7ccddd9864b19cf909937664f10209c37..b728dfc8981b9e3f6bfa5474c6269bc5f6d3910a 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -18,32 +12,12 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-translate-type.rs b/bindgen-tests/tests/expectations/tests/enum-translate-type.rs index 89e6003e447f2b73e1760b01d678f87862efcc5e..2431e48d5bd1e44c31785fc20dad11af809ccfad 100644 --- a/bindgen-tests/tests/expectations/tests/enum-translate-type.rs +++ b/bindgen-tests/tests/expectations/tests/enum-translate-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const my_enum1_A: my_enum1 = 0; pub type my_enum1 = u32; pub const my_enum2_B: my_enum2 = -1; diff --git a/bindgen-tests/tests/expectations/tests/enum-typedef.rs b/bindgen-tests/tests/expectations/tests/enum-typedef.rs index dc78eb11eb18d4ff0bc5b3819b4e2e9211b4449a..772184b39f5acf6e92d11ff06cd2567396c9de6c 100644 --- a/bindgen-tests/tests/expectations/tests/enum-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/enum-typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Enum_Variant: Enum = 0; pub type Enum = i16; pub type TypedefFirst = i16; diff --git a/bindgen-tests/tests/expectations/tests/enum-undefault.rs b/bindgen-tests/tests/expectations/tests/enum-undefault.rs index e5618b914852265d64da06604ce976318ee7cfed..01a7aa3cea630980e6e0c29ed35dd28891c26a7a 100644 --- a/bindgen-tests/tests/expectations/tests/enum-undefault.rs +++ b/bindgen-tests/tests/expectations/tests/enum-undefault.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs b/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs index d927657492e023ea234d787b95d73cacf245d3a8..a661ca833bce2e3b65759f9c1f9e417932319734 100644 --- a/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs +++ b/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/**

-///
-/// -/// Should see PASS below. + Should see PASS below.*/ pub const OGRErr_PASS: OGRErr = 0; -///
-/// -/// Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below. +/**
+ + Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below.*/ pub const OGRErr_OGRERR_NONE: OGRErr = 1; ///
pub type OGRErr = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs index 65b734a32598402e53ef691bb5c9282d81825804..820182125a3c8d6745b21a899b4bc6a220f3208c 100644 --- a/bindgen-tests/tests/expectations/tests/enum.rs +++ b/bindgen-tests/tests/expectations/tests/enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -13,32 +7,12 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum_alias.rs b/bindgen-tests/tests/expectations/tests/enum_alias.rs index ad62d16fa294e609ca331aea16f4608a63ee9752..0d297688373fc1876333194a659b026c443c4cdc 100644 --- a/bindgen-tests/tests/expectations/tests/enum_alias.rs +++ b/bindgen-tests/tests/expectations/tests/enum_alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index f414812b82afa12e0f0a862c9a2c18832b6497a5..18e1ad8e367c1d9090ca01be6a5434f9e52b8c6d 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] @@ -23,27 +17,12 @@ pub struct C { pub vtable_: *const C__bindgen_vtable, pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 16usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::i"][::std::mem::offset_of!(C, i) - 8usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum_dupe.rs b/bindgen-tests/tests/expectations/tests/enum_dupe.rs index 869375bbfd15c98a074a736f00c38552f1cc5b74..3ee4c68cbd44cbd7cb4f0c1fb8d9297456a63dc9 100644 --- a/bindgen-tests/tests/expectations/tests/enum_dupe.rs +++ b/bindgen-tests/tests/expectations/tests/enum_dupe.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Dupe: Foo = Foo::Bar; } diff --git a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs index 29bc5d8cfcabd7712823938649510c9cfee486fc..1f3dd36f96625b0f38be72962dbefe0122c814a9 100644 --- a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs +++ b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { @@ -49,10 +43,8 @@ pub type MyType = bool; pub enum BoolEnumsAreFun2 { Value2 = 1, } -pub const AnonymousVariantOne: _bindgen_ty_1 = - _bindgen_ty_1::AnonymousVariantOne; -pub const AnonymousVariantTwo: _bindgen_ty_1 = - _bindgen_ty_1::AnonymousVariantTwo; +pub const AnonymousVariantOne: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantOne; +pub const AnonymousVariantTwo: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantTwo; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs index 0c833b6640357768fb2c25531f190b9591df2b59..8f310572b6552ca1802ee8192cff592987b37d7f 100644 --- a/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; pub type Foo = ::std::os::raw::c_uchar; diff --git a/bindgen-tests/tests/expectations/tests/enum_in_template.rs b/bindgen-tests/tests/expectations/tests/enum_in_template.rs index c4c06a373315aca2afc607948431f951a02ed2ec..e54a97b5f455d9c8ca20a2951366245642843fe1 100644 --- a/bindgen-tests/tests/expectations/tests/enum_in_template.rs +++ b/bindgen-tests/tests/expectations/tests/enum_in_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs index 75dce30c0ee8d5f262edccb2ffc1c3b58c786490..b71923e10fa7000087c724aa0b7b3a5652861252 100644 --- a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct std_fbstring_core { diff --git a/bindgen-tests/tests/expectations/tests/enum_negative.rs b/bindgen-tests/tests/expectations/tests/enum_negative.rs index 02b4baed59b9d0d4a7c138f65705add8cd569b68..f946e0f0449240e1d84956672167a3d3ba77fb1d 100644 --- a/bindgen-tests/tests/expectations/tests/enum_negative.rs +++ b/bindgen-tests/tests/expectations/tests/enum_negative.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_packed.rs b/bindgen-tests/tests/expectations/tests/enum_packed.rs index 89b0da461d555a2f37cba1602c5784faea66b7c3..d4ec2192d1b79a88894ef70e09358db27f1e2863 100644 --- a/bindgen-tests/tests/expectations/tests/enum_packed.rs +++ b/bindgen-tests/tests/expectations/tests/enum_packed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs new file mode 100644 index 0000000000000000000000000000000000000000..79004238fc9e5519c0de1fc9458790e98295fec5 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -0,0 +1,3 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow(overflowing_literals)] +pub const a: u32 = 4294967291; diff --git a/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs b/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs index 3376bfc6b370dc4bb6af68056a97fede88e7eb46..b9b2709cfa5e3c218ece6eba7364a44bf23b3037 100644 --- a/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs +++ b/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct e { diff --git a/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs b/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs index 576bb721c5ed299f853d7917e87bc6c0014eebfe..fccd2ad5d7e6e5271c39ea3b55028db162310194 100644 --- a/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { diff --git a/bindgen-tests/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs index a6ea7671292c4142257657cf34c6ff163780403c..ec21399106a7355d3989c13e7a8d70f42c275c85 100644 --- a/bindgen-tests/tests/expectations/tests/explicit-padding.rs +++ b/bindgen-tests/tests/expectations/tests/explicit-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct pad_me { @@ -14,52 +8,14 @@ pub struct pad_me { pub third: u16, pub __bindgen_padding_1: [u8; 2usize], } -#[test] -fn bindgen_test_layout_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(pad_me)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pad_me)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(first) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(second) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(third) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of pad_me"][::std::mem::size_of::() - 12usize]; + ["Alignment of pad_me"][::std::mem::align_of::() - 4usize]; + ["Offset of field: pad_me::first"][::std::mem::offset_of!(pad_me, first) - 0usize]; + ["Offset of field: pad_me::second"][::std::mem::offset_of!(pad_me, second) - 4usize]; + ["Offset of field: pad_me::third"][::std::mem::offset_of!(pad_me, third) - 8usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub union dont_pad_me { @@ -67,52 +23,20 @@ pub union dont_pad_me { pub second: u32, pub third: u16, } -#[test] -fn bindgen_test_layout_dont_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dont_pad_me)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dont_pad_me)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(first) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(second) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(third) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of dont_pad_me"][::std::mem::size_of::() - 4usize]; + ["Alignment of dont_pad_me"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: dont_pad_me::first", + ][::std::mem::offset_of!(dont_pad_me, first) - 0usize]; + [ + "Offset of field: dont_pad_me::second", + ][::std::mem::offset_of!(dont_pad_me, second) - 0usize]; + [ + "Offset of field: dont_pad_me::third", + ][::std::mem::offset_of!(dont_pad_me, third) - 0usize]; +}; impl Default for dont_pad_me { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs index 8060316a35e91afcc5bdcefcb8419f833fe42658..c449e1a019246e76ac6335cad2d66902469e3402 100644 --- a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs +++ b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct nsFoo { @@ -12,28 +6,14 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1600usize, - concat!("Size of: ", stringify!(nsFoo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(nsFoo)) - ); + assert_eq!(::std::mem::size_of::(), 1600usize, "Size of nsFoo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of nsFoo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(details) - ) + "Offset of field: nsFoo::details", ); } impl Default for nsFoo { diff --git a/bindgen-tests/tests/expectations/tests/extern.rs b/bindgen-tests/tests/expectations/tests/extern.rs index 7ded13f17931f44373b1d41ee6802a8d9f82b54a..496f595a0d6a8fd27190a07603d0a31a47a6bf61 100644 --- a/bindgen-tests/tests/expectations/tests/extern.rs +++ b/bindgen-tests/tests/expectations/tests/extern.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type foo = ::std::option::Option< unsafe extern "C" fn(bar: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs new file mode 100644 index 0000000000000000000000000000000000000000..9be373e5a7cb3ba4e1befc04e56c90a8418dbb74 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -0,0 +1,153 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct { + pub a: ::std::os::raw::c_int, + private_b: ::std::os::raw::c_int, + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + __bindgen_padding_0: [u8; 3usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of my_struct"][::std::mem::size_of::() - 12usize]; + ["Alignment of my_struct"][::std::mem::align_of::() - 4usize]; + ["Offset of field: my_struct::a"][::std::mem::offset_of!(my_struct, a) - 0usize]; + [ + "Offset of field: my_struct::private_b", + ][::std::mem::offset_of!(my_struct, private_b) - 4usize]; +}; +impl my_struct { + #[inline] + pub fn c(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_c(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn private_d(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } + } + #[inline] + fn set_private_d(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + c: ::std::os::raw::c_int, + private_d: ::std::os::raw::c_int, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let private_d: u32 = unsafe { ::std::mem::transmute(private_d) }; + private_d as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs new file mode 100644 index 0000000000000000000000000000000000000000..2ad5dc838e969f3ed1b1d15a32883570cc07b723 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -0,0 +1,167 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct1 { + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + __bindgen_padding_0: [u8; 3usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of my_struct1"][::std::mem::size_of::() - 4usize]; + ["Alignment of my_struct1"][::std::mem::align_of::() - 4usize]; +}; +impl my_struct1 { + #[inline] + fn a(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + fn set_a(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1(a: ::std::os::raw::c_int) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct2 { + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of my_struct2"][::std::mem::size_of::() - 4usize]; + ["Alignment of my_struct2"][::std::mem::align_of::() - 4usize]; +}; +impl my_struct2 { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_int, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs index ccb76b85075a9da098c67a94d469f53050b3dd30..0602f7714a5ed72256c24dda5ff97a756321a553 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: i8 = 0; pub const N1: i8 = 1; pub const N2: i8 = 2; diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs index d8d3f207c1239afdc01f13187a40d52a2667134a..f5d2a56ff206371d9fd51c8faebf7850074561c4 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u8 = 0; pub const N1: u8 = 1; pub const N2: u8 = 2; diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs new file mode 100644 index 0000000000000000000000000000000000000000..b9c800366e146366d3b8408fa97b899f34e816e5 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -0,0 +1,555 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(feature = "nightly")] +#![feature(ptr_metadata, layout_for_ptr)] +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl ::std::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of flexarray"][::std::mem::size_of::() - 4usize]; + ["Alignment of flexarray"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray::count", + ][::std::mem::offset_of!(flexarray, count) - 0usize]; + [ + "Offset of field: flexarray::data", + ][::std::mem::offset_of!(flexarray, data) - 4usize]; +}; +impl flexarray<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); + ::std::alloc::Layout::for_value_raw(p) + } + } + #[inline] + pub fn fixed(&self) -> (&flexarray<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray<[::std::os::raw::c_int; 0]>), len) + } + } + #[inline] + pub fn fixed_mut(&mut self) -> (&mut flexarray<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray<[::std::os::raw::c_int; 0]>), len) + } + } +} +impl flexarray<[::std::os::raw::c_int; 0]> { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &flexarray<[::std::os::raw::c_int]> { + Self::flex_ptr(self, len) + } + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray<[::std::os::raw::c_int]> { + Self::flex_ptr_mut(self, len).assume_init() + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray<[::std::os::raw::c_int]> { + &*::std::ptr::from_raw_parts(ptr as *const (), len) + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray<[::std::os::raw::c_int]>> { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray_zero { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of flexarray_zero"][::std::mem::size_of::() - 4usize]; + ["Alignment of flexarray_zero"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray_zero::count", + ][::std::mem::offset_of!(flexarray_zero, count) - 0usize]; + [ + "Offset of field: flexarray_zero::data", + ][::std::mem::offset_of!(flexarray_zero, data) - 4usize]; +}; +impl flexarray_zero<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); + ::std::alloc::Layout::for_value_raw(p) + } + } + #[inline] + pub fn fixed(&self) -> (&flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_zero<[::std::os::raw::c_int; 0]>), len) + } + } + #[inline] + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_zero<[::std::os::raw::c_int; 0]>), len) + } + } +} +impl flexarray_zero<[::std::os::raw::c_int; 0]> { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( + &self, + len: usize, + ) -> &flexarray_zero<[::std::os::raw::c_int]> { + Self::flex_ptr(self, len) + } + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_zero<[::std::os::raw::c_int]> { + Self::flex_ptr_mut(self, len).assume_init() + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_zero<[::std::os::raw::c_int]> { + &*::std::ptr::from_raw_parts(ptr as *const (), len) + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_zero<[::std::os::raw::c_int]>, + > { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_zero<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_zero<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } +} +#[repr(C)] +#[derive(Debug)] +pub struct flexarray_template { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +impl flexarray_template { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); + ::std::alloc::Layout::for_value_raw(p) + } + } + #[inline] + pub fn fixed(&self) -> (&flexarray_template, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_template), len) + } + } + #[inline] + pub fn fixed_mut(&mut self) -> (&mut flexarray_template, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_template), len) + } + } +} +impl flexarray_template { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &flexarray_template { + Self::flex_ptr(self, len) + } + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_template { + Self::flex_ptr_mut(self, len).assume_init() + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_template { + &*::std::ptr::from_raw_parts(ptr as *const (), len) + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray_template> { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_template, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_template) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } +} +impl Default for flexarray_template { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct flexarray_ref { + pub things: *mut flexarray, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of flexarray_ref"][::std::mem::size_of::() - 8usize]; + ["Alignment of flexarray_ref"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: flexarray_ref::things", + ][::std::mem::offset_of!(flexarray_ref, things) - 0usize]; +}; +impl Default for flexarray_ref { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray_bogus_zero_fam { + pub count: ::std::os::raw::c_int, + pub data1: __IncompleteArrayField<::std::os::raw::c_int>, + pub data2: FAM, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of flexarray_bogus_zero_fam", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of flexarray_bogus_zero_fam", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::count", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, count) - 0usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::data1", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, data1) - 4usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::data2", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, data2) - 4usize]; +}; +impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); + ::std::alloc::Layout::for_value_raw(p) + } + } + #[inline] + pub fn fixed( + &self, + ) -> (&flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + ( + &*(ptr as *const flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>), + len, + ) + } + } + #[inline] + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + ( + &mut *(ptr + as *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>), + len, + ) + } + } +} +impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( + &self, + len: usize, + ) -> &flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + Self::flex_ptr(self, len) + } + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + Self::flex_ptr_mut(self, len).assume_init() + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + &*::std::ptr::from_raw_parts(ptr as *const (), len) + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, + > { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, + >::uninit(); + (uninit.as_mut_ptr() + as *mut *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } +} +#[repr(C)] +#[repr(align(128))] +#[derive(Debug)] +pub struct flexarray_align { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of flexarray_align"][::std::mem::size_of::() - 128usize]; + [ + "Alignment of flexarray_align", + ][::std::mem::align_of::() - 128usize]; + [ + "Offset of field: flexarray_align::count", + ][::std::mem::offset_of!(flexarray_align, count) - 0usize]; + [ + "Offset of field: flexarray_align::data", + ][::std::mem::offset_of!(flexarray_align, data) - 4usize]; +}; +impl flexarray_align<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); + ::std::alloc::Layout::for_value_raw(p) + } + } + #[inline] + pub fn fixed(&self) -> (&flexarray_align<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_align<[::std::os::raw::c_int; 0]>), len) + } + } + #[inline] + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_align<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_align<[::std::os::raw::c_int; 0]>), len) + } + } +} +impl flexarray_align<[::std::os::raw::c_int; 0]> { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( + &self, + len: usize, + ) -> &flexarray_align<[::std::os::raw::c_int]> { + Self::flex_ptr(self, len) + } + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_align<[::std::os::raw::c_int]> { + Self::flex_ptr_mut(self, len).assume_init() + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_align<[::std::os::raw::c_int]> { + &*::std::ptr::from_raw_parts(ptr as *const (), len) + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_align<[::std::os::raw::c_int]>, + > { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_align<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_align<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } +} +impl Default for flexarray_align<[::std::os::raw::c_int; 0]> { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/float128.rs b/bindgen-tests/tests/expectations/tests/float128.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/float128.rs +++ b/bindgen-tests/tests/expectations/tests/float128.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/float16.rs b/bindgen-tests/tests/expectations/tests/float16.rs new file mode 100644 index 0000000000000000000000000000000000000000..1804d1007a0ad5db37aa8c01f08c653009e42658 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/float16.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] +#[repr(transparent)] +pub struct __BindgenFloat16(pub u16); +extern "C" { + pub static mut global: __BindgenFloat16; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] +pub struct Test__Float16 { + pub f: __BindgenFloat16, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test__Float16"][::std::mem::size_of::() - 2usize]; + ["Alignment of Test__Float16"][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: Test__Float16::f", + ][::std::mem::offset_of!(Test__Float16, f) - 0usize]; +}; +#[repr(C)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Test__Float16Ref { + pub f: *mut __BindgenFloat16, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test__Float16Ref"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of Test__Float16Ref", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: Test__Float16Ref::f", + ][::std::mem::offset_of!(Test__Float16Ref, f) - 0usize]; +}; +impl Default for Test__Float16Ref { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 9f4fdca0a64dfd6d25b3a116256be61f10f6e0cc..b74b408841d605970a5651f045229a7ee6a7f680 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -13,8 +7,8 @@ pub struct Foo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub m_inner: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_inner: *mut T, } impl Default for RefPtr { fn default() -> Self { @@ -30,34 +24,12 @@ impl Default for RefPtr { pub struct Bar { pub m_member: RefPtr, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::m_member"][::std::mem::offset_of!(Bar, m_member) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -67,19 +39,12 @@ impl Default for Bar { } } } -#[test] -fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!("Size of template specialization: ", stringify!(RefPtr)) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(RefPtr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: RefPtr_open0_Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: RefPtr_open0_Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs index 0ac550bcba929a8dfb9e6c99bf157cfc01af9cf7..9949b39aae4b5fdb78658b6e83a551b5399a93ef 100644 --- a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs +++ b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum CSSPseudoClassType { diff --git a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs index 330d766b31d6ddbbf9b30046f77f88f73a0c2e9c..069c76feada8f5f3873bc14ef6b5df11e7a74132 100644 --- a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: *mut T, pub next: *mut Rooted, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for js_RootedBase { fn default() -> Self { @@ -24,8 +18,8 @@ impl Default for js_RootedBase { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub _base: js_RootedBase, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: js_RootedBase, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs index 2c4546eb41d15ece0b0a78692061779836ad4dbb..52888c4626f102881023ea316caa90298b83a8aa 100644 --- a/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct js_RootedBase { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index c1b1f23d2df1636c7e795ea787a56b528c2a6e40..2ba1071c8ec637b416b8bbadad3bbdbcefa94eca 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo_empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo_empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo_empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo_empty"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -33,27 +19,12 @@ pub struct Foo { pub struct Bar { pub f: *mut Foo, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::f"][::std::mem::offset_of!(Bar, f) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs index ecdbe49da7649760a849508658156740b2f16241..e891a6b01b2471df18931a7a38fa0da9922ab95b 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Foo_empty { @@ -12,16 +6,8 @@ pub struct Foo_empty { } #[test] fn bindgen_test_layout_Foo_empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)) - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo_empty"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo_empty"); } impl Clone for Foo_empty { fn clone(&self) -> Self { @@ -45,23 +31,14 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + "Offset of field: Bar::f", ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs b/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs index 58c02b44067e71e553c5b7b12a440c8d76d0259a..1f92194045b9a3332621f912907b84464b9716c9 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs index f877666adc9958462b6bc8a1de9f2ef301c989e0..1f6dfd0f58d3115f3ee91a911610882f403aed26 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs @@ -1,59 +1,23 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of a"][::std::mem::size_of::() - 4usize]; + ["Alignment of a"][::std::mem::align_of::() - 4usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct c { pub d: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_c() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(c)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of c"][::std::mem::size_of::() - 4usize]; + ["Alignment of c"][::std::mem::align_of::() - 4usize]; + ["Offset of field: c::d"][::std::mem::offset_of!(c, d) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/func_proto.rs b/bindgen-tests/tests/expectations/tests/func_proto.rs index 7ded13f17931f44373b1d41ee6802a8d9f82b54a..496f595a0d6a8fd27190a07603d0a31a47a6bf61 100644 --- a/bindgen-tests/tests/expectations/tests/func_proto.rs +++ b/bindgen-tests/tests/expectations/tests/func_proto.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type foo = ::std::option::Option< unsafe extern "C" fn(bar: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; diff --git a/bindgen-tests/tests/expectations/tests/func_ptr.rs b/bindgen-tests/tests/expectations/tests/func_ptr.rs index 9c718f03ec7ce66859b516d891148a4d7bd97efc..4e9c5b131d1a1608340ca0cca5a4b7a6ab814f33 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index 745720d998c04644ca4504bae044c55c55fbe99b..308bb069e09b6d5da78cf856c0c70cd02a0e9db1 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum baz { @@ -14,30 +8,12 @@ pub enum baz { #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub bar: ::std::option::Option< - unsafe extern "C" fn( - x: ::std::os::raw::c_int, - y: ::std::os::raw::c_int, - ) -> baz, + unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz, >, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs index 8f2da8efdad2780fd3f1030898921fd31b15a787..c1c890249f1546c0094b74acab8530fcc9b01029 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn func() -> ::std::option::Option< unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index 6ea6c704f0422f2e8bc0650c425276202c7c7b46..bc9deb081843e940597bb15ecf47b727c07865b7 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type MustUseInt = ::std::os::raw::c_int; extern "C" { #[must_use] @@ -34,19 +28,11 @@ extern "C" { #[derive(Debug, Default, Copy, Clone)] #[must_use] pub struct AnnotatedStruct {} -#[test] -fn bindgen_test_layout_AnnotatedStruct() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(AnnotatedStruct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AnnotatedStruct)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AnnotatedStruct"][::std::mem::size_of::() - 0usize]; + ["Alignment of AnnotatedStruct"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[must_use] pub fn return_annotated_struct() -> AnnotatedStruct; @@ -54,19 +40,11 @@ extern "C" { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct PlainStruct {} -#[test] -fn bindgen_test_layout_PlainStruct() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(PlainStruct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PlainStruct)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PlainStruct"][::std::mem::size_of::() - 0usize]; + ["Alignment of PlainStruct"][::std::mem::align_of::() - 1usize]; +}; ///
pub type TypedefPlainStruct = PlainStruct; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs index f98192f8dbc32b35bd916fa5aacfe93a188de7be..e41cb2ce44c9e0f011bfe8fc7fb0ef1c77224ce8 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(x: *mut ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs index fb06b88e6868f5af467bff9bf43368e25a0313fa..af8a3fc68c743641623d8aa194bc2b67f8c7f047 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs @@ -1,26 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(bar: ::std::option::Option); } extern "C" { pub fn bar( one: ::std::option::Option< - unsafe extern "C" fn( - a: ::std::os::raw::c_int, - b: ::std::os::raw::c_int, - ), + unsafe extern "C" fn(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int), >, two: ::std::option::Option< - unsafe extern "C" fn( - c: ::std::os::raw::c_int, - d: ::std::os::raw::c_int, - ), + unsafe extern "C" fn(c: ::std::os::raw::c_int, d: ::std::os::raw::c_int), >, ); } diff --git a/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs b/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs index 11c9ef2072d4de7e22b345012f9d868a09cab689..3b08e0988cbc376361ce20d84880b4a4018aba53 100644 --- a/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs +++ b/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type PFN_VIGEM_X360_NOTIFICATION = ::std::option::Option< unsafe extern "C" fn( arg1: *mut ::std::os::raw::c_void, diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs index f5ba025a25a0697bb796d28c00ac4be4b6f5b0ff..551dff82cfb9e323724af19dbf5e8991f42ec22a 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 89b8637954232f9811dcc4596e58766ae713132c..c1a8b676fdf174ab74b84fa306aee7949b8169e4 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs index b87eb1d46c197d4dfb4cf13c2ce38982b84d242e..77b6a07bb120551bef2837a14eac59feef63d439 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct Foo { pub bar: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 1711f76d0c9ba4d69459244115cacc7a88c1fd07..f3dc655f08a46b5e44667a08c91e796898ea72c9 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct Foo { pub bar: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooD1Ev"] pub fn Foo_Foo_destructor(this: *mut Foo); diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 3cb865a4d7b3c8f90a4045a999ed5680f94ca85a..1d60a98570013611a2376dd28a5d42876575963d 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo3barEv"] pub fn Foo_bar() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 22b2f67f754f3d6fd4db47750682db1ac5be6cf8..a8fd5045d28c9f93fd8c00de62ef7bbd308dd73e 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -1,14 +1,32 @@ -int foo__extern(void) asm("foo__extern"); -int foo__extern() { return foo(); } -int bar__extern(void) asm("bar__extern"); -int bar__extern() { return bar(); } -int takes_ptr__extern(int *arg) asm("takes_ptr__extern"); +#include "tests/headers/wrap-static-fns.h" + +// Static wrappers + +int foo__extern(void) { return foo(); } +int bar__extern(void) { return bar(); } int takes_ptr__extern(int *arg) { return takes_ptr(arg); } -int takes_fn_ptr__extern(int (*f) (int)) asm("takes_fn_ptr__extern"); int takes_fn_ptr__extern(int (*f) (int)) { return takes_fn_ptr(f); } -int takes_fn__extern(int (f) (int)) asm("takes_fn__extern"); int takes_fn__extern(int (f) (int)) { return takes_fn(f); } -int takes_alias__extern(func f) asm("takes_alias__extern"); int takes_alias__extern(func f) { return takes_alias(f); } -int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern"); int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } +enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } +void nevermore__extern(void) { nevermore(); } +int takes_fn_with_no_args__extern(int (f) (void)) { return takes_fn_with_no_args(f); } +void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); } +int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); } +int wrap_as_variadic_fn1__extern(int i, ...) { + int ret; + va_list ap; + + va_start(ap, i); + ret = wrap_as_variadic_fn1(i, ap); + va_end(ap); + return ret; +} +void wrap_as_variadic_fn2__extern(int i, ...) { + va_list ap; + + va_start(ap, i); + wrap_as_variadic_fn2(i, ap); + va_end(ap); +} diff --git a/bindgen-tests/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs index dee57a6ded428a093b54e3f66cacee894f8730d0..87459b5e759034f341abc01f3c7353bd38987a80 100644 --- a/bindgen-tests/tests/expectations/tests/i128.rs +++ b/bindgen-tests/tests/expectations/tests/i128.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -14,41 +8,18 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 32usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of foo"); assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_signed) - ) + "Offset of field: foo::my_signed", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_unsigned) - ) + "Offset of field: foo::my_unsigned", ); } diff --git a/bindgen-tests/tests/expectations/tests/in_class_typedef.rs b/bindgen-tests/tests/expectations/tests/in_class_typedef.rs index 7bb7d39182138016c95b62194a60ad88680a1022..ccb73520d716666af57a67c3fdb7e7ed69e51f7b 100644 --- a/bindgen-tests/tests/expectations/tests/in_class_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/in_class_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 18061ea12a04b814fcdde76320203d8f305f762c..148f4ffa4136297fc78964e175b5f3451f7a295a 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -128,19 +120,12 @@ pub struct foo { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::b"][::std::mem::offset_of!(foo, b) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -153,9 +138,7 @@ impl Default for foo { impl foo { #[inline] pub fn a(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_char) { @@ -168,12 +151,16 @@ impl foo { pub fn new_bitfield_1( a: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index 081a0c296bdabb343c75d071ab8543e61aef0f8f..f19879fb17198c8d2ddf006d2ae7bd63de087b29 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const INFINITY: f64 = ::std::f64::INFINITY; -pub const NAN: f64 = ::std::f64::NAN; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const INFINITY: f64 = f64::INFINITY; +pub const NAN: f64 = f64::NAN; diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 0876878efccd6809b9d0f035b07683a701a33b9d..59e35f7b6cd28c1c54b09d26d930e6ce65163f13 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -1,19 +1,13 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct BaseWithVtable__bindgen_vtable {} /// This should have an explicit vtable. #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithVtable { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub vtable_: *const BaseWithVtable__bindgen_vtable, pub t: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for BaseWithVtable { fn default() -> Self { @@ -30,19 +24,15 @@ impl Default for BaseWithVtable { pub struct DerivedWithNoVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithNoVirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of DerivedWithNoVirtualMethods", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithNoVirtualMethods", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithNoVirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -58,19 +48,15 @@ impl Default for DerivedWithNoVirtualMethods { pub struct DerivedWithVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithVirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithVirtualMethods)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithVirtualMethods)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of DerivedWithVirtualMethods", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithVirtualMethods", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithVirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -84,8 +70,8 @@ impl Default for DerivedWithVirtualMethods { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithoutVtable { - pub u: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub u: U, } impl Default for BaseWithoutVtable { fn default() -> Self { @@ -105,19 +91,13 @@ pub struct DerivedWithVtable { pub vtable_: *const DerivedWithVtable__bindgen_vtable, pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithVtable() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithVtable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithVtable)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of DerivedWithVtable"][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithVtable", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithVtable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -133,19 +113,15 @@ impl Default for DerivedWithVtable { pub struct DerivedWithoutVtable { pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithoutVtable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(DerivedWithoutVtable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithoutVtable)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of DerivedWithoutVtable", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of DerivedWithoutVtable", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithoutVtable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -155,84 +131,39 @@ impl Default for DerivedWithoutVtable { } } } -#[test] -fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) - ); -} -#[test] -fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() -{ - assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) - ); -} -#[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() -{ - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>( - ), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) - ); -} -#[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1( -) { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>( - ), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 16usize]; + [ + "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 16usize]; + [ + "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs b/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs index 2c4546eb41d15ece0b0a78692061779836ad4dbb..52888c4626f102881023ea316caa90298b83a8aa 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct js_RootedBase { diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs index 46aa15db77f1d59d00197fbc9e33cd67ab9ebc87..da9e51915654168dd3811ba89c0f658954be671e 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct A__bindgen_vtable {} #[repr(C)] @@ -13,27 +7,12 @@ pub struct A { pub vtable_: *const A__bindgen_vtable, pub member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(member)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 16usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::member"][::std::mem::offset_of!(A, member) - 8usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -51,32 +30,12 @@ pub struct B { pub vtable_: *const B__bindgen_vtable, pub member2: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(B)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(B), - "::", - stringify!(member2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 16usize]; + ["Alignment of B"][::std::mem::align_of::() - 8usize]; + ["Offset of field: B::member2"][::std::mem::offset_of!(B, member2) - 8usize]; +}; impl Default for B { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -93,32 +52,12 @@ pub struct C { pub _base_1: B, pub member3: f32, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(member3) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 40usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::member3"][::std::mem::offset_of!(C, member3) - 32usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/inherit_named.rs b/bindgen-tests/tests/expectations/tests/inherit_named.rs index a8eee207677c6042f89a5ab9c08a1665c555835c..a371249ab06ab1ac6d2c111c6fce7a272e13da23 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_named.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_named.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Wohoo { @@ -13,8 +7,8 @@ pub struct Wohoo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Weeee { - pub _base: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: T, } impl Default for Weeee { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs index 285dd44f1c0feffad94937aaed444db780222328..92320f45ef12d69db5cd8348ee93766c460547ca 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs @@ -1,44 +1,22 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; pub type TypedefedFoo = Foo; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inline-function.rs b/bindgen-tests/tests/expectations/tests/inline-function.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/inline-function.rs +++ b/bindgen-tests/tests/expectations/tests/inline-function.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs index c569bba688ac704d053e0b7e6b6e03d525a372d1..df05ab7b9d87bfa6ce457c79beedf70cce9dd7ac 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -19,30 +13,10 @@ pub mod root { pub struct Bar { pub baz: root::foo::Ty, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs index 1f4bc686c1bebdf6e41fbe7af020f41b14e0484d..915a40c654cfba5ec7f66d3233b47308ee37d73b 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs index 4ffafd46b7759c18a03229f9bc812012df419f54..6941e74adbf9867655031b716f12cae993f0e0a8 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -24,30 +18,10 @@ pub mod root { pub struct Bar { pub baz: root::foo::bar::Ty, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs index 29b5b35ffa9b742c9237719ed7e3e84331344a2c..1474f47ba2e199e42e7f8e96a32c0e095fd7d4dd 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index 7a0c993555a11a5f6c9ac8a72ef87ecc95b91414..66359bd51ba30c48b9d24addf4cb95806a258c26 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct std_basic_string { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub hider: std_basic_string_Alloc_hider, pub length: ::std::os::raw::c_ulong, pub __bindgen_anon_1: std_basic_string__bindgen_ty_1, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -30,8 +24,8 @@ impl Default for std_basic_string_Alloc_hider { #[repr(C)] #[derive(Debug)] pub struct std_basic_string__bindgen_ty_1 { - pub inline_storage: [CharT; 4usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub inline_storage: [CharT; 4usize], } impl Default for std_basic_string__bindgen_ty_1 { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs index 1cfa549c328d470a6b905f0a7b45a6d6484c9b33..69d2151bbb12bd3a85933c0e797f00fce216c5d9 100644 --- a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs +++ b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,8 +7,8 @@ pub struct Foo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo_InnerType { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Foo_InnerType { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index 69a7c39a699ad3dd248ddd196d0afb5ca0c82adf..f8f0c45a29adbc54fe986c23d0ec9e502ea316e1 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -18,24 +12,9 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo8whateverE"] pub static mut Foo_whatever: Foo; } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs index 13d9ac14235c04a8e33da509cd17e11a04c47bc1..c8f9799be6de681363f0e115ec86079de7d20a43 100644 --- a/bindgen-tests/tests/expectations/tests/inner_template_self.rs +++ b/bindgen-tests/tests/expectations/tests/inner_template_self.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct LinkedList { @@ -25,32 +19,14 @@ impl Default for LinkedList { pub struct InstantiateIt { pub m_list: LinkedList, } -#[test] -fn bindgen_test_layout_InstantiateIt() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(InstantiateIt)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(InstantiateIt)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InstantiateIt), - "::", - stringify!(m_list) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of InstantiateIt"][::std::mem::size_of::() - 16usize]; + ["Alignment of InstantiateIt"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: InstantiateIt::m_list", + ][::std::mem::offset_of!(InstantiateIt, m_list) - 0usize]; +}; impl Default for InstantiateIt { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -60,19 +36,12 @@ impl Default for InstantiateIt { } } } -#[test] -fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of template specialization: ", stringify!(LinkedList)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(LinkedList) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: LinkedList_open0_int_close0", + ][::std::mem::size_of::() - 16usize]; + [ + "Align of template specialization: LinkedList_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/int128_t.rs b/bindgen-tests/tests/expectations/tests/int128_t.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/int128_t.rs +++ b/bindgen-tests/tests/expectations/tests/int128_t.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index c42e167fba643ffbd29b9a46bca49c9f77c7a98b..6e27b94ca9921d350899fe73224c815fbfed05d7 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 32f4310e49509d51178b50fc62d960938ef248bf..17450a13460ae2cf3a0decbe6c513293c250788f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,30 +83,21 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } -#[test] -fn bindgen_test_layout_S2() { - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(S2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S2)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of S2"][::std::mem::size_of::() - 2usize]; + ["Alignment of S2"][::std::mem::align_of::() - 1usize]; +}; impl S2 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1040.rs b/bindgen-tests/tests/expectations/tests/issue-1040.rs index 8503e8d22683cfc19666ac3528d1cc7bb7459579..788c480424737d3b78eb454cb8e5faf5be4965c9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1040.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1040.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const g_107: ::std::os::raw::c_ulonglong = 18446744073709551615; diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index d91dd8fa5c0354498dc14de17d4b7da1c9e42a26..5bdf08d992685dee260334a76b0cd9087ffc5a50 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,30 +83,21 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } -#[test] -fn bindgen_test_layout_S1() { - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(S1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of S1"][::std::mem::size_of::() - 3usize]; + ["Alignment of S1"][::std::mem::align_of::() - 1usize]; +}; impl S1 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs index c146583521d91e45b9e8782a3139516f15862fdc..c0e76d804702b8f69c6bcd8774569425826b8884 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Entry { - pub _base: K, - pub mData: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: K, + pub mData: V, } impl Default for Entry { fn default() -> Self { @@ -31,10 +25,10 @@ pub type nsBaseHashtable_EntryType = Entry; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsBaseHashtable_EntryPtr { - pub mEntry: *mut nsBaseHashtable_EntryType, - pub mExistingEntry: bool, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mEntry: *mut nsBaseHashtable_EntryType, + pub mExistingEntry: bool, } impl Default for nsBaseHashtable_EntryPtr { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index e881c8c482fa4d92a62930c8aac87c6c39db7d2a..7356aa679a523473807c57175b549a5bbed30656 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -1,42 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type c = nsTArray; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray_base { pub d: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_nsTArray_base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsTArray_base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsTArray_base)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsTArray_base), - "::", - stringify!(d) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsTArray_base"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsTArray_base"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsTArray_base::d", + ][::std::mem::offset_of!(nsTArray_base, d) - 0usize]; +}; impl Default for nsTArray_base { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -65,32 +41,14 @@ impl Default for nsTArray { pub struct nsIContent { pub foo: nsTArray, } -#[test] -fn bindgen_test_layout_nsIContent() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIContent)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIContent)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsIContent), - "::", - stringify!(foo) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsIContent"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsIContent"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsIContent::foo", + ][::std::mem::offset_of!(nsIContent, foo) - 0usize]; +}; impl Default for nsIContent { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -104,36 +62,21 @@ extern "C" { #[link_name = "\u{1}_Z35Gecko_GetAnonymousContentForElementv"] pub fn Gecko_GetAnonymousContentForElement() -> *mut nsTArray; } -#[test] -fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) - ); -} -#[test] -fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation_1() -{ - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::align_of::() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index fd023363d79a502e37b2628989677f2917e604a1..10c769c38cbc98414ae75b46c263bb407a91b440 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Foo__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] @@ -12,19 +6,11 @@ pub struct Foo__bindgen_vtable(::std::os::raw::c_void); pub struct Foo { pub vtable_: *const Foo__bindgen_vtable, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; +}; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index ed9f7c9ba84c9e17ec3b520da9007adbdf572887..7bbcb0d50b209dd471273f654126762e5cd67972 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl MyDupeEnum { pub const A: MyDupeEnum = MyDupeEnum(0); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs index 81c74abbf07471e63185524723c61f926cfcb679..76c1de0b1c6732c17a45e4b7fe2716905f32aff9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs index 81c74abbf07471e63185524723c61f926cfcb679..76c1de0b1c6732c17a45e4b7fe2716905f32aff9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs index fda73a021fe54a2ed0746a888e706de8a438e831..f41d6e90eca9ad78cf690749b3ac5da56e6464b1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl MyDupeEnum { pub const A_alias: MyDupeEnum = MyDupeEnum::A; } diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index bb57c8568a07a564d5faa89d7d15d3dda3033d72..e3fe80365478aa34ece75153bffe0828f5c05770 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: ::std::os::raw::c_int, ...); } @@ -20,24 +14,9 @@ pub struct Foo { ), >, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::f"][::std::mem::offset_of!(Foo, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs b/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs index 006900cb6e953be8327e4cf4afedf399bb521305..81e8fed5f368a3de697888f106a372f8e8f3ba35 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct MyType { diff --git a/bindgen-tests/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs index db99cbce99e13ab6157f63627b54003ea09a679c..03c80d21fb4e3039d4c1f8cb17a06d6ff72c7984 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1281.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1281.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct bar { @@ -15,72 +9,27 @@ pub struct bar { pub struct foo { pub foo: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) - ); -} -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::foo"][::std::mem::offset_of!(foo, foo) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::u"][::std::mem::offset_of!(bar, u) - 0usize]; +}; pub type bar_t = bar; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct baz { pub f: foo, } -#[test] -fn bindgen_test_layout_baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: baz::f"][::std::mem::offset_of!(baz, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs index 08aab0a94c50773027a8d0da072cd53fb4bab2e3..6520163259a60eef963e27fc631153da9a7e3bab 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1285.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1285.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -16,42 +10,19 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -61,27 +32,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs index 25f4f1055d01375c95e93f2095920450b2024552..190e899d7f854d4f3f366f704a9da6acd96054f4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1291.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1291.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -27,157 +21,83 @@ pub struct RTCRay { } #[test] fn bindgen_test_layout_RTCRay() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 96usize, - concat!("Size of: ", stringify!(RTCRay)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(RTCRay)) - ); + assert_eq!(::std::mem::size_of::(), 96usize, "Size of RTCRay"); + assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of RTCRay"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(org) - ) + "Offset of field: RTCRay::org", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align0) - ) + "Offset of field: RTCRay::align0", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(dir) - ) + "Offset of field: RTCRay::dir", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, 28usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align1) - ) + "Offset of field: RTCRay::align1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tnear) - ) + "Offset of field: RTCRay::tnear", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, 36usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tfar) - ) + "Offset of field: RTCRay::tfar", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(time) - ) + "Offset of field: RTCRay::time", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 44usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(mask) - ) + "Offset of field: RTCRay::mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, 48usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(Ng) - ) + "Offset of field: RTCRay::Ng", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, 60usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align2) - ) + "Offset of field: RTCRay::align2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) + "Offset of field: RTCRay::u", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, 68usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) + "Offset of field: RTCRay::v", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, 72usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(geomID) - ) + "Offset of field: RTCRay::geomID", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, 76usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(primID) - ) + "Offset of field: RTCRay::primID", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, 80usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(instID) - ) + "Offset of field: RTCRay::instID", ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs index 4deed0605584dfe9617996a1a0c86dfba75eb39f..908ccfbc2e397607f140948c0ab9f02649c2a651 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z11my_functioni"] pub fn my_function(a: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index edcca46d8a15ec8b382b5bc1fc08a0288e12e122..2e9a594a3172c6025c50e374ed87613c27c3364c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}my_custom_prefix_var_const_name"] pub static var_const_name: ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs index b767d5e430e2c41fa0181d96da7ccf5923362303..277978d93c1dac816beb3ce4143e1ad2996260dd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type i8_ = i8; pub type u8_ = u8; pub type i16_ = i16; @@ -31,109 +25,22 @@ pub struct Foo { pub f32_: ::std::os::raw::c_int, pub f64_: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 56usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 20usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, - 28usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i128_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u128_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(isize_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(usize_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize }, - 48usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize }, - 52usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 56usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::i8_"][::std::mem::offset_of!(Foo, i8_) - 0usize]; + ["Offset of field: Foo::u8_"][::std::mem::offset_of!(Foo, u8_) - 4usize]; + ["Offset of field: Foo::i16_"][::std::mem::offset_of!(Foo, i16_) - 8usize]; + ["Offset of field: Foo::u16_"][::std::mem::offset_of!(Foo, u16_) - 12usize]; + ["Offset of field: Foo::i32_"][::std::mem::offset_of!(Foo, i32_) - 16usize]; + ["Offset of field: Foo::u32_"][::std::mem::offset_of!(Foo, u32_) - 20usize]; + ["Offset of field: Foo::i64_"][::std::mem::offset_of!(Foo, i64_) - 24usize]; + ["Offset of field: Foo::u64_"][::std::mem::offset_of!(Foo, u64_) - 28usize]; + ["Offset of field: Foo::i128_"][::std::mem::offset_of!(Foo, i128_) - 32usize]; + ["Offset of field: Foo::u128_"][::std::mem::offset_of!(Foo, u128_) - 36usize]; + ["Offset of field: Foo::isize_"][::std::mem::offset_of!(Foo, isize_) - 40usize]; + ["Offset of field: Foo::usize_"][::std::mem::offset_of!(Foo, usize_) - 44usize]; + ["Offset of field: Foo::f32_"][::std::mem::offset_of!(Foo, f32_) - 48usize]; + ["Offset of field: Foo::f64_"][::std::mem::offset_of!(Foo, f64_) - 52usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1435.rs b/bindgen-tests/tests/expectations/tests/issue-1435.rs index 79ed7b294b38782e5d33dc883447a924418d5e6a..3040c1451e176b9fd30d9909c971050140facaa8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1435.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1435.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -16,7 +10,7 @@ pub mod root { pub const AB_B: root::ns::AB = 1; pub type AB = ::std::os::raw::c_int; } - pub use self::super::root::ns::AB; + pub use self::super::root::ns::AB as AB; extern "C" { #[link_name = "\u{1}_ZL2kA"] pub static kA: root::AB; diff --git a/bindgen-tests/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs index 48cae79faa6c2bbc5c98e23c6b0865ab7597c752..ee1ffca8e5fdabba8896dfc81ab58c3ca303e9b9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1443.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1443.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -16,32 +10,13 @@ pub struct Bar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::f"][::std::mem::offset_of!(Bar, f) - 0usize]; + ["Offset of field: Bar::m"][::std::mem::offset_of!(Bar, m) - 8usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -57,32 +32,13 @@ pub struct Baz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Baz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 16usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Baz::f"][::std::mem::offset_of!(Baz, f) - 0usize]; + ["Offset of field: Baz::m"][::std::mem::offset_of!(Baz, m) - 8usize]; +}; impl Default for Baz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -98,32 +54,13 @@ pub struct Tar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Tar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Tar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Tar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Tar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Tar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Tar::f"][::std::mem::offset_of!(Tar, f) - 0usize]; + ["Offset of field: Tar::m"][::std::mem::offset_of!(Tar, m) - 8usize]; +}; impl Default for Tar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -139,32 +76,13 @@ pub struct Taz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Taz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Taz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Taz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Taz"][::std::mem::size_of::() - 16usize]; + ["Alignment of Taz"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Taz::f"][::std::mem::offset_of!(Taz, f) - 0usize]; + ["Offset of field: Taz::m"][::std::mem::offset_of!(Taz, m) - 8usize]; +}; impl Default for Taz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs index 8da43cb0901b7bc115eb523e8b99e7fb8b7f4bf3..325ccfd9772e92059f845c962f8b4a4d2edfcfa8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1454.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1454.rs @@ -1,42 +1,17 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct extern_type; - #[repr(C)] #[derive(Debug)] pub struct local_type { pub inner: extern_type, } -#[test] -fn bindgen_test_layout_local_type() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(local_type)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(local_type)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(local_type), - "::", - stringify!(inner) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of local_type"][::std::mem::size_of::() - 0usize]; + ["Alignment of local_type"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: local_type::inner", + ][::std::mem::offset_of!(local_type, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1464.rs b/bindgen-tests/tests/expectations/tests/issue-1464.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1464.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1464.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs index b762659a505446f82f877f049f205b7adaa99b6d..60882da2d54caa53ec1a2fde0a2b6cc02e735c53 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Foo_A: Foo = 0; pub const Foo_B: Foo = 1; pub type Foo = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-options.rs b/bindgen-tests/tests/expectations/tests/issue-1488-options.rs index cf13b562848ae11ea5911d156e5953b12ea99e31..0f6efb93d478da4ee296e1f2c711c80a908067b9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-options.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-options.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type OSStatus = ::std::os::raw::c_int; #[repr(transparent)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs index 1af0c5751d72a74ee6501318ec0ad89882f1b0c3..de43753e9c431a4c187daaa4b2064f48523626b4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapped(pub T); diff --git a/bindgen-tests/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs index eb5e280457c8960e2efcd7e4b0d01b7e1bc1cf34..286d2eb6ee4c5c417be71bfc35d130cb23020ab8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1498.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1498.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed)] #[derive(Copy, Clone)] pub struct rte_memseg { @@ -30,42 +24,21 @@ pub union rte_memseg__bindgen_ty_1 { ///< Makes sure addr is always 64 bits pub addr_64: u64, } -#[test] -fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr_64) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_memseg__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_memseg__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_memseg__bindgen_ty_1::addr", + ][::std::mem::offset_of!(rte_memseg__bindgen_ty_1, addr) - 0usize]; + [ + "Offset of field: rte_memseg__bindgen_ty_1::addr_64", + ][::std::mem::offset_of!(rte_memseg__bindgen_ty_1, addr_64) - 0usize]; +}; impl Default for rte_memseg__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -75,90 +48,29 @@ impl Default for rte_memseg__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_memseg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 44usize, - concat!("Size of: ", stringify!(rte_memseg)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(rte_memseg)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(phys_addr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(hugepage_sz) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(socket_id) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nchannel) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nrank) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_memseg"][::std::mem::size_of::() - 44usize]; + ["Alignment of rte_memseg"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: rte_memseg::phys_addr", + ][::std::mem::offset_of!(rte_memseg, phys_addr) - 0usize]; + [ + "Offset of field: rte_memseg::len", + ][::std::mem::offset_of!(rte_memseg, len) - 16usize]; + [ + "Offset of field: rte_memseg::hugepage_sz", + ][::std::mem::offset_of!(rte_memseg, hugepage_sz) - 24usize]; + [ + "Offset of field: rte_memseg::socket_id", + ][::std::mem::offset_of!(rte_memseg, socket_id) - 32usize]; + [ + "Offset of field: rte_memseg::nchannel", + ][::std::mem::offset_of!(rte_memseg, nchannel) - 36usize]; + [ + "Offset of field: rte_memseg::nrank", + ][::std::mem::offset_of!(rte_memseg, nrank) - 40usize]; +}; impl Default for rte_memseg { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1514.rs b/bindgen-tests/tests/expectations/tests/issue-1514.rs index 31939ca5881fd53c9491971d762657334a4d3d8c..aef63037aecab63a8f6bcfd3304fadf9c5bc0e98 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1514.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1514.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Thing { @@ -13,8 +7,8 @@ pub struct Thing { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing_Inner { - pub ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: *mut T, } impl Default for Thing_Inner { fn default() -> Self { @@ -28,8 +22,8 @@ impl Default for Thing_Inner { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing_AnotherInner { - pub _base: Thing_Inner, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: Thing_Inner, } impl Default for Thing_AnotherInner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1554.rs b/bindgen-tests/tests/expectations/tests/issue-1554.rs index 7e7cddd6108cd1f81195b6e52863e0f39bdc308f..7b1a2cd41045f7cde05bb589cc0e4790890c7fc5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1554.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1554.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(non_exhaustive)] - #[repr(u32)] #[non_exhaustive] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs index eacb34111c9f36c5e56a803591ddbb308c717ed2..325ee4adc4524971ebaead27eee27d228afb39df 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const a_b: a = 0; pub const a_c: a = 1; pub type a = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs b/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index e133ed85bab6ad917e393e3ec3e315c8b08d97a8..32f9bbe146dcc52f2d9fe3edcedfe4b96d756c5e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -94,7 +86,6 @@ where pub type U8 = ::std::os::raw::c_uchar; pub type U16 = ::std::os::raw::c_ushort; #[repr(C)] -#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct V56AMDY { pub _bitfield_align_1: [u16; 0], @@ -105,58 +96,18 @@ pub struct V56AMDY { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 3usize]>, pub _rB_: U8, } -#[test] -fn bindgen_test_layout_V56AMDY() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(V56AMDY)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(V56AMDY)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MADK) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MABR) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, - 7usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(_rB_) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of V56AMDY"][::std::mem::size_of::() - 8usize]; + ["Alignment of V56AMDY"][::std::mem::align_of::() - 2usize]; + ["Offset of field: V56AMDY::MADK"][::std::mem::offset_of!(V56AMDY, MADK) - 2usize]; + ["Offset of field: V56AMDY::MABR"][::std::mem::offset_of!(V56AMDY, MABR) - 3usize]; + ["Offset of field: V56AMDY::_rB_"][::std::mem::offset_of!(V56AMDY, _rB_) - 7usize]; +}; impl V56AMDY { #[inline] pub fn MADZ(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 10u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 10u8) as u16) } } #[inline] pub fn set_MADZ(&mut self, val: U16) { @@ -167,9 +118,7 @@ impl V56AMDY { } #[inline] pub fn MAI0(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) } } #[inline] pub fn set_MAI0(&mut self, val: U16) { @@ -180,9 +129,7 @@ impl V56AMDY { } #[inline] pub fn MAI1(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) } } #[inline] pub fn set_MAI1(&mut self, val: U16) { @@ -193,9 +140,7 @@ impl V56AMDY { } #[inline] pub fn MAI2(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) } } #[inline] pub fn set_MAI2(&mut self, val: U16) { @@ -211,31 +156,48 @@ impl V56AMDY { MAI1: U16, MAI2: U16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 10u8, { - let MADZ: u16 = unsafe { ::std::mem::transmute(MADZ) }; - MADZ as u64 - }); - __bindgen_bitfield_unit.set(10usize, 2u8, { - let MAI0: u16 = unsafe { ::std::mem::transmute(MAI0) }; - MAI0 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 2u8, { - let MAI1: u16 = unsafe { ::std::mem::transmute(MAI1) }; - MAI1 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 2u8, { - let MAI2: u16 = unsafe { ::std::mem::transmute(MAI2) }; - MAI2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 10u8, + { + let MADZ: u16 = unsafe { ::std::mem::transmute(MADZ) }; + MADZ as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 2u8, + { + let MAI0: u16 = unsafe { ::std::mem::transmute(MAI0) }; + MAI0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 2u8, + { + let MAI1: u16 = unsafe { ::std::mem::transmute(MAI1) }; + MAI1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 2u8, + { + let MAI2: u16 = unsafe { ::std::mem::transmute(MAI2) }; + MAI2 as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn MATH(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 10u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 10u8) as u16) } } #[inline] pub fn set_MATH(&mut self, val: U16) { @@ -246,9 +208,7 @@ impl V56AMDY { } #[inline] pub fn MATE(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) } } #[inline] pub fn set_MATE(&mut self, val: U16) { @@ -259,9 +219,7 @@ impl V56AMDY { } #[inline] pub fn MATW(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) } } #[inline] pub fn set_MATW(&mut self, val: U16) { @@ -272,9 +230,7 @@ impl V56AMDY { } #[inline] pub fn MASW(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) } } #[inline] pub fn set_MASW(&mut self, val: U8) { @@ -285,9 +241,7 @@ impl V56AMDY { } #[inline] pub fn MABW(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) } } #[inline] pub fn set_MABW(&mut self, val: U8) { @@ -298,9 +252,7 @@ impl V56AMDY { } #[inline] pub fn MAXN(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) } } #[inline] pub fn set_MAXN(&mut self, val: U8) { @@ -318,32 +270,61 @@ impl V56AMDY { MABW: U8, MAXN: U8, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 10u8, { - let MATH: u16 = unsafe { ::std::mem::transmute(MATH) }; - MATH as u64 - }); - __bindgen_bitfield_unit.set(10usize, 4u8, { - let MATE: u16 = unsafe { ::std::mem::transmute(MATE) }; - MATE as u64 - }); - __bindgen_bitfield_unit.set(14usize, 2u8, { - let MATW: u16 = unsafe { ::std::mem::transmute(MATW) }; - MATW as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let MASW: u8 = unsafe { ::std::mem::transmute(MASW) }; - MASW as u64 - }); - __bindgen_bitfield_unit.set(20usize, 3u8, { - let MABW: u8 = unsafe { ::std::mem::transmute(MABW) }; - MABW as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let MAXN: u8 = unsafe { ::std::mem::transmute(MAXN) }; - MAXN as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 10u8, + { + let MATH: u16 = unsafe { ::std::mem::transmute(MATH) }; + MATH as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 4u8, + { + let MATE: u16 = unsafe { ::std::mem::transmute(MATE) }; + MATE as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 2u8, + { + let MATW: u16 = unsafe { ::std::mem::transmute(MATW) }; + MATW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let MASW: u8 = unsafe { ::std::mem::transmute(MASW) }; + MASW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 3u8, + { + let MABW: u8 = unsafe { ::std::mem::transmute(MABW) }; + MABW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let MAXN: u8 = unsafe { ::std::mem::transmute(MAXN) }; + MAXN as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index 6375ea7e67a375d6e7e4f8ae844f87c5a59acb78..df7a2192ed3d7f9f0337a7de64a948c42ad53d8e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -1,43 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct S { pub large_array: [::std::os::raw::c_char; 33usize], } -#[test] -fn bindgen_test_layout_S() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 33usize, - concat!("Size of: ", stringify!(S)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of S"][::std::mem::size_of::() - 33usize]; + ["Alignment of S"][::std::mem::align_of::() - 1usize]; + ["Offset of field: S::large_array"][::std::mem::offset_of!(S, large_array) - 0usize]; +}; impl Default for S { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -50,8 +22,8 @@ impl Default for S { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ST { - pub large_array: [T; 33usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub large_array: [T; 33usize], } impl Default for ST { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs index 890479b5df4d9c3e7e4bdd0c2808159a0db7ce39..0e36bdd9c9fd92da8ac46180ba0e1f2cf7053e73 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1995.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1995.rs @@ -1,40 +1,19 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is a constant that has a docstring -/// This is a constant that has a docstring -/// -/// And expected to be found in generated bindings code too. + And expected to be found in generated bindings code too.*/ pub const FOO: ::std::os::raw::c_int = 1; -/// This is a constant that has a docstring -/// -/// And expected to be found in generated bindings code too. +/** This is a constant that has a docstring + + And expected to be found in generated bindings code too.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 294e9f0e83bc70bfc009be59b962a858c7e4f6a0..88921d615ae1a4437e5f6394bd4a8f3c7823d7b2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::a"][::std::mem::offset_of!(A, a) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A4makeEv"] pub fn make() -> A; @@ -46,27 +25,12 @@ impl A { pub struct B { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: B::b"][::std::mem::offset_of!(B, b) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1B4makeEv"] pub fn make1() -> B; diff --git a/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs b/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs index 75ec9e439ef8360f7c93d0333d0f4472ae504d46..6ff58b75591a84bb6d20f257e364f99da51d41bc 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct b { diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs new file mode 100644 index 0000000000000000000000000000000000000000..5f7c1d369a3c6983d67c05a1301d986e056c7ddd --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct nsSize { + pub width: ::std::os::raw::c_int, + pub height: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of nsSize"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsSize"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: nsSize::width", + ][::std::mem::offset_of!(nsSize, width) - 0usize]; + [ + "Offset of field: nsSize::height", + ][::std::mem::offset_of!(nsSize, height) - 4usize]; + }; + pub mod foo { + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN3fooL22kFallbackIntrinsicSizeE"] + pub static kFallbackIntrinsicSize: root::nsSize; + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs b/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs new file mode 100644 index 0000000000000000000000000000000000000000..4227cf2956aa3a535c0ba048244088d5c7aa41cd --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs @@ -0,0 +1,2 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FOO: &[u8; 4] = b"a\0b\0"; diff --git a/bindgen-tests/tests/expectations/tests/issue-2566.rs b/bindgen-tests/tests/expectations/tests/issue-2566.rs new file mode 100644 index 0000000000000000000000000000000000000000..4227cf2956aa3a535c0ba048244088d5c7aa41cd --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2566.rs @@ -0,0 +1,2 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FOO: &[u8; 4] = b"a\0b\0"; diff --git a/bindgen-tests/tests/expectations/tests/issue-2695.rs b/bindgen-tests/tests/expectations/tests/issue-2695.rs new file mode 100644 index 0000000000000000000000000000000000000000..20a016dbabb2c2b20f8f3ee7da126a1e2a0af409 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2695.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C, packed(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct Test { + pub x: ::std::os::raw::c_ulong, + pub a: ::std::os::raw::c_char, + pub b: ::std::os::raw::c_char, + pub c: ::std::os::raw::c_char, + pub __bindgen_padding_0: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Test::x"][::std::mem::offset_of!(Test, x) - 0usize]; + ["Offset of field: Test::a"][::std::mem::offset_of!(Test, a) - 8usize]; + ["Offset of field: Test::b"][::std::mem::offset_of!(Test, b) - 9usize]; + ["Offset of field: Test::c"][::std::mem::offset_of!(Test, c) - 10usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-358.rs b/bindgen-tests/tests/expectations/tests/issue-358.rs index e9ee0f502f37cf7e71aa15dc718f38e05071aec9..ff915e9fbabebb64e6e0c8bdb288a5d419366816 100644 --- a/bindgen-tests/tests/expectations/tests/issue-358.rs +++ b/bindgen-tests/tests/expectations/tests/issue-358.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_PersistentRooted { diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index e87fb4d108af8dac8c7e25d19eee6758e4eb12ca..80b8cbe8b6885a9b734d96355ceea021edbf633e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -18,33 +12,24 @@ pub mod root { } #[test] fn bindgen_test_layout_i() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(i)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(i)) - ); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of i"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of i"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) + "Offset of field: i::j", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) + "Offset of field: i::k", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) + "Offset of field: i::l", ); } impl Default for i { @@ -63,23 +48,14 @@ pub mod root { } #[test] fn bindgen_test_layout_d() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(d)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(d)) - ); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of d"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of d"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) + "Offset of field: d::m", ); } impl Default for d { @@ -113,23 +89,14 @@ pub mod root { } #[test] fn bindgen_test_layout_F() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 264usize, - concat!("Size of: ", stringify!(F)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(F)) - ); + assert_eq!(::std::mem::size_of::(), 264usize, "Size of F"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of F"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) + "Offset of field: F::w", ); } impl Default for F { diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index ad7463c266283a3aa0ab52e0d5a6c213c38fecb7..e52aa25a136ed34939512ce2baa29a7f267c8660 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -17,19 +11,11 @@ pub mod root { pub struct Value { pub _address: u8, } - #[test] - fn bindgen_test_layout_Value() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Value)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Value)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Value"][::std::mem::size_of::() - 1usize]; + ["Alignment of Value"][::std::mem::align_of::() - 1usize]; + }; extern "C" { #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"] pub fn Value_a(this: *mut root::JS::Value, arg1: root::JSWhyMagic); diff --git a/bindgen-tests/tests/expectations/tests/issue-446.rs b/bindgen-tests/tests/expectations/tests/issue-446.rs index db69f159c72c599848bc9f62076fd598af1a8a39..5d625cb311139804a371828d24e632cf6011de9f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-446.rs +++ b/bindgen-tests/tests/expectations/tests/issue-446.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct List { diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 949db73b795503d0a30e57217975b90cee3187ee..305fa739d02b652e78cc692b713d49eb5799e901 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -20,19 +14,15 @@ pub mod root { pub struct GuardObjectNotifier { pub _address: u8, } - #[test] - fn bindgen_test_layout_GuardObjectNotifier() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(GuardObjectNotifier)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(GuardObjectNotifier)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of GuardObjectNotifier", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of GuardObjectNotifier", + ][::std::mem::align_of::() - 1usize]; + }; } } #[repr(C)] @@ -40,19 +30,15 @@ pub mod root { pub struct JSAutoCompartment { pub _address: u8, } - #[test] - fn bindgen_test_layout_JSAutoCompartment() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JSAutoCompartment)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(JSAutoCompartment)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of JSAutoCompartment", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of JSAutoCompartment", + ][::std::mem::align_of::() - 1usize]; + }; extern "C" { #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"] pub fn JSAutoCompartment_JSAutoCompartment( @@ -62,14 +48,9 @@ pub mod root { } impl JSAutoCompartment { #[inline] - pub unsafe fn new( - arg1: root::mozilla::detail::GuardObjectNotifier, - ) -> Self { + pub unsafe fn new(arg1: root::mozilla::detail::GuardObjectNotifier) -> Self { let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - JSAutoCompartment_JSAutoCompartment( - __bindgen_tmp.as_mut_ptr(), - arg1, - ); + JSAutoCompartment_JSAutoCompartment(__bindgen_tmp.as_mut_ptr(), arg1); __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 61c7f7929ee7faaa2052bc1be71bcf7f527a3c01..d2e4ea53759de7d36fa97ab55db5b0e68dca30a5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -72,8 +66,7 @@ impl Default for basic_string___long { } } } -pub const basic_string___min_cap: basic_string__bindgen_ty_1 = - basic_string__bindgen_ty_1::__min_cap; +pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -123,8 +116,7 @@ impl Default for basic_string___ulx { } } } -pub const basic_string___n_words: basic_string__bindgen_ty_2 = - basic_string__bindgen_ty_2::__n_words; +pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 1a0131c3273162e058050ffaa475e5872c791dee..ff0c93428b0a3a470c9da64403c4a806f9d2b833 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -72,8 +66,7 @@ impl Default for basic_string___long { } } } -pub const basic_string___min_cap: basic_string__bindgen_ty_1 = - basic_string__bindgen_ty_1::__min_cap; +pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -108,8 +101,7 @@ pub struct basic_string___ulx { pub __lxx: __BindgenUnionField, pub bindgen_union_field: [u8; 0usize], } -pub const basic_string___n_words: basic_string__bindgen_ty_2 = - basic_string__bindgen_ty_2::__n_words; +pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-511.rs b/bindgen-tests/tests/expectations/tests/issue-511.rs index b7705ef2b1724697417cdbadccd2296751b3a02f..e2bb991946e8895f6fa39af4baa6b2d087a731a1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-511.rs +++ b/bindgen-tests/tests/expectations/tests/issue-511.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut a: *mut ::std::os::raw::c_char; } diff --git a/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs b/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs index b1e42ca72abd7f8b8a79f530116a5f95cc94aa75..0142673f3ee775cec68b56e9c6c4bba7fb1e3969 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -1,13 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - -/// This should not be opaque; we can see the attributes and can pack the -/// struct. +/** This should not be opaque; we can see the attributes and can pack the + struct.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToOne { @@ -15,31 +9,21 @@ pub struct AlignedToOne { } #[test] fn bindgen_test_layout_AlignedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToOne)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToOne"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)) + "Alignment of AlignedToOne", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) + "Offset of field: AlignedToOne::i", ); } -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { @@ -47,33 +31,23 @@ pub struct AlignedToTwo { } #[test] fn bindgen_test_layout_AlignedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToTwo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToTwo"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)) + "Alignment of AlignedToTwo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) + "Offset of field: AlignedToTwo::i", ); } -/// This should not be opaque because although `libclang` doesn't give us the -/// `#pragma pack(1)`, we can detect that alignment is 1 and add -/// `#[repr(packed)]` to the struct ourselves. +/** This should not be opaque because although `libclang` doesn't give us the + `#pragma pack(1)`, we can detect that alignment is 1 and add + `#[repr(packed)]` to the struct ourselves.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToOne { @@ -82,41 +56,26 @@ pub struct PackedToOne { } #[test] fn bindgen_test_layout_PackedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToOne)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToOne"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(PackedToOne)) + "Alignment of PackedToOne", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) + "Offset of field: PackedToOne::x", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) + "Offset of field: PackedToOne::y", ); } -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { @@ -125,37 +84,22 @@ pub struct PackedToTwo { } #[test] fn bindgen_test_layout_PackedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToTwo)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToTwo"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)) + "Alignment of PackedToTwo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) + "Offset of field: PackedToTwo::x", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) + "Offset of field: PackedToTwo::y", ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs index e2be9d63ba3064cc6fa6befc5e27cb8e436475e7..d630b9ea4c8c025047386684ab64a2500709f6dd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537.rs @@ -1,163 +1,63 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// This should not be opaque; we can see the attributes and can pack the -/// struct. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This should not be opaque; we can see the attributes and can pack the + struct.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToOne { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AlignedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToOne)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) - ); -} -/// This should be opaque because although we can see the attributes, Rust before -/// 1.33 doesn't have `#[repr(packed(N))]`. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AlignedToOne"][::std::mem::size_of::() - 4usize]; + ["Alignment of AlignedToOne"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: AlignedToOne::i", + ][::std::mem::offset_of!(AlignedToOne, i) - 0usize]; +}; +/** This should be opaque because although we can see the attributes, Rust before + 1.33 doesn't have `#[repr(packed(N))]`.*/ #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AlignedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToTwo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) - ); -} -/// This should not be opaque because although `libclang` doesn't give us the -/// `#pragma pack(1)`, we can detect that alignment is 1 and add -/// `#[repr(packed)]` to the struct ourselves. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AlignedToTwo"][::std::mem::size_of::() - 4usize]; + ["Alignment of AlignedToTwo"][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: AlignedToTwo::i", + ][::std::mem::offset_of!(AlignedToTwo, i) - 0usize]; +}; +/** This should not be opaque because although `libclang` doesn't give us the + `#pragma pack(1)`, we can detect that alignment is 1 and add + `#[repr(packed)]` to the struct ourselves.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToOne { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PackedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToOne)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PackedToOne)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) - ); -} -/// In this case, even if we can detect the weird alignment triggered by -/// `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 -/// doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PackedToOne"][::std::mem::size_of::() - 8usize]; + ["Alignment of PackedToOne"][::std::mem::align_of::() - 1usize]; + ["Offset of field: PackedToOne::x"][::std::mem::offset_of!(PackedToOne, x) - 0usize]; + ["Offset of field: PackedToOne::y"][::std::mem::offset_of!(PackedToOne, y) - 4usize]; +}; +/** In this case, even if we can detect the weird alignment triggered by + `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 + doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque.*/ #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PackedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToTwo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PackedToTwo"][::std::mem::size_of::() - 8usize]; + ["Alignment of PackedToTwo"][::std::mem::align_of::() - 2usize]; + ["Offset of field: PackedToTwo::x"][::std::mem::offset_of!(PackedToTwo, x) - 0usize]; + ["Offset of field: PackedToTwo::y"][::std::mem::offset_of!(PackedToTwo, y) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 6165419d65b1c712fdfce03e9dec9fcbb3074592..c81b672956e6bfd75282b48b6a86755cf2f9f717 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,16 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct Foo { - pub member: Foo_SecondAlias, + pub member: *mut Foo_SecondAlias, } pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; +pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs index 1516c0a95e812e0c4b64d2ca5ebc8e6d6268218e..b9c42ae12af5c5ff46f1c28eefe99e9bfad147fc 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 997a73112d8b734a5b346105d0d26fe07c92492c..567325b82d8fea395a093b23af049d066d152711 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] @@ -33,19 +27,11 @@ impl Default for JS_Base { pub struct JS_AutoIdVector { pub _base: JS_Base, } -#[test] -fn bindgen_test_layout_JS_AutoIdVector() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JS_AutoIdVector)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(JS_AutoIdVector)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of JS_AutoIdVector"][::std::mem::size_of::() - 1usize]; + ["Alignment of JS_AutoIdVector"][::std::mem::align_of::() - 1usize]; +}; impl Default for JS_AutoIdVector { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -55,19 +41,12 @@ impl Default for JS_AutoIdVector { } } } -#[test] -fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(JS_Base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(JS_Base) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: JS_Base_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: JS_Base_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs index fbff13627905ce4b4812ab4a2dee58c8f95f2887..aa5f45779287b206fb332f570310b95bf6092b78 100644 --- a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Outer { @@ -15,42 +9,20 @@ pub struct Outer { pub struct AutoIdVector { pub ar: Outer, } -#[test] -fn bindgen_test_layout_AutoIdVector() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AutoIdVector)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AutoIdVector)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AutoIdVector), - "::", - stringify!(ar) - ) - ); -} -#[test] -fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Outer)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Outer)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AutoIdVector"][::std::mem::size_of::() - 1usize]; + ["Alignment of AutoIdVector"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: AutoIdVector::ar", + ][::std::mem::offset_of!(AutoIdVector, ar) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Outer_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Outer_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 22aa9d16e6860151a73aca4d330166d646beee72..85f66c5a730c2d07725a2857840f40d9c2a4ac0b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { @@ -15,45 +9,23 @@ pub struct a { pub struct _bindgen_ty_1 { pub ar: a, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 1usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 1usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(ar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 1usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 1usize]; + [ + "Offset of field: _bindgen_ty_1::ar", + ][::std::mem::offset_of!(_bindgen_ty_1, ar) - 0usize]; +}; extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; } -#[test] -fn __bindgen_test_layout_a_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: a_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: a_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 3765315c4302b47233a2f237ba379fb977b7f578..e53b10d4afc753aec8ee0fc034fb5877ef82bb9b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -1,35 +1,20 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type RefPtr = T; - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub _address: u8, } pub type A_a = b; -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] pub struct e { - pub d: RefPtr, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub d: RefPtr, } impl Default for e { fn default() -> Self { @@ -49,27 +34,12 @@ pub struct f { pub struct g { pub h: f, } -#[test] -fn bindgen_test_layout_g() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(g)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(g)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of g"][::std::mem::size_of::() - 1usize]; + ["Alignment of g"][::std::mem::align_of::() - 1usize]; + ["Offset of field: g::h"][::std::mem::offset_of!(g, h) - 0usize]; +}; impl Default for g { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -83,19 +53,11 @@ impl Default for g { pub struct b { pub _base: g, } -#[test] -fn bindgen_test_layout_b() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of b"][::std::mem::size_of::() - 1usize]; + ["Alignment of b"][::std::mem::align_of::() - 1usize]; +}; impl Default for b { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -109,16 +71,12 @@ extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] pub fn Servo_Element_GetSnapshot() -> A; } -#[test] -fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(f)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(f)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: f_open0_e_open1_int_close1_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: f_open0_e_open1_int_close1_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs index ba886f361e1b3046928faf77f1893c14c44e7d29..db94687737839d9a6a25cfaac79789279d7f452c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub use_of_t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub use_of_t: T, } impl Default for RefPtr { fn default() -> Self { @@ -23,8 +17,8 @@ impl Default for RefPtr { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesRefPtrWithAliasedTypeParam { - pub member: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: RefPtr>, } pub type UsesRefPtrWithAliasedTypeParam_V = U; impl Default for UsesRefPtrWithAliasedTypeParam { diff --git a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs index bac8a04c240c6fb638c58f3a54304e14ffed4ed5..e940db110349c6c966561e3d5890ade89ca01a8d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -15,53 +9,18 @@ pub struct Foo { pub struct Foo_Bar { pub abc: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo_Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo_Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo_Bar), - "::", - stringify!(abc) - ) - ); -} -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo_Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo_Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo_Bar::abc"][::std::mem::offset_of!(Foo_Bar, abc) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { @@ -72,42 +31,14 @@ pub struct Baz { pub struct Baz_Bar { pub abc: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Baz_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz_Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz_Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz_Bar), - "::", - stringify!(abc) - ) - ); -} -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz_Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz_Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz_Bar::abc"][::std::mem::offset_of!(Baz_Bar, abc) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index b69aa16ef318f9c34141bd2eb78452acb570d2b8..0012c8f6aad9fcaf5ad72bc253ab25524c466721 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -48,80 +42,42 @@ pub struct rte_ring { pub struct rte_ring_prod { pub watermark: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ring_prod"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_ring_prod"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ring_prod::watermark", + ][::std::mem::offset_of!(rte_ring_prod, watermark) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rte_ring_cons { pub sc_dequeue: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) - ); -} -#[test] -fn bindgen_test_layout_rte_ring() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ring_cons"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_ring_cons"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ring_cons::sc_dequeue", + ][::std::mem::offset_of!(rte_ring_cons, sc_dequeue) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_ring"][::std::mem::size_of::() - 16usize]; + ["Alignment of rte_ring"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_ring::memzone", + ][::std::mem::offset_of!(rte_ring, memzone) - 0usize]; + ["Offset of field: rte_ring::prod"][::std::mem::offset_of!(rte_ring, prod) - 8usize]; + [ + "Offset of field: rte_ring::cons", + ][::std::mem::offset_of!(rte_ring, cons) - 12usize]; + [ + "Offset of field: rte_ring::ring", + ][::std::mem::offset_of!(rte_ring, ring) - 16usize]; +}; impl Default for rte_ring { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs index 75d6581e2dc2943ef438772c1113769ae766b67a..82e2ab4c422878cb24a9ee7bd7cc6fe540745213 100644 --- a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -1,17 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug)] pub struct RefPtr(T); - #[repr(C)] pub struct HasRefPtr { - pub refptr_member: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub refptr_member: RefPtr>, } pub type HasRefPtr_TypedefOfT = T; impl Default for HasRefPtr { diff --git a/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 13cdf0c97b9a2b8d60a24eb32c7f07604d89faf5..08e47bc2c6b88b773d02777991005185856bdef4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// We emit a `[u8; 63usize]` padding field for this struct, which cannot derive -/// Debug/Hash because 63 is over the hard coded limit. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** We emit a `[u8; 63usize]` padding field for this struct, which cannot derive + Debug/Hash because 63 is over the hard coded limit.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -15,28 +9,14 @@ pub struct NoDebug { } #[test] fn bindgen_test_layout_NoDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 64usize, - concat!("Size of: ", stringify!(NoDebug)) - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(NoDebug)) - ); + assert_eq!(::std::mem::size_of::(), 64usize, "Size of NoDebug"); + assert_eq!(::std::mem::align_of::(), 64usize, "Alignment of NoDebug"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(c) - ) + "Offset of field: NoDebug::c", ); } impl Default for NoDebug { @@ -53,10 +33,10 @@ impl ::std::cmp::PartialEq for NoDebug { self.c == other.c } } -/// This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive -/// Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don't derive Debug/Hash because -/// we determine Debug derive-ability before we compute padding, which happens at -/// codegen. +/** This should derive Debug/Hash/PartialEq/Eq because the padding size is less than the max derive + Debug/Hash/PartialEq/Eq impl for arrays. However, we conservatively don't derive Debug/Hash because + we determine Debug derive-ability before we compute padding, which happens at + codegen.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -66,38 +46,27 @@ pub struct ShouldDeriveDebugButDoesNot { } #[test] fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 64usize, - concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)) + "Size of ShouldDeriveDebugButDoesNot", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) + "Alignment of ShouldDeriveDebugButDoesNot", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(c) - ) + "Offset of field: ShouldDeriveDebugButDoesNot::c", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(d) - ) + "Offset of field: ShouldDeriveDebugButDoesNot::d", ); } impl Default for ShouldDeriveDebugButDoesNot { diff --git a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs index 65d3a516366c75e6bbd91c33b9a240b1276c4b45..289dac9a1c02cf3dcddf2f939fe03a4b98179ac1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs +++ b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs index 5636a977b4163f49cf9e4410ebef2772db377666..2e686283238cdf5600a6fbc379e89fb52f88fc26 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for RefPtr { fn default() -> Self { @@ -23,8 +17,8 @@ impl Default for RefPtr { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHolder { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for nsMainThreadPtrHolder { fn default() -> Self { @@ -38,8 +32,8 @@ impl Default for nsMainThreadPtrHolder { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHandle { - pub mPtr: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mPtr: RefPtr>, } impl Default for nsMainThreadPtrHandle { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs index e8d14bfe892253d47f702d34081578f85f377ff9..9ddcdc5e8d52f2730b70085c57155fa1ca9180f1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs @@ -1,18 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug)] pub struct RefPtr(T); - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHolder { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for nsMainThreadPtrHolder { fn default() -> Self { @@ -25,8 +18,8 @@ impl Default for nsMainThreadPtrHolder { } #[repr(C)] pub struct nsMainThreadPtrHandle { - pub mPtr: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mPtr: RefPtr>, } impl Default for nsMainThreadPtrHandle { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs index b37d7a27d706f0d9a1232705c47d139d352c8af8..1a3dce44d0aca61f049df8adfe957535c9227a3f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-1.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -24,30 +18,16 @@ pub mod root { pub struct CapturingContentInfo { pub a: u8, } - #[test] - fn bindgen_test_layout_CapturingContentInfo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(CapturingContentInfo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(CapturingContentInfo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(CapturingContentInfo), - "::", - stringify!(a) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of CapturingContentInfo", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of CapturingContentInfo", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: CapturingContentInfo::a", + ][::std::mem::offset_of!(CapturingContentInfo, a) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs index 12b2aa20a5d75433aeb06bd9a1f2b87013e25430..980928fe972f0bd3b12c97657af3a158584a7f34 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-2.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -24,75 +18,35 @@ pub mod root { pub struct c { pub b: u8, } - #[test] - fn bindgen_test_layout_c() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of c"][::std::mem::size_of::() - 1usize]; + ["Alignment of c"][::std::mem::align_of::() - 1usize]; + ["Offset of field: c::b"][::std::mem::offset_of!(c, b) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { pub a: root::c, } - #[test] - fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; + ["Offset of field: B::a"][::std::mem::offset_of!(B, a) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StaticRefPtr { pub _address: u8, } - #[test] - fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(root::StaticRefPtr) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::StaticRefPtr) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of template specialization: StaticRefPtr_open0_B_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: StaticRefPtr_open0_B_close0", + ][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs index e7af6b8dc0c3691ea3e1dcb5d50f8367939921d0..4e2f26a46f0ee66b448af936140527f0043ee346 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-3.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-3.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -20,56 +14,23 @@ pub mod root { pub struct a { pub b: u8, } - #[test] - fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of a"][::std::mem::size_of::() - 1usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsCSSValue { pub c: root::a, } - #[test] - fn bindgen_test_layout_nsCSSValue() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(nsCSSValue)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(nsCSSValue)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsCSSValue), - "::", - stringify!(c) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of nsCSSValue"][::std::mem::size_of::() - 1usize]; + ["Alignment of nsCSSValue"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: nsCSSValue::c", + ][::std::mem::offset_of!(nsCSSValue, c) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs b/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs index 800f0dc84b4b4de15b8503260666e51ef7c16532..34ec99688aadab379ab125abf76fd449b3f24830 100644 --- a/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs +++ b/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs index e71b2aae914e0922406cd4b3b9e6cec4196878ca..1313d61168989588c4fab581eb3dcec706e67b5f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct VirtualMethods__bindgen_vtable {} #[repr(C)] @@ -12,19 +6,11 @@ pub struct VirtualMethods__bindgen_vtable {} pub struct VirtualMethods { pub vtable_: *const VirtualMethods__bindgen_vtable, } -#[test] -fn bindgen_test_layout_VirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VirtualMethods)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(VirtualMethods)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of VirtualMethods"][::std::mem::size_of::() - 8usize]; + ["Alignment of VirtualMethods"][::std::mem::align_of::() - 8usize]; +}; impl Default for VirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -44,19 +30,15 @@ pub struct Set { pub struct ServoElementSnapshotTable { pub _base: Set, } -#[test] -fn bindgen_test_layout_ServoElementSnapshotTable() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ServoElementSnapshotTable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ServoElementSnapshotTable)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ServoElementSnapshotTable", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ServoElementSnapshotTable", + ][::std::mem::align_of::() - 4usize]; +}; impl Default for ServoElementSnapshotTable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -66,16 +48,12 @@ impl Default for ServoElementSnapshotTable { } } } -#[test] -fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of template specialization: ", stringify!(Set)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of template specialization: ", stringify!(Set)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Set_open0_VirtualMethods_close0", + ][::std::mem::size_of::() - 4usize]; + [ + "Align of template specialization: Set_open0_VirtualMethods_close0", + ][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs b/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs index 1d59824146524e247b18ece051ca0e5e998dd4c2..d7006dd011056a0584bfcece1a97fbbb49e2e76a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] #[must_use] diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 1a633844f271b85dd77c8126edce635c11bb5c82..84dc763e6fdaebd7e349b4106e0b030e559d6065 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -56,8 +50,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -77,8 +70,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -93,31 +85,20 @@ where } } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize]>, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 32usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; +}; impl Foo { #[inline] pub fn m_bitfield(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 64u8) as u64) } } #[inline] pub fn set_m_bitfield(&mut self, val: ::std::os::raw::c_ulong) { @@ -128,9 +109,7 @@ impl Foo { } #[inline] pub fn m_bar(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(64usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 64u8) as u64) } } #[inline] pub fn set_m_bar(&mut self, val: ::std::os::raw::c_ulong) { @@ -141,9 +120,7 @@ impl Foo { } #[inline] pub fn foo(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(128usize, 1u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 1u8) as u64) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_ulong) { @@ -154,9 +131,7 @@ impl Foo { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(192usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 64u8) as u64) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_ulong) { @@ -172,24 +147,43 @@ impl Foo { foo: ::std::os::raw::c_ulong, bar: ::std::os::raw::c_ulong, ) -> __BindgenBitfieldUnit<[u8; 32usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 32usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 64u8, { - let m_bitfield: u64 = unsafe { ::std::mem::transmute(m_bitfield) }; - m_bitfield as u64 - }); - __bindgen_bitfield_unit.set(64usize, 64u8, { - let m_bar: u64 = unsafe { ::std::mem::transmute(m_bar) }; - m_bar as u64 - }); - __bindgen_bitfield_unit.set(128usize, 1u8, { - let foo: u64 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(192usize, 64u8, { - let bar: u64 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 32usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 64u8, + { + let m_bitfield: u64 = unsafe { ::std::mem::transmute(m_bitfield) }; + m_bitfield as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 64usize, + 64u8, + { + let m_bar: u64 = unsafe { ::std::mem::transmute(m_bar) }; + m_bar as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 128usize, + 1u8, + { + let foo: u64 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 192usize, + 64u8, + { + let bar: u64 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-753.rs b/bindgen-tests/tests/expectations/tests/issue-753.rs new file mode 100644 index 0000000000000000000000000000000000000000..3119ec569e092eaaa31c9b68d72264f40ff7814a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-753.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const CONST: u32 = 5; +pub const OTHER_CONST: u32 = 6; +pub const LARGE_CONST: u32 = 1536; diff --git a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs new file mode 100644 index 0000000000000000000000000000000000000000..59a1d9afa3841be1f9647938014fabbf5acc1241 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Copy, Clone)] + pub struct Rooted { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, + } + impl Default for Rooted { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } + } + pub type AutoValueVector_Alias = ::std::os::raw::c_int; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of template specialization: Rooted_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: Rooted_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of template specialization: Rooted_open0_AutoValueVector_Alias_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: Rooted_open0_AutoValueVector_Alias_close0", + ][::std::mem::align_of::>() - 4usize]; + }; +} diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index b3192b72436a68ed414c945e2f475edcf56e456c..b08ef2fd1d14195ae2e2882d33dc41d8b755b663 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct A { @@ -16,19 +10,11 @@ pub struct A { pub struct B { pub _bindgen_opaque_blob: u8, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1B1aE"] pub static mut B_a: A; @@ -38,24 +24,9 @@ extern "C" { pub struct C { pub b: B, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; + ["Offset of field: C::b"][::std::mem::offset_of!(C, b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index f886952822e9a973295ad59128a8771e478ad289..c0150a73f04c598ae50db9b9b8edf475680062ea 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -1,83 +1,45 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Pupper { pub _address: u8, } -#[test] -fn bindgen_test_layout_Pupper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Pupper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Pupper)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Pupper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Pupper"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Doggo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Doggo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Doggo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Doggo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Doggo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Doggo"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct SuchWow { pub _address: u8, } -#[test] -fn bindgen_test_layout_SuchWow() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(SuchWow)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(SuchWow)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of SuchWow"][::std::mem::size_of::() - 1usize]; + ["Alignment of SuchWow"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[repr(align(1))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { pub _bindgen_opaque_blob: u8, } -#[test] -fn bindgen_test_layout_Opaque() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Opaque)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Opaque)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Opaque"][::std::mem::size_of::() - 1usize]; + ["Alignment of Opaque"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN6Opaque17eleven_out_of_tenEv"] pub fn Opaque_eleven_out_of_ten(this: *mut Opaque) -> SuchWow; @@ -107,31 +69,11 @@ extern "C" { pub struct Allowlisted { pub some_member: Opaque, } -#[test] -fn bindgen_test_layout_Allowlisted() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Allowlisted)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Allowlisted)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Allowlisted), - "::", - stringify!(some_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Allowlisted"][::std::mem::size_of::() - 1usize]; + ["Alignment of Allowlisted"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Allowlisted::some_member", + ][::std::mem::offset_of!(Allowlisted, some_member) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index c7f94106f4b080ab204413fd211a043d4779d522..1f1112eff58d6c0239e6147dacdfb9e33f628afd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,25 +90,15 @@ pub struct capabilities { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_capabilities() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(capabilities)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(capabilities)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of capabilities"][::std::mem::size_of::() - 16usize]; + ["Alignment of capabilities"][::std::mem::align_of::() - 4usize]; +}; impl capabilities { #[inline] pub fn bit_1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_bit_1(&mut self, val: ::std::os::raw::c_uint) { @@ -127,9 +109,7 @@ impl capabilities { } #[inline] pub fn bit_2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_bit_2(&mut self, val: ::std::os::raw::c_uint) { @@ -140,9 +120,7 @@ impl capabilities { } #[inline] pub fn bit_3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } #[inline] pub fn set_bit_3(&mut self, val: ::std::os::raw::c_uint) { @@ -153,9 +131,7 @@ impl capabilities { } #[inline] pub fn bit_4(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } #[inline] pub fn set_bit_4(&mut self, val: ::std::os::raw::c_uint) { @@ -166,9 +142,7 @@ impl capabilities { } #[inline] pub fn bit_5(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } #[inline] pub fn set_bit_5(&mut self, val: ::std::os::raw::c_uint) { @@ -179,9 +153,7 @@ impl capabilities { } #[inline] pub fn bit_6(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } #[inline] pub fn set_bit_6(&mut self, val: ::std::os::raw::c_uint) { @@ -192,9 +164,7 @@ impl capabilities { } #[inline] pub fn bit_7(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } #[inline] pub fn set_bit_7(&mut self, val: ::std::os::raw::c_uint) { @@ -205,9 +175,7 @@ impl capabilities { } #[inline] pub fn bit_8(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } #[inline] pub fn set_bit_8(&mut self, val: ::std::os::raw::c_uint) { @@ -218,9 +186,7 @@ impl capabilities { } #[inline] pub fn bit_9(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } #[inline] pub fn set_bit_9(&mut self, val: ::std::os::raw::c_uint) { @@ -231,9 +197,7 @@ impl capabilities { } #[inline] pub fn bit_10(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } #[inline] pub fn set_bit_10(&mut self, val: ::std::os::raw::c_uint) { @@ -244,9 +208,7 @@ impl capabilities { } #[inline] pub fn bit_11(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u32) } } #[inline] pub fn set_bit_11(&mut self, val: ::std::os::raw::c_uint) { @@ -257,9 +219,7 @@ impl capabilities { } #[inline] pub fn bit_12(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u32) } } #[inline] pub fn set_bit_12(&mut self, val: ::std::os::raw::c_uint) { @@ -270,9 +230,7 @@ impl capabilities { } #[inline] pub fn bit_13(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u32) } } #[inline] pub fn set_bit_13(&mut self, val: ::std::os::raw::c_uint) { @@ -283,9 +241,7 @@ impl capabilities { } #[inline] pub fn bit_14(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u32) } } #[inline] pub fn set_bit_14(&mut self, val: ::std::os::raw::c_uint) { @@ -296,9 +252,7 @@ impl capabilities { } #[inline] pub fn bit_15(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u32) } } #[inline] pub fn set_bit_15(&mut self, val: ::std::os::raw::c_uint) { @@ -309,9 +263,7 @@ impl capabilities { } #[inline] pub fn bit_16(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u32) } } #[inline] pub fn set_bit_16(&mut self, val: ::std::os::raw::c_uint) { @@ -322,9 +274,7 @@ impl capabilities { } #[inline] pub fn bit_17(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u32) } } #[inline] pub fn set_bit_17(&mut self, val: ::std::os::raw::c_uint) { @@ -335,9 +285,7 @@ impl capabilities { } #[inline] pub fn bit_18(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u32) } } #[inline] pub fn set_bit_18(&mut self, val: ::std::os::raw::c_uint) { @@ -348,9 +296,7 @@ impl capabilities { } #[inline] pub fn bit_19(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u32) } } #[inline] pub fn set_bit_19(&mut self, val: ::std::os::raw::c_uint) { @@ -361,9 +307,7 @@ impl capabilities { } #[inline] pub fn bit_20(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u32) } } #[inline] pub fn set_bit_20(&mut self, val: ::std::os::raw::c_uint) { @@ -374,9 +318,7 @@ impl capabilities { } #[inline] pub fn bit_21(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u32) } } #[inline] pub fn set_bit_21(&mut self, val: ::std::os::raw::c_uint) { @@ -387,9 +329,7 @@ impl capabilities { } #[inline] pub fn bit_22(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u32) } } #[inline] pub fn set_bit_22(&mut self, val: ::std::os::raw::c_uint) { @@ -400,9 +340,7 @@ impl capabilities { } #[inline] pub fn bit_23(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u32) } } #[inline] pub fn set_bit_23(&mut self, val: ::std::os::raw::c_uint) { @@ -413,9 +351,7 @@ impl capabilities { } #[inline] pub fn bit_24(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u32) } } #[inline] pub fn set_bit_24(&mut self, val: ::std::os::raw::c_uint) { @@ -426,9 +362,7 @@ impl capabilities { } #[inline] pub fn bit_25(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u32) } } #[inline] pub fn set_bit_25(&mut self, val: ::std::os::raw::c_uint) { @@ -439,9 +373,7 @@ impl capabilities { } #[inline] pub fn bit_26(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u32) } } #[inline] pub fn set_bit_26(&mut self, val: ::std::os::raw::c_uint) { @@ -452,9 +384,7 @@ impl capabilities { } #[inline] pub fn bit_27(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u32) } } #[inline] pub fn set_bit_27(&mut self, val: ::std::os::raw::c_uint) { @@ -465,9 +395,7 @@ impl capabilities { } #[inline] pub fn bit_28(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u32) } } #[inline] pub fn set_bit_28(&mut self, val: ::std::os::raw::c_uint) { @@ -478,9 +406,7 @@ impl capabilities { } #[inline] pub fn bit_29(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u32) } } #[inline] pub fn set_bit_29(&mut self, val: ::std::os::raw::c_uint) { @@ -491,9 +417,7 @@ impl capabilities { } #[inline] pub fn bit_30(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u32) } } #[inline] pub fn set_bit_30(&mut self, val: ::std::os::raw::c_uint) { @@ -504,9 +428,7 @@ impl capabilities { } #[inline] pub fn bit_31(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u32) } } #[inline] pub fn set_bit_31(&mut self, val: ::std::os::raw::c_uint) { @@ -517,9 +439,7 @@ impl capabilities { } #[inline] pub fn bit_32(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) } } #[inline] pub fn set_bit_32(&mut self, val: ::std::os::raw::c_uint) { @@ -530,9 +450,7 @@ impl capabilities { } #[inline] pub fn bit_33(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u32) } } #[inline] pub fn set_bit_33(&mut self, val: ::std::os::raw::c_uint) { @@ -543,9 +461,7 @@ impl capabilities { } #[inline] pub fn bit_34(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(33usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(33usize, 1u8) as u32) } } #[inline] pub fn set_bit_34(&mut self, val: ::std::os::raw::c_uint) { @@ -556,9 +472,7 @@ impl capabilities { } #[inline] pub fn bit_35(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(34usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(34usize, 1u8) as u32) } } #[inline] pub fn set_bit_35(&mut self, val: ::std::os::raw::c_uint) { @@ -569,9 +483,7 @@ impl capabilities { } #[inline] pub fn bit_36(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(35usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(35usize, 1u8) as u32) } } #[inline] pub fn set_bit_36(&mut self, val: ::std::os::raw::c_uint) { @@ -582,9 +494,7 @@ impl capabilities { } #[inline] pub fn bit_37(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(36usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(36usize, 1u8) as u32) } } #[inline] pub fn set_bit_37(&mut self, val: ::std::os::raw::c_uint) { @@ -595,9 +505,7 @@ impl capabilities { } #[inline] pub fn bit_38(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(37usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(37usize, 1u8) as u32) } } #[inline] pub fn set_bit_38(&mut self, val: ::std::os::raw::c_uint) { @@ -608,9 +516,7 @@ impl capabilities { } #[inline] pub fn bit_39(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(38usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(38usize, 1u8) as u32) } } #[inline] pub fn set_bit_39(&mut self, val: ::std::os::raw::c_uint) { @@ -621,9 +527,7 @@ impl capabilities { } #[inline] pub fn bit_40(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(39usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(39usize, 1u8) as u32) } } #[inline] pub fn set_bit_40(&mut self, val: ::std::os::raw::c_uint) { @@ -634,9 +538,7 @@ impl capabilities { } #[inline] pub fn bit_41(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 1u8) as u32) } } #[inline] pub fn set_bit_41(&mut self, val: ::std::os::raw::c_uint) { @@ -689,172 +591,376 @@ impl capabilities { bit_40: ::std::os::raw::c_uint, bit_41: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let bit_1: u32 = unsafe { ::std::mem::transmute(bit_1) }; - bit_1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let bit_2: u32 = unsafe { ::std::mem::transmute(bit_2) }; - bit_2 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let bit_3: u32 = unsafe { ::std::mem::transmute(bit_3) }; - bit_3 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let bit_4: u32 = unsafe { ::std::mem::transmute(bit_4) }; - bit_4 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let bit_5: u32 = unsafe { ::std::mem::transmute(bit_5) }; - bit_5 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let bit_6: u32 = unsafe { ::std::mem::transmute(bit_6) }; - bit_6 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let bit_7: u32 = unsafe { ::std::mem::transmute(bit_7) }; - bit_7 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let bit_8: u32 = unsafe { ::std::mem::transmute(bit_8) }; - bit_8 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let bit_9: u32 = unsafe { ::std::mem::transmute(bit_9) }; - bit_9 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let bit_10: u32 = unsafe { ::std::mem::transmute(bit_10) }; - bit_10 as u64 - }); - __bindgen_bitfield_unit.set(10usize, 1u8, { - let bit_11: u32 = unsafe { ::std::mem::transmute(bit_11) }; - bit_11 as u64 - }); - __bindgen_bitfield_unit.set(11usize, 1u8, { - let bit_12: u32 = unsafe { ::std::mem::transmute(bit_12) }; - bit_12 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 1u8, { - let bit_13: u32 = unsafe { ::std::mem::transmute(bit_13) }; - bit_13 as u64 - }); - __bindgen_bitfield_unit.set(13usize, 1u8, { - let bit_14: u32 = unsafe { ::std::mem::transmute(bit_14) }; - bit_14 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 1u8, { - let bit_15: u32 = unsafe { ::std::mem::transmute(bit_15) }; - bit_15 as u64 - }); - __bindgen_bitfield_unit.set(15usize, 1u8, { - let bit_16: u32 = unsafe { ::std::mem::transmute(bit_16) }; - bit_16 as u64 - }); - __bindgen_bitfield_unit.set(16usize, 1u8, { - let bit_17: u32 = unsafe { ::std::mem::transmute(bit_17) }; - bit_17 as u64 - }); - __bindgen_bitfield_unit.set(17usize, 1u8, { - let bit_18: u32 = unsafe { ::std::mem::transmute(bit_18) }; - bit_18 as u64 - }); - __bindgen_bitfield_unit.set(18usize, 1u8, { - let bit_19: u32 = unsafe { ::std::mem::transmute(bit_19) }; - bit_19 as u64 - }); - __bindgen_bitfield_unit.set(19usize, 1u8, { - let bit_20: u32 = unsafe { ::std::mem::transmute(bit_20) }; - bit_20 as u64 - }); - __bindgen_bitfield_unit.set(20usize, 1u8, { - let bit_21: u32 = unsafe { ::std::mem::transmute(bit_21) }; - bit_21 as u64 - }); - __bindgen_bitfield_unit.set(21usize, 1u8, { - let bit_22: u32 = unsafe { ::std::mem::transmute(bit_22) }; - bit_22 as u64 - }); - __bindgen_bitfield_unit.set(22usize, 1u8, { - let bit_23: u32 = unsafe { ::std::mem::transmute(bit_23) }; - bit_23 as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let bit_24: u32 = unsafe { ::std::mem::transmute(bit_24) }; - bit_24 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 1u8, { - let bit_25: u32 = unsafe { ::std::mem::transmute(bit_25) }; - bit_25 as u64 - }); - __bindgen_bitfield_unit.set(25usize, 1u8, { - let bit_26: u32 = unsafe { ::std::mem::transmute(bit_26) }; - bit_26 as u64 - }); - __bindgen_bitfield_unit.set(26usize, 1u8, { - let bit_27: u32 = unsafe { ::std::mem::transmute(bit_27) }; - bit_27 as u64 - }); - __bindgen_bitfield_unit.set(27usize, 1u8, { - let bit_28: u32 = unsafe { ::std::mem::transmute(bit_28) }; - bit_28 as u64 - }); - __bindgen_bitfield_unit.set(28usize, 1u8, { - let bit_29: u32 = unsafe { ::std::mem::transmute(bit_29) }; - bit_29 as u64 - }); - __bindgen_bitfield_unit.set(29usize, 1u8, { - let bit_30: u32 = unsafe { ::std::mem::transmute(bit_30) }; - bit_30 as u64 - }); - __bindgen_bitfield_unit.set(30usize, 1u8, { - let bit_31: u32 = unsafe { ::std::mem::transmute(bit_31) }; - bit_31 as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bit_32: u32 = unsafe { ::std::mem::transmute(bit_32) }; - bit_32 as u64 - }); - __bindgen_bitfield_unit.set(32usize, 1u8, { - let bit_33: u32 = unsafe { ::std::mem::transmute(bit_33) }; - bit_33 as u64 - }); - __bindgen_bitfield_unit.set(33usize, 1u8, { - let bit_34: u32 = unsafe { ::std::mem::transmute(bit_34) }; - bit_34 as u64 - }); - __bindgen_bitfield_unit.set(34usize, 1u8, { - let bit_35: u32 = unsafe { ::std::mem::transmute(bit_35) }; - bit_35 as u64 - }); - __bindgen_bitfield_unit.set(35usize, 1u8, { - let bit_36: u32 = unsafe { ::std::mem::transmute(bit_36) }; - bit_36 as u64 - }); - __bindgen_bitfield_unit.set(36usize, 1u8, { - let bit_37: u32 = unsafe { ::std::mem::transmute(bit_37) }; - bit_37 as u64 - }); - __bindgen_bitfield_unit.set(37usize, 1u8, { - let bit_38: u32 = unsafe { ::std::mem::transmute(bit_38) }; - bit_38 as u64 - }); - __bindgen_bitfield_unit.set(38usize, 1u8, { - let bit_39: u32 = unsafe { ::std::mem::transmute(bit_39) }; - bit_39 as u64 - }); - __bindgen_bitfield_unit.set(39usize, 1u8, { - let bit_40: u32 = unsafe { ::std::mem::transmute(bit_40) }; - bit_40 as u64 - }); - __bindgen_bitfield_unit.set(40usize, 1u8, { - let bit_41: u32 = unsafe { ::std::mem::transmute(bit_41) }; - bit_41 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let bit_1: u32 = unsafe { ::std::mem::transmute(bit_1) }; + bit_1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let bit_2: u32 = unsafe { ::std::mem::transmute(bit_2) }; + bit_2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let bit_3: u32 = unsafe { ::std::mem::transmute(bit_3) }; + bit_3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let bit_4: u32 = unsafe { ::std::mem::transmute(bit_4) }; + bit_4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let bit_5: u32 = unsafe { ::std::mem::transmute(bit_5) }; + bit_5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let bit_6: u32 = unsafe { ::std::mem::transmute(bit_6) }; + bit_6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let bit_7: u32 = unsafe { ::std::mem::transmute(bit_7) }; + bit_7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let bit_8: u32 = unsafe { ::std::mem::transmute(bit_8) }; + bit_8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let bit_9: u32 = unsafe { ::std::mem::transmute(bit_9) }; + bit_9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let bit_10: u32 = unsafe { ::std::mem::transmute(bit_10) }; + bit_10 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 1u8, + { + let bit_11: u32 = unsafe { ::std::mem::transmute(bit_11) }; + bit_11 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 11usize, + 1u8, + { + let bit_12: u32 = unsafe { ::std::mem::transmute(bit_12) }; + bit_12 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 1u8, + { + let bit_13: u32 = unsafe { ::std::mem::transmute(bit_13) }; + bit_13 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 13usize, + 1u8, + { + let bit_14: u32 = unsafe { ::std::mem::transmute(bit_14) }; + bit_14 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 1u8, + { + let bit_15: u32 = unsafe { ::std::mem::transmute(bit_15) }; + bit_15 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 15usize, + 1u8, + { + let bit_16: u32 = unsafe { ::std::mem::transmute(bit_16) }; + bit_16 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 1u8, + { + let bit_17: u32 = unsafe { ::std::mem::transmute(bit_17) }; + bit_17 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 17usize, + 1u8, + { + let bit_18: u32 = unsafe { ::std::mem::transmute(bit_18) }; + bit_18 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 18usize, + 1u8, + { + let bit_19: u32 = unsafe { ::std::mem::transmute(bit_19) }; + bit_19 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 19usize, + 1u8, + { + let bit_20: u32 = unsafe { ::std::mem::transmute(bit_20) }; + bit_20 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 1u8, + { + let bit_21: u32 = unsafe { ::std::mem::transmute(bit_21) }; + bit_21 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 21usize, + 1u8, + { + let bit_22: u32 = unsafe { ::std::mem::transmute(bit_22) }; + bit_22 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 22usize, + 1u8, + { + let bit_23: u32 = unsafe { ::std::mem::transmute(bit_23) }; + bit_23 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let bit_24: u32 = unsafe { ::std::mem::transmute(bit_24) }; + bit_24 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 1u8, + { + let bit_25: u32 = unsafe { ::std::mem::transmute(bit_25) }; + bit_25 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 25usize, + 1u8, + { + let bit_26: u32 = unsafe { ::std::mem::transmute(bit_26) }; + bit_26 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 26usize, + 1u8, + { + let bit_27: u32 = unsafe { ::std::mem::transmute(bit_27) }; + bit_27 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 27usize, + 1u8, + { + let bit_28: u32 = unsafe { ::std::mem::transmute(bit_28) }; + bit_28 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 28usize, + 1u8, + { + let bit_29: u32 = unsafe { ::std::mem::transmute(bit_29) }; + bit_29 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 29usize, + 1u8, + { + let bit_30: u32 = unsafe { ::std::mem::transmute(bit_30) }; + bit_30 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 30usize, + 1u8, + { + let bit_31: u32 = unsafe { ::std::mem::transmute(bit_31) }; + bit_31 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bit_32: u32 = unsafe { ::std::mem::transmute(bit_32) }; + bit_32 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 1u8, + { + let bit_33: u32 = unsafe { ::std::mem::transmute(bit_33) }; + bit_33 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 33usize, + 1u8, + { + let bit_34: u32 = unsafe { ::std::mem::transmute(bit_34) }; + bit_34 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 34usize, + 1u8, + { + let bit_35: u32 = unsafe { ::std::mem::transmute(bit_35) }; + bit_35 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 35usize, + 1u8, + { + let bit_36: u32 = unsafe { ::std::mem::transmute(bit_36) }; + bit_36 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 36usize, + 1u8, + { + let bit_37: u32 = unsafe { ::std::mem::transmute(bit_37) }; + bit_37 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 37usize, + 1u8, + { + let bit_38: u32 = unsafe { ::std::mem::transmute(bit_38) }; + bit_38 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 38usize, + 1u8, + { + let bit_39: u32 = unsafe { ::std::mem::transmute(bit_39) }; + bit_39 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 39usize, + 1u8, + { + let bit_40: u32 = unsafe { ::std::mem::transmute(bit_40) }; + bit_40 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 1u8, + { + let bit_41: u32 = unsafe { ::std::mem::transmute(bit_41) }; + bit_41 as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs b/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs index cfe00784553d323e9bf0a151e94bf5f89420e22f..a367e2e0e13949587a9f8ee96a054e38877ef00b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs +++ b/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Foo_self_type = u8; diff --git a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index f5ba025a25a0697bb796d28c00ac4be4b6f5b0ff..551dff82cfb9e323724af19dbf5e8991f42ec22a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-833-1.rs b/bindgen-tests/tests/expectations/tests/issue-833-1.rs index f91266f634fdda948760fdb9d14c69bfaf630c88..b86a4e0df358d428fbebd7487a3e79557e7809c4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833-1.rs @@ -1,15 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsTArray { pub hdr: *const (), } - extern "C" { pub fn func() -> *mut nsTArray; } diff --git a/bindgen-tests/tests/expectations/tests/issue-833-2.rs b/bindgen-tests/tests/expectations/tests/issue-833-2.rs index 1dfe1abda6b4a8bb9c897fb3a5476e8c30cc164a..b8ef2f855484200a49d8ea0692e2ca5566c55665 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833-2.rs @@ -1,12 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -// If the output of this changes, please ensure issue-833-1.hpp changes too - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsTArray { diff --git a/bindgen-tests/tests/expectations/tests/issue-833.rs b/bindgen-tests/tests/expectations/tests/issue-833.rs index a092fb715661c7c40127d77a291e6e51bb70b806..2a2d375e894da6488b37112dbae1fff58c6c4975 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833.rs @@ -1,15 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsTArray { pub hdr: *const T, } - extern "C" { pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; } diff --git a/bindgen-tests/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs index 465341fb71ad1ce510c3244c795ddba931b4a9bb..4119a450e01995cfb76c191109536d02252cd271 100644 --- a/bindgen-tests/tests/expectations/tests/issue-834.rs +++ b/bindgen-tests/tests/expectations/tests/issue-834.rs @@ -1,25 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct U { pub _address: u8, } -#[test] -fn bindgen_test_layout_U() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(U)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(U)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of U"][::std::mem::size_of::() - 1usize]; + ["Alignment of U"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs index 294df575da3717d31eb77e7f4250ce88e266857e..d224612ba983e932a6b11d0a8dcf439602cb7fc7 100644 --- a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -1,21 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is intended to replace another type, but won't if we treat this include + as a system include, because clang doesn't parse comments there. -/// This is intended to replace another type, but won't if we treat this include -/// as a system include, because clang doesn't parse comments there. -/// -/// See #848. -/// -///
+ See #848. + +
*/ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { - pub m: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m: *mut T, } impl Default for nsTArray { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 6ac308a74f398f670911635128e341024b7d6cab..0a0d05f9f91b118e0becee33f0467b8c64d8cdca 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -21,19 +15,11 @@ pub mod root { #[link_name = "\u{1}_ZN6Halide4Type1bE"] pub static mut Type_b: root::a; } - #[test] - fn bindgen_test_layout_Type() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Type)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Type)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Type"][::std::mem::size_of::() - 1usize]; + ["Alignment of Type"][::std::mem::align_of::() - 1usize]; + }; } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index d9c365d82810f5d8b0154dc8196c99f109bac406..5e8dde04e3fc264dd05bac2c352e500feb8a0064 100644 --- a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -1,43 +1,18 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Copy. #[repr(C)] pub struct ShouldNotBeCopy { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotBeCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotBeCopy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotBeCopy)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotBeCopy), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ShouldNotBeCopy"][::std::mem::size_of::() - 1usize]; + ["Alignment of ShouldNotBeCopy"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotBeCopy::a", + ][::std::mem::offset_of!(ShouldNotBeCopy, a) - 0usize]; +}; impl Default for ShouldNotBeCopy { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs index 897700b3258cad6e2ef07f0f76094fa86da8a162..bdd56c032600384a3106ddff736e318b661aa97d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-946.rs +++ b/bindgen-tests/tests/expectations/tests/issue-946.rs @@ -1,24 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo {} -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 0usize]; + ["Alignment of foo"][::std::mem::align_of::() - 1usize]; +}; pub type bar = foo; diff --git a/bindgen-tests/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs index 49e30d84072db136e6eefc5b9fb386bfbadb0b81..2e0114e43e68a30ab1591e4ef46c203e13dd9911 100644 --- a/bindgen-tests/tests/expectations/tests/issue_311.rs +++ b/bindgen-tests/tests/expectations/tests/issue_311.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -19,30 +13,18 @@ pub mod root { pub struct jsval_layout__bindgen_ty_1 { pub _address: u8, } - #[test] - fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) - ); - } - #[test] - fn bindgen_test_layout_jsval_layout() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(jsval_layout)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(jsval_layout)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of jsval_layout__bindgen_ty_1", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of jsval_layout__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of jsval_layout"][::std::mem::size_of::() - 1usize]; + ["Alignment of jsval_layout"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue_315.rs b/bindgen-tests/tests/expectations/tests/issue_315.rs index 71ae1f2746bedf12ae345111a2e55a614b9ad65a..cecdccc2aaca7192f830c9ca1363e359d00b46c5 100644 --- a/bindgen-tests/tests/expectations/tests/issue_315.rs +++ b/bindgen-tests/tests/expectations/tests/issue_315.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
pub type c
= a; diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index a812e905603ed847985ab53ec60f49c040bd17c2..e7cb9af39ebdf39412a4ab4e7aa3e91fabefb42f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -189,25 +181,20 @@ pub union jsval_layout { pub asUIntPtr: usize, } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of jsval_layout__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for jsval_layout__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -220,9 +207,7 @@ impl Default for jsval_layout__bindgen_ty_1 { impl jsval_layout__bindgen_ty_1 { #[inline] pub fn payload47(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) } } #[inline] pub fn set_payload47(&mut self, val: u64) { @@ -233,9 +218,7 @@ impl jsval_layout__bindgen_ty_1 { } #[inline] pub fn tag(&self) -> JSValueTag { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: JSValueTag) { @@ -249,16 +232,25 @@ impl jsval_layout__bindgen_ty_1 { payload47: u64, tag: JSValueTag, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 47u8, { - let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; - payload47 as u64 - }); - __bindgen_bitfield_unit.set(47usize, 17u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 47u8, + { + let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; + payload47 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 47usize, + 17u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); __bindgen_bitfield_unit } } @@ -274,59 +266,24 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub u32_: u32, pub why: JSWhyMagic, } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of jsval_layout__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::i32_", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, i32_) - 0usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::u32_", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, u32_) - 0usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::why", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, why) - 0usize]; +}; impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -336,32 +293,18 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of jsval_layout__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2::payload", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2, payload) - 0usize]; +}; impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -371,98 +314,32 @@ impl Default for jsval_layout__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of jsval_layout"][::std::mem::size_of::() - 8usize]; + ["Alignment of jsval_layout"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: jsval_layout::asBits", + ][::std::mem::offset_of!(jsval_layout, asBits) - 0usize]; + [ + "Offset of field: jsval_layout::debugView", + ][::std::mem::offset_of!(jsval_layout, debugView) - 0usize]; + [ + "Offset of field: jsval_layout::s", + ][::std::mem::offset_of!(jsval_layout, s) - 0usize]; + [ + "Offset of field: jsval_layout::asDouble", + ][::std::mem::offset_of!(jsval_layout, asDouble) - 0usize]; + [ + "Offset of field: jsval_layout::asPtr", + ][::std::mem::offset_of!(jsval_layout, asPtr) - 0usize]; + [ + "Offset of field: jsval_layout::asWord", + ][::std::mem::offset_of!(jsval_layout, asWord) - 0usize]; + [ + "Offset of field: jsval_layout::asUIntPtr", + ][::std::mem::offset_of!(jsval_layout, asUIntPtr) - 0usize]; +}; impl Default for jsval_layout { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -477,32 +354,12 @@ impl Default for jsval_layout { pub struct Value { pub data: jsval_layout, } -#[test] -fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Value"][::std::mem::size_of::() - 8usize]; + ["Alignment of Value"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Value::data"][::std::mem::offset_of!(Value, data) - 0usize]; +}; impl Default for Value { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index b43949935593691b47cfd4d80de236f1c256909e..7ae53bc40ff60d045bbc0a48684991853ce1356d 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -237,19 +229,18 @@ pub struct jsval_layout { pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) + "Size of jsval_layout__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) + "Alignment of jsval_layout__bindgen_ty_1", ); } impl Clone for jsval_layout__bindgen_ty_1 { @@ -269,9 +260,7 @@ impl Default for jsval_layout__bindgen_ty_1 { impl jsval_layout__bindgen_ty_1 { #[inline] pub fn payload47(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) } } #[inline] pub fn set_payload47(&mut self, val: u64) { @@ -282,9 +271,7 @@ impl jsval_layout__bindgen_ty_1 { } #[inline] pub fn tag(&self) -> JSValueTag { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: JSValueTag) { @@ -298,16 +285,25 @@ impl jsval_layout__bindgen_ty_1 { payload47: u64, tag: JSValueTag, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 47u8, { - let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; - payload47 as u64 - }); - __bindgen_bitfield_unit.set(47usize, 17u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 47u8, + { + let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; + payload47 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 47usize, + 17u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); __bindgen_bitfield_unit } } @@ -326,55 +322,32 @@ pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + "Alignment of jsval_layout__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::i32_", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::u32_", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::why", ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -384,28 +357,22 @@ impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) + "Size of jsval_layout__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) + "Alignment of jsval_layout__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) + "Offset of field: jsval_layout__bindgen_ty_2::payload", ); } impl Clone for jsval_layout__bindgen_ty_2 { @@ -415,94 +382,48 @@ impl Clone for jsval_layout__bindgen_ty_2 { } #[test] fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of jsval_layout"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(jsval_layout)) + "Alignment of jsval_layout", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) + "Offset of field: jsval_layout::asBits", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) + "Offset of field: jsval_layout::debugView", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) + "Offset of field: jsval_layout::s", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) + "Offset of field: jsval_layout::asDouble", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) + "Offset of field: jsval_layout::asPtr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) + "Offset of field: jsval_layout::asWord", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) + "Offset of field: jsval_layout::asUIntPtr", ); } impl Clone for jsval_layout { @@ -517,28 +438,14 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Value"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Value"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) + "Offset of field: Value::data", ); } impl Clone for Value { diff --git a/bindgen-tests/tests/expectations/tests/keywords.rs b/bindgen-tests/tests/expectations/tests/keywords.rs index a1e7f877e185f418fae93a36619a9910c3020c99..d07f241376a4dd6b830bb11ae826e4c9a074640c 100644 --- a/bindgen-tests/tests/expectations/tests/keywords.rs +++ b/bindgen-tests/tests/expectations/tests/keywords.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}u8"] pub static mut u8_: ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index ae417259cd4603cc589293b5e058b48fd91c658e..8c4819f5434175c1fe30410155040c5befb5dcad 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -1,21 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct header { pub _bindgen_opaque_blob: [u8; 16usize], } #[test] fn bindgen_test_layout_header() { - assert_eq!( - ::std::mem::size_of::
(), - 16usize, - concat!("Size of: ", stringify!(header)) - ); + assert_eq!(::std::mem::size_of::
(), 16usize, "Size of header"); } impl Default for header { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 466e76862ce864b15e99460ea4efee06a0983145..c641ff843f3137c90262ec0325ee2157c2855d24 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -135,19 +127,26 @@ pub struct rte_kni_fifo { ///< The buffer contains mbuf pointers pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } -#[test] -fn bindgen_test_layout_rte_kni_fifo() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_kni_fifo"][::std::mem::size_of::() - 16usize]; + ["Alignment of rte_kni_fifo"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_kni_fifo::write", + ][::std::mem::offset_of!(rte_kni_fifo, write) - 0usize]; + [ + "Offset of field: rte_kni_fifo::read", + ][::std::mem::offset_of!(rte_kni_fifo, read) - 4usize]; + [ + "Offset of field: rte_kni_fifo::len", + ][::std::mem::offset_of!(rte_kni_fifo, len) - 8usize]; + [ + "Offset of field: rte_kni_fifo::elem_size", + ][::std::mem::offset_of!(rte_kni_fifo, elem_size) - 12usize]; + [ + "Offset of field: rte_kni_fifo::buffer", + ][::std::mem::offset_of!(rte_kni_fifo, buffer) - 16usize]; +}; impl Default for rte_kni_fifo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -167,40 +166,18 @@ pub struct rte_eth_link { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_eth_link"][::std::mem::size_of::() - 8usize]; + ["Alignment of rte_eth_link"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_eth_link::link_speed", + ][::std::mem::offset_of!(rte_eth_link, link_speed) - 0usize]; +}; impl rte_eth_link { #[inline] pub fn link_duplex(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_link_duplex(&mut self, val: u16) { @@ -211,9 +188,7 @@ impl rte_eth_link { } #[inline] pub fn link_autoneg(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_link_autoneg(&mut self, val: u16) { @@ -224,9 +199,7 @@ impl rte_eth_link { } #[inline] pub fn link_status(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_link_status(&mut self, val: u16) { @@ -241,23 +214,36 @@ impl rte_eth_link { link_autoneg: u16, link_status: u16, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let link_duplex: u16 = - unsafe { ::std::mem::transmute(link_duplex) }; - link_duplex as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let link_autoneg: u16 = - unsafe { ::std::mem::transmute(link_autoneg) }; - link_autoneg as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let link_status: u16 = - unsafe { ::std::mem::transmute(link_status) }; - link_status as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; + link_duplex as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let link_autoneg: u16 = unsafe { + ::std::mem::transmute(link_autoneg) + }; + link_autoneg as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; + link_status as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index 6852c23635f25ba3f50504e43f73e32cdf4b2925..c94dc2ce243a389b21ee70734c948ed18fd8805b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ETHER_ADDR_LEN: u32 = 6; pub const ARP_HRD_ETHER: u32 = 1; pub const ARP_OP_REQUEST: u32 = 1; @@ -13,49 +7,29 @@ pub const ARP_OP_REVREQUEST: u32 = 3; pub const ARP_OP_REVREPLY: u32 = 4; pub const ARP_OP_INVREQUEST: u32 = 8; pub const ARP_OP_INVREPLY: u32 = 9; -/// Ethernet address: -/// A universally administered address is uniquely assigned to a device by its -/// manufacturer. The first three octets (in transmission order) contain the -/// Organizationally Unique Identifier (OUI). The following three (MAC-48 and -/// EUI-48) octets are assigned by that organization with the only constraint -/// of uniqueness. -/// A locally administered address is assigned to a device by a network -/// administrator and does not contain OUIs. -/// See http://standards.ieee.org/regauth/groupmac/tutorial.html +/** Ethernet address: + A universally administered address is uniquely assigned to a device by its + manufacturer. The first three octets (in transmission order) contain the + Organizationally Unique Identifier (OUI). The following three (MAC-48 and + EUI-48) octets are assigned by that organization with the only constraint + of uniqueness. + A locally administered address is assigned to a device by a network + administrator and does not contain OUIs. + See http://standards.ieee.org/regauth/groupmac/tutorial.html*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct ether_addr { ///< Addr bytes in tx order pub addr_bytes: [u8; 6usize], } -#[test] -fn bindgen_test_layout_ether_addr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 6usize, - concat!("Size of: ", stringify!(ether_addr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ether_addr)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ether_addr), - "::", - stringify!(addr_bytes) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ether_addr"][::std::mem::size_of::() - 6usize]; + ["Alignment of ether_addr"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ether_addr::addr_bytes", + ][::std::mem::offset_of!(ether_addr, addr_bytes) - 0usize]; +}; /// ARP header IPv4 payload. #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] @@ -69,62 +43,23 @@ pub struct arp_ipv4 { ///< target IP address pub arp_tip: u32, } -#[test] -fn bindgen_test_layout_arp_ipv4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(arp_ipv4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_ipv4)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sha) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sip) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tha) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tip) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of arp_ipv4"][::std::mem::size_of::() - 20usize]; + ["Alignment of arp_ipv4"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: arp_ipv4::arp_sha", + ][::std::mem::offset_of!(arp_ipv4, arp_sha) - 0usize]; + [ + "Offset of field: arp_ipv4::arp_sip", + ][::std::mem::offset_of!(arp_ipv4, arp_sip) - 6usize]; + [ + "Offset of field: arp_ipv4::arp_tha", + ][::std::mem::offset_of!(arp_ipv4, arp_tha) - 10usize]; + [ + "Offset of field: arp_ipv4::arp_tip", + ][::std::mem::offset_of!(arp_ipv4, arp_tip) - 16usize]; +}; /// ARP header. #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] @@ -136,81 +71,26 @@ pub struct arp_hdr { pub arp_op: u16, pub arp_data: arp_ipv4, } -#[test] -fn bindgen_test_layout_arp_hdr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(arp_hdr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_hdr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hrd) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pro) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hln) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, - 5usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pln) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_op) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_data) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of arp_hdr"][::std::mem::size_of::() - 28usize]; + ["Alignment of arp_hdr"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: arp_hdr::arp_hrd", + ][::std::mem::offset_of!(arp_hdr, arp_hrd) - 0usize]; + [ + "Offset of field: arp_hdr::arp_pro", + ][::std::mem::offset_of!(arp_hdr, arp_pro) - 2usize]; + [ + "Offset of field: arp_hdr::arp_hln", + ][::std::mem::offset_of!(arp_hdr, arp_hln) - 4usize]; + [ + "Offset of field: arp_hdr::arp_pln", + ][::std::mem::offset_of!(arp_hdr, arp_pln) - 5usize]; + [ + "Offset of field: arp_hdr::arp_op", + ][::std::mem::offset_of!(arp_hdr, arp_op) - 6usize]; + [ + "Offset of field: arp_hdr::arp_data", + ][::std::mem::offset_of!(arp_hdr, arp_data) - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index daf0ad06fd6109e7192b9fd2b79bf779531af68a..b910159beb8ae8579c5954d45103513bc3603e19 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; @@ -14,20 +8,21 @@ pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; pub struct rte_mempool { _unused: [u8; 0], } -/// Prototype for implementation specific data provisioning function. -/// -/// The function should provide the implementation specific memory for -/// for use by the other mempool ops functions in a given mempool ops struct. -/// E.g. the default ops provides an instance of the rte_ring for this purpose. -/// it will most likely point to a different type of data structure, and -/// will be transparent to the application programmer. -/// This function should set mp->pool_data. +/** Prototype for implementation specific data provisioning function. + + The function should provide the implementation specific memory for + for use by the other mempool ops functions in a given mempool ops struct. + E.g. the default ops provides an instance of the rte_ring for this purpose. + it will most likely point to a different type of data structure, and + will be transparent to the application programmer. + This function should set mp->pool_data.*/ pub type rte_mempool_alloc_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool) -> ::std::os::raw::c_int, >; /// Free the opaque private data pointed to by mp->pool_data pointer. -pub type rte_mempool_free_t = - ::std::option::Option; +pub type rte_mempool_free_t = ::std::option::Option< + unsafe extern "C" fn(mp: *mut rte_mempool), +>; /// Enqueue an object into the external pool. pub type rte_mempool_enqueue_t = ::std::option::Option< unsafe extern "C" fn( @@ -68,80 +63,47 @@ pub struct rte_mempool_ops { } #[test] fn bindgen_test_layout_rte_mempool_ops() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(rte_mempool_ops)) + "Size of rte_mempool_ops", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops)) + "Alignment of rte_mempool_ops", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(name) - ) + "Offset of field: rte_mempool_ops::name", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(alloc) - ) + "Offset of field: rte_mempool_ops::alloc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(free) - ) + "Offset of field: rte_mempool_ops::free", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, 48usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(enqueue) - ) + "Offset of field: rte_mempool_ops::enqueue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(dequeue) - ) + "Offset of field: rte_mempool_ops::dequeue", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(get_count) - ) + "Offset of field: rte_mempool_ops::get_count", ); } impl Default for rte_mempool_ops { @@ -155,12 +117,9 @@ impl Default for rte_mempool_ops { } impl ::std::cmp::PartialEq for rte_mempool_ops { fn eq(&self, other: &rte_mempool_ops) -> bool { - self.name == other.name && - self.alloc == other.alloc && - self.free == other.free && - self.enqueue == other.enqueue && - self.dequeue == other.dequeue && - self.get_count == other.get_count + self.name == other.name && self.alloc == other.alloc && self.free == other.free + && self.enqueue == other.enqueue && self.dequeue == other.dequeue + && self.get_count == other.get_count } } /// The rte_spinlock_t type. @@ -172,37 +131,31 @@ pub struct rte_spinlock_t { } #[test] fn bindgen_test_layout_rte_spinlock_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_spinlock_t)) + "Size of rte_spinlock_t", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_spinlock_t)) + "Alignment of rte_spinlock_t", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_spinlock_t), - "::", - stringify!(locked) - ) + "Offset of field: rte_spinlock_t::locked", ); } -/// Structure storing the table of registered ops structs, each of which contain -/// the function pointers for the mempool ops functions. -/// Each process has its own storage for this ops struct array so that -/// the mempools can be shared across primary and secondary processes. -/// The indices used to access the array are valid across processes, whereas -/// any function pointers stored directly in the mempool struct would not be. -/// This results in us simply having "ops_index" in the mempool struct. +/** Structure storing the table of registered ops structs, each of which contain + the function pointers for the mempool ops functions. + Each process has its own storage for this ops struct array so that + the mempools can be shared across primary and secondary processes. + The indices used to access the array are valid across processes, whereas + any function pointers stored directly in the mempool struct would not be. + This results in us simply having "ops_index" in the mempool struct.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -217,48 +170,32 @@ pub struct rte_mempool_ops_table { } #[test] fn bindgen_test_layout_rte_mempool_ops_table() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2112usize, - concat!("Size of: ", stringify!(rte_mempool_ops_table)) + "Size of rte_mempool_ops_table", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops_table)) + "Alignment of rte_mempool_ops_table", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(sl) - ) + "Offset of field: rte_mempool_ops_table::sl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(num_ops) - ) + "Offset of field: rte_mempool_ops_table::num_ops", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(ops) - ) + "Offset of field: rte_mempool_ops_table::ops", ); } impl Default for rte_mempool_ops_table { @@ -287,30 +224,22 @@ pub struct malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1)) + "Size of malloc_heap__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) + "Alignment of malloc_heap__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap__bindgen_ty_1), - "::", - stringify!(lh_first) - ) + "Offset of field: malloc_heap__bindgen_ty_1::lh_first", ); } impl Default for malloc_heap__bindgen_ty_1 { @@ -324,64 +253,33 @@ impl Default for malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(malloc_heap)) - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of malloc_heap"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(malloc_heap)) + "Alignment of malloc_heap", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(lock) - ) + "Offset of field: malloc_heap::lock", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(free_head) - ) + "Offset of field: malloc_heap::free_head", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, 112usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(alloc_count) - ) + "Offset of field: malloc_heap::alloc_count", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 120usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(total_size) - ) + "Offset of field: malloc_heap::total_size", ); } impl Default for malloc_heap { @@ -395,10 +293,9 @@ impl Default for malloc_heap { } impl ::std::cmp::PartialEq for malloc_heap { fn eq(&self, other: &malloc_heap) -> bool { - self.lock == other.lock && - self.free_head == other.free_head && - self.alloc_count == other.alloc_count && - self.total_size == other.total_size + self.lock == other.lock && self.free_head == other.free_head + && self.alloc_count == other.alloc_count + && self.total_size == other.total_size } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs index 56b3c021f561c40d886681fe767ae4b26ae1d4dc..d6ce2883d7d31b9208714b2b2330c7bbcc25fcd2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_LIBRTE_IP_FRAG_MAX_FRAG: u32 = 4; pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX; @@ -35,48 +29,24 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_frag)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_frag"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of ip_frag"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) + "Offset of field: ip_frag::ofs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) + "Offset of field: ip_frag::len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) + "Offset of field: ip_frag::mb", ); } impl Default for ip_frag { @@ -101,52 +71,32 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ip_frag_key)) - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)) + "Alignment of ip_frag_key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) + "Offset of field: ip_frag_key::src_dst", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) + "Offset of field: ip_frag_key::id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) + "Offset of field: ip_frag_key::key_len", ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +/** @internal Fragmented packet to reassemble. + First two entries in the frags[] array are for the last and first fragments.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -174,42 +124,27 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) + "Size of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) + "Alignment of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_next", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -223,94 +158,48 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 192usize, - concat!("Size of: ", stringify!(ip_frag_pkt)) - ); + assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)) + "Alignment of ip_frag_pkt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) + "Offset of field: ip_frag_pkt::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) + "Offset of field: ip_frag_pkt::key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) + "Offset of field: ip_frag_pkt::start", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) + "Offset of field: ip_frag_pkt::total_size", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) + "Offset of field: ip_frag_pkt::frag_size", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) + "Offset of field: ip_frag_pkt::last_idx", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) + "Offset of field: ip_frag_pkt::frags", ); } impl Default for ip_frag_pkt { @@ -324,13 +213,9 @@ impl Default for ip_frag_pkt { } impl ::std::cmp::PartialEq for ip_frag_pkt { fn eq(&self, other: &ip_frag_pkt) -> bool { - self.lru == other.lru && - self.key == other.key && - self.start == other.start && - self.total_size == other.total_size && - self.frag_size == other.frag_size && - self.last_idx == other.last_idx && - self.frags == other.frags + self.lru == other.lru && self.key == other.key && self.start == other.start + && self.total_size == other.total_size && self.frag_size == other.frag_size + && self.last_idx == other.last_idx && self.frags == other.frags } } ///< fragment mbuf diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index 899703bd04e54f639e7ea317ecc154047217a570..fb7b3bf584648ef8c3f7ee8b9fe19b9ed001bc20 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -1,54 +1,25 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// Stores a pointer to the ops struct, and the offset: the place to -/// write the parsed result in the destination structure. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** Stores a pointer to the ops struct, and the offset: the place to + write the parsed result in the destination structure.*/ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct cmdline_token_hdr { pub ops: *mut cmdline_token_ops, pub offset: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_cmdline_token_hdr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(cmdline_token_hdr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_hdr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(ops) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(offset) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cmdline_token_hdr"][::std::mem::size_of::() - 16usize]; + [ + "Alignment of cmdline_token_hdr", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_hdr::ops", + ][::std::mem::offset_of!(cmdline_token_hdr, ops) - 0usize]; + [ + "Offset of field: cmdline_token_hdr::offset", + ][::std::mem::offset_of!(cmdline_token_hdr, offset) - 8usize]; +}; impl Default for cmdline_token_hdr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -58,26 +29,26 @@ impl Default for cmdline_token_hdr { } } } -/// Stores a pointer to the ops struct, and the offset: the place to -/// write the parsed result in the destination structure. +/** Stores a pointer to the ops struct, and the offset: the place to + write the parsed result in the destination structure.*/ pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; -/// A token is defined by this structure. -/// -/// parse() takes the token as first argument, then the source buffer -/// starting at the token we want to parse. The 3rd arg is a pointer -/// where we store the parsed data (as binary). It returns the number of -/// parsed chars on success and a negative value on error. -/// -/// complete_get_nb() returns the number of possible values for this -/// token if completion is possible. If it is NULL or if it returns 0, -/// no completion is possible. -/// -/// complete_get_elt() copy in dstbuf (the size is specified in the -/// parameter) the i-th possible completion for this token. returns 0 -/// on success or and a negative value on error. -/// -/// get_help() fills the dstbuf with the help for the token. It returns -/// -1 on error and 0 on success. +/** A token is defined by this structure. + + parse() takes the token as first argument, then the source buffer + starting at the token we want to parse. The 3rd arg is a pointer + where we store the parsed data (as binary). It returns the number of + parsed chars on success and a negative value on error. + + complete_get_nb() returns the number of possible values for this + token if completion is possible. If it is NULL or if it returns 0, + no completion is possible. + + complete_get_elt() copy in dstbuf (the size is specified in the + parameter) the i-th possible completion for this token. returns 0 + on success or and a negative value on error. + + get_help() fills the dstbuf with the help for the token. It returns + -1 on error and 0 on success.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct cmdline_token_ops { @@ -114,69 +85,25 @@ pub struct cmdline_token_ops { ) -> ::std::os::raw::c_int, >, } -#[test] -fn bindgen_test_layout_cmdline_token_ops() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(cmdline_token_ops)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_ops)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(parse) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_nb) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_elt) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(get_help) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cmdline_token_ops"][::std::mem::size_of::() - 32usize]; + [ + "Alignment of cmdline_token_ops", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_ops::parse", + ][::std::mem::offset_of!(cmdline_token_ops, parse) - 0usize]; + [ + "Offset of field: cmdline_token_ops::complete_get_nb", + ][::std::mem::offset_of!(cmdline_token_ops, complete_get_nb) - 8usize]; + [ + "Offset of field: cmdline_token_ops::complete_get_elt", + ][::std::mem::offset_of!(cmdline_token_ops, complete_get_elt) - 16usize]; + [ + "Offset of field: cmdline_token_ops::get_help", + ][::std::mem::offset_of!(cmdline_token_ops, get_help) - 24usize]; +}; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum cmdline_numtype { @@ -194,32 +121,18 @@ pub enum cmdline_numtype { pub struct cmdline_token_num_data { pub type_: cmdline_numtype, } -#[test] -fn bindgen_test_layout_cmdline_token_num_data() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cmdline_token_num_data)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(cmdline_token_num_data)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num_data), - "::", - stringify!(type_) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of cmdline_token_num_data", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of cmdline_token_num_data", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: cmdline_token_num_data::type_", + ][::std::mem::offset_of!(cmdline_token_num_data, type_) - 0usize]; +}; impl Default for cmdline_token_num_data { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -235,44 +148,19 @@ pub struct cmdline_token_num { pub hdr: cmdline_token_hdr, pub num_data: cmdline_token_num_data, } -#[test] -fn bindgen_test_layout_cmdline_token_num() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(cmdline_token_num)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_num)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(hdr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(num_data) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cmdline_token_num"][::std::mem::size_of::() - 24usize]; + [ + "Alignment of cmdline_token_num", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_num::hdr", + ][::std::mem::offset_of!(cmdline_token_num, hdr) - 0usize]; + [ + "Offset of field: cmdline_token_num::num_data", + ][::std::mem::offset_of!(cmdline_token_num, num_data) - 16usize]; +}; impl Default for cmdline_token_num { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 62b99e90410d7f4860f3033e99583eca8e7728ee..9b98bac3768adb27f41418212c4035b0c6b52757 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -124,8 +116,8 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +/** A set of values to identify what method is to be used to route + packets to multiple queues.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode @@ -160,52 +152,32 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)) + "Size of rte_eth_rxmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)) + "Alignment of rte_eth_rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) + "Offset of field: rte_eth_rxmode::mq_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) + "Offset of field: rte_eth_rxmode::max_rx_pkt_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) + "Offset of field: rte_eth_rxmode::split_hdr_size", ); } impl Default for rte_eth_rxmode { @@ -220,9 +192,7 @@ impl Default for rte_eth_rxmode { impl rte_eth_rxmode { #[inline] pub fn header_split(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_header_split(&mut self, val: u16) { @@ -233,9 +203,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_ip_checksum(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_hw_ip_checksum(&mut self, val: u16) { @@ -246,9 +214,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_filter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_filter(&mut self, val: u16) { @@ -259,9 +225,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_strip(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_strip(&mut self, val: u16) { @@ -272,9 +236,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_extend(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_extend(&mut self, val: u16) { @@ -285,9 +247,7 @@ impl rte_eth_rxmode { } #[inline] pub fn jumbo_frame(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } #[inline] pub fn set_jumbo_frame(&mut self, val: u16) { @@ -298,9 +258,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_strip_crc(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } #[inline] pub fn set_hw_strip_crc(&mut self, val: u16) { @@ -311,9 +269,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_scatter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } #[inline] pub fn set_enable_scatter(&mut self, val: u16) { @@ -324,9 +280,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_lro(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } #[inline] pub fn set_enable_lro(&mut self, val: u16) { @@ -347,58 +301,108 @@ impl rte_eth_rxmode { enable_scatter: u16, enable_lro: u16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let header_split: u16 = - unsafe { ::std::mem::transmute(header_split) }; - header_split as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_ip_checksum: u16 = - unsafe { ::std::mem::transmute(hw_ip_checksum) }; - hw_ip_checksum as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_filter: u16 = - unsafe { ::std::mem::transmute(hw_vlan_filter) }; - hw_vlan_filter as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let hw_vlan_strip: u16 = - unsafe { ::std::mem::transmute(hw_vlan_strip) }; - hw_vlan_strip as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let hw_vlan_extend: u16 = - unsafe { ::std::mem::transmute(hw_vlan_extend) }; - hw_vlan_extend as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let jumbo_frame: u16 = - unsafe { ::std::mem::transmute(jumbo_frame) }; - jumbo_frame as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let hw_strip_crc: u16 = - unsafe { ::std::mem::transmute(hw_strip_crc) }; - hw_strip_crc as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let enable_scatter: u16 = - unsafe { ::std::mem::transmute(enable_scatter) }; - enable_scatter as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; - enable_lro as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let header_split: u16 = unsafe { + ::std::mem::transmute(header_split) + }; + header_split as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_ip_checksum: u16 = unsafe { + ::std::mem::transmute(hw_ip_checksum) + }; + hw_ip_checksum as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_filter: u16 = unsafe { + ::std::mem::transmute(hw_vlan_filter) + }; + hw_vlan_filter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let hw_vlan_strip: u16 = unsafe { + ::std::mem::transmute(hw_vlan_strip) + }; + hw_vlan_strip as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let hw_vlan_extend: u16 = unsafe { + ::std::mem::transmute(hw_vlan_extend) + }; + hw_vlan_extend as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let jumbo_frame: u16 = unsafe { ::std::mem::transmute(jumbo_frame) }; + jumbo_frame as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let hw_strip_crc: u16 = unsafe { + ::std::mem::transmute(hw_strip_crc) + }; + hw_strip_crc as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let enable_scatter: u16 = unsafe { + ::std::mem::transmute(enable_scatter) + }; + enable_scatter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; + enable_lro as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +/** A set of values to identify what method is to be used to transmit + packets using multi-TCs.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. @@ -423,38 +427,27 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)) + "Size of rte_eth_txmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)) + "Alignment of rte_eth_txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) + "Offset of field: rte_eth_txmode::mq_mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) + "Offset of field: rte_eth_txmode::pvid", ); } impl Default for rte_eth_txmode { @@ -469,9 +462,7 @@ impl Default for rte_eth_txmode { impl rte_eth_txmode { #[inline] pub fn hw_vlan_reject_tagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { @@ -482,9 +473,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { @@ -495,9 +484,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { @@ -512,41 +499,58 @@ impl rte_eth_txmode { hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let hw_vlan_reject_tagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; - hw_vlan_reject_tagged as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_vlan_reject_untagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_untagged) }; - hw_vlan_reject_untagged as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_insert_pvid: u8 = - unsafe { ::std::mem::transmute(hw_vlan_insert_pvid) }; - hw_vlan_insert_pvid as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let hw_vlan_reject_tagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_tagged) + }; + hw_vlan_reject_tagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_vlan_reject_untagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_untagged) + }; + hw_vlan_reject_untagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_insert_pvid: u8 = unsafe { + ::std::mem::transmute(hw_vlan_insert_pvid) + }; + hw_vlan_insert_pvid as u64 + }, + ); __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +/** A structure used to configure the Receive Side Scaling (RSS) feature + of an Ethernet port. + If not NULL, the *rss_key* pointer of the *rss_conf* structure points + to an array holding the RSS key to use for hashing specific header + fields of received packets. The length of this array should be indicated + by *rss_key_len* below. Otherwise, a default random hash key is used by + the device driver. + + The *rss_key_len* field of the *rss_conf* structure indicates the length + in bytes of the array pointed by *rss_key*. To be compatible, this length + will be checked in i40e only. Others assume 40 bytes to be used as before. + + The *rss_hf* field of the *rss_conf* structure indicates the different + types of IPv4/IPv6 packets to which the RSS hashing must be applied. + Supplying an *rss_hf* equal to zero disables the RSS feature.*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { @@ -559,50 +563,32 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)) + "Size of rte_eth_rss_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)) + "Alignment of rte_eth_rss_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) + "Offset of field: rte_eth_rss_conf::rss_key", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) + "Offset of field: rte_eth_rss_conf::rss_key_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) + "Offset of field: rte_eth_rss_conf::rss_hf", ); } impl Default for rte_eth_rss_conf { @@ -615,8 +601,8 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +/** This enum indicates the possible number of traffic classes + in DCB configratioins*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. @@ -625,8 +611,8 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +/** This enum indicates the possible number of queue pools + in VMDQ configurations.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. @@ -638,15 +624,15 @@ pub enum rte_eth_nb_pools { ///< 64 VMDq pools. ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +/** A structure used to configure the VMDQ+DCB feature + of an Ethernet port. + + Using this feature, packets are routed to a pool of queues, based + on the vlan ID in the vlan tag, and then to a specific queue within + that pool, using the user priority vlan tag field. + + A default pool may be used, if desired, to route all traffic which + does not match the vlan filter rules.*/ #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_vmdq_dcb_conf { @@ -665,135 +651,81 @@ pub struct rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) - ) + "Alignment of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::vlan_id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) + "Size of rte_eth_vmdq_dcb_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) + "Alignment of rte_eth_vmdq_dcb_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::nb_queue_pools", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::enable_default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::nb_pool_maps", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::pool_map", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", ); } impl Default for rte_eth_vmdq_dcb_conf { @@ -815,38 +747,27 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)) + "Size of rte_eth_dcb_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) + "Alignment of rte_eth_dcb_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) + "Offset of field: rte_eth_dcb_rx_conf::nb_tcs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", ); } impl Default for rte_eth_dcb_rx_conf { @@ -868,40 +789,27 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + "Size of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + "Alignment of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_dcb_tx_conf::nb_queue_pools", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", ); } impl Default for rte_eth_vmdq_dcb_tx_conf { @@ -923,38 +831,27 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)) + "Size of rte_eth_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) + "Alignment of rte_eth_dcb_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) + "Offset of field: rte_eth_dcb_tx_conf::nb_tcs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", ); } impl Default for rte_eth_dcb_tx_conf { @@ -974,30 +871,22 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)) + "Size of rte_eth_vmdq_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) + "Alignment of rte_eth_vmdq_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", ); } impl Default for rte_eth_vmdq_tx_conf { @@ -1030,148 +919,86 @@ pub struct rte_eth_vmdq_rx_conf { #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) - ) + "Alignment of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::vlan_id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) + "Size of rte_eth_vmdq_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) + "Alignment of rte_eth_vmdq_rx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_rx_conf::nb_queue_pools", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) + "Offset of field: rte_eth_vmdq_rx_conf::enable_default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) + "Offset of field: rte_eth_vmdq_rx_conf::default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) + "Offset of field: rte_eth_vmdq_rx_conf::enable_loop_back", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) + "Offset of field: rte_eth_vmdq_rx_conf::nb_pool_maps", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) + "Offset of field: rte_eth_vmdq_rx_conf::rx_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) + "Offset of field: rte_eth_vmdq_rx_conf::pool_map", ); } impl Default for rte_eth_vmdq_rx_conf { @@ -1199,8 +1026,8 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +/** Memory space that can be configured to store Flow Director filters + in the board memory.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. @@ -1238,68 +1065,42 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)) + "Size of rte_eth_ipv4_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) + "Alignment of rte_eth_ipv4_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) + "Offset of field: rte_eth_ipv4_flow::src_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) + "Offset of field: rte_eth_ipv4_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) + "Offset of field: rte_eth_ipv4_flow::tos", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) + "Offset of field: rte_eth_ipv4_flow::ttl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) + "Offset of field: rte_eth_ipv4_flow::proto", ); } /// A structure used to define the input for IPV6 flow @@ -1319,74 +1120,46 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)) + "Size of rte_eth_ipv6_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) + "Alignment of rte_eth_ipv6_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) + "Offset of field: rte_eth_ipv6_flow::src_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) + "Offset of field: rte_eth_ipv6_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) + "Offset of field: rte_eth_ipv6_flow::tc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) + "Offset of field: rte_eth_ipv6_flow::proto", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) + "Offset of field: rte_eth_ipv6_flow::hop_limits", ); } -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. +/** A structure used to configure FDIR masks that are used by the device + to match the various fields of RX packet headers.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { @@ -1400,127 +1173,70 @@ pub struct rte_eth_fdir_masks { pub src_port_mask: u16, /// Bit mask for L4 destination port in big endian. pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - ///first byte on the wire + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the +first byte on the wire*/ pub mac_addr_byte_mask: u8, /// Bit mask for tunnel ID in big endian. pub tunnel_id_mask: u32, - ///< 1 - Match tunnel type, - ///0 - Ignore tunnel type. + /**< 1 - Match tunnel type, +0 - Ignore tunnel type.*/ pub tunnel_type_mask: u8, } #[test] fn bindgen_test_layout_rte_eth_fdir_masks() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)) + "Size of rte_eth_fdir_masks", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) + "Alignment of rte_eth_fdir_masks", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) + "Offset of field: rte_eth_fdir_masks::vlan_tci_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) + "Offset of field: rte_eth_fdir_masks::ipv4_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) + "Offset of field: rte_eth_fdir_masks::ipv6_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) + "Offset of field: rte_eth_fdir_masks::src_port_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) + "Offset of field: rte_eth_fdir_masks::dst_port_mask", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) + "Offset of field: rte_eth_fdir_masks::mac_addr_byte_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) + "Offset of field: rte_eth_fdir_masks::tunnel_id_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) + "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", ); } #[repr(u32)] @@ -1534,8 +1250,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +/** A structure used to select bytes extracted from the protocol layers to + flexible payload for filter*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { @@ -1545,40 +1261,27 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) + "Size of rte_eth_flex_payload_cfg", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) + "Alignment of rte_eth_flex_payload_cfg", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) + "Offset of field: rte_eth_flex_payload_cfg::type_", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) + "Offset of field: rte_eth_flex_payload_cfg::src_offset", ); } impl Default for rte_eth_flex_payload_cfg { @@ -1590,8 +1293,8 @@ impl Default for rte_eth_flex_payload_cfg { } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +/** A structure used to define FDIR masks for flexible payload + for each flow type*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1600,44 +1303,31 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) + "Size of rte_eth_fdir_flex_mask", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) + "Alignment of rte_eth_fdir_flex_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) + "Offset of field: rte_eth_fdir_flex_mask::flow_type", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) + "Offset of field: rte_eth_fdir_flex_mask::mask", ); } -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask +/** A structure used to define all flexible payload related setting + include flex payload and flex mask*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { @@ -1650,66 +1340,37 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) + "Size of rte_eth_fdir_flex_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) + "Alignment of rte_eth_fdir_flex_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) + "Offset of field: rte_eth_fdir_flex_conf::nb_payloads", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) + "Offset of field: rte_eth_fdir_flex_conf::nb_flexmasks", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) + "Offset of field: rte_eth_fdir_flex_conf::flex_set", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) + "Offset of field: rte_eth_fdir_flex_conf::flex_mask", ); } impl Default for rte_eth_fdir_flex_conf { @@ -1721,10 +1382,10 @@ impl Default for rte_eth_fdir_flex_conf { } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +/** A structure used to configure the Flow Director (FDIR) feature + of an Ethernet port. + + If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { @@ -1741,82 +1402,47 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)) + "Size of rte_fdir_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)) + "Alignment of rte_fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) + "Offset of field: rte_fdir_conf::mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) + "Offset of field: rte_fdir_conf::pballoc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) + "Offset of field: rte_fdir_conf::status", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) + "Offset of field: rte_fdir_conf::drop_queue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) + "Offset of field: rte_fdir_conf::mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) + "Offset of field: rte_fdir_conf::flex_conf", ); } impl Default for rte_fdir_conf { @@ -1839,70 +1465,55 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_intr_conf)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of rte_intr_conf"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)) + "Alignment of rte_intr_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) + "Offset of field: rte_intr_conf::lsc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) + "Offset of field: rte_intr_conf::rxq", ); } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +/** A structure used to configure an Ethernet port. + Depending upon the RX multi-queue mode, extra advanced + configuration settings may be needed.*/ #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_conf { - ///< bitmap of ETH_LINK_SPEED_XXX of speeds to be - ///used. ETH_LINK_SPEED_FIXED disables link - ///autonegotiation, and a unique speed shall be - ///set. Otherwise, the bitmap defines the set of - ///speeds to be advertised. If the special value - ///ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - ///supported are advertised. + /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be +used. ETH_LINK_SPEED_FIXED disables link +autonegotiation, and a unique speed shall be +set. Otherwise, the bitmap defines the set of +speeds to be advertised. If the special value +ETH_LINK_SPEED_AUTONEG (0) is used, all speeds +supported are advertised.*/ pub link_speeds: u32, ///< Port RX configuration. pub rxmode: rte_eth_rxmode, ///< Port TX configuration. pub txmode: rte_eth_txmode, - ///< Loopback operation mode. By default the value - ///is 0, meaning the loopback mode is disabled. - ///Read the datasheet of given ethernet controller - ///for details. The possible values of this field - ///are defined in implementation of each driver. + /**< Loopback operation mode. By default the value +is 0, meaning the loopback mode is disabled. +Read the datasheet of given ethernet controller +for details. The possible values of this field +are defined in implementation of each driver.*/ pub lpbk_mode: u32, ///< Port RX filtering configuration (union). pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, ///< Port TX DCB configuration (union). pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - ///is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC +is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ pub dcb_capability_en: u32, ///< FDIR configuration. pub fdir_conf: rte_fdir_conf, @@ -1920,66 +1531,37 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) + "Size of rte_eth_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) + "Alignment of rte_eth_conf__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::rss_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_dcb_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::dcb_rx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", ); } impl Default for rte_eth_conf__bindgen_ty_1 { @@ -2000,55 +1582,32 @@ pub union rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) + "Size of rte_eth_conf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) + "Alignment of rte_eth_conf__bindgen_ty_2", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", ); } impl Default for rte_eth_conf__bindgen_ty_2 { @@ -2062,123 +1621,60 @@ impl Default for rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2944usize, - concat!("Size of: ", stringify!(rte_eth_conf)) - ); + assert_eq!(::std::mem::size_of::(), 2944usize, "Size of rte_eth_conf"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)) + "Alignment of rte_eth_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) + "Offset of field: rte_eth_conf::link_speeds", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) + "Offset of field: rte_eth_conf::rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) + "Offset of field: rte_eth_conf::txmode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) + "Offset of field: rte_eth_conf::lpbk_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) + "Offset of field: rte_eth_conf::rx_adv_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) + "Offset of field: rte_eth_conf::tx_adv_conf", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize }, 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) + "Offset of field: rte_eth_conf::dcb_capability_en", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) + "Offset of field: rte_eth_conf::fdir_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) + "Offset of field: rte_eth_conf::intr_conf", ); } impl Default for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index d7fa0a634ad47e33497007f46280654b2aaf3b99..34688b20b3251d8633dcbe8f281a0adcc8730340 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -167,8 +159,8 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +/** A set of values to identify what method is to be used to route + packets to multiple queues.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode @@ -203,52 +195,32 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)) + "Size of rte_eth_rxmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)) + "Alignment of rte_eth_rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) + "Offset of field: rte_eth_rxmode::mq_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) + "Offset of field: rte_eth_rxmode::max_rx_pkt_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) + "Offset of field: rte_eth_rxmode::split_hdr_size", ); } impl Clone for rte_eth_rxmode { @@ -268,9 +240,7 @@ impl Default for rte_eth_rxmode { impl rte_eth_rxmode { #[inline] pub fn header_split(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_header_split(&mut self, val: u16) { @@ -281,9 +251,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_ip_checksum(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_hw_ip_checksum(&mut self, val: u16) { @@ -294,9 +262,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_filter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_filter(&mut self, val: u16) { @@ -307,9 +273,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_strip(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_strip(&mut self, val: u16) { @@ -320,9 +284,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_extend(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_extend(&mut self, val: u16) { @@ -333,9 +295,7 @@ impl rte_eth_rxmode { } #[inline] pub fn jumbo_frame(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } #[inline] pub fn set_jumbo_frame(&mut self, val: u16) { @@ -346,9 +306,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_strip_crc(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } #[inline] pub fn set_hw_strip_crc(&mut self, val: u16) { @@ -359,9 +317,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_scatter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } #[inline] pub fn set_enable_scatter(&mut self, val: u16) { @@ -372,9 +328,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_lro(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } #[inline] pub fn set_enable_lro(&mut self, val: u16) { @@ -395,58 +349,108 @@ impl rte_eth_rxmode { enable_scatter: u16, enable_lro: u16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let header_split: u16 = - unsafe { ::std::mem::transmute(header_split) }; - header_split as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_ip_checksum: u16 = - unsafe { ::std::mem::transmute(hw_ip_checksum) }; - hw_ip_checksum as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_filter: u16 = - unsafe { ::std::mem::transmute(hw_vlan_filter) }; - hw_vlan_filter as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let hw_vlan_strip: u16 = - unsafe { ::std::mem::transmute(hw_vlan_strip) }; - hw_vlan_strip as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let hw_vlan_extend: u16 = - unsafe { ::std::mem::transmute(hw_vlan_extend) }; - hw_vlan_extend as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let jumbo_frame: u16 = - unsafe { ::std::mem::transmute(jumbo_frame) }; - jumbo_frame as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let hw_strip_crc: u16 = - unsafe { ::std::mem::transmute(hw_strip_crc) }; - hw_strip_crc as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let enable_scatter: u16 = - unsafe { ::std::mem::transmute(enable_scatter) }; - enable_scatter as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; - enable_lro as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let header_split: u16 = unsafe { + ::std::mem::transmute(header_split) + }; + header_split as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_ip_checksum: u16 = unsafe { + ::std::mem::transmute(hw_ip_checksum) + }; + hw_ip_checksum as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_filter: u16 = unsafe { + ::std::mem::transmute(hw_vlan_filter) + }; + hw_vlan_filter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let hw_vlan_strip: u16 = unsafe { + ::std::mem::transmute(hw_vlan_strip) + }; + hw_vlan_strip as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let hw_vlan_extend: u16 = unsafe { + ::std::mem::transmute(hw_vlan_extend) + }; + hw_vlan_extend as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let jumbo_frame: u16 = unsafe { ::std::mem::transmute(jumbo_frame) }; + jumbo_frame as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let hw_strip_crc: u16 = unsafe { + ::std::mem::transmute(hw_strip_crc) + }; + hw_strip_crc as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let enable_scatter: u16 = unsafe { + ::std::mem::transmute(enable_scatter) + }; + enable_scatter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; + enable_lro as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +/** A set of values to identify what method is to be used to transmit + packets using multi-TCs.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. @@ -471,38 +475,27 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)) + "Size of rte_eth_txmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)) + "Alignment of rte_eth_txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) + "Offset of field: rte_eth_txmode::mq_mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) + "Offset of field: rte_eth_txmode::pvid", ); } impl Clone for rte_eth_txmode { @@ -522,9 +515,7 @@ impl Default for rte_eth_txmode { impl rte_eth_txmode { #[inline] pub fn hw_vlan_reject_tagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { @@ -535,9 +526,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { @@ -548,9 +537,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { @@ -565,41 +552,58 @@ impl rte_eth_txmode { hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let hw_vlan_reject_tagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; - hw_vlan_reject_tagged as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_vlan_reject_untagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_untagged) }; - hw_vlan_reject_untagged as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_insert_pvid: u8 = - unsafe { ::std::mem::transmute(hw_vlan_insert_pvid) }; - hw_vlan_insert_pvid as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let hw_vlan_reject_tagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_tagged) + }; + hw_vlan_reject_tagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_vlan_reject_untagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_untagged) + }; + hw_vlan_reject_untagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_insert_pvid: u8 = unsafe { + ::std::mem::transmute(hw_vlan_insert_pvid) + }; + hw_vlan_insert_pvid as u64 + }, + ); __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +/** A structure used to configure the Receive Side Scaling (RSS) feature + of an Ethernet port. + If not NULL, the *rss_key* pointer of the *rss_conf* structure points + to an array holding the RSS key to use for hashing specific header + fields of received packets. The length of this array should be indicated + by *rss_key_len* below. Otherwise, a default random hash key is used by + the device driver. + + The *rss_key_len* field of the *rss_conf* structure indicates the length + in bytes of the array pointed by *rss_key*. To be compatible, this length + will be checked in i40e only. Others assume 40 bytes to be used as before. + + The *rss_hf* field of the *rss_conf* structure indicates the different + types of IPv4/IPv6 packets to which the RSS hashing must be applied. + Supplying an *rss_hf* equal to zero disables the RSS feature.*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { @@ -612,50 +616,32 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)) + "Size of rte_eth_rss_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)) + "Alignment of rte_eth_rss_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) + "Offset of field: rte_eth_rss_conf::rss_key", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) + "Offset of field: rte_eth_rss_conf::rss_key_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) + "Offset of field: rte_eth_rss_conf::rss_hf", ); } impl Clone for rte_eth_rss_conf { @@ -673,8 +659,8 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +/** This enum indicates the possible number of traffic classes + in DCB configratioins*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. @@ -683,8 +669,8 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +/** This enum indicates the possible number of queue pools + in VMDQ configurations.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. @@ -696,15 +682,15 @@ pub enum rte_eth_nb_pools { ///< 64 VMDq pools. ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +/** A structure used to configure the VMDQ+DCB feature + of an Ethernet port. + + Using this feature, packets are routed to a pool of queues, based + on the vlan ID in the vlan tag, and then to a specific queue within + that pool, using the user priority vlan tag field. + + A default pool may be used, if desired, to route all traffic which + does not match the vlan filter rules.*/ #[repr(C)] #[derive(Copy)] pub struct rte_eth_vmdq_dcb_conf { @@ -723,48 +709,34 @@ pub struct rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) - ) + "Alignment of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::vlan_id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", ); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { @@ -774,89 +746,49 @@ impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) + "Size of rte_eth_vmdq_dcb_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) + "Alignment of rte_eth_vmdq_dcb_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::nb_queue_pools", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::enable_default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::nb_pool_maps", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::pool_map", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", ); } impl Clone for rte_eth_vmdq_dcb_conf { @@ -883,38 +815,27 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)) + "Size of rte_eth_dcb_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) + "Alignment of rte_eth_dcb_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) + "Offset of field: rte_eth_dcb_rx_conf::nb_tcs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", ); } impl Clone for rte_eth_dcb_rx_conf { @@ -941,40 +862,27 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + "Size of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + "Alignment of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_dcb_tx_conf::nb_queue_pools", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", ); } impl Clone for rte_eth_vmdq_dcb_tx_conf { @@ -1001,38 +909,27 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)) + "Size of rte_eth_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) + "Alignment of rte_eth_dcb_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) + "Offset of field: rte_eth_dcb_tx_conf::nb_tcs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", ); } impl Clone for rte_eth_dcb_tx_conf { @@ -1057,30 +954,22 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)) + "Size of rte_eth_vmdq_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) + "Alignment of rte_eth_vmdq_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", ); } impl Clone for rte_eth_vmdq_tx_conf { @@ -1118,48 +1007,34 @@ pub struct rte_eth_vmdq_rx_conf { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) - ) + "Alignment of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::vlan_id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", ); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { @@ -1169,102 +1044,54 @@ impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) + "Size of rte_eth_vmdq_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) + "Alignment of rte_eth_vmdq_rx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) + "Offset of field: rte_eth_vmdq_rx_conf::nb_queue_pools", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) + "Offset of field: rte_eth_vmdq_rx_conf::enable_default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) + "Offset of field: rte_eth_vmdq_rx_conf::default_pool", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) + "Offset of field: rte_eth_vmdq_rx_conf::enable_loop_back", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) + "Offset of field: rte_eth_vmdq_rx_conf::nb_pool_maps", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) + "Offset of field: rte_eth_vmdq_rx_conf::rx_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) + "Offset of field: rte_eth_vmdq_rx_conf::pool_map", ); } impl Clone for rte_eth_vmdq_rx_conf { @@ -1297,8 +1124,8 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +/** Memory space that can be configured to store Flow Director filters + in the board memory.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. @@ -1336,68 +1163,42 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)) + "Size of rte_eth_ipv4_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) + "Alignment of rte_eth_ipv4_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) + "Offset of field: rte_eth_ipv4_flow::src_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) + "Offset of field: rte_eth_ipv4_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) + "Offset of field: rte_eth_ipv4_flow::tos", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) + "Offset of field: rte_eth_ipv4_flow::ttl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) + "Offset of field: rte_eth_ipv4_flow::proto", ); } impl Clone for rte_eth_ipv4_flow { @@ -1422,70 +1223,42 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)) + "Size of rte_eth_ipv6_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) + "Alignment of rte_eth_ipv6_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) + "Offset of field: rte_eth_ipv6_flow::src_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) + "Offset of field: rte_eth_ipv6_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) + "Offset of field: rte_eth_ipv6_flow::tc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) + "Offset of field: rte_eth_ipv6_flow::proto", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) + "Offset of field: rte_eth_ipv6_flow::hop_limits", ); } impl Clone for rte_eth_ipv6_flow { @@ -1493,8 +1266,8 @@ impl Clone for rte_eth_ipv6_flow { *self } } -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. +/** A structure used to configure FDIR masks that are used by the device + to match the various fields of RX packet headers.*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { @@ -1508,127 +1281,70 @@ pub struct rte_eth_fdir_masks { pub src_port_mask: u16, /// Bit mask for L4 destination port in big endian. pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - ///first byte on the wire + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the +first byte on the wire*/ pub mac_addr_byte_mask: u8, /// Bit mask for tunnel ID in big endian. pub tunnel_id_mask: u32, - ///< 1 - Match tunnel type, - ///0 - Ignore tunnel type. + /**< 1 - Match tunnel type, +0 - Ignore tunnel type.*/ pub tunnel_type_mask: u8, } #[test] fn bindgen_test_layout_rte_eth_fdir_masks() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)) + "Size of rte_eth_fdir_masks", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) + "Alignment of rte_eth_fdir_masks", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) + "Offset of field: rte_eth_fdir_masks::vlan_tci_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) + "Offset of field: rte_eth_fdir_masks::ipv4_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) + "Offset of field: rte_eth_fdir_masks::ipv6_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) + "Offset of field: rte_eth_fdir_masks::src_port_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) + "Offset of field: rte_eth_fdir_masks::dst_port_mask", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) + "Offset of field: rte_eth_fdir_masks::mac_addr_byte_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) + "Offset of field: rte_eth_fdir_masks::tunnel_id_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) + "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", ); } impl Clone for rte_eth_fdir_masks { @@ -1647,8 +1363,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +/** A structure used to select bytes extracted from the protocol layers to + flexible payload for filter*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { @@ -1658,40 +1374,27 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) + "Size of rte_eth_flex_payload_cfg", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) + "Alignment of rte_eth_flex_payload_cfg", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) + "Offset of field: rte_eth_flex_payload_cfg::type_", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) + "Offset of field: rte_eth_flex_payload_cfg::src_offset", ); } impl Clone for rte_eth_flex_payload_cfg { @@ -1708,8 +1411,8 @@ impl Default for rte_eth_flex_payload_cfg { } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +/** A structure used to define FDIR masks for flexible payload + for each flow type*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1718,40 +1421,27 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) + "Size of rte_eth_fdir_flex_mask", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) + "Alignment of rte_eth_fdir_flex_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) + "Offset of field: rte_eth_fdir_flex_mask::flow_type", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) + "Offset of field: rte_eth_fdir_flex_mask::mask", ); } impl Clone for rte_eth_fdir_flex_mask { @@ -1759,8 +1449,8 @@ impl Clone for rte_eth_fdir_flex_mask { *self } } -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask +/** A structure used to define all flexible payload related setting + include flex payload and flex mask*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { @@ -1773,66 +1463,37 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) + "Size of rte_eth_fdir_flex_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) + "Alignment of rte_eth_fdir_flex_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) + "Offset of field: rte_eth_fdir_flex_conf::nb_payloads", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) + "Offset of field: rte_eth_fdir_flex_conf::nb_flexmasks", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) + "Offset of field: rte_eth_fdir_flex_conf::flex_set", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) + "Offset of field: rte_eth_fdir_flex_conf::flex_mask", ); } impl Clone for rte_eth_fdir_flex_conf { @@ -1849,10 +1510,10 @@ impl Default for rte_eth_fdir_flex_conf { } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +/** A structure used to configure the Flow Director (FDIR) feature + of an Ethernet port. + + If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { @@ -1869,82 +1530,47 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)) + "Size of rte_fdir_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)) + "Alignment of rte_fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) + "Offset of field: rte_fdir_conf::mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) + "Offset of field: rte_fdir_conf::pballoc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) + "Offset of field: rte_fdir_conf::status", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) + "Offset of field: rte_fdir_conf::drop_queue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) + "Offset of field: rte_fdir_conf::mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) + "Offset of field: rte_fdir_conf::flex_conf", ); } impl Clone for rte_fdir_conf { @@ -1972,38 +1598,23 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_intr_conf)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of rte_intr_conf"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)) + "Alignment of rte_intr_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) + "Offset of field: rte_intr_conf::lsc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) + "Offset of field: rte_intr_conf::rxq", ); } impl Clone for rte_intr_conf { @@ -2011,36 +1622,36 @@ impl Clone for rte_intr_conf { *self } } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +/** A structure used to configure an Ethernet port. + Depending upon the RX multi-queue mode, extra advanced + configuration settings may be needed.*/ #[repr(C)] #[derive(Copy)] pub struct rte_eth_conf { - ///< bitmap of ETH_LINK_SPEED_XXX of speeds to be - ///used. ETH_LINK_SPEED_FIXED disables link - ///autonegotiation, and a unique speed shall be - ///set. Otherwise, the bitmap defines the set of - ///speeds to be advertised. If the special value - ///ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - ///supported are advertised. + /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be +used. ETH_LINK_SPEED_FIXED disables link +autonegotiation, and a unique speed shall be +set. Otherwise, the bitmap defines the set of +speeds to be advertised. If the special value +ETH_LINK_SPEED_AUTONEG (0) is used, all speeds +supported are advertised.*/ pub link_speeds: u32, ///< Port RX configuration. pub rxmode: rte_eth_rxmode, ///< Port TX configuration. pub txmode: rte_eth_txmode, - ///< Loopback operation mode. By default the value - ///is 0, meaning the loopback mode is disabled. - ///Read the datasheet of given ethernet controller - ///for details. The possible values of this field - ///are defined in implementation of each driver. + /**< Loopback operation mode. By default the value +is 0, meaning the loopback mode is disabled. +Read the datasheet of given ethernet controller +for details. The possible values of this field +are defined in implementation of each driver.*/ pub lpbk_mode: u32, ///< Port RX filtering configuration (union). pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, ///< Port TX DCB configuration (union). pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - ///is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC +is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ pub dcb_capability_en: u32, ///< FDIR configuration. pub fdir_conf: rte_fdir_conf, @@ -2058,66 +1669,37 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) + "Size of rte_eth_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) + "Alignment of rte_eth_conf__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::rss_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_dcb_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::dcb_rx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", ); } impl Clone for rte_eth_conf__bindgen_ty_1 { @@ -2144,55 +1726,32 @@ pub struct rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) + "Size of rte_eth_conf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) + "Alignment of rte_eth_conf__bindgen_ty_2", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::dcb_tx_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", ); } impl Clone for rte_eth_conf__bindgen_ty_2 { @@ -2202,123 +1761,60 @@ impl Clone for rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2944usize, - concat!("Size of: ", stringify!(rte_eth_conf)) - ); + assert_eq!(::std::mem::size_of::(), 2944usize, "Size of rte_eth_conf"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)) + "Alignment of rte_eth_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) + "Offset of field: rte_eth_conf::link_speeds", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) + "Offset of field: rte_eth_conf::rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) + "Offset of field: rte_eth_conf::txmode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) + "Offset of field: rte_eth_conf::lpbk_mode", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) + "Offset of field: rte_eth_conf::rx_adv_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) + "Offset of field: rte_eth_conf::tx_adv_conf", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize }, 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) + "Offset of field: rte_eth_conf::dcb_capability_en", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) + "Offset of field: rte_eth_conf::fdir_conf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) + "Offset of field: rte_eth_conf::intr_conf", ); } impl Clone for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs index be88d20fff3b34b28c33cb2941208b6c09963451..a9d779e9a1914da384828abec7ff678ec3bc1586 100644 --- a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; pub const RTE_CACHE_LINE_SIZE: u32 = 64; #[repr(C)] @@ -34,168 +28,83 @@ pub struct rte_kni_mbuf { } #[test] fn bindgen_test_layout_rte_kni_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_kni_mbuf)) - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of rte_kni_mbuf"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_kni_mbuf)) + "Alignment of rte_kni_mbuf", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_addr) - ) + "Offset of field: rte_kni_mbuf::buf_addr", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_physaddr) - ) + "Offset of field: rte_kni_mbuf::buf_physaddr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad0) - ) + "Offset of field: rte_kni_mbuf::pad0", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_off) - ) + "Offset of field: rte_kni_mbuf::data_off", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, 20usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad1) - ) + "Offset of field: rte_kni_mbuf::pad1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(nb_segs) - ) + "Offset of field: rte_kni_mbuf::nb_segs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, 23usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad4) - ) + "Offset of field: rte_kni_mbuf::pad4", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(ol_flags) - ) + "Offset of field: rte_kni_mbuf::ol_flags", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad2) - ) + "Offset of field: rte_kni_mbuf::pad2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pkt_len) - ) + "Offset of field: rte_kni_mbuf::pkt_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_len) - ) + "Offset of field: rte_kni_mbuf::data_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad3) - ) + "Offset of field: rte_kni_mbuf::pad3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pool) - ) + "Offset of field: rte_kni_mbuf::pool", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(next) - ) + "Offset of field: rte_kni_mbuf::next", ); } impl Default for rte_kni_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs index 075ef46ae46f81698cde74ded76d760d68788685..b72c221dca420a0cd592cbba406f361e669795a8 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -65,48 +59,24 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_frag)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_frag"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of ip_frag"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) + "Offset of field: ip_frag::ofs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) + "Offset of field: ip_frag::len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) + "Offset of field: ip_frag::mb", ); } impl Default for ip_frag { @@ -131,52 +101,32 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ip_frag_key)) - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)) + "Alignment of ip_frag_key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) + "Offset of field: ip_frag_key::src_dst", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) + "Offset of field: ip_frag_key::id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) + "Offset of field: ip_frag_key::key_len", ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +/** @internal Fragmented packet to reassemble. + First two entries in the frags[] array are for the last and first fragments.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -204,42 +154,27 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) + "Size of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) + "Alignment of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_next", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -253,94 +188,48 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 192usize, - concat!("Size of: ", stringify!(ip_frag_pkt)) - ); + assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)) + "Alignment of ip_frag_pkt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) + "Offset of field: ip_frag_pkt::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) + "Offset of field: ip_frag_pkt::key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) + "Offset of field: ip_frag_pkt::start", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) + "Offset of field: ip_frag_pkt::total_size", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) + "Offset of field: ip_frag_pkt::frag_size", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) + "Offset of field: ip_frag_pkt::last_idx", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) + "Offset of field: ip_frag_pkt::frags", ); } impl Default for ip_frag_pkt { @@ -360,42 +249,23 @@ pub struct ip_pkt_list { } #[test] fn bindgen_test_layout_ip_pkt_list() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_pkt_list)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_pkt_list"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_pkt_list)) + "Alignment of ip_pkt_list", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_first) - ) + "Offset of field: ip_pkt_list::tqh_first", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_last) - ) + "Offset of field: ip_pkt_list::tqh_last", ); } impl Default for ip_pkt_list { @@ -427,86 +297,47 @@ pub struct ip_frag_tbl_stat { } #[test] fn bindgen_test_layout_ip_frag_tbl_stat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 64usize, - concat!("Size of: ", stringify!(ip_frag_tbl_stat)) + "Size of ip_frag_tbl_stat", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) + "Alignment of ip_frag_tbl_stat", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(find_num) - ) + "Offset of field: ip_frag_tbl_stat::find_num", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(add_num) - ) + "Offset of field: ip_frag_tbl_stat::add_num", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(del_num) - ) + "Offset of field: ip_frag_tbl_stat::del_num", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(reuse_num) - ) + "Offset of field: ip_frag_tbl_stat::reuse_num", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_total) - ) + "Offset of field: ip_frag_tbl_stat::fail_total", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_nospace) - ) + "Offset of field: ip_frag_tbl_stat::fail_nospace", ); } impl Default for ip_frag_tbl_stat { @@ -548,142 +379,72 @@ pub struct rte_ip_frag_tbl { } #[test] fn bindgen_test_layout_rte_ip_frag_tbl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(rte_ip_frag_tbl)) + "Size of rte_ip_frag_tbl", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) + "Alignment of rte_ip_frag_tbl", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_cycles) - ) + "Offset of field: rte_ip_frag_tbl::max_cycles", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(entry_mask) - ) + "Offset of field: rte_ip_frag_tbl::entry_mask", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_entries) - ) + "Offset of field: rte_ip_frag_tbl::max_entries", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(use_entries) - ) + "Offset of field: rte_ip_frag_tbl::use_entries", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize }, 20usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(bucket_entries) - ) + "Offset of field: rte_ip_frag_tbl::bucket_entries", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_entries) - ) + "Offset of field: rte_ip_frag_tbl::nb_entries", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize }, 28usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_buckets) - ) + "Offset of field: rte_ip_frag_tbl::nb_buckets", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(last) - ) + "Offset of field: rte_ip_frag_tbl::last", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(lru) - ) + "Offset of field: rte_ip_frag_tbl::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(stat) - ) + "Offset of field: rte_ip_frag_tbl::stat", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, 128usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(pkt) - ) + "Offset of field: rte_ip_frag_tbl::pkt", ); } impl Default for rte_ip_frag_tbl { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index 800a303be1129c37cc3ab5c54e7ec1c8a6374539..aa2c121c2d9c22146dd805aa8dd3baa597d603b5 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -104,32 +96,14 @@ pub struct rte_atomic16_t { ///< An internal counter value. pub cnt: i16, } -#[test] -fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_atomic16_t"][::std::mem::size_of::() - 2usize]; + ["Alignment of rte_atomic16_t"][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_atomic16_t::cnt", + ][::std::mem::offset_of!(rte_atomic16_t, cnt) - 0usize]; +}; /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] #[repr(align(64))] @@ -171,18 +145,18 @@ pub struct rte_mbuf { ///< Next segment of scattered packet. pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + /** Size of the application private data. In case of an indirect + mbuf, it stores the direct mbuf private data size.*/ pub priv_size: u16, /// Timesync flags for use with IEEE1588. pub timesync: u16, } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +/** 16-bit Reference counter. + It should only be accessed using the following functions: + rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + config option.*/ #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { @@ -191,44 +165,21 @@ pub union rte_mbuf__bindgen_ty_1 { ///< Non-atomically accessed refcnt pub refcnt: u16, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_1", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt_atomic", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_1, refcnt_atomic) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_1, refcnt) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -252,31 +203,19 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; +}; impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_l2_type(&mut self, val: u32) { @@ -287,9 +226,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_l3_type(&mut self, val: u32) { @@ -300,9 +237,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } #[inline] pub fn set_l4_type(&mut self, val: u32) { @@ -313,9 +248,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn tun_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } #[inline] pub fn set_tun_type(&mut self, val: u32) { @@ -326,9 +259,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } #[inline] pub fn set_inner_l2_type(&mut self, val: u32) { @@ -339,9 +270,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } #[inline] pub fn set_inner_l3_type(&mut self, val: u32) { @@ -352,9 +281,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } #[inline] pub fn set_inner_l4_type(&mut self, val: u32) { @@ -373,70 +300,91 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l3_type: u32, inner_l4_type: u32, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; - l2_type as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; - l3_type as u64 - }); - __bindgen_bitfield_unit.set(8usize, 4u8, { - let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; - l4_type as u64 - }); - __bindgen_bitfield_unit.set(12usize, 4u8, { - let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; - tun_type as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let inner_l2_type: u32 = - unsafe { ::std::mem::transmute(inner_l2_type) }; - inner_l2_type as u64 - }); - __bindgen_bitfield_unit.set(20usize, 4u8, { - let inner_l3_type: u32 = - unsafe { ::std::mem::transmute(inner_l3_type) }; - inner_l3_type as u64 - }); - __bindgen_bitfield_unit.set(24usize, 4u8, { - let inner_l4_type: u32 = - unsafe { ::std::mem::transmute(inner_l4_type) }; - inner_l4_type as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; + l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; + l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; + l4_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 4u8, + { + let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; + tun_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let inner_l2_type: u32 = unsafe { + ::std::mem::transmute(inner_l2_type) + }; + inner_l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 4u8, + { + let inner_l3_type: u32 = unsafe { + ::std::mem::transmute(inner_l3_type) + }; + inner_l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 4u8, + { + let inner_l4_type: u32 = unsafe { + ::std::mem::transmute(inner_l4_type) + }; + inner_l4_type as u64 + }, + ); __bindgen_bitfield_unit } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_2::packet_type", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_2, packet_type) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -467,8 +415,7 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { - pub __bindgen_anon_1: - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, pub lo: u32, } #[repr(C)] @@ -477,54 +424,44 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( -) { - const UNINIT: ::std::mem::MaybeUninit< +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::( - ), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); -} + >() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >() - 2usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::hash", + ][::std::mem::offset_of!( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, hash + ) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::id", + ][::std::mem::offset_of!( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, id + ) - 2usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() + - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() + - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1::lo", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, lo) + - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -534,39 +471,18 @@ impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1::hi", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_1, hi) - 4usize]; +}; impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -582,105 +498,42 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) - ); -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::lo", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_2, lo) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_2, hi) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::rss", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, rss) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::fdir", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, fdir) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::sched", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, sched) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::usr", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, usr) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -698,44 +551,21 @@ pub union rte_mbuf__bindgen_ty_4 { ///< Allow 8-byte userdata on 32-bit pub udata64: u64, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_4", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_4", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_4::userdata", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_4, userdata) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_4::udata64", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_4, udata64) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -759,31 +589,19 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_5__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; +}; impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) } } #[inline] pub fn set_l2_len(&mut self, val: u64) { @@ -794,9 +612,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } #[inline] pub fn set_l3_len(&mut self, val: u64) { @@ -807,9 +623,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l4_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } #[inline] pub fn set_l4_len(&mut self, val: u64) { @@ -820,9 +634,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn tso_segsz(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } #[inline] pub fn set_tso_segsz(&mut self, val: u64) { @@ -833,9 +645,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } #[inline] pub fn set_outer_l3_len(&mut self, val: u64) { @@ -846,9 +656,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } #[inline] pub fn set_outer_l2_len(&mut self, val: u64) { @@ -866,65 +674,80 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { outer_l3_len: u64, outer_l2_len: u64, ) -> __BindgenBitfieldUnit<[u8; 7usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; - l2_len as u64 - }); - __bindgen_bitfield_unit.set(7usize, 9u8, { - let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; - l3_len as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; - l4_len as u64 - }); - __bindgen_bitfield_unit.set(24usize, 16u8, { - let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; - tso_segsz as u64 - }); - __bindgen_bitfield_unit.set(40usize, 9u8, { - let outer_l3_len: u64 = - unsafe { ::std::mem::transmute(outer_l3_len) }; - outer_l3_len as u64 - }); - __bindgen_bitfield_unit.set(49usize, 7u8, { - let outer_l2_len: u64 = - unsafe { ::std::mem::transmute(outer_l2_len) }; - outer_l2_len as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; + l2_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 9u8, + { + let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; + l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; + l4_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 16u8, + { + let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; + tso_segsz as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 9u8, + { + let outer_l3_len: u64 = unsafe { + ::std::mem::transmute(outer_l3_len) + }; + outer_l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 49usize, + 7u8, + { + let outer_l2_len: u64 = unsafe { + ::std::mem::transmute(outer_l2_len) + }; + outer_l2_len as u64 + }, + ); __bindgen_bitfield_unit } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_5", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_5", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_5::tx_offload", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_5, tx_offload) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -934,259 +757,74 @@ impl Default for rte_mbuf__bindgen_ty_5 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)) - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of rte_mbuf"][::std::mem::size_of::() - 128usize]; + ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; + [ + "Offset of field: rte_mbuf::cacheline0", + ][::std::mem::offset_of!(rte_mbuf, cacheline0) - 0usize]; + [ + "Offset of field: rte_mbuf::buf_addr", + ][::std::mem::offset_of!(rte_mbuf, buf_addr) - 0usize]; + [ + "Offset of field: rte_mbuf::buf_physaddr", + ][::std::mem::offset_of!(rte_mbuf, buf_physaddr) - 8usize]; + [ + "Offset of field: rte_mbuf::buf_len", + ][::std::mem::offset_of!(rte_mbuf, buf_len) - 16usize]; + [ + "Offset of field: rte_mbuf::rearm_data", + ][::std::mem::offset_of!(rte_mbuf, rearm_data) - 18usize]; + [ + "Offset of field: rte_mbuf::data_off", + ][::std::mem::offset_of!(rte_mbuf, data_off) - 18usize]; + [ + "Offset of field: rte_mbuf::nb_segs", + ][::std::mem::offset_of!(rte_mbuf, nb_segs) - 22usize]; + [ + "Offset of field: rte_mbuf::port", + ][::std::mem::offset_of!(rte_mbuf, port) - 23usize]; + [ + "Offset of field: rte_mbuf::ol_flags", + ][::std::mem::offset_of!(rte_mbuf, ol_flags) - 24usize]; + [ + "Offset of field: rte_mbuf::rx_descriptor_fields1", + ][::std::mem::offset_of!(rte_mbuf, rx_descriptor_fields1) - 32usize]; + [ + "Offset of field: rte_mbuf::pkt_len", + ][::std::mem::offset_of!(rte_mbuf, pkt_len) - 36usize]; + [ + "Offset of field: rte_mbuf::data_len", + ][::std::mem::offset_of!(rte_mbuf, data_len) - 40usize]; + [ + "Offset of field: rte_mbuf::vlan_tci", + ][::std::mem::offset_of!(rte_mbuf, vlan_tci) - 42usize]; + [ + "Offset of field: rte_mbuf::hash", + ][::std::mem::offset_of!(rte_mbuf, hash) - 44usize]; + [ + "Offset of field: rte_mbuf::seqn", + ][::std::mem::offset_of!(rte_mbuf, seqn) - 52usize]; + [ + "Offset of field: rte_mbuf::vlan_tci_outer", + ][::std::mem::offset_of!(rte_mbuf, vlan_tci_outer) - 56usize]; + [ + "Offset of field: rte_mbuf::cacheline1", + ][::std::mem::offset_of!(rte_mbuf, cacheline1) - 64usize]; + [ + "Offset of field: rte_mbuf::pool", + ][::std::mem::offset_of!(rte_mbuf, pool) - 72usize]; + [ + "Offset of field: rte_mbuf::next", + ][::std::mem::offset_of!(rte_mbuf, next) - 80usize]; + [ + "Offset of field: rte_mbuf::priv_size", + ][::std::mem::offset_of!(rte_mbuf, priv_size) - 96usize]; + [ + "Offset of field: rte_mbuf::timesync", + ][::std::mem::offset_of!(rte_mbuf, timesync) - 98usize]; +}; impl Default for rte_mbuf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 90f7ed09b2dec7416e9d42c54ad4032e7a52d49b..19394d271fb7320fa979c6f3ae8c9fceeb10fbf4 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -149,28 +141,22 @@ pub struct rte_atomic16_t { } #[test] fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)) + "Size of rte_atomic16_t", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)) + "Alignment of rte_atomic16_t", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) + "Offset of field: rte_atomic16_t::cnt", ); } impl Clone for rte_atomic16_t { @@ -218,19 +204,19 @@ pub struct rte_mbuf { ///< Next segment of scattered packet. pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + /** Size of the application private data. In case of an indirect + mbuf, it stores the direct mbuf private data size.*/ pub priv_size: u16, /// Timesync flags for use with IEEE1588. pub timesync: u16, pub __bindgen_padding_0: [u32; 7usize], } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +/** 16-bit Reference counter. + It should only be accessed using the following functions: + rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + config option.*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_1 { @@ -242,40 +228,27 @@ pub struct rte_mbuf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) + "Size of rte_mbuf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) + "Alignment of rte_mbuf__bindgen_ty_1", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt_atomic", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt", ); } impl Clone for rte_mbuf__bindgen_ty_1 { @@ -288,8 +261,7 @@ impl Clone for rte_mbuf__bindgen_ty_1 { pub struct rte_mbuf__bindgen_ty_2 { ///< L2/L3/L4 and tunnel information. pub packet_type: __BindgenUnionField, - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] @@ -304,18 +276,12 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + "Alignment of rte_mbuf__bindgen_ty_2__bindgen_ty_1", ); } impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { @@ -326,9 +292,7 @@ impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_l2_type(&mut self, val: u32) { @@ -339,9 +303,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_l3_type(&mut self, val: u32) { @@ -352,9 +314,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } #[inline] pub fn set_l4_type(&mut self, val: u32) { @@ -365,9 +325,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn tun_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } #[inline] pub fn set_tun_type(&mut self, val: u32) { @@ -378,9 +336,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } #[inline] pub fn set_inner_l2_type(&mut self, val: u32) { @@ -391,9 +347,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } #[inline] pub fn set_inner_l3_type(&mut self, val: u32) { @@ -404,9 +358,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } #[inline] pub fn set_inner_l4_type(&mut self, val: u32) { @@ -425,68 +377,97 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l3_type: u32, inner_l4_type: u32, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; - l2_type as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; - l3_type as u64 - }); - __bindgen_bitfield_unit.set(8usize, 4u8, { - let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; - l4_type as u64 - }); - __bindgen_bitfield_unit.set(12usize, 4u8, { - let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; - tun_type as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let inner_l2_type: u32 = - unsafe { ::std::mem::transmute(inner_l2_type) }; - inner_l2_type as u64 - }); - __bindgen_bitfield_unit.set(20usize, 4u8, { - let inner_l3_type: u32 = - unsafe { ::std::mem::transmute(inner_l3_type) }; - inner_l3_type as u64 - }); - __bindgen_bitfield_unit.set(24usize, 4u8, { - let inner_l4_type: u32 = - unsafe { ::std::mem::transmute(inner_l4_type) }; - inner_l4_type as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; + l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; + l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; + l4_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 4u8, + { + let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; + tun_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let inner_l2_type: u32 = unsafe { + ::std::mem::transmute(inner_l2_type) + }; + inner_l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 4u8, + { + let inner_l3_type: u32 = unsafe { + ::std::mem::transmute(inner_l3_type) + }; + inner_l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 4u8, + { + let inner_l4_type: u32 = unsafe { + ::std::mem::transmute(inner_l4_type) + }; + inner_l4_type as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)) + "Size of rte_mbuf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) + "Alignment of rte_mbuf__bindgen_ty_2", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) + "Offset of field: rte_mbuf__bindgen_ty_2::packet_type", ); } impl Clone for rte_mbuf__bindgen_ty_2 { @@ -529,20 +510,37 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub id: u16, } #[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( -) { +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq!( + ::std::mem::size_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 4usize, + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ); + assert_eq!( + ::std::mem::align_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 2usize, + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, + 0usize, + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::hash", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, + 2usize, + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::id", + ); } -impl Clone - for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 -{ +impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -554,33 +552,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::( - ), + ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >(), + ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1::lo", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -590,35 +574,22 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1::hi", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -634,45 +605,27 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::lo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { @@ -682,58 +635,37 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)) + "Size of rte_mbuf__bindgen_ty_3", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) + "Alignment of rte_mbuf__bindgen_ty_3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) + "Offset of field: rte_mbuf__bindgen_ty_3::rss", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) + "Offset of field: rte_mbuf__bindgen_ty_3::fdir", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) + "Offset of field: rte_mbuf__bindgen_ty_3::sched", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) + "Offset of field: rte_mbuf__bindgen_ty_3::usr", ); } impl Clone for rte_mbuf__bindgen_ty_3 { @@ -752,40 +684,27 @@ pub struct rte_mbuf__bindgen_ty_4 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)) + "Size of rte_mbuf__bindgen_ty_4", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) + "Alignment of rte_mbuf__bindgen_ty_4", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) + "Offset of field: rte_mbuf__bindgen_ty_4::userdata", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) + "Offset of field: rte_mbuf__bindgen_ty_4::udata64", ); } impl Clone for rte_mbuf__bindgen_ty_4 { @@ -798,8 +717,7 @@ impl Clone for rte_mbuf__bindgen_ty_4 { pub struct rte_mbuf__bindgen_ty_5 { ///< combined for easy fetch pub tx_offload: __BindgenUnionField, - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u64, } #[repr(C)] @@ -814,18 +732,12 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + "Alignment of rte_mbuf__bindgen_ty_5__bindgen_ty_1", ); } impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { @@ -836,9 +748,7 @@ impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) } } #[inline] pub fn set_l2_len(&mut self, val: u64) { @@ -849,9 +759,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } #[inline] pub fn set_l3_len(&mut self, val: u64) { @@ -862,9 +770,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l4_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } #[inline] pub fn set_l4_len(&mut self, val: u64) { @@ -875,9 +781,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn tso_segsz(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } #[inline] pub fn set_tso_segsz(&mut self, val: u64) { @@ -888,9 +792,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } #[inline] pub fn set_outer_l3_len(&mut self, val: u64) { @@ -901,9 +803,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } #[inline] pub fn set_outer_l2_len(&mut self, val: u64) { @@ -921,63 +821,86 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { outer_l3_len: u64, outer_l2_len: u64, ) -> __BindgenBitfieldUnit<[u8; 7usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; - l2_len as u64 - }); - __bindgen_bitfield_unit.set(7usize, 9u8, { - let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; - l3_len as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; - l4_len as u64 - }); - __bindgen_bitfield_unit.set(24usize, 16u8, { - let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; - tso_segsz as u64 - }); - __bindgen_bitfield_unit.set(40usize, 9u8, { - let outer_l3_len: u64 = - unsafe { ::std::mem::transmute(outer_l3_len) }; - outer_l3_len as u64 - }); - __bindgen_bitfield_unit.set(49usize, 7u8, { - let outer_l2_len: u64 = - unsafe { ::std::mem::transmute(outer_l2_len) }; - outer_l2_len as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; + l2_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 9u8, + { + let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; + l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; + l4_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 16u8, + { + let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; + tso_segsz as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 9u8, + { + let outer_l3_len: u64 = unsafe { + ::std::mem::transmute(outer_l3_len) + }; + outer_l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 49usize, + 7u8, + { + let outer_l2_len: u64 = unsafe { + ::std::mem::transmute(outer_l2_len) + }; + outer_l2_len as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)) + "Size of rte_mbuf__bindgen_ty_5", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) + "Alignment of rte_mbuf__bindgen_ty_5", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) + "Offset of field: rte_mbuf__bindgen_ty_5::tx_offload", ); } impl Clone for rte_mbuf__bindgen_ty_5 { @@ -987,250 +910,115 @@ impl Clone for rte_mbuf__bindgen_ty_5 { } #[test] fn bindgen_test_layout_rte_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of rte_mbuf"); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) + "Offset of field: rte_mbuf::cacheline0", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) + "Offset of field: rte_mbuf::buf_addr", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) + "Offset of field: rte_mbuf::buf_physaddr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) + "Offset of field: rte_mbuf::buf_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) + "Offset of field: rte_mbuf::rearm_data", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) + "Offset of field: rte_mbuf::data_off", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) + "Offset of field: rte_mbuf::nb_segs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) + "Offset of field: rte_mbuf::port", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) + "Offset of field: rte_mbuf::ol_flags", ); assert_eq!( unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) + "Offset of field: rte_mbuf::rx_descriptor_fields1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) + "Offset of field: rte_mbuf::pkt_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) + "Offset of field: rte_mbuf::data_len", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) + "Offset of field: rte_mbuf::vlan_tci", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) + "Offset of field: rte_mbuf::hash", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) + "Offset of field: rte_mbuf::seqn", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) + "Offset of field: rte_mbuf::vlan_tci_outer", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) + "Offset of field: rte_mbuf::cacheline1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) + "Offset of field: rte_mbuf::pool", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) + "Offset of field: rte_mbuf::next", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) + "Offset of field: rte_mbuf::priv_size", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) + "Offset of field: rte_mbuf::timesync", ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs new file mode 100644 index 0000000000000000000000000000000000000000..4f8296c65c73c98272d89be3a4dfac12bcfcc36d --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub _address: u8, +} +pub type C_U = B; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub u: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; + ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: C_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: C_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs new file mode 100644 index 0000000000000000000000000000000000000000..5c5ad156e30f6d50b4a6f49599688fc4f5c7633c --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo { + pub member: *mut [u8; 0usize], +} +pub type Foo_FirstAlias = [u8; 0usize]; +pub type Foo_SecondAlias = [u8; 0usize]; +impl Default for Foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs new file mode 100644 index 0000000000000000000000000000000000000000..fe64295a689cfab8aaff286fcf9c73b18247d1b3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs @@ -0,0 +1 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs b/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs new file mode 100644 index 0000000000000000000000000000000000000000..8f5c4ba2dae5aa389351eb30f90da29b2f081a6e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs @@ -0,0 +1 @@ +pub const NEGATIVE: i32 = -1; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs new file mode 100644 index 0000000000000000000000000000000000000000..f55f88f496b51c383d88072c80e5f717b02f9adb --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEST_STRUCT { + pub ptr_32bit: *mut ::std::os::raw::c_void, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TEST_STRUCT"][::std::mem::size_of::() - 8usize]; + ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TEST_STRUCT::ptr_32bit", + ][::std::mem::offset_of!(TEST_STRUCT, ptr_32bit) - 0usize]; +}; +impl Default for TEST_STRUCT { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs new file mode 100644 index 0000000000000000000000000000000000000000..d93a62e74609a874a0dbd813823fa08bb96acbfe --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + pub mod whatever { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct typedef_struct { + pub foo: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum typedef_enum { + BAR = 1, + } + } + pub mod _bindgen_mod_id_12 { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct _bindgen_ty_1 { + pub foo: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; + [ + "Alignment of _bindgen_ty_1", + ][::std::mem::align_of::<_bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1::foo", + ][::std::mem::offset_of!(_bindgen_ty_1, foo) - 0usize]; + }; + pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; + pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum _bindgen_ty_2 { + BAR = 1, + } + pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; + } +} diff --git a/bindgen-tests/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs index 2c3b6c937fcffa2e1613774d001b80e61070bd6f..aa3109ca433c383652fdd92dcbfd8fc44b2d5b05 100644 --- a/bindgen-tests/tests/expectations/tests/long_double.rs +++ b/bindgen-tests/tests/expectations/tests/long_double.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -13,22 +7,13 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + "Offset of field: foo::bar", ); } diff --git a/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs b/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs index 4eeb310c8fa96a2d260e060f1aff5c3a6c4a4d7f..21c81b317c4239f10a6a9a71a2d343a53f666057 100644 --- a/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs +++ b/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO: u32 = 1; pub const BAR: u32 = 4; pub const BAZ: u32 = 5; diff --git a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs index b2f2ebd2e2579ca64c224b04d509d7649503db75..c905e5aa906febfbd587efae0a731ada48fefec6 100644 --- a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs +++ b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const MODBUS_WOOT: u32 = 3; extern "C" { pub fn foo(); diff --git a/bindgen-tests/tests/expectations/tests/macro-redef.rs b/bindgen-tests/tests/expectations/tests/macro-redef.rs index ff5654f47bc296162ea0fae0482cdc7eca250e2d..12e3d3d5877820cba8b0b36851403ce01f702704 100644 --- a/bindgen-tests/tests/expectations/tests/macro-redef.rs +++ b/bindgen-tests/tests/expectations/tests/macro-redef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO: u32 = 4; pub const BAR: u32 = 5; pub const BAZ: u32 = 6; diff --git a/bindgen-tests/tests/expectations/tests/macro_const.rs b/bindgen-tests/tests/expectations/tests/macro_const.rs index de423a2af0cdc76af9d070e3ffca712e6c723637..e4e27dea522f6375e5740cc4f1f48669780d1e83 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const.rs @@ -1,14 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const foo: &[u8; 4usize] = b"bar\0"; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const foo: &[u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; pub const FLOAT: f64 = 5.09; pub const FLOAT_EXPR: f64 = 0.005; pub const LONG: u32 = 3; -pub const INVALID_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const INVALID_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs index e135661121682a330399d4f351d1770faeea6ee3..2f3e228d8044342c0380702fd4de40b84392c18c 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs @@ -1,14 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const foo: &'static [u8; 4usize] = b"bar\0"; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const foo: &'static [u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; pub const FLOAT: f64 = 5.09; pub const FLOAT_EXPR: f64 = 0.005; pub const LONG: u32 = 3; -pub const INVALID_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const INVALID_UTF8: &'static [u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs b/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs index 12157f4b9d6629c54a52e33224440a382b43b0a5..0876aeb904e79644e0a4c0c02f591a8d50f4665e 100644 --- a/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs +++ b/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct RefPtr { diff --git a/bindgen-tests/tests/expectations/tests/mangling-ios.rs b/bindgen-tests/tests/expectations/tests/mangling-ios.rs index 8a4ff6578ec13967c667772a6ec05c6fa47dc766..05b7aecd3ee787862df1317088278d6d7fa99704 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-ios.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-ios.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index bddd761794818428c66c2e65310459d984a94ba2..ab1f7996941441cc4e1df35038c80f080d365165 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -17,16 +11,8 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index bddd761794818428c66c2e65310459d984a94ba2..ab1f7996941441cc4e1df35038c80f080d365165 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -17,16 +11,8 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index 9af36259fd22d111c7a0b2ac3c2acfbcf7b01edd..b5d78cedb564a6a195d4f0f1e2e07abecb2dcf69 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -17,16 +11,8 @@ extern "C" { #[link_name = "\u{1}__ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs new file mode 100644 index 0000000000000000000000000000000000000000..572b69962c219b55e037e9c0b56018140d6a6c51 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/mangling-win32.rs @@ -0,0 +1,38 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; +extern "fastcall" { + pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "fastcall" { + pub fn fast_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_no_args() -> ::std::os::raw::c_int; +} +extern "stdcall" { + pub fn std_call_func_many_args( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index cb5f7103adc09f735891402cc0e2f77e0b99b3b1..1e71710f6c4b2188e349a6d1d638e490409a6e9f 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -17,16 +11,8 @@ extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index ae9799d27529682922cf71630a48521314bbec97..595d865af1863fa5c95c67c21dd511e97ea1acec 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -14,32 +8,12 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; pub mod ns { #[allow(unused_imports)] use self::super::super::root; @@ -48,34 +22,12 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; extern "C" { #[link_name = "\u{1}_ZN2ns3fooEv"] pub fn foo() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index e4627ac8a72014896f897de26c0d22f4190e5041..bde0a0f2ff7085b21c066f993a42e96e0a3f19f1 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs index 30cdb3580b3913721b01c46ecd36b55a9567bdf5..9ac408dc8f221f82cc44ea374008a505183417da 100644 --- a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -14,17 +8,9 @@ pub mod root { pub struct Test { pub _address: u8, } - #[test] - fn bindgen_test_layout_Test() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs index 64db43a6b6c85d6e852fd7cb531de0f4482e158a..adaa1a07b28ad86dd2e10d8dcfa63bf7725176c4 100644 --- a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs +++ b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub foo: usize, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 8usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::foo"][::std::mem::offset_of!(A, foo) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 55b3d1e31bcff2b7feb791479db09f1d3d10aa1e..b0cf27451cef3c86a8c6ca484c87067140211ac8 100644 --- a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -1,61 +1,31 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs index 94c703266a986808ea03093da65ae7114a094f1b..ff98d31f242829ef1968cf25fb0d7dd2c53f5683 100644 --- a/bindgen-tests/tests/expectations/tests/mutable.rs +++ b/bindgen-tests/tests/expectations/tests/mutable.rs @@ -1,124 +1,45 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub m_member: ::std::os::raw::c_int, pub m_other: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_member) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_other) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::m_member"][::std::mem::offset_of!(C, m_member) - 0usize]; + ["Offset of field: C::m_other"][::std::mem::offset_of!(C, m_other) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct NonCopiable { pub m_member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopiable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopiable)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiable), - "::", - stringify!(m_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NonCopiable"][::std::mem::size_of::() - 4usize]; + ["Alignment of NonCopiable"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopiable::m_member", + ][::std::mem::offset_of!(NonCopiable, m_member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct NonCopiableWithNonCopiableMutableMember { pub m_member: NonCopiable, } -#[test] -fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { - const UNINIT: ::std::mem::MaybeUninit< - NonCopiableWithNonCopiableMutableMember, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(NonCopiableWithNonCopiableMutableMember) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(NonCopiableWithNonCopiableMutableMember) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), - "::", - stringify!(m_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of NonCopiableWithNonCopiableMutableMember", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of NonCopiableWithNonCopiableMutableMember", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopiableWithNonCopiableMutableMember::m_member", + ][::std::mem::offset_of!(NonCopiableWithNonCopiableMutableMember, m_member) + - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index 49c8a7ef4867321f44d5f34073b076bc88adf084..f4f2a76c3e30b204345be5732c2bde7769f82a9d 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -31,43 +25,21 @@ pub mod root { pub struct A { pub b: root::whatever::whatever_int_t, } - #[test] - fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(b) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::b"][::std::mem::offset_of!(A, b) - 0usize]; + }; } #[repr(C)] #[derive(Debug)] pub struct C { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: root::_bindgen_mod_id_17::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for C { fn default() -> Self { @@ -85,9 +57,8 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct D { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub m_c: root::C, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for D { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs b/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs index ab761d286f834b784f08203ac4fb4f9a36dfb193..4a4dd2ffe16b4d57ecd2494fcd0f68f13b016707 100644 --- a/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs index 415a74056142fe6537436e43b0f33c610ea48370..5e0a8b07c837bf53bc51f721036a2624a7c72cb4 100644 --- a/bindgen-tests/tests/expectations/tests/nested.rs +++ b/bindgen-tests/tests/expectations/tests/nested.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Calc { pub w: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Calc() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Calc)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Calc)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Calc"][::std::mem::size_of::() - 4usize]; + ["Alignment of Calc"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Calc::w"][::std::mem::offset_of!(Calc, w) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { @@ -47,65 +26,28 @@ pub struct Test_Size { pub struct Test_Size_Dimension { pub _base: Calc, } -#[test] -fn bindgen_test_layout_Test_Size_Dimension() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test_Size_Dimension)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test_Size_Dimension)) - ); -} -#[test] -fn bindgen_test_layout_Test_Size() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test_Size)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test_Size)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mWidth) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mHeight) - ) - ); -} -#[test] -fn bindgen_test_layout_Test() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of Test_Size_Dimension", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of Test_Size_Dimension", + ][::std::mem::align_of::() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test_Size"][::std::mem::size_of::() - 8usize]; + ["Alignment of Test_Size"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Test_Size::mWidth", + ][::std::mem::offset_of!(Test_Size, mWidth) - 0usize]; + [ + "Offset of field: Test_Size::mHeight", + ][::std::mem::offset_of!(Test_Size, mHeight) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index 7ee483044e5e365c06e506bfe1d589069eead24f..6356f9efd10411c2603f9706c3d8318fafdac006 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -1,33 +1,20 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsISupports__bindgen_vtable { - pub nsISupports_QueryInterface: - unsafe extern "C" fn(this: *mut nsISupports) -> *mut nsISupports, + pub nsISupports_QueryInterface: unsafe extern "C" fn( + this: *mut nsISupports, + ) -> *mut nsISupports, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsISupports { pub vtable_: *const nsISupports__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsISupports() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsISupports)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsISupports)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsISupports"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsISupports"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsISupports { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -48,19 +35,11 @@ extern "C" { pub struct nsIRunnable { pub _base: nsISupports, } -#[test] -fn bindgen_test_layout_nsIRunnable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIRunnable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIRunnable)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsIRunnable"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsIRunnable"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsIRunnable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -75,19 +54,11 @@ impl Default for nsIRunnable { pub struct Runnable { pub _base: nsIRunnable, } -#[test] -fn bindgen_test_layout_Runnable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Runnable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Runnable)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Runnable"][::std::mem::size_of::() - 8usize]; + ["Alignment of Runnable"][::std::mem::align_of::() - 8usize]; +}; impl Default for Runnable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs index 629c449a61feada7ced1a1d76d7fbfec046f2c1d..f470571ddcd956a03db7a1113b03b7ae001b5670 100644 --- a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -22,94 +16,30 @@ pub mod root { pub struct Bar_Baz { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Bar_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar_Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar_Baz)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar_Baz), - "::", - stringify!(foo) - ) - ); - } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar_Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar_Baz"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Bar_Baz::foo", + ][::std::mem::offset_of!(Bar_Baz, foo) - 0usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::foo"][::std::mem::offset_of!(Bar, foo) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub baz: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(baz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz::baz"][::std::mem::offset_of!(Baz, baz) - 0usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/newtype-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-enum.rs index 26a4eb1fdf4aaf04a9f6b5e46fc23c8da1a06dd5..ea25950de0fb2a08cc3db955716692af46c2d7cb 100644 --- a/bindgen-tests/tests/expectations/tests/newtype-enum.rs +++ b/bindgen-tests/tests/expectations/tests/newtype-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs index cf23cca60b9b1fa0cf6a0b6db91f72701c85d7e6..29b87bff06bf5cb5787d6b2853dae6483f38866a 100644 --- a/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs +++ b/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Foo_Bar: Foo = Foo(2); pub const Foo_Baz: Foo = Foo(4); pub const Foo_Duplicated: Foo = Foo(4); diff --git a/bindgen-tests/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs index a375d8ea69c590fec47dc4afb84696eac8d01aa1..6a60973fb4c4ad0ffc7d108be1c2d7085e4142ac 100644 --- a/bindgen-tests/tests/expectations/tests/no-comments.rs +++ b/bindgen-tests/tests/expectations/tests/no-comments.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub s: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::s"][::std::mem::offset_of!(Foo, s) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs index c7a6d1843b8e03ff142f5e1fc2b7fd26ea761b76..5e525068fd1a1c96b20494b875599251f51b7cd9 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs @@ -1,50 +1,24 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, } - -/// bar should compile. It will normally derive debug, but our blocklist of foo -/// and replacement for another type that doesn't implement it would prevent it -/// from building if --no-derive-debug didn't work. +/** bar should compile. It will normally derive debug, but our blocklist of foo + and replacement for another type that doesn't implement it would prevent it + from building if --no-derive-debug didn't work.*/ #[repr(C)] pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::foo"][::std::mem::offset_of!(bar, foo) - 0usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 4usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs index 46b2cb4ee7cee7712835a5f4b1dafc415d38abd1..a1d86a65024e79c1a261cf00b2ee31b1271e3c49 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-default.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-default.rs @@ -1,47 +1,21 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, } - -/// bar should compile. It will normally derive default, but our blocklist of foo -/// and replacement for another type that doesn't implement it would prevent it -/// from building if --no-derive-default didn't work. +/** bar should compile. It will normally derive default, but our blocklist of foo + and replacement for another type that doesn't implement it would prevent it + from building if --no-derive-default didn't work.*/ #[repr(C)] pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::foo"][::std::mem::offset_of!(bar, foo) - 0usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs index 549b72b53bf1af6b28a1df6277cea9e53c475ef6..ff4dd1e38edd2e996a22101d7ff0f436d5f8e65b 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoHash() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoHash::i"][::std::mem::offset_of!(NoHash, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs index 49ff4daad795a83ed2732214467c929e2888c1e1..9dc9e01989f69567997eadf0cd0cc0411bb8f96c 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs @@ -1,26 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoHash() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs index c7895fe64ba86cad1e30f32e272e55887361caa8..68ae1a7449578ffb6ecec1cd911bf1ba12bad87b 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -1,38 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoPartialEq), - "::", - stringify!(i) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoPartialEq::i"][::std::mem::offset_of!(NoPartialEq, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs index 423799a6b9234ba9254b0c0e3b0210e2c26913d4..4b488df6a5320e8627395bf8fd8d43737ade72c7 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs @@ -1,26 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs index 6f1e19ba950069e6cd66911a77b77cd725b86d71..dc1e4721abb8f48202741641d3a36d3200f6dacb 100644 --- a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs @@ -1,38 +1,16 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub enum Bar {} - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { pub baz: *mut Bar, } -#[test] -fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::baz"][::std::mem::offset_of!(Foo, baz) - 0usize]; +}; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs index 457242c2baf1a650eff04202a7b2663e7536185a..0f03c222ef48281665ed5fa99d13acc7a7711aae 100644 --- a/bindgen-tests/tests/expectations/tests/no-std.rs +++ b/bindgen-tests/tests/expectations/tests/no-std.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![no_std] mod libc { pub type c_int = i32; pub enum c_void {} } - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -17,37 +11,14 @@ pub struct foo { pub b: libc::c_int, pub bar: *mut libc::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no_copy.rs b/bindgen-tests/tests/expectations/tests/no_copy.rs index daccf757ec90902b5b3030a6bff5b2d342b3b774..b92c5424821b5bafdf6c3b83e1fdd0c5487939ba 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default)] diff --git a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs index 1c46de75f14b30c9be0391a4e517138e4868d394..67be3917997a29419d59440dba12a65e140be83f 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct NoCopy { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoCopy::i"][::std::mem::offset_of!(NoCopy, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs index 7fc3529f6e90510263619322a61efa167d9592c9..dea6a0a6cf0716f9ae58828b8f83fb33d1b288fd 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs @@ -1,26 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default)] pub struct NoCopy { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoCopy() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug.rs index 21850ecb15b925bc357048181aa5d5009c60fa13..9a162c6f703e5e1cfe2ac2aa60160419da328a5a 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs index 859dad8cb3a9b9af16bd24e24c3837ab215258cd..1ddb20a7477adde08eedd3d6b3986e409341bcfa 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs @@ -1,38 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default, Copy, Clone)] pub struct NoDebug { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(i) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoDebug::i"][::std::mem::offset_of!(NoDebug, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs index 334f39ddb0cdc34ef5a97b94a7a9a44f00d14653..d972c74376af3c5bb9ff670fd5fdd29c0709e7b1 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs @@ -1,14 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { @@ -26,8 +20,8 @@ impl ::std::fmt::Debug for Generic { } #[repr(C)] pub struct NoDebug { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for NoDebug { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs index 4b657481cdca0ab2b8c703502a815377a8d8c85e..0bb37ec711f5d36d0a3acddc9669e535c1564b5f 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs @@ -1,26 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Default, Copy, Clone)] pub struct NoDebug { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoDebug() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_default.rs b/bindgen-tests/tests/expectations/tests/no_default.rs index 22fdbf36e4de6542610326bc82a6e8acc61695dc..fd3d86e277990954b78bd72a1a955d746eecc28a 100644 --- a/bindgen-tests/tests/expectations/tests/no_default.rs +++ b/bindgen-tests/tests/expectations/tests/no_default.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs index c4deceb4b06cf0361476d6057a4a70f3b2e018d7..593e64434376c67aa9a293b91ee568924c6c8a32 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs @@ -1,38 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NoDefault { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoDefault() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDefault), - "::", - stringify!(i) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoDefault::i"][::std::mem::offset_of!(NoDefault, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs b/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs index 6c44a9dd2898286ecc955208dbedc867485df265..58f3684ac9e488624cab0d4a8d7ae5ca9d2827f0 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs @@ -1,14 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { @@ -21,6 +15,6 @@ impl Default for Generic { } #[repr(C)] pub struct NoDefault { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } diff --git a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs index 3c928551e61013141453d821f12bc2f78f9d80f0..ba2f63f91c55c16ee412e825f66ffbfff460460c 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs @@ -1,26 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Copy, Clone)] pub struct NoDefault { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoDefault() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs index f399a66724b6c58a9cce7c18c3a095ec7b614c30..94ce735b31af70a2af3886d574829678f311ed2e 100644 --- a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs +++ b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type size_t = ::std::os::raw::c_ulong; pub type ssize_t = ::std::os::raw::c_long; #[repr(C)] @@ -14,37 +8,14 @@ pub struct A { pub offset: ssize_t, pub next: *mut A, } -#[test] -fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 24usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::len"][::std::mem::offset_of!(A, len) - 0usize]; + ["Offset of field: A::offset"][::std::mem::offset_of!(A, offset) - 8usize]; + ["Offset of field: A::next"][::std::mem::offset_of!(A, next) - 16usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index 2b38e216670527370c3252b3448cbfb7ead9179d..64b293cb1be7545bcc45953535d52f71532e7231 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Array16 = u8; pub type ArrayInt4 = [u32; 4usize]; #[repr(C)] @@ -14,55 +8,17 @@ pub struct UsesArray { pub array_bool_8: [u8; 8usize], pub array_int_4: ArrayInt4, } -#[test] -fn bindgen_test_layout_UsesArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(UsesArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(UsesArray)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_char_16) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_bool_8) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_int_4) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of UsesArray"][::std::mem::size_of::() - 40usize]; + ["Alignment of UsesArray"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: UsesArray::array_char_16", + ][::std::mem::offset_of!(UsesArray, array_char_16) - 0usize]; + [ + "Offset of field: UsesArray::array_bool_8", + ][::std::mem::offset_of!(UsesArray, array_bool_8) - 16usize]; + [ + "Offset of field: UsesArray::array_int_4", + ][::std::mem::offset_of!(UsesArray, array_int_4) - 24usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/noreturn.rs b/bindgen-tests/tests/expectations/tests/noreturn.rs index a39057821127c0dbd3746b6393a02d7b14a81b86..2081d3d44b0746cafce4faadb2813beddc67934a 100644 --- a/bindgen-tests/tests/expectations/tests/noreturn.rs +++ b/bindgen-tests/tests/expectations/tests/noreturn.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f() -> !; @@ -17,3 +11,11 @@ extern "C" { #[link_name = "\u{1}_Z1hv"] pub fn h() -> !; } +extern "C" { + #[link_name = "\u{1}_Z1iPFvvE"] + pub fn i(arg: ::std::option::Option !>); +} +extern "C" { + #[link_name = "\u{1}_Z1jPFvvE"] + pub fn j(arg: ::std::option::Option !>) -> !; +} diff --git a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs index 26179b763eda410a0a6072bd0860bcb71029f8f2..f2f7eefb462545575e8a7489493c31c86295b627 100644 --- a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs +++ b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsBaseHashtableET { diff --git a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs index fab18c1cab5558f7e5910fa879ebc485cc723332..3d8edcfdc1bea8e19cf380420edb7263bd7a4b29 100644 --- a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs +++ b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { - pub mBuff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mBuff: *mut T, } impl Default for nsTArray { fn default() -> Self { @@ -23,9 +17,9 @@ impl Default for nsTArray { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsStyleAutoArray { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub mFirstElement: T, pub mOtherElements: nsTArray, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs index 370cab933261fdc34f1d7b5fc62b3c53b8d4dfa2..7ccd4e3c041ae9185b02baac9248fdc44c7ec605 100644 --- a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PSomeProtocol: Sized + std::ops::Deref { @@ -14,7 +8,7 @@ pub trait PSomeProtocol: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, protocolMethod) + msg_send!(* self, protocolMethod) } unsafe fn protocolClassMethod() where @@ -45,7 +39,7 @@ pub trait IAllowlistMe: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } unsafe fn classMethod() where diff --git a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs index 7d5d19b083b83e06004e907ab06042c8fd7d50ad..e5c5d2bfd55de267c27dbf9414a1af5d0c547bf8 100644 --- a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - #[macro_use] extern crate objc; #[allow(non_camel_case_types)] @@ -31,12 +25,12 @@ pub trait ISomeClass: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, ambiguouslyBlockedMethod) + msg_send!(* self, ambiguouslyBlockedMethod) } unsafe fn instanceMethod(&self) where ::Target: objc::Message + Sized, { - msg_send!(*self, instanceMethod) + msg_send!(* self, instanceMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs index 9d60233bedbbb966b4c4b3b9629da074d149710e..a1b1e3b1f177dcb3c7f5bdbe2e99f55fc82ce1e5 100644 --- a/bindgen-tests/tests/expectations/tests/objc_category.rs +++ b/bindgen-tests/tests/expectations/tests/objc_category.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } } impl Foo_BarCategory for Foo {} @@ -39,6 +33,6 @@ pub trait Foo_BarCategory: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, categoryMethod) + msg_send!(* self, categoryMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index b322bddcb64d5c12bb93366edc7312704a329b40..50bdea53ee14e5578b2067fb16e3a158f09ecb49 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { @@ -33,6 +27,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs index 29e70256ff641cc3633261d5e67a93454273fa5f..6bc26214626d37d4829c7b62761a3a02376a177d 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class_method.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -36,13 +30,13 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithInt: foo) + msg_send!(class!(Foo), methodWithInt : foo) } unsafe fn methodWithFoo_(foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithFoo: foo) + msg_send!(class!(Foo), methodWithFoo : foo) } unsafe fn methodReturningInt() -> ::std::os::raw::c_int where @@ -60,9 +54,12 @@ pub trait IFoo: Sized + std::ops::Deref { intvalue: ::std::os::raw::c_int, ptr: *mut ::std::os::raw::c_char, floatvalue: f32, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + msg_send!( + class!(Foo), methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue + ) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_escape.rs b/bindgen-tests/tests/expectations/tests/objc_escape.rs index c2f0ce313c6a1e308877f01320ee459ae5d8c27f..1351231d62bf4306b12b934db15f90247ce09074 100644 --- a/bindgen-tests/tests/expectations/tests/objc_escape.rs +++ b/bindgen-tests/tests/expectations/tests/objc_escape.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -26,13 +20,46 @@ impl A { } impl IA for A {} pub trait IA: Sized + std::ops::Deref { - unsafe fn f_as_( - &self, - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - ) where + unsafe fn f_as_(&self, arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int) + where ::Target: objc::Message + Sized, { - msg_send ! (* self , f : arg1 r#as : arg2) + msg_send!(* self, f : arg1 r#as : arg2) + } + unsafe fn crate_(&self, self_: ::std::os::raw::c_int) + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, crate_ : self_) + } +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct B(pub id); +impl std::ops::Deref for B { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for B {} +impl B { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(B), alloc) }) + } +} +impl IB for B {} +pub trait IB: Sized + std::ops::Deref { + unsafe fn type_(&self) -> id + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, type) + } + unsafe fn setType_(&self, type_: id) + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, setType : type_) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_inheritance.rs new file mode 100644 index 0000000000000000000000000000000000000000..6fb4e6b857f18491341afc2f0e5cbc15f6a8d8a8 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/objc_inheritance.rs @@ -0,0 +1,107 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target_os = "macos")] +use objc::{self, msg_send, sel, sel_impl, class}; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Foo), alloc) }) + } +} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Bar(pub id); +impl std::ops::Deref for Bar { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Bar {} +impl Bar { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Bar), alloc) }) + } +} +impl IFoo for Bar {} +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Bar { + type Error = &'static str; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err("This Foo cannot be downcasted to Bar") + } + } +} +impl IBar for Bar {} +pub trait IBar: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Baz(pub id); +impl std::ops::Deref for Baz { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Baz {} +impl Baz { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Baz), alloc) }) + } +} +impl IBar for Baz {} +impl From for Bar { + fn from(child: Baz) -> Bar { + Bar(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = &'static str; + fn try_from(parent: Bar) -> Result { + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err("This Bar cannot be downcasted to Baz") + } + } +} +impl IFoo for Baz {} +impl From for Foo { + fn from(child: Baz) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = &'static str; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err("This Foo cannot be downcasted to Baz") + } + } +} +impl IBaz for Baz {} +pub trait IBaz: Sized + std::ops::Deref {} diff --git a/bindgen-tests/tests/expectations/tests/objc_interface.rs b/bindgen-tests/tests/expectations/tests/objc_interface.rs index 89e64d86b66bc8eabba89528fb33f4eecd134055..2cc602efd4ab0a6ee18e8401826f7a9fc424db6d 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index 423ba910d45145299b950f42af9ad9b8e9d49e50..66c65be2d71337992b21814dc722d46b3de5d294 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -31,32 +25,12 @@ pub trait IFoo: Sized + std::ops::Deref {} pub struct FooStruct { pub foo: Foo, } -#[test] -fn bindgen_test_layout_FooStruct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(FooStruct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(FooStruct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FooStruct), - "::", - stringify!(foo) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of FooStruct"][::std::mem::size_of::() - 8usize]; + ["Alignment of FooStruct"][::std::mem::align_of::() - 8usize]; + ["Offset of field: FooStruct::foo"][::std::mem::offset_of!(FooStruct, foo) - 0usize]; +}; impl Default for FooStruct { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs index 593fd27738bab0534fa9f91cbbafd96ae2e91c4b..7d9fd84cf2b09d4b887d9540e211043ba95c3ba4 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,41 +24,42 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithInt: foo) + msg_send!(* self, methodWithInt : foo) } unsafe fn methodWithFoo_(&self, foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithFoo: foo) + msg_send!(* self, methodWithFoo : foo) } unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningInt) + msg_send!(* self, methodReturningInt) } unsafe fn methodReturningFoo(&self) -> Foo where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningFoo) + msg_send!(* self, methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( &self, intvalue: ::std::os::raw::c_int, ptr: *mut ::std::os::raw::c_char, floatvalue: f32, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + msg_send!(* self, methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -76,7 +71,10 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) + msg_send!( + * self, methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 + arg4Name : arg4 + ) } } pub type instancetype = id; diff --git a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs index ac77cc19e31430ab8e4d0a6add3e4509b072b0c3..4d35661f8ca4c8ea6341544e69c87460ddf1d3c2 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, foo) + msg_send!(* self, foo) } unsafe fn class_foo() where diff --git a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs index 1ec8494d2547a7ba1fc4a542548b7b371b62acbc..73c3d6e5c8099f1cdff3457afe2a5783b4d37ff5 100644 --- a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs +++ b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -47,7 +41,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, methodUsingBar: my_bar) + msg_send!(* self, methodUsingBar : my_bar) } unsafe fn methodReturningBar() -> Bar where diff --git a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs index 9f3fabd2720d1e572a524db89729a426e8439b2d..e038edf7f1e525d84662e972069c4700fd519d41 100644 --- a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs +++ b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -38,7 +32,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, func) + msg_send!(* self, func) } unsafe fn setFunc_( &self, @@ -49,9 +43,10 @@ pub trait IFoo: Sized + std::ops::Deref { arg3: f32, ) -> ::std::os::raw::c_int, >, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send!(*self, setFunc: func) + msg_send!(* self, setFunc : func) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_protocol.rs b/bindgen-tests/tests/expectations/tests/objc_protocol.rs index 5bd7d433f4cf48c90499fe6cf115c61132093ef0..533f5e2ef3dcc0ac54a0fa6e826b2c625405d525 100644 --- a/bindgen-tests/tests/expectations/tests/objc_protocol.rs +++ b/bindgen-tests/tests/expectations/tests/objc_protocol.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} diff --git a/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs index f5f80e2e30efff4841b152ee4616363eda692529..8bb0ef6f62fb99d87c55ecd415e4621c75c68eb4 100644 --- a/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} @@ -53,8 +47,7 @@ impl From for Foo { impl std::convert::TryFrom for Bar { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { diff --git a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs index 0017eab00d8760dd462f911ebd0253224d289531..25854d8488d33e7729eb2ab05630bcd202976110 100644 --- a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs +++ b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/objc_template.rs b/bindgen-tests/tests/expectations/tests/objc_template.rs new file mode 100644 index 0000000000000000000000000000000000000000..ee47f67d4c022469c6be470d9eff4cc9e4ba7a28 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/objc_template.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target_os = "macos")] +use objc::{self, msg_send, sel, sel_impl, class}; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Foo), alloc) }) + } +} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref { + unsafe fn get(&self) -> u64 + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, get) + } +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct FooMultiGeneric(pub id); +impl std::ops::Deref for FooMultiGeneric { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for FooMultiGeneric {} +impl FooMultiGeneric { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) + } +} +impl IFooMultiGeneric +for FooMultiGeneric {} +pub trait IFooMultiGeneric< + KeyType: 'static, + ObjectType: 'static, +>: Sized + std::ops::Deref { + unsafe fn objectForKey_(&self, key: u64) -> u64 + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, objectForKey : key) + } +} diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index 2f063b5b383d9673cd1c1bfebfa905a1af6bd7fd..5cd01b4485feb70b0492136b78d7b18ca7e8ced1 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,31 +83,21 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; +}; impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -126,9 +108,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -138,20 +118,26 @@ impl C { } } #[inline] - pub fn new_bitfield_1( - a: bool, - b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs index c28d93566411f1cbb42c6b211a8af3cced267540..14718a931262120f8a042158cf90c9cae05dbf47 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// This is like `opaque-template-inst-member.hpp` except exercising the cases -/// where we are OK to derive Debug/Hash/PartialEq. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is like `opaque-template-inst-member.hpp` except exercising the cases + where we are OK to derive Debug/Hash/PartialEq.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { @@ -19,42 +13,21 @@ pub struct ContainsOpaqueTemplate { pub mBlah: u32, pub mBaz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContainsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContainsOpaqueTemplate", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ContainsOpaqueTemplate", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueTemplate::mBlah", + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBlah) - 0usize]; + [ + "Offset of field: ContainsOpaqueTemplate::mBaz", + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBaz) - 4usize]; +}; /// Should also derive Debug/Hash/PartialEq. #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -62,32 +35,18 @@ pub struct InheritsOpaqueTemplate { pub _base: u8, pub wow: *mut ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_InheritsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of InheritsOpaqueTemplate", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of InheritsOpaqueTemplate", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: InheritsOpaqueTemplate::wow", + ][::std::mem::offset_of!(InheritsOpaqueTemplate, wow) - 8usize]; +}; impl Default for InheritsOpaqueTemplate { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs index 4ba85f660f39e100db48f19fc7fd8f8ca60d3685..4b070fa697bf4f381c4eb29dfb093f6f9f6456e3 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { pub _address: u8, } -/// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive -/// Debug/Hash because the instantiation's definition cannot derive Debug/Hash. +/** This should not end up deriving Debug/Hash because its `mBlah` field cannot derive + Debug/Hash because the instantiation's definition cannot derive Debug/Hash.*/ #[repr(C)] pub struct ContainsOpaqueTemplate { pub mBlah: [u32; 101usize], @@ -19,38 +13,27 @@ pub struct ContainsOpaqueTemplate { } #[test] fn bindgen_test_layout_ContainsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 408usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)) + "Size of ContainsOpaqueTemplate", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) + "Alignment of ContainsOpaqueTemplate", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) + "Offset of field: ContainsOpaqueTemplate::mBlah", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 404usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) + "Offset of field: ContainsOpaqueTemplate::mBaz", ); } impl Default for ContainsOpaqueTemplate { @@ -67,8 +50,8 @@ impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { &self.mBlah[..] == &other.mBlah[..] && self.mBaz == other.mBaz } } -/// This should not end up deriving Debug/Hash either, for similar reasons, although -/// we're exercising base member edges now. +/** This should not end up deriving Debug/Hash either, for similar reasons, although + we're exercising base member edges now.*/ #[repr(C)] pub struct InheritsOpaqueTemplate { pub _base: [u8; 401usize], @@ -76,28 +59,22 @@ pub struct InheritsOpaqueTemplate { } #[test] fn bindgen_test_layout_InheritsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 416usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) + "Size of InheritsOpaqueTemplate", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) + "Alignment of InheritsOpaqueTemplate", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 408usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) + "Offset of field: InheritsOpaqueTemplate::wow", ); } impl Default for InheritsOpaqueTemplate { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 3575216cb006539b3fbc082947c3ac1d7ebe770d..58644e053d798ae8ca48a65573d997b3744b7521 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -15,9 +9,8 @@ pub mod root { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub member: T, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Template { fn default() -> Self { @@ -33,101 +26,40 @@ pub mod root { pub struct Foo { pub c: ::std::os::raw::c_char, } - #[test] - fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(c) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Foo::c"][::std::mem::offset_of!(Foo, c) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub i: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(i) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::i"][::std::mem::offset_of!(Bar, i) - 0usize]; + }; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsInstantiation { pub not_opaque: root::zoidberg::Template, } - #[test] - fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of ContainsInstantiation", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ContainsInstantiation", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsInstantiation::not_opaque", + ][::std::mem::offset_of!(ContainsInstantiation, not_opaque) - 0usize]; + }; impl Default for ContainsInstantiation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -142,57 +74,28 @@ pub mod root { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } - #[test] - fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(ContainsOpaqueInstantiation) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); - } - } - #[test] - fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>( - ), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(root::zoidberg::Template) - ) - ); - assert_eq!( - ::std::mem::align_of::>( - ), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::zoidberg::Template) - ) - ); + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of ContainsOpaqueInstantiation", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ContainsOpaqueInstantiation", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueInstantiation::opaque", + ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; + }; } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of template specialization: Template_open0_Foo_close0", + ][::std::mem::size_of::>() + - 1usize]; + [ + "Align of template specialization: Template_open0_Foo_close0", + ][::std::mem::align_of::>() + - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index 910c616fd81733ee8577c87653ae3ace90152fd9..ab68c21856da0eab8e825bf2075c58423fc6d9e5 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for Template { fn default() -> Self { @@ -25,34 +19,18 @@ impl Default for Template { pub struct ContainsInstantiation { pub not_opaque: Template<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContainsInstantiation", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ContainsInstantiation", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsInstantiation::not_opaque", + ][::std::mem::offset_of!(ContainsInstantiation, not_opaque) - 0usize]; +}; impl Default for ContainsInstantiation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -67,48 +45,24 @@ impl Default for ContainsInstantiation { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } -#[test] -fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); -} -#[test] -fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(Template<::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(Template<::std::os::raw::c_char>) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContainsOpaqueInstantiation", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ContainsOpaqueInstantiation", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueInstantiation::opaque", + ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Template_open0_char_close0", + ][::std::mem::size_of::>() - 1usize]; + [ + "Align of template specialization: Template_open0_char_close0", + ][::std::mem::align_of::>() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index 98c5417138eab1b84b0d36da9a3d2c4fae9ad911..c181dc90d697ba2a36ae6577aea495b1713f46a4 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooP9Container"] pub fn foo(c: *mut Container); @@ -15,16 +9,8 @@ extern "C" { pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } -#[test] -fn bindgen_test_layout_Container() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Container)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Container)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Container"][::std::mem::size_of::() - 8usize]; + ["Alignment of Container"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs index 0d13b12106ce66b94c0fb70ab7577581c53e0302..b651cd3354397a1dcb2c0724d7572ac0b52d90a7 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[repr(align(4))] @@ -12,49 +6,21 @@ pub struct opaque { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_opaque() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(opaque)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(opaque)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of opaque"][::std::mem::size_of::() - 4usize]; + ["Alignment of opaque"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub contained: opaque, } -#[test] -fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(contained) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of container"][::std::mem::size_of::() - 4usize]; + ["Alignment of container"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: container::contained", + ][::std::mem::offset_of!(container, contained) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs index 13b8cc366c14d3927fb9c265550473b5c82363cd..ec519d9c6b91e91f2423240bd64b0d0d072e8c97 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[repr(align(4))] @@ -12,19 +6,11 @@ pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_OtherOpaque() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(OtherOpaque)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OtherOpaque)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of OtherOpaque"][::std::mem::size_of::() - 4usize]; + ["Alignment of OtherOpaque"][::std::mem::align_of::() - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -38,54 +24,20 @@ pub struct WithOpaquePtr { pub other: u32, pub t: OtherOpaque, } -#[test] -fn bindgen_test_layout_WithOpaquePtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(WithOpaquePtr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithOpaquePtr)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(whatever) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(other) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(t) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithOpaquePtr"][::std::mem::size_of::() - 16usize]; + ["Alignment of WithOpaquePtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: WithOpaquePtr::whatever", + ][::std::mem::offset_of!(WithOpaquePtr, whatever) - 0usize]; + [ + "Offset of field: WithOpaquePtr::other", + ][::std::mem::offset_of!(WithOpaquePtr, other) - 8usize]; + [ + "Offset of field: WithOpaquePtr::t", + ][::std::mem::offset_of!(WithOpaquePtr, t) - 12usize]; +}; impl Default for WithOpaquePtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/opaque_typedef.rs b/bindgen-tests/tests/expectations/tests/opaque_typedef.rs index c61a294cf693745855b6e93d68379c57f1fd763d..90c3b709e3f76527d93e6093d3871b5c81902577 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RandomTemplate { diff --git a/bindgen-tests/tests/expectations/tests/operator.rs b/bindgen-tests/tests/expectations/tests/operator.rs index 5128226dd80f830a99c0de616c2faac5bac35178..fa018724fc46304b1bc3564c82606a9046c59f84 100644 --- a/bindgen-tests/tests/expectations/tests/operator.rs +++ b/bindgen-tests/tests/expectations/tests/operator.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z20operator_informationv"] pub fn operator_information() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/ord-enum.rs b/bindgen-tests/tests/expectations/tests/ord-enum.rs index a72fef8df6c622e4752c78f65ea017d005bd4686..aa2e67ab912de5ddc747e12172390f52b6968b31 100644 --- a/bindgen-tests/tests/expectations/tests/ord-enum.rs +++ b/bindgen-tests/tests/expectations/tests/ord-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum A { diff --git a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs index 94e166addb475354fc9be685f8248c547f160ee6..2c67ba6903ca7712b4e97a91c44f993fb1480ce0 100644 --- a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs +++ b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/overloading.rs b/bindgen-tests/tests/expectations/tests/overloading.rs index b43432eb0d047d4fe2fade24fd74c41f2e1811be..3e8fced8e7d9cbf9f26afb39f566fc0044c29fdb 100644 --- a/bindgen-tests/tests/expectations/tests/overloading.rs +++ b/bindgen-tests/tests/expectations/tests/overloading.rs @@ -1,20 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z8Evaluatec"] pub fn Evaluate(r: ::std::os::raw::c_char) -> bool; } extern "C" { #[link_name = "\u{1}_Z8Evaluateii"] - pub fn Evaluate1( - x: ::std::os::raw::c_int, - y: ::std::os::raw::c_int, - ) -> bool; + pub fn Evaluate1(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> bool; } extern "C" { #[link_name = "\u{1}_ZN3foo10MyFunctionEv"] diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index f90edb930bf22f238fd64a64ebf6fbe2b80d04a6..852126ecfcea02f8340b9fea6dea0f504c981fdc 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -97,25 +89,15 @@ pub struct Date { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } -#[test] -fn bindgen_test_layout_Date() { - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(Date)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Date)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Date"][::std::mem::size_of::() - 3usize]; + ["Alignment of Date"][::std::mem::align_of::() - 1usize]; +}; impl Date { #[inline] pub fn day(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 5u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 5u8) as u8) } } #[inline] pub fn set_day(&mut self, val: ::std::os::raw::c_uchar) { @@ -126,9 +108,7 @@ impl Date { } #[inline] pub fn month(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 4u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 4u8) as u8) } } #[inline] pub fn set_month(&mut self, val: ::std::os::raw::c_uchar) { @@ -139,9 +119,7 @@ impl Date { } #[inline] pub fn year(&self) -> ::std::os::raw::c_short { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 15u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 15u8) as u16) } } #[inline] pub fn set_year(&mut self, val: ::std::os::raw::c_short) { @@ -156,20 +134,34 @@ impl Date { month: ::std::os::raw::c_uchar, year: ::std::os::raw::c_short, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 5u8, { - let day: u8 = unsafe { ::std::mem::transmute(day) }; - day as u64 - }); - __bindgen_bitfield_unit.set(5usize, 4u8, { - let month: u8 = unsafe { ::std::mem::transmute(month) }; - month as u64 - }); - __bindgen_bitfield_unit.set(9usize, 15u8, { - let year: u16 = unsafe { ::std::mem::transmute(year) }; - year as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 5u8, + { + let day: u8 = unsafe { ::std::mem::transmute(day) }; + day as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 4u8, + { + let month: u8 = unsafe { ::std::mem::transmute(month) }; + month as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 15u8, + { + let year: u16 = unsafe { ::std::mem::transmute(year) }; + year as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs index b171b1da70ffdcbf3a36a5420a6793059444d933..162a1bebed3e53d247d8696662405f4c0c2ba78b 100644 --- a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Packed { @@ -13,39 +7,12 @@ pub struct Packed { pub c: ::std::os::raw::c_char, pub d: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Packed() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(Packed)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Packed)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Packed"][::std::mem::size_of::() - 10usize]; + ["Alignment of Packed"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Packed::a"][::std::mem::offset_of!(Packed, a) - 0usize]; + ["Offset of field: Packed::b"][::std::mem::offset_of!(Packed, b) - 2usize]; + ["Offset of field: Packed::c"][::std::mem::offset_of!(Packed, c) - 4usize]; + ["Offset of field: Packed::d"][::std::mem::offset_of!(Packed, d) - 6usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs index 71688151f57119dce107511fa663d8d5760c9338..362017a233c585bed0dcd10cb9cca2341fa124b5 100644 --- a/bindgen-tests/tests/expectations/tests/packed-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/packed-vtable.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - #[repr(C)] pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); #[repr(C, packed)] @@ -14,15 +8,11 @@ pub struct PackedVtable { } #[test] fn bindgen_test_layout_PackedVtable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedVtable)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedVtable"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(PackedVtable)) + "Alignment of PackedVtable", ); } impl Default for PackedVtable { diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 9f7dd20ad95eee20fb74e5a98c9a4d0bd8de4101..9c4f2f4e254b4ceadae14cd7cc9ce82a49f5347b 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Struct { pub _address: u8, } -#[test] -fn bindgen_test_layout_Struct() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 1usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN6Struct8FunctionER5Union"] pub fn Struct_Function(this: *mut Struct, arg1: *mut Union); diff --git a/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs index 8ead5b8a60c6cd0c6e2d29c3f90ccb0bd3162180..98c10d7ec5ba2fad78919472aa2e681ed6024ed3 100644 --- a/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs +++ b/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RENAMED_MyVal: _bindgen_ty_1 = 0; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs new file mode 100644 index 0000000000000000000000000000000000000000..e7c9a38d7f87e9b0e621cd0fd4a87c37f33278e9 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Base { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Derived { + pub b: bool, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Usage { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_ZN5Usage13static_memberE"] + pub static mut Usage_static_member: [u32; 2usize]; +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Usage"][::std::mem::size_of::() - 1usize]; + ["Alignment of Usage"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/pointer-attr.rs b/bindgen-tests/tests/expectations/tests/pointer-attr.rs index 95fe9c5f0db41abbffdbbfbc87e18efd84d604d2..edb29dc4993dd58303d02e5d8d2f564354c80146 100644 --- a/bindgen-tests/tests/expectations/tests/pointer-attr.rs +++ b/bindgen-tests/tests/expectations/tests/pointer-attr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn a(arg1: *const ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs new file mode 100644 index 0000000000000000000000000000000000000000..e81a3b667da554c4bc40ddb9b5ffe4eab8ae8b46 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs @@ -0,0 +1,5 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + #[link_name = "\u{1}foo_bar"] + pub fn bar() -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs new file mode 100644 index 0000000000000000000000000000000000000000..bf53473d88fdc746fc0db4a22c9df37fc858a272 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs @@ -0,0 +1,5 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + #[link_name = "\u{1}foo_foo"] + pub fn baz_foo() -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs index b2b094443b9c66789c57b148baa25dcf852f49d8..ff49d684f163637dd55a218db1514e385f0b1f2c 100644 --- a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl AVCodecID { pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; } diff --git a/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs b/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs index 31db41444cf6e137a42b5b328cd1cd6a196ebce7..b4201a8cd958fd63857cd3df1f79bbf8bdaed506 100644 --- a/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs +++ b/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO_BAR: foo = 0; pub const FOO_BAZ: foo = 1; pub type foo = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs index ab57d37f3be572d41f335bcaaf8267d056c207a7..bf1e853e6aff63c3177444bec84f621a96d3ffe9 100644 --- a/bindgen-tests/tests/expectations/tests/private.rs +++ b/bindgen-tests/tests/expectations/tests/private.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasPrivate { @@ -12,46 +6,17 @@ pub struct HasPrivate { ///
mIsPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_HasPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(HasPrivate)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(HasPrivate)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mIsPrivate) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of HasPrivate"][::std::mem::size_of::() - 8usize]; + ["Alignment of HasPrivate"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: HasPrivate::mNotPrivate", + ][::std::mem::offset_of!(HasPrivate, mNotPrivate) - 0usize]; + [ + "Offset of field: HasPrivate::mIsPrivate", + ][::std::mem::offset_of!(HasPrivate, mIsPrivate) - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -59,46 +24,17 @@ pub struct VeryPrivate { mIsPrivate: ::std::os::raw::c_int, mIsAlsoPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_VeryPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VeryPrivate)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(VeryPrivate)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsPrivate) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsAlsoPrivate) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of VeryPrivate"][::std::mem::size_of::() - 8usize]; + ["Alignment of VeryPrivate"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: VeryPrivate::mIsPrivate", + ][::std::mem::offset_of!(VeryPrivate, mIsPrivate) - 0usize]; + [ + "Offset of field: VeryPrivate::mIsAlsoPrivate", + ][::std::mem::offset_of!(VeryPrivate, mIsAlsoPrivate) - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -107,43 +43,16 @@ pub struct ContradictPrivate { pub mNotPrivate: ::std::os::raw::c_int, mIsPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContradictPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ContradictPrivate)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContradictPrivate)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mIsPrivate) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ContradictPrivate"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ContradictPrivate", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContradictPrivate::mNotPrivate", + ][::std::mem::offset_of!(ContradictPrivate, mNotPrivate) - 0usize]; + [ + "Offset of field: ContradictPrivate::mIsPrivate", + ][::std::mem::offset_of!(ContradictPrivate, mIsPrivate) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 8db332a5f30c529488fe36e41d7e4ff5648c07ec..5a7bee9508502e770c54f4e97de1c5f7e37670df 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -97,42 +89,13 @@ pub struct PubPriv { pub x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PubPriv() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PubPriv)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PubPriv)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(y) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PubPriv"][::std::mem::size_of::() - 8usize]; + ["Alignment of PubPriv"][::std::mem::align_of::() - 4usize]; + ["Offset of field: PubPriv::x"][::std::mem::offset_of!(PubPriv, x) - 0usize]; + ["Offset of field: PubPriv::y"][::std::mem::offset_of!(PubPriv, y) - 4usize]; +}; #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] @@ -141,25 +104,17 @@ pub struct PrivateBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_PrivateBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PrivateBitFields)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PrivateBitFields)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PrivateBitFields"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of PrivateBitFields", + ][::std::mem::align_of::() - 4usize]; +}; impl PrivateBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -170,9 +125,7 @@ impl PrivateBitFields { } #[inline] fn b(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] fn set_b(&mut self, val: ::std::os::raw::c_uint) { @@ -186,16 +139,25 @@ impl PrivateBitFields { a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } @@ -207,25 +169,15 @@ pub struct PublicBitFields { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_PublicBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PublicBitFields)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PublicBitFields)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PublicBitFields"][::std::mem::size_of::() - 4usize]; + ["Alignment of PublicBitFields"][::std::mem::align_of::() - 4usize]; +}; impl PublicBitFields { #[inline] pub fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -236,9 +188,7 @@ impl PublicBitFields { } #[inline] pub fn b(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_uint) { @@ -252,16 +202,25 @@ impl PublicBitFields { a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } @@ -273,25 +232,15 @@ pub struct MixedBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_MixedBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(MixedBitFields)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(MixedBitFields)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of MixedBitFields"][::std::mem::size_of::() - 4usize]; + ["Alignment of MixedBitFields"][::std::mem::align_of::() - 4usize]; +}; impl MixedBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -302,9 +251,7 @@ impl MixedBitFields { } #[inline] pub fn d(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_uint) { @@ -318,16 +265,25 @@ impl MixedBitFields { a: ::std::os::raw::c_uint, d: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let d: u32 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let d: u32 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); __bindgen_bitfield_unit } } @@ -336,68 +292,36 @@ impl MixedBitFields { pub struct Base { pub member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Base"][::std::mem::size_of::() - 4usize]; + ["Alignment of Base"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Base::member"][::std::mem::offset_of!(Base, member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InheritsPrivately { _base: Base, } -#[test] -fn bindgen_test_layout_InheritsPrivately() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPrivately)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(InheritsPrivately)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of InheritsPrivately"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of InheritsPrivately", + ][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InheritsPublically { pub _base: Base, } -#[test] -fn bindgen_test_layout_InheritsPublically() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPublically)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(InheritsPublically)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of InheritsPublically"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of InheritsPublically", + ][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithAnonStruct { @@ -409,76 +333,40 @@ pub struct WithAnonStruct { pub struct WithAnonStruct__bindgen_ty_1 { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_1), - "::", - stringify!(a) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of WithAnonStruct__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithAnonStruct__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithAnonStruct__bindgen_ty_1::a", + ][::std::mem::offset_of!(WithAnonStruct__bindgen_ty_1, a) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithAnonStruct__bindgen_ty_2 { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_2), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_WithAnonStruct() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithAnonStruct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of WithAnonStruct__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithAnonStruct__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithAnonStruct__bindgen_ty_2::b", + ][::std::mem::offset_of!(WithAnonStruct__bindgen_ty_2, b) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithAnonStruct"][::std::mem::size_of::() - 8usize]; + ["Alignment of WithAnonStruct"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub struct WithAnonUnion { @@ -489,19 +377,15 @@ pub struct WithAnonUnion { pub union WithAnonUnion__bindgen_ty_1 { pub _address: u8, } -#[test] -fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of WithAnonUnion__bindgen_ty_1", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of WithAnonUnion__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; +}; impl Default for WithAnonUnion__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -511,19 +395,11 @@ impl Default for WithAnonUnion__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_WithAnonUnion() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(WithAnonUnion)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithAnonUnion"][::std::mem::size_of::() - 1usize]; + ["Alignment of WithAnonUnion"][::std::mem::align_of::() - 1usize]; +}; impl Default for WithAnonUnion { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -533,3 +409,97 @@ impl Default for WithAnonUnion { } } } +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Override { + pub a: ::std::os::raw::c_uint, + ///
+ b: ::std::os::raw::c_uint, + private_c: ::std::os::raw::c_uint, + pub _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, + pub __bindgen_padding_0: u16, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Override"][::std::mem::size_of::() - 16usize]; + ["Alignment of Override"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Override::a"][::std::mem::offset_of!(Override, a) - 0usize]; + ["Offset of field: Override::b"][::std::mem::offset_of!(Override, b) - 4usize]; + [ + "Offset of field: Override::private_c", + ][::std::mem::offset_of!(Override, private_c) - 8usize]; +}; +impl Override { + #[inline] + pub fn bf_a(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } + } + #[inline] + pub fn set_bf_a(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + fn bf_b(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } + } + #[inline] + fn set_bf_b(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + fn private_bf_c(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } + } + #[inline] + fn set_private_bf_c(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(8usize, 4u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + bf_a: ::std::os::raw::c_uint, + bf_b: ::std::os::raw::c_uint, + private_bf_c: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let bf_a: u32 = unsafe { ::std::mem::transmute(bf_a) }; + bf_a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let bf_b: u32 = unsafe { ::std::mem::transmute(bf_b) }; + bf_b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let private_bf_c: u32 = unsafe { + ::std::mem::transmute(private_bf_c) + }; + private_bf_c as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs new file mode 100644 index 0000000000000000000000000000000000000000..f4f3ab4294907a42b3d279d2ddabc71cdb1d5e90 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEST_STRUCT { + pub ptr_32bit: u32, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of TEST_STRUCT"][::std::mem::size_of::() - 4usize]; + ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: TEST_STRUCT::ptr_32bit", + ][::std::mem::offset_of!(TEST_STRUCT, ptr_32bit) - 0usize]; +}; +impl Default for TEST_STRUCT { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index 979dd4b56408f7107b677bb388c3b7162ed6fff3..c271125097a4ccae922595d732887bdddd74fd02 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct cv_Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_cv_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cv_Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of cv_Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN2cv3FooD1Ev"] pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); @@ -38,16 +24,8 @@ impl cv_Foo { pub struct cv_Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_cv_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cv_Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of cv_Bar"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs b/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs index f1b2c8459c914d1a51c2b3bd0dbffc857819adff..9bbbddd88dd56674ac6cf90e88bf6436ab83fd37 100644 --- a/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs +++ b/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/redeclaration.rs b/bindgen-tests/tests/expectations/tests/redeclaration.rs index 8a4ff6578ec13967c667772a6ec05c6fa47dc766..05b7aecd3ee787862df1317088278d6d7fa99704 100644 --- a/bindgen-tests/tests/expectations/tests/redeclaration.rs +++ b/bindgen-tests/tests/expectations/tests/redeclaration.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs new file mode 100644 index 0000000000000000000000000000000000000000..6e7db24870464ffacd8a5c4162226fcfd4989420 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -0,0 +1,263 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), + ); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_packed { + pub a: u32, + pub b: u32, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of redundant_packed"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of redundant_packed", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: redundant_packed::a", + ][::std::mem::offset_of!(redundant_packed, a) - 0usize]; + [ + "Offset of field: redundant_packed::b", + ][::std::mem::offset_of!(redundant_packed, b) - 4usize]; +}; +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_packed_bitfield { + pub a: [u8; 3usize], + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub c: u32, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of redundant_packed_bitfield", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of redundant_packed_bitfield", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: redundant_packed_bitfield::a", + ][::std::mem::offset_of!(redundant_packed_bitfield, a) - 0usize]; + [ + "Offset of field: redundant_packed_bitfield::c", + ][::std::mem::offset_of!(redundant_packed_bitfield, c) - 4usize]; +}; +impl redundant_packed_bitfield { + #[inline] + pub fn b0(&self) -> u8 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_b0(&mut self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn b1(&self) -> u8 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } + } + #[inline] + pub fn set_b1(&mut self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1(b0: u8, b1: u8) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b0: u8 = unsafe { ::std::mem::transmute(b0) }; + b0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b1: u8 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(16))] +#[derive(Copy, Clone)] +pub union redundant_packed_union { + pub a: u64, + pub b: u32, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of redundant_packed_union", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of redundant_packed_union", + ][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: redundant_packed_union::a", + ][::std::mem::offset_of!(redundant_packed_union, a) - 0usize]; + [ + "Offset of field: redundant_packed_union::b", + ][::std::mem::offset_of!(redundant_packed_union, b) - 0usize]; +}; +impl Default for redundant_packed_union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[repr(align(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct inner { + pub a: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of inner"][::std::mem::size_of::() - 2usize]; + ["Alignment of inner"][::std::mem::align_of::() - 2usize]; + ["Offset of field: inner::a"][::std::mem::offset_of!(inner, a) - 0usize]; +}; +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct outer_redundant_packed { + pub a: [inner; 2usize], + pub b: u32, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of outer_redundant_packed", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of outer_redundant_packed", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: outer_redundant_packed::a", + ][::std::mem::offset_of!(outer_redundant_packed, a) - 0usize]; + [ + "Offset of field: outer_redundant_packed::b", + ][::std::mem::offset_of!(outer_redundant_packed, b) - 4usize]; +}; +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_pragma_packed { + pub a: u8, + pub b: u16, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of redundant_pragma_packed", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of redundant_pragma_packed", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: redundant_pragma_packed::a", + ][::std::mem::offset_of!(redundant_pragma_packed, a) - 0usize]; + [ + "Offset of field: redundant_pragma_packed::b", + ][::std::mem::offset_of!(redundant_pragma_packed, b) - 2usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index 00a8e0ee3567e262c98af9f36d8cd4f37ba1ed8c..de5f81c3c01b5c9f2b24abf64be3f0db930894ad 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NSID_LENGTH: u32 = 10; #[repr(C)] pub struct nsID__bindgen_vtable { @@ -18,19 +12,11 @@ pub struct nsID__bindgen_vtable { pub struct nsID { pub vtable_: *const nsID__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsID() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsID)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsID)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsID"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsID"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsID { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs index d9d13c1a9d4a4e352843e827c45d4f5ff845ae38..9b2cc33ce99cf0b8a1302247ebce4ad69c36b719 100644 --- a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs +++ b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -18,34 +12,12 @@ pub mod root { pub struct Bar { pub bazz: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bazz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::bazz"][::std::mem::offset_of!(Bar, bazz) - 0usize]; + }; } pub type ReferencesBar = root::foo::Bar; } diff --git a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs index 4f464129feefba667278b0cb8fbf41ab6dbc0a39..2efa164ddfad3960036a530cfbabb22dd34dfb73 100644 --- a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs @@ -1,19 +1,13 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** But the replacement type does use T! -/// But the replacement type does use T! -/// -///
+
*/ pub type JS_detail_MaybeWrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_Rooted { - pub ptr: JS_detail_MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: JS_detail_MaybeWrapped, } impl Default for JS_Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs index d4228e126e41a5415a2de409cfadf47782ec2792..ebf9657176116d4230b4ca6a6acaab9b4cc108e4 100644 --- a/bindgen-tests/tests/expectations/tests/replace_use.rs +++ b/bindgen-tests/tests/expectations/tests/replace_use.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -16,40 +10,18 @@ pub struct nsTArray { pub struct Test { pub a: nsTArray, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) - ); -} -#[test] -fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 4usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::a"][::std::mem::offset_of!(Test, a) - 0usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: nsTArray_open0_long_close0", + ][::std::mem::size_of::() - 4usize]; + [ + "Align of template specialization: nsTArray_open0_long_close0", + ][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/replaces_double.rs b/bindgen-tests/tests/expectations/tests/replaces_double.rs index 99de1320907fbda70009456a38df3f09b4cfbf86..e764113f219cbc4089a3eec4521016dc60b51554 100644 --- a/bindgen-tests/tests/expectations/tests/replaces_double.rs +++ b/bindgen-tests/tests/expectations/tests/replaces_double.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Wrapper_Wrapped { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Wrapper_Wrapped { fn default() -> Self { @@ -24,8 +18,8 @@ pub type Wrapper_Type = Wrapper_Wrapped; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub ptr: Rooted_MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: Rooted_MaybeWrapped, } ///
pub type Rooted_MaybeWrapped = T; diff --git a/bindgen-tests/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs index c6fee20dbc58abf22e81b644df296403e0bcda10..6afc0ba85952dcd3a4d5238595d09801bbcf5943 100644 --- a/bindgen-tests/tests/expectations/tests/repr-align.rs +++ b/bindgen-tests/tests/expectations/tests/repr-align.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -15,28 +9,19 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of a"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of a"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + "Offset of field: a::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + "Offset of field: a::c", ); } #[repr(C)] @@ -48,27 +33,18 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(b)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of b"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of b"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) + "Offset of field: b::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) + "Offset of field: b::c", ); } diff --git a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs index 797976798fad1525e521780d54d6749b64921045..8fe7eb7da28e7031e6be826d84c88c401162eba3 100644 --- a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs +++ b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type FuncType = ::std::option::Option; extern "C" { pub fn Func(); diff --git a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 8002476197fe1c36d46690e427861e6d8b1f6d32..e6e4088abfae7625adfbadab73c6fa7c57a07989 100644 --- a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_Zone { @@ -16,39 +10,14 @@ pub struct JS_shadow_Zone { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_JS_shadow_Zone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(JS_shadow_Zone)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(JS_shadow_Zone)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(y) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of JS_shadow_Zone"][::std::mem::size_of::() - 8usize]; + ["Alignment of JS_shadow_Zone"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: JS_shadow_Zone::x", + ][::std::mem::offset_of!(JS_shadow_Zone, x) - 0usize]; + [ + "Offset of field: JS_shadow_Zone::y", + ][::std::mem::offset_of!(JS_shadow_Zone, y) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs index 48f8ca8133ded966e8a7d1b5cf6ac9d4d7fe49f1..0fe153e700c923d8bade1f91cdeb163cfef0f9e2 100644 --- a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -27,89 +21,47 @@ pub mod root { pub struct sentry { pub i_am_plain_sentry: bool, } - #[test] - fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(sentry)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(sentry)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_plain_sentry) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of sentry"][::std::mem::size_of::() - 1usize]; + ["Alignment of sentry"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: sentry::i_am_plain_sentry", + ][::std::mem::offset_of!(sentry, i_am_plain_sentry) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper { pub _address: u8, } - #[test] - fn bindgen_test_layout_NotTemplateWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of NotTemplateWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of NotTemplateWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper_sentry { pub i_am_not_template_wrapper_sentry: ::std::os::raw::c_char, } - #[test] - fn bindgen_test_layout_NotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper_sentry)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!( - (*ptr).i_am_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotTemplateWrapper_sentry), - "::", - stringify!(i_am_not_template_wrapper_sentry) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of NotTemplateWrapper_sentry", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of NotTemplateWrapper_sentry", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: NotTemplateWrapper_sentry::i_am_not_template_wrapper_sentry", + ][::std::mem::offset_of!( + NotTemplateWrapper_sentry, i_am_not_template_wrapper_sentry + ) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InlineNotTemplateWrapper { @@ -120,57 +72,29 @@ pub mod root { pub struct InlineNotTemplateWrapper_sentry { pub i_am_inline_not_template_wrapper_sentry: bool, } - #[test] - fn bindgen_test_layout_InlineNotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit< - InlineNotTemplateWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of: ", - stringify!(InlineNotTemplateWrapper_sentry) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(InlineNotTemplateWrapper_sentry) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!( - (*ptr).i_am_inline_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), - "::", - stringify!(i_am_inline_not_template_wrapper_sentry) - ) - ); - } - #[test] - fn bindgen_test_layout_InlineNotTemplateWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InlineNotTemplateWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of InlineNotTemplateWrapper_sentry", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of InlineNotTemplateWrapper_sentry", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: InlineNotTemplateWrapper_sentry::i_am_inline_not_template_wrapper_sentry", + ][::std::mem::offset_of!( + InlineNotTemplateWrapper_sentry, i_am_inline_not_template_wrapper_sentry + ) - 0usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of InlineNotTemplateWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of InlineNotTemplateWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InlineTemplateWrapper { @@ -191,84 +115,45 @@ pub mod root { pub struct OuterDoubleWrapper_InnerDoubleWrapper { pub _address: u8, } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper) - ) - ); - } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(OuterDoubleWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(OuterDoubleWrapper)) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleWrapper_InnerDoubleWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleWrapper_InnerDoubleWrapper", + ][::std::mem::align_of::() - 1usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleWrapper_InnerDoubleWrapper_sentry { pub i_am_double_wrapper_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >(), - 4usize, - concat!( - "Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) - ) - ); - assert_eq!( - ::std::mem::align_of::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - "::", - stringify!(i_am_double_wrapper_sentry) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleWrapper_InnerDoubleWrapper_sentry", + ][::std::mem::size_of::() + - 4usize]; + [ + "Alignment of OuterDoubleWrapper_InnerDoubleWrapper_sentry", + ][::std::mem::align_of::() + - 4usize]; + [ + "Offset of field: OuterDoubleWrapper_InnerDoubleWrapper_sentry::i_am_double_wrapper_sentry", + ][::std::mem::offset_of!( + OuterDoubleWrapper_InnerDoubleWrapper_sentry, i_am_double_wrapper_sentry + ) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleInlineWrapper { @@ -284,58 +169,45 @@ pub mod root { pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry { pub i_am_double_wrapper_inline_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry( - ) { - const UNINIT: ::std::mem::MaybeUninit< + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry", + ][::std::mem::size_of::< OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); - } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( - ) { - assert_eq!( - ::std::mem::size_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Size of: ", - stringify!( - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper - ) - ) - ); - assert_eq!( - ::std::mem::align_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Alignment of ", - stringify!( - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper - ) - ) - ); - } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(OuterDoubleInlineWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)) - ); - } + >() - 4usize]; + [ + "Alignment of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry", + ][::std::mem::align_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + >() - 4usize]; + [ + "Offset of field: OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry::i_am_double_wrapper_inline_sentry", + ][::std::mem::offset_of!( + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + i_am_double_wrapper_inline_sentry + ) - 0usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper", + ][::std::mem::size_of::() + - 1usize]; + [ + "Alignment of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper", + ][::std::mem::align_of::() + - 1usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [ + "Size of OuterDoubleInlineWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleInlineWrapper", + ][::std::mem::align_of::() - 1usize]; + }; } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -352,34 +224,12 @@ pub mod root { pub struct sentry { pub i_am_outside_namespace_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(sentry)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(sentry)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_outside_namespace_sentry) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of sentry"][::std::mem::size_of::() - 4usize]; + ["Alignment of sentry"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: sentry::i_am_outside_namespace_sentry", + ][::std::mem::offset_of!(sentry, i_am_outside_namespace_sentry) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/short-enums.rs b/bindgen-tests/tests/expectations/tests/short-enums.rs index a8a494eaa63e8a3ee725785e50a5a315f6188d90..493bb5b419a9b8d0fef81d1a949495a5c783650c 100644 --- a/bindgen-tests/tests/expectations/tests/short-enums.rs +++ b/bindgen-tests/tests/expectations/tests/short-enums.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum one_byte_t { diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 1aa8b9acae52fc59b6efbc93ab8d22f2444b133c..e422131ca72dc65c28af0b796af3dfa93ffa739d 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -1,33 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub arr: [u32; 3usize], } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 12usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::arr"][::std::mem::offset_of!(C, arr) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index e04e3b6090298588cbb47e871b472b3ae31461af..5f1505bd86921b12231eef6696ccdaa44bc6e47f 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { pub type number = ::std::os::raw::c_int; @@ -20,79 +14,21 @@ pub mod root { pub a: root::number, pub b: root::number, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; + }; pub const NUMBER: root::number = 42; - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(y) - ) - ); - } - #[test] - fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(b) - ) - ); - } pub mod ns { pub type number = ::std::os::raw::c_int; #[repr(C)] @@ -107,87 +43,21 @@ pub mod root { pub a: root::ns::number, pub b: root::ns::number, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; + }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; + }; pub const NUMBER: root::ns::number = 42; - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(y) - ) - ); - } - #[test] - fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(b) - ) - ); - } #[allow(unused_imports)] use self::super::super::root; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index a52db49691d36554e2cd76241669dbbfd71afb5a..8594727dfa59d3cd1915ee6a22bd71eb3b1c1373 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn fun() -> u64; } @@ -13,29 +7,9 @@ extern "C" { pub struct Struct { pub field: u64, } -#[test] -fn bindgen_test_layout_Struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Struct), - "::", - stringify!(field) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 8usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Struct::field"][::std::mem::offset_of!(Struct, field) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/strings_array.rs b/bindgen-tests/tests/expectations/tests/strings_array.rs new file mode 100644 index 0000000000000000000000000000000000000000..6f352b32caf16a0233dbf69e7dabc7cfda74319e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_array.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const MY_STRING_UTF8: &'static [u8; 14] = b"Hello, world!\0"; +pub const MY_STRING_INTERIOR_NULL: &'static [u8; 7] = b"Hello,\0"; +pub const MY_STRING_NON_UTF8: &'static [u8; 7] = b"ABCDE\xFF\0"; diff --git a/bindgen-tests/tests/expectations/tests/strings_cstr.rs b/bindgen-tests/tests/expectations/tests/strings_cstr.rs new file mode 100644 index 0000000000000000000000000000000000000000..ca089cf130b2695e25e2c82bad3e7d7cdbbe465d --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_cstr.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(unsafe_code)] +pub const MY_STRING_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello, world!\0") +}; +#[allow(unsafe_code)] +pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello,\0") +}; +#[allow(unsafe_code)] +pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"ABCDE\xFF\0") +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 8279fe1f7d80fbd39ffda42944c7beea655ab035..0fe9024a5f3932d1b2a9a6c9b6294a05d26cf27b 100644 --- a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -1,36 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { pub val_a: *mut b, } -#[test] -fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of a"][::std::mem::size_of::() - 8usize]; + ["Alignment of a"][::std::mem::align_of::() - 8usize]; + ["Offset of field: a::val_a"][::std::mem::offset_of!(a, val_a) - 0usize]; +}; impl Default for a { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -45,24 +24,9 @@ impl Default for a { pub struct b { pub val_b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of b"][::std::mem::size_of::() - 4usize]; + ["Alignment of b"][::std::mem::align_of::() - 4usize]; + ["Offset of field: b::val_b"][::std::mem::offset_of!(b, val_b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index f9d7fedb2572085d834b6b2717d8a2c67aaeaf2c..bc12a1bce8659bdf51804be414734de7a151522e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -1,74 +1,34 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct typedef_named_struct { pub has_name: bool, } -#[test] -fn bindgen_test_layout_typedef_named_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(typedef_named_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(typedef_named_struct)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_named_struct), - "::", - stringify!(has_name) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of typedef_named_struct", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of typedef_named_struct", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: typedef_named_struct::has_name", + ][::std::mem::offset_of!(typedef_named_struct, has_name) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct _bindgen_ty_1 { pub no_name: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(no_name) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 8usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; + [ + "Offset of field: _bindgen_ty_1::no_name", + ][::std::mem::offset_of!(_bindgen_ty_1, no_name) - 0usize]; +}; impl Default for _bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 2bad358aee87a2505c193e09e6e836a660850c1a..82f93dfd16411e901cf112cd8639e592b4756efe 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -17,34 +11,16 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_typedef_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(typedef_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(typedef_struct)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { @@ -56,45 +32,23 @@ pub mod root { use self::super::super::root; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] - pub struct _bindgen_ty_1 { + pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(foo) - ) - ); - } - pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; - pub const _bindgen_mod_id_12_BAR: - root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] - pub enum _bindgen_ty_2 { + pub enum typedef_enum { BAR = 1, } - pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; } } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs index 238400a17cfb9269cc9738b3c8f4ffbc06656900..51aa19c572c1d851059fcc79a9175aed21fb85ad 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -16,60 +10,22 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs index f3af6b60ff9340fb4af669dabd73ee07a546d0ed..930e6b9aba12a083445e9a96f24301e81f0fcfb4 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -17,107 +11,42 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 208usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_2"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_2::a", + ][::std::mem::offset_of!(foo__bindgen_ty_2, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_2::b", + ][::std::mem::offset_of!(foo__bindgen_ty_2, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 208usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; + ["Offset of field: foo::baz"][::std::mem::offset_of!(foo, baz) - 16usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 5bb10079a3aad995adcee9d5f696a0c06b86b2ca..6bdee34590816b8de89d5f6d32b025e8e708b685 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -16,63 +10,25 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs index 08aab0a94c50773027a8d0da072cd53fb4bab2e3..6520163259a60eef963e27fc631153da9a7e3bab 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -16,42 +10,19 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -61,27 +32,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 8db33d113e548c9403aafcb705e18a5d6ed82126..dda2d06eb8c4a5e82c9ef921be3a6f7aa982e34c 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -62,38 +56,27 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -103,23 +86,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 56981065288a2bde7557f1ca412f2714f7708f8a..29cf382e5fbe3a467d305b54ad8ea751b5c4e5c9 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -16,52 +10,21 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 499fc7a174864bc7e8c3e46171044be47d04a1b0..2f95e0f5e07a3e933a7cfca74ff1f8061c84f14e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -16,42 +10,19 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -61,19 +32,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 55432d47fcc65d7aa54687a039fc2622ec3b4ae0..b9977c688ba336a0c263c962e20e020b690e501e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -62,38 +56,27 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -103,16 +86,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index a9be30069e034a15c34e434ebeece12eed247137..fb214334156517185ee0e539cb49fbc1fb292f29 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,38 +92,16 @@ pub struct bitfield { pub _bitfield_align_2: [u32; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_bitfield() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bitfield)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bitfield)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bitfield), - "::", - stringify!(e) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bitfield"][::std::mem::size_of::() - 16usize]; + ["Alignment of bitfield"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bitfield::e"][::std::mem::offset_of!(bitfield, e) - 4usize]; +}; impl bitfield { #[inline] pub fn a(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_ushort) { @@ -142,9 +112,7 @@ impl bitfield { } #[inline] pub fn b(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_ushort) { @@ -155,9 +123,7 @@ impl bitfield { } #[inline] pub fn c(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_ushort) { @@ -168,9 +134,7 @@ impl bitfield { } #[inline] pub fn d(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 2u8) as u16) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) { @@ -186,31 +150,48 @@ impl bitfield { c: ::std::os::raw::c_ushort, d: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u16 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b: u16 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let c: u16 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); - __bindgen_bitfield_unit.set(6usize, 2u8, { - let d: u16 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u16 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b: u16 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let c: u16 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 2u8, + { + let d: u16 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn f(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 2u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 2u8) as u32) } } #[inline] pub fn set_f(&mut self, val: ::std::os::raw::c_uint) { @@ -221,9 +202,7 @@ impl bitfield { } #[inline] pub fn g(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(32usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(32usize, 32u8) as u32) } } #[inline] pub fn set_g(&mut self, val: ::std::os::raw::c_uint) { @@ -237,16 +216,25 @@ impl bitfield { f: ::std::os::raw::c_uint, g: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 2u8, { - let f: u32 = unsafe { ::std::mem::transmute(f) }; - f as u64 - }); - __bindgen_bitfield_unit.set(32usize, 32u8, { - let g: u32 = unsafe { ::std::mem::transmute(g) }; - g as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 2u8, + { + let f: u32 = unsafe { ::std::mem::transmute(f) }; + f as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 32u8, + { + let g: u32 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs index 1bb7c77d26894fd846506fbe6d67b00a8fdbff13..b4726660813969c1e0812eedba45cc2d15e7c6cc 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct LittleArray { @@ -12,28 +6,18 @@ pub struct LittleArray { } #[test] fn bindgen_test_layout_LittleArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(LittleArray)) - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of LittleArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(LittleArray)) + "Alignment of LittleArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(LittleArray), - "::", - stringify!(a) - ) + "Offset of field: LittleArray::a", ); } #[repr(C)] @@ -43,28 +27,14 @@ pub struct BigArray { } #[test] fn bindgen_test_layout_BigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(BigArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(BigArray)) - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of BigArray"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of BigArray"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(BigArray), - "::", - stringify!(a) - ) + "Offset of field: BigArray::a", ); } impl Default for BigArray { @@ -83,28 +53,22 @@ pub struct WithLittleArray { } #[test] fn bindgen_test_layout_WithLittleArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(WithLittleArray)) + "Size of WithLittleArray", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithLittleArray)) + "Alignment of WithLittleArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithLittleArray), - "::", - stringify!(a) - ) + "Offset of field: WithLittleArray::a", ); } #[repr(C)] @@ -114,28 +78,18 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of WithBigArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) + "Alignment of WithBigArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) + "Offset of field: WithBigArray::a", ); } impl Default for WithBigArray { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs index 9f2c0ecc2807e8eb5b5c9bafa4867e7b4bf51e71..eda7cadb46ad5790fcb61d1fc0b6c671422487b0 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct S { @@ -12,30 +6,14 @@ pub struct S { } #[test] fn bindgen_test_layout_S() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 33usize, "Size of S"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of S"); assert_eq!( - ::std::mem::size_of::(), - 33usize, - concat!("Size of: ", stringify!(S)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) + "Offset of field: S::large_array", ); } impl Default for S { @@ -49,8 +27,8 @@ impl Default for S { } #[repr(C)] pub struct ST { - pub large_array: [T; 33usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub large_array: [T; 33usize], } impl Default for ST { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs index ff177ff131cd5af140654170925b532f7c490f5d..369384e88cbfbd0c99b858b969da60f9a429bd30 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -24,42 +18,21 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, c1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, c2) - 2usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { @@ -68,88 +41,37 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d3: ::std::os::raw::c_uchar, pub d4: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) - ); -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d2) - 1usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d3", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d3) - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d4) - 3usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -159,27 +81,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index af795b64239b09fe0c35333237aa2b3dcc8f3cab..0753326174280f55aace84f284781ac7086c6d01 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -70,38 +64,27 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + "Size of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -119,58 +102,37 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + "Size of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -180,28 +142,22 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -211,23 +167,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs index b8ea17cd830ddb18e16b0109422825a8f3141c0b..2687f9750b7dcc0c860e115cbd677f1ce2071ccf 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs @@ -1,39 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, } -#[test] -fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of a"][::std::mem::size_of::() - 3usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; + ["Offset of field: a::c"][::std::mem::offset_of!(a, c) - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs index b1ee5db48bc0d3a38f9caebd745f1883bf55d7dc..40c3972600bfccf81ef6d55f613010879dfd96df 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -16,60 +10,22 @@ pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(y) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::x", + ][::std::mem::offset_of!(foo__bindgen_ty_1, x) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::y", + ][::std::mem::offset_of!(foo__bindgen_ty_1, y) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs b/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs index 49afe55906fdd55681316ae882f951c4af80af3f..2aaae12dcf63d412e4e29384fa9ea6a5a76295a3 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -1,14 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Proxy { pub _address: u8, } -pub type Proxy_foo = - ::std::option::Option; +pub type Proxy_foo = ::std::option::Option; diff --git a/bindgen-tests/tests/expectations/tests/template-fun-ty.rs b/bindgen-tests/tests/expectations/tests/template-fun-ty.rs index a7132cf04c5ce9d123bbf56a5bfc263bde6fcfaa..5337af037a47c8ef1d4460e85ebdb6142921e83f 100644 --- a/bindgen-tests/tests/expectations/tests/template-fun-ty.rs +++ b/bindgen-tests/tests/expectations/tests/template-fun-ty.rs @@ -1,17 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub _address: u8, } -pub type Foo_FunctionPtr = - ::std::option::Option T>; +pub type Foo_FunctionPtr = ::std::option::Option T>; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RefPtr { @@ -22,6 +15,7 @@ pub struct RefPtr { pub struct RefPtr_Proxy { pub _address: u8, } -pub type RefPtr_Proxy_member_function = - ::std::option::Option R>; +pub type RefPtr_Proxy_member_function = ::std::option::Option< + unsafe extern "C" fn(arg1: Args) -> R, +>; pub type Returner = ::std::option::Option T>; diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs index 2acfb06926a1a3fe9709ff3f195136b9d042ce63..ba8980be00394c9c5c4f41835895d13b7e63946b 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for UsesTemplateParameter { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs index 4fc227c9147255a88649c73e083cf62f08c6724b..7cbec9610d3f53baec0618fa2ccab0b748314305 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs index c6034fb8fea9cd1c67857a2f4b957794d4b7e25e..a4e5d0ce828f3209c776a6364c372b8fd1f3b3fc 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs @@ -1,26 +1,20 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoublyIndirectUsage { - pub doubly_indirect: DoublyIndirectUsage_IndirectUsage, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub doubly_indirect: DoublyIndirectUsage_IndirectUsage, } pub type DoublyIndirectUsage_Aliased = T; pub type DoublyIndirectUsage_Typedefed = U; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoublyIndirectUsage_IndirectUsage { - pub member: DoublyIndirectUsage_Aliased, - pub another: DoublyIndirectUsage_Typedefed, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: DoublyIndirectUsage_Aliased, + pub another: DoublyIndirectUsage_Typedefed, } impl Default for DoublyIndirectUsage_IndirectUsage { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs index 63a31e234a541ff36ba2b80a9e6c2ee92089beb5..e914375875971ae80d015c24afd00d7a3a3322a3 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs index 626e451af4392e5ed3312c57530003e094d2b7c7..7f3a306b6bd328c50205a67bc35af8ca5ae32960 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { - pub t: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: *mut T, } impl Default for BaseUsesT { fn default() -> Self { @@ -23,9 +17,9 @@ impl Default for BaseUsesT { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct CrtpUsesU { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: BaseUsesT>, pub usage: U, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for CrtpUsesU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs index 70c1778bd5fb17f24be6f58da6bd887a93b15fa2..185f16be1112ff6dd74db0d0f237389b96c0deca 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BaseIgnoresT { @@ -13,9 +7,9 @@ pub struct BaseIgnoresT { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct CrtpUsesU { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: BaseIgnoresT, pub usage: U, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for CrtpUsesU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs index 0e0fd0c9eff7fef387e38290a4edaeb862f77fbf..b008bb5b8f252829f7efc38fe828dec8b0c1d312 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BaseIgnoresT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs index 941c6073218d51e2571a70734beb40b27a3f56f7..fced6dc58c38b80139794a215d62ce3d5e26df46 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { - pub usage: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub usage: *mut T, } impl Default for BaseUsesT { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs index 0ad5d7bb69a28554e4f7bce6a2419b1455adb9ef..4c671ce2abfc936d3b4e10278d75234c87c42794 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs @@ -1,21 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter_AlsoUsesTemplateParameter { - pub also: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub also: T, } impl Default for UsesTemplateParameter_AlsoUsesTemplateParameter { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs index 414818d920cb1019c014282d9660c662159845a6..511365e6568e6cca65688b95b9e33c7ce7d339ad 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs @@ -1,27 +1,19 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { - pub also: T, - pub more: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub also: T, + pub more: U, } -impl Default - for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore -{ +impl Default for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs index afcba978dee6f5f5c52f1e9e352d1a57c9d11e62..5655a6d26083a6cf596d5cea77269e8e20327866 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs index 2cc8db6fe2d1bd3c1df75660ae829c23810ca8d7..5049559b3331165e55594d086b92804d2a3e614f 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectlyUsesTemplateParameter { - pub aliased: IndirectlyUsesTemplateParameter_Aliased, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub aliased: IndirectlyUsesTemplateParameter_Aliased, } pub type IndirectlyUsesTemplateParameter_Aliased = T; impl Default for IndirectlyUsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs index 3c0e5152647b55cfeaf78fb3eb8226a10a82a951..0a08bc9da9e741d6848f5f22677820bf58444a7d 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs index 3ed7a45dfc292a8c478a79f0ea370dc3beed6f39..1552ae852fe2eb62f97ed0d8f621adafbef6f430 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoesNotUseU { - pub t: T, - pub v: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, + pub v: V, } impl Default for DoesNotUseU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs index f8ac6714104a7e4d7bb05c8f3bcb3f500ea7ebaa..61de18a833bc8f258c6e0c6e7925e689774f09bd 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectUsage { - pub member1: IndirectUsage_Typedefed, - pub member2: IndirectUsage_Aliased, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member1: IndirectUsage_Typedefed, + pub member2: IndirectUsage_Aliased, } pub type IndirectUsage_Typedefed = T; pub type IndirectUsage_Aliased = U; diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs index a50079a2edeac436f0888d4f8515737d3318a154..ff0eedc8aea1d9c2dec56553a6debde35ea294f9 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUse { @@ -15,10 +9,10 @@ pub type DoesNotUse_Typedefed = U; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoesNotUse_IndirectUsage { - pub member: DoesNotUse_Aliased, - pub another: DoesNotUse_Typedefed, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: DoesNotUse_Aliased, + pub another: DoesNotUse_Typedefed, } impl Default for DoesNotUse_IndirectUsage { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-with-var.rs b/bindgen-tests/tests/expectations/tests/template-with-var.rs index 0476a256bf63274dda996d1858dd054bb9037bb9..cdc0b5b1492cc1e2cd765c9d4cbdc1e12c139d33 100644 --- a/bindgen-tests/tests/expectations/tests/template-with-var.rs +++ b/bindgen-tests/tests/expectations/tests/template-with-var.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TemplateWithVar { diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index 7637295a9288f49b737afd600de3c6780d4afbe4..aa2a7753e2613f1d1d91e773b6a153a7294bb05f 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct Foo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub m_member: T, pub m_member_ptr: *mut T, pub m_member_arr: [T; 1usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Foo { fn default() -> Self { @@ -25,8 +19,8 @@ impl Default for Foo { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct B { - pub m_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: T, } impl Default for B { fn default() -> Self { @@ -66,196 +60,37 @@ pub struct C { pub mArrayRef: B<*mut [::std::os::raw::c_int; 1usize]>, pub mBConstArray: B<[::std::os::raw::c_int; 1usize]>, } -#[test] -fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 104usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstPtr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtr) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtrArray) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConst) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBVolatile) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstBool) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstChar) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArray) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBPtrArray) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArrayPtr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize }, - 64usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstRef) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mPtrRef) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize - }, - 88usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mArrayRef) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstArray) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 104usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::mB"][::std::mem::offset_of!(C, mB) - 0usize]; + ["Offset of field: C::mBConstPtr"][::std::mem::offset_of!(C, mBConstPtr) - 8usize]; + [ + "Offset of field: C::mBConstStructPtr", + ][::std::mem::offset_of!(C, mBConstStructPtr) - 16usize]; + [ + "Offset of field: C::mBConstStructPtrArray", + ][::std::mem::offset_of!(C, mBConstStructPtrArray) - 24usize]; + ["Offset of field: C::mBConst"][::std::mem::offset_of!(C, mBConst) - 32usize]; + ["Offset of field: C::mBVolatile"][::std::mem::offset_of!(C, mBVolatile) - 36usize]; + [ + "Offset of field: C::mBConstBool", + ][::std::mem::offset_of!(C, mBConstBool) - 40usize]; + [ + "Offset of field: C::mBConstChar", + ][::std::mem::offset_of!(C, mBConstChar) - 42usize]; + ["Offset of field: C::mBArray"][::std::mem::offset_of!(C, mBArray) - 44usize]; + ["Offset of field: C::mBPtrArray"][::std::mem::offset_of!(C, mBPtrArray) - 48usize]; + ["Offset of field: C::mBArrayPtr"][::std::mem::offset_of!(C, mBArrayPtr) - 56usize]; + ["Offset of field: C::mBRef"][::std::mem::offset_of!(C, mBRef) - 64usize]; + ["Offset of field: C::mBConstRef"][::std::mem::offset_of!(C, mBConstRef) - 72usize]; + ["Offset of field: C::mPtrRef"][::std::mem::offset_of!(C, mPtrRef) - 80usize]; + ["Offset of field: C::mArrayRef"][::std::mem::offset_of!(C, mArrayRef) - 88usize]; + [ + "Offset of field: C::mBConstArray", + ][::std::mem::offset_of!(C, mBConstArray) - 96usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -274,9 +109,9 @@ pub type D_MyFoo = Foo<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct D_U { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub m_nested_foo: D_MyFoo, pub m_baz: Z, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for D_U { fn default() -> Self { @@ -299,10 +134,10 @@ impl Default for D { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rooted { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub prev: *mut T, pub next: *mut Rooted<*mut ::std::os::raw::c_void>, pub ptr: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Rooted { fn default() -> Self { @@ -318,32 +153,14 @@ impl Default for Rooted { pub struct RootedContainer { pub root: Rooted<*mut ::std::os::raw::c_void>, } -#[test] -fn bindgen_test_layout_RootedContainer() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(RootedContainer)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(RootedContainer)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RootedContainer), - "::", - stringify!(root) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of RootedContainer"][::std::mem::size_of::() - 24usize]; + ["Alignment of RootedContainer"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: RootedContainer::root", + ][::std::mem::offset_of!(RootedContainer, root) - 0usize]; +}; impl Default for RootedContainer { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -357,8 +174,8 @@ pub type WithDtorIntFwd = WithDtor<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct WithDtor { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for WithDtor { fn default() -> Self { @@ -374,32 +191,16 @@ impl Default for WithDtor { pub struct PODButContainsDtor { pub member: WithDtorIntFwd, } -#[test] -fn bindgen_test_layout_PODButContainsDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PODButContainsDtor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PODButContainsDtor)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PODButContainsDtor), - "::", - stringify!(member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PODButContainsDtor"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of PODButContainsDtor", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: PODButContainsDtor::member", + ][::std::mem::offset_of!(PODButContainsDtor, member) - 0usize]; +}; impl Default for PODButContainsDtor { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -420,40 +221,20 @@ pub struct Opaque { pub struct POD { pub opaque_member: u32, } -#[test] -fn bindgen_test_layout_POD() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(POD)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(POD)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(POD), - "::", - stringify!(opaque_member) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of POD"][::std::mem::size_of::() - 4usize]; + ["Alignment of POD"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: POD::opaque_member", + ][::std::mem::offset_of!(POD, opaque_member) - 0usize]; +}; ///
#[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedReplaced { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for NestedReplaced { fn default() -> Self { @@ -467,8 +248,8 @@ impl Default for NestedReplaced { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedBase { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for NestedBase { fn default() -> Self { @@ -482,10 +263,10 @@ impl Default for NestedBase { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedContainer { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub c: T, pub nested: NestedReplaced, pub inc: Incomplete, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for NestedContainer { fn default() -> Self { @@ -499,8 +280,8 @@ impl Default for NestedContainer { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Incomplete { - pub d: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub d: T, } impl Default for Incomplete { fn default() -> Self { @@ -516,33 +297,25 @@ impl Default for Incomplete { pub struct Untemplated { pub _address: u8, } -#[test] -fn bindgen_test_layout_Untemplated() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Untemplated)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Untemplated)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Untemplated"][::std::mem::size_of::() - 1usize]; + ["Alignment of Untemplated"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { pub m_untemplated: Untemplated, } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+/** If the replacement doesn't happen at the parse level the container would be + copy and the replacement wouldn't, so this wouldn't compile. + +
*/ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructor { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for ReplacedWithoutDestructor { fn default() -> Self { @@ -556,8 +329,8 @@ impl Default for ReplacedWithoutDestructor { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ShouldNotBeCopiable { - pub m_member: ReplacedWithoutDestructor, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: ReplacedWithoutDestructor, } impl Default for ShouldNotBeCopiable { fn default() -> Self { @@ -571,8 +344,8 @@ impl Default for ShouldNotBeCopiable { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ShouldNotBeCopiableAsWell { - pub m_member: ReplacedWithoutDestructorFwd, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: ReplacedWithoutDestructorFwd, } impl Default for ShouldNotBeCopiableAsWell { fn default() -> Self { @@ -583,15 +356,15 @@ impl Default for ShouldNotBeCopiableAsWell { } } } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+/** If the replacement doesn't happen at the parse level the container would be + copy and the replacement wouldn't, so this wouldn't compile. + +
*/ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructorFwd { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for ReplacedWithoutDestructorFwd { fn default() -> Self { @@ -602,394 +375,192 @@ impl Default for ReplacedWithoutDestructorFwd { } } } -#[test] -fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_uint>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_uint>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const mozilla_Foo>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const mozilla_Foo>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation( -) { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<[*const mozilla_Foo; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[*const mozilla_Foo; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!("Size of template specialization: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(B) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 2usize, - concat!("Size of template specialization: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::>(), - 2usize, - concat!("Alignment of template specialization: ", stringify!(B)) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut ::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut ::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut *mut ::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut *mut ::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) - ); -} -#[test] -fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) - ); -} -#[test] -fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) - ); -} -#[test] -fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) - ); -} -#[test] -fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(WithDtor<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(WithDtor<::std::os::raw::c_int>) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Foo_open0_int_int_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Foo_open0_int_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_unsigned_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_unsigned_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ptr_const_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_const_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ptr_const_mozilla__Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_const_mozilla__Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_const_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_const_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_volatile_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_volatile_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_const_bool_close0", + ][::std::mem::size_of::>() - 1usize]; + [ + "Align of template specialization: B_open0_const_bool_close0", + ][::std::mem::align_of::>() - 1usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_const_char16_t_close0", + ][::std::mem::size_of::>() - 2usize]; + [ + "Align of template specialization: B_open0_const_char16_t_close0", + ][::std::mem::align_of::>() - 2usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_array1_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_array1_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_array1_ptr_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_array1_ptr_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ptr_array1_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_array1_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ref_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ref_const_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_const_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ref_ptr_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_ptr_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_ref_array1_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_array1_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: B_open0_array1_const_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_array1_const_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Foo_open0_int_int_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Foo_open0_int_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: WithDtor_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: WithDtor_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/template_alias.rs b/bindgen-tests/tests/expectations/tests/template_alias.rs index 7e0af20d78ce65c1c2b3f247ae7ab2eb36377e07..b270c9f3a48a999ef9374595a9f055158eaf7b4e 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type JS_detail_Wrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct JS_Rooted { - pub ptr: JS_detail_Wrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: JS_detail_Wrapped, } impl Default for JS_Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_alias_basic.rs b/bindgen-tests/tests/expectations/tests/template_alias_basic.rs index e06ffadab351d62d7e1461dfeef7f2f13784ce64..d0f8f104c7dda9fbaf7442fa2e168c4bafcb3263 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias_basic.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias_basic.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Wrapped = T; diff --git a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs index 7196b532f6e66e34d72dac3fb33eef2eec892b26..0aa5fc679ad708c46292a636ef2b90f07defcb54 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -20,9 +14,8 @@ pub mod root { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rooted { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub ptr: root::JS::detail::Wrapped, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_fun.rs b/bindgen-tests/tests/expectations/tests/template_fun.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/template_fun.rs +++ b/bindgen-tests/tests/expectations/tests/template_fun.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index d968e71baee57f93b7d5ac4f675b7120127ed9ed..0bf9cc6d828e5498ce09e6dc3fc29f6fb6e202cb 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -14,83 +8,51 @@ extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f(); } -#[test] -fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Foo_open0_Bar_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Foo_open0_Bar_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) - ); -} -#[test] -fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: Foo_open0_Boo_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Foo_open0_Boo_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Boo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Boo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Boo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Boo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Boo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Boo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/template_partial_specification.rs b/bindgen-tests/tests/expectations/tests/template_partial_specification.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/template_partial_specification.rs +++ b/bindgen-tests/tests/expectations/tests/template_partial_specification.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs index 68ca126ac92d0ae9fffa5213f14b1d962a3eeab6..2efdde944ed25bd7e3c53a6f9a05a146102a366c 100644 --- a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapper { @@ -13,8 +7,8 @@ pub struct Wrapper { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapper_Wrapped { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Wrapper_Wrapped { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_typedefs.rs b/bindgen-tests/tests/expectations/tests/template_typedefs.rs index 3883879d28a78cc4e0eef9490f81205f8970ca75..71f0732a638a2dd945e9047065e818f48b3f541d 100644 --- a/bindgen-tests/tests/expectations/tests/template_typedefs.rs +++ b/bindgen-tests/tests/expectations/tests/template_typedefs.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub type foo = - ::std::option::Option; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type foo = ::std::option::Option; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -15,8 +8,5 @@ pub struct Foo { pub type Foo_Char = T; pub type Foo_FooPtrTypedef = *mut Foo_Char; pub type Foo_nsCOMArrayEnumFunc = ::std::option::Option< - unsafe extern "C" fn( - aElement: *mut T, - aData: *mut ::std::os::raw::c_void, - ) -> bool, + unsafe extern "C" fn(aElement: *mut T, aData: *mut ::std::os::raw::c_void) -> bool, >; diff --git a/bindgen-tests/tests/expectations/tests/templateref_opaque.rs b/bindgen-tests/tests/expectations/tests/templateref_opaque.rs index 70cef8671700be42f81ea8a1e78f1a36d2de279d..8f73e86c3138fbd8883042eee06da16330242463 100644 --- a/bindgen-tests/tests/expectations/tests/templateref_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/templateref_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct detail_PointerType { diff --git a/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs b/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs index 5657a655400c91c395055cbe0b3286c2fb7acea7..1b3e71236115976da48827326c5041e0f394df4d 100644 --- a/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs @@ -1,13 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// We don't get a layout for this bitfield, since we don't know what `T` will -/// be, so we cannot allocate bitfield units. The best thing we can do is make -/// the struct opaque. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** We don't get a layout for this bitfield, since we don't know what `T` will + be, so we cannot allocate bitfield units. The best thing we can do is make + the struct opaque.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TemplatizedBitfield { diff --git a/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs b/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs new file mode 100644 index 0000000000000000000000000000000000000000..bf9739f3fa7b2925755cd36ccc1a5a9e8fef42c1 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs @@ -0,0 +1,6 @@ +pub const CONST: u32 = 5; +pub const OTHER_CONST: u32 = 6; +pub const LARGE_CONST: u32 = 1536; +pub const THE_CONST: u32 = 28; +pub const MY_CONST: u32 = 69; +pub const NEGATIVE: i32 = -1; diff --git a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs index 5f8da2affbb11cfebbcac5a29799c1625d9fc479..a2910b9b24951a904a9df21d9f6738e970ce598d 100644 --- a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -31,84 +31,20 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index b594d70c93ee6eff87fc87a36510e580d04c6b31..bcc27d259f097208de82345ce4401e8a8154362c 100644 --- a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -25,84 +25,20 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index dfcebdd29c152ebd50764af9f9b96c08dab7fed6..a9f78066f0a42e82cb03ddab3903ccab37b5d596 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,32 +90,12 @@ pub struct timex { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } -#[test] -fn bindgen_test_layout_timex() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex), - "::", - stringify!(tai) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of timex"][::std::mem::size_of::() - 48usize]; + ["Alignment of timex"][::std::mem::align_of::() - 4usize]; + ["Offset of field: timex::tai"][::std::mem::offset_of!(timex, tai) - 0usize]; +}; impl Default for timex { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -140,32 +112,14 @@ pub struct timex_named { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } -#[test] -fn bindgen_test_layout_timex_named() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex_named)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex_named)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex_named), - "::", - stringify!(tai) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of timex_named"][::std::mem::size_of::() - 48usize]; + ["Alignment of timex_named"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: timex_named::tai", + ][::std::mem::offset_of!(timex_named, tai) - 0usize]; +}; impl Default for timex_named { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -178,9 +132,7 @@ impl Default for timex_named { impl timex_named { #[inline] pub fn a(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 32u8) as u32) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_int) { @@ -191,9 +143,7 @@ impl timex_named { } #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -204,9 +154,7 @@ impl timex_named { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -217,9 +165,7 @@ impl timex_named { } #[inline] pub fn d(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_int) { @@ -230,9 +176,7 @@ impl timex_named { } #[inline] pub fn e(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) } } #[inline] pub fn set_e(&mut self, val: ::std::os::raw::c_int) { @@ -243,9 +187,7 @@ impl timex_named { } #[inline] pub fn f(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) } } #[inline] pub fn set_f(&mut self, val: ::std::os::raw::c_int) { @@ -256,9 +198,7 @@ impl timex_named { } #[inline] pub fn g(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) } } #[inline] pub fn set_g(&mut self, val: ::std::os::raw::c_int) { @@ -269,9 +209,7 @@ impl timex_named { } #[inline] pub fn h(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) } } #[inline] pub fn set_h(&mut self, val: ::std::os::raw::c_int) { @@ -282,9 +220,7 @@ impl timex_named { } #[inline] pub fn i(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) } } #[inline] pub fn set_i(&mut self, val: ::std::os::raw::c_int) { @@ -295,9 +231,7 @@ impl timex_named { } #[inline] pub fn j(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) } } #[inline] pub fn set_j(&mut self, val: ::std::os::raw::c_int) { @@ -308,9 +242,7 @@ impl timex_named { } #[inline] pub fn k(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) } } #[inline] pub fn set_k(&mut self, val: ::std::os::raw::c_int) { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 84a946036224b8b266966dbe5341284e88e30bfa..b53cea166a5a18d4a68c95203c9d7111a7e35ac8 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -51,9 +45,9 @@ impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StylePoint { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: T, pub y: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StylePoint { fn default() -> Self { @@ -67,12 +61,12 @@ impl Default for StylePoint { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StyleFoo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub __bindgen_anon_1: __BindgenUnionField, pub foo: __BindgenUnionField>, pub bar: __BindgenUnionField>, pub baz: __BindgenUnionField>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } pub const StyleFoo_Tag_Foo: StyleFoo_Tag = 0; pub const StyleFoo_Tag_Bar: StyleFoo_Tag = 0; @@ -82,11 +76,11 @@ pub type StyleFoo_Tag = u8; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Foo_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub x: i32, pub y: StylePoint, pub z: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Foo_Body { fn default() -> Self { @@ -100,9 +94,9 @@ impl Default for StyleFoo_Foo_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Bar_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub _0: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Bar_Body { fn default() -> Self { @@ -116,9 +110,9 @@ impl Default for StyleFoo_Bar_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Baz_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub _0: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Baz_Body { fn default() -> Self { @@ -146,9 +140,9 @@ impl Default for StyleFoo__bindgen_ty_1 { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleBar_Tag, pub __bindgen_anon_1: StyleBar__bindgen_ty_1, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } pub const StyleBar_Tag_Bar1: StyleBar_Tag = 0; pub const StyleBar_Tag_Bar2: StyleBar_Tag = 0; @@ -158,10 +152,10 @@ pub type StyleBar_Tag = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar1_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: i32, pub y: StylePoint, pub z: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleBar_StyleBar1_Body { fn default() -> Self { @@ -175,8 +169,8 @@ impl Default for StyleBar_StyleBar1_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar2_Body { - pub _0: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _0: T, } impl Default for StyleBar_StyleBar2_Body { fn default() -> Self { @@ -190,8 +184,8 @@ impl Default for StyleBar_StyleBar2_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar3_Body { - pub _0: StylePoint, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _0: StylePoint, } impl Default for StyleBar_StyleBar3_Body { fn default() -> Self { @@ -205,11 +199,11 @@ impl Default for StyleBar_StyleBar3_Body { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StyleBar__bindgen_ty_1 { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub bar1: __BindgenUnionField>, pub bar2: __BindgenUnionField>, pub bar3: __BindgenUnionField>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleBar { fn default() -> Self { @@ -225,18 +219,12 @@ fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation() { assert_eq!( ::std::mem::size_of::>(), 8usize, - concat!( - "Size of template specialization: ", - stringify!(StylePoint) - ) + "Size of template specialization: StylePoint_open0_float_close0", ); assert_eq!( ::std::mem::align_of::>(), 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(StylePoint) - ) + "Align of template specialization: StylePoint_open0_float_close0", ); } #[test] @@ -244,17 +232,11 @@ fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation_1() { assert_eq!( ::std::mem::size_of::>(), 8usize, - concat!( - "Size of template specialization: ", - stringify!(StylePoint) - ) + "Size of template specialization: StylePoint_open0_float_close0", ); assert_eq!( ::std::mem::align_of::>(), 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(StylePoint) - ) + "Align of template specialization: StylePoint_open0_float_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 7ae042bc9c1b5f0feed8d3f26edc2cc9f8433371..8ddfaa7c6875be2a14e1760a34bbfe4d722e01c7 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -1,41 +1,17 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct dl_phdr_info { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_dl_phdr_info() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dl_phdr_info)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dl_phdr_info)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dl_phdr_info), - "::", - stringify!(x) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of dl_phdr_info"][::std::mem::size_of::() - 4usize]; + ["Alignment of dl_phdr_info"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: dl_phdr_info::x", + ][::std::mem::offset_of!(dl_phdr_info, x) - 0usize]; +}; extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/type_alias_empty.rs b/bindgen-tests/tests/expectations/tests/type_alias_empty.rs index cb871a33a20fd0165e9393d8da69dca5773c6a89..2cbeb755708a44301aa04490a1c5c877fcb1e8b3 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_empty.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_empty.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type bool_constant = u8; diff --git a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs index 44449f20d1f5160a02eabe01b64b5bad96bd4acf..29df017a9bac141284e5074ce810a417da899f66 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type MaybeWrapped
= A; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub ptr: MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: MaybeWrapped, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs new file mode 100644 index 0000000000000000000000000000000000000000..13e3f8139c3d867a06172308c3bdc12ee64382c3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Rooted { + pub ptr: MaybeWrapped<::std::os::raw::c_int>, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Rooted"][::std::mem::size_of::() - 4usize]; + ["Alignment of Rooted"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Rooted::ptr"][::std::mem::offset_of!(Rooted, ptr) - 0usize]; +}; +impl Default for Rooted { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +///
+pub type MaybeWrapped
= a; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: MaybeWrapped_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: MaybeWrapped_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index 2d5c5aae8cdc3c5da79b37789e1ecf9d612ec125..f2376ed227133691b4bd9202f37b2889b6a52502 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -1,73 +1,27 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { pub inner: ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(inner) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of foo"][::std::mem::align_of::() - 1usize]; + ["Offset of field: foo::inner"][::std::mem::offset_of!(foo, inner) - 0usize]; +}; pub type foo_ptr = *const foo; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct bar { pub inner: ::std::os::raw::c_char, } -#[test] -fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(inner) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of bar"][::std::mem::align_of::() - 1usize]; + ["Offset of field: bar::inner"][::std::mem::offset_of!(bar, inner) - 0usize]; +}; pub type bar_ptr = *mut bar; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -80,34 +34,14 @@ pub type baz_ptr = *mut baz; pub union cat { pub standard_issue: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_cat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cat)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(cat)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).standard_issue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cat), - "::", - stringify!(standard_issue) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of cat"][::std::mem::size_of::() - 4usize]; + ["Alignment of cat"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: cat::standard_issue", + ][::std::mem::offset_of!(cat, standard_issue) - 0usize]; +}; impl Default for cat { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs index 330499b8ab3c3e1ebc006ed9309bf5de1756708e..792b243a7a35742fecf64f1dd9f26328de9cfc5f 100644 --- a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs +++ b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type myVector3 = [f32; 3usize]; extern "C" { pub fn modifyVectorFunc(v: *mut f32); diff --git a/bindgen-tests/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs index a3a31dafa727b44efddf211abe576603bcc8772f..e48f0eb254f70a0486d797009a188dc3e01e8638 100644 --- a/bindgen-tests/tests/expectations/tests/typeref.rs +++ b/bindgen-tests/tests/expectations/tests/typeref.rs @@ -1,61 +1,33 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } -#[test] -fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of mozilla_FragmentOrURL", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of mozilla_FragmentOrURL", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: mozilla_FragmentOrURL::mIsLocalRef", + ][::std::mem::offset_of!(mozilla_FragmentOrURL, mIsLocalRef) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_Position { pub _address: u8, } -#[test] -fn bindgen_test_layout_mozilla_Position() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_Position)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of mozilla_Position"][::std::mem::size_of::() - 1usize]; + [ + "Alignment of mozilla_Position", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, @@ -88,27 +60,12 @@ impl Default for mozilla_StyleShapeSource { pub struct Bar { pub mFoo: *mut nsFoo, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::mFoo"][::std::mem::offset_of!(Bar, mFoo) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -122,32 +79,12 @@ impl Default for Bar { pub struct nsFoo { pub mBar: mozilla_StyleShapeSource, } -#[test] -fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsFoo"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsFoo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: nsFoo::mBar"][::std::mem::offset_of!(nsFoo, mBar) - 0usize]; +}; impl Default for nsFoo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -157,23 +94,12 @@ impl Default for nsFoo { } } } -#[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation( -) { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: mozilla_StyleShapeSource_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 8e4143c082b4107dea4da8a026405f15f3b93415..2cf1633a610a625d59de7915abcec889b5d59773 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -55,30 +49,22 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + "Size of mozilla_FragmentOrURL", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + "Alignment of mozilla_FragmentOrURL", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) + "Offset of field: mozilla_FragmentOrURL::mIsLocalRef", ); } impl Clone for mozilla_FragmentOrURL { @@ -96,12 +82,12 @@ fn bindgen_test_layout_mozilla_Position() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(mozilla_Position)) + "Size of mozilla_Position", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)) + "Alignment of mozilla_Position", ); } impl Clone for mozilla_Position { @@ -128,23 +114,14 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) + "Offset of field: Bar::mFoo", ); } impl Clone for Bar { @@ -168,28 +145,14 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of nsFoo"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of nsFoo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) + "Offset of field: nsFoo::mBar", ); } impl Clone for nsFoo { @@ -198,22 +161,15 @@ impl Clone for nsFoo { } } #[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation( -) { +fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + "Align of template specialization: mozilla_StyleShapeSource_open0_int_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs index bfc05ac17a8c01da918b70167b476d86d1147b63..f94d5fc580f6d670363709c4f533f273ff715586 100644 --- a/bindgen-tests/tests/expectations/tests/underscore.rs +++ b/bindgen-tests/tests/expectations/tests/underscore.rs @@ -1,34 +1,13 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const __: ::std::os::raw::c_int = 10; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ptr_t { pub __: [::std::os::raw::c_uchar; 8usize], } -#[test] -fn bindgen_test_layout_ptr_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ptr_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ptr_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ptr_t"][::std::mem::size_of::() - 8usize]; + ["Alignment of ptr_t"][::std::mem::align_of::() - 1usize]; + ["Offset of field: ptr_t::__"][::std::mem::offset_of!(ptr_t, __) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs index 062ea97a86d0708334c85e3a2b74cc8041373a3d..2838ef34c3456fa2c27068aa45175b0370543e9e 100644 --- a/bindgen-tests/tests/expectations/tests/union-align.rs +++ b/bindgen-tests/tests/expectations/tests/union-align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Copy, Clone)] @@ -13,23 +7,14 @@ pub union Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Bar)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of Bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) + "Offset of field: Bar::foo", ); } impl Default for Bar { @@ -49,23 +34,14 @@ pub union Baz { } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Baz)) - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of Baz"); + assert_eq!(::std::mem::align_of::(), 16usize, "Alignment of Baz"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) + "Offset of field: Baz::bar", ); } impl Default for Baz { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs index 65f3f8f2885ac0682dfb6f871cf785132d6c63a1..781041addb30c3bb0fb9c2b360e58c7e7522efc9 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] @@ -14,32 +8,12 @@ pub mod root { pub union bar { pub baz: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); - } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 0usize]; + }; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index a057cc348a44853327dda0ef1d0c2639e4cfebdb..eac1df1a137e32a7a81fc78de5ac9225af35a550 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[repr(C)] @@ -32,15 +26,12 @@ pub mod root { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt( - &self, - fmt: &mut ::std::fmt::Formatter<'_>, - ) -> ::std::fmt::Result { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } @@ -63,28 +54,14 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of bar"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) + "Offset of field: bar::baz", ); } impl Clone for bar { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index 9e07a1dfcdda460eb1881ad6ca766eb7ffcb5f20..b529dcfbc800bdb83fe3c7430f853aaf0468e5cb 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,19 +90,11 @@ pub union U4 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_U4() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of U4"][::std::mem::size_of::() - 4usize]; + ["Alignment of U4"][::std::mem::align_of::() - 4usize]; +}; impl Default for U4 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -123,9 +107,7 @@ impl Default for U4 { impl U4 { #[inline] pub fn derp(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_derp(&mut self, val: ::std::os::raw::c_uint) { @@ -138,35 +120,30 @@ impl U4 { pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let derp: u32 = unsafe { ::std::mem::transmute(derp) }; - derp as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let derp: u32 = unsafe { ::std::mem::transmute(derp) }; + derp as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; +}; impl Default for B { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -179,9 +156,7 @@ impl Default for B { impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) { @@ -192,9 +167,7 @@ impl B { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { @@ -208,16 +181,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index 2227746849b9251542577f6084485ade864e4413..c2c7173bfeb3f18a124530e1d75e428db98e9281 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -143,16 +135,8 @@ pub struct U4 { } #[test] fn bindgen_test_layout_U4() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of U4"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of U4"); } impl Clone for U4 { fn clone(&self) -> Self { @@ -163,9 +147,7 @@ impl U4 { #[inline] pub fn derp(&self) -> ::std::os::raw::c_uint { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(0usize, 1u8) as u32 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 1u8) as u32) } } #[inline] @@ -179,12 +161,16 @@ impl U4 { pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let derp: u32 = unsafe { ::std::mem::transmute(derp) }; - derp as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let derp: u32 = unsafe { ::std::mem::transmute(derp) }; + derp as u64 + }, + ); __bindgen_bitfield_unit } } @@ -197,16 +183,8 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of B"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); } impl Clone for B { fn clone(&self) -> Self { @@ -217,9 +195,7 @@ impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(0usize, 31u8) as u32 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 31u8) as u32) } } #[inline] @@ -232,9 +208,7 @@ impl B { #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(31usize, 1u8) as u8 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) } } #[inline] @@ -249,16 +223,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } @@ -274,7 +257,7 @@ fn bindgen_test_layout_HasBigBitfield() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)) + "Size of HasBigBitfield", ); } impl Clone for HasBigBitfield { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 085e5ca30a5b24b9625273b8576bd5bfc03cfbd4..168b0a0b1ee80ba779c4e6c19ef63cf5f1930979 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -1,51 +1,20 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of UnionWithDtor"][::std::mem::size_of::() - 8usize]; + ["Alignment of UnionWithDtor"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: UnionWithDtor::mFoo", + ][::std::mem::offset_of!(UnionWithDtor, mFoo) - 0usize]; + [ + "Offset of field: UnionWithDtor::mBar", + ][::std::mem::offset_of!(UnionWithDtor, mBar) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor); diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 67455aa8b8c731eccb021ce5652b02120fe0947d..e9c777df941f76878e60935d91f8570dfc074ab9 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -57,38 +51,23 @@ pub struct UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of UnionWithDtor"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)) + "Alignment of UnionWithDtor", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) + "Offset of field: UnionWithDtor::mFoo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) + "Offset of field: UnionWithDtor::mBar", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs index 9135ca3c6ce752ce4dfe81662b34f17990429e33..c3d0f8db61c3967b8b0a04e8b6cda3aec95fdf58 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union nsStyleUnion { @@ -12,54 +6,20 @@ pub union nsStyleUnion { pub mFloat: f32, pub mPointer: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsStyleUnion"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsStyleUnion"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsStyleUnion::mInt", + ][::std::mem::offset_of!(nsStyleUnion, mInt) - 0usize]; + [ + "Offset of field: nsStyleUnion::mFloat", + ][::std::mem::offset_of!(nsStyleUnion, mFloat) - 0usize]; + [ + "Offset of field: nsStyleUnion::mPointer", + ][::std::mem::offset_of!(nsStyleUnion, mPointer) - 0usize]; +}; impl Default for nsStyleUnion { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index b5f94bcd05ef73e8a60ab7fef46a9d500f7f32fb..9cf2f098326363f0e0982f6f2e301bf1210ffff1 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -58,50 +52,28 @@ pub struct nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of nsStyleUnion"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)) + "Alignment of nsStyleUnion", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) + "Offset of field: nsStyleUnion::mInt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) + "Offset of field: nsStyleUnion::mFloat", ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) + "Offset of field: nsStyleUnion::mPointer", ); } impl Clone for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_template.rs b/bindgen-tests/tests/expectations/tests/union_template.rs index 9c3d7a07ebf2892f1271bd2b10dbd459c6ce6cb1..62019e6dd72aa7a86fe2a1095f515ae3fab97749 100644 --- a/bindgen-tests/tests/expectations/tests/union_template.rs +++ b/bindgen-tests/tests/expectations/tests/union_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct NastyStruct { pub mIsSome: bool, diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 487579f7e516cccdc2a39af58a9b02e18d136586..4ebad2a2e2b100394cbd6f036fa0118fd68c0cf1 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs index 35b5829beb72c2da85554b380cd77d94468bd783..20f4dd22654435c9127972a3a699408f7d94dd9c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -16,63 +10,25 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 8b11e75796ab1411f712514b8ce9dd1bd9639daa..7ea38b8bae641d4f1a6902e226402de885872189 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -62,38 +56,27 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -103,23 +86,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index e81b3bef505ad63fc292b797ffd50b23e86b62e4..f850f6a3dacff44cff4704045f195f28ea8f02dc 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -98,31 +90,22 @@ pub union foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; +}; impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -133,9 +116,7 @@ impl foo__bindgen_ty_1 { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -149,40 +130,34 @@ impl foo__bindgen_ty_1 { b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(7usize, 25u8, { - let c: u32 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 25u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); __bindgen_bitfield_unit } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 6ce6ed22824c8e0f7fc3c5be1def0af412b95a88..ce81f8a04eeaf7fcd7497c55a297a90b63352000 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -146,19 +138,18 @@ pub struct foo { pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); } impl Clone for foo__bindgen_ty_1 { @@ -169,9 +160,7 @@ impl Clone for foo__bindgen_ty_1 { impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -182,9 +171,7 @@ impl foo__bindgen_ty_1 { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -198,38 +185,38 @@ impl foo__bindgen_ty_1 { b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(7usize, 25u8, { - let c: u32 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 25u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs index 487650bfe4a4cfce6f0bde10ba4ea2c39d66f691..212a159cd22509b62c6f3b4044385528c92735e3 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -16,42 +10,19 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -61,27 +32,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index f3e4b84003094391a84621a6eaf186e2a33030e1..ad6d9c7e16aa87dfea6b4fd245f7092098fddf5c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -63,38 +57,27 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -104,23 +87,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs index cff5df047278cf4f1bbaebb8621c981120cc5908..859188e891ae80c58370a399e9457ed5ccc4fce0 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union pixel { @@ -19,88 +13,33 @@ pub struct pixel__bindgen_ty_1 { pub b: ::std::os::raw::c_uchar, pub a: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) - ); -} -#[test] -fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of pixel__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of pixel__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: pixel__bindgen_ty_1::r", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, r) - 0usize]; + [ + "Offset of field: pixel__bindgen_ty_1::g", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, g) - 1usize]; + [ + "Offset of field: pixel__bindgen_ty_1::b", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, b) - 2usize]; + [ + "Offset of field: pixel__bindgen_ty_1::a", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, a) - 3usize]; +}; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of pixel"][::std::mem::size_of::() - 4usize]; + ["Alignment of pixel"][::std::mem::align_of::() - 4usize]; + ["Offset of field: pixel::rgba"][::std::mem::offset_of!(pixel, rgba) - 0usize]; +}; impl Default for pixel { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 1562a8c97154a37c85ce515c40210392da5e7864..20ceaee90cc92888aaf962aa7ddff1b0c79f0d41 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -65,58 +59,37 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)) + "Size of pixel__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) + "Alignment of pixel__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) + "Offset of field: pixel__bindgen_ty_1::r", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) + "Offset of field: pixel__bindgen_ty_1::g", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: pixel__bindgen_ty_1::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) + "Offset of field: pixel__bindgen_ty_1::a", ); } impl Clone for pixel__bindgen_ty_1 { @@ -126,28 +99,14 @@ impl Clone for pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of pixel"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of pixel"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) + "Offset of field: pixel::rgba", ); } impl Clone for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs index f1abfc5a25afbb2ad5fe148406ec3a907872fd2d..6e136c0d9217109d69939ab1411e417def2a0a84 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -17,42 +11,19 @@ pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, pub c: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::c", + ][::std::mem::offset_of!(foo__bindgen_ty_1, c) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -62,27 +33,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 197a6bbfbca3523156882a20b7887c0f1d0f9413..561c7f80719b2b05e8f5e7eb3342e5f2d846255e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -64,38 +58,27 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + "Offset of field: foo__bindgen_ty_1::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) + "Offset of field: foo__bindgen_ty_1::c", ); } impl Clone for foo__bindgen_ty_1 { @@ -105,23 +88,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs index 7110257bc7c59cfd45bceab37e77d189bad71a50..9d69957a851bacd7b9c8837caeac13feb1590035 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs @@ -1,52 +1,21 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union WithBigArray { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_int; 33usize], } -#[test] -fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithBigArray"][::std::mem::size_of::() - 132usize]; + ["Alignment of WithBigArray"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBigArray::a", + ][::std::mem::offset_of!(WithBigArray, a) - 0usize]; + [ + "Offset of field: WithBigArray::b", + ][::std::mem::offset_of!(WithBigArray, b) - 0usize]; +}; impl Default for WithBigArray { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -62,42 +31,17 @@ pub union WithBigArray2 { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_char; 33usize], } -#[test] -fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithBigArray2"][::std::mem::size_of::() - 36usize]; + ["Alignment of WithBigArray2"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBigArray2::a", + ][::std::mem::offset_of!(WithBigArray2, a) - 0usize]; + [ + "Offset of field: WithBigArray2::b", + ][::std::mem::offset_of!(WithBigArray2, b) - 0usize]; +}; impl Default for WithBigArray2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -113,42 +57,17 @@ pub union WithBigMember { pub a: ::std::os::raw::c_int, pub b: WithBigArray, } -#[test] -fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigMember)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigMember)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithBigMember"][::std::mem::size_of::() - 132usize]; + ["Alignment of WithBigMember"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBigMember::a", + ][::std::mem::offset_of!(WithBigMember, a) - 0usize]; + [ + "Offset of field: WithBigMember::b", + ][::std::mem::offset_of!(WithBigMember, b) - 0usize]; +}; impl Default for WithBigMember { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 63b43baa828182acc0d40fb47f2309961dc9074c..14a68fc0bf7ee2b1a7be9907ee16d701d25e23f9 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -57,38 +51,23 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of WithBigArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) + "Alignment of WithBigArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) + "Offset of field: WithBigArray::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) + "Offset of field: WithBigArray::b", ); } impl Clone for WithBigArray { @@ -114,38 +93,23 @@ pub struct WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)) - ); + assert_eq!(::std::mem::size_of::(), 36usize, "Size of WithBigArray2"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)) + "Alignment of WithBigArray2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) + "Offset of field: WithBigArray2::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) + "Offset of field: WithBigArray2::b", ); } impl Clone for WithBigArray2 { @@ -162,38 +126,27 @@ pub struct WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(WithBigMember)) + "Size of WithBigMember", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigMember)) + "Alignment of WithBigMember", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) + "Offset of field: WithBigMember::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) + "Offset of field: WithBigMember::b", ); } impl Clone for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs index ec9c14801178bba6e131435a46773d3d12e5780f..5b60193ba432e66d565931fdfbae7b0ac83d8722 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -23,42 +17,21 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, pub b2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, b1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, b2) - 0usize]; +}; impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -74,42 +47,21 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, c1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, c2) - 0usize]; +}; impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -119,19 +71,13 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -141,27 +87,12 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index a1e452fe0368667792e4dacd81c14f3e3a8bd477..22b902d82c690348bd63c486d27c3653248f0ad0 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -70,38 +64,27 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + "Size of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -118,38 +101,27 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + "Size of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -162,12 +134,12 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + "Alignment of foo__bindgen_ty_1", ); } impl Clone for foo__bindgen_ty_1 { @@ -177,23 +149,14 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 3c500b210610251310a0a89425d7d69390938f56..d13c24d2d85839a42bd24da8391c888e5d0b46ed 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -53,76 +47,35 @@ impl ::std::cmp::Eq for __BindgenUnionField {} pub struct NonCopyType { pub foo: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NonCopyType() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopyType)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopyType)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopyType), - "::", - stringify!(foo) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of NonCopyType"][::std::mem::size_of::() - 4usize]; + ["Alignment of NonCopyType"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopyType::foo", + ][::std::mem::offset_of!(NonCopyType, foo) - 0usize]; +}; #[repr(C)] pub struct WithBindgenGeneratedWrapper { pub non_copy_type: __BindgenUnionField, pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } -#[test] -fn bindgen_test_layout_WithBindgenGeneratedWrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(non_copy_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of WithBindgenGeneratedWrapper", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithBindgenGeneratedWrapper", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBindgenGeneratedWrapper::non_copy_type", + ][::std::mem::offset_of!(WithBindgenGeneratedWrapper, non_copy_type) - 0usize]; + [ + "Offset of field: WithBindgenGeneratedWrapper::bar", + ][::std::mem::offset_of!(WithBindgenGeneratedWrapper, bar) - 0usize]; +}; impl Default for WithBindgenGeneratedWrapper { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -137,44 +90,19 @@ pub union WithManuallyDrop { pub non_copy_type: ::std::mem::ManuallyDrop, pub bar: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_WithManuallyDrop() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithManuallyDrop)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithManuallyDrop)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithManuallyDrop), - "::", - stringify!(non_copy_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithManuallyDrop), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithManuallyDrop"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithManuallyDrop", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithManuallyDrop::non_copy_type", + ][::std::mem::offset_of!(WithManuallyDrop, non_copy_type) - 0usize]; + [ + "Offset of field: WithManuallyDrop::bar", + ][::std::mem::offset_of!(WithManuallyDrop, bar) - 0usize]; +}; impl Default for WithManuallyDrop { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -190,44 +118,19 @@ pub struct WithDefaultWrapper { pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } -#[test] -fn bindgen_test_layout_WithDefaultWrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDefaultWrapper)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDefaultWrapper)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(non_copy_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(bar) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of WithDefaultWrapper"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithDefaultWrapper", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithDefaultWrapper::non_copy_type", + ][::std::mem::offset_of!(WithDefaultWrapper, non_copy_type) - 0usize]; + [ + "Offset of field: WithDefaultWrapper::bar", + ][::std::mem::offset_of!(WithDefaultWrapper, bar) - 0usize]; +}; impl Default for WithDefaultWrapper { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index c790f009c9ac90842605e7b20c55fe68553724f0..bdfebb29dc48cf741094fc1abec2319134f76dd7 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -13,45 +7,14 @@ pub struct max_align_t { pub __bindgen_padding_0: u64, pub __clang_max_align_nonce2: ::std::os::raw::c_longlong, } -#[test] -fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of max_align_t"][::std::mem::size_of::() - 32usize]; + ["Alignment of max_align_t"][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: max_align_t::__clang_max_align_nonce1", + ][::std::mem::offset_of!(max_align_t, __clang_max_align_nonce1) - 0usize]; + [ + "Offset of field: max_align_t::__clang_max_align_nonce2", + ][::std::mem::offset_of!(max_align_t, __clang_max_align_nonce2) - 16usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index ce0c5f3f66795c5430902a4a782c51e6042dd6d7..fca5715533cfceadc90eb76f8a1584d96475fdbd 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo() -> ::std::os::raw::c_int; } @@ -18,64 +12,26 @@ pub struct Point { pub x: number, pub y: number, } -#[test] -fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Angle { pub a: number, pub b: number, } -#[test] -fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; +}; extern "C" { pub fn baz(point: Point) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index 569e8d24700867910e6b5016423b9c8cc3da6b2e..e7b3ce898236ba3f36f9b8f9ffd8f061f03953ff 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] extern crate core; - #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -14,37 +8,14 @@ pub struct foo { pub b: ::core::ffi::c_int, pub bar: *mut ::core::ffi::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); @@ -60,42 +31,17 @@ pub union _bindgen_ty_1 { pub bar: ::core::ffi::c_int, pub baz: ::core::ffi::c_long, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = - ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - ::core::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of _bindgen_ty_1"][::core::mem::size_of::<_bindgen_ty_1>() - 8usize]; + ["Alignment of _bindgen_ty_1"][::core::mem::align_of::<_bindgen_ty_1>() - 8usize]; + [ + "Offset of field: _bindgen_ty_1::bar", + ][::core::mem::offset_of!(_bindgen_ty_1, bar) - 0usize]; + [ + "Offset of field: _bindgen_ty_1::baz", + ][::core::mem::offset_of!(_bindgen_ty_1, baz) - 0usize]; +}; impl Default for _bindgen_ty_1 { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); @@ -108,5 +54,6 @@ impl Default for _bindgen_ty_1 { extern "C" { pub static mut bazz: _bindgen_ty_1; } -pub type fooFunction = - ::core::option::Option; +pub type fooFunction = ::core::option::Option< + unsafe extern "C" fn(bar: ::core::ffi::c_int), +>; diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 8c6d0fd272963e4278d6981a984b4e3a9019b0ea..707ca3d962cbf2326efb1541c773d3399b31ed9b 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] pub struct __BindgenUnionField(::core::marker::PhantomData); impl __BindgenUnionField { @@ -32,7 +25,7 @@ impl ::core::default::Default for __BindgenUnionField { impl ::core::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::core::marker::Copy for __BindgenUnionField {} @@ -59,33 +52,24 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); + assert_eq!(::core::mem::size_of::(), 16usize, "Size of foo"); + assert_eq!(::core::mem::align_of::(), 8usize, "Alignment of foo"); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + "Offset of field: foo::a", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + "Offset of field: foo::b", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + "Offset of field: foo::bar", ); } impl Clone for foo { @@ -111,38 +95,23 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) - ); + assert_eq!(::core::mem::size_of::<_bindgen_ty_1>(), 8usize, "Size of _bindgen_ty_1"); assert_eq!( ::core::mem::align_of::<_bindgen_ty_1>(), 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + "Alignment of _bindgen_ty_1", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) + "Offset of field: _bindgen_ty_1::bar", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) + "Offset of field: _bindgen_ty_1::baz", ); } impl Clone for _bindgen_ty_1 { @@ -153,5 +122,6 @@ impl Clone for _bindgen_ty_1 { extern "C" { pub static mut bazz: _bindgen_ty_1; } -pub type fooFunction = - ::core::option::Option; +pub type fooFunction = ::core::option::Option< + unsafe extern "C" fn(bar: ::std::os::raw::c_int), +>; diff --git a/bindgen-tests/tests/expectations/tests/using.rs b/bindgen-tests/tests/expectations/tests/using.rs index 4749ed555283d675b0249d9ee0ec2fa325a14d09..9737fef0a5f687fc596966b5708a2482eac7ea98 100644 --- a/bindgen-tests/tests/expectations/tests/using.rs +++ b/bindgen-tests/tests/expectations/tests/using.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Point { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: T, pub y: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Point { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 37fdd95105dfe4e192ea50569c2c1673c3a3192b..606cdd70b8aa95570882f82349073aa8101c7284 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -1,41 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub m_baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_baz) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::m_baz"][::std::mem::offset_of!(Bar, m_baz) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] pub fn Bar_Bar(this: *mut Bar, baz: ::std::os::raw::c_int); @@ -57,16 +31,8 @@ extern "C" { #[link_name = "\u{1}_ZN3Baz3FOOE"] pub static Baz_FOO: [Bar; 0usize]; } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index be93dda70b4b3fec712e692fa0449fa4a42f708f..93ce01b81371afaf3420392f8bfedb981120ac89 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooPKcz"] pub fn foo(fmt: *const ::std::os::raw::c_char, ...); @@ -14,19 +8,11 @@ extern "C" { pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Bar3fooEPKcz"] pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...); diff --git a/bindgen-tests/tests/expectations/tests/variadic_template_function.rs b/bindgen-tests/tests/expectations/tests/variadic_template_function.rs index 8f67136ac82c1609ccd7af1e8c6bc98f6384b9ad..ee945f259946d616d55cf12c80c0df42c1d8cec9 100644 --- a/bindgen-tests/tests/expectations/tests/variadic_template_function.rs +++ b/bindgen-tests/tests/expectations/tests/variadic_template_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct VariadicFunctionObject { diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index 12d2e1b1f772389bb96a581e65b66ec9506d6c93..2278b520d9e4e5397ec45a505ef4edda56caaf0a 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -1,41 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { pub mMember: [::std::os::raw::c_longlong; 1usize], } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(mMember) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::mMember"][::std::mem::offset_of!(foo, mMember) - 0usize]; +}; pub type __m128 = [f32; 4usize]; pub type __m128d = [f64; 2usize]; pub type __m128i = [::std::os::raw::c_longlong; 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index c3c66e91d8b8d091ea5a5d337050b5a26d49a3cd..84211429b191299d15a540a99277d6aff58328b8 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] @@ -12,19 +6,11 @@ pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); pub struct nsSlots { pub vtable_: *const nsSlots__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsSlots() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsSlots)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsSlots)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of nsSlots"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsSlots"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsSlots { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs index 07b94ec89c0d2e3dd6b790d583aa6cf528e5a983..6b5a855fae9bea60d74a5b24abc83e95e899d37d 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { diff --git a/bindgen-tests/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs index be94f23205460fe5663b53d5b7d03a67cbcdf958..44b245c4ea195148fa24ceb3f036c5a2b4b35b6f 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_interface.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_interface.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { pub PureVirtualIFace_Foo: unsafe extern "C" fn(this: *mut PureVirtualIFace), @@ -18,19 +12,13 @@ pub struct PureVirtualIFace__bindgen_vtable { pub struct PureVirtualIFace { pub vtable_: *const PureVirtualIFace__bindgen_vtable, } -#[test] -fn bindgen_test_layout_PureVirtualIFace() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PureVirtualIFace)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(PureVirtualIFace)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of PureVirtualIFace"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of PureVirtualIFace", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for PureVirtualIFace { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -49,19 +37,13 @@ pub struct AnotherInterface__bindgen_vtable { pub struct AnotherInterface { pub vtable_: *const AnotherInterface__bindgen_vtable, } -#[test] -fn bindgen_test_layout_AnotherInterface() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AnotherInterface)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(AnotherInterface)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of AnotherInterface"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of AnotherInterface", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for AnotherInterface { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -76,19 +58,11 @@ impl Default for AnotherInterface { pub struct Implementation { pub _base: PureVirtualIFace, } -#[test] -fn bindgen_test_layout_Implementation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Implementation)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Implementation)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Implementation"][::std::mem::size_of::() - 8usize]; + ["Alignment of Implementation"][::std::mem::align_of::() - 8usize]; +}; impl Default for Implementation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -104,19 +78,11 @@ pub struct DoubleImpl { pub _base: PureVirtualIFace, pub _base_1: AnotherInterface, } -#[test] -fn bindgen_test_layout_DoubleImpl() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DoubleImpl)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DoubleImpl)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of DoubleImpl"][::std::mem::size_of::() - 16usize]; + ["Alignment of DoubleImpl"][::std::mem::align_of::() - 8usize]; +}; impl Default for DoubleImpl { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index c117d9ef6c27477bcd98226f016d70d8578c9854..800ebbef8f7fb06281734628d69157c2f665850c 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -1,35 +1,19 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct C__bindgen_vtable { - pub C_do_thing: - unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_char), - pub C_do_thing1: - unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_int), + pub C_do_thing: unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_char), + pub C_do_thing1: unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_int), } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { pub vtable_: *const C__bindgen_vtable, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -41,15 +25,9 @@ impl Default for C { } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEc"] - pub fn C_do_thing( - this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_char, - ); + pub fn C_do_thing(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_char); } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEi"] - pub fn C_do_thing1( - this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_int, - ); + pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/void_typedef.rs b/bindgen-tests/tests/expectations/tests/void_typedef.rs index 7e148e723844ce5c8751cbe687af805170d63be1..6c3b45dcc7e8a835776550044087bb3f49bfe90d 100644 --- a/bindgen-tests/tests/expectations/tests/void_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/void_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type VOID = ::std::os::raw::c_void; pub type ALSO_VOID = VOID; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index 74e1dc79145317a1e84ff9a89ffeef109e38f41c..fe08228ab91df4d4a4fc46b0e9d0feb5410a24ee 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Base__bindgen_vtable { pub Base_AsDerived: unsafe extern "C" fn(this: *mut Base) -> *mut Derived, @@ -14,19 +8,11 @@ pub struct Base__bindgen_vtable { pub struct Base { pub vtable_: *const Base__bindgen_vtable, } -#[test] -fn bindgen_test_layout_Base() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Base)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Base)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Base"][::std::mem::size_of::() - 8usize]; + ["Alignment of Base"][::std::mem::align_of::() - 8usize]; +}; impl Default for Base { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -45,19 +31,11 @@ extern "C" { pub struct Derived { pub _base: Base, } -#[test] -fn bindgen_test_layout_Derived() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Derived)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Derived)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Derived"][::std::mem::size_of::() - 8usize]; + ["Alignment of Derived"][::std::mem::align_of::() - 8usize]; +}; impl Default for Derived { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 6d15c51f9d145e19292acf7b3acd56880676858e..092d592e29f1f950085dfe43e4614a38e081d277 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -1,28 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo( diff --git a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs index e334a7b73412b64d3f9f625f2b85f7564f3419fc..9725195e0e5492d9dead93e22676a6daf138c2a2 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[link(wasm_import_module = "test-module")] extern "C" { pub fn test_function(); diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index 9383bada44bfa9720a9ae10f9ae128b488e8f69f..f76189eb74974bf05d0400a6a76f7db7bc349dbe 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - self.storage.as_ref().len() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -119,169 +111,47 @@ pub struct Weird { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_Weird() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(Weird)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Weird)) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeDasharrayLength) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mClipRule) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolation) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolationFilters) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mFillRule) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mImageRendering) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize - }, - 13usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mPaintOrder) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize - }, - 14usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mShapeRendering) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize - }, - 15usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinecap) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinejoin) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextAnchor) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextRendering) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Weird"][::std::mem::size_of::() - 24usize]; + ["Alignment of Weird"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Weird::mStrokeDasharrayLength", + ][::std::mem::offset_of!(Weird, mStrokeDasharrayLength) - 0usize]; + [ + "Offset of field: Weird::mClipRule", + ][::std::mem::offset_of!(Weird, mClipRule) - 8usize]; + [ + "Offset of field: Weird::mColorInterpolation", + ][::std::mem::offset_of!(Weird, mColorInterpolation) - 9usize]; + [ + "Offset of field: Weird::mColorInterpolationFilters", + ][::std::mem::offset_of!(Weird, mColorInterpolationFilters) - 10usize]; + [ + "Offset of field: Weird::mFillRule", + ][::std::mem::offset_of!(Weird, mFillRule) - 11usize]; + [ + "Offset of field: Weird::mImageRendering", + ][::std::mem::offset_of!(Weird, mImageRendering) - 12usize]; + [ + "Offset of field: Weird::mPaintOrder", + ][::std::mem::offset_of!(Weird, mPaintOrder) - 13usize]; + [ + "Offset of field: Weird::mShapeRendering", + ][::std::mem::offset_of!(Weird, mShapeRendering) - 14usize]; + [ + "Offset of field: Weird::mStrokeLinecap", + ][::std::mem::offset_of!(Weird, mStrokeLinecap) - 15usize]; + [ + "Offset of field: Weird::mStrokeLinejoin", + ][::std::mem::offset_of!(Weird, mStrokeLinejoin) - 16usize]; + [ + "Offset of field: Weird::mTextAnchor", + ][::std::mem::offset_of!(Weird, mTextAnchor) - 17usize]; + [ + "Offset of field: Weird::mTextRendering", + ][::std::mem::offset_of!(Weird, mTextRendering) - 18usize]; +}; impl Default for Weird { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -294,9 +164,7 @@ impl Default for Weird { impl Weird { #[inline] pub fn bitTest(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) } } #[inline] pub fn set_bitTest(&mut self, val: ::std::os::raw::c_uint) { @@ -307,9 +175,7 @@ impl Weird { } #[inline] pub fn bitTest2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 15u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 15u8) as u32) } } #[inline] pub fn set_bitTest2(&mut self, val: ::std::os::raw::c_uint) { @@ -323,23 +189,30 @@ impl Weird { bitTest: ::std::os::raw::c_uint, bitTest2: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 16u8, { - let bitTest: u32 = unsafe { ::std::mem::transmute(bitTest) }; - bitTest as u64 - }); - __bindgen_bitfield_unit.set(16usize, 15u8, { - let bitTest2: u32 = unsafe { ::std::mem::transmute(bitTest2) }; - bitTest2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 16u8, + { + let bitTest: u32 = unsafe { ::std::mem::transmute(bitTest) }; + bitTest as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 15u8, + { + let bitTest2: u32 = unsafe { ::std::mem::transmute(bitTest2) }; + bitTest2 as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn mFillOpacitySource(&self) -> nsStyleSVGOpacitySource { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 3u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 3u8) as u32) } } #[inline] pub fn set_mFillOpacitySource(&mut self, val: nsStyleSVGOpacitySource) { @@ -350,9 +223,7 @@ impl Weird { } #[inline] pub fn mStrokeOpacitySource(&self) -> nsStyleSVGOpacitySource { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(3usize, 3u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(3usize, 3u8) as u32) } } #[inline] pub fn set_mStrokeOpacitySource(&mut self, val: nsStyleSVGOpacitySource) { @@ -363,9 +234,7 @@ impl Weird { } #[inline] pub fn mStrokeDasharrayFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(6usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(6usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeDasharrayFromObject(&mut self, val: bool) { @@ -376,9 +245,7 @@ impl Weird { } #[inline] pub fn mStrokeDashoffsetFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(7usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(7usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeDashoffsetFromObject(&mut self, val: bool) { @@ -389,9 +256,7 @@ impl Weird { } #[inline] pub fn mStrokeWidthFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(8usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(8usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeWidthFromObject(&mut self, val: bool) { @@ -408,33 +273,62 @@ impl Weird { mStrokeDashoffsetFromObject: bool, mStrokeWidthFromObject: bool, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let mFillOpacitySource: u32 = - unsafe { ::std::mem::transmute(mFillOpacitySource) }; - mFillOpacitySource as u64 - }); - __bindgen_bitfield_unit.set(3usize, 3u8, { - let mStrokeOpacitySource: u32 = - unsafe { ::std::mem::transmute(mStrokeOpacitySource) }; - mStrokeOpacitySource as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let mStrokeDasharrayFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeDasharrayFromObject) }; - mStrokeDasharrayFromObject as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let mStrokeDashoffsetFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeDashoffsetFromObject) }; - mStrokeDashoffsetFromObject as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let mStrokeWidthFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeWidthFromObject) }; - mStrokeWidthFromObject as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let mFillOpacitySource: u32 = unsafe { + ::std::mem::transmute(mFillOpacitySource) + }; + mFillOpacitySource as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 3u8, + { + let mStrokeOpacitySource: u32 = unsafe { + ::std::mem::transmute(mStrokeOpacitySource) + }; + mStrokeOpacitySource as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let mStrokeDasharrayFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeDasharrayFromObject) + }; + mStrokeDasharrayFromObject as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let mStrokeDashoffsetFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeDashoffsetFromObject) + }; + mStrokeDashoffsetFromObject as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let mStrokeWidthFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeWidthFromObject) + }; + mStrokeWidthFromObject as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index b4f42791db02ffe1d6129cb39ee20978645a939e..aaeab668e1fb83ecfeea78fccd747aef896fc8fe 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -1,35 +1,21 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct UnknownUnits { pub _address: u8, } -#[test] -fn bindgen_test_layout_UnknownUnits() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(UnknownUnits)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(UnknownUnits)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of UnknownUnits"][::std::mem::size_of::() - 1usize]; + ["Alignment of UnknownUnits"][::std::mem::align_of::() - 1usize]; +}; pub type Float = f32; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PointTyped { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: F, pub y: F, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for PointTyped { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/win32-dtors.rs b/bindgen-tests/tests/expectations/tests/win32-dtors.rs new file mode 100644 index 0000000000000000000000000000000000000000..042aa8ceceafec92cd554e37ee3b819ead526c31 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/win32-dtors.rs @@ -0,0 +1,169 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default)] +pub struct CppObj { + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CppObj() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of CppObj"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of CppObj"); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + "Offset of field: CppObj::x", + ); +} +extern "C" { + #[link_name = "\u{1}??0CppObj@@QEAA@H@Z"] + pub fn CppObj_CppObj(this: *mut CppObj, x: ::std::os::raw::c_int); +} +extern "C" { + #[link_name = "\u{1}??1CppObj@@QEAA@XZ"] + pub fn CppObj_CppObj_destructor(this: *mut CppObj); +} +impl CppObj { + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + CppObj_CppObj(&mut __bindgen_tmp, x); + __bindgen_tmp + } + #[inline] + pub unsafe fn destruct(&mut self) { + CppObj_CppObj_destructor(self) + } +} +#[repr(C)] +pub struct CppObj2__bindgen_vtable(::std::os::raw::c_void); +#[repr(C)] +#[derive(Debug)] +pub struct CppObj2 { + pub vtable_: *const CppObj2__bindgen_vtable, + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CppObj2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of CppObj2"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj2"); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 8usize, + "Offset of field: CppObj2::x", + ); +} +extern "C" { + #[link_name = "\u{1}??0CppObj2@@QEAA@H@Z"] + pub fn CppObj2_CppObj2(this: *mut CppObj2, x: ::std::os::raw::c_int); +} +impl Default for CppObj2 { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +impl CppObj2 { + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + CppObj2_CppObj2(&mut __bindgen_tmp, x); + __bindgen_tmp + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj2@@UEAA@XZ"] + pub fn CppObj2_CppObj2_destructor(this: *mut CppObj2); +} +#[repr(C)] +#[derive(Debug)] +pub struct CppObj3 { + pub _base: CppObj2, + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CppObj3() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of CppObj3"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj3"); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 16usize, + "Offset of field: CppObj3::x", + ); +} +extern "C" { + #[link_name = "\u{1}??0CppObj3@@QEAA@H@Z"] + pub fn CppObj3_CppObj3(this: *mut CppObj3, x: ::std::os::raw::c_int); +} +impl Default for CppObj3 { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +impl CppObj3 { + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + CppObj3_CppObj3(&mut __bindgen_tmp, x); + __bindgen_tmp + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj3@@UEAA@XZ"] + pub fn CppObj3_CppObj3_destructor(this: *mut CppObj3); +} +#[repr(C)] +#[derive(Debug)] +pub struct CppObj4 { + pub _base: CppObj2, + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_CppObj4() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of CppObj4"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of CppObj4"); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 16usize, + "Offset of field: CppObj4::x", + ); +} +extern "C" { + #[link_name = "\u{1}??0CppObj4@@QEAA@H@Z"] + pub fn CppObj4_CppObj4(this: *mut CppObj4, x: ::std::os::raw::c_int); +} +impl Default for CppObj4 { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +impl CppObj4 { + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + CppObj4_CppObj4(&mut __bindgen_tmp, x); + __bindgen_tmp + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj4@@UEAA@XZ"] + pub fn CppObj4_CppObj4_destructor(this: *mut CppObj4); +} diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs index 502e12fe44cc79a9be1bb60d5dcffe8848ed857d..185b93580850602bb082276fd84b97786bf8e99b 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Foo { @@ -12,16 +6,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } impl Clone for Foo { fn clone(&self) -> Self { diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs new file mode 100644 index 0000000000000000000000000000000000000000..4741f029ffa37295f4ced440d14dbd670e22bd85 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target = "i686-pc-windows-msvc")] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); +} +extern "thiscall" { + #[link_name = "\u{1}?test@Foo@@QAEXXZ"] + pub fn Foo_test(this: *mut Foo); +} +extern "thiscall" { + #[link_name = "\u{1}?test2@Foo@@QAEHH@Z"] + pub fn Foo_test2( + this: *mut Foo, + var: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +impl Foo { + #[inline] + pub unsafe fn test(&mut self) { + Foo_test(self) + } + #[inline] + pub unsafe fn test2(&mut self, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int { + Foo_test2(self, var) + } +} diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 92bb13cc61474ffc9d58532718eda1a0f7d47d64..3c84de7b95388289e0007eb3eabf9c576245855f 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -1,30 +1,16 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_thiscall)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "thiscall" { #[link_name = "\u{1}?test@Foo@@QAEXXZ"] pub fn Foo_test(this: *mut Foo); @@ -42,10 +28,7 @@ impl Foo { Foo_test(self) } #[inline] - pub unsafe fn test2( - &mut self, - var: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn test2(&mut self, var: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_test2(self, var) } } diff --git a/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs index 131dbdf39f2a9ea2ecd8d94554d636acc6e1044c..fe64295a689cfab8aaff286fcf9c73b18247d1b3 100644 --- a/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs index 163741df6281c5faf51883567083fa24a8c19906..a262b78c59f9462f6a3c8d004e39fac2d0c2b2ff 100644 --- a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_vectorcall)] - extern "vectorcall" { #[link_name = "\u{1}test_vectorcall@@16"] pub fn test_vectorcall( diff --git a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs index 2a7d18025d4399bf4e88ff23fff9f6f7293bf2cd..cc82fd4daf87af99396c44ce8703aeefbf785abd 100644 --- a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn test_fn( a: f32, diff --git a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs index c4acdb3e91da3f4d5b9e7cc7222d2d1212ed7b64..f48e5f7f5c29ae24dd484d8a6c530a3699750268 100644 --- a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs @@ -1,25 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { - pub fn test_fn( - a: f32, - arr: *mut ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn test_fn(a: f32, arr: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } extern "C" { - pub fn test_fn2( - arr: *const f32, - b: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn test_fn2(arr: *const f32, b: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } pub type defArr = [::std::os::raw::c_char; 20usize]; -pub type foo = - ::std::option::Option; +pub type foo = ::std::option::Option< + unsafe extern "C" fn(a: *mut ::std::os::raw::c_char), +>; extern "C" { pub fn bar(a: *mut ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 54ed9fd4dd3ee2b380c223b3a4387f12cd796c9e..46b369b2f4c9dbeb0d164dc8b081388fe3b17700 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -1,39 +1,29 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - #[link_name = "\u{1}foo__extern"] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + #[link_name = "foo__extern"] pub fn foo() -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}bar__extern"] + #[link_name = "bar__extern"] pub fn bar() -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_ptr__extern"] + #[link_name = "takes_ptr__extern"] pub fn takes_ptr(arg: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_fn_ptr__extern"] + #[link_name = "takes_fn_ptr__extern"] pub fn takes_fn_ptr( f: ::std::option::Option< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >, ) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_fn__extern"] + #[link_name = "takes_fn__extern"] pub fn takes_fn( f: ::std::option::Option< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >, ) -> ::std::os::raw::c_int; } @@ -41,12 +31,61 @@ pub type func = ::std::option::Option< unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; extern "C" { - #[link_name = "\u{1}takes_alias__extern"] + #[link_name = "takes_alias__extern"] pub fn takes_alias(f: func) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_qualified__extern"] + #[link_name = "takes_qualified__extern"] pub fn takes_qualified( arg: *const *const ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; } +pub const foo_BAR: foo = 0; +pub type foo = ::std::os::raw::c_uint; +extern "C" { + #[link_name = "takes_enum__extern"] + pub fn takes_enum(f: foo) -> foo; +} +extern "C" { + #[link_name = "nevermore__extern"] + pub fn nevermore(); +} +extern "C" { + #[link_name = "takes_fn_with_no_args__extern"] + pub fn takes_fn_with_no_args( + f: ::std::option::Option ::std::os::raw::c_int>, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "no_extra_argument__extern"] + pub fn no_extra_argument(va: *mut __va_list_tag); +} +extern "C" { + #[link_name = "many_va_list__extern"] + pub fn many_va_list( + i: ::std::os::raw::c_int, + va1: *mut __va_list_tag, + va2: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn1__extern"] + pub fn wrap_as_variadic_fn1_wrapped( + i: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn2__extern"] + pub fn wrap_as_variadic_fn2_wrapped(i: ::std::os::raw::c_int, ...); +} +pub type __builtin_va_list = [__va_list_tag; 1usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __va_list_tag { + pub gp_offset: ::std::os::raw::c_uint, + pub fp_offset: ::std::os::raw::c_uint, + pub overflow_arg_area: *mut ::std::os::raw::c_void, + pub reg_save_area: *mut ::std::os::raw::c_void, + _unused: [u8; 0], +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs index 0eef6d2e78499df2b4bd0bdd44de918c7cb232cd..dfe2213ed4f27f09a942e03c0ce52bf85d712ae3 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -30,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} @@ -73,8 +67,7 @@ pub struct TErrorResult_DOMExceptionInfo { #[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: - __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, } impl Default for TErrorResult { diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs index d621b450a2e1046002a0ea8c55c5f1fe9beb49c9..5f64396f6b9978faaec980b754277e4ff6cea60e 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index 5864ba0a8d607482c21c9963c49de7f95c2919dc..2f5b4cc5ba508f3b4166904a41db231a280df75e 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -1,11 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern crate libloading; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct TestLib { __library: ::libloading::Library, pub foo: Result< @@ -16,9 +9,7 @@ pub struct TestLib { ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< @@ -34,9 +25,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; unsafe { Self::from_library(library) } } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -56,17 +45,10 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x, y) - } + unsafe { (self.foo.as_ref().expect("Expected function, got error."))(x, y) } } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { + unsafe { (self.bar.as_ref().expect("Expected function, got error."))(x) } } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs index 0fe8e254c3dcfd4dc64a8ecba1e3ae989a1d4c3f..c8f7241fcff92250307b37ea0c99f6d689d43b50 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { @@ -33,6 +27,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + unsafe { msg_send!(* self, method) } } } diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index d7d0f6613dcf041c224056c0e62a0dedbb552732..48fc0cb1d691cf2a4d24a4dd2cefc31b2f53c02b 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -42,49 +36,15 @@ pub struct dm_deps { pub filler: ::std::os::raw::c_uint, pub device: __IncompleteArrayField<::std::os::raw::c_ulonglong>, } -#[test] -fn bindgen_test_layout_dm_deps() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(dm_deps)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(dm_deps)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(count) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(filler) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(device) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of dm_deps"][::std::mem::size_of::() - 8usize]; + ["Alignment of dm_deps"][::std::mem::align_of::() - 8usize]; + ["Offset of field: dm_deps::count"][::std::mem::offset_of!(dm_deps, count) - 0usize]; + [ + "Offset of field: dm_deps::filler", + ][::std::mem::offset_of!(dm_deps, filler) - 4usize]; + [ + "Offset of field: dm_deps::device", + ][::std::mem::offset_of!(dm_deps, device) - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 4ba52498c4860c799cff3a4a904c111fbeb643e0..229a6ee4dbbdc86c328041643fa541db44a730ff 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -41,119 +35,81 @@ impl ::std::fmt::Debug for __IncompleteArrayField { pub struct ZeroSizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of ZeroSizedArray"][::std::mem::size_of::() - 0usize]; + ["Alignment of ZeroSizedArray"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ZeroSizedArray::arr", + ][::std::mem::offset_of!(ZeroSizedArray, arr) - 0usize]; +}; /// And nor should this get an `_address` field. #[repr(C)] #[derive(Debug, Default)] pub struct ContainsZeroSizedArray { pub zsa: ZeroSizedArray, } -#[test] -fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) - ); -} -/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted -/// either. +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContainsZeroSizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of ContainsZeroSizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsZeroSizedArray::zsa", + ][::std::mem::offset_of!(ContainsZeroSizedArray, zsa) - 0usize]; +}; +/** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted + either.*/ #[repr(C)] #[derive(Debug, Default)] pub struct InheritsZeroSizedArray { pub _base: ZeroSizedArray, } -#[test] -fn bindgen_test_layout_InheritsZeroSizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of InheritsZeroSizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of InheritsZeroSizedArray", + ][::std::mem::align_of::() - 1usize]; +}; /// And this should not get an `_address` field either. #[repr(C)] #[derive(Debug, Default)] pub struct DynamicallySizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DynamicallySizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of DynamicallySizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of DynamicallySizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: DynamicallySizedArray::arr", + ][::std::mem::offset_of!(DynamicallySizedArray, arr) - 0usize]; +}; /// No `_address` field here either. #[repr(C)] #[derive(Debug, Default)] pub struct ContainsDynamicallySizedArray { pub dsa: DynamicallySizedArray, } -#[test] -fn bindgen_test_layout_ContainsDynamicallySizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) - ); -} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + [ + "Size of ContainsDynamicallySizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of ContainsDynamicallySizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsDynamicallySizedArray::dsa", + ][::std::mem::offset_of!(ContainsDynamicallySizedArray, dsa) - 0usize]; +}; diff --git a/bindgen-tests/tests/headers/abi-override.h b/bindgen-tests/tests/headers/abi-override.h index cee72caeef9b923dd1cd34f2c9baf33f5aa225b5..578659733ec9165742a1d5ddf62f76b273fe49a2 100644 --- a/bindgen-tests/tests/headers/abi-override.h +++ b/bindgen-tests/tests/headers/abi-override.h @@ -1,5 +1,9 @@ -// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall +// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi --override-abi qux=system void foo(); void bar(); void baz(); +void qux(); + +typedef void (*boo)(); +typedef void (*foobar)(boo boo); diff --git a/bindgen-tests/tests/headers/alias_comments.h b/bindgen-tests/tests/headers/alias_comments.h new file mode 100644 index 0000000000000000000000000000000000000000..2547c3c1a2d55ab4099ba32e07bbb4911746da66 --- /dev/null +++ b/bindgen-tests/tests/headers/alias_comments.h @@ -0,0 +1,26 @@ +// bindgen-flags: --no-layout-tests + +/** + * This is Struct + */ +typedef struct { + /** + * This is field + */ + int field; +} Struct; + +/** + * This is AliasToStruct + */ +typedef Struct AliasToStruct; + +/** + * This is AliasToInt + */ +typedef int AliasToInt; + +/** + * This is AliasToAliasToInt + */ +typedef AliasToInt AliasToAliasToInt; diff --git a/bindgen-tests/tests/headers/allowlist_item.h b/bindgen-tests/tests/headers/allowlist_item.h new file mode 100644 index 0000000000000000000000000000000000000000..7e5e00d0e39c6a2b67872411a592e8d101919a44 --- /dev/null +++ b/bindgen-tests/tests/headers/allowlist_item.h @@ -0,0 +1,17 @@ +// bindgen-flags: --allowlist-item 'Foo.*' + +struct Foo { + int field; +}; + +struct Foo FooNew(int value); + +#define FooDefault 0 + +struct Bar { + int field; +}; + +struct Foo BarNew(int value); + +#define BarDefault 0 diff --git a/bindgen-tests/tests/headers/anon_enum_allowlist_item.h b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h new file mode 100644 index 0000000000000000000000000000000000000000..23caacc9a124683f32985026a25ff42ac91042af --- /dev/null +++ b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h @@ -0,0 +1,6 @@ +// bindgen-flags: --allowlist-item "NODE_.*" + +enum { + NODE_FLAG_FOO, + NODE_FLAG_BAR, +}; diff --git a/bindgen-tests/tests/headers/anon_enum_blocklist.h b/bindgen-tests/tests/headers/anon_enum_blocklist.h new file mode 100644 index 0000000000000000000000000000000000000000..61aa6e680c2b9207aef14de4a12f89c5922b59dc --- /dev/null +++ b/bindgen-tests/tests/headers/anon_enum_blocklist.h @@ -0,0 +1,11 @@ +// bindgen-flags: --blocklist-type "_bindgen_ty_1" + +enum { + FLAG_X, + FLAG_Y, +}; + +enum { + FLAG_Z, + FLAG_W, +}; diff --git a/bindgen-tests/tests/headers/bitfield_pragma_packed.h b/bindgen-tests/tests/headers/bitfield_pragma_packed.h index b4011ca8449d201a6997d2b13b4d7ab83bad66ce..c18b80ddfc250908bc126c786bcef3df5f4392a3 100644 --- a/bindgen-tests/tests/headers/bitfield_pragma_packed.h +++ b/bindgen-tests/tests/headers/bitfield_pragma_packed.h @@ -7,3 +7,14 @@ struct Struct { unsigned char e : 8; }; #pragma pack(pop) + +struct Inner { + unsigned short a: 16; + unsigned short b: 16; +}; + +#pragma pack(push, 1) +struct Outer { + struct Inner inner; +}; +#pragma pop diff --git a/bindgen-tests/tests/headers/blocklist-var.hpp b/bindgen-tests/tests/headers/blocklist-var.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3c70e6f0321e00f3077707a00a3cddc4cb3faa90 --- /dev/null +++ b/bindgen-tests/tests/headers/blocklist-var.hpp @@ -0,0 +1,3 @@ +// bindgen-flags: --blocklist-var should_be_blocked + +extern int should_be_blocked; diff --git a/bindgen-tests/tests/headers/blocklist_bitfield_unit.h b/bindgen-tests/tests/headers/blocklist_bitfield_unit.h new file mode 100644 index 0000000000000000000000000000000000000000..5f7d94ced9bd6c4f6eae83271d0d9a6526df9d3e --- /dev/null +++ b/bindgen-tests/tests/headers/blocklist_bitfield_unit.h @@ -0,0 +1,7 @@ +// bindgen-flags: --blocklist-type "__BindgenBitfieldUnit" --raw-line '#[path = "./struct_with_bitfields.rs"] mod bitfields;' --raw-line 'use bitfields::*;' +struct C { + unsigned char x; + unsigned b1 : 1; + unsigned b2 : 1; + unsigned baz; +}; diff --git a/bindgen-tests/tests/headers/c-unwind-abi-override.h b/bindgen-tests/tests/headers/c-unwind-abi-override.h new file mode 100644 index 0000000000000000000000000000000000000000..591f4b84ff3750b8281b30085dfe68617416b9c9 --- /dev/null +++ b/bindgen-tests/tests/headers/c-unwind-abi-override.h @@ -0,0 +1,5 @@ +// bindgen-flags: --override-abi="foo|bar=C-unwind" + +void foo(); +void bar(); +void baz(); diff --git a/bindgen-tests/tests/headers/const_array_typedef.h b/bindgen-tests/tests/headers/const_array_typedef.h new file mode 100644 index 0000000000000000000000000000000000000000..e5379c97ba3eee9b8e6e5ec19505d0944085e443 --- /dev/null +++ b/bindgen-tests/tests/headers/const_array_typedef.h @@ -0,0 +1,13 @@ +typedef struct { + int field; +} strct; + +typedef strct typ[1]; + +extern typ w; +extern strct *x; + +extern const typ y; +extern const strct *z; + +void function(const typ a, const strct *b); diff --git a/bindgen-tests/tests/headers/constructors.hpp b/bindgen-tests/tests/headers/constructors.hpp index d4174889172dddc81497445154ba3fbbef7a3add..2f8d57b00b350e20856fd1106cde877b665bb4a9 100644 --- a/bindgen-tests/tests/headers/constructors.hpp +++ b/bindgen-tests/tests/headers/constructors.hpp @@ -1,6 +1,6 @@ class TestOverload { - // This one shouldnt' be generated. + // This one shouldn't be generated. TestOverload(); public: TestOverload(int); diff --git a/bindgen-tests/tests/headers/constructors_1_33.hpp b/bindgen-tests/tests/headers/constructors_1_33.hpp index 7c6262d4172f77b859395454734249e155175132..e275f8907e7d72f0aa38fea08563afc4ad234948 100644 --- a/bindgen-tests/tests/headers/constructors_1_33.hpp +++ b/bindgen-tests/tests/headers/constructors_1_33.hpp @@ -1,7 +1,7 @@ // bindgen-flags: --rust-target 1.33 class TestOverload { - // This one shouldnt' be generated. + // This one shouldn't be generated. TestOverload(); public: /// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that. diff --git a/bindgen-tests/tests/headers/default_visibility_crate.h b/bindgen-tests/tests/headers/default_visibility_crate.h new file mode 100644 index 0000000000000000000000000000000000000000..c6f0be87c5ca757915bd6e1709ac1254f26815c1 --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_crate.h @@ -0,0 +1,12 @@ +// bindgen-flags: --no-layout-tests --default-visibility=crate + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen-tests/tests/headers/default_visibility_private.h b/bindgen-tests/tests/headers/default_visibility_private.h new file mode 100644 index 0000000000000000000000000000000000000000..7ba75f7cb8185cc7a86626fc347a4e2977b64fd9 --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_private.h @@ -0,0 +1,12 @@ +// bindgen-flags: --no-layout-tests --default-visibility=private + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h b/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h new file mode 100644 index 0000000000000000000000000000000000000000..875484099a1babafcb9ba3e93c0a1563089fe791 --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h @@ -0,0 +1,12 @@ +// bindgen-flags: --respect-cxx-access-specs --no-layout-tests --default-visibility=private + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_required.h b/bindgen-tests/tests/headers/dynamic_loading_variable_required.h new file mode 100644 index 0000000000000000000000000000000000000000..8e811bb3200dd701907487356afc65870fec3a62 --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_required.h @@ -0,0 +1,4 @@ +// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all + +int foo; +int *baz; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h b/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h new file mode 100644 index 0000000000000000000000000000000000000000..5ecad752edef8ba241bc7c54b77633875c83294c --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h @@ -0,0 +1,4 @@ +// bindgen-flags: --dynamic-loading TestLib + +int foo; +int *baz; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp b/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e27303063a6941708b3e7ea4bdb4f507876e5f2 --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib --allowlist-var foo --allowlist-var bar + +int foo; +int bar; +int baz; // should not be allowed \ No newline at end of file diff --git a/bindgen-tests/tests/headers/enum-doc.h b/bindgen-tests/tests/headers/enum-doc.h index 58e2c69e13bbdc84990b3683e39bc6d363e24234..7a2f425cda7d3d204fe912b0f48999e6adc2fec6 100644 --- a/bindgen-tests/tests/headers/enum-doc.h +++ b/bindgen-tests/tests/headers/enum-doc.h @@ -2,14 +2,14 @@ enum B { /// Document field with three slashes VAR_A = 0, - /** Document field with preceeding star */ + /** Document field with preceding star */ VAR_B = 1, - /*! Document field with preceeding exclamation */ + /*! Document field with preceding exclamation */ VAR_C = 2, VAR_D = 3, /**< Document field with following star */ VAR_E = 4, /*!< Document field with following exclamation */ /** - * Document field with preceeding star, with a loong long multiline + * Document field with preceding star, with a loong long multiline * comment. * * Very interesting documentation, definitely. diff --git a/bindgen-tests/tests/headers/field-visibility-callback.h b/bindgen-tests/tests/headers/field-visibility-callback.h new file mode 100644 index 0000000000000000000000000000000000000000..d2fe3ace80579222b41134d853cb0efeb1392259 --- /dev/null +++ b/bindgen-tests/tests/headers/field-visibility-callback.h @@ -0,0 +1,9 @@ +// bindgen-flags: --default-visibility private +// bindgen-parse-callbacks: field-visibility-default-private + +struct my_struct { + int a; + int private_b; + int c: 1; + int private_d: 1; +}; diff --git a/bindgen-tests/tests/headers/field-visibility.h b/bindgen-tests/tests/headers/field-visibility.h new file mode 100644 index 0000000000000000000000000000000000000000..adb73159c2873d1655945da0fc04cd8391fb88e1 --- /dev/null +++ b/bindgen-tests/tests/headers/field-visibility.h @@ -0,0 +1,10 @@ +// bindgen-flags: --default-visibility private --no-doc-comments + +struct my_struct1 { + int a: 1; +}; + +/**
*/ +struct my_struct2 { + int a: 1; +}; diff --git a/bindgen-tests/tests/headers/flexarray.hpp b/bindgen-tests/tests/headers/flexarray.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b698c38d1985499429a4dab1ae71c7ec78c4f2e2 --- /dev/null +++ b/bindgen-tests/tests/headers/flexarray.hpp @@ -0,0 +1,32 @@ +// bindgen-flags: --rust-target nightly --flexarray-dst --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(ptr_metadata, layout_for_ptr)]' + +struct flexarray { + int count; + int data[]; +}; + +struct flexarray_zero { + int count; + int data[0]; +}; + +template +struct flexarray_template { + int count; + T data[]; +}; + +struct flexarray_ref { + flexarray *things; +}; + +struct flexarray_bogus_zero_fam { + int count; + int data1[0]; + char data2[]; +}; + +struct flexarray_align { + int count; + int data[]; +} __attribute__((aligned(128))); diff --git a/bindgen-tests/tests/headers/float16.h b/bindgen-tests/tests/headers/float16.h new file mode 100644 index 0000000000000000000000000000000000000000..3b1058591d856fcfac6793d5db8ab7edffd9d099 --- /dev/null +++ b/bindgen-tests/tests/headers/float16.h @@ -0,0 +1,36 @@ +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq + +static __fp16 global; + +struct Test__Float16 +{ + __fp16 f; +}; + +struct Test__Float16Ref +{ + __fp16 *f; +}; + +/* +// This options are currently supported only on specific targets (eg. x86 with sse2) +_Float16 returns_f16(); + +void gets_f16(_Float16 arg); + +struct Test__Float16_Complex +{ + _Float16 _Complex mMember; +}; + +struct Test__Float16_ComplexPtr +{ + _Float16 _Complex *mMember; +}; + +_Float16 _Complex globalValueHalf; + +_Float16 _Complex returns_f16_complex(); + +void gets_f16_complex(_Float16 _Complex arg); +*/ \ No newline at end of file diff --git a/bindgen-tests/tests/headers/issue-2556.h b/bindgen-tests/tests/headers/issue-2556.h new file mode 100644 index 0000000000000000000000000000000000000000..bbb1b874ecc08f7376f1e6051dbf40e14ce31f30 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556.h @@ -0,0 +1,4 @@ +// bindgen-flags: --enable-cxx-namespaces -- -x c++ -Itests/headers -include tests/headers/issue-2556/nsStyleStruct.h -include tests/headers/issue-2556/LayoutConstants.h + +#include "issue-2556/nsSize.h" +#include "issue-2556/nsStyleStruct.h" diff --git a/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h b/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h new file mode 100644 index 0000000000000000000000000000000000000000..2ed1c864b2c43dc5d456b23e1bdf4521fc1da182 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h @@ -0,0 +1,7 @@ +#include "nsSize.h" + +namespace foo { + +static constexpr nsSize kFallbackIntrinsicSize(0, 0); + +} diff --git a/bindgen-tests/tests/headers/issue-2556/nsSize.h b/bindgen-tests/tests/headers/issue-2556/nsSize.h new file mode 100644 index 0000000000000000000000000000000000000000..8fe8b95023ae9a53292d46dfbe40767ac4a39eee --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/nsSize.h @@ -0,0 +1,6 @@ +#pragma once + +struct nsSize { + int width, height; + constexpr nsSize(int aWidth, int aHeight) : width(aWidth), height(aHeight) {} +}; diff --git a/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h b/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h new file mode 100644 index 0000000000000000000000000000000000000000..4c6eedfb9a5761d39275956f71c999cec0f706cf --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h @@ -0,0 +1,3 @@ +#pragma once + +#include "nsSize.h" diff --git a/bindgen-tests/tests/headers/issue-2566-cstr.h b/bindgen-tests/tests/headers/issue-2566-cstr.h new file mode 100644 index 0000000000000000000000000000000000000000..674b894024755d09ae66b4b9e5556af4fc6274db --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2566-cstr.h @@ -0,0 +1,4 @@ +// bindgen-flags: --generate-cstr + +/// We should _not_ generate a cstr for this because cstr shouldn't have interior nulls. +#define FOO "a\0b" diff --git a/bindgen-tests/tests/headers/issue-2566.h b/bindgen-tests/tests/headers/issue-2566.h new file mode 100644 index 0000000000000000000000000000000000000000..6e15ec1979ff6e01ad634475132907adeb65f645 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2566.h @@ -0,0 +1 @@ +#define FOO "a\0b" diff --git a/bindgen-tests/tests/headers/issue-2695.h b/bindgen-tests/tests/headers/issue-2695.h new file mode 100644 index 0000000000000000000000000000000000000000..4fbcc39bf87ae6979d5462138b1151895ca41469 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2695.h @@ -0,0 +1,10 @@ +// bindgen-flags: --explicit-padding + +#pragma pack(2) + +struct Test { + unsigned long x; + char a; + char b; + char c; +}; diff --git a/bindgen-tests/tests/headers/issue-537-repr-packed-n.h b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h index f4c0070a4a74fc2c95528ff9d862af05d264ac59..7beaf88383cf967175ed544802383a7525d456bf 100644 --- a/bindgen-tests/tests/headers/issue-537-repr-packed-n.h +++ b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h @@ -6,7 +6,7 @@ struct AlignedToOne { int i; } __attribute__ ((packed,aligned(1))); -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. struct AlignedToTwo { int i; } __attribute__ ((packed,aligned(2))); @@ -25,7 +25,7 @@ struct PackedToOne { #pragma pack(2) -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. struct PackedToTwo { int x; int y; diff --git a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp index f3467f4528f92b359c8cf7ba1bad551ab26d1451..b41b422d1e280e7551cb8bf7ca6e6510b0f5a922 100644 --- a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp +++ b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp @@ -4,5 +4,12 @@ template struct Foo { template using FirstAlias = typename T::Associated; template using SecondAlias = Foo>; + +#if 0 + // FIXME: This regressed sometime between libclang 9 and 16, though it + // never quite worked properly so... SecondAlias member; +#else + SecondAlias* member; +#endif }; diff --git a/bindgen-tests/tests/headers/issue-753.h b/bindgen-tests/tests/headers/issue-753.h new file mode 100644 index 0000000000000000000000000000000000000000..3a6c82528a6e20ffd9050ee510723a9062619112 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-753.h @@ -0,0 +1,12 @@ +// bindgen-flags: --clang-macro-fallback + +#ifndef ISSUE_753_H +#define ISSUE_753_H + +#define UINT32_C(c) c ## U + +#define CONST UINT32_C(5) +#define OTHER_CONST UINT32_C(6) +#define LARGE_CONST UINT32_C(6 << 8) + +#endif diff --git a/bindgen-tests/tests/headers/layout_eth_conf.h b/bindgen-tests/tests/headers/layout_eth_conf.h index 9446bffb4cba45825cd54b7a6b679640e21ff527..1c821c97695c06e1a85ff74454c01773424d3838 100644 --- a/bindgen-tests/tests/headers/layout_eth_conf.h +++ b/bindgen-tests/tests/headers/layout_eth_conf.h @@ -139,7 +139,7 @@ enum rte_eth_nb_pools { * of an Ethernet port. * * Using this feature, packets are routed to a pool of queues, based - * on the vlan id in the vlan tag, and then to a specific queue within + * on the vlan ID in the vlan tag, and then to a specific queue within * that pool, using the user priority vlan tag field. * * A default pool may be used, if desired, to route all traffic which @@ -151,7 +151,7 @@ struct rte_eth_vmdq_dcb_conf { uint8_t default_pool; /**< The default pool, if applicable */ uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; @@ -189,7 +189,7 @@ struct rte_eth_vmdq_rx_conf { uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ }; diff --git a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h index 48ba39ff874f97ca9614c227b24c02afcc81e48e..7da582ba19aa49998a8ebdaf2d08a58cec1e1924 100644 --- a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h +++ b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h @@ -140,7 +140,7 @@ enum rte_eth_nb_pools { * of an Ethernet port. * * Using this feature, packets are routed to a pool of queues, based - * on the vlan id in the vlan tag, and then to a specific queue within + * on the vlan ID in the vlan tag, and then to a specific queue within * that pool, using the user priority vlan tag field. * * A default pool may be used, if desired, to route all traffic which @@ -152,7 +152,7 @@ struct rte_eth_vmdq_dcb_conf { uint8_t default_pool; /**< The default pool, if applicable */ uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; @@ -190,7 +190,7 @@ struct rte_eth_vmdq_rx_conf { uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ }; diff --git a/bindgen-tests/tests/headers/noreturn.hpp b/bindgen-tests/tests/headers/noreturn.hpp index 4ce1e11e3fd6d62e95ad146ae21f012d0ab2f9a0..bf9d58c7fa7199899a331703c491577c44c870bd 100644 --- a/bindgen-tests/tests/headers/noreturn.hpp +++ b/bindgen-tests/tests/headers/noreturn.hpp @@ -2,3 +2,5 @@ _Noreturn void f(void); __attribute__((noreturn)) void g(void); [[noreturn]] void h(void); +void i(__attribute__((noreturn)) void (*arg)(void)); +__attribute__((noreturn)) void j(__attribute__((noreturn)) void (*arg)(void)); diff --git a/bindgen-tests/tests/headers/objc_escape.h b/bindgen-tests/tests/headers/objc_escape.h index 184d1da8b1b8a1a20631a98e69ac9e42507bc600..2d21bd5481dc03ea035dd98f0e0ef417db106ffb 100644 --- a/bindgen-tests/tests/headers/objc_escape.h +++ b/bindgen-tests/tests/headers/objc_escape.h @@ -3,4 +3,11 @@ @interface A -(void)f:(int)arg1 as:(int)arg2; +-(void)crate:(int)self; +@end + +@interface B + +@property(nonatomic, retain) id type; + @end diff --git a/bindgen-tests/tests/headers/prefix-link-name-c.h b/bindgen-tests/tests/headers/prefix-link-name-c.h new file mode 100644 index 0000000000000000000000000000000000000000..2432798fcec9477cf9c6dc9bd3747c11330b6a38 --- /dev/null +++ b/bindgen-tests/tests/headers/prefix-link-name-c.h @@ -0,0 +1,4 @@ +// bindgen-parse-callbacks: prefix-link-name-foo_ +// bindgen-flags: --prefix-link-name foo_ + +int bar(void); diff --git a/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp b/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4fd26123278bb97aee3a60486fa0f37c72ac8894 --- /dev/null +++ b/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp @@ -0,0 +1,8 @@ +// bindgen-parse-callbacks: prefix-link-name-foo_ +// bindgen-flags: --prefix-link-name foo_ + +namespace baz { + +int foo(); + +} // end namespace baz diff --git a/bindgen-tests/tests/headers/private_fields.hpp b/bindgen-tests/tests/headers/private_fields.hpp index 9d55ebcac8299136711a9134ae9118195d27fdf5..965acde9e89be3793a875f9b7e79a43720822170 100644 --- a/bindgen-tests/tests/headers/private_fields.hpp +++ b/bindgen-tests/tests/headers/private_fields.hpp @@ -1,4 +1,6 @@ // bindgen-flags: --respect-cxx-access-specs +// bindgen-parse-callbacks: field-visibility-default-public + class PubPriv { public: int x; @@ -41,4 +43,21 @@ class WithAnonStruct { class WithAnonUnion { union {}; -}; \ No newline at end of file +}; + +class Override { + public: + unsigned int a; + // override with annotation + /**
*/ + unsigned int b; + // override with callback + unsigned int private_c; + + unsigned int bf_a : 4; + // override with annotation + /**
*/ + unsigned int bf_b : 4; + // override with callback + unsigned int private_bf_c : 4; +}; diff --git a/bindgen-tests/tests/headers/ptr32-has-different-size.h b/bindgen-tests/tests/headers/ptr32-has-different-size.h new file mode 100644 index 0000000000000000000000000000000000000000..8cda702c5305790c2a32e9c6a00bad3d3f4f21ec --- /dev/null +++ b/bindgen-tests/tests/headers/ptr32-has-different-size.h @@ -0,0 +1,4 @@ +// bindgen-flags: -- -fms-extensions +typedef struct TEST_STRUCT { + void* __ptr32 ptr_32bit; +} TEST; diff --git a/bindgen-tests/tests/headers/redundant-packed-and-align.h b/bindgen-tests/tests/headers/redundant-packed-and-align.h new file mode 100644 index 0000000000000000000000000000000000000000..75e15e4139de2cb81eaf6bf2a084be63a1d4e255 --- /dev/null +++ b/bindgen-tests/tests/headers/redundant-packed-and-align.h @@ -0,0 +1,42 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +struct redundant_packed { + uint32_t a; + uint32_t b; +} __attribute__((packed, aligned(8))); + +struct redundant_packed_bitfield { + uint8_t a[3]; + uint8_t b0:1; + uint8_t b1:1; + uint32_t c; +} __attribute__((packed, aligned(8))); + + +union redundant_packed_union { + uint64_t a; + uint32_t b; +} __attribute__((packed, aligned(16))); + + +struct inner { + uint8_t a; +} __attribute__((packed, aligned(2))); + +struct outer_redundant_packed { + struct inner a[2]; + uint32_t b; +} __attribute__((packed, aligned(8))); + + +#pragma pack(2) + +struct redundant_pragma_packed { + uint8_t a; + uint16_t b; +} __attribute__((aligned(4))); + +#pragma pack() diff --git a/bindgen-tests/tests/headers/strings_array.h b/bindgen-tests/tests/headers/strings_array.h new file mode 100644 index 0000000000000000000000000000000000000000..6a61d710492206dd1b20ee1b455cfd81b7727009 --- /dev/null +++ b/bindgen-tests/tests/headers/strings_array.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.0 + +const char* MY_STRING_UTF8 = "Hello, world!"; +const char* MY_STRING_INTERIOR_NULL = "Hello,\0World!"; +const char* MY_STRING_NON_UTF8 = "ABCDE\xFF"; diff --git a/bindgen-tests/tests/headers/strings_cstr.h b/bindgen-tests/tests/headers/strings_cstr.h new file mode 100644 index 0000000000000000000000000000000000000000..8b1d40e689145789f19b42304cf8f47ba89c2dfc --- /dev/null +++ b/bindgen-tests/tests/headers/strings_cstr.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.59 --generate-cstr + +const char* MY_STRING_UTF8 = "Hello, world!"; +const char* MY_STRING_INTERIOR_NULL = "Hello,\0World!"; +const char* MY_STRING_NON_UTF8 = "ABCDE\xFF"; diff --git a/bindgen-tests/tests/headers/template-param-usage-7.hpp b/bindgen-tests/tests/headers/template-param-usage-7.hpp index 99d4cc71b4507a8a3300ead67869a09f28062f92..3d70cee1451c9ff3e4b8280d1ed1075986001c4e 100644 --- a/bindgen-tests/tests/headers/template-param-usage-7.hpp +++ b/bindgen-tests/tests/headers/template-param-usage-7.hpp @@ -6,5 +6,5 @@ class DoesNotUseU { V v; }; -// The bool should go away becuase U is not used. +// The bool should go away because U is not used. using Alias = DoesNotUseU; diff --git a/bindgen-tests/tests/headers/win32-dtors.hpp b/bindgen-tests/tests/headers/win32-dtors.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dc9b0fdc6e5fb57422260d29d690e43af2ebbf59 --- /dev/null +++ b/bindgen-tests/tests/headers/win32-dtors.hpp @@ -0,0 +1,29 @@ +// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc + +struct CppObj { + int x; + + CppObj(int x); + ~CppObj(); +}; + +struct CppObj2 { + int x; + + CppObj2(int x); + virtual ~CppObj2(); +}; + +struct CppObj3 : CppObj2 { + int x; + + CppObj3(int x); + virtual ~CppObj3(); +}; + +struct CppObj4 : CppObj2 { + int x; + + CppObj4(int x); + ~CppObj4(); +}; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/win32-thiscall_1_73.hpp b/bindgen-tests/tests/headers/win32-thiscall_1_73.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8c240055b26c47cddc0c0001482f5ce8fc322395 --- /dev/null +++ b/bindgen-tests/tests/headers/win32-thiscall_1_73.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --rust-target=1.73 --raw-line '#![cfg(target = "i686-pc-windows-msvc")]' -- --target=i686-pc-windows-msvc + +class Foo { + public: + void test(); + int test2(int var); +}; diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 8b90c7bc3819136107258f5f04a120a24a501da0..2be7bd93d95daeda09e042199515006ea4e0b2dc 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -1,8 +1,16 @@ // bindgen-flags: --experimental --wrap-static-fns +// bindgen-parse-callbacks: wrap-as-variadic-fn + +// to avoid polluting the expectation tests we put the stdarg.h behind a conditional +// variable only used in bindgen-integration +#ifdef USE_VA_HEADER +#include +#endif static inline int foo() { return 11; } +static int bar(); static int bar() { return 1; } @@ -31,3 +39,48 @@ static inline int takes_alias(func f) { static inline int takes_qualified(const int *const *arg) { return **arg; } + +enum foo { + BAR = 0x0, +}; + +static inline enum foo takes_enum(const enum foo f) { + return f; +} + +static inline void nevermore() { + while (1) { } +} + +static inline int takes_fn_with_no_args(int(f)(void)) { + return f(); +} + +static inline int variadic(int x, ...) { + return x; +} + +static inline void no_extra_argument(__builtin_va_list va) {} + +static inline int many_va_list(int i, __builtin_va_list va1, __builtin_va_list va2) { + return i; +} + +#ifndef USE_VA_HEADER +static inline int wrap_as_variadic_fn1(int i, __builtin_va_list va) { + return i; +} + +static inline void wrap_as_variadic_fn2(int i, __builtin_va_list va) {} +#else +static inline int wrap_as_variadic_fn1(int i, va_list va) { + int res = 0; + + for (int j = 0; j < i; j++) + res += (int) va_arg(va, int); + + return res; +} + +static inline void wrap_as_variadic_fn2(int i, va_list va) {} +#endif diff --git a/bindgen-tests/tests/macro_fallback_test_headers/another_header.h b/bindgen-tests/tests/macro_fallback_test_headers/another_header.h new file mode 100644 index 0000000000000000000000000000000000000000..b0c40eb43fe454851e9fc262ec2ed5e70fea0285 --- /dev/null +++ b/bindgen-tests/tests/macro_fallback_test_headers/another_header.h @@ -0,0 +1,10 @@ +#ifndef ANOTHER_HEADER_H +#define ANOTHER_HEADER_H + +#include + +#define SHOULD_NOT_GENERATE UINT64_C(~0) +#define MY_CONST UINT32_C(69) +#define NEGATIVE ~0 + +#endif diff --git a/bindgen-tests/tests/macro_fallback_test_headers/one_header.h b/bindgen-tests/tests/macro_fallback_test_headers/one_header.h new file mode 100644 index 0000000000000000000000000000000000000000..5058814bba2c5b9cef5a8cd3086349dd1fd9e2be --- /dev/null +++ b/bindgen-tests/tests/macro_fallback_test_headers/one_header.h @@ -0,0 +1,8 @@ +#ifndef ONE_HEADER_H +#define ONE_HEADER_H + +#include + +#define THE_CONST UINT32_C(28) + +#endif diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 00967fe8d7b51a9063d4b89d103e270ba49c1edb..ee31d56e493240129e4f8c693827f14ac693dae0 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -1,4 +1,5 @@ use bindgen::callbacks::*; +use bindgen::FieldVisibilityKind; #[derive(Debug)] pub struct RemovePrefixParseCallback { @@ -31,6 +32,30 @@ impl ParseCallbacks for RemovePrefixParseCallback { } } +#[derive(Debug)] +pub struct PrefixLinkNameParseCallback { + pub prefix: Option, +} + +impl PrefixLinkNameParseCallback { + pub fn new(prefix: &str) -> Self { + PrefixLinkNameParseCallback { + prefix: Some(prefix.to_string()), + } + } +} + +impl ParseCallbacks for PrefixLinkNameParseCallback { + fn generated_link_name_override( + &self, + item_info: ItemInfo, + ) -> Option { + self.prefix + .as_deref() + .map(|prefix| format!("{}{}", prefix, item_info.name)) + } +} + #[derive(Debug)] struct EnumVariantRename; @@ -62,20 +87,67 @@ impl ParseCallbacks for BlocklistedTypeImplementsTrait { } } +#[derive(Debug)] +struct FieldVisibility { + default: FieldVisibilityKind, +} + +/// Implements the `field_visibility` function of the trait by checking if the +/// field name starts with `private_`. If it does it makes it private, if it +/// doesn't it makes it public, taking into account the default visibility. +impl ParseCallbacks for FieldVisibility { + fn field_visibility( + &self, + FieldInfo { field_name, .. }: FieldInfo, + ) -> Option { + match (self.default, field_name.starts_with("private_")) { + (FieldVisibilityKind::Private, false) => { + Some(FieldVisibilityKind::Public) + } + (FieldVisibilityKind::Public, true) => { + Some(FieldVisibilityKind::Private) + } + (FieldVisibilityKind::PublicCrate, _) => unimplemented!(), + _ => None, + } + } +} + +#[derive(Debug)] +pub(super) struct WrapAsVariadicFn; + +impl ParseCallbacks for WrapAsVariadicFn { + fn wrap_as_variadic_fn(&self, name: &str) -> Option { + Some(name.to_owned() + "_wrapped") + } +} + pub fn lookup(cb: &str) -> Box { match cb { "enum-variant-rename" => Box::new(EnumVariantRename), "blocklisted-type-implements-trait" => { Box::new(BlocklistedTypeImplementsTrait) } + "wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn), call_back => { - if call_back.starts_with("remove-function-prefix-") { - let prefix = call_back - .split("remove-function-prefix-") - .last() - .to_owned(); - let lnopc = RemovePrefixParseCallback::new(prefix.unwrap()); + if let Some(prefix) = + call_back.strip_prefix("remove-function-prefix-") + { + let lnopc = RemovePrefixParseCallback::new(prefix); Box::new(lnopc) + } else if let Some(prefix) = + call_back.strip_prefix("prefix-link-name-") + { + let plnpc = PrefixLinkNameParseCallback::new(prefix); + Box::new(plnpc) + } else if let Some(default) = + call_back.strip_prefix("field-visibility-default-") + { + Box::new(FieldVisibility { + default: default.parse().expect( + "unable to parse field-visibility-default callback", + ), + }) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) } diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 455a8240392b8f7d6b9d4c0c4b7fa2e8a05ff1ab..0fafac97f344fa4174560aa0faa05c714068f145 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "quickchecking" description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script" -version = "0.1.0" -authors = ["Shea Newton "] +version = "0.0.0" +publish = false +rust-version = "1.70" +edition = "2018" [lib] name = "quickchecking" @@ -13,11 +15,9 @@ name = "quickchecking" path = "src/bin.rs" [dependencies] -clap = "2.28" -lazy_static = "1.0" -quickcheck = "0.4" -rand = "0.3" -tempdir = "0.3" +clap = "4" +quickcheck = "1.0" +tempfile = "3" [features] # No features by default. diff --git a/bindgen-tests/tests/quickchecking/README.md b/bindgen-tests/tests/quickchecking/README.md index d3cfe17071344a3e7e7a1325e71241299daf2aa5..03aa0f231312aada136441fa3998aca5ad2373e9 100644 --- a/bindgen-tests/tests/quickchecking/README.md +++ b/bindgen-tests/tests/quickchecking/README.md @@ -1,7 +1,7 @@ # Property tests for `bindgen` with `quickchecking` `quickchecking` generates random C headers to test `bindgen` -using the [`quickcheck`][quickcheck] property testing crate. When testing +using the [`quickcheck`] property testing crate. When testing `bindgen` with `quickchecking`, the generated header files are passed to `bindgen`'s `csmith-fuzzing/predicate.py` script. If that script fails, `quickchecking` panics, and you can report an issue containing the test case! @@ -36,4 +36,5 @@ Run `quickchecking` binary to generate and test fuzzed C headers with ``` $ cargo run --bin=quickchecking -- -h ``` -[quickcheck]: https://github.com/BurntSushi/quickcheck + +[`quickcheck`]: https://github.com/BurntSushi/quickcheck diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index f2b52e828f8d7f06b9975c4c53dbd964e5edc446..fcd56652be1c63b28824f89e2d3cf17c524d7211 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -14,42 +14,41 @@ //! ``` //! #![deny(missing_docs)] -extern crate clap; -extern crate quickchecking; -use clap::{App, Arg}; -use std::path::Path; +use clap::{Arg, ArgAction, Command}; +use std::path::PathBuf; -// Validate CLI argument input for generation range. -fn validate_generate_range(v: String) -> Result<(), String> { +// Parse CLI argument input for generation range. +fn parse_generate_range(v: &str) -> Result { match v.parse::() { - Ok(_) => Ok(()), + Ok(v) => Ok(v), Err(_) => Err(String::from( "Generate range could not be converted to a usize.", )), } } -// Validate CLI argument input for tests count. -fn validate_tests_count(v: String) -> Result<(), String> { - match v.parse::() { - Ok(_) => Ok(()), +// Parse CLI argument input for tests count. +fn parse_tests_count(v: &str) -> Result { + match v.parse::() { + Ok(v) => Ok(v), Err(_) => Err(String::from( "Tests count could not be converted to a usize.", )), } } -// Validate CLI argument input for fuzzed headers output path. -fn validate_path(v: String) -> Result<(), String> { - match Path::new(&v).is_dir() { - true => Ok(()), +// Parse CLI argument input for fuzzed headers output path. +fn parse_path(v: &str) -> Result { + let path = PathBuf::from(v); + match path.is_dir() { + true => Ok(path), false => Err(String::from("Provided directory path does not exist.")), } } fn main() { - let matches = App::new("quickchecking") + let matches = Command::new("quickchecking") .version("0.2.0") .about( "Bindgen property tests with quickcheck. \ @@ -57,20 +56,20 @@ fn main() { csmith/predicate.py script", ) .arg( - Arg::with_name("path") - .short("p") + Arg::new("path") + .short('p') .long("path") .value_name("PATH") .help( "Optional. Preserve generated headers for inspection, \ provide directory path for header output. [default: None] ", ) - .takes_value(true) - .validator(validate_path), + .action(ArgAction::Set) + .value_parser(parse_path), ) .arg( - Arg::with_name("range") - .short("r") + Arg::new("range") + .short('r') .long("range") .value_name("RANGE") .help( @@ -80,13 +79,13 @@ fn main() { to grow much for execution time to increase \ significantly.", ) - .takes_value(true) + .action(ArgAction::Set) .default_value("32") - .validator(validate_generate_range), + .value_parser(parse_generate_range), ) .arg( - Arg::with_name("count") - .short("c") + Arg::new("count") + .short('c') .long("count") .value_name("COUNT") .help( @@ -96,17 +95,15 @@ fn main() { large. Increase this number if you're willing to \ wait a while.", ) - .takes_value(true) + .action(ArgAction::Set) .default_value("2") - .validator(validate_tests_count), + .value_parser(parse_tests_count), ) .get_matches(); - let output_path: Option<&str> = matches.value_of("path"); - let generate_range: usize = - matches.value_of("range").unwrap().parse::().unwrap(); - let tests: usize = - matches.value_of("count").unwrap().parse::().unwrap(); + let output_path = matches.get_one::("path").map(PathBuf::as_path); + let generate_range = *matches.get_one::("range").unwrap(); + let tests = *matches.get_one::("count").unwrap(); quickchecking::test_bindgen(generate_range, tests, output_path) } diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index 4188f8f5575e302e2a347fa28a3523db347834c9..569ed6e09bb6d0b629e720c701fe8e35af9be0f8 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -1,5 +1,4 @@ -use quickcheck::{Arbitrary, Gen, StdGen}; -use rand::thread_rng; +use quickcheck::{Arbitrary, Gen}; use std::fmt; /// BaseTypeC is used in generation of C headers to represent the C language's @@ -182,8 +181,8 @@ impl MakeUnique for DeclarationC { /// A qucickcheck trait for describing how DeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationC { - fn arbitrary(g: &mut G) -> DeclarationC { - match g.gen_range(0, 5) { + fn arbitrary(g: &mut Gen) -> DeclarationC { + match gen_range(g, 0, 5) { 0 => DeclarationC::FunctionDecl(FunctionPrototypeC::arbitrary(g)), 1 => DeclarationC::FunctionPtrDecl( FunctionPointerDeclarationC::arbitrary(g), @@ -214,7 +213,7 @@ impl fmt::Display for DeclarationC { /// A qucickcheck trait for describing how DeclarationListC types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationListC { - fn arbitrary(g: &mut G) -> DeclarationListC { + fn arbitrary(g: &mut Gen) -> DeclarationListC { DeclarationListC { decls: Arbitrary::arbitrary(g), } @@ -232,10 +231,10 @@ impl fmt::Display for DeclarationListC { } } -/// A qucickcheck trait for describing how BaseTypeC types can be +/// A quickcheck trait for describing how BaseTypeC types can be /// randomly generated and shrunk. impl Arbitrary for BaseTypeC { - fn arbitrary(g: &mut G) -> BaseTypeC { + fn arbitrary(g: &mut Gen) -> BaseTypeC { // Special case `long double` until issue #550 is resolved. let base_type = vec![ "char", @@ -286,7 +285,7 @@ impl fmt::Display for BaseTypeC { /// A qucickcheck trait for describing how TypeQualifierC types can be /// randomly generated and shrunk. impl Arbitrary for TypeQualifierC { - fn arbitrary(g: &mut G) -> TypeQualifierC { + fn arbitrary(g: &mut Gen) -> TypeQualifierC { let qualifier = vec!["const", ""]; TypeQualifierC { def: String::from(*g.choose(&qualifier).unwrap()), @@ -304,10 +303,10 @@ impl fmt::Display for TypeQualifierC { /// A qucickcheck trait for describing how PointerLevelC types can be /// randomly generated and shrunk. impl Arbitrary for PointerLevelC { - fn arbitrary(g: &mut G) -> PointerLevelC { + fn arbitrary(g: &mut Gen) -> PointerLevelC { PointerLevelC { // 16 is an arbitrary "not too big" number for capping pointer level. - def: (0..g.gen_range(0, 16)).map(|_| "*").collect::(), + def: (0..gen_range(g, 0, 16)).map(|_| "*").collect::(), } } } @@ -322,16 +321,16 @@ impl fmt::Display for PointerLevelC { /// A qucickcheck trait for describing how ArrayDimensionC types can be /// randomly generated and shrunk. impl Arbitrary for ArrayDimensionC { - fn arbitrary(g: &mut G) -> ArrayDimensionC { + fn arbitrary(g: &mut Gen) -> ArrayDimensionC { // Keep these small, clang complains when they get too big. - let dimensions = g.gen_range(0, 5); + let dimensions = gen_range(g, 0, 5); let mut def = String::new(); - let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays")); + let lower_bound = u64::from(cfg!(feature = "zero-sized-arrays")); for _ in 1..dimensions { // 16 is an arbitrary "not too big" number for capping array size. - def += &format!("[{}]", g.gen_range(lower_bound, 16)); + def += &format!("[{}]", gen_range(g, lower_bound, 16)); } ArrayDimensionC { def } } @@ -355,7 +354,7 @@ impl MakeUnique for BasicTypeDeclarationC { /// A qucickcheck trait for describing how BasicTypeDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for BasicTypeDeclarationC { - fn arbitrary(g: &mut G) -> BasicTypeDeclarationC { + fn arbitrary(g: &mut Gen) -> BasicTypeDeclarationC { BasicTypeDeclarationC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -392,12 +391,12 @@ impl MakeUnique for StructDeclarationC { /// A qucickcheck trait for describing how StructDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for StructDeclarationC { - fn arbitrary(g: &mut G) -> StructDeclarationC { + fn arbitrary(g: &mut Gen) -> StructDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = - Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); + Arbitrary::arbitrary(&mut Gen::new(reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; for (i, decl) in decl_list.decls.iter_mut().enumerate() { @@ -440,12 +439,12 @@ impl MakeUnique for UnionDeclarationC { /// A qucickcheck trait for describing how UnionDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for UnionDeclarationC { - fn arbitrary(g: &mut G) -> UnionDeclarationC { + fn arbitrary(g: &mut Gen) -> UnionDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = - Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); + Arbitrary::arbitrary(&mut Gen::new(reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; for (i, decl) in decl_list.decls.iter_mut().enumerate() { @@ -488,7 +487,7 @@ impl MakeUnique for FunctionPointerDeclarationC { /// A qucickcheck trait for describing how FunctionPointerDeclarationC types can /// be randomly generated and shrunk. impl Arbitrary for FunctionPointerDeclarationC { - fn arbitrary(g: &mut G) -> FunctionPointerDeclarationC { + fn arbitrary(g: &mut Gen) -> FunctionPointerDeclarationC { FunctionPointerDeclarationC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -525,7 +524,7 @@ impl MakeUnique for FunctionPrototypeC { /// A qucickcheck trait for describing how FunctionPrototypeC types can be /// randomly generated and shrunk. impl Arbitrary for FunctionPrototypeC { - fn arbitrary(g: &mut G) -> FunctionPrototypeC { + fn arbitrary(g: &mut Gen) -> FunctionPrototypeC { FunctionPrototypeC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -554,7 +553,7 @@ impl fmt::Display for FunctionPrototypeC { /// A qucickcheck trait for describing how ParameterC types can be /// randomly generated and shrunk. impl Arbitrary for ParameterC { - fn arbitrary(g: &mut G) -> ParameterC { + fn arbitrary(g: &mut Gen) -> ParameterC { ParameterC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -577,7 +576,7 @@ impl fmt::Display for ParameterC { /// A qucickcheck trait for describing how ParameterListC types can be /// randomly generated and shrunk. impl Arbitrary for ParameterListC { - fn arbitrary(g: &mut G) -> ParameterListC { + fn arbitrary(g: &mut Gen) -> ParameterListC { ParameterListC { params: Arbitrary::arbitrary(g), } @@ -601,7 +600,7 @@ impl fmt::Display for ParameterListC { /// A qucickcheck trait for describing how HeaderC types can be /// randomly generated and shrunk. impl Arbitrary for HeaderC { - fn arbitrary(g: &mut G) -> HeaderC { + fn arbitrary(g: &mut Gen) -> HeaderC { let mut decl_list: DeclarationListC = Arbitrary::arbitrary(g); for (i, decl) in decl_list.decls.iter_mut().enumerate() { decl.make_unique(i); @@ -628,3 +627,9 @@ impl fmt::Debug for HeaderC { write!(f, "{}", self) } } + +/// FIXME: is this actually uniform? +fn gen_range(gen: &mut Gen, lo: u64, hi: u64) -> u64 { + let len = hi - lo; + (u64::arbitrary(gen) % len) + lo +} diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 75bfc2376b4aa4e4cc34e07135692adbef13da23..d23ea792aa6188bda58ccbb9dfab514f2ab2670a 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -3,38 +3,27 @@ //! ## Example //! //! ```rust -//! extern crate quickcheck; -//! extern crate quickchecking; -//! extern crate rand; -//! use quickcheck::{Arbitrary, Gen, StdGen}; +//! use quickcheck::{Arbitrary, Gen}; //! use quickchecking::fuzzers; -//! use rand::thread_rng; //! //! fn main() { //! let generate_range: usize = 10; // Determines things like the length of //! // arbitrary vectors generated. //! let header = fuzzers::HeaderC::arbitrary( -//! &mut StdGen::new(thread_rng(), generate_range)); +//! &mut Gen::new(generate_range)); //! println!("{}", header); //! } //! ``` -//! #![deny(missing_docs)] -#[macro_use] -extern crate lazy_static; -extern crate quickcheck; -extern crate rand; -extern crate tempdir; -use quickcheck::{QuickCheck, StdGen, TestResult}; -use rand::thread_rng; +use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; use std::fs::File; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::{Command, Output}; use std::sync::Mutex; -use tempdir::TempDir; +use tempfile::Builder; /// Contains definitions of and impls for types used to fuzz C declarations. pub mod fuzzers; @@ -46,17 +35,14 @@ struct Context { } // Initialize global context. -lazy_static! { - static ref CONTEXT: Mutex = - Mutex::new(Context { output_path: None }); -} +static CONTEXT: Mutex = Mutex::new(Context { output_path: None }); // Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns // output of the associated command. fn run_predicate_script( header: fuzzers::HeaderC, ) -> Result> { - let dir = TempDir::new("bindgen_prop")?; + let dir = Builder::new().prefix("bindgen_prop").tempdir()?; let header_path = dir.path().join("prop_test.h"); let mut header_file = File::create(&header_path)?; @@ -86,7 +72,7 @@ fn run_predicate_script( .output()?; } - Ok(Command::new(&predicate_script_path_string) + Ok(Command::new(predicate_script_path_string) .arg(&header_path_string) .output()?) } @@ -110,16 +96,15 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { /// to the `csmith-fuzzing/predicate.py` script. pub fn test_bindgen( generate_range: usize, - tests: usize, - output_path: Option<&str>, + tests: u64, + output_path: Option<&Path>, ) { if let Some(path) = output_path { - CONTEXT.lock().unwrap().output_path = - Some(String::from(PathBuf::from(path).to_str().unwrap())); + CONTEXT.lock().unwrap().output_path = Some(path.display().to_string()); } QuickCheck::new() .tests(tests) - .gen(StdGen::new(thread_rng(), generate_range)) + .gen(Gen::new(generate_range)) .quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult) } diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index 0d43f30050392addc80b36af17b139cad87fd4f8..0735a70c4751051f4abfd0c1c6660fe0fc1272a2 100644 --- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -1,96 +1,90 @@ -extern crate quickcheck; -extern crate quickchecking; -extern crate rand; - -use quickcheck::{Arbitrary, StdGen}; +use quickcheck::{Arbitrary, Gen}; use quickchecking::fuzzers::{ ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC, DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, HeaderC, ParameterC, ParameterListC, PointerLevelC, StructDeclarationC, TypeQualifierC, UnionDeclarationC, }; -use rand::thread_rng; - #[test] fn test_declaraion_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: DeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_declaraion_list_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: DeclarationListC = Arbitrary::arbitrary(gen); } #[test] fn test_base_type_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: BaseTypeC = Arbitrary::arbitrary(gen); } #[test] fn test_type_qualifier_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: TypeQualifierC = Arbitrary::arbitrary(gen); } #[test] fn test_pointer_level_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: PointerLevelC = Arbitrary::arbitrary(gen); } #[test] fn test_array_dimension_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ArrayDimensionC = Arbitrary::arbitrary(gen); } #[test] fn test_basic_type_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_struct_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: StructDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_union_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: UnionDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_pointer_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_prototype_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: FunctionPrototypeC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ParameterC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_list_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ParameterListC = Arbitrary::arbitrary(gen); } #[test] fn test_header_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: HeaderC = Arbitrary::arbitrary(gen); } diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs index 52b96355e0c2c9dcbeb3b4ad14d729826b22ed44..7b94e2989e8b22931c2f39df2e9a4e5d4ee40893 100755 --- a/bindgen-tests/tests/stylo_sanity.rs +++ b/bindgen-tests/tests/stylo_sanity.rs @@ -1,7 +1,3 @@ -// Don't want to copy that nasty `cfg` below... -#[allow(unused_extern_crates)] -extern crate bindgen; - /// A sanity test that we can generate bindings for Stylo. /// /// We don't assert on expected output because its just too big. The output will @@ -14,10 +10,13 @@ extern crate bindgen; /// how long bindings generation takes for Stylo. Stylo bindings generation /// takes too long to be a proper `#[bench]`. #[test] -#[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))] +#[cfg(not(any( + debug_assertions, + feature = "__testing_only_extra_assertions", +)))] #[cfg(any( - feature = "testing_only_libclang_5", - feature = "testing_only_libclang_9" + feature = "__testing_only_libclang_9", + feature = "__testing_only_libclang_16" ))] fn sanity_check_can_generate_stylo_bindings() { use std::time::Instant; diff --git a/bindgen-tests/tests/test-one.sh b/bindgen-tests/tests/test-one.sh index 163d23a2003a7dfb502784ea197a7796ea8557bb..5ab6e9a4680782d554a255414b0d8412e6b14659 100755 --- a/bindgen-tests/tests/test-one.sh +++ b/bindgen-tests/tests/test-one.sh @@ -45,7 +45,7 @@ TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX) FLAGS="$(grep "// bindgen-flags: " "$TEST" || echo)" FLAGS="${FLAGS/\/\/ bindgen\-flags:/}" # Prepend the default flags added in test.rs's `create_bindgen_builder`. -FLAGS="--rustfmt-bindings --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" +FLAGS="--with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" eval ../target/debug/bindgen \ @@ -53,11 +53,10 @@ eval ../target/debug/bindgen \ --emit-ir \ --emit-ir-graphviz ir.dot \ --emit-clang-ast \ + --formatter prettyplease \ -o "\"$BINDINGS\"" \ $FLAGS -rustup run nightly rustfmt "$BINDINGS" || true - dot -Tpng ir.dot -o ir.png echo @@ -80,8 +79,6 @@ EXPECTED=${TEST/headers/expectations\/tests} EXPECTED=${EXPECTED/.hpp/.rs} EXPECTED=${EXPECTED/.h/.rs} -rustup run nightly rustfmt "$EXPECTED" || true - # Don't exit early if there is a diff. diff -U8 "$EXPECTED" "$BINDINGS" || true diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index ed8566c607771b955d65d12c6db5d5ee96083671..14988e463f55fc217a023bd71f81302934927d3d 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -1,17 +1,11 @@ -extern crate bindgen; -extern crate clap; -extern crate diff; -#[cfg(feature = "logging")] -extern crate env_logger; -extern crate shlex; - use bindgen::{clang_version, Builder}; +use owo_colors::{OwoColorize, Style}; +use similar::{ChangeTag, TextDiff}; use std::env; +use std::fmt; use std::fs; -use std::io::{self, BufRead, BufReader, Error, ErrorKind, Read, Write}; +use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write}; use std::path::{Path, PathBuf}; -use std::process; -use std::sync::Once; use crate::options::builder_from_flags; @@ -20,100 +14,14 @@ mod options; mod parse_callbacks; -// Run `rustfmt` on the given source string and return a tuple of the formatted -// bindings, and rustfmt's stderr. -fn rustfmt(source: String) -> (String, String) { - static CHECK_RUSTFMT: Once = Once::new(); - - CHECK_RUSTFMT.call_once(|| { - if env::var_os("RUSTFMT").is_some() { - return; - } +// Format the given source string. It can fail if the source string does not contain syntactically +// valid Rust. +fn format_code>(source: S) -> syn::Result { + use prettyplease::unparse; + use syn::{parse_str, File}; - let mut rustfmt = { - let mut p = process::Command::new("rustup"); - p.args(["run", "nightly", "rustfmt", "--version"]); - p - }; - - let have_working_rustfmt = rustfmt - .stdout(process::Stdio::null()) - .stderr(process::Stdio::null()) - .status() - .ok() - .map_or(false, |status| status.success()); - - if !have_working_rustfmt { - panic!( - " -The latest `rustfmt` is required to run the `bindgen` test suite. Install -`rustfmt` with: - - $ rustup update nightly - $ rustup component add rustfmt --toolchain nightly -" - ); - } - }); - - let mut child = match env::var_os("RUSTFMT") { - Some(r) => process::Command::new(r), - None => { - let mut p = process::Command::new("rustup"); - p.args(["run", "nightly", "rustfmt"]); - p - } - }; - - let mut child = child - .args([ - "--config-path", - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/rustfmt.toml"), - ]) - .stdin(process::Stdio::piped()) - .stdout(process::Stdio::piped()) - .stderr(process::Stdio::piped()) - .spawn() - .expect("should spawn `rustup run nightly rustfmt`"); - - let mut stdin = child.stdin.take().unwrap(); - let mut stdout = child.stdout.take().unwrap(); - let mut stderr = child.stderr.take().unwrap(); - - // Write to stdin in a new thread, so that we can read from stdout on this - // thread. This keeps the child from blocking on writing to its stdout which - // might block us from writing to its stdin. - let stdin_handle = - ::std::thread::spawn(move || stdin.write_all(source.as_bytes())); - - // Read stderr on a new thread for similar reasons. - let stderr_handle = ::std::thread::spawn(move || { - let mut output = vec![]; - io::copy(&mut stderr, &mut output) - .map(|_| String::from_utf8_lossy(&output).to_string()) - }); - - let mut output = vec![]; - io::copy(&mut stdout, &mut output).expect("Should copy stdout into vec OK"); - - // Ignore actual rustfmt status because it is often non-zero for trivial - // things. - let _ = child.wait().expect("should wait on rustfmt child OK"); - - stdin_handle - .join() - .expect("writer thread should not have panicked") - .expect("should have written to child rustfmt's stdin OK"); - - let bindings = String::from_utf8(output) - .expect("rustfmt should only emit valid utf-8"); - - let stderr = stderr_handle - .join() - .expect("stderr reader thread should not have panicked") - .expect("should have read child rustfmt's stderr OK"); - - (bindings, stderr) + let file = parse_str::(source.as_ref())?; + Ok(unparse(&file)) } fn should_overwrite_expected() -> bool { @@ -140,13 +48,7 @@ fn error_diff_mismatch( println!("+++ generated from: {:?}", header); } - for diff in diff::lines(expected, actual) { - match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), - } - } + show_diff(expected, actual); if should_overwrite_expected() { // Overwrite the expectation with actual output. @@ -172,6 +74,52 @@ fn error_diff_mismatch( Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")) } +struct Line(Option); + +impl fmt::Display for Line { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self.0 { + None => write!(f, " "), + Some(idx) => write!(f, "{:<4}", idx + 1), + } + } +} + +fn show_diff(old: &str, new: &str) { + let diff = TextDiff::from_lines(old, new); + for (count, group) in diff.grouped_ops(3).iter().enumerate() { + if count > 0 { + let message = format!("(chunk {count}/n)"); + println!("{}", message.cyan().dimmed()); + } + for diff_op in group { + for change in diff.iter_inline_changes(diff_op) { + let (sign, color) = match change.tag() { + ChangeTag::Delete => ("-", Style::new().red()), + ChangeTag::Insert => ("+", Style::new().green()), + ChangeTag::Equal => (" ", Style::new()), + }; + print!( + "{}{}| {}", + Line(change.old_index()).style(color).dimmed(), + Line(change.new_index()).style(color).dimmed(), + sign.style(color).bold(), + ); + for (emphasized, text) in change.iter_strings_lossy() { + if emphasized { + print!("{}", text.style(color).underline()); + } else { + print!("{}", text.style(color)); + } + } + if change.missing_newline() { + println!(); + } + } + } + } +} + fn compare_generated_header( header: &Path, builder: BuilderState, @@ -194,21 +142,19 @@ fn compare_generated_header( { let mut expectation = expectation.clone(); - if cfg!(feature = "testing_only_libclang_9") { + if cfg!(feature = "__testing_only_libclang_16") { + expectation.push("libclang-16"); + } else if cfg!(feature = "__testing_only_libclang_9") { expectation.push("libclang-9"); - } else if cfg!(feature = "testing_only_libclang_5") { - expectation.push("libclang-5"); } else { match clang_version().parsed { - None => expectation.push("libclang-9"), + None => expectation.push("libclang-16"), Some(version) => { let (maj, min) = version; - let version_str = if maj >= 9 { + let version_str = if maj >= 16 { + "16".to_owned() + } else if maj >= 9 { "9".to_owned() - } else if maj >= 5 { - "5".to_owned() - } else if maj >= 4 { - "4".to_owned() } else { format!("{}.{}", maj, min) }; @@ -237,7 +183,7 @@ fn compare_generated_header( BufReader::new(f).read_to_string(&mut expected)?; } None => panic!( - "missing test expectation file and/or 'testing_only_libclang_$VERSION' \ + "missing test expectation file and/or '__testing_only_libclang_$VERSION' \ feature for header '{}'; looking for expectation file at '{:?}'", header.display(), looked_at, @@ -247,17 +193,15 @@ fn compare_generated_header( let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; // We skip the generate() error here so we get a full diff below - let (actual, rustfmt_stderr) = match builder.generate() { - Ok(bindings) => { - let actual = bindings.to_string(); - rustfmt(actual) - } - Err(_) => ("/* error generating bindings */\n".into(), "".to_string()), + let actual = match builder.generate() { + Ok(bindings) => format_code(bindings.to_string()).map_err(|err| { + Error::new( + ErrorKind::Other, + format!("Cannot parse the generated bindings: {}", err), + ) + })?, + Err(_) => "/* error generating bindings */\n".into(), }; - println!("{}", rustfmt_stderr); - - let (expected, rustfmt_stderr) = rustfmt(expected); - println!("{}", rustfmt_stderr); if actual.is_empty() { return Err(Error::new( @@ -265,9 +209,7 @@ fn compare_generated_header( "Something's gone really wrong!", )); } - if actual != expected { - println!("{}", rustfmt_stderr); return error_diff_mismatch( &actual, &expected, @@ -346,7 +288,7 @@ fn create_bindgen_builder(header: &Path) -> Result { .last() .and_then(shlex::split) .unwrap(); - flags.extend(extra_flags.into_iter()); + flags.extend(extra_flags); } else if line.contains("bindgen-osx-only") { let prepend_flags = ["--raw-line", "#![cfg(target_os=\"macos\")]"]; flags = prepend_flags @@ -383,7 +325,7 @@ fn create_bindgen_builder(header: &Path) -> Result { "bindgen", // We format in `compare_generated_header` ourselves to have a little // more control. - "--no-rustfmt-bindings", + "--formatter=none", "--with-derive-default", "--disable-header-comment", "--vtable-generation", @@ -396,10 +338,7 @@ fn create_bindgen_builder(header: &Path) -> Result { "", ]; - let args = prepend - .iter() - .map(ToString::to_string) - .chain(flags.into_iter()); + let args = prepend.iter().map(ToString::to_string).chain(flags); let mut builder = builder_from_flags(args)?.0; if let Some(ref parse_cb) = parse_callbacks { @@ -445,25 +384,24 @@ fn test_clang_env_args() { "test.hpp", "#ifdef _ENV_ONE\nextern const int x[] = { 42 };\n#endif\n\ #ifdef _ENV_TWO\nextern const int y[] = { 42 };\n#endif\n\ - #ifdef NOT_THREE\nextern const int z[] = { 42 };\n#endif\n", + #if defined NOT_THREE && NOT_THREE == 1\nextern const int z[] = { 42 };\n#endif\n", ) .generate() .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub static x: [::std::os::raw::c_int; 1usize]; } extern \"C\" { pub static y: [::std::os::raw::c_int; 1usize]; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -478,16 +416,15 @@ fn test_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -505,8 +442,43 @@ fn test_multiple_header_calls_in_builder() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); + + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" + )); + let expected = format_code(expected).unwrap(); + + if actual != expected { + println!("Generated bindings differ from expected!"); + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); + } +} + +#[test] +fn test_headers_call_in_builder() { + let actual = builder() + .headers([ + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h"), + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h"), + ]) + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let actual = format_code(actual).unwrap(); let expected_filename = concat!( env!("CARGO_MANIFEST_DIR"), @@ -516,7 +488,7 @@ fn test_multiple_header_calls_in_builder() { env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" )); - let (expected, _) = rustfmt(expected.to_string()); + let expected = format_code(expected).unwrap(); if actual != expected { println!("Generated bindings differ from expected!"); @@ -540,19 +512,18 @@ fn test_multiple_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub fn foo2(b: *const ::std::os::raw::c_char) -> f32; } extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -572,8 +543,7 @@ fn test_mixed_header_and_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); let expected_filename = concat!( env!("CARGO_MANIFEST_DIR"), @@ -583,7 +553,62 @@ fn test_mixed_header_and_header_contents() { env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" )); - let (expected, _) = rustfmt(expected.to_string()); + let expected = format_code(expected).unwrap(); + if expected != actual { + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); + } +} + +#[test] +fn test_macro_fallback_non_system_dir() { + let actual = builder() + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/macro_fallback_test_headers/one_header.h" + )) + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/macro_fallback_test_headers/another_header.h" + )) + .clang_macro_fallback() + .clang_arg(format!("-I{}/tests/headers", env!("CARGO_MANIFEST_DIR"))) + .generate() + .unwrap() + .to_string(); + + let actual = format_code(actual).unwrap(); + + let (expected_filename, expected) = match clang_version().parsed { + Some((9, _)) => { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) + } + _ => { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) + } + }; + let expected = format_code(expected).unwrap(); if expected != actual { error_diff_mismatch( &actual, @@ -672,29 +697,13 @@ fn dump_preprocessed_input() { ); } -#[test] -fn allowlist_warnings() { - let header = concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/headers/allowlist_warnings.h" - ); - - let bindings = builder() - .header(header) - .allowlist_function("doesnt_match_anything") - .generate() - .expect("unable to generate bindings"); - - assert_eq!(1, bindings.warnings().len()); -} - fn build_flags_output_helper(builder: &bindgen::Builder) { let mut command_line_flags = builder.command_line_flags(); command_line_flags.insert(0, "bindgen".to_string()); let flags_quoted: Vec = command_line_flags .iter() - .map(|x| format!("{}", shlex::quote(x))) + .map(|x| format!("{}", shlex::try_quote(x).unwrap())) .collect(); let flags_str = flags_quoted.join(" "); println!("{}", flags_str); @@ -731,6 +740,7 @@ fn test_wrap_static_fns() { .header("tests/headers/wrap-static-fns.h") .wrap_static_fns(true) .wrap_static_fns_path(generated_path.display().to_string()) + .parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn)) .generate() .expect("Failed to generate bindings"); diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index bcc46e455eac49c06ed31a699d34ef61ac7d0bfb..9eddd5157df553b393d3b4bb82c37472bb178536 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,45 +14,58 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.64.0" +version = "0.70.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.60.0" +rust-version = "1.70.0" [lib] name = "bindgen" -path = "./lib.rs" +path = "lib.rs" [dependencies] -bitflags = "1.0.3" +annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } +bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } -lazycell = "1" -lazy_static = "1" -peeking_take_while = "0.1.2" +itertools = { version = ">=0.10,<0.14", default-features = false } +log = { version = "0.4", optional = true } +prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } +proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } -syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} -regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } -which = { version = "4.2.1", optional = true, default-features = false } -shlex = "1" +regex = { version = "1.5.3", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" -proc-macro2 = { version = "1", default-features = false } -log = { version = "0.4", optional = true } +shlex = "1" +syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } [features] -default = ["logging", "runtime", "which-rustfmt"] -logging = ["log"] +default = ["logging", "prettyplease", "runtime"] +logging = ["dep:log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] -# Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["which"] -cli = [] -experimental = [] +# This feature is no longer used for anything and should be removed in bindgen 0.70 +which-rustfmt = [] +experimental = ["dep:annotate-snippets"] + +## The following features are for internal use and they shouldn't be used if +## you're not hacking on bindgen +# Features used by `bindgen-cli` +__cli = [] +# Features used for CI testing +__testing_only_extra_assertions = [] +__testing_only_libclang_9 = [] +__testing_only_libclang_16 = [] + +[package.metadata.docs.rs] +features = ["experimental"] + +[package.metadata.release] +release = true +pre-release-hook = ["../node_modules/doctoc/doctoc.js", "../CHANGELOG.md"] -# These features only exist for CI testing -- don't use them if you're not hacking -# on bindgen! -testing_only_docs = [] -testing_only_extra_assertions = [] -testing_only_libclang_9 = [] -testing_only_libclang_5 = [] +# Add version and date to changelog file +[[package.metadata.release.pre-release-replacements]] +file = "../CHANGELOG.md" +search = "# Unreleased" +replace = "# Unreleased\n## Added\n## Changed\n## Removed\n## Fixed\n## Security\n\n# {{version}} ({{date}})" diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index dc20e2581e154106f80abdee1bafe4015e6ea1e8..76309aa526abfc9bc9f9cb98c84dae55a2c0c004 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -7,25 +7,20 @@ pub use crate::ir::int::IntKind; use std::fmt; /// An enum to allow ignoring parsing of macros. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum MacroParsingBehavior { /// Ignore the macro, generating no code for it, or anything that depends on /// it. Ignore, /// The default behavior bindgen would have otherwise. + #[default] Default, } -impl Default for MacroParsingBehavior { - fn default() -> Self { - MacroParsingBehavior::Default - } -} - /// A trait to allow configuring different kinds of types in different /// situations. pub trait ParseCallbacks: fmt::Debug { - #[cfg(feature = "cli")] + // #[cfg(feature = "__cli")] #[doc(hidden)] fn cli_args(&self) -> Vec { vec![] @@ -45,6 +40,15 @@ pub trait ParseCallbacks: fmt::Debug { None } + /// This function will run for every extern variable and function. The returned value determines + /// the link name in the bindings. + fn generated_link_name_override( + &self, + _item_info: ItemInfo<'_>, + ) -> Option { + None + } + /// The integer kind an integer macro should have, given a name and the /// value of that macro, or `None` if you want the default to be chosen. fn int_macro(&self, _name: &str, _value: i64) -> Option { @@ -90,9 +94,16 @@ pub trait ParseCallbacks: fmt::Debug { None } + /// This will be called on every header filename passed to (`Builder::header`)[`crate::Builder::header`]. + fn header_file(&self, _filename: &str) {} + /// This will be called on every file inclusion, with the full path of the included file. fn include_file(&self, _filename: &str) {} + /// This will be called every time `bindgen` reads an environment variable whether it has any + /// content or not. + fn read_env_var(&self, _key: &str) {} + /// This will be called to determine whether a particular blocklisted type /// implements a trait or not. This will be used to implement traits on /// other types containing the blocklisted type. @@ -122,6 +133,27 @@ pub trait ParseCallbacks: fmt::Debug { fn process_comment(&self, _comment: &str) -> Option { None } + + /// Potentially override the visibility of a composite type field. + /// + /// Caution: This allows overriding standard C++ visibility inferred by + /// `respect_cxx_access_specs`. + fn field_visibility( + &self, + _info: FieldInfo<'_>, + ) -> Option { + None + } + + /// Process a function name that as exactly one `va_list` argument + /// to be wrapped as a variadic function with the wrapped static function + /// feature. + /// + /// The returned string is new function name. + #[cfg(feature = "experimental")] + fn wrap_as_variadic_fn(&self, _name: &str) -> Option { + None + } } /// Relevant information about a type to which new derive attributes will be added using @@ -146,7 +178,7 @@ pub enum TypeKind { Union, } -/// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`. +/// A struct providing information about the item being passed to [`ParseCallbacks::generated_name_override`]. #[non_exhaustive] pub struct ItemInfo<'a> { /// The name of the item @@ -163,3 +195,14 @@ pub enum ItemKind { /// A Variable Var, } + +/// Relevant information about a field for which visibility can be determined using +/// [`ParseCallbacks::field_visibility`]. +#[derive(Debug)] +#[non_exhaustive] +pub struct FieldInfo<'a> { + /// The name of the type. + pub type_name: &'a str, + /// The name of the field. + pub field_name: &'a str, +} diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 32a25449bc4b0e015c7a8f016161ce0ccd7ae0d3..47c7b1704a56a4778533d9c3b1e0ba91ab750c86 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2,21 +2,26 @@ //! `clang_sys` module. #![allow(non_upper_case_globals, dead_code)] +#![deny(clippy::missing_docs_in_private_items)] use crate::ir::context::BindgenContext; use clang_sys::*; +use std::cmp; + use std::ffi::{CStr, CString}; use std::fmt; +use std::fs::OpenOptions; use std::hash::Hash; use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; +use std::sync::OnceLock; use std::{mem, ptr, slice}; /// Type representing a clang attribute. /// /// Values of this type can be used to check for different attributes using the `has_attrs` /// function. -pub struct Attribute { +pub(crate) struct Attribute { name: &'static [u8], kind: Option, token_kind: CXTokenKind, @@ -24,7 +29,7 @@ pub struct Attribute { impl Attribute { /// A `warn_unused_result` attribute. - pub const MUST_USE: Self = Self { + pub(crate) const MUST_USE: Self = Self { name: b"warn_unused_result", // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). kind: Some(440), @@ -32,14 +37,14 @@ impl Attribute { }; /// A `_Noreturn` attribute. - pub const NO_RETURN: Self = Self { + pub(crate) const NO_RETURN: Self = Self { name: b"_Noreturn", kind: None, token_kind: CXToken_Keyword, }; /// A `[[noreturn]]` attribute. - pub const NO_RETURN_CPP: Self = Self { + pub(crate) const NO_RETURN_CPP: Self = Self { name: b"noreturn", kind: None, token_kind: CXToken_Identifier, @@ -50,7 +55,7 @@ impl Attribute { /// /// We call the AST node pointed to by the cursor the cursor's "referent". #[derive(Copy, Clone)] -pub struct Cursor { +pub(crate) struct Cursor { x: CXCursor, } @@ -72,7 +77,7 @@ impl Cursor { /// available. /// /// The USR can be used to compare entities across translation units. - pub fn usr(&self) -> Option { + pub(crate) fn usr(&self) -> Option { let s = unsafe { cxstring_into_string(clang_getCursorUSR(self.x)) }; if s.is_empty() { None @@ -82,17 +87,17 @@ impl Cursor { } /// Is this cursor's referent a declaration? - pub fn is_declaration(&self) -> bool { + pub(crate) fn is_declaration(&self) -> bool { unsafe { clang_isDeclaration(self.kind()) != 0 } } /// Is this cursor's referent an anonymous record or so? - pub fn is_anonymous(&self) -> bool { + pub(crate) fn is_anonymous(&self) -> bool { unsafe { clang_Cursor_isAnonymous(self.x) != 0 } } /// Get this cursor's referent's spelling. - pub fn spelling(&self) -> String { + pub(crate) fn spelling(&self) -> String { unsafe { cxstring_into_string(clang_getCursorSpelling(self.x)) } } @@ -100,18 +105,18 @@ impl Cursor { /// /// This is not necessarily a valid identifier. It includes extra /// information, such as parameters for a function, etc. - pub fn display_name(&self) -> String { + pub(crate) fn display_name(&self) -> String { unsafe { cxstring_into_string(clang_getCursorDisplayName(self.x)) } } /// Get the mangled name of this cursor's referent. - pub fn mangling(&self) -> String { + pub(crate) fn mangling(&self) -> String { unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) } } /// Gets the C++ manglings for this cursor, or an error if the manglings /// are not available. - pub fn cxx_manglings(&self) -> Result, ()> { + pub(crate) fn cxx_manglings(&self) -> Result, ()> { use clang_sys::*; unsafe { let manglings = clang_Cursor_getCXXManglings(self.x); @@ -131,7 +136,7 @@ impl Cursor { } /// Returns whether the cursor refers to a built-in definition. - pub fn is_builtin(&self) -> bool { + pub(crate) fn is_builtin(&self) -> bool { let (file, _, _, _) = self.location().location(); file.name().is_none() } @@ -153,7 +158,7 @@ impl Cursor { /// /// void Foo::method() { /* ... */ } /// ``` - pub fn lexical_parent(&self) -> Cursor { + pub(crate) fn lexical_parent(&self) -> Cursor { unsafe { Cursor { x: clang_getCursorLexicalParent(self.x), @@ -165,7 +170,7 @@ impl Cursor { /// /// See documentation for `lexical_parent` for details on semantic vs /// lexical parents. - pub fn fallible_semantic_parent(&self) -> Option { + pub(crate) fn fallible_semantic_parent(&self) -> Option { let sp = unsafe { Cursor { x: clang_getCursorSemanticParent(self.x), @@ -181,7 +186,7 @@ impl Cursor { /// /// See documentation for `lexical_parent` for details on semantic vs /// lexical parents. - pub fn semantic_parent(&self) -> Cursor { + pub(crate) fn semantic_parent(&self) -> Cursor { self.fallible_semantic_parent().unwrap() } @@ -191,7 +196,7 @@ impl Cursor { /// /// NOTE: This may not return `Some` for partial template specializations, /// see #193 and #194. - pub fn num_template_args(&self) -> Option { + pub(crate) fn num_template_args(&self) -> Option { // XXX: `clang_Type_getNumTemplateArguments` is sort of reliable, while // `clang_Cursor_getNumTemplateArguments` is totally unreliable. // Therefore, try former first, and only fallback to the latter if we @@ -225,7 +230,7 @@ impl Cursor { /// bindgen assumes there will only be one of them alive at a time, and /// disposes it on drop. That can change if this would be required, but I /// think we can survive fine without it. - pub fn translation_unit(&self) -> Cursor { + pub(crate) fn translation_unit(&self) -> Cursor { assert!(self.is_valid()); unsafe { let tu = clang_Cursor_getTranslationUnit(self.x); @@ -238,7 +243,7 @@ impl Cursor { } /// Is the referent a top level construct? - pub fn is_toplevel(&self) -> bool { + pub(crate) fn is_toplevel(&self) -> bool { let mut semantic_parent = self.fallible_semantic_parent(); while semantic_parent.is_some() && @@ -259,7 +264,7 @@ impl Cursor { /// There are a few kinds of types that we need to treat specially, mainly /// not tracking the type declaration but the location of the cursor, given /// clang doesn't expose a proper declaration for these types. - pub fn is_template_like(&self) -> bool { + pub(crate) fn is_template_like(&self) -> bool { matches!( self.kind(), CXCursor_ClassTemplate | @@ -269,28 +274,28 @@ impl Cursor { } /// Is this Cursor pointing to a function-like macro definition? - pub fn is_macro_function_like(&self) -> bool { + pub(crate) fn is_macro_function_like(&self) -> bool { unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 } } /// Get the kind of referent this cursor is pointing to. - pub fn kind(&self) -> CXCursorKind { + pub(crate) fn kind(&self) -> CXCursorKind { self.x.kind } /// Returns true if the cursor is a definition - pub fn is_definition(&self) -> bool { + pub(crate) fn is_definition(&self) -> bool { unsafe { clang_isCursorDefinition(self.x) != 0 } } /// Is the referent a template specialization? - pub fn is_template_specialization(&self) -> bool { + pub(crate) fn is_template_specialization(&self) -> bool { self.specialized().is_some() } /// Is the referent a fully specialized template specialization without any /// remaining free template arguments? - pub fn is_fully_specialized_template(&self) -> bool { + pub(crate) fn is_fully_specialized_template(&self) -> bool { self.is_template_specialization() && self.kind() != CXCursor_ClassTemplatePartialSpecialization && self.num_template_args().unwrap_or(0) > 0 @@ -298,7 +303,7 @@ impl Cursor { /// Is the referent a template specialization that still has remaining free /// template arguments? - pub fn is_in_non_fully_specialized_template(&self) -> bool { + pub(crate) fn is_in_non_fully_specialized_template(&self) -> bool { if self.is_toplevel() { return false; } @@ -316,7 +321,7 @@ impl Cursor { } /// Is the referent any kind of template parameter? - pub fn is_template_parameter(&self) -> bool { + pub(crate) fn is_template_parameter(&self) -> bool { matches!( self.kind(), CXCursor_TemplateTemplateParameter | @@ -326,7 +331,7 @@ impl Cursor { } /// Does the referent's type or value depend on a template parameter? - pub fn is_dependent_on_template_parameter(&self) -> bool { + pub(crate) fn is_dependent_on_template_parameter(&self) -> bool { fn visitor( found_template_parameter: &mut bool, cur: Cursor, @@ -366,12 +371,12 @@ impl Cursor { } /// Is this cursor pointing a valid referent? - pub fn is_valid(&self) -> bool { + pub(crate) fn is_valid(&self) -> bool { unsafe { clang_isInvalid(self.kind()) == 0 } } /// Get the source location for the referent. - pub fn location(&self) -> SourceLocation { + pub(crate) fn location(&self) -> SourceLocation { unsafe { SourceLocation { x: clang_getCursorLocation(self.x), @@ -380,12 +385,12 @@ impl Cursor { } /// Get the source location range for the referent. - pub fn extent(&self) -> CXSourceRange { + pub(crate) fn extent(&self) -> CXSourceRange { unsafe { clang_getCursorExtent(self.x) } } /// Get the raw declaration comment for this referent, if one exists. - pub fn raw_comment(&self) -> Option { + pub(crate) fn raw_comment(&self) -> Option { let s = unsafe { cxstring_into_string(clang_Cursor_getRawCommentText(self.x)) }; @@ -397,7 +402,7 @@ impl Cursor { } /// Get the referent's parsed comment. - pub fn comment(&self) -> Comment { + pub(crate) fn comment(&self) -> Comment { unsafe { Comment { x: clang_Cursor_getParsedComment(self.x), @@ -406,7 +411,7 @@ impl Cursor { } /// Get the referent's type. - pub fn cur_type(&self) -> Type { + pub(crate) fn cur_type(&self) -> Type { unsafe { Type { x: clang_getCursorType(self.x), @@ -417,7 +422,7 @@ impl Cursor { /// Given that this cursor's referent is a reference to another type, or is /// a declaration, get the cursor pointing to the referenced type or type of /// the declared thing. - pub fn definition(&self) -> Option { + pub(crate) fn definition(&self) -> Option { unsafe { let ret = Cursor { x: clang_getCursorDefinition(self.x), @@ -433,7 +438,7 @@ impl Cursor { /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. - pub fn referenced(&self) -> Option { + pub(crate) fn referenced(&self) -> Option { unsafe { let ret = Cursor { x: clang_getCursorReferenced(self.x), @@ -452,7 +457,7 @@ impl Cursor { /// Many types can be declared multiple times before finally being properly /// defined. This method allows us to get the canonical cursor for the /// referent type. - pub fn canonical(&self) -> Cursor { + pub(crate) fn canonical(&self) -> Cursor { unsafe { Cursor { x: clang_getCanonicalCursor(self.x), @@ -463,7 +468,7 @@ impl Cursor { /// Given that this cursor points to either a template specialization or a /// template instantiation, get a cursor pointing to the template definition /// that is being specialized. - pub fn specialized(&self) -> Option { + pub(crate) fn specialized(&self) -> Option { unsafe { let ret = Cursor { x: clang_getSpecializedCursorTemplate(self.x), @@ -478,14 +483,14 @@ impl Cursor { /// Assuming that this cursor's referent is a template declaration, get the /// kind of cursor that would be generated for its specializations. - pub fn template_kind(&self) -> CXCursorKind { + pub(crate) fn template_kind(&self) -> CXCursorKind { unsafe { clang_getTemplateCursorKind(self.x) } } /// Traverse this cursor's referent and its children. /// /// Call the given function on each AST node traversed. - pub fn visit(&self, mut visitor: Visitor) + pub(crate) fn visit(&self, mut visitor: Visitor) where Visitor: FnMut(Cursor) -> CXChildVisitResult, { @@ -495,8 +500,98 @@ impl Cursor { } } + /// Traverse all of this cursor's children, sorted by where they appear in source code. + /// + /// Call the given function on each AST node traversed. + pub(crate) fn visit_sorted( + &self, + ctx: &mut BindgenContext, + mut visitor: Visitor, + ) where + Visitor: FnMut(&mut BindgenContext, Cursor), + { + // FIXME(#2556): The current source order stuff doesn't account well for different levels + // of includes, or includes that show up at the same byte offset because they are passed in + // via CLI. + const SOURCE_ORDER_ENABLED: bool = false; + if !SOURCE_ORDER_ENABLED { + return self.visit(|c| { + visitor(ctx, c); + CXChildVisit_Continue + }); + } + + let mut children = self.collect_children(); + for child in &children { + if child.kind() == CXCursor_InclusionDirective { + if let Some(included_file) = child.get_included_file_name() { + let location = child.location(); + let (source_file, _, _, offset) = location.location(); + + if let Some(source_file) = source_file.name() { + ctx.add_include(source_file, included_file, offset); + } + } + } + } + children + .sort_by(|child1, child2| child1.cmp_by_source_order(child2, ctx)); + for child in children { + visitor(ctx, child); + } + } + + /// Compare source order of two cursors, considering `#include` directives. + /// + /// Built-in items provided by the compiler (which don't have a source file), + /// are sorted first. Remaining files are sorted by their position in the source file. + /// If the items' source files differ, they are sorted by the position of the first + /// `#include` for their source file. If no source files are included, `None` is returned. + fn cmp_by_source_order( + &self, + other: &Self, + ctx: &BindgenContext, + ) -> cmp::Ordering { + let (file, _, _, offset) = self.location().location(); + let (other_file, _, _, other_offset) = other.location().location(); + + let (file, other_file) = match (file.name(), other_file.name()) { + (Some(file), Some(other_file)) => (file, other_file), + // Built-in definitions should come first. + (Some(_), None) => return cmp::Ordering::Greater, + (None, Some(_)) => return cmp::Ordering::Less, + (None, None) => return cmp::Ordering::Equal, + }; + + if file == other_file { + // Both items are in the same source file, compare by byte offset. + return offset.cmp(&other_offset); + } + + let include_location = ctx.included_file_location(&file); + let other_include_location = ctx.included_file_location(&other_file); + match (include_location, other_include_location) { + (Some((file2, offset2)), _) if file2 == other_file => { + offset2.cmp(&other_offset) + } + (Some(_), None) => cmp::Ordering::Greater, + (_, Some((other_file2, other_offset2))) if file == other_file2 => { + offset.cmp(&other_offset2) + } + (None, Some(_)) => cmp::Ordering::Less, + (Some((file2, offset2)), Some((other_file2, other_offset2))) => { + if file2 == other_file2 { + offset2.cmp(&other_offset2) + } else { + cmp::Ordering::Equal + } + } + (None, None) => cmp::Ordering::Equal, + } + } + /// Collect all of this cursor's children into a vec and return them. - pub fn collect_children(&self) -> Vec { + pub(crate) fn collect_children(&self) -> Vec { let mut children = vec![]; self.visit(|c| { children.push(c); @@ -506,7 +601,7 @@ impl Cursor { } /// Does this cursor have any children? - pub fn has_children(&self) -> bool { + pub(crate) fn has_children(&self) -> bool { let mut has_children = false; self.visit(|_| { has_children = true; @@ -516,7 +611,7 @@ impl Cursor { } /// Does this cursor have at least `n` children? - pub fn has_at_least_num_children(&self, n: usize) -> bool { + pub(crate) fn has_at_least_num_children(&self, n: usize) -> bool { assert!(n > 0); let mut num_left = n; self.visit(|_| { @@ -533,7 +628,7 @@ impl Cursor { /// Returns whether the given location contains a cursor with the given /// kind in the first level of nesting underneath (doesn't look /// recursively). - pub fn contains_cursor(&self, kind: CXCursorKind) -> bool { + pub(crate) fn contains_cursor(&self, kind: CXCursorKind) -> bool { let mut found = false; self.visit(|c| { @@ -549,17 +644,17 @@ impl Cursor { } /// Is the referent an inlined function? - pub fn is_inlined_function(&self) -> bool { + pub(crate) fn is_inlined_function(&self) -> bool { unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } } /// Is the referent a defaulted function? - pub fn is_defaulted_function(&self) -> bool { + pub(crate) fn is_defaulted_function(&self) -> bool { unsafe { clang_CXXMethod_isDefaulted(self.x) != 0 } } /// Is the referent a deleted function? - pub fn is_deleted_function(&self) -> bool { + pub(crate) fn is_deleted_function(&self) -> bool { // Unfortunately, libclang doesn't yet have an API for checking if a // member function is deleted, but the following should be a good // enough approximation. @@ -575,13 +670,13 @@ impl Cursor { } /// Is the referent a bit field declaration? - pub fn is_bit_field(&self) -> bool { + pub(crate) fn is_bit_field(&self) -> bool { unsafe { clang_Cursor_isBitField(self.x) != 0 } } /// Get a cursor to the bit field's width expression, or `None` if it's not /// a bit field. - pub fn bit_width_expr(&self) -> Option { + pub(crate) fn bit_width_expr(&self) -> Option { if !self.is_bit_field() { return None; } @@ -605,7 +700,7 @@ impl Cursor { /// Get the width of this cursor's referent bit field, or `None` if the /// referent is not a bit field or if the width could not be evaluated. - pub fn bit_width(&self) -> Option { + pub(crate) fn bit_width(&self) -> Option { // It is not safe to check the bit width without ensuring it doesn't // depend on a template parameter. See // https://github.com/rust-lang/rust-bindgen/issues/2239 @@ -625,7 +720,7 @@ impl Cursor { /// Get the integer representation type used to hold this cursor's referent /// enum type. - pub fn enum_type(&self) -> Option { + pub(crate) fn enum_type(&self) -> Option { unsafe { let t = Type { x: clang_getEnumDeclIntegerType(self.x), @@ -641,7 +736,7 @@ impl Cursor { /// Get the boolean constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_boolean(&self) -> Option { + pub(crate) fn enum_val_boolean(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { Some(clang_getEnumConstantDeclValue(self.x) != 0) @@ -654,7 +749,7 @@ impl Cursor { /// Get the signed constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_signed(&self) -> Option { + pub(crate) fn enum_val_signed(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { #[allow(clippy::unnecessary_cast)] @@ -668,7 +763,7 @@ impl Cursor { /// Get the unsigned constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_unsigned(&self) -> Option { + pub(crate) fn enum_val_unsigned(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { #[allow(clippy::unnecessary_cast)] @@ -680,7 +775,7 @@ impl Cursor { } /// Does this cursor have the given attributes? - pub fn has_attrs( + pub(crate) fn has_attrs( &self, attrs: &[Attribute; N], ) -> [bool; N] { @@ -718,7 +813,7 @@ impl Cursor { /// Given that this cursor's referent is a `typedef`, get the `Type` that is /// being aliased. - pub fn typedef_type(&self) -> Option { + pub(crate) fn typedef_type(&self) -> Option { let inner = Type { x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }, }; @@ -733,12 +828,12 @@ impl Cursor { /// Get the linkage kind for this cursor's referent. /// /// This only applies to functions and variables. - pub fn linkage(&self) -> CXLinkageKind { + pub(crate) fn linkage(&self) -> CXLinkageKind { unsafe { clang_getCursorLinkage(self.x) } } /// Get the visibility of this cursor's referent. - pub fn visibility(&self) -> CXVisibilityKind { + pub(crate) fn visibility(&self) -> CXVisibilityKind { unsafe { clang_getCursorVisibility(self.x) } } @@ -747,7 +842,7 @@ impl Cursor { /// /// Returns None if the cursor's referent is not a function/method call or /// declaration. - pub fn args(&self) -> Option> { + pub(crate) fn args(&self) -> Option> { // match self.kind() { // CXCursor_FunctionDecl | // CXCursor_CXXMethod => { @@ -765,7 +860,7 @@ impl Cursor { /// /// Returns Err if the cursor's referent is not a function/method call or /// declaration. - pub fn num_args(&self) -> Result { + pub(crate) fn num_args(&self) -> Result { unsafe { let w = clang_Cursor_getNumArguments(self.x); if w == -1 { @@ -777,27 +872,27 @@ impl Cursor { } /// Get the access specifier for this cursor's referent. - pub fn access_specifier(&self) -> CX_CXXAccessSpecifier { + pub(crate) fn access_specifier(&self) -> CX_CXXAccessSpecifier { unsafe { clang_getCXXAccessSpecifier(self.x) } } - /// Is the cursor's referrent publically accessible in C++? + /// Is the cursor's referent publicly accessible in C++? /// /// Returns true if self.access_specifier() is `CX_CXXPublic` or /// `CX_CXXInvalidAccessSpecifier`. - pub fn public_accessible(&self) -> bool { + pub(crate) fn public_accessible(&self) -> bool { let access = self.access_specifier(); access == CX_CXXPublic || access == CX_CXXInvalidAccessSpecifier } /// Is this cursor's referent a field declaration that is marked as /// `mutable`? - pub fn is_mutable_field(&self) -> bool { + pub(crate) fn is_mutable_field(&self) -> bool { unsafe { clang_CXXField_isMutable(self.x) != 0 } } /// Get the offset of the field represented by the Cursor. - pub fn offset_of_field(&self) -> Result { + pub(crate) fn offset_of_field(&self) -> Result { let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) }; if offset < 0 { @@ -808,37 +903,37 @@ impl Cursor { } /// Is this cursor's referent a member function that is declared `static`? - pub fn method_is_static(&self) -> bool { + pub(crate) fn method_is_static(&self) -> bool { unsafe { clang_CXXMethod_isStatic(self.x) != 0 } } /// Is this cursor's referent a member function that is declared `const`? - pub fn method_is_const(&self) -> bool { + pub(crate) fn method_is_const(&self) -> bool { unsafe { clang_CXXMethod_isConst(self.x) != 0 } } /// Is this cursor's referent a member function that is virtual? - pub fn method_is_virtual(&self) -> bool { + pub(crate) fn method_is_virtual(&self) -> bool { unsafe { clang_CXXMethod_isVirtual(self.x) != 0 } } /// Is this cursor's referent a member function that is pure virtual? - pub fn method_is_pure_virtual(&self) -> bool { + pub(crate) fn method_is_pure_virtual(&self) -> bool { unsafe { clang_CXXMethod_isPureVirtual(self.x) != 0 } } /// Is this cursor's referent a struct or class with virtual members? - pub fn is_virtual_base(&self) -> bool { + pub(crate) fn is_virtual_base(&self) -> bool { unsafe { clang_isVirtualBase(self.x) != 0 } } /// Try to evaluate this cursor. - pub fn evaluate(&self) -> Option { + pub(crate) fn evaluate(&self) -> Option { EvalResult::new(*self) } /// Return the result type for this cursor - pub fn ret_type(&self) -> Option { + pub(crate) fn ret_type(&self) -> Option { let rt = Type { x: unsafe { clang_getCursorResultType(self.x) }, }; @@ -850,12 +945,12 @@ impl Cursor { } /// Gets the tokens that correspond to that cursor. - pub fn tokens(&self) -> RawTokens { + pub(crate) fn tokens(&self) -> RawTokens { RawTokens::new(self) } /// Gets the tokens that correspond to that cursor as `cexpr` tokens. - pub fn cexpr_tokens(self) -> Vec { + pub(crate) fn cexpr_tokens(self) -> Vec { self.tokens() .iter() .filter_map(|token| token.as_cexpr_token()) @@ -865,7 +960,7 @@ impl Cursor { /// Obtain the real path name of a cursor of InclusionDirective kind. /// /// Returns None if the cursor does not include a file, otherwise the file's full name - pub fn get_included_file_name(&self) -> Option { + pub(crate) fn get_included_file_name(&self) -> Option { let file = unsafe { clang_sys::clang_getIncludedFile(self.x) }; if file.is_null() { None @@ -878,7 +973,7 @@ impl Cursor { } /// A struct that owns the tokenizer result from a given cursor. -pub struct RawTokens<'a> { +pub(crate) struct RawTokens<'a> { cursor: &'a Cursor, tu: CXTranslationUnit, tokens: *mut CXToken, @@ -908,7 +1003,7 @@ impl<'a> RawTokens<'a> { } /// Get an iterator over these tokens. - pub fn iter(&self) -> ClangTokenIterator { + pub(crate) fn iter(&self) -> ClangTokenIterator { ClangTokenIterator { tu: self.tu, raw: self.as_slice().iter(), @@ -934,19 +1029,19 @@ impl<'a> Drop for RawTokens<'a> { /// slightly more convenient version of `CXToken` which owns the spelling /// string and extent. #[derive(Debug)] -pub struct ClangToken { +pub(crate) struct ClangToken { spelling: CXString, /// The extent of the token. This is the same as the relevant member from /// `CXToken`. - pub extent: CXSourceRange, + pub(crate) extent: CXSourceRange, /// The kind of the token. This is the same as the relevant member from /// `CXToken`. - pub kind: CXTokenKind, + pub(crate) kind: CXTokenKind, } impl ClangToken { /// Get the token spelling, without being converted to utf-8. - pub fn spelling(&self) -> &[u8] { + pub(crate) fn spelling(&self) -> &[u8] { let c_str = unsafe { CStr::from_ptr(clang_getCString(self.spelling) as *const _) }; @@ -954,7 +1049,7 @@ impl ClangToken { } /// Converts a ClangToken to a `cexpr` token if possible. - pub fn as_cexpr_token(&self) -> Option { + pub(crate) fn as_cexpr_token(&self) -> Option { use cexpr::token; let kind = match self.kind { @@ -985,7 +1080,7 @@ impl Drop for ClangToken { } /// An iterator over a set of Tokens. -pub struct ClangTokenIterator<'a> { +pub(crate) struct ClangTokenIterator<'a> { tu: CXTranslationUnit, raw: slice::Iter<'a, CXToken>, } @@ -1010,7 +1105,7 @@ impl<'a> Iterator for ClangTokenIterator<'a> { /// Checks whether the name looks like an identifier, i.e. is alphanumeric /// (including '_') and does not start with a digit. -pub fn is_valid_identifier(name: &str) -> bool { +pub(crate) fn is_valid_identifier(name: &str) -> bool { let mut chars = name.chars(); let first_valid = chars .next() @@ -1050,7 +1145,7 @@ impl Hash for Cursor { /// The type of a node in clang's AST. #[derive(Clone, Copy)] -pub struct Type { +pub(crate) struct Type { x: CXType, } @@ -1078,7 +1173,7 @@ impl fmt::Debug for Type { /// An error about the layout of a struct, class, or type. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum LayoutError { +pub(crate) enum LayoutError { /// Asked for the layout of an invalid type. Invalid, /// Asked for the layout of an incomplete type. @@ -1111,12 +1206,12 @@ impl ::std::convert::From for LayoutError { impl Type { /// Get this type's kind. - pub fn kind(&self) -> CXTypeKind { + pub(crate) fn kind(&self) -> CXTypeKind { self.x.kind } /// Get a cursor pointing to this type's declaration. - pub fn declaration(&self) -> Cursor { + pub(crate) fn declaration(&self) -> Cursor { unsafe { Cursor { x: clang_getTypeDeclaration(self.x), @@ -1125,7 +1220,7 @@ impl Type { } /// Get the canonical declaration of this type, if it is available. - pub fn canonical_declaration( + pub(crate) fn canonical_declaration( &self, location: Option<&Cursor>, ) -> Option { @@ -1151,7 +1246,7 @@ impl Type { } /// Get a raw display name for this type. - pub fn spelling(&self) -> String { + pub(crate) fn spelling(&self) -> String { let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; // Clang 5.0 introduced changes in the spelling API so it returned the // full qualified name. Let's undo that here. @@ -1165,7 +1260,7 @@ impl Type { } /// Is this type const qualified? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { unsafe { clang_isConstQualifiedType(self.x) != 0 } } @@ -1203,7 +1298,7 @@ impl Type { /// What is the size of this type? Paper over invalid types by returning `0` /// for them. - pub fn size(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn size(&self, ctx: &BindgenContext) -> usize { let val = self.clang_size_of(ctx); if val < 0 { 0 @@ -1213,7 +1308,7 @@ impl Type { } /// What is the size of this type? - pub fn fallible_size( + pub(crate) fn fallible_size( &self, ctx: &BindgenContext, ) -> Result { @@ -1227,7 +1322,7 @@ impl Type { /// What is the alignment of this type? Paper over invalid types by /// returning `0`. - pub fn align(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn align(&self, ctx: &BindgenContext) -> usize { let val = self.clang_align_of(ctx); if val < 0 { 0 @@ -1237,7 +1332,7 @@ impl Type { } /// What is the alignment of this type? - pub fn fallible_align( + pub(crate) fn fallible_align( &self, ctx: &BindgenContext, ) -> Result { @@ -1251,7 +1346,7 @@ impl Type { /// Get the layout for this type, or an error describing why it does not /// have a valid layout. - pub fn fallible_layout( + pub(crate) fn fallible_layout( &self, ctx: &BindgenContext, ) -> Result { @@ -1263,7 +1358,7 @@ impl Type { /// Get the number of template arguments this type has, or `None` if it is /// not some kind of template. - pub fn num_template_args(&self) -> Option { + pub(crate) fn num_template_args(&self) -> Option { let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; if n >= 0 { Some(n as u32) @@ -1275,7 +1370,7 @@ impl Type { /// If this type is a class template specialization, return its /// template arguments. Otherwise, return None. - pub fn template_args(&self) -> Option { + pub(crate) fn template_args(&self) -> Option { self.num_template_args().map(|n| TypeTemplateArgIterator { x: self.x, length: n, @@ -1286,7 +1381,7 @@ impl Type { /// Given that this type is a function prototype, return the types of its parameters. /// /// Returns None if the type is not a function prototype. - pub fn args(&self) -> Option> { + pub(crate) fn args(&self) -> Option> { self.num_args().ok().map(|num| { (0..num) .map(|i| Type { @@ -1299,7 +1394,7 @@ impl Type { /// Given that this type is a function prototype, return the number of arguments it takes. /// /// Returns Err if the type is not a function prototype. - pub fn num_args(&self) -> Result { + pub(crate) fn num_args(&self) -> Result { unsafe { let w = clang_getNumArgTypes(self.x); if w == -1 { @@ -1312,7 +1407,7 @@ impl Type { /// Given that this type is a pointer type, return the type that it points /// to. - pub fn pointee_type(&self) -> Option { + pub(crate) fn pointee_type(&self) -> Option { match self.kind() { CXType_Pointer | CXType_RValueReference | @@ -1332,7 +1427,7 @@ impl Type { /// Given that this type is an array, vector, or complex type, return the /// type of its elements. - pub fn elem_type(&self) -> Option { + pub(crate) fn elem_type(&self) -> Option { let current_type = Type { x: unsafe { clang_getElementType(self.x) }, }; @@ -1345,7 +1440,7 @@ impl Type { /// Given that this type is an array or vector type, return its number of /// elements. - pub fn num_elements(&self) -> Option { + pub(crate) fn num_elements(&self) -> Option { let num_elements_returned = unsafe { clang_getNumElements(self.x) }; if num_elements_returned != -1 { Some(num_elements_returned as usize) @@ -1356,7 +1451,7 @@ impl Type { /// Get the canonical version of this type. This sees through `typedef`s and /// aliases to get the underlying, canonical type. - pub fn canonical_type(&self) -> Type { + pub(crate) fn canonical_type(&self) -> Type { unsafe { Type { x: clang_getCanonicalType(self.x), @@ -1365,13 +1460,13 @@ impl Type { } /// Is this type a variadic function type? - pub fn is_variadic(&self) -> bool { + pub(crate) fn is_variadic(&self) -> bool { unsafe { clang_isFunctionTypeVariadic(self.x) != 0 } } /// Given that this type is a function type, get the type of its return /// value. - pub fn ret_type(&self) -> Option { + pub(crate) fn ret_type(&self) -> Option { let rt = Type { x: unsafe { clang_getResultType(self.x) }, }; @@ -1384,13 +1479,13 @@ impl Type { /// Given that this type is a function type, get its calling convention. If /// this is not a function type, `CXCallingConv_Invalid` is returned. - pub fn call_conv(&self) -> CXCallingConv { + pub(crate) fn call_conv(&self) -> CXCallingConv { unsafe { clang_getFunctionTypeCallingConv(self.x) } } /// For elaborated types (types which use `class`, `struct`, or `union` to /// disambiguate types from local bindings), get the underlying type. - pub fn named(&self) -> Type { + pub(crate) fn named(&self) -> Type { unsafe { Type { x: clang_Type_getNamedType(self.x), @@ -1399,17 +1494,17 @@ impl Type { } /// Is this a valid type? - pub fn is_valid(&self) -> bool { + pub(crate) fn is_valid(&self) -> bool { self.kind() != CXType_Invalid } /// Is this a valid and exposed type? - pub fn is_valid_and_exposed(&self) -> bool { + pub(crate) fn is_valid_and_exposed(&self) -> bool { self.is_valid() && self.kind() != CXType_Unexposed } /// Is this type a fully instantiated template? - pub fn is_fully_instantiated_template(&self) -> bool { + pub(crate) fn is_fully_instantiated_template(&self) -> bool { // Yep, the spelling of this containing type-parameter is extremely // nasty... But can happen in . Unfortunately I couldn't // reduce it enough :( @@ -1431,16 +1526,16 @@ impl Type { /// typename T::Associated member; /// }; /// ``` - pub fn is_associated_type(&self) -> bool { + pub(crate) fn is_associated_type(&self) -> bool { // This is terrible :( fn hacky_parse_associated_type>(spelling: S) -> bool { - lazy_static! { - static ref ASSOC_TYPE_RE: regex::Regex = regex::Regex::new( - r"typename type\-parameter\-\d+\-\d+::.+" - ) - .unwrap(); - } - ASSOC_TYPE_RE.is_match(spelling.as_ref()) + static ASSOC_TYPE_RE: OnceLock = OnceLock::new(); + ASSOC_TYPE_RE + .get_or_init(|| { + regex::Regex::new(r"typename type\-parameter\-\d+\-\d+::.+") + .unwrap() + }) + .is_match(spelling.as_ref()) } self.kind() == CXType_Unexposed && @@ -1457,22 +1552,22 @@ impl Type { /// cursor match up in a canonical declaration relationship, and it simply /// cannot be otherwise. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct CanonicalTypeDeclaration(Type, Cursor); +pub(crate) struct CanonicalTypeDeclaration(Type, Cursor); impl CanonicalTypeDeclaration { /// Get the type. - pub fn ty(&self) -> &Type { + pub(crate) fn ty(&self) -> &Type { &self.0 } /// Get the type's canonical declaration cursor. - pub fn cursor(&self) -> &Cursor { + pub(crate) fn cursor(&self) -> &Cursor { &self.1 } } /// An iterator for a type's template arguments. -pub struct TypeTemplateArgIterator { +pub(crate) struct TypeTemplateArgIterator { x: CXType, length: u32, index: u32, @@ -1502,20 +1597,20 @@ impl ExactSizeIterator for TypeTemplateArgIterator { /// A `SourceLocation` is a file, line, column, and byte offset location for /// some source text. -pub struct SourceLocation { +pub(crate) struct SourceLocation { x: CXSourceLocation, } impl SourceLocation { /// Get the (file, line, column, byte offset) tuple for this source /// location. - pub fn location(&self) -> (File, usize, usize, usize) { + pub(crate) fn location(&self) -> (File, usize, usize, usize) { unsafe { let mut file = mem::zeroed(); let mut line = 0; let mut col = 0; let mut off = 0; - clang_getSpellingLocation( + clang_getFileLocation( self.x, &mut file, &mut line, &mut col, &mut off, ); (File { x: file }, line as usize, col as usize, off as usize) @@ -1543,18 +1638,18 @@ impl fmt::Debug for SourceLocation { /// A comment in the source text. /// /// Comments are sort of parsed by Clang, and have a tree structure. -pub struct Comment { +pub(crate) struct Comment { x: CXComment, } impl Comment { /// What kind of comment is this? - pub fn kind(&self) -> CXCommentKind { + pub(crate) fn kind(&self) -> CXCommentKind { unsafe { clang_Comment_getKind(self.x) } } /// Get this comment's children comment - pub fn get_children(&self) -> CommentChildrenIterator { + pub(crate) fn get_children(&self) -> CommentChildrenIterator { CommentChildrenIterator { parent: self.x, length: unsafe { clang_Comment_getNumChildren(self.x) }, @@ -1564,12 +1659,12 @@ impl Comment { /// Given that this comment is the start or end of an HTML tag, get its tag /// name. - pub fn get_tag_name(&self) -> String { + pub(crate) fn get_tag_name(&self) -> String { unsafe { cxstring_into_string(clang_HTMLTagComment_getTagName(self.x)) } } /// Given that this comment is an HTML start tag, get its attributes. - pub fn get_tag_attrs(&self) -> CommentAttributesIterator { + pub(crate) fn get_tag_attrs(&self) -> CommentAttributesIterator { CommentAttributesIterator { x: self.x, length: unsafe { clang_HTMLStartTag_getNumAttrs(self.x) }, @@ -1579,7 +1674,7 @@ impl Comment { } /// An iterator for a comment's children -pub struct CommentChildrenIterator { +pub(crate) struct CommentChildrenIterator { parent: CXComment, length: c_uint, index: c_uint, @@ -1601,15 +1696,15 @@ impl Iterator for CommentChildrenIterator { } /// An HTML start tag comment attribute -pub struct CommentAttribute { +pub(crate) struct CommentAttribute { /// HTML start tag attribute name - pub name: String, + pub(crate) name: String, /// HTML start tag attribute value - pub value: String, + pub(crate) value: String, } /// An iterator for a comment's attributes -pub struct CommentAttributesIterator { +pub(crate) struct CommentAttributesIterator { x: CXComment, length: c_uint, index: c_uint, @@ -1640,13 +1735,13 @@ impl Iterator for CommentAttributesIterator { } /// A source file. -pub struct File { +pub(crate) struct File { x: CXFile, } impl File { /// Get the name of this source file. - pub fn name(&self) -> Option { + pub(crate) fn name(&self) -> Option { if self.x.is_null() { return None; } @@ -1670,7 +1765,7 @@ fn cxstring_into_string(s: CXString) -> String { /// An `Index` is an environment for a set of translation units that will /// typically end up linked together in one final binary. -pub struct Index { +pub(crate) struct Index { x: CXIndex, } @@ -1681,7 +1776,7 @@ impl Index { /// headers are included when enumerating a translation unit's "locals". /// /// The `diag` parameter controls whether debugging diagnostics are enabled. - pub fn new(pch: bool, diag: bool) -> Index { + pub(crate) fn new(pch: bool, diag: bool) -> Index { unsafe { Index { x: clang_createIndex(pch as c_int, diag as c_int), @@ -1705,7 +1800,7 @@ impl Drop for Index { } /// A translation unit (or "compilation unit"). -pub struct TranslationUnit { +pub(crate) struct TranslationUnit { x: CXTranslationUnit, } @@ -1717,17 +1812,17 @@ impl fmt::Debug for TranslationUnit { impl TranslationUnit { /// Parse a source file into a translation unit. - pub fn parse( + pub(crate) fn parse( ix: &Index, file: &str, - cmd_args: &[String], + cmd_args: &[Box], unsaved: &[UnsavedFile], opts: CXTranslationUnit_Flags, ) -> Option { let fname = CString::new(file).unwrap(); let _c_args: Vec = cmd_args .iter() - .map(|s| CString::new(s.clone()).unwrap()) + .map(|s| CString::new(s.as_bytes()).unwrap()) .collect(); let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect(); @@ -1753,7 +1848,7 @@ impl TranslationUnit { /// Get the Clang diagnostic information associated with this translation /// unit. - pub fn diags(&self) -> Vec { + pub(crate) fn diags(&self) -> Vec { unsafe { let num = clang_getNumDiagnostics(self.x) as usize; let mut diags = vec![]; @@ -1767,7 +1862,7 @@ impl TranslationUnit { } /// Get a cursor pointing to the root of this translation unit's AST. - pub fn cursor(&self) -> Cursor { + pub(crate) fn cursor(&self) -> Cursor { unsafe { Cursor { x: clang_getTranslationUnitCursor(self.x), @@ -1775,8 +1870,29 @@ impl TranslationUnit { } } + /// Save a translation unit to the given file. + pub(crate) fn save(&mut self, file: &str) -> Result<(), CXSaveError> { + let file = if let Ok(cstring) = CString::new(file) { + cstring + } else { + return Err(CXSaveError_Unknown); + }; + let ret = unsafe { + clang_saveTranslationUnit( + self.x, + file.as_ptr(), + clang_defaultSaveOptions(self.x), + ) + }; + if ret != 0 { + Err(ret) + } else { + Ok(()) + } + } + /// Is this the null translation unit? - pub fn is_null(&self) -> bool { + pub(crate) fn is_null(&self) -> bool { self.x.is_null() } } @@ -1789,15 +1905,100 @@ impl Drop for TranslationUnit { } } +/// Translation unit used for macro fallback parsing +pub(crate) struct FallbackTranslationUnit { + file_path: String, + header_path: String, + pch_path: String, + idx: Box, + tu: TranslationUnit, +} + +impl fmt::Debug for FallbackTranslationUnit { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "FallbackTranslationUnit {{ }}") + } +} + +impl FallbackTranslationUnit { + /// Create a new fallback translation unit + pub(crate) fn new( + file: String, + header_path: String, + pch_path: String, + c_args: &[Box], + ) -> Option { + // Create empty file + OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(&file) + .ok()?; + + let f_index = Box::new(Index::new(true, false)); + let f_translation_unit = TranslationUnit::parse( + &f_index, + &file, + c_args, + &[], + CXTranslationUnit_None, + )?; + Some(FallbackTranslationUnit { + file_path: file, + header_path, + pch_path, + tu: f_translation_unit, + idx: f_index, + }) + } + + /// Get reference to underlying translation unit. + pub(crate) fn translation_unit(&self) -> &TranslationUnit { + &self.tu + } + + /// Reparse a translation unit. + pub(crate) fn reparse( + &mut self, + unsaved_contents: &str, + ) -> Result<(), CXErrorCode> { + let unsaved = &[UnsavedFile::new(&self.file_path, unsaved_contents)]; + let mut c_unsaved: Vec = + unsaved.iter().map(|f| f.x).collect(); + let ret = unsafe { + clang_reparseTranslationUnit( + self.tu.x, + unsaved.len() as c_uint, + c_unsaved.as_mut_ptr(), + clang_defaultReparseOptions(self.tu.x), + ) + }; + if ret != 0 { + Err(ret) + } else { + Ok(()) + } + } +} + +impl Drop for FallbackTranslationUnit { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.file_path); + let _ = std::fs::remove_file(&self.header_path); + let _ = std::fs::remove_file(&self.pch_path); + } +} + /// A diagnostic message generated while parsing a translation unit. -pub struct Diagnostic { +pub(crate) struct Diagnostic { x: CXDiagnostic, } impl Diagnostic { /// Format this diagnostic message as a string, using the given option bit /// flags. - pub fn format(&self) -> String { + pub(crate) fn format(&self) -> String { unsafe { let opts = clang_defaultDiagnosticDisplayOptions(); cxstring_into_string(clang_formatDiagnostic(self.x, opts)) @@ -1805,7 +2006,7 @@ impl Diagnostic { } /// What is the severity of this diagnostic message? - pub fn severity(&self) -> CXDiagnosticSeverity { + pub(crate) fn severity(&self) -> CXDiagnosticSeverity { unsafe { clang_getDiagnosticSeverity(self.x) } } } @@ -1820,19 +2021,19 @@ impl Drop for Diagnostic { } /// A file which has not been saved to disk. -pub struct UnsavedFile { +pub(crate) struct UnsavedFile { x: CXUnsavedFile, /// The name of the unsaved file. Kept here to avoid leaving dangling pointers in /// `CXUnsavedFile`. - pub name: CString, + pub(crate) name: CString, contents: CString, } impl UnsavedFile { /// Construct a new unsaved file with the given `name` and `contents`. - pub fn new(name: String, contents: String) -> UnsavedFile { - let name = CString::new(name).unwrap(); - let contents = CString::new(contents).unwrap(); + pub(crate) fn new(name: &str, contents: &str) -> UnsavedFile { + let name = CString::new(name.as_bytes()).unwrap(); + let contents = CString::new(contents.as_bytes()).unwrap(); let x = CXUnsavedFile { Filename: name.as_ptr(), Contents: contents.as_ptr(), @@ -1853,17 +2054,17 @@ impl fmt::Debug for UnsavedFile { } /// Convert a cursor kind into a static string. -pub fn kind_to_str(x: CXCursorKind) -> String { +pub(crate) fn kind_to_str(x: CXCursorKind) -> String { unsafe { cxstring_into_string(clang_getCursorKindSpelling(x)) } } /// Convert a type kind to a static string. -pub fn type_to_str(x: CXTypeKind) -> String { +pub(crate) fn type_to_str(x: CXTypeKind) -> String { unsafe { cxstring_into_string(clang_getTypeKindSpelling(x)) } } /// Dump the Clang AST to stdout for debugging purposes. -pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { +pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { fn print_indent>(depth: isize, s: S) { for _ in 0..depth { print!(" "); @@ -2095,19 +2296,20 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { } /// Try to extract the clang version to a string -pub fn extract_clang_version() -> String { +pub(crate) fn extract_clang_version() -> String { unsafe { cxstring_into_string(clang_getClangVersion()) } } /// A wrapper for the result of evaluating an expression. #[derive(Debug)] -pub struct EvalResult { +pub(crate) struct EvalResult { x: CXEvalResult, + ty: Type, } impl EvalResult { /// Evaluate `cursor` and return the result. - pub fn new(cursor: Cursor) -> Option { + pub(crate) fn new(cursor: Cursor) -> Option { // Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see: // * https://github.com/rust-lang/rust-bindgen/issues/283 // * https://github.com/rust-lang/rust-bindgen/issues/1590 @@ -2130,6 +2332,7 @@ impl EvalResult { } Some(EvalResult { x: unsafe { clang_Cursor_Evaluate(cursor.x) }, + ty: cursor.cur_type().canonical_type(), }) } @@ -2138,7 +2341,7 @@ impl EvalResult { } /// Try to get back the result as a double. - pub fn as_double(&self) -> Option { + pub(crate) fn as_double(&self) -> Option { match self.kind() { CXEval_Float => { Some(unsafe { clang_EvalResult_getAsDouble(self.x) }) @@ -2148,14 +2351,14 @@ impl EvalResult { } /// Try to get back the result as an integer. - pub fn as_int(&self) -> Option { + pub(crate) fn as_int(&self) -> Option { if self.kind() != CXEval_Int { return None; } if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 { let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) }; - if value > i64::max_value() as c_ulonglong { + if value > i64::MAX as c_ulonglong { return None; } @@ -2163,10 +2366,10 @@ impl EvalResult { } let value = unsafe { clang_EvalResult_getAsLongLong(self.x) }; - if value > i64::max_value() as c_longlong { + if value > i64::MAX as c_longlong { return None; } - if value < i64::min_value() as c_longlong { + if value < i64::MIN as c_longlong { return None; } #[allow(clippy::unnecessary_cast)] @@ -2175,14 +2378,23 @@ impl EvalResult { /// Evaluates the expression as a literal string, that may or may not be /// valid utf-8. - pub fn as_literal_string(&self) -> Option> { - match self.kind() { - CXEval_StrLiteral => { + pub(crate) fn as_literal_string(&self) -> Option> { + if self.kind() != CXEval_StrLiteral { + return None; + } + + let char_ty = self.ty.pointee_type().or_else(|| self.ty.elem_type())?; + match char_ty.kind() { + CXType_Char_S | CXType_SChar | CXType_Char_U | CXType_UChar => { let ret = unsafe { CStr::from_ptr(clang_EvalResult_getAsStr(self.x)) }; Some(ret.to_bytes().to_vec()) } + // FIXME: Support generating these. + CXType_Char16 => None, + CXType_Char32 => None, + CXType_WChar => None, _ => None, } } @@ -2193,19 +2405,30 @@ impl Drop for EvalResult { unsafe { clang_EvalResult_dispose(self.x) }; } } +/// ABI kinds as defined in +/// +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub(crate) enum ABIKind { + /// All the regular targets like Linux, Mac, WASM, etc. implement the Itanium ABI + GenericItanium, + /// The ABI used when compiling for the MSVC target + Microsoft, +} /// Target information obtained from libclang. #[derive(Debug)] -pub struct TargetInfo { +pub(crate) struct TargetInfo { /// The target triple. - pub triple: String, + pub(crate) triple: String, /// The width of the pointer _in bits_. - pub pointer_width: usize, + pub(crate) pointer_width: usize, + /// The ABI of the target + pub(crate) abi: ABIKind, } impl TargetInfo { /// Tries to obtain target information from libclang. - pub fn new(tu: &TranslationUnit) -> Self { + pub(crate) fn new(tu: &TranslationUnit) -> Self { let triple; let pointer_width; unsafe { @@ -2216,9 +2439,17 @@ impl TargetInfo { } assert!(pointer_width > 0); assert_eq!(pointer_width % 8, 0); + + let abi = if triple.contains("msvc") { + ABIKind::Microsoft + } else { + ABIKind::GenericItanium + }; + TargetInfo { triple, pointer_width: pointer_width as usize, + abi, } } } diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index d8ea81175e265e35354995c729b401bc69272dc4..4b2749ec0ccc9a87d14c482252486515949a4a72 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -1,11 +1,11 @@ use crate::codegen; use crate::ir::context::BindgenContext; use crate::ir::function::ClangAbi; -use proc_macro2::Ident; +use proc_macro2::{Ident, TokenStream}; /// Used to build the output tokens for dynamic bindings. #[derive(Default)] -pub struct DynamicItems { +pub(crate) struct DynamicItems { /// Tracks the tokens that will appears inside the library struct -- e.g.: /// ```ignore /// struct Lib { @@ -69,11 +69,11 @@ pub struct DynamicItems { } impl DynamicItems { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self::default() } - pub fn get_tokens( + pub(crate) fn get_tokens( &self, lib_ident: Ident, ctx: &BindgenContext, @@ -90,8 +90,6 @@ impl DynamicItems { }; quote! { - extern crate libloading; - pub struct #lib_ident { __library: ::libloading::Library, #(#struct_members)* @@ -124,7 +122,7 @@ impl DynamicItems { } #[allow(clippy::too_many_arguments)] - pub(crate) fn push( + pub(crate) fn push_func( &mut self, ident: Ident, abi: ClangAbi, @@ -198,4 +196,47 @@ impl DynamicItems { #ident }); } + + pub fn push_var( + &mut self, + ident: Ident, + ty: TokenStream, + is_required: bool, + ) { + let member = if is_required { + quote! { *mut #ty } + } else { + quote! { Result<*mut #ty, ::libloading::Error> } + }; + + self.struct_members.push(quote! { + pub #ident: #member, + }); + + let deref = if is_required { + quote! { self.#ident } + } else { + quote! { *self.#ident.as_ref().expect("Expected variable, got error.") } + }; + self.struct_implementation.push(quote! { + pub unsafe fn #ident (&self) -> *mut #ty { + #deref + } + }); + + let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + self.constructor_inits.push(if is_required { + quote! { + let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym)?; + } + } else { + quote! { + let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym); + } + }); + + self.init_fields.push(quote! { + #ident + }); + } } diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index c1bcf4e1cb51adf74f4b0ef0bfee14ffeed81ed0..82e921d771c57292d59925f5ea2589df6f19d619 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -3,7 +3,7 @@ use std::fmt; /// Errors that can occur during code generation. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum Error { +pub(crate) enum Error { /// Tried to generate an opaque blob for a type that did not have a layout. NoLayoutForOpaqueBlob, @@ -11,23 +11,43 @@ pub enum Error { /// definition that is too difficult for us to understand (like a partial /// template specialization). InstantiationOfOpaqueType, + + /// Function ABI is not supported. + UnsupportedAbi(&'static str), + + /// The pointer type size does not match the target's pointer size. + InvalidPointerSize { + ty_name: String, + ty_size: usize, + ptr_size: usize, + }, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match *self { + match self { Error::NoLayoutForOpaqueBlob => { - "Tried to generate an opaque blob, but had no layout" + "Tried to generate an opaque blob, but had no layout.".fmt(f) } Error::InstantiationOfOpaqueType => { - "Instantiation of opaque template type or partial template \ - specialization" + "Instantiation of opaque template type or partial template specialization." + .fmt(f) + } + Error::UnsupportedAbi(abi) => { + write!( + f, + "{} ABI is not supported by the configured Rust target.", + abi + ) + } + Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => { + write!(f, "The {} pointer type has size {} but the current target's pointer size is {}.", ty_name, ty_size, ptr_size) } - }) + } } } impl error::Error for Error {} /// A `Result` of `T` or an error of `bindgen::codegen::error::Error`. -pub type Result = ::std::result::Result; +pub(crate) type Result = ::std::result::Result; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 088c7f9363e0a37b9e698f4e605637bc01d8b023..40383401006a5724810c9d7de0eb1f7fef7d2e76 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -1,22 +1,22 @@ //! Helpers for code generation that don't need macro expansion. +use proc_macro2::{Ident, Span}; + use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; -use proc_macro2::{Ident, Span, TokenStream}; -use quote::TokenStreamExt; -pub mod attributes { +pub(crate) mod attributes { use proc_macro2::{Ident, Span, TokenStream}; - use std::str::FromStr; + use std::{borrow::Cow, str::FromStr}; - pub fn repr(which: &str) -> TokenStream { + pub(crate) fn repr(which: &str) -> TokenStream { let which = Ident::new(which, Span::call_site()); quote! { #[repr( #which )] } } - pub fn repr_list(which_ones: &[&str]) -> TokenStream { + pub(crate) fn repr_list(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() .cloned() @@ -26,7 +26,7 @@ pub mod attributes { } } - pub fn derives(which_ones: &[&str]) -> TokenStream { + pub(crate) fn derives(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() .cloned() @@ -36,25 +36,25 @@ pub mod attributes { } } - pub fn inline() -> TokenStream { + pub(crate) fn inline() -> TokenStream { quote! { #[inline] } } - pub fn must_use() -> TokenStream { + pub(crate) fn must_use() -> TokenStream { quote! { #[must_use] } } - pub fn non_exhaustive() -> TokenStream { + pub(crate) fn non_exhaustive() -> TokenStream { quote! { #[non_exhaustive] } } - pub fn doc(comment: String) -> TokenStream { + pub(crate) fn doc(comment: String) -> TokenStream { if comment.is_empty() { quote!() } else { @@ -62,10 +62,15 @@ pub mod attributes { } } - pub fn link_name(name: &str) -> TokenStream { + pub(crate) fn link_name(name: &str) -> TokenStream { // LLVM mangles the name by default but it's already mangled. // Prefixing the name with \u{1} should tell LLVM to not mangle it. - let name = format!("\u{1}{}", name); + let name: Cow<'_, str> = if MANGLE { + name.into() + } else { + format!("\u{1}{}", name).into() + }; + quote! { #[link_name = #name] } @@ -74,140 +79,188 @@ pub mod attributes { /// Generates a proper type for a field or type with a given `Layout`, that is, /// a type with the correct size and alignment restrictions. -pub fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { +pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> syn::Type { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are // some things that legitimately are more than 8-byte aligned. // // Eventually we should be able to `unwrap` here, but... - let ty_name = match opaque.known_rust_type_for_array(ctx) { + let ty = match opaque.known_rust_type_for_array(ctx) { Some(ty) => ty, None => { warn!("Found unknown alignment on code generation!"); - "u8" + syn::parse_quote! { u8 } } }; - let ty_name = Ident::new(ty_name, Span::call_site()); - let data_len = opaque.array_size(ctx).unwrap_or(layout.size); if data_len == 1 { - quote! { - #ty_name - } + ty } else { - quote! { - [ #ty_name ; #data_len ] - } + syn::parse_quote! { [ #ty ; #data_len ] } } } /// Integer type of the same size as the given `Layout`. -pub fn integer_type( +pub(crate) fn integer_type( ctx: &BindgenContext, layout: Layout, -) -> Option { - let name = Layout::known_type_for_size(ctx, layout.size)?; - let name = Ident::new(name, Span::call_site()); - Some(quote! { #name }) +) -> Option { + Layout::known_type_for_size(ctx, layout.size) } +pub(crate) const BITFIELD_UNIT: &str = "__BindgenBitfieldUnit"; + /// Generates a bitfield allocation unit type for a type with the given `Layout`. -pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> TokenStream { - let mut tokens = quote! {}; +pub(crate) fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> syn::Type { + let size = layout.size; + let bitfield_unit_name = Ident::new(BITFIELD_UNIT, Span::call_site()); + let ty = syn::parse_quote! { #bitfield_unit_name<[u8; #size]> }; if ctx.options().enable_cxx_namespaces { - tokens.append_all(quote! { root:: }); + return syn::parse_quote! { root::#ty }; } - let size = layout.size; - tokens.append_all(quote! { - __BindgenBitfieldUnit<[u8; #size]> - }); - - tokens + ty } -pub mod ast_ty { +pub(crate) mod ast_ty { use crate::ir::context::BindgenContext; use crate::ir::function::FunctionSig; use crate::ir::layout::Layout; - use crate::ir::ty::FloatKind; - use proc_macro2::{self, TokenStream}; + use crate::ir::ty::{FloatKind, IntKind}; + use crate::RustTarget; + use proc_macro2::TokenStream; use std::str::FromStr; - pub fn c_void(ctx: &BindgenContext) -> TokenStream { + pub(crate) fn c_void(ctx: &BindgenContext) -> syn::Type { // ctypes_prefix takes precedence match ctx.options().ctypes_prefix { Some(ref prefix) => { let prefix = TokenStream::from_str(prefix.as_str()).unwrap(); - quote! { - #prefix::c_void - } + syn::parse_quote! { #prefix::c_void } } None => { if ctx.options().use_core && ctx.options().rust_features.core_ffi_c_void { - quote! { ::core::ffi::c_void } + syn::parse_quote! { ::core::ffi::c_void } } else { - quote! { ::std::os::raw::c_void } + syn::parse_quote! { ::std::os::raw::c_void } } } } } - pub fn raw_type(ctx: &BindgenContext, name: &str) -> TokenStream { + pub(crate) fn raw_type(ctx: &BindgenContext, name: &str) -> syn::Type { let ident = ctx.rust_ident_raw(name); match ctx.options().ctypes_prefix { Some(ref prefix) => { let prefix = TokenStream::from_str(prefix.as_str()).unwrap(); - quote! { - #prefix::#ident - } + syn::parse_quote! { #prefix::#ident } } None => { if ctx.options().use_core && ctx.options().rust_features().core_ffi_c { - quote! { - ::core::ffi::#ident - } + syn::parse_quote! { ::core::ffi::#ident } } else { - quote! { - ::std::os::raw::#ident - } + syn::parse_quote! { ::std::os::raw::#ident } + } + } + } + } + + pub(crate) fn int_kind_rust_type( + ctx: &BindgenContext, + ik: IntKind, + layout: Option, + ) -> syn::Type { + match ik { + IntKind::Bool => syn::parse_quote! { bool }, + IntKind::Char { .. } => raw_type(ctx, "c_char"), + IntKind::SChar => raw_type(ctx, "c_schar"), + IntKind::UChar => raw_type(ctx, "c_uchar"), + IntKind::Short => raw_type(ctx, "c_short"), + IntKind::UShort => raw_type(ctx, "c_ushort"), + IntKind::Int => raw_type(ctx, "c_int"), + IntKind::UInt => raw_type(ctx, "c_uint"), + IntKind::Long => raw_type(ctx, "c_long"), + IntKind::ULong => raw_type(ctx, "c_ulong"), + IntKind::LongLong => raw_type(ctx, "c_longlong"), + IntKind::ULongLong => raw_type(ctx, "c_ulonglong"), + IntKind::WChar => { + let layout = + layout.expect("Couldn't compute wchar_t's layout?"); + Layout::known_type_for_size(ctx, layout.size) + .expect("Non-representable wchar_t?") + } + + IntKind::I8 => syn::parse_quote! { i8 }, + IntKind::U8 => syn::parse_quote! { u8 }, + IntKind::I16 => syn::parse_quote! { i16 }, + IntKind::U16 => syn::parse_quote! { u16 }, + IntKind::I32 => syn::parse_quote! { i32 }, + IntKind::U32 => syn::parse_quote! { u32 }, + IntKind::I64 => syn::parse_quote! { i64 }, + IntKind::U64 => syn::parse_quote! { u64 }, + IntKind::Custom { name, .. } => { + syn::parse_str(name).expect("Invalid integer type.") + } + IntKind::U128 => { + if ctx.options().rust_features.i128_and_u128 { + syn::parse_quote! { u128 } + } else { + // Best effort thing, but wrong alignment + // unfortunately. + syn::parse_quote! { [u64; 2] } + } + } + IntKind::I128 => { + if ctx.options().rust_features.i128_and_u128 { + syn::parse_quote! { i128 } + } else { + syn::parse_quote! { [u64; 2] } } } } } - pub fn float_kind_rust_type( + pub(crate) fn float_kind_rust_type( ctx: &BindgenContext, fk: FloatKind, layout: Option, - ) -> TokenStream { + ) -> syn::Type { // TODO: we probably should take the type layout into account more // often? // // Also, maybe this one shouldn't be the default? match (fk, ctx.options().convert_floats) { - (FloatKind::Float, true) => quote! { f32 }, - (FloatKind::Double, true) => quote! { f64 }, + (FloatKind::Float16, _) => { + // TODO: do f16 when rust lands it + ctx.generated_bindgen_float16(); + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__BindgenFloat16 } + } else { + syn::parse_quote! { __BindgenFloat16 } + } + } + (FloatKind::Float, true) => syn::parse_quote! { f32 }, + (FloatKind::Double, true) => syn::parse_quote! { f64 }, (FloatKind::Float, false) => raw_type(ctx, "c_float"), (FloatKind::Double, false) => raw_type(ctx, "c_double"), (FloatKind::LongDouble, _) => { match layout { Some(layout) => { match layout.size { - 4 => quote! { f32 }, - 8 => quote! { f64 }, + 4 => syn::parse_quote! { f32 }, + 8 => syn::parse_quote! { f64 }, // TODO(emilio): If rust ever gains f128 we should // use it here and below. _ => super::integer_type(ctx, layout) - .unwrap_or(quote! { f64 }), + .unwrap_or(syn::parse_quote! { f64 }), } } None => { @@ -215,39 +268,33 @@ pub mod ast_ty { false, "How didn't we know the layout for a primitive type?" ); - quote! { f64 } + syn::parse_quote! { f64 } } } } (FloatKind::Float128, _) => { if ctx.options().rust_features.i128_and_u128 { - quote! { u128 } + syn::parse_quote! { u128 } } else { - quote! { [u64; 2] } + syn::parse_quote! { [u64; 2] } } } } } - pub fn int_expr(val: i64) -> TokenStream { + pub(crate) fn int_expr(val: i64) -> TokenStream { // Don't use quote! { #val } because that adds the type suffix. let val = proc_macro2::Literal::i64_unsuffixed(val); quote!(#val) } - pub fn uint_expr(val: u64) -> TokenStream { + pub(crate) fn uint_expr(val: u64) -> TokenStream { // Don't use quote! { #val } because that adds the type suffix. let val = proc_macro2::Literal::u64_unsuffixed(val); quote!(#val) } - pub fn byte_array_expr(bytes: &[u8]) -> TokenStream { - let mut bytes: Vec<_> = bytes.to_vec(); - bytes.push(0); - quote! { [ #(#bytes),* ] } - } - - pub fn cstr_expr(mut string: String) -> TokenStream { + pub(crate) fn cstr_expr(mut string: String) -> TokenStream { string.push('\0'); let b = proc_macro2::Literal::byte_string(string.as_bytes()); quote! { @@ -255,7 +302,10 @@ pub mod ast_ty { } } - pub fn float_expr(ctx: &BindgenContext, f: f64) -> Result { + pub(crate) fn float_expr( + ctx: &BindgenContext, + f: f64, + ) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); @@ -263,30 +313,52 @@ pub mod ast_ty { } let prefix = ctx.trait_prefix(); + let rust_target = ctx.options().rust_target; if f.is_nan() { - return Ok(quote! { - ::#prefix::f64::NAN - }); + let tokens = if rust_target >= RustTarget::Stable_1_43 { + quote! { + f64::NAN + } + } else { + quote! { + ::#prefix::f64::NAN + } + }; + return Ok(tokens); } if f.is_infinite() { - return Ok(if f.is_sign_positive() { - quote! { - ::#prefix::f64::INFINITY + let tokens = if f.is_sign_positive() { + if rust_target >= RustTarget::Stable_1_43 { + quote! { + f64::INFINITY + } + } else { + quote! { + ::#prefix::f64::INFINITY + } } } else { - quote! { - ::#prefix::f64::NEG_INFINITY + // Negative infinity + if rust_target >= RustTarget::Stable_1_43 { + quote! { + f64::NEG_INFINITY + } + } else { + quote! { + ::#prefix::f64::NEG_INFINITY + } } - }); + }; + return Ok(tokens); } warn!("Unknown non-finite float number: {:?}", f); Err(()) } - pub fn arguments_from_signature( + pub(crate) fn arguments_from_signature( signature: &FunctionSig, ctx: &BindgenContext, ) -> Vec { diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 0e2cd33ad56e48f72915374474ab23e826245df9..67ec214ee887b5f981d3d300d33128cc02258e51 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -3,7 +3,7 @@ use crate::ir::context::BindgenContext; use crate::ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName}; use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; -pub fn gen_debug_impl( +pub(crate) fn gen_debug_impl( ctx: &BindgenContext, fields: &[Field], item: &Item, @@ -51,7 +51,7 @@ pub fn gen_debug_impl( /// A trait for the things which we can codegen tokens that contribute towards a /// generated `impl Debug`. -pub trait ImplDebug<'a> { +pub(crate) trait ImplDebug<'a> { /// Any extra parameter required by this a particular `ImplDebug` implementation. type Extra; diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 960306ffc6235e77a299d5ddb22ae3cdd29ece9d..42fabf6ad05962c07c4c2235aca39369c28ee990 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -5,7 +5,7 @@ use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; /// Generate a manual implementation of `PartialEq` trait for the /// specified compound type. -pub fn gen_partialeq_impl( +pub(crate) fn gen_partialeq_impl( ctx: &BindgenContext, comp_info: &CompInfo, item: &Item, @@ -18,7 +18,7 @@ pub fn gen_partialeq_impl( &self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..] }); } else if comp_info.kind() == CompKind::Union { - assert!(!ctx.options().rust_features().untagged_union); + assert!(!ctx.options().untagged_union); tokens.push(quote! { &self.bindgen_union_field[..] == &other.bindgen_union_field[..] }); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b6fb70eb01beb0816eae69abb94096c1e041c762..2eabcf05ee49c39ee753265a24a40c07c5798e0d 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1,11 +1,12 @@ mod dyngen; -mod error; +pub(crate) mod error; + mod helpers; mod impl_debug; mod impl_partialeq; mod postprocessing; mod serialize; -pub mod struct_layout; +pub(crate) mod struct_layout; #[cfg(test)] #[allow(warnings)] @@ -19,9 +20,12 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; -use crate::callbacks::{DeriveInfo, TypeKind as DeriveTypeKind}; +use crate::callbacks::{DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind}; +use crate::codegen::error::Error; use crate::ir::analysis::{HasVtable, Sizedness}; -use crate::ir::annotations::FieldAccessorKind; +use crate::ir::annotations::{ + Annotations, FieldAccessorKind, FieldVisibilityKind, +}; use crate::ir::comp::{ Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, FieldMethods, Method, MethodKind, @@ -34,7 +38,7 @@ use crate::ir::derive::{ use crate::ir::dot; use crate::ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; use crate::ir::function::{ - Abi, ClangAbi, Function, FunctionKind, FunctionSig, Linkage, + ClangAbi, Function, FunctionKind, FunctionSig, Linkage, }; use crate::ir::int::IntKind; use crate::ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; @@ -48,17 +52,17 @@ use crate::ir::template::{ use crate::ir::ty::{Type, TypeKind}; use crate::ir::var::Var; -use proc_macro2::{self, Ident, Span}; -use quote::TokenStreamExt; +use proc_macro2::{Ident, Span}; +use quote::{ToTokens, TokenStreamExt}; use crate::{Entry, HashMap, HashSet}; use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; -use std::fmt::Write; -use std::iter; +use std::ffi::CStr; +use std::fmt::{self, Write}; use std::ops; -use std::str::FromStr; +use std::str::{self, FromStr}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CodegenError { @@ -72,19 +76,19 @@ impl From for CodegenError { } } -impl std::fmt::Display for CodegenError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for CodegenError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - CodegenError::Serialize { msg, loc } => { + Self::Serialize { msg, loc } => { write!(f, "serialization error at {}: {}", loc, msg) } - CodegenError::Io(err) => err.fmt(f), + Self::Io(err) => err.fmt(f), } } } // Name of type defined in constified enum module -pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; +pub(crate) static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; fn top_level_path( ctx: &BindgenContext, @@ -124,6 +128,7 @@ fn root_import( } bitflags! { + // #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] struct DerivableTraits: u16 { const DEBUG = 1 << 0; const DEFAULT = 1 << 1; @@ -218,11 +223,16 @@ impl From for Vec<&'static str> { } } +struct WrapAsVariadic { + new_name: String, + idx_of_va_list_arg: usize, +} + struct CodegenResult<'a> { items: Vec, dynamic_items: DynamicItems, - /// A monotonic counter used to add stable unique id's to stuff that doesn't + /// A monotonic counter used to add stable unique ID's to stuff that doesn't /// need to be referenced by anything. codegen_id: &'a Cell, @@ -266,7 +276,9 @@ struct CodegenResult<'a> { /// that name. This lets us give each overload a unique suffix. overload_counters: HashMap, - items_to_serialize: Vec, + /// List of items to serialize. With optionally the argument for the wrap as + /// variadic transformation to be applied. + items_to_serialize: Vec<(ItemId, Option)>, } impl<'a> CodegenResult<'a> { @@ -381,45 +393,44 @@ impl<'a> ops::DerefMut for CodegenResult<'a> { /// A trait to convert a rust type into a pointer, optionally const, to the same /// type. trait ToPtr { - fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream; + fn to_ptr(self, is_const: bool) -> syn::Type; } -impl ToPtr for proc_macro2::TokenStream { - fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream { +impl ToPtr for syn::Type { + fn to_ptr(self, is_const: bool) -> syn::Type { if is_const { - quote! { *const #self } + syn::parse_quote! { *const #self } } else { - quote! { *mut #self } + syn::parse_quote! { *mut #self } } } } -/// An extension trait for `proc_macro2::TokenStream` that lets us append any implicit +/// An extension trait for `syn::Type` that lets us append any implicit /// template parameters that exist for some type, if necessary. -trait AppendImplicitTemplateParams { - fn append_implicit_template_params( - &mut self, +trait WithImplicitTemplateParams { + fn with_implicit_template_params( + self, ctx: &BindgenContext, item: &Item, - ); + ) -> Self; } -impl AppendImplicitTemplateParams for proc_macro2::TokenStream { - fn append_implicit_template_params( - &mut self, +impl WithImplicitTemplateParams for syn::Type { + fn with_implicit_template_params( + self, ctx: &BindgenContext, item: &Item, - ) { + ) -> Self { let item = item.id().into_resolver().through_type_refs().resolve(ctx); - match *item.expect_type().kind() { + let params = match *item.expect_type().kind() { TypeKind::UnresolvedTypeRef(..) => { unreachable!("already resolved unresolved type refs") } TypeKind::ResolvedTypeRef(..) => { unreachable!("we resolved item through type refs") } - // None of these types ever have implicit template parameters. TypeKind::Void | TypeKind::NullPtr | @@ -435,22 +446,25 @@ impl AppendImplicitTemplateParams for proc_macro2::TokenStream { TypeKind::Enum(..) | TypeKind::ObjCId | TypeKind::ObjCSel | - TypeKind::TemplateInstantiation(..) => return, - _ => {} - } + TypeKind::TemplateInstantiation(..) => None, + _ => { + let params = item.used_template_params(ctx); + if params.is_empty() { + None + } else { + Some(params.into_iter().map(|p| { + p.try_to_rust_ty(ctx, &()).expect( + "template params cannot fail to be a rust type", + ) + })) + } + } + }; - let params: Vec<_> = item - .used_template_params(ctx) - .iter() - .map(|p| { - p.try_to_rust_ty(ctx, &()) - .expect("template params cannot fail to be a rust type") - }) - .collect(); - if !params.is_empty() { - self.append_all(quote! { - < #( #params ),* > - }); + if let Some(params) = params { + syn::parse_quote! { #self<#(#params),*> } + } else { + self } } } @@ -564,6 +578,9 @@ impl CodeGenerator for Module { if result.saw_incomplete_array { utils::prepend_incomplete_array_types(ctx, &mut *result); } + if ctx.need_bindgen_float16_type() { + utils::prepend_float16_type(&mut *result); + } if ctx.need_bindgen_complex_type() { utils::prepend_complex_type(&mut *result); } @@ -588,7 +605,10 @@ impl CodeGenerator for Module { let inner_items = result.inner(|result| { result.push(root_import(ctx, item)); - let path = item.namespace_aware_canonical_path(ctx).join("::"); + let path = item + .namespace_aware_canonical_path(ctx) + .join("::") + .into_boxed_str(); if let Some(raw_lines) = ctx.options().module_lines.get(&path) { for raw_line in raw_lines { found_any = true; @@ -660,7 +680,8 @@ impl CodeGenerator for Var { attrs.push(attributes::doc(comment)); } - let ty = self.ty().to_rust_ty_or_opaque(ctx, &()); + let var_ty = self.ty(); + let ty = var_ty.to_rust_ty_or_opaque(ctx, &()); if let Some(val) = self.val() { match *val { @@ -671,8 +692,7 @@ impl CodeGenerator for Var { }); } VarType::Int(val) => { - let int_kind = self - .ty() + let int_kind = var_ty .into_resolver() .through_type_aliases() .through_type_refs() @@ -691,41 +711,48 @@ impl CodeGenerator for Var { }); } VarType::String(ref bytes) => { - // Account the trailing zero. - // + let prefix = ctx.trait_prefix(); + + let options = ctx.options(); + let rust_features = options.rust_features; + + let mut cstr_bytes = bytes.clone(); + cstr_bytes.push(0); + let len = proc_macro2::Literal::usize_unsuffixed( + cstr_bytes.len(), + ); + // TODO: Here we ignore the type we just made up, probably - // we should refactor how the variable type and ty id work. - let len = bytes.len() + 1; - let ty = quote! { - [u8; #len] - }; + // we should refactor how the variable type and ty ID work. + let array_ty = quote! { [u8; #len] }; + let cstr_ty = quote! { ::#prefix::ffi::CStr }; - match String::from_utf8(bytes.clone()) { - Ok(string) => { - let cstr = helpers::ast_ty::cstr_expr(string); - if ctx - .options() - .rust_features - .static_lifetime_elision - { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : &#ty = #cstr ; - }); - } else { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : &'static #ty = #cstr ; - }); - } - } - Err(..) => { - let bytes = helpers::ast_ty::byte_array_expr(bytes); - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #bytes ; - }); + let bytes = proc_macro2::Literal::byte_string(&cstr_bytes); + + if options.generate_cstr && + rust_features.const_cstr && + CStr::from_bytes_with_nul(&cstr_bytes).is_ok() + { + result.push(quote! { + #(#attrs)* + #[allow(unsafe_code)] + pub const #canonical_ident: &#cstr_ty = unsafe { + #cstr_ty::from_bytes_with_nul_unchecked(#bytes) + }; + }); + } else { + let lifetime = if rust_features.static_lifetime_elision + { + None + } else { + Some(quote! { 'static }) } + .into_iter(); + + result.push(quote! { + #(#attrs)* + pub const #canonical_ident: &#(#lifetime )*#array_ty = #bytes ; + }); } } VarType::Float(f) => { @@ -745,13 +772,18 @@ impl CodeGenerator for Var { } } else { // If necessary, apply a `#[link_name]` attribute - let link_name = self.mangled_name().unwrap_or_else(|| self.name()); - if !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - None, - ) { - attrs.push(attributes::link_name(link_name)); + if let Some(link_name) = self.link_name() { + attrs.push(attributes::link_name::(link_name)); + } else { + let link_name = + self.mangled_name().unwrap_or_else(|| self.name()); + if !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + None, + ) { + attrs.push(attributes::link_name::(link_name)); + } } let maybe_mut = if self.is_const() { @@ -767,7 +799,17 @@ impl CodeGenerator for Var { } ); - result.push(tokens); + if ctx.options().dynamic_library_name.is_some() { + result.dynamic_items().push_var( + canonical_ident, + self.ty() + .to_rust_ty_or_opaque(ctx, &()) + .into_token_stream(), + ctx.options().dynamic_link_require_all, + ); + } else { + result.push(tokens); + } } } } @@ -907,11 +949,10 @@ impl CodeGenerator for Type { // Its possible that we have better layout information than // the inner type does, so fall back to an opaque blob based // on our layout if converting the inner item fails. - let mut inner_ty = inner_item + inner_item .try_to_rust_ty_or_opaque(ctx, &()) - .unwrap_or_else(|_| self.to_opaque(ctx, item)); - inner_ty.append_implicit_template_params(ctx, inner_item); - inner_ty + .unwrap_or_else(|_| self.to_opaque(ctx, item)) + .with_implicit_template_params(ctx, inner_item) }; { @@ -957,9 +998,8 @@ impl CodeGenerator for Type { // We prefer using `pub use` over `pub type` because of: // https://github.com/rust-lang/rust/issues/26264 - // These are the only characters allowed in simple - // paths, eg `good::dogs::Bront`. - if inner_rust_type.to_string().chars().all(|c| matches!(c, 'A'..='Z' | 'a'..='z' | '0'..='9' | ':' | '_' | ' ')) && outer_params.is_empty() && + if matches!(inner_rust_type, syn::Type::Path(_)) && + outer_params.is_empty() && !is_opaque && alias_style == AliasVariation::TypeAlias && inner_item.expect_type().canonical_type(ctx).is_enum() @@ -992,10 +1032,20 @@ impl CodeGenerator for Type { let packed = false; // Types can't be packed in Rust. let derivable_traits = derives_of_item(item, ctx, packed); - if !derivable_traits.is_empty() { - let derives: Vec<_> = derivable_traits.into(); - attributes.push(attributes::derives(&derives)) - } + let mut derives: Vec<_> = derivable_traits.into(); + // The custom derives callback may return a list of derive attributes; + // add them to the end of the list. + let custom_derives = + ctx.options().all_callbacks(|cb| { + cb.add_derives(&DeriveInfo { + name: &name, + kind: DeriveTypeKind::Struct, + }) + }); + // In most cases this will be a no-op, since custom_derives will be empty. + derives + .extend(custom_derives.iter().map(|s| s.as_str())); + attributes.push(attributes::derives(&derives)); quote! { #( #attributes )* @@ -1034,13 +1084,15 @@ impl CodeGenerator for Type { }); } + let access_spec = + access_specifier(ctx.options().default_visibility); tokens.append_all(match alias_style { AliasVariation::TypeAlias => quote! { = #inner_rust_type ; }, AliasVariation::NewType | AliasVariation::NewTypeDeref => { quote! { - (pub #inner_rust_type) ; + (#access_spec #inner_rust_type) ; } } }); @@ -1184,11 +1236,9 @@ impl<'a> TryToRustTy for Vtable<'a> { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { let name = ctx.rust_ident(self.canonical_name(ctx)); - Ok(quote! { - #name - }) + Ok(syn::parse_quote! { #name }) } } @@ -1214,6 +1264,9 @@ impl CodeGenerator for TemplateInstantiation { return; } + // For consistency with other layout tests, gate this on offset_of. + let compile_time = ctx.options().rust_features().offset_of; + // If there are any unbound type parameters, then we can't generate a // layout test because we aren't dealing with a concrete type with a // concrete size and alignment. @@ -1228,14 +1281,17 @@ impl CodeGenerator for TemplateInstantiation { let align = layout.align; let name = item.full_disambiguated_name(ctx); - let mut fn_name = - format!("__bindgen_test_layout_{}_instantiation", name); - let times_seen = result.overload_number(&fn_name); - if times_seen > 0 { - write!(&mut fn_name, "_{}", times_seen).unwrap(); - } - - let fn_name = ctx.rust_ident_raw(fn_name); + let fn_name = if compile_time { + None + } else { + let mut fn_name = + format!("__bindgen_test_layout_{name}_instantiation"); + let times_seen = result.overload_number(&fn_name); + if times_seen > 0 { + write!(&mut fn_name, "_{times_seen}").unwrap(); + } + Some(ctx.rust_ident_raw(fn_name)) + }; let prefix = ctx.trait_prefix(); let ident = item.to_rust_ty_or_opaque(ctx, &()); @@ -1245,20 +1301,33 @@ impl CodeGenerator for TemplateInstantiation { let align_of_expr = quote! { ::#prefix::mem::align_of::<#ident>() }; - - let item = quote! { - #[test] - fn #fn_name() { - assert_eq!(#size_of_expr, #size, - concat!("Size of template specialization: ", - stringify!(#ident))); - assert_eq!(#align_of_expr, #align, - concat!("Alignment of template specialization: ", - stringify!(#ident))); - } - }; - - result.push(item); + let size_of_err = + format!("Size of template specialization: {name}"); + let align_of_err = + format!("Align of template specialization: {name}"); + + if compile_time { + // In an ideal world this would be assert_eq!, but that is not + // supported in const fn due to the need for string formatting. + // If #size_of_expr > #size, this will index OOB, and if + // #size_of_expr < #size, the subtraction will overflow, both + // of which print enough information to see what has gone wrong. + result.push(quote! { + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [#size_of_err][#size_of_expr - #size]; + [#align_of_err][#align_of_expr - #align]; + }; + }); + } else { + result.push(quote! { + #[test] + fn #fn_name() { + assert_eq!(#size_of_expr, #size, #size_of_err); + assert_eq!(#align_of_expr, #align, #align_of_err); + } + }); + } } } } @@ -1271,9 +1340,11 @@ trait FieldCodegen<'a> { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1290,9 +1361,11 @@ impl<'a> FieldCodegen<'a> for Field { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1306,9 +1379,11 @@ impl<'a> FieldCodegen<'a> for Field { Field::DataMember(ref data) => { data.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, + parent_item, + last_field, result, struct_layout, fields, @@ -1319,9 +1394,11 @@ impl<'a> FieldCodegen<'a> for Field { Field::Bitfields(ref unit) => { unit.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, + parent_item, + last_field, result, struct_layout, fields, @@ -1336,28 +1413,22 @@ impl<'a> FieldCodegen<'a> for Field { fn wrap_union_field_if_needed( ctx: &BindgenContext, struct_layout: &StructLayoutTracker, - ty: proc_macro2::TokenStream, + ty: syn::Type, result: &mut CodegenResult, -) -> proc_macro2::TokenStream { +) -> syn::Type { if struct_layout.is_rust_union() { if struct_layout.can_copy_union_fields() { ty } else { let prefix = ctx.trait_prefix(); - quote! { - ::#prefix::mem::ManuallyDrop<#ty> - } + syn::parse_quote! { ::#prefix::mem::ManuallyDrop<#ty> } } } else { result.saw_bindgen_union(); if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenUnionField<#ty> - } + syn::parse_quote! { root::__BindgenUnionField<#ty> } } else { - quote! { - __BindgenUnionField<#ty> - } + syn::parse_quote! { __BindgenUnionField<#ty> } } } } @@ -1368,9 +1439,11 @@ impl<'a> FieldCodegen<'a> for FieldData { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + parent_visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1387,24 +1460,28 @@ impl<'a> FieldCodegen<'a> for FieldData { let field_item = self.ty().into_resolver().through_type_refs().resolve(ctx); let field_ty = field_item.expect_type(); - let mut ty = self.ty().to_rust_ty_or_opaque(ctx, &()); - ty.append_implicit_template_params(ctx, field_item); + let ty = self + .ty() + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, field_item); // NB: If supported, we use proper `union` types. let ty = if parent.is_union() { wrap_union_field_if_needed(ctx, struct_layout, ty, result) } else if let Some(item) = field_ty.is_incomplete_array(ctx) { - result.saw_incomplete_array(); + // Only FAM if its the last field + if ctx.options().flexarray_dst && last_field { + struct_layout.saw_flexible_array(); + syn::parse_quote! { FAM } + } else { + result.saw_incomplete_array(); - let inner = item.to_rust_ty_or_opaque(ctx, &()); + let inner = item.to_rust_ty_or_opaque(ctx, &()); - if ctx.options().enable_cxx_namespaces { - quote! { - root::__IncompleteArrayField<#inner> - } - } else { - quote! { - __IncompleteArrayField<#inner> + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__IncompleteArrayField<#inner> } + } else { + syn::parse_quote! { __IncompleteArrayField<#inner> } } } } else { @@ -1423,31 +1500,46 @@ impl<'a> FieldCodegen<'a> for FieldData { .name() .map(|name| ctx.rust_mangle(name).into_owned()) .expect("Each field should have a name in codegen!"); - let field_ident = ctx.rust_ident_raw(field_name.as_str()); + let field_name = field_name.as_str(); + let field_ident = ctx.rust_ident_raw(field_name); if let Some(padding_field) = - struct_layout.saw_field(&field_name, field_ty, self.offset()) + struct_layout.saw_field(field_name, field_ty, self.offset()) { fields.extend(Some(padding_field)); } - let is_private = (!self.is_public() && - ctx.options().respect_cxx_access_specs) || - self.annotations() - .private_fields() - .unwrap_or(fields_should_be_private); - + let visibility = compute_visibility( + ctx, + self.is_public(), + ctx.options().last_callback(|cb| { + cb.field_visibility(FieldInfo { + type_name: &parent_item.canonical_name(ctx), + field_name, + }) + }), + self.annotations(), + parent_visibility_kind, + ); let accessor_kind = self.annotations().accessor_kind().unwrap_or(accessor_kind); - if is_private { - field.append_all(quote! { - #field_ident : #ty , - }); - } else { - field.append_all(quote! { - pub #field_ident : #ty , - }); + match visibility { + FieldVisibilityKind::Private => { + field.append_all(quote! { + #field_ident : #ty , + }); + } + FieldVisibilityKind::PublicCrate => { + field.append_all(quote! { + pub(crate) #field_ident : #ty , + }); + } + FieldVisibilityKind::Public => { + field.append_all(quote! { + pub #field_ident : #ty , + }); + } } fields.extend(Some(field)); @@ -1460,7 +1552,6 @@ impl<'a> FieldCodegen<'a> for FieldData { let getter_name = ctx.rust_ident_raw(format!("get_{}", field_name)); let mutable_getter_name = ctx.rust_ident_raw(format!("get_{}_mut", field_name)); - let field_name = ctx.rust_ident_raw(field_name); methods.extend(Some(match accessor_kind { FieldAccessorKind::None => unreachable!(), @@ -1468,12 +1559,12 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } #[inline] pub fn #mutable_getter_name(&mut self) -> &mut #ty { - &mut self.#field_name + &mut self.#field_ident } } } @@ -1481,12 +1572,12 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub unsafe fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } #[inline] pub unsafe fn #mutable_getter_name(&mut self) -> &mut #ty { - &mut self.#field_name + &mut self.#field_ident } } } @@ -1494,7 +1585,7 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } } } @@ -1557,25 +1648,63 @@ impl Bitfield { } fn access_specifier( - ctx: &BindgenContext, - is_pub: bool, + visibility: FieldVisibilityKind, ) -> proc_macro2::TokenStream { - if is_pub || !ctx.options().respect_cxx_access_specs { - quote! { pub } - } else { - quote! {} + match visibility { + FieldVisibilityKind::Private => quote! {}, + FieldVisibilityKind::PublicCrate => quote! { pub(crate) }, + FieldVisibilityKind::Public => quote! { pub }, } } +/// Compute a fields or structs visibility based on multiple conditions. +/// 1. If the element was declared public, and we respect such CXX accesses specs +/// (context option) => By default Public, but this can be overruled by an `annotation`. +/// +/// 2. If the element was declared private, and we respect such CXX accesses specs +/// (context option) => By default Private, but this can be overruled by an `annotation`. +/// +/// 3. If we do not respect visibility modifiers, the result depends on the `annotation`, +/// if any, or the passed `default_kind`. +/// +fn compute_visibility( + ctx: &BindgenContext, + is_declared_public: bool, + callback_override: Option, + annotations: &Annotations, + default_kind: FieldVisibilityKind, +) -> FieldVisibilityKind { + callback_override + .or_else(|| annotations.visibility_kind()) + .unwrap_or_else(|| { + match (is_declared_public, ctx.options().respect_cxx_access_specs) { + (true, true) => { + // declared as public, cxx specs are respected + FieldVisibilityKind::Public + } + (false, true) => { + // declared as private, cxx specs are respected + FieldVisibilityKind::Private + } + (_, false) => { + // cxx specs are not respected, declaration does not matter. + default_kind + } + } + }) +} + impl<'a> FieldCodegen<'a> for BitfieldUnit { type Extra = (); fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1591,15 +1720,18 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let layout = self.layout(); let unit_field_ty = helpers::bitfield_unit(ctx, layout); - let field_ty = if parent.is_union() { - wrap_union_field_if_needed( - ctx, - struct_layout, - unit_field_ty.clone(), - result, - ) - } else { - unit_field_ty.clone() + let field_ty = { + let unit_field_ty = unit_field_ty.clone(); + if parent.is_union() { + wrap_union_field_if_needed( + ctx, + struct_layout, + unit_field_ty, + result, + ) + } else { + unit_field_ty + } }; { @@ -1611,8 +1743,9 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { 2 => quote! { u16 }, _ => quote! { u8 }, }; + let access_spec = access_specifier(visibility_kind); let align_field = quote! { - pub #align_field_ident: [#align_ty; 0], + #access_spec #align_field_ident: [#align_ty; 0], }; fields.extend(Some(align_field)); } @@ -1631,8 +1764,9 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { // the 32 items limitation. let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; - let mut access_spec = !fields_should_be_private; - for bf in self.bitfields() { + let mut unit_visibility = visibility_kind; + let bfields = self.bitfields(); + for (idx, bf) in bfields.iter().enumerate() { // Codegen not allowed for anonymous bitfields if bf.name().is_none() { continue; @@ -1644,20 +1778,28 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } - access_spec &= bf.is_public(); let mut bitfield_representable_as_int = true; - + let mut bitfield_visibility = visibility_kind; bf.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, + parent_item, + last_field && idx == bfields.len() - 1, result, struct_layout, fields, methods, - (&unit_field_name, &mut bitfield_representable_as_int), + ( + &unit_field_name, + &mut bitfield_representable_as_int, + &mut bitfield_visibility, + ), ); + if bitfield_visibility < unit_visibility { + unit_visibility = bitfield_visibility; + } // Generating a constructor requires the bitfield to be representable as an integer. if !bitfield_representable_as_int { @@ -1677,7 +1819,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); } - let access_spec = access_specifier(ctx, access_spec); + let access_spec = access_specifier(unit_visibility); let field = quote! { #access_spec #unit_field_ident : #field_ty , @@ -1718,19 +1860,25 @@ fn bitfield_setter_name( } impl<'a> FieldCodegen<'a> for Bitfield { - type Extra = (&'a str, &'a mut bool); + type Extra = (&'a str, &'a mut bool, &'a mut FieldVisibilityKind); fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, _accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, + _last_field: bool, _result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, _fields: &mut F, methods: &mut M, - (unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), + (unit_field_name, bitfield_representable_as_int, bitfield_visibility): ( + &'a str, + &mut bool, + &'a mut FieldVisibilityKind, + ), ) where F: Extend, M: Extend, @@ -1763,10 +1911,23 @@ impl<'a> FieldCodegen<'a> for Bitfield { let offset = self.offset_into_unit(); let width = self.width() as u8; - let access_spec = access_specifier( + + let override_visibility = self.name().and_then(|field_name| { + ctx.options().last_callback(|cb| { + cb.field_visibility(FieldInfo { + type_name: &parent_item.canonical_name(ctx), + field_name, + }) + }) + }); + *bitfield_visibility = compute_visibility( ctx, - self.is_public() && !fields_should_be_private, + self.is_public(), + override_visibility, + self.annotations(), + visibility_kind, ); + let access_spec = access_specifier(*bitfield_visibility); if parent.is_union() && !struct_layout.is_rust_union() { methods.extend(Some(quote! { @@ -1860,8 +2021,35 @@ impl CodeGenerator for CompInfo { // the parent too. let is_opaque = item.is_opaque(ctx, &()); let mut fields = vec![]; - let mut struct_layout = - StructLayoutTracker::new(ctx, self, ty, &canonical_name); + let visibility = item + .annotations() + .visibility_kind() + .unwrap_or(ctx.options().default_visibility); + let mut struct_layout = StructLayoutTracker::new( + ctx, + self, + ty, + &canonical_name, + visibility, + packed, + ); + + let mut generic_param_names = vec![]; + + for (idx, ty) in item.used_template_params(ctx).iter().enumerate() { + let param = ctx.resolve_type(*ty); + let name = param.name().unwrap(); + let ident = ctx.rust_ident(name); + generic_param_names.push(ident.clone()); + + let prefix = ctx.trait_prefix(); + let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); + fields.push(quote! { + pub #field_name : ::#prefix::marker::PhantomData< + ::#prefix::cell::UnsafeCell<#ident> + > , + }); + } if !is_opaque { if item.has_vtable_ptr(ctx) { @@ -1886,13 +2074,23 @@ impl CodeGenerator for CompInfo { } let inner_item = ctx.resolve_item(base.ty); - let mut inner = inner_item.to_rust_ty_or_opaque(ctx, &()); - inner.append_implicit_template_params(ctx, inner_item); + let inner = inner_item + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, inner_item); let field_name = ctx.rust_ident(&base.field_name); struct_layout.saw_base(inner_item.expect_type()); - let access_spec = access_specifier(ctx, base.is_public()); + let visibility = match ( + base.is_public(), + ctx.options().respect_cxx_access_specs, + ) { + (true, true) => FieldVisibilityKind::Public, + (false, true) => FieldVisibilityKind::Private, + _ => ctx.options().default_visibility, + }; + + let access_spec = access_specifier(visibility); fields.push(quote! { #access_spec #field_name: #inner, }); @@ -1901,18 +2099,19 @@ impl CodeGenerator for CompInfo { let mut methods = vec![]; if !is_opaque { - let fields_should_be_private = - item.annotations().private_fields().unwrap_or(false); let struct_accessor_kind = item .annotations() .accessor_kind() .unwrap_or(FieldAccessorKind::None); - for field in self.fields() { + let field_decls = self.fields(); + for (idx, field) in field_decls.iter().enumerate() { field.codegen( ctx, - fields_should_be_private, + visibility, struct_accessor_kind, self, + item, + idx == field_decls.len() - 1, result, &mut struct_layout, &mut fields, @@ -2037,41 +2236,71 @@ impl CodeGenerator for CompInfo { }); } - let mut generic_param_names = vec![]; - - for (idx, ty) in item.used_template_params(ctx).iter().enumerate() { - let param = ctx.resolve_type(*ty); - let name = param.name().unwrap(); - let ident = ctx.rust_ident(name); - generic_param_names.push(ident.clone()); - - let prefix = ctx.trait_prefix(); - let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); - fields.push(quote! { - pub #field_name : ::#prefix::marker::PhantomData< - ::#prefix::cell::UnsafeCell<#ident> - > , - }); - } - - let generics = if !generic_param_names.is_empty() { - let generic_param_names = generic_param_names.clone(); - quote! { - < #( #generic_param_names ),* > + let (flex_array_generic, flex_inner_ty) = if ctx.options().flexarray_dst + { + match self.flex_array_member(ctx) { + Some(ty) => { + let inner = ty.to_rust_ty_or_opaque(ctx, &()); + ( + Some(quote! { FAM: ?Sized = [ #inner; 0 ] }), + Some(quote! { #inner }), + ) + } + None => (None, None), } } else { - quote! {} + (None, None) }; + // Generics, including the flexible array member. + // + // generics - generic parameters for the struct declaration + // impl_generics_labels - generic parameters for `impl<...>` + // impl_generics_params - generic parameters for `impl structname<...>` + // + // `impl` blocks are for non-FAM related impls like Default, etc + let (generics, impl_generics_labels, impl_generics_params) = + if !generic_param_names.is_empty() || flex_array_generic.is_some() { + let (flex_sized, flex_fam) = match flex_inner_ty.as_ref() { + None => (None, None), + Some(ty) => ( + Some(quote! { [ #ty; 0 ] }), + Some(quote! { FAM: ?Sized = [ #ty; 0 ] }), + ), + }; + + ( + quote! { + < #( #generic_param_names , )* #flex_fam > + }, + quote! { + < #( #generic_param_names , )* > + }, + quote! { + < #( #generic_param_names , )* #flex_sized > + }, + ) + } else { + (quote! {}, quote! {}, quote! {}) + }; + let mut attributes = vec![]; let mut needs_clone_impl = false; let mut needs_default_impl = false; let mut needs_debug_impl = false; let mut needs_partialeq_impl = false; + let needs_flexarray_impl = flex_array_generic.is_some(); if let Some(comment) = item.comment(ctx) { attributes.push(attributes::doc(comment)); } - if packed && !is_opaque { + + // if a type has both a "packed" attribute and an "align(N)" attribute, then check if the + // "packed" attr is redundant, and do not include it if so. + if packed && + !is_opaque && + !(explicit_align.is_some() && + self.already_packed(ctx).unwrap_or(false)) + { let n = layout.map_or(1, |l| l.align); assert!(ctx.options().rust_features().repr_packed_n || n == 1); let packed_repr = if n == 1 { @@ -2201,9 +2430,14 @@ impl CodeGenerator for CompInfo { if ctx.options().layout_tests && !self.is_forward_declaration() { if let Some(layout) = layout { - let fn_name = - format!("bindgen_test_layout_{}", canonical_ident); - let fn_name = ctx.rust_ident_raw(fn_name); + let compile_time = ctx.options().rust_features().offset_of; + let fn_name = if compile_time { + None + } else { + let fn_name = + format!("bindgen_test_layout_{canonical_ident}"); + Some(ctx.rust_ident_raw(fn_name)) + }; let prefix = ctx.trait_prefix(); let size_of_expr = quote! { ::#prefix::mem::size_of::<#canonical_ident>() @@ -2213,18 +2447,22 @@ impl CodeGenerator for CompInfo { }; let size = layout.size; let align = layout.align; + let size_of_err = format!("Size of {canonical_ident}"); + let align_of_err = + format!("Alignment of {canonical_ident}"); let check_struct_align = if align > ctx.target_pointer_size() && !ctx.options().rust_features().repr_align { None + } else if compile_time { + Some(quote! { + [#align_of_err][#align_of_expr - #align]; + }) } else { Some(quote! { - assert_eq!(#align_of_expr, - #align, - concat!("Alignment of ", stringify!(#canonical_ident))); - + assert_eq!(#align_of_expr, #align, #align_of_err); }) }; @@ -2245,21 +2483,34 @@ impl CodeGenerator for CompInfo { field.offset().map(|offset| { let field_offset = offset / 8; let field_name = ctx.rust_ident(name); - quote! { - assert_eq!( - unsafe { - ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize - }, - #field_offset, - concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) - ); + let offset_of_err = format!("Offset of field: {canonical_ident}::{field_name}"); + if compile_time { + quote! { + [#offset_of_err][ + ::#prefix::mem::offset_of!(#canonical_ident, #field_name) - #field_offset + ]; + } + } else { + quote! { + assert_eq!( + unsafe { + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize + }, + #field_offset, + #offset_of_err + ); + } } }) }) .collect() }; - let uninit_decl = if !check_field_offset.is_empty() { + let uninit_decl = if check_field_offset.is_empty() || + compile_time + { + None + } else { // FIXME: When MSRV >= 1.59.0, we can use // > const PTR: *const #canonical_ident = ::#prefix::mem::MaybeUninit::uninit().as_ptr(); Some(quote! { @@ -2269,22 +2520,28 @@ impl CodeGenerator for CompInfo { const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); }) - } else { - None }; - let item = quote! { - #[test] - fn #fn_name() { - #uninit_decl - assert_eq!(#size_of_expr, - #size, - concat!("Size of: ", stringify!(#canonical_ident))); - #check_struct_align - #( #check_field_offset )* - } - }; - result.push(item); + if compile_time { + result.push(quote! { + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + [#size_of_err][#size_of_expr - #size]; + #check_struct_align + #( #check_field_offset )* + }; + }); + } else { + result.push(quote! { + #[test] + fn #fn_name() { + #uninit_decl + assert_eq!(#size_of_expr, #size, #size_of_err); + #check_struct_align + #( #check_field_offset )* + } + }); + } } } @@ -2337,17 +2594,27 @@ impl CodeGenerator for CompInfo { // NB: We can't use to_rust_ty here since for opaque types this tries to // use the specialization knowledge to generate a blob field. let ty_for_impl = quote! { - #canonical_ident #generics + #canonical_ident #impl_generics_params }; if needs_clone_impl { result.push(quote! { - impl #generics Clone for #ty_for_impl { + impl #impl_generics_labels Clone for #ty_for_impl { fn clone(&self) -> Self { *self } } }); } + if needs_flexarray_impl { + result.push(self.generate_flexarray( + ctx, + &canonical_ident, + flex_inner_ty, + &generic_param_names, + &impl_generics_labels, + )); + } + if needs_default_impl { let prefix = ctx.trait_prefix(); let body = if ctx.options().rust_features().maybe_uninit { @@ -2369,10 +2636,10 @@ impl CodeGenerator for CompInfo { }; // Note we use `ptr::write_bytes()` instead of `mem::zeroed()` because the latter does // not necessarily ensure padding bytes are zeroed. Some C libraries are sensitive to - // non-zero padding bytes, especially when forwards/backwards compatability is + // non-zero padding bytes, especially when forwards/backwards compatibility is // involved. result.push(quote! { - impl #generics Default for #ty_for_impl { + impl #impl_generics_labels Default for #ty_for_impl { fn default() -> Self { #body } @@ -2391,7 +2658,7 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); result.push(quote! { - impl #generics ::#prefix::fmt::Debug for #ty_for_impl { + impl #impl_generics_labels ::#prefix::fmt::Debug for #ty_for_impl { #impl_ } }); @@ -2415,7 +2682,7 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); result.push(quote! { - impl #generics ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds { + impl #impl_generics_labels ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds { #impl_ } }); @@ -2424,7 +2691,7 @@ impl CodeGenerator for CompInfo { if !methods.is_empty() { result.push(quote! { - impl #generics #ty_for_impl { + impl #impl_generics_labels #ty_for_impl { #( #methods )* } }); @@ -2432,6 +2699,142 @@ impl CodeGenerator for CompInfo { } } +impl CompInfo { + fn generate_flexarray( + &self, + ctx: &BindgenContext, + canonical_ident: &Ident, + flex_inner_ty: Option, + generic_param_names: &[Ident], + impl_generics_labels: &proc_macro2::TokenStream, + ) -> proc_macro2::TokenStream { + let prefix = ctx.trait_prefix(); + + let flex_array = flex_inner_ty.as_ref().map(|ty| quote! { [ #ty ] }); + + let dst_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* #flex_array > + + }; + let sized_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] > + }; + + let layout = if ctx.options().rust_features().layout_for_ptr { + quote! { + pub fn layout(len: usize) -> ::#prefix::alloc::Layout { + // SAFETY: Null pointers are OK if we don't deref them + unsafe { + let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null::<()>(), len); + ::#prefix::alloc::Layout::for_value_raw(p) + } + } + } + } else { + quote!() + }; + + let (from_ptr_dst, from_ptr_sized) = if ctx + .options() + .rust_features() + .ptr_metadata + { + let flex_ref_inner = ctx.wrap_unsafe_ops(quote! { + Self::flex_ptr(self, len) + }); + let flex_ref_mut_inner = ctx.wrap_unsafe_ops(quote! { + Self::flex_ptr_mut(self, len).assume_init() + }); + let flex_ptr_inner = ctx.wrap_unsafe_ops(quote! { + &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) + }); + let flex_ptr_mut_inner = ctx.wrap_unsafe_ops(quote! { + // Initialize reference without ever exposing it, as its possibly uninitialized + let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); + (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) + .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); + + uninit + }); + + ( + quote! { + #[inline] + pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const #sized_ty_for_impl), len) + } + } + + #[inline] + pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut #sized_ty_for_impl), len) + } + } + }, + quote! { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + #flex_ref_inner + } + + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + #flex_ref_mut_inner + } + + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] + pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { + #flex_ptr_inner + } + + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> { + #flex_ptr_mut_inner + } + }, + ) + } else { + (quote!(), quote!()) + }; + + quote! { + impl #impl_generics_labels #dst_ty_for_impl { + #layout + #from_ptr_dst + } + + impl #impl_generics_labels #sized_ty_for_impl { + #from_ptr_sized + } + } + } +} + impl Method { fn codegen_method( &self, @@ -2481,19 +2884,7 @@ impl Method { _ => panic!("How in the world?"), }; - let supported_abi = match signature.abi(ctx, Some(&*name)) { - ClangAbi::Known(Abi::ThisCall) => { - ctx.options().rust_features().thiscall_abi - } - ClangAbi::Known(Abi::Vectorcall) => { - ctx.options().rust_features().vectorcall_abi - } - ClangAbi::Known(Abi::CUnwind) => { - ctx.options().rust_features().c_unwind_abi - } - _ => true, - }; - + let supported_abi = signature.abi(ctx, Some(&*name)).is_ok(); if !supported_abi { return; } @@ -2621,7 +3012,7 @@ impl Method { } /// A helper type that represents different enum variations. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum EnumVariation { /// The code for this enum will use a Rust enum. Note that creating this in unsafe code /// (including FFI) with an invalid value will invoke undefined behaviour, whether or not @@ -2638,6 +3029,7 @@ pub enum EnumVariation { is_global: bool, }, /// The code for this enum will use consts + #[default] Consts, /// The code for this enum will use a module containing consts ModuleConsts, @@ -2655,9 +3047,32 @@ impl EnumVariation { } } -impl Default for EnumVariation { - fn default() -> EnumVariation { - EnumVariation::Consts +impl fmt::Display for EnumVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::Rust { + non_exhaustive: false, + } => "rust", + Self::Rust { + non_exhaustive: true, + } => "rust_non_exhaustive", + Self::NewType { + is_bitfield: true, .. + } => "bitfield", + Self::NewType { + is_bitfield: false, + is_global, + } => { + if *is_global { + "newtype_global" + } else { + "newtype" + } + } + Self::Consts => "consts", + Self::ModuleConsts => "moduleconsts", + }; + s.fmt(f) } } @@ -2733,7 +3148,7 @@ impl<'a> EnumBuilder<'a> { fn new( name: &'a str, mut attrs: Vec, - repr: proc_macro2::TokenStream, + repr: syn::Type, enum_variation: EnumVariation, has_typedef: bool, ) -> Self { @@ -2802,7 +3217,7 @@ impl<'a> EnumBuilder<'a> { ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, - rust_ty: proc_macro2::TokenStream, + rust_ty: syn::Type, result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { @@ -2917,7 +3332,7 @@ impl<'a> EnumBuilder<'a> { fn build( self, ctx: &BindgenContext, - rust_ty: proc_macro2::TokenStream, + rust_ty: syn::Type, result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { match self { @@ -3168,7 +3583,7 @@ impl CodeGenerator for Enum { // value. variant_name: &Ident, referenced_name: &Ident, - enum_rust_ty: proc_macro2::TokenStream, + enum_rust_ty: syn::Type, result: &mut CodegenResult<'_>, ) { let constant_name = if enum_.name().is_some() { @@ -3339,27 +3754,22 @@ impl CodeGenerator for Enum { } /// Enum for the default type of macro constants. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum MacroTypeVariation { /// Use i32 or i64 Signed, /// Use u32 or u64 + #[default] Unsigned, } -impl MacroTypeVariation { - /// Convert a `MacroTypeVariation` to its str representation. - pub fn as_str(&self) -> &str { - match self { - MacroTypeVariation::Signed => "signed", - MacroTypeVariation::Unsigned => "unsigned", - } - } -} - -impl Default for MacroTypeVariation { - fn default() -> MacroTypeVariation { - MacroTypeVariation::Unsigned +impl fmt::Display for MacroTypeVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::Signed => "signed", + Self::Unsigned => "unsigned", + }; + s.fmt(f) } } @@ -3383,9 +3793,10 @@ impl std::str::FromStr for MacroTypeVariation { } /// Enum for how aliases should be translated. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum AliasVariation { /// Convert to regular Rust alias + #[default] TypeAlias, /// Create a new type by wrapping the old type in a struct and using #[repr(transparent)] NewType, @@ -3393,20 +3804,15 @@ pub enum AliasVariation { NewTypeDeref, } -impl AliasVariation { - /// Convert an `AliasVariation` to its str representation. - pub fn as_str(&self) -> &str { - match self { - AliasVariation::TypeAlias => "type_alias", - AliasVariation::NewType => "new_type", - AliasVariation::NewTypeDeref => "new_type_deref", - } - } -} +impl fmt::Display for AliasVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::TypeAlias => "type_alias", + Self::NewType => "new_type", + Self::NewTypeDeref => "new_type_deref", + }; -impl Default for AliasVariation { - fn default() -> AliasVariation { - AliasVariation::TypeAlias + s.fmt(f) } } @@ -3430,10 +3836,10 @@ impl std::str::FromStr for AliasVariation { } } -/// Enum for how non-Copy unions should be translated. +/// Enum for how non-`Copy` `union`s should be translated. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum NonCopyUnionStyle { - /// Wrap members in a type generated by bindgen. + /// Wrap members in a type generated by `bindgen`. BindgenWrapper, /// Wrap members in [`::core::mem::ManuallyDrop`]. /// @@ -3442,13 +3848,14 @@ pub enum NonCopyUnionStyle { ManuallyDrop, } -impl NonCopyUnionStyle { - /// Convert an `NonCopyUnionStyle` to its str representation. - pub fn as_str(&self) -> &'static str { - match self { +impl fmt::Display for NonCopyUnionStyle { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { Self::BindgenWrapper => "bindgen_wrapper", Self::ManuallyDrop => "manually_drop", - } + }; + + s.fmt(f) } } @@ -3481,7 +3888,7 @@ impl std::str::FromStr for NonCopyUnionStyle { /// Implementors of this trait should provide the `try_get_layout` method to /// fallibly get this thing's layout, which the provided `try_to_opaque` trait /// method will use to convert the `Layout` into an opaque blob Rust type. -trait TryToOpaque { +pub(crate) trait TryToOpaque { type Extra; /// Get the layout for this thing, if one is available. @@ -3496,7 +3903,7 @@ trait TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result { + ) -> error::Result { self.try_get_layout(ctx, extra) .map(|layout| helpers::blob(ctx, layout)) } @@ -3512,7 +3919,7 @@ trait TryToOpaque { /// /// Don't implement this directly. Instead implement `TryToOpaque`, and then /// leverage the blanket impl for this trait. -trait ToOpaque: TryToOpaque { +pub(crate) trait ToOpaque: TryToOpaque { fn get_layout(&self, ctx: &BindgenContext, extra: &Self::Extra) -> Layout { self.try_get_layout(ctx, extra) .unwrap_or_else(|_| Layout::for_size(ctx, 1)) @@ -3522,7 +3929,7 @@ trait ToOpaque: TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { let layout = self.get_layout(ctx, extra); helpers::blob(ctx, layout) } @@ -3537,14 +3944,14 @@ impl ToOpaque for T where T: TryToOpaque {} /// const-value generic parameters) then the impl should return an `Err`. It /// should *not* attempt to return an opaque blob with the correct size and /// alignment. That is the responsibility of the `TryToOpaque` trait. -trait TryToRustTy { +pub(crate) trait TryToRustTy { type Extra; fn try_to_rust_ty( &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result; + ) -> error::Result; } /// Fallible conversion to a Rust type or an opaque blob with the correct size @@ -3552,14 +3959,14 @@ trait TryToRustTy { /// /// Don't implement this directly. Instead implement `TryToRustTy` and /// `TryToOpaque`, and then leverage the blanket impl for this trait below. -trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque { +pub(crate) trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque { type Extra; fn try_to_rust_ty_or_opaque( &self, ctx: &BindgenContext, extra: &::Extra, - ) -> error::Result; + ) -> error::Result; } impl TryToRustTyOrOpaque for T @@ -3572,7 +3979,7 @@ where &self, ctx: &BindgenContext, extra: &E, - ) -> error::Result { + ) -> error::Result { self.try_to_rust_ty(ctx, extra).or_else(|_| { if let Ok(layout) = self.try_get_layout(ctx, extra) { Ok(helpers::blob(ctx, layout)) @@ -3600,14 +4007,14 @@ where /// `ToRustTyOrOpaque`. The further out we push error recovery, the more likely /// we are to get a usable `Layout` even if we can't generate an equivalent Rust /// type for a C++ construct. -trait ToRustTyOrOpaque: TryToRustTy + ToOpaque { +pub(crate) trait ToRustTyOrOpaque: TryToRustTy + ToOpaque { type Extra; fn to_rust_ty_or_opaque( &self, ctx: &BindgenContext, extra: &::Extra, - ) -> proc_macro2::TokenStream; + ) -> syn::Type; } impl ToRustTyOrOpaque for T @@ -3620,7 +4027,7 @@ where &self, ctx: &BindgenContext, extra: &E, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { self.try_to_rust_ty(ctx, extra) .unwrap_or_else(|_| self.to_opaque(ctx, extra)) } @@ -3651,7 +4058,7 @@ where &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { ctx.resolve_item((*self).into()).try_to_rust_ty(ctx, &()) } } @@ -3675,7 +4082,7 @@ impl TryToRustTy for Item { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { self.kind().expect_type().try_to_rust_ty(ctx, self) } } @@ -3699,7 +4106,7 @@ impl TryToRustTy for Type { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { use self::helpers::ast_ty::*; match *self.kind() { @@ -3708,57 +4115,7 @@ impl TryToRustTy for Type { // c_void is enough? TypeKind::NullPtr => Ok(c_void(ctx).to_ptr(true)), TypeKind::Int(ik) => { - match ik { - IntKind::Bool => Ok(quote! { bool }), - IntKind::Char { .. } => Ok(raw_type(ctx, "c_char")), - IntKind::SChar => Ok(raw_type(ctx, "c_schar")), - IntKind::UChar => Ok(raw_type(ctx, "c_uchar")), - IntKind::Short => Ok(raw_type(ctx, "c_short")), - IntKind::UShort => Ok(raw_type(ctx, "c_ushort")), - IntKind::Int => Ok(raw_type(ctx, "c_int")), - IntKind::UInt => Ok(raw_type(ctx, "c_uint")), - IntKind::Long => Ok(raw_type(ctx, "c_long")), - IntKind::ULong => Ok(raw_type(ctx, "c_ulong")), - IntKind::LongLong => Ok(raw_type(ctx, "c_longlong")), - IntKind::ULongLong => Ok(raw_type(ctx, "c_ulonglong")), - IntKind::WChar => { - let layout = self - .layout(ctx) - .expect("Couldn't compute wchar_t's layout?"); - let ty = Layout::known_type_for_size(ctx, layout.size) - .expect("Non-representable wchar_t?"); - let ident = ctx.rust_ident_raw(ty); - Ok(quote! { #ident }) - } - - IntKind::I8 => Ok(quote! { i8 }), - IntKind::U8 => Ok(quote! { u8 }), - IntKind::I16 => Ok(quote! { i16 }), - IntKind::U16 => Ok(quote! { u16 }), - IntKind::I32 => Ok(quote! { i32 }), - IntKind::U32 => Ok(quote! { u32 }), - IntKind::I64 => Ok(quote! { i64 }), - IntKind::U64 => Ok(quote! { u64 }), - IntKind::Custom { name, .. } => { - Ok(proc_macro2::TokenStream::from_str(name).unwrap()) - } - IntKind::U128 => { - Ok(if ctx.options().rust_features.i128_and_u128 { - quote! { u128 } - } else { - // Best effort thing, but wrong alignment - // unfortunately. - quote! { [u64; 2] } - }) - } - IntKind::I128 => { - Ok(if ctx.options().rust_features.i128_and_u128 { - quote! { i128 } - } else { - quote! { [u64; 2] } - }) - } - } + Ok(int_kind_rust_type(ctx, ik, self.layout(ctx))) } TypeKind::Float(fk) => { Ok(float_kind_rust_type(ctx, fk, self.layout(ctx))) @@ -3769,38 +4126,30 @@ impl TryToRustTy for Type { ctx.generated_bindgen_complex(); Ok(if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenComplex<#float_path> - } + syn::parse_quote! { root::__BindgenComplex<#float_path> } } else { - quote! { - __BindgenComplex<#float_path> - } + syn::parse_quote! { __BindgenComplex<#float_path> } }) } - TypeKind::Function(ref fs) => { + TypeKind::Function(ref signature) => { // We can't rely on the sizeof(Option>) == // sizeof(NonZero<_>) optimization with opaque blobs (because // they aren't NonZero), so don't *ever* use an or_opaque // variant here. - let ty = fs.try_to_rust_ty(ctx, &())?; + let ty = signature.try_to_rust_ty(ctx, item)?; let prefix = ctx.trait_prefix(); - Ok(quote! { - ::#prefix::option::Option<#ty> - }) + Ok(syn::parse_quote! { ::#prefix::option::Option<#ty> }) } TypeKind::Array(item, len) | TypeKind::Vector(item, len) => { let ty = item.try_to_rust_ty(ctx, &())?; - Ok(quote! { - [ #ty ; #len ] - }) + Ok(syn::parse_quote! { [ #ty ; #len ] }) } TypeKind::Enum(..) => { let path = item.namespace_aware_canonical_path(ctx); let path = proc_macro2::TokenStream::from_str(&path.join("::")) .unwrap(); - Ok(quote!(#path)) + Ok(syn::parse_quote!(#path)) } TypeKind::TemplateInstantiation(ref inst) => { inst.try_to_rust_ty(ctx, item) @@ -3841,6 +4190,16 @@ impl TryToRustTy for Type { } TypeKind::Opaque => self.try_to_opaque(ctx, item), TypeKind::Pointer(inner) | TypeKind::Reference(inner) => { + // Check that this type has the same size as the target's pointer type. + let size = self.get_layout(ctx, item).size; + if size != ctx.target_pointer_size() { + return Err(Error::InvalidPointerSize { + ty_name: self.name().unwrap_or("unknown").into(), + ty_size: size, + ptr_size: ctx.target_pointer_size(), + }); + } + let is_const = ctx.resolve_type(inner).is_const(); let inner = @@ -3853,8 +4212,9 @@ impl TryToRustTy for Type { // Regardless if we can properly represent the inner type, we // should always generate a proper pointer here, so use // infallible conversion of the inner type. - let mut ty = inner.to_rust_ty_or_opaque(ctx, &()); - ty.append_implicit_template_params(ctx, inner); + let ty = inner + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, inner); // Avoid the first function pointer level, since it's already // represented in Rust. @@ -3868,21 +4228,13 @@ impl TryToRustTy for Type { TypeKind::TypeParam => { let name = item.canonical_name(ctx); let ident = ctx.rust_ident(name); - Ok(quote! { - #ident - }) + Ok(syn::parse_quote! { #ident }) } - TypeKind::ObjCSel => Ok(quote! { - objc::runtime::Sel - }), - TypeKind::ObjCId => Ok(quote! { - id - }), + TypeKind::ObjCSel => Ok(syn::parse_quote! { objc::runtime::Sel }), + TypeKind::ObjCId => Ok(syn::parse_quote! { id }), TypeKind::ObjCInterface(ref interface) => { let name = ctx.rust_ident(interface.name()); - Ok(quote! { - #name - }) + Ok(syn::parse_quote! { #name }) } ref u @ TypeKind::UnresolvedTypeRef(..) => { unreachable!("Should have been resolved after parsing {:?}!", u) @@ -3912,7 +4264,7 @@ impl TryToRustTy for TemplateInstantiation { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { if self.is_opaque(ctx, item) { return Err(error::Error::InstantiationOfOpaqueType); } @@ -3956,57 +4308,50 @@ impl TryToRustTy for TemplateInstantiation { .filter(|&(_, param)| ctx.uses_template_parameter(def.id(), *param)) .map(|(arg, _)| { let arg = arg.into_resolver().through_type_refs().resolve(ctx); - let mut ty = arg.try_to_rust_ty(ctx, &())?; - ty.append_implicit_template_params(ctx, arg); + let ty = arg + .try_to_rust_ty(ctx, &())? + .with_implicit_template_params(ctx, arg); Ok(ty) }) .collect::>>()?; - if template_args.is_empty() { - return Ok(ty); - } - - Ok(quote! { - #ty < #( #template_args ),* > + Ok(if template_args.is_empty() { + syn::parse_quote! { #ty } + } else { + syn::parse_quote! { #ty<#(#template_args),*> } }) } } impl TryToRustTy for FunctionSig { - type Extra = (); + type Extra = Item; fn try_to_rust_ty( &self, ctx: &BindgenContext, - _: &(), - ) -> error::Result { + item: &Item, + ) -> error::Result { // TODO: we might want to consider ignoring the reference return value. let ret = utils::fnsig_return_ty(ctx, self); let arguments = utils::fnsig_arguments(ctx, self); - let abi = self.abi(ctx, None); - match abi { - ClangAbi::Known(Abi::ThisCall) - if !ctx.options().rust_features().thiscall_abi => - { - warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) - } - ClangAbi::Known(Abi::Vectorcall) - if !ctx.options().rust_features().vectorcall_abi => - { - warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) - } - ClangAbi::Known(Abi::CUnwind) - if !ctx.options().rust_features().c_unwind_abi => - { - warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) + match self.abi(ctx, None) { + Ok(abi) => Ok( + syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }, + ), + Err(err) => { + // if matches!(err, error::Error::UnsupportedAbi(_)) { + // unsupported_abi_diagnostic( + // self.name(), + // self.is_variadic(), + // item.location(), + // ctx, + // &err, + // ); + // } + + Err(err) } - _ => Ok(quote! { - unsafe extern #abi fn ( #( #arguments ),* ) #ret - }), } } } @@ -4029,12 +4374,24 @@ impl CodeGenerator for Function { let is_internal = matches!(self.linkage(), Linkage::Internal); + let signature_item = ctx.resolve_item(self.signature()); + let signature = signature_item.kind().expect_type().canonical_type(ctx); + let signature = match *signature.kind() { + TypeKind::Function(ref sig) => sig, + _ => panic!("Signature kind is not a Function: {:?}", signature), + }; + if is_internal { - if ctx.options().wrap_static_fns { - result.items_to_serialize.push(item.id()); - } else { - // We can't do anything with Internal functions if we are not wrapping them so just - // avoid generating anything for them. + if !ctx.options().wrap_static_fns { + // We cannot do anything with internal functions if we are not wrapping them so + // just avoid generating anything for them. + return None; + } + + if signature.is_variadic() { + // We cannot generate wrappers for variadic static functions so we avoid + // generating any code for them. + // variadic_fn_diagnostic(self.name(), item.location(), ctx); return None; } } @@ -4076,16 +4433,6 @@ impl CodeGenerator for Function { result.saw_function(seen_symbol_name); } - let signature_item = ctx.resolve_item(self.signature()); - let signature = signature_item.kind().expect_type().canonical_type(ctx); - let signature = match *signature.kind() { - TypeKind::Function(ref sig) => sig, - _ => panic!("Signature kind is not a Function: {:?}", signature), - }; - - let args = utils::fnsig_arguments(ctx, signature); - let ret = utils::fnsig_return_ty(ctx, signature); - let mut attributes = vec![]; if ctx.options().rust_features().must_use_function { @@ -4108,35 +4455,26 @@ impl CodeGenerator for Function { } let abi = match signature.abi(ctx, Some(name)) { - ClangAbi::Known(Abi::ThisCall) - if !ctx.options().rust_features().thiscall_abi => - { - warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); - return None; - } - ClangAbi::Known(Abi::Vectorcall) - if !ctx.options().rust_features().vectorcall_abi => - { - warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); - return None; - } - ClangAbi::Known(Abi::CUnwind) - if !ctx.options().rust_features().c_unwind_abi => - { - warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); - return None; - } - ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { - warn!("Skipping variadic function with Win64 ABI that isn't supported"); + Err(err) => { + if matches!(err, error::Error::UnsupportedAbi(_)) { + // unsupported_abi_diagnostic( + // name, + // signature.is_variadic(), + // item.location(), + // ctx, + // &err, + // ); + } + return None; } - ClangAbi::Unknown(unknown_abi) => { + Ok(ClangAbi::Unknown(unknown_abi)) => { panic!( "Invalid or unknown abi {:?} for function {:?} ({:?})", unknown_abi, canonical_name, self ); } - abi => abi, + Ok(abi) => abi, }; // Handle overloaded functions by giving each overload its own unique @@ -4147,16 +4485,21 @@ impl CodeGenerator for Function { } let mut has_link_name_attr = false; - let link_name = mangled_name.unwrap_or(name); - if !is_dynamic_function && - !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - Some(abi), - ) - { - attributes.push(attributes::link_name(link_name)); + if let Some(link_name) = self.link_name() { + attributes.push(attributes::link_name::(link_name)); has_link_name_attr = true; + } else { + let link_name = mangled_name.unwrap_or(name); + if !is_dynamic_function && + !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + Some(abi), + ) + { + attributes.push(attributes::link_name::(link_name)); + has_link_name_attr = true; + } } // Unfortunately this can't piggyback on the `attributes` list because @@ -4167,12 +4510,49 @@ impl CodeGenerator for Function { quote! { #[link(wasm_import_module = #name)] } }); - if is_internal && ctx.options().wrap_static_fns && !has_link_name_attr { + let should_wrap = + is_internal && ctx.options().wrap_static_fns && !has_link_name_attr; + + if should_wrap { let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); - attributes.push(attributes::link_name(&name)); + attributes.push(attributes::link_name::(&name)); } - let ident = ctx.rust_ident(canonical_name); + let wrap_as_variadic = if should_wrap && !signature.is_variadic() { + utils::wrap_as_variadic_fn(ctx, signature, name) + } else { + None + }; + + let (ident, args) = if let Some(WrapAsVariadic { + idx_of_va_list_arg, + new_name, + }) = &wrap_as_variadic + { + ( + new_name, + utils::fnsig_arguments_iter( + ctx, + // Prune argument at index (idx_of_va_list_arg) + signature.argument_types().iter().enumerate().filter_map( + |(idx, t)| { + if idx == *idx_of_va_list_arg { + None + } else { + Some(t) + } + }, + ), + // and replace it by a `...` (variadic symbol and the end of the signature) + true, + ), + ) + } else { + (&canonical_name, utils::fnsig_arguments(ctx, signature)) + }; + let ret = utils::fnsig_return_ty(ctx, signature); + + let ident = ctx.rust_ident(ident); let tokens = quote! { #wasm_link_attribute extern #abi { @@ -4181,12 +4561,19 @@ impl CodeGenerator for Function { } }; + // Add the item to the serialization list if necessary + if should_wrap { + result + .items_to_serialize + .push((item.id(), wrap_as_variadic)); + } + // If we're doing dynamic binding generation, add to the dynamic items. if is_dynamic_function { let args_identifiers = utils::fnsig_argument_identifiers(ctx, signature); let ret_ty = utils::fnsig_return_ty(ctx, signature); - result.dynamic_items().push( + result.dynamic_items().push_func( ident, abi, signature.is_variadic(), @@ -4205,6 +4592,103 @@ impl CodeGenerator for Function { } } +// #[cfg_attr(not(feature = "experimental"), allow(unused_variables))] +// fn unsupported_abi_diagnostic( +// fn_name: &str, +// variadic: bool, +// location: Option<&crate::clang::SourceLocation>, +// ctx: &BindgenContext, +// error: &error::Error, +// ) { +// warn!( +// "Skipping {}function `{}` because the {}", +// if variadic { "variadic " } else { "" }, +// fn_name, +// error +// ); + +// #[cfg(feature = "experimental")] +// if ctx.options().emit_diagnostics { +// use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + +// let mut diag = Diagnostic::default(); +// diag.with_title( +// format!( +// "Skipping {}function `{}` because the {}", +// if variadic { "variadic " } else { "" }, +// fn_name, +// error +// ), +// Level::Warn, +// ) +// .add_annotation( +// "No code will be generated for this function.", +// Level::Warn, +// ) +// .add_annotation( +// format!( +// "The configured Rust version is {}.", +// ctx.options().rust_target +// ), +// Level::Note, +// ); + +// if let Some(loc) = location { +// let (file, line, col, _) = loc.location(); + +// if let Some(filename) = file.name() { +// if let Ok(Some(source)) = get_line(&filename, line) { +// let mut slice = Slice::default(); +// slice +// .with_source(source) +// .with_location(filename, line, col); +// diag.add_slice(slice); +// } +// } +// } + +// diag.display() +// } +// } + +// fn variadic_fn_diagnostic( +// fn_name: &str, +// _location: Option<&crate::clang::SourceLocation>, +// _ctx: &BindgenContext, +// ) { +// warn!( +// "Cannot generate wrapper for the static variadic function `{}`.", +// fn_name, +// ); + +// #[cfg(feature = "experimental")] +// if _ctx.options().emit_diagnostics { +// use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + +// let mut diag = Diagnostic::default(); + +// diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn) +// .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) +// .add_annotation("No code will be generated for this function.", Level::Note); + +// if let Some(loc) = _location { +// let (file, line, col, _) = loc.location(); + +// if let Some(filename) = file.name() { +// if let Ok(Some(source)) = get_line(&filename, line) { +// let mut slice = Slice::default(); +// slice +// .with_source(source) +// .with_location(filename, line, col); +// diag.add_slice(slice); +// } +// } +// } + +// diag.display() +// } +// } + fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, @@ -4226,13 +4710,12 @@ fn objc_method_codegen( let fn_ret = utils::fnsig_return_ty(ctx, signature); let sig = if method.is_class_method() { - let fn_args = fn_args.clone(); quote! { ( #( #fn_args ),* ) #fn_ret } } else { - let fn_args = fn_args.clone(); - let args = iter::once(quote! { &self }).chain(fn_args.into_iter()); + let self_arr = [quote! { &self }]; + let args = self_arr.iter().chain(fn_args.iter()); quote! { ( #( #args ),* ) #fn_ret } @@ -4476,8 +4959,7 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> Result<(proc_macro2::TokenStream, BindgenOptions, Vec), CodegenError> -{ +) -> Result<(proc_macro2::TokenStream, BindgenOptions), CodegenError> { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); @@ -4536,16 +5018,18 @@ pub(crate) fn codegen( }) } -pub mod utils { +pub(crate) mod utils { + use super::helpers::BITFIELD_UNIT; use super::serialize::CSerialize; use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; + use crate::ir::context::TypeId; use crate::ir::function::{Abi, ClangAbi, FunctionSig}; use crate::ir::item::{Item, ItemCanonicalPath}; use crate::ir::ty::TypeKind; use crate::{args_are_cpp, file_is_cpp}; - use proc_macro2; use std::borrow::Cow; + use std::io::Write; use std::mem; use std::path::PathBuf; use std::str::FromStr; @@ -4570,7 +5054,7 @@ pub mod utils { let dir = path.parent().unwrap(); if !dir.exists() { - std::fs::create_dir_all(&dir)?; + std::fs::create_dir_all(dir)?; } let is_cpp = args_are_cpp(&context.options().clang_args) || @@ -4584,9 +5068,27 @@ pub mod utils { let mut code = Vec::new(); - for &id in &result.items_to_serialize { - let item = context.resolve_item(id); - item.serialize(context, (), &mut vec![], &mut code)?; + if !context.options().input_headers.is_empty() { + for header in &context.options().input_headers { + writeln!(code, "#include \"{}\"", header)?; + } + + writeln!(code)?; + } + + if !context.options().input_header_contents.is_empty() { + for (name, contents) in &context.options().input_header_contents { + writeln!(code, "// {}\n{}", name, contents)?; + } + + writeln!(code)?; + } + + writeln!(code, "// Static wrappers\n")?; + + for (id, wrap_as_variadic) in &result.items_to_serialize { + let item = context.resolve_item(*id); + item.serialize(context, wrap_as_variadic, &mut vec![], &mut code)?; } std::fs::write(source_path, code)?; @@ -4594,10 +5096,72 @@ pub mod utils { Ok(()) } - pub fn prepend_bitfield_unit_type( + pub(super) fn wrap_as_variadic_fn( + ctx: &BindgenContext, + signature: &FunctionSig, + name: &str, + ) -> Option { + // Fast path, exclude because: + // - with 0 args: no va_list possible, so no point searching for one + // - with 1 args: cannot have a `va_list` and another arg (required by va_start) + if signature.argument_types().len() <= 1 { + return None; + } + + let mut it = signature.argument_types().iter().enumerate().filter_map( + |(idx, (_name, mut type_id))| { + // Hand rolled visitor that checks for the presence of `va_list` + loop { + let ty = ctx.resolve_type(type_id); + if Some("__builtin_va_list") == ty.name() { + return Some(idx); + } + match ty.kind() { + TypeKind::Alias(type_id_alias) => { + type_id = *type_id_alias + } + TypeKind::ResolvedTypeRef(type_id_typedef) => { + type_id = *type_id_typedef + } + _ => break, + } + } + None + }, + ); + + // Return THE idx (by checking that there is no idx after) + // This is done since we cannot handle multiple `va_list` + it.next().filter(|_| it.next().is_none()).and_then(|idx| { + // Call the `wrap_as_variadic_fn` callback + #[cfg(feature = "experimental")] + { + ctx.options() + .last_callback(|c| c.wrap_as_variadic_fn(name)) + .map(|new_name| super::WrapAsVariadic { + new_name, + idx_of_va_list_arg: idx, + }) + } + #[cfg(not(feature = "experimental"))] + { + let _ = name; + let _ = idx; + None + } + }) + } + + pub(crate) fn prepend_bitfield_unit_type( ctx: &BindgenContext, result: &mut Vec, ) { + if ctx.options().blocklisted_items.matches(BITFIELD_UNIT) || + ctx.options().blocklisted_types.matches(BITFIELD_UNIT) + { + return; + } + let bitfield_unit_src = include_str!("./bitfield_unit.rs"); let bitfield_unit_src = if ctx.options().rust_features().min_const_fn { Cow::Borrowed(bitfield_unit_src) @@ -4613,7 +5177,7 @@ pub mod utils { result.extend(old_items); } - pub fn prepend_objc_header( + pub(crate) fn prepend_objc_header( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4635,10 +5199,10 @@ pub mod utils { let items = vec![use_objc, id_type]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } - pub fn prepend_block_header( + pub(crate) fn prepend_block_header( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4654,10 +5218,10 @@ pub mod utils { let items = vec![use_block]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } - pub fn prepend_union_types( + pub(crate) fn prepend_union_types( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4713,7 +5277,7 @@ pub mod utils { impl ::#prefix::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } }; @@ -4766,10 +5330,10 @@ pub mod utils { ]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } - pub fn prepend_incomplete_array_types( + pub(crate) fn prepend_incomplete_array_types( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4842,10 +5406,26 @@ pub mod utils { ]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } - pub fn prepend_complex_type(result: &mut Vec) { + pub(crate) fn prepend_float16_type( + result: &mut Vec, + ) { + let float16_type = quote! { + #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] + #[repr(transparent)] + pub struct __BindgenFloat16(pub u16); + }; + + let items = vec![float16_type]; + let old_items = mem::replace(result, items); + result.extend(old_items); + } + + pub(crate) fn prepend_complex_type( + result: &mut Vec, + ) { let complex_type = quote! { #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] @@ -4857,34 +5437,29 @@ pub mod utils { let items = vec![complex_type]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } - pub fn build_path( + pub(crate) fn build_path( item: &Item, ctx: &BindgenContext, - ) -> error::Result { + ) -> error::Result { let path = item.namespace_aware_canonical_path(ctx); let tokens = proc_macro2::TokenStream::from_str(&path.join("::")).unwrap(); - Ok(tokens) + Ok(syn::parse_quote! { #tokens }) } - fn primitive_ty( - ctx: &BindgenContext, - name: &str, - ) -> proc_macro2::TokenStream { + fn primitive_ty(ctx: &BindgenContext, name: &str) -> syn::Type { let ident = ctx.rust_ident_raw(name); - quote! { - #ident - } + syn::parse_quote! { #ident } } - pub fn type_from_named( + pub(crate) fn type_from_named( ctx: &BindgenContext, name: &str, - ) -> Option { + ) -> Option { // FIXME: We could use the inner item to check this is really a // primitive type but, who the heck overrides these anyway? Some(match name { @@ -4913,14 +5488,9 @@ pub mod utils { fn fnsig_return_ty_internal( ctx: &BindgenContext, sig: &FunctionSig, - include_arrow: bool, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { if sig.is_divergent() { - return if include_arrow { - quote! { -> ! } - } else { - quote! { ! } - }; + return syn::parse_quote! { ! }; } let canonical_type_kind = sig @@ -4933,77 +5503,81 @@ pub mod utils { .expect_type() .kind(); - if let TypeKind::Void = canonical_type_kind { - return if include_arrow { - quote! {} - } else { - quote! { () } - }; - } - - let ret_ty = sig.return_type().to_rust_ty_or_opaque(ctx, &()); - if include_arrow { - quote! { -> #ret_ty } - } else { - ret_ty + match canonical_type_kind { + TypeKind::Void => syn::parse_quote! { () }, + _ => sig.return_type().to_rust_ty_or_opaque(ctx, &()), } } - pub fn fnsig_return_ty( + pub(crate) fn fnsig_return_ty( ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { - fnsig_return_ty_internal(ctx, sig, /* include_arrow = */ true) + match fnsig_return_ty_internal(ctx, sig) { + syn::Type::Tuple(syn::TypeTuple { elems, .. }) + if elems.is_empty() => + { + quote! {} + } + ty => quote! { -> #ty }, + } } - pub fn fnsig_arguments( + pub(crate) fn fnsig_argument_type( ctx: &BindgenContext, - sig: &FunctionSig, - ) -> Vec { + ty: &TypeId, + ) -> syn::Type { use super::ToPtr; - let mut unnamed_arguments = 0; - let mut args = sig - .argument_types() - .iter() - .map(|&(ref name, ty)| { - let arg_item = ctx.resolve_item(ty); - let arg_ty = arg_item.kind().expect_type(); - - // From the C90 standard[1]: - // - // A declaration of a parameter as "array of type" shall be - // adjusted to "qualified pointer to type", where the type - // qualifiers (if any) are those specified within the [ and ] of - // the array type derivation. - // - // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html - let arg_ty = match *arg_ty.canonical_type(ctx).kind() { - TypeKind::Array(t, _) => { - let stream = - if ctx.options().array_pointers_in_arguments { - arg_ty.to_rust_ty_or_opaque(ctx, arg_item) - } else { - t.to_rust_ty_or_opaque(ctx, &()) - }; - stream.to_ptr(ctx.resolve_type(t).is_const()) - } - TypeKind::Pointer(inner) => { - let inner = ctx.resolve_item(inner); - let inner_ty = inner.expect_type(); - if let TypeKind::ObjCInterface(ref interface) = - *inner_ty.canonical_type(ctx).kind() - { - let name = ctx.rust_ident(interface.name()); - quote! { - #name - } - } else { - arg_item.to_rust_ty_or_opaque(ctx, &()) - } - } - _ => arg_item.to_rust_ty_or_opaque(ctx, &()), + let arg_item = ctx.resolve_item(ty); + let arg_ty = arg_item.kind().expect_type(); + + // From the C90 standard[1]: + // + // A declaration of a parameter as "array of type" shall be + // adjusted to "qualified pointer to type", where the type + // qualifiers (if any) are those specified within the [ and ] of + // the array type derivation. + // + // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html + match *arg_ty.canonical_type(ctx).kind() { + TypeKind::Array(t, _) => { + let stream = if ctx.options().array_pointers_in_arguments { + arg_ty.to_rust_ty_or_opaque(ctx, arg_item) + } else { + t.to_rust_ty_or_opaque(ctx, &()) }; + stream + .to_ptr(ctx.resolve_type(t).is_const() || arg_ty.is_const()) + } + TypeKind::Pointer(inner) => { + let inner = ctx.resolve_item(inner); + let inner_ty = inner.expect_type(); + if let TypeKind::ObjCInterface(ref interface) = + *inner_ty.canonical_type(ctx).kind() + { + let name = ctx.rust_ident(interface.name()); + syn::parse_quote! { #name } + } else { + arg_item.to_rust_ty_or_opaque(ctx, &()) + } + } + _ => arg_item.to_rust_ty_or_opaque(ctx, &()), + } + } + + pub(crate) fn fnsig_arguments_iter< + 'a, + I: Iterator, crate::ir::context::TypeId)>, + >( + ctx: &BindgenContext, + args_iter: I, + is_variadic: bool, + ) -> Vec { + let mut unnamed_arguments = 0; + let mut args = args_iter + .map(|(name, ty)| { + let arg_ty = fnsig_argument_type(ctx, ty); let arg_name = match *name { Some(ref name) => ctx.rust_mangle(name).into_owned(), @@ -5022,14 +5596,25 @@ pub mod utils { }) .collect::>(); - if sig.is_variadic() { + if is_variadic { args.push(quote! { ... }) } args } - pub fn fnsig_argument_identifiers( + pub(crate) fn fnsig_arguments( + ctx: &BindgenContext, + sig: &FunctionSig, + ) -> Vec { + fnsig_arguments_iter( + ctx, + sig.argument_types().iter(), + sig.is_variadic(), + ) + } + + pub(crate) fn fnsig_argument_identifiers( ctx: &BindgenContext, sig: &FunctionSig, ) -> Vec { @@ -5058,7 +5643,7 @@ pub mod utils { args } - pub fn fnsig_block( + pub(crate) fn fnsig_block( ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { @@ -5068,9 +5653,7 @@ pub mod utils { arg_item.to_rust_ty_or_opaque(ctx, &()) }); - let ret_ty = fnsig_return_ty_internal( - ctx, sig, /* include_arrow = */ false, - ); + let ret_ty = fnsig_return_ty_internal(ctx, sig); quote! { *const ::block::Block<(#(#args,)*), #ret_ty> } diff --git a/bindgen/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs index eb91683e423477fdcb775999d35bb91004e59041..10fa0ec80bb84d1139d557f5ad4c8dd8cd46fb83 100644 --- a/bindgen/codegen/postprocessing/merge_extern_blocks.rs +++ b/bindgen/codegen/postprocessing/merge_extern_blocks.rs @@ -1,68 +1,72 @@ use syn::{ - visit_mut::{visit_item_mod_mut, VisitMut}, - Item, ItemForeignMod, ItemMod, + visit_mut::{visit_file_mut, visit_item_mod_mut, VisitMut}, + File, Item, ItemForeignMod, ItemMod, }; -pub(super) fn merge_extern_blocks(item_mod: &mut ItemMod) { - Visitor.visit_item_mod_mut(item_mod) +pub(super) fn merge_extern_blocks(file: &mut File) { + Visitor.visit_file_mut(file) } struct Visitor; impl VisitMut for Visitor { + fn visit_file_mut(&mut self, file: &mut File) { + visit_items(&mut file.items); + visit_file_mut(self, file) + } + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { - // Keep all the extern blocks in a different `Vec` for faster search. - let mut extern_blocks = Vec::::new(); + visit_items(items); + } + visit_item_mod_mut(self, item_mod) + } +} + +fn visit_items(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut extern_blocks = Vec::::new(); - for item in std::mem::take(items) { - if let Item::ForeignMod(ItemForeignMod { + for item in std::mem::take(items) { + if let Item::ForeignMod(ItemForeignMod { + attrs, + abi, + brace_token, + unsafety, + items: extern_block_items, + }) = item + { + let mut exists = false; + for extern_block in &mut extern_blocks { + // Check if there is a extern block with the same ABI and + // attributes. + if extern_block.attrs == attrs && extern_block.abi == abi { + // Merge the items of the two blocks. + extern_block.items.extend_from_slice(&extern_block_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + extern_blocks.push(ItemForeignMod { attrs, abi, brace_token, unsafety, items: extern_block_items, - }) = item - { - let mut exists = false; - for extern_block in &mut extern_blocks { - // Check if there is a extern block with the same ABI and - // attributes. - if extern_block.attrs == attrs && - extern_block.abi == abi - { - // Merge the items of the two blocks. - extern_block - .items - .extend_from_slice(&extern_block_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - extern_blocks.push(ItemForeignMod { - attrs, - abi, - brace_token, - unsafety, - items: extern_block_items, - }); - } - } else { - // If the item is not an extern block, we don't have to do anything and just - // push it back. - items.push(item); - } - } - - // Move all the extern blocks alongside the rest of the items. - for extern_block in extern_blocks { - items.push(Item::ForeignMod(extern_block)); + }); } + } else { + // If the item is not an extern block, we don't have to do anything and just + // push it back. + items.push(item); } + } - visit_item_mod_mut(self, item_mod) + // Move all the extern blocks alongside the rest of the items. + for extern_block in extern_blocks { + items.push(Item::ForeignMod(extern_block)); } } diff --git a/bindgen/codegen/postprocessing/mod.rs b/bindgen/codegen/postprocessing/mod.rs index 1d5a4983bd8a4ccd0c443b1c40d9a1a26190a2ba..964169852100a145149a2a8c3b00f12c620e4690 100644 --- a/bindgen/codegen/postprocessing/mod.rs +++ b/bindgen/codegen/postprocessing/mod.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; use quote::ToTokens; -use syn::{parse2, ItemMod}; +use syn::{parse2, File}; use crate::BindgenOptions; @@ -12,7 +12,7 @@ use sort_semantically::sort_semantically; struct PostProcessingPass { should_run: fn(&BindgenOptions) -> bool, - run: fn(&mut ItemMod), + run: fn(&mut File), } // TODO: This can be a const fn when mutable references are allowed in const @@ -21,7 +21,7 @@ macro_rules! pass { ($pass:ident) => { PostProcessingPass { should_run: |options| options.$pass, - run: |item_mod| $pass(item_mod), + run: |file| $pass(file), } }; } @@ -33,34 +33,25 @@ pub(crate) fn postprocessing( items: Vec, options: &BindgenOptions, ) -> TokenStream { + let items = items.into_iter().collect(); let require_syn = PASSES.iter().any(|pass| (pass.should_run)(options)); + if !require_syn { - return items.into_iter().collect(); + return items; } - let module_wrapped_tokens = - quote!(mod wrapper_for_postprocessing_hack { #( #items )* }); // This syn business is a hack, for now. This means that we are re-parsing already // generated code using `syn` (as opposed to `quote`) because `syn` provides us more // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. // The `unwrap` here is deliberate because bindgen should generate valid rust items at all // times. - let mut item_mod = parse2::(module_wrapped_tokens).unwrap(); + let mut file = parse2::(items).unwrap(); for pass in PASSES { if (pass.should_run)(options) { - (pass.run)(&mut item_mod); + (pass.run)(&mut file); } } - let synful_items = item_mod - .content - .map(|(_, items)| items) - .unwrap_or_default() - .into_iter() - .map(|item| item.into_token_stream()); - - quote! { #( #synful_items )* } + file.into_token_stream() } diff --git a/bindgen/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs index 71fb75c4bb773650c7d252418fad1240c946ec3f..be94ce69c548ebe54a3813cc2270f59e6e68ad8d 100644 --- a/bindgen/codegen/postprocessing/sort_semantically.rs +++ b/bindgen/codegen/postprocessing/sort_semantically.rs @@ -1,37 +1,46 @@ use syn::{ - visit_mut::{visit_item_mod_mut, VisitMut}, - Item, ItemMod, + visit_mut::{visit_file_mut, visit_item_mod_mut, VisitMut}, + File, Item, ItemMod, }; -pub(super) fn sort_semantically(item_mod: &mut ItemMod) { - Visitor.visit_item_mod_mut(item_mod) +pub(super) fn sort_semantically(file: &mut File) { + Visitor.visit_file_mut(file) } struct Visitor; impl VisitMut for Visitor { + fn visit_file_mut(&mut self, file: &mut File) { + visit_items(&mut file.items); + visit_file_mut(self, file) + } + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { - items.sort_by_key(|item| match item { - Item::Type(_) => 0, - Item::Struct(_) => 1, - Item::Const(_) => 2, - Item::Fn(_) => 3, - Item::Enum(_) => 4, - Item::Union(_) => 5, - Item::Static(_) => 6, - Item::Trait(_) => 7, - Item::TraitAlias(_) => 8, - Item::Impl(_) => 9, - Item::Mod(_) => 10, - Item::Use(_) => 11, - Item::Verbatim(_) => 12, - Item::ExternCrate(_) => 13, - Item::ForeignMod(_) => 14, - Item::Macro(_) => 15, - _ => 18, - }); + visit_items(items); } visit_item_mod_mut(self, item_mod) } } + +fn visit_items(items: &mut [Item]) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + _ => 18, + }); +} diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 217098e5906b9d89a274df34743c93f6591ed30b..7f00f809f46a596780fa64f0775d15eaffb0e4bf 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -10,7 +10,7 @@ use crate::ir::item::ItemCanonicalName; use crate::ir::item_kind::ItemKind; use crate::ir::ty::{FloatKind, Type, TypeKind}; -use super::CodegenError; +use super::{CodegenError, WrapAsVariadic}; fn get_loc(item: &Item) -> String { item.location() @@ -18,7 +18,7 @@ fn get_loc(item: &Item) -> String { .unwrap_or_else(|| "unknown".to_owned()) } -pub(crate) trait CSerialize<'a> { +pub(super) trait CSerialize<'a> { type Extra; fn serialize( @@ -31,36 +31,34 @@ pub(crate) trait CSerialize<'a> { } impl<'a> CSerialize<'a> for Item { - type Extra = (); + type Extra = &'a Option; fn serialize( &self, ctx: &BindgenContext, - (): Self::Extra, + extra: Self::Extra, stack: &mut Vec, writer: &mut W, ) -> Result<(), CodegenError> { match self.kind() { ItemKind::Function(func) => { - func.serialize(ctx, self, stack, writer) - } - kind => { - return Err(CodegenError::Serialize { - msg: format!("Cannot serialize item kind {:?}", kind), - loc: get_loc(self), - }); + func.serialize(ctx, (self, extra), stack, writer) } + kind => Err(CodegenError::Serialize { + msg: format!("Cannot serialize item kind {:?}", kind), + loc: get_loc(self), + }), } } } impl<'a> CSerialize<'a> for Function { - type Extra = &'a Item; + type Extra = (&'a Item, &'a Option); fn serialize( &self, ctx: &BindgenContext, - item: Self::Extra, + (item, wrap_as_variadic): Self::Extra, stack: &mut Vec, writer: &mut W, ) -> Result<(), CodegenError> { @@ -79,69 +77,122 @@ impl<'a> CSerialize<'a> for Function { _ => unreachable!(), }; + assert!(!signature.is_variadic()); + let name = self.name(); - // Function argoments stored as `(name, type_id)` tuples. + // Function arguments stored as `(name, type_id)` tuples. let args = { let mut count = 0; + let idx_to_prune = wrap_as_variadic.as_ref().map( + |WrapAsVariadic { + idx_of_va_list_arg, .. + }| *idx_of_va_list_arg, + ); + signature .argument_types() .iter() .cloned() - .map(|(opt_name, type_id)| { - ( - opt_name.unwrap_or_else(|| { - let name = format!("arg_{}", count); - count += 1; - name - }), - type_id, - ) + .enumerate() + .filter_map(|(idx, (opt_name, type_id))| { + if Some(idx) == idx_to_prune { + None + } else { + Some(( + opt_name.unwrap_or_else(|| { + let name = format!("arg_{}", count); + count += 1; + name + }), + type_id, + )) + } }) .collect::>() }; // The name used for the wrapper self. let wrap_name = format!("{}{}", name, ctx.wrap_static_fns_suffix()); + // The function's return type - let ret_ty = signature.return_type(); + let (ret_item, ret_ty) = { + let type_id = signature.return_type(); + let ret_item = ctx.resolve_item(type_id); + let ret_ty = ret_item.expect_type(); + + // Write `ret_ty`. + ret_ty.serialize(ctx, ret_item, stack, writer)?; - // Write `ret_ty wrap_name(args) asm("wrap_name");` - ret_ty.serialize(ctx, (), stack, writer)?; + (ret_item, ret_ty) + }; + + const INDENT: &str = " "; + + // Write `wrap_name(args`. write!(writer, " {}(", wrap_name)?; - if args.is_empty() { - write!(writer, "void")?; + serialize_args(&args, ctx, writer)?; + + if wrap_as_variadic.is_none() { + // Write `) { name(` if the function returns void and `) { return name(` if it does not. + if ret_ty.is_void() { + write!(writer, ") {{ {}(", name)?; + } else { + write!(writer, ") {{ return {}(", name)?; + } } else { - serialize_sep( - ", ", - args.iter(), - ctx, + // Write `, ...) {` + writeln!(writer, ", ...) {{")?; + + // Declare the return type `RET_TY ret;` if their is a need to do so + if !ret_ty.is_void() { + write!(writer, "{INDENT}")?; + ret_ty.serialize(ctx, ret_item, stack, writer)?; + writeln!(writer, " ret;")?; + } + + // Setup va_list + writeln!(writer, "{INDENT}va_list ap;\n")?; + writeln!( writer, - |(name, type_id), ctx, buf| { - type_id.serialize(ctx, (), &mut vec![name.clone()], buf) - }, + "{INDENT}va_start(ap, {});", + args.last().unwrap().0 )?; + + write!(writer, "{INDENT}")?; + // Write `ret = name(` or `name(` depending if the function returns something + if !ret_ty.is_void() { + write!(writer, "ret = ")?; + } + write!(writer, "{}(", name)?; } - writeln!(writer, ") asm(\"{}\");", wrap_name)?; - // Write `ret_ty wrap_name(args) { return name(arg_names)' }` - ret_ty.serialize(ctx, (), stack, writer)?; - write!(writer, " {}(", wrap_name)?; - serialize_sep( - ", ", - args.iter(), - ctx, - writer, - |(name, type_id), _, buf| { - type_id.serialize(ctx, (), &mut vec![name.clone()], buf) - }, - )?; - write!(writer, ") {{ return {}(", name)?; - serialize_sep(", ", args.iter(), ctx, writer, |(name, _), _, buf| { + // Get the arguments names and insert at the right place if necessary `ap` + let mut args: Vec<_> = args.into_iter().map(|(name, _)| name).collect(); + if let Some(WrapAsVariadic { + idx_of_va_list_arg, .. + }) = wrap_as_variadic + { + args.insert(*idx_of_va_list_arg, "ap".to_owned()); + } + + // Write `arg_names);`. + serialize_sep(", ", args.iter(), ctx, writer, |name, _, buf| { write!(buf, "{}", name).map_err(From::from) })?; - writeln!(writer, "); }}")?; + #[rustfmt::skip] + write!(writer, ");{}", if wrap_as_variadic.is_none() { " " } else { "\n" })?; + + if wrap_as_variadic.is_some() { + // End va_list and return the result if their is one + writeln!(writer, "{INDENT}va_end(ap);")?; + if !ret_ty.is_void() { + writeln!(writer, "{INDENT}return ret;")?; + } + } + + writeln!(writer, "}}")?; Ok(()) } @@ -219,6 +270,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, "const ")?; } match float_kind { + FloatKind::Float16 => write!(writer, "_Float16")?, FloatKind::Float => write!(writer, "float")?, FloatKind::Double => write!(writer, "double")?, FloatKind::LongDouble => write!(writer, "long double")?, @@ -230,6 +282,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, "const ")?; } match float_kind { + FloatKind::Float16 => write!(writer, "_Float16 complex")?, FloatKind::Float => write!(writer, "float complex")?, FloatKind::Double => write!(writer, "double complex")?, FloatKind::LongDouble => { @@ -271,21 +324,26 @@ impl<'a> CSerialize<'a> for Type { } write!(writer, ")")?; - write!(writer, " (")?; - serialize_sep( - ", ", - signature.argument_types().iter(), - ctx, - writer, - |(name, type_id), ctx, buf| { - let mut stack = vec![]; - if let Some(name) = name { - stack.push(name.clone()); - } - type_id.serialize(ctx, (), &mut stack, buf) - }, - )?; - write!(writer, ")")? + let args = signature.argument_types(); + if args.is_empty() { + write!(writer, " (void)")?; + } else { + write!(writer, " (")?; + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + let mut stack = vec![]; + if let Some(name) = name { + stack.push(name.clone()); + } + type_id.serialize(ctx, (), &mut stack, buf) + }, + )?; + write!(writer, ")")? + } } TypeKind::ResolvedTypeRef(type_id) => { if self.is_const() { @@ -313,6 +371,14 @@ impl<'a> CSerialize<'a> for Type { CompKind::Union => write!(writer, "union {}", name)?, }; } + TypeKind::Enum(_enum_ty) => { + if self.is_const() { + write!(writer, "const ")?; + } + + let name = item.canonical_name(ctx); + write!(writer, "enum {}", name)?; + } ty => { return Err(CodegenError::Serialize { msg: format!("Cannot serialize type kind {:?}", ty), @@ -332,6 +398,28 @@ impl<'a> CSerialize<'a> for Type { } } +fn serialize_args( + args: &[(String, TypeId)], + ctx: &BindgenContext, + writer: &mut W, +) -> Result<(), CodegenError> { + if args.is_empty() { + write!(writer, "void")?; + } else { + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + type_id.serialize(ctx, (), &mut vec![name.clone()], buf) + }, + )?; + } + + Ok(()) +} + fn serialize_sep< W: Write, F: FnMut(I::Item, &BindgenContext, &mut W) -> Result<(), CodegenError>, diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index ddac1b0abb529793050c9e65ccbde2c7511647ba..507c8d40e24b45f134c1e3da2184071edfe7d678 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -6,14 +6,15 @@ use crate::ir::comp::CompInfo; use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; use crate::ir::ty::{Type, TypeKind}; -use proc_macro2::{self, Ident, Span}; +use crate::FieldVisibilityKind; +use proc_macro2::{Ident, Span}; use std::cmp; const MAX_GUARANTEED_ALIGN: usize = 8; /// Trace the layout of struct. #[derive(Debug)] -pub struct StructLayoutTracker<'a> { +pub(crate) struct StructLayoutTracker<'a> { name: &'a str, ctx: &'a BindgenContext, comp: &'a CompInfo, @@ -26,10 +27,12 @@ pub struct StructLayoutTracker<'a> { latest_field_layout: Option, max_field_align: usize, last_field_was_bitfield: bool, + visibility: FieldVisibilityKind, + last_field_was_flexible_array: bool, } /// Returns a size aligned to a given value. -pub fn align_to(size: usize, align: usize) -> usize { +pub(crate) fn align_to(size: usize, align: usize) -> usize { if align == 0 { return size; } @@ -43,7 +46,7 @@ pub fn align_to(size: usize, align: usize) -> usize { } /// Returns the lower power of two byte count that can hold at most n bits. -pub fn bytes_from_bits_pow2(mut n: usize) -> usize { +pub(crate) fn bytes_from_bits_pow2(mut n: usize) -> usize { if n == 0 { return 0; } @@ -83,20 +86,22 @@ fn test_bytes_from_bits_pow2() { } impl<'a> StructLayoutTracker<'a> { - pub fn new( + pub(crate) fn new( ctx: &'a BindgenContext, comp: &'a CompInfo, ty: &'a Type, name: &'a str, + visibility: FieldVisibilityKind, + is_packed: bool, ) -> Self { let known_type_layout = ty.layout(ctx); - let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); let (is_rust_union, can_copy_union_fields) = comp.is_rust_union(ctx, known_type_layout.as_ref(), name); StructLayoutTracker { name, ctx, comp, + visibility, is_packed, known_type_layout, is_rust_union, @@ -106,18 +111,23 @@ impl<'a> StructLayoutTracker<'a> { latest_field_layout: None, max_field_align: 0, last_field_was_bitfield: false, + last_field_was_flexible_array: false, } } - pub fn can_copy_union_fields(&self) -> bool { + pub(crate) fn can_copy_union_fields(&self) -> bool { self.can_copy_union_fields } - pub fn is_rust_union(&self) -> bool { + pub(crate) fn is_rust_union(&self) -> bool { self.is_rust_union } - pub fn saw_vtable(&mut self) { + pub(crate) fn saw_flexible_array(&mut self) { + self.last_field_was_flexible_array = true; + } + + pub(crate) fn saw_vtable(&mut self) { debug!("saw vtable for {}", self.name); let ptr_size = self.ctx.target_pointer_size(); @@ -126,7 +136,7 @@ impl<'a> StructLayoutTracker<'a> { self.max_field_align = ptr_size; } - pub fn saw_base(&mut self, base_ty: &Type) { + pub(crate) fn saw_base(&mut self, base_ty: &Type) { debug!("saw base for {}", self.name); if let Some(layout) = base_ty.layout(self.ctx) { self.align_to_latest_field(layout); @@ -137,7 +147,7 @@ impl<'a> StructLayoutTracker<'a> { } } - pub fn saw_bitfield_unit(&mut self, layout: Layout) { + pub(crate) fn saw_bitfield_unit(&mut self, layout: Layout) { debug!("saw bitfield unit for {}: {:?}", self.name, layout); self.align_to_latest_field(layout); @@ -152,14 +162,12 @@ impl<'a> StructLayoutTracker<'a> { self.latest_field_layout = Some(layout); self.last_field_was_bitfield = true; - // NB: We intentionally don't update the max_field_align here, since our - // bitfields code doesn't necessarily guarantee it, so we need to - // actually generate the dummy alignment. + self.max_field_align = cmp::max(self.max_field_align, layout.align); } /// Returns a padding field if necessary for a given new field _before_ /// adding that field. - pub fn saw_field( + pub(crate) fn saw_field( &mut self, field_name: &str, field_ty: &Type, @@ -189,7 +197,7 @@ impl<'a> StructLayoutTracker<'a> { self.saw_field_with_layout(field_name, field_layout, field_offset) } - pub fn saw_field_with_layout( + pub(crate) fn saw_field_with_layout( &mut self, field_name: &str, field_layout: Layout, @@ -210,7 +218,10 @@ impl<'a> StructLayoutTracker<'a> { 0 } else if !self.is_packed { self.padding_bytes(field_layout) - } else if let Some(l) = self.known_type_layout { + } else if let Some(mut l) = self.known_type_layout { + if field_layout.align < l.align { + l.align = field_layout.align; + } self.padding_bytes(l) } else { 0 @@ -274,7 +285,7 @@ impl<'a> StructLayoutTracker<'a> { padding_layout.map(|layout| self.padding_field(layout)) } - pub fn add_tail_padding( + pub(crate) fn add_tail_padding( &mut self, comp_name: &str, comp_layout: Layout, @@ -290,6 +301,11 @@ impl<'a> StructLayoutTracker<'a> { return None; } + // Also doesn't make sense for structs with flexible array members + if self.last_field_was_flexible_array { + return None; + } + if self.latest_offset == comp_layout.size { // This struct does not contain tail padding. return None; @@ -305,7 +321,7 @@ impl<'a> StructLayoutTracker<'a> { Some(self.padding_field(Layout::new(size, 0))) } - pub fn pad_struct( + pub(crate) fn pad_struct( &mut self, layout: Layout, ) -> Option { @@ -360,7 +376,7 @@ impl<'a> StructLayoutTracker<'a> { } } - pub fn requires_explicit_align(&self, layout: Layout) -> bool { + pub(crate) fn requires_explicit_align(&self, layout: Layout) -> bool { let repr_align = self.ctx.options().rust_features().repr_align; // Always force explicit repr(align) for stuff more than 16-byte aligned @@ -397,8 +413,10 @@ impl<'a> StructLayoutTracker<'a> { self.max_field_align = cmp::max(self.max_field_align, layout.align); + let vis = super::access_specifier(self.visibility); + quote! { - pub #padding_field_name : #ty , + #vis #padding_field_name : #ty , } } diff --git a/bindgen/deps.rs b/bindgen/deps.rs index 987225b28eb91279f43235236f559661d70dd2c0..be31f928960171442bb6ad36d35c184caa4485de 100644 --- a/bindgen/deps.rs +++ b/bindgen/deps.rs @@ -8,13 +8,54 @@ pub(crate) struct DepfileSpec { } impl DepfileSpec { - pub fn write(&self, deps: &BTreeSet) -> std::io::Result<()> { - let mut buf = format!("{}:", self.output_module); + pub fn write(&self, deps: &BTreeSet>) -> std::io::Result<()> { + std::fs::write(&self.depfile_path, self.to_string(deps)) + } + + fn to_string(&self, deps: &BTreeSet>) -> String { + // Transforms a string by escaping spaces and backslashes. + let escape = |s: &str| s.replace('\\', "\\\\").replace(' ', "\\ "); + let mut buf = format!("{}:", escape(&self.output_module)); for file in deps { - buf = format!("{} {}", buf, file); + buf = format!("{} {}", buf, escape(file)); } + buf + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn escaping_depfile() { + let spec = DepfileSpec { + output_module: "Mod Name".to_owned(), + depfile_path: PathBuf::new(), + }; - std::fs::write(&self.depfile_path, &buf) + let deps: BTreeSet<_> = vec![ + r"/absolute/path".into(), + r"C:\win\absolute\path".into(), + r"../relative/path".into(), + r"..\win\relative\path".into(), + r"../path/with spaces/in/it".into(), + r"..\win\path\with spaces\in\it".into(), + r"path\with/mixed\separators".into(), + ] + .into_iter() + .collect(); + assert_eq!( + spec.to_string(&deps), + "Mod\\ Name: \ + ../path/with\\ spaces/in/it \ + ../relative/path \ + ..\\\\win\\\\path\\\\with\\ spaces\\\\in\\\\it \ + ..\\\\win\\\\relative\\\\path \ + /absolute/path \ + C:\\\\win\\\\absolute\\\\path \ + path\\\\with/mixed\\\\separators" + ); } } diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs new file mode 100644 index 0000000000000000000000000000000000000000..f765afe97097f90be71dbac15e4b98ca689b6fe1 --- /dev/null +++ b/bindgen/diagnostics.rs @@ -0,0 +1,189 @@ +//! Types and function used to emit pretty diagnostics for `bindgen`. +//! +//! The entry point of this module is the [`Diagnostic`] type. + +use std::fmt::Write; +use std::io::{self, BufRead, BufReader}; +use std::{borrow::Cow, fs::File}; + +use annotate_snippets::{ + display_list::{DisplayList, FormatOptions}, + snippet::{Annotation, Slice as ExtSlice, Snippet}, +}; + +use annotate_snippets::snippet::AnnotationType; + +#[derive(Clone, Copy, Debug)] +pub(crate) enum Level { + Error, + Warn, + Info, + Note, + Help, +} + +impl From for AnnotationType { + fn from(level: Level) -> Self { + match level { + Level::Error => Self::Error, + Level::Warn => Self::Warning, + Level::Info => Self::Info, + Level::Note => Self::Note, + Level::Help => Self::Help, + } + } +} + +/// A `bindgen` diagnostic. +#[derive(Default)] +pub(crate) struct Diagnostic<'a> { + title: Option<(Cow<'a, str>, Level)>, + slices: Vec>, + footer: Vec<(Cow<'a, str>, Level)>, +} + +impl<'a> Diagnostic<'a> { + /// Add a title to the diagnostic and set its type. + pub(crate) fn with_title( + &mut self, + title: impl Into>, + level: Level, + ) -> &mut Self { + self.title = Some((title.into(), level)); + self + } + + /// Add a slice of source code to the diagnostic. + pub(crate) fn add_slice(&mut self, slice: Slice<'a>) -> &mut Self { + self.slices.push(slice); + self + } + + /// Add a footer annotation to the diagnostic. This annotation will have its own type. + pub(crate) fn add_annotation( + &mut self, + msg: impl Into>, + level: Level, + ) -> &mut Self { + self.footer.push((msg.into(), level)); + self + } + + /// Print this diagnostic. + /// + /// The diagnostic is printed using `cargo:warning` if `bindgen` is being invoked by a build + /// script or using `eprintln` otherwise. + pub(crate) fn display(&self) { + std::thread_local! { + static INVOKED_BY_BUILD_SCRIPT: bool = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some(); + } + + let mut title = None; + let mut footer = vec![]; + let mut slices = vec![]; + if let Some((msg, level)) = &self.title { + title = Some(Annotation { + id: Some("bindgen"), + label: Some(msg.as_ref()), + annotation_type: (*level).into(), + }) + } + + for (msg, level) in &self.footer { + footer.push(Annotation { + id: None, + label: Some(msg.as_ref()), + annotation_type: (*level).into(), + }); + } + + // add additional info that this is generated by bindgen + // so as to not confuse with rustc warnings + footer.push(Annotation { + id: None, + label: Some("This diagnostic was generated by bindgen."), + annotation_type: AnnotationType::Info, + }); + + for slice in &self.slices { + if let Some(source) = &slice.source { + slices.push(ExtSlice { + source: source.as_ref(), + line_start: slice.line.unwrap_or_default(), + origin: slice.filename.as_deref(), + annotations: vec![], + fold: false, + }) + } + } + + let snippet = Snippet { + title, + footer, + slices, + opt: FormatOptions { + color: true, + ..Default::default() + }, + }; + let dl = DisplayList::from(snippet); + + if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) { + // This is just a hack which hides the `warning:` added by cargo at the beginning of + // every line. This should be fine as our diagnostics already have a colorful title. + // FIXME (pvdrz): Could it be that this doesn't work in other languages? + let hide_warning = "\r \r"; + let string = dl.to_string(); + for line in string.lines() { + println!("cargo:warning={}{}", hide_warning, line); + } + } else { + eprintln!("{}\n", dl); + } + } +} + +/// A slice of source code. +#[derive(Default)] +pub(crate) struct Slice<'a> { + source: Option>, + filename: Option, + line: Option, +} + +impl<'a> Slice<'a> { + /// Set the source code. + pub(crate) fn with_source( + &mut self, + source: impl Into>, + ) -> &mut Self { + self.source = Some(source.into()); + self + } + + /// Set the file, line and column. + pub(crate) fn with_location( + &mut self, + mut name: String, + line: usize, + col: usize, + ) -> &mut Self { + write!(name, ":{}:{}", line, col) + .expect("Writing to a string cannot fail"); + self.filename = Some(name); + self.line = Some(line); + self + } +} + +pub(crate) fn get_line( + filename: &str, + line: usize, +) -> io::Result> { + let file = BufReader::new(File::open(filename)?); + if let Some(line) = file.lines().nth(line.wrapping_sub(1)) { + return line.map(Some); + } + + Ok(None) +} diff --git a/bindgen/extra_assertions.rs b/bindgen/extra_assertions.rs index 0888bf396961790d671a6644e9bba7a65dec010a..fbddad7825737d0dc08d7c95cc4d5c415f90696c 100644 --- a/bindgen/extra_assertions.rs +++ b/bindgen/extra_assertions.rs @@ -1,34 +1,17 @@ //! Macros for defining extra assertions that should only be checked in testing -//! and/or CI when the `testing_only_extra_assertions` feature is enabled. +//! and/or CI when the `__testing_only_extra_assertions` feature is enabled. /// Simple macro that forwards to assert! when using -/// testing_only_extra_assertions. -#[macro_export] +/// __testing_only_extra_assertions. macro_rules! extra_assert { ( $cond:expr ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!($cond); } }; ( $cond:expr , $( $arg:tt )+ ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!($cond, $( $arg )* ) } }; } - -/// Simple macro that forwards to assert_eq! when using -/// testing_only_extra_assertions. -#[macro_export] -macro_rules! extra_assert_eq { - ( $lhs:expr , $rhs:expr ) => { - if cfg!(feature = "testing_only_extra_assertions") { - assert_eq!($lhs, $rhs); - } - }; - ( $lhs:expr , $rhs:expr , $( $arg:tt )+ ) => { - if cfg!(feature = "testing_only_extra_assertions") { - assert!($lhs, $rhs, $( $arg )* ); - } - }; -} diff --git a/bindgen/features.rs b/bindgen/features.rs index 4fee5d63fc179dc1e0c69800390cc68d807be996..ca4c41edc92617f69b310ac361a57dbc960aaaf0 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -1,263 +1,239 @@ //! Contains code for selecting features -#![deny(missing_docs)] #![deny(unused_extern_crates)] +#![deny(clippy::missing_docs_in_private_items)] #![allow(deprecated)] +use std::cmp::Ordering; use std::io; use std::str::FromStr; -/// Define RustTarget struct definition, Default impl, and conversions -/// between RustTarget and String. -macro_rules! rust_target_def { - ( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => { +/// This macro defines the [`RustTarget`] and [`RustFeatures`] types. +macro_rules! define_rust_targets { + ( + Nightly => {$($nightly_feature:ident $(: #$issue:literal)?),* $(,)?} $(,)? + $( + $(#[$attrs:meta])* + $variant:ident($minor:literal) => {$($feature:ident $(: #$pull:literal)?),* $(,)?}, + )* + $(,)? + ) => { /// Represents the version of the Rust language to target. /// /// To support a beta release, use the corresponding stable release. /// /// This enum will have more variants added as necessary. - #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Hash)] #[allow(non_camel_case_types)] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum RustTarget { + /// Rust Nightly + $(#[doc = concat!( + "- [`", stringify!($nightly_feature), "`]", + "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", + )])* + Nightly, $( - $( - #[$attr] - )* - $release, + #[doc = concat!("Rust 1.", stringify!($minor))] + $(#[doc = concat!( + "- [`", stringify!($feature), "`]", + "(", $("https://github.com/rust-lang/rust/pull/", stringify!($pull),)* ")", + )])* + $(#[$attrs])* + $variant, )* } - impl Default for RustTarget { - /// Gives the latest stable Rust version - fn default() -> RustTarget { - LATEST_STABLE_RUST + impl RustTarget { + fn minor(self) -> Option { + match self { + $( Self::$variant => Some($minor),)* + Self::Nightly => None + } + } + + const fn stable_releases() -> [(Self, u64); [$($minor,)*].len()] { + [$((Self::$variant, $minor),)*] } } - impl FromStr for RustTarget { - type Err = io::Error; + // #[cfg(feature = "__cli")] + /// Strings of allowed `RustTarget` values + pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; - /// Create a `RustTarget` from a string. - /// - /// * The stable/beta versions of Rust are of the form "1.0", - /// "1.19", etc. - /// * The nightly version should be specified with "nightly". - fn from_str(s: &str) -> Result { - match s.as_ref() { - $( - stringify!($value) => Ok(RustTarget::$release), - )* - _ => Err( - io::Error::new( - io::ErrorKind::InvalidInput, - concat!( - "Got an invalid rust target. Accepted values ", - "are of the form ", - "\"1.0\" or \"nightly\"."))), - } - } + #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] + pub(crate) struct RustFeatures { + $($(pub(crate) $feature: bool,)*)* + $(pub(crate) $nightly_feature: bool,)* } - impl From for String { + impl From for RustFeatures { fn from(target: RustTarget) -> Self { - match target { - $( - RustTarget::$release => stringify!($value), - )* - }.into() + if target == RustTarget::Nightly { + return Self { + $($($feature: true,)*)* + $($nightly_feature: true,)* + }; + } + + let mut features = Self { + $($($feature: false,)*)* + $($nightly_feature: false,)* + }; + + $(if target >= RustTarget::$variant { + $(features.$feature = true;)* + })* + + features } } - } + }; } -/// Defines an array slice with all RustTarget values -macro_rules! rust_target_values_def { - ( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => { - /// Strings of allowed `RustTarget` values - pub static RUST_TARGET_STRINGS: &'static [&str] = &[ - $( - stringify!($value), - )* - ]; +// NOTE: When adding or removing features here, make sure to add the stabilization PR +// number for the feature if it has been stabilized or the tracking issue number if the feature is +// not stable. +define_rust_targets! { + Nightly => { + vectorcall_abi: #124485, + ptr_metadata: #81513, + layout_for_ptr: #69835, + }, + Stable_1_77(77) => { offset_of: #106655 }, + Stable_1_73(73) => { thiscall_abi: #42202 }, + Stable_1_71(71) => { c_unwind_abi: #106075 }, + Stable_1_68(68) => { abi_efiapi: #105795 }, + Stable_1_64(64) => { core_ffi_c: #94503 }, + Stable_1_59(59) => { const_cstr: #54745 }, + Stable_1_47(47) => { larger_arrays: #74060 }, + Stable_1_43(43) => { associated_constants: #68952 }, + Stable_1_40(40) => { non_exhaustive: #44109 }, + Stable_1_36(36) => { maybe_uninit: #60445 }, + Stable_1_33(33) => { repr_packed_n: #57049 }, + #[deprecated] + Stable_1_30(30) => { + core_ffi_c_void: #53910, + min_const_fn: #54835, + }, + #[deprecated] + Stable_1_28(28) => { repr_transparent: #51562 }, + #[deprecated] + Stable_1_27(27) => { must_use_function: #48925 }, + #[deprecated] + Stable_1_26(26) => { i128_and_u128: #49101 }, + #[deprecated] + Stable_1_25(25) => { repr_align: #47006 }, + #[deprecated] + Stable_1_21(21) => { builtin_clone_impls: #43690 }, + #[deprecated] + Stable_1_20(20) => { associated_const: #42809 }, + #[deprecated] + Stable_1_19(19) => { untagged_union: #42068 }, + #[deprecated] + Stable_1_17(17) => { static_lifetime_elision: #39265 }, + #[deprecated] + Stable_1_0(0) => {}, +} + +/// Latest stable release of Rust +pub const LATEST_STABLE_RUST: RustTarget = { + // FIXME: replace all this code by + // ``` + // RustTarget::stable_releases() + // .into_iter() + // .max_by_key(|(_, m)| m) + // .map(|(t, _)| t) + // .unwrap_or(RustTarget::Nightly) + // ``` + // once those operations can be used in constants. + let targets = RustTarget::stable_releases(); + + let mut i = 0; + let mut latest_target = None; + let mut latest_minor = 0; + + while i < targets.len() { + let (target, minor) = targets[i]; + + if latest_minor < minor { + latest_minor = minor; + latest_target = Some(target); + } + + i += 1; + } + + match latest_target { + Some(target) => target, + None => unreachable!(), + } +}; + +impl Default for RustTarget { + fn default() -> Self { + LATEST_STABLE_RUST } } -/// Defines macro which takes a macro -macro_rules! rust_target_base { - ( $x_macro:ident ) => { - $x_macro!( - /// Rust stable 1.0 - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_0 => 1.0; - /// Rust stable 1.17 - /// * Static lifetime elision ([RFC 1623](https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_17 => 1.17; - /// Rust stable 1.19 - /// * Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_19 => 1.19; - /// Rust stable 1.20 - /// * Associated constants ([PR](https://github.com/rust-lang/rust/pull/42809)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_20 => 1.20; - /// Rust stable 1.21 - /// * Builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_21 => 1.21; - /// Rust stable 1.25 - /// * `repr(align)` ([PR](https://github.com/rust-lang/rust/pull/47006)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_25 => 1.25; - /// Rust stable 1.26 - /// * [i128 / u128 support](https://doc.rust-lang.org/std/primitive.i128.html) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_26 => 1.26; - /// Rust stable 1.27 - /// * `must_use` attribute on functions ([PR](https://github.com/rust-lang/rust/pull/48925)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_27 => 1.27; - /// Rust stable 1.28 - /// * `repr(transparent)` ([PR](https://github.com/rust-lang/rust/pull/51562)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_28 => 1.28; - /// Rust stable 1.30 - /// * `const fn` support for limited cases ([PR](https://github.com/rust-lang/rust/pull/54835/) - /// * [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_30 => 1.30; - /// Rust stable 1.33 - /// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049)) - => Stable_1_33 => 1.33; - /// Rust stable 1.36 - /// * `MaybeUninit` instead of `mem::uninitialized()` ([PR](https://github.com/rust-lang/rust/pull/60445)) - => Stable_1_36 => 1.36; - /// Rust stable 1.40 - /// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109)) - => Stable_1_40 => 1.40; - /// Rust stable 1.47 - /// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060)) - => Stable_1_47 => 1.47; - /// Rust stable 1.64 - /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) - => Stable_1_64 => 1.64; - /// Nightly rust - /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) - /// * `vectorcall` calling convention (no tracking issue) - /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) - => Nightly => nightly; - ); +impl PartialOrd for RustTarget { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) } } -rust_target_base!(rust_target_def); -rust_target_base!(rust_target_values_def); +impl Ord for RustTarget { + fn cmp(&self, other: &Self) -> Ordering { + match (self.minor(), other.minor()) { + (Some(a), Some(b)) => a.cmp(&b), + (Some(_), None) => Ordering::Less, + (None, Some(_)) => Ordering::Greater, + (None, None) => Ordering::Equal, + } + } +} -/// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_64; +impl FromStr for RustTarget { + type Err = io::Error; -/// Create RustFeatures struct definition, new(), and a getter for each field -macro_rules! rust_feature_def { - ( - $( $rust_target:ident { - $( $( #[$attr:meta] )* => $feature:ident; )* - } )* - ) => { - /// Features supported by a rust target - #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] - #[allow(missing_docs)] // Documentation should go into the relevant variants. - pub(crate) struct RustFeatures { - $( $( - $( - #[$attr] - )* - pub $feature: bool, - )* )* + fn from_str(s: &str) -> Result { + if s == "nightly" { + return Ok(Self::Nightly); } - impl RustFeatures { - /// Gives a RustFeatures struct with all features disabled - fn new() -> Self { - RustFeatures { - $( $( - $feature: false, - )* )* + if let Some(("1", str_minor)) = s.split_once('.') { + if let Ok(minor) = str_minor.parse::() { + for (target, target_minor) in Self::stable_releases() { + if minor == target_minor { + return Ok(target); + } } } } - impl From for RustFeatures { - fn from(rust_target: RustTarget) -> Self { - let mut features = RustFeatures::new(); - - $( - if rust_target >= RustTarget::$rust_target { - $( - features.$feature = true; - )* - } - )* - - features - } - } + Err(io::Error::new( + io::ErrorKind::InvalidInput, + "Got an invalid Rust target. Accepted values are of the form \"1.71\" or \"nightly\"." + )) } } -// NOTE(emilio): When adding or removing features here, make sure to update the -// documentation for the relevant variant in the rust_target_base macro -// definition. -rust_feature_def!( - Stable_1_17 { - => static_lifetime_elision; - } - Stable_1_19 { - => untagged_union; - } - Stable_1_20 { - => associated_const; - } - Stable_1_21 { - => builtin_clone_impls; - } - Stable_1_25 { - => repr_align; - } - Stable_1_26 { - => i128_and_u128; - } - Stable_1_27 { - => must_use_function; - } - Stable_1_28 { - => repr_transparent; - } - Stable_1_30 { - => min_const_fn; - => core_ffi_c_void; - } - Stable_1_33 { - => repr_packed_n; - } - Stable_1_36 { - => maybe_uninit; - } - Stable_1_40 { - => non_exhaustive; - } - Stable_1_47 { - => larger_arrays; - } - Stable_1_64 { - => core_ffi_c; - } - Nightly { - => thiscall_abi; - => vectorcall_abi; - => c_unwind_abi; +impl std::fmt::Display for RustTarget { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.minor() { + Some(minor) => write!(f, "1.{}", minor), + None => "nightly".fmt(f), + } } -); +} impl Default for RustFeatures { fn default() -> Self { - let default_rust_target: RustTarget = Default::default(); - Self::from(default_rust_target) + RustTarget::default().into() } } #[cfg(test)] mod test { - #![allow(unused_imports)] use super::*; #[test] @@ -284,6 +260,12 @@ mod test { !f_1_21.thiscall_abi && !f_1_21.vectorcall_abi ); + let features = RustFeatures::from(RustTarget::Stable_1_71); + assert!( + features.c_unwind_abi && + features.abi_efiapi && + !features.thiscall_abi + ); let f_nightly = RustFeatures::from(RustTarget::Nightly); assert!( f_nightly.static_lifetime_elision && @@ -294,13 +276,12 @@ mod test { f_nightly.maybe_uninit && f_nightly.repr_align && f_nightly.thiscall_abi && - f_nightly.vectorcall_abi && - f_nightly.c_unwind_abi + f_nightly.vectorcall_abi ); } fn test_target(target_str: &str, target: RustTarget) { - let target_string: String = target.into(); + let target_string = target.to_string(); assert_eq!(target_str, target_string); assert_eq!(target, RustTarget::from_str(target_str).unwrap()); } @@ -312,6 +293,7 @@ mod test { test_target("1.19", RustTarget::Stable_1_19); test_target("1.21", RustTarget::Stable_1_21); test_target("1.25", RustTarget::Stable_1_25); + test_target("1.71", RustTarget::Stable_1_71); test_target("nightly", RustTarget::Nightly); } } diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index d888cd558b7dfc9719c701bdc17fe8a5f664b9ec..d8d29ed9a8ef14792400d171489ebb5e36115fcc 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -61,7 +61,7 @@ pub enum DeriveTrait { /// * For all other (simple) types, compiler and standard library limitations /// dictate whether the trait is implemented. #[derive(Debug, Clone)] -pub struct CannotDerive<'ctx> { +pub(crate) struct CannotDerive<'ctx> { ctx: &'ctx BindgenContext, derive_trait: DeriveTrait, @@ -172,7 +172,7 @@ impl<'ctx> CannotDerive<'ctx> { if item.is_opaque(self.ctx, &()) { if !self.derive_trait.can_derive_union() && ty.is_union() && - self.ctx.options().rust_features().untagged_union + self.ctx.options().untagged_union { trace!( " cannot derive {} for Rust unions", @@ -322,7 +322,7 @@ impl<'ctx> CannotDerive<'ctx> { if info.kind() == CompKind::Union { if self.derive_trait.can_derive_union() { - if self.ctx.options().rust_features().untagged_union && + if self.ctx.options().untagged_union && // https://github.com/rust-lang/rust/issues/36640 (!info.self_template_params(self.ctx).is_empty() || !item.all_template_params(self.ctx).is_empty()) @@ -334,7 +334,7 @@ impl<'ctx> CannotDerive<'ctx> { } // fall through to be same as non-union handling } else { - if self.ctx.options().rust_features().untagged_union { + if self.ctx.options().untagged_union { trace!( " cannot derive {} for Rust unions", self.derive_trait @@ -722,7 +722,7 @@ impl<'ctx> From> for HashMap { /// /// Elements that are not `CanDerive::Yes` are kept in the set, so that it /// represents all items that cannot derive. -pub fn as_cannot_derive_set( +pub(crate) fn as_cannot_derive_set( can_derive: HashMap, ) -> HashSet { can_derive diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 74fd73d14e8b8ae4dd619bda2e976533b799bdee..cbcbe55af2dd21e00faa921326d7d0962f7127a7 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -22,7 +22,7 @@ use crate::{HashMap, HashSet}; /// * If T is the type of a field, that field has a destructor if it's not a bitfield, /// and if T has a destructor. #[derive(Debug, Clone)] -pub struct HasDestructorAnalysis<'ctx> { +pub(crate) struct HasDestructorAnalysis<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index bbf2126f70a3b615dc1bf0871a2da191f37e2a4a..219c5a5a8d1a9d2792be61f4c90054445cae63e9 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -22,7 +22,7 @@ use crate::{HashMap, HashSet}; /// float if any of the template arguments or template definition /// has. #[derive(Debug, Clone)] -pub struct HasFloat<'ctx> { +pub(crate) struct HasFloat<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index aa5230475885e0893c04974217fa5380ab91f8d9..6665547ca609a9758a896fbb0c2dd93a2884c82c 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -17,12 +17,12 @@ use crate::{HashMap, HashSet}; /// * If T is a type alias, a templated alias or an indirection to another type, /// it has type parameter in array if the type T refers to has. /// * If T is a compound type, it has array if any of base memter or field -/// has type paramter in array. +/// has type parameter in array. /// * If T is an instantiation of an abstract template definition, T has /// type parameter in array if any of the template arguments or template definition /// has. #[derive(Debug, Clone)] -pub struct HasTypeParameterInArray<'ctx> { +pub(crate) struct HasTypeParameterInArray<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 8ac47a65daf8864e3af06d49b787c92d128a4619..45dea55e6bc58cb2433ee66facc5b3860d14b987 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -9,9 +9,10 @@ use std::cmp; use std::ops; /// The result of the `HasVtableAnalysis` for an individual item. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub enum HasVtableResult { +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] +pub(crate) enum HasVtableResult { /// The item does not have a vtable pointer. + #[default] No, /// The item has a vtable and the actual vtable pointer is within this item. @@ -22,15 +23,9 @@ pub enum HasVtableResult { BaseHasVtable, } -impl Default for HasVtableResult { - fn default() -> Self { - HasVtableResult::No - } -} - impl HasVtableResult { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } @@ -60,7 +55,7 @@ impl ops::BitOrAssign for HasVtableResult { /// * If T is an instantiation of an abstract template definition, T has /// vtable if template definition has vtable #[derive(Debug, Clone)] -pub struct HasVtableAnalysis<'ctx> { +pub(crate) struct HasVtableAnalysis<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this @@ -230,7 +225,7 @@ impl<'ctx> From> for HashMap { /// This is not for _computing_ whether the thing has a vtable, it is for /// looking up the results of the HasVtableAnalysis's computations for a /// specific thing. -pub trait HasVtable { +pub(crate) trait HasVtable { /// Return `true` if this thing has vtable, `false` otherwise. fn has_vtable(&self, ctx: &BindgenContext) -> bool; diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 40dfc6d644f69fbdaeb61b1344290d23fc45c1e4..1c05f1216d2852fa7e4ff95a7b81b838393aa2cd 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -39,19 +39,24 @@ // Re-export individual analyses. mod template_params; -pub use self::template_params::UsedTemplateParameters; +pub(crate) use self::template_params::UsedTemplateParameters; mod derive; -pub use self::derive::{as_cannot_derive_set, CannotDerive, DeriveTrait}; +pub use self::derive::DeriveTrait; +pub(crate) use self::derive::{as_cannot_derive_set, CannotDerive}; mod has_vtable; -pub use self::has_vtable::{HasVtable, HasVtableAnalysis, HasVtableResult}; +pub(crate) use self::has_vtable::{ + HasVtable, HasVtableAnalysis, HasVtableResult, +}; mod has_destructor; -pub use self::has_destructor::HasDestructorAnalysis; +pub(crate) use self::has_destructor::HasDestructorAnalysis; mod has_type_param_in_array; -pub use self::has_type_param_in_array::HasTypeParameterInArray; +pub(crate) use self::has_type_param_in_array::HasTypeParameterInArray; mod has_float; -pub use self::has_float::HasFloat; +pub(crate) use self::has_float::HasFloat; mod sizedness; -pub use self::sizedness::{Sizedness, SizednessAnalysis, SizednessResult}; +pub(crate) use self::sizedness::{ + Sizedness, SizednessAnalysis, SizednessResult, +}; use crate::ir::context::{BindgenContext, ItemId}; @@ -73,7 +78,7 @@ use std::ops; /// /// For a simple example analysis, see the `ReachableFrom` type in the `tests` /// module below. -pub trait MonotoneFramework: Sized + fmt::Debug { +pub(crate) trait MonotoneFramework: Sized + fmt::Debug { /// The type of node in our dependency graph. /// /// This is just generic (and not `ItemId`) so that we can easily unit test @@ -120,22 +125,17 @@ pub trait MonotoneFramework: Sized + fmt::Debug { /// Whether an analysis's `constrain` function modified the incremental results /// or not. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum ConstrainResult { +#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)] +pub(crate) enum ConstrainResult { /// The incremental results were updated, and the fix-point computation /// should continue. Changed, /// The incremental results were not updated. + #[default] Same, } -impl Default for ConstrainResult { - fn default() -> Self { - ConstrainResult::Same - } -} - impl ops::BitOr for ConstrainResult { type Output = Self; @@ -155,7 +155,7 @@ impl ops::BitOrAssign for ConstrainResult { } /// Run an analysis in the monotone framework. -pub fn analyze(extra: Analysis::Extra) -> Analysis::Output +pub(crate) fn analyze(extra: Analysis::Extra) -> Analysis::Output where Analysis: MonotoneFramework, { @@ -174,7 +174,7 @@ where } /// Generate the dependency map for analysis -pub fn generate_dependencies( +pub(crate) fn generate_dependencies( ctx: &BindgenContext, consider_edge: F, ) -> HashMap> @@ -211,7 +211,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::{HashMap, HashSet}; + use crate::HashSet; // Here we find the set of nodes that are reachable from any given // node. This is a lattice mapping nodes to subsets of all nodes. Our join @@ -329,20 +329,13 @@ mod tests { // Yes, what follows is a **terribly** inefficient set union // implementation. Don't copy this code outside of this test! - let original_size = self - .reachable - .entry(node) - .or_insert_with(HashSet::default) - .len(); + let original_size = self.reachable.entry(node).or_default().len(); for sub_node in self.graph.0[&node].iter() { self.reachable.get_mut(&node).unwrap().insert(*sub_node); - let sub_reachable = self - .reachable - .entry(*sub_node) - .or_insert_with(HashSet::default) - .clone(); + let sub_reachable = + self.reachable.entry(*sub_node).or_default().clone(); for transitive in sub_reachable { self.reachable.get_mut(&node).unwrap().insert(transitive); diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index 251c3747b2c89e021f0c71441b3d39dd4665eaa0..edcf47f5c6c2cf2628b37ec84c98038db39e1191 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -24,13 +24,14 @@ use std::{cmp, ops}; /// /// We initially assume that all types are `ZeroSized` and then update our /// understanding as we learn more about each type. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub enum SizednessResult { +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] +pub(crate) enum SizednessResult { /// The type is zero-sized. /// /// This means that if it is a C++ type, and is not being used as a base /// member, then we must add an `_address` byte to enforce the /// unique-address-per-distinct-object-instance rule. + #[default] ZeroSized, /// Whether this type is zero-sized or not depends on whether a type @@ -52,7 +53,7 @@ pub enum SizednessResult { /// have an `_address` byte inserted. /// /// We don't properly handle this situation correctly right now: - /// https://github.com/rust-lang/rust-bindgen/issues/586 + /// DependsOnTypeParam, /// Has some size that is known to be greater than zero. That doesn't mean @@ -62,15 +63,9 @@ pub enum SizednessResult { NonZeroSized, } -impl Default for SizednessResult { - fn default() -> Self { - SizednessResult::ZeroSized - } -} - impl SizednessResult { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } @@ -92,17 +87,17 @@ impl ops::BitOrAssign for SizednessResult { /// An analysis that computes the sizedness of all types. /// /// * For types with known sizes -- for example pointers, scalars, etc... -- -/// they are assigned `NonZeroSized`. +/// they are assigned `NonZeroSized`. /// /// * For compound structure types with one or more fields, they are assigned -/// `NonZeroSized`. +/// `NonZeroSized`. /// /// * For compound structure types without any fields, the results of the bases -/// are `join`ed. +/// are `join`ed. /// /// * For type parameters, `DependsOnTypeParam` is assigned. #[derive(Debug)] -pub struct SizednessAnalysis<'ctx> { +pub(crate) struct SizednessAnalysis<'ctx> { ctx: &'ctx BindgenContext, dependencies: HashMap>, // Incremental results of the analysis. Missing entries are implicitly @@ -346,11 +341,11 @@ impl<'ctx> From> for HashMap { } } -/// A convenience trait for querying whether some type or id is sized. +/// A convenience trait for querying whether some type or ID is sized. /// /// This is not for _computing_ whether the thing is sized, it is for looking up /// the results of the `Sizedness` analysis's computations for a specific thing. -pub trait Sizedness { +pub(crate) trait Sizedness { /// Get the sizedness of this type. fn sizedness(&self, ctx: &BindgenContext) -> SizednessResult; diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index f4f0c59d71dfbcd60a34e2722a44b29d52f35f2c..a35dcd98e3994aa5aa783751c31a95d4e3026f67 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -14,7 +14,7 @@ //! If we generate the naive Rust code for this alias, we get: //! //! ```ignore -//! pub type Fml = ::std::os::raw::int; +//! pub(crate) type Fml = ::std::os::raw::int; //! ``` //! //! And this is rejected by `rustc` due to the unused type parameter. @@ -124,8 +124,8 @@ use crate::{HashMap, HashSet}; /// ``` /// /// * Finally, for all other IR item kinds, we use our lattice's `join` -/// operation: set union with each successor of the given item's template -/// parameter usage: +/// operation: set union with each successor of the given item's template +/// parameter usage: /// /// ```ignore /// template_param_usage(v) = @@ -146,7 +146,7 @@ use crate::{HashMap, HashSet}; /// specially; see `constrain_instantiation_of_blocklisted_template` and its /// documentation for details. #[derive(Debug, Clone)] -pub struct UsedTemplateParameters<'ctx> { +pub(crate) struct UsedTemplateParameters<'ctx> { ctx: &'ctx BindgenContext, // The Option is only there for temporary moves out of the hash map. See the @@ -329,7 +329,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> { } } - /// The join operation on our lattice: the set union of all of this id's + /// The join operation on our lattice: the set union of all of this ID's /// successors. fn constrain_join(&self, used_by_this_id: &mut ItemSet, item: &Item) { trace!(" other item: join with successors' usage"); @@ -459,7 +459,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { } } - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { // Invariant: The `used` map has an entry for every allowlisted // item, as well as all explicitly blocklisted items that are // reachable from allowlisted items. @@ -518,7 +518,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // exiting this method. extra_assert!(self.used.values().all(|v| v.is_some())); - // Take the set for this id out of the hash map while we mutate it based + // Take the set for this ID out of the hash map while we mutate it based // on other hash map entries. We *must* put it back into the hash map at // the end of this method. This allows us to side-step HashMap's lack of // an analog to slice::split_at_mut. diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 288c11ebae8d9cd3ea6c2eca17c84fa86442c2be..fc9cc0ffe7b210d941aae1a2504e931ccfcf29a8 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -4,11 +4,50 @@ //! replace other types with, mark as opaque, etc. This module deals with all of //! that stuff. +use std::str::FromStr; + use crate::clang; +/// What kind of visibility modifier should be used for a struct or field? +#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)] +pub enum FieldVisibilityKind { + /// Fields are marked as private, i.e., struct Foo {bar: bool} + Private, + /// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool} + PublicCrate, + /// Fields are marked as public, i.e., struct Foo {pub bar: bool} + #[default] + Public, +} + +impl FromStr for FieldVisibilityKind { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "private" => Ok(Self::Private), + "crate" => Ok(Self::PublicCrate), + "public" => Ok(Self::Public), + _ => Err(format!("Invalid visibility kind: `{}`", s)), + } + } +} + +impl std::fmt::Display for FieldVisibilityKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match self { + FieldVisibilityKind::Private => "private", + FieldVisibilityKind::PublicCrate => "crate", + FieldVisibilityKind::Public => "public", + }; + + s.fmt(f) + } +} + /// What kind of accessor should we provide for a field? #[derive(Copy, PartialEq, Eq, Clone, Debug)] -pub enum FieldAccessorKind { +pub(crate) enum FieldAccessorKind { /// No accessor. None, /// Plain accessor. @@ -21,12 +60,9 @@ pub enum FieldAccessorKind { /// Annotations for a given item, or a field. /// -/// You can see the kind of comments that are accepted in the Doxygen -/// documentation: -/// -/// http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html +/// You can see the kind of comments that are accepted in the [Doxygen documentation](https://www.doxygen.nl/manual/docblocks.html). #[derive(Default, Clone, PartialEq, Eq, Debug)] -pub struct Annotations { +pub(crate) struct Annotations { /// Whether this item is marked as opaque. Only applies to types. opaque: bool, /// Whether this item should be hidden from the output. Only applies to @@ -42,11 +78,11 @@ pub struct Annotations { disallow_debug: bool, /// Manually disable deriving/implement default on this type. disallow_default: bool, - /// Whether to add a #[must_use] annotation to this type. + /// Whether to add a `#[must_use]` annotation to this type. must_use_type: bool, - /// Whether fields should be marked as private or not. You can set this on + /// Visibility of struct fields. You can set this on /// structs (it will apply to all the fields), or individual fields. - private_fields: Option, + visibility_kind: Option, /// The kind of accessor this field will have. Also can be applied to /// structs so all the fields inside share it by default. accessor_kind: Option, @@ -80,7 +116,7 @@ fn parse_accessor(s: &str) -> FieldAccessorKind { impl Annotations { /// Construct new annotations for the given cursor and its bindgen comments /// (if any). - pub fn new(cursor: &clang::Cursor) -> Option { + pub(crate) fn new(cursor: &clang::Cursor) -> Option { let mut anno = Annotations::default(); let mut matched_one = false; anno.parse(&cursor.comment(), &mut matched_one); @@ -93,12 +129,12 @@ impl Annotations { } /// Should this type be hidden? - pub fn hide(&self) -> bool { + pub(crate) fn hide(&self) -> bool { self.hide } /// Should this type be opaque? - pub fn opaque(&self) -> bool { + pub(crate) fn opaque(&self) -> bool { self.opaque } @@ -124,42 +160,42 @@ impl Annotations { /// ``` /// /// That is, code for `Foo` is used to generate `Bar`. - pub fn use_instead_of(&self) -> Option<&[String]> { + pub(crate) fn use_instead_of(&self) -> Option<&[String]> { self.use_instead_of.as_deref() } /// The list of derives that have been specified in this annotation. - pub fn derives(&self) -> &[String] { + pub(crate) fn derives(&self) -> &[String] { &self.derives } /// Should we avoid implementing the `Copy` trait? - pub fn disallow_copy(&self) -> bool { + pub(crate) fn disallow_copy(&self) -> bool { self.disallow_copy } /// Should we avoid implementing the `Debug` trait? - pub fn disallow_debug(&self) -> bool { + pub(crate) fn disallow_debug(&self) -> bool { self.disallow_debug } /// Should we avoid implementing the `Default` trait? - pub fn disallow_default(&self) -> bool { + pub(crate) fn disallow_default(&self) -> bool { self.disallow_default } /// Should this type get a `#[must_use]` annotation? - pub fn must_use_type(&self) -> bool { + pub(crate) fn must_use_type(&self) -> bool { self.must_use_type } - /// Should the fields be private? - pub fn private_fields(&self) -> Option { - self.private_fields + /// What kind of accessors should we provide for this type's fields? + pub(crate) fn visibility_kind(&self) -> Option { + self.visibility_kind } /// What kind of accessors should we provide for this type's fields? - pub fn accessor_kind(&self) -> Option { + pub(crate) fn accessor_kind(&self) -> Option { self.accessor_kind } @@ -188,7 +224,11 @@ impl Annotations { } "derive" => self.derives.push(attr.value), "private" => { - self.private_fields = Some(attr.value != "false") + self.visibility_kind = if attr.value != "false" { + Some(FieldVisibilityKind::Private) + } else { + Some(FieldVisibilityKind::Public) + }; } "accessor" => { self.accessor_kind = Some(parse_accessor(&attr.value)) @@ -205,7 +245,7 @@ impl Annotations { } /// Returns whether we've parsed a "constant" attribute. - pub fn constify_enum_variant(&self) -> bool { + pub(crate) fn constify_enum_variant(&self) -> bool { self.constify_enum_variant } } diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index 3eb17aacb9ddc87082ac28ff27e5f20ad18e5ba6..7b6f105a4d7011e9ea9774b10dad335685173731 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -12,7 +12,7 @@ enum Kind { } /// Preprocesses a C/C++ comment so that it is a valid Rust comment. -pub fn preprocess(comment: &str) -> String { +pub(crate) fn preprocess(comment: &str) -> String { match self::kind(comment) { Some(Kind::SingleLines) => preprocess_single_lines(comment), Some(Kind::MultiLine) => preprocess_multi_line(comment), diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 18a4291cf9dba6709dfc53aa371b9067404fe478..628f1d9633c56a44f039a6d381d7acecd1c61610 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1,5 +1,7 @@ //! Compound types (unions and structs) in our intermediate representation. +// use itertools::Itertools; + use super::analysis::Sizedness; use super::annotations::Annotations; use super::context::{BindgenContext, FunctionId, ItemId, TypeId, VarId}; @@ -15,14 +17,13 @@ use crate::ir::derive::CanDeriveCopy; use crate::parse::ParseError; use crate::HashMap; use crate::NonCopyUnionStyle; -use peeking_take_while::PeekableExt; use std::cmp; use std::io; use std::mem; /// The kind of compound type. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum CompKind { +pub(crate) enum CompKind { /// A struct. Struct, /// A union. @@ -31,7 +32,7 @@ pub enum CompKind { /// The kind of C++ method. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum MethodKind { +pub(crate) enum MethodKind { /// A constructor. We represent it as method for convenience, to avoid code /// duplication. Constructor, @@ -55,7 +56,7 @@ pub enum MethodKind { impl MethodKind { /// Is this a destructor method? - pub fn is_destructor(&self) -> bool { + pub(crate) fn is_destructor(&self) -> bool { matches!( *self, MethodKind::Destructor | MethodKind::VirtualDestructor { .. } @@ -63,7 +64,7 @@ impl MethodKind { } /// Is this a pure virtual method? - pub fn is_pure_virtual(&self) -> bool { + pub(crate) fn is_pure_virtual(&self) -> bool { match *self { MethodKind::Virtual { pure_virtual } | MethodKind::VirtualDestructor { pure_virtual } => pure_virtual, @@ -74,7 +75,7 @@ impl MethodKind { /// A struct representing a C++ method, either static, normal, or virtual. #[derive(Debug)] -pub struct Method { +pub(crate) struct Method { kind: MethodKind, /// The signature of the method. Take into account this is not a `Type` /// item, but a `Function` one. @@ -86,7 +87,7 @@ pub struct Method { impl Method { /// Construct a new `Method`. - pub fn new( + pub(crate) fn new( kind: MethodKind, signature: FunctionId, is_const: bool, @@ -99,17 +100,17 @@ impl Method { } /// What kind of method is this? - pub fn kind(&self) -> MethodKind { + pub(crate) fn kind(&self) -> MethodKind { self.kind } /// Is this a constructor? - pub fn is_constructor(&self) -> bool { + pub(crate) fn is_constructor(&self) -> bool { self.kind == MethodKind::Constructor } /// Is this a virtual method? - pub fn is_virtual(&self) -> bool { + pub(crate) fn is_virtual(&self) -> bool { matches!( self.kind, MethodKind::Virtual { .. } | MethodKind::VirtualDestructor { .. } @@ -117,23 +118,23 @@ impl Method { } /// Is this a static method? - pub fn is_static(&self) -> bool { + pub(crate) fn is_static(&self) -> bool { self.kind == MethodKind::Static } - /// Get the id for the `Function` signature for this method. - pub fn signature(&self) -> FunctionId { + /// Get the ID for the `Function` signature for this method. + pub(crate) fn signature(&self) -> FunctionId { self.signature } /// Is this a const qualified method? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } } /// Methods common to the various field types. -pub trait FieldMethods { +pub(crate) trait FieldMethods { /// Get the name of this field. fn name(&self) -> Option<&str>; @@ -146,7 +147,7 @@ pub trait FieldMethods { /// If this is a bitfield, how many bits does it need? fn bitfield_width(&self) -> Option; - /// Is this feild declared public? + /// Is this field declared public? fn is_public(&self) -> bool; /// Get the annotations for this field. @@ -161,7 +162,7 @@ pub trait FieldMethods { /// 2.4.II.1 in the Itanium C++ /// ABI](http://itanium-cxx-abi.github.io/cxx-abi/abi.html#class-types). #[derive(Debug)] -pub struct BitfieldUnit { +pub(crate) struct BitfieldUnit { nth: usize, layout: Layout, bitfields: Vec, @@ -171,24 +172,24 @@ impl BitfieldUnit { /// Get the 1-based index of this bitfield unit within its containing /// struct. Useful for generating a Rust struct's field name for this unit /// of bitfields. - pub fn nth(&self) -> usize { + pub(crate) fn nth(&self) -> usize { self.nth } /// Get the layout within which these bitfields reside. - pub fn layout(&self) -> Layout { + pub(crate) fn layout(&self) -> Layout { self.layout } /// Get the bitfields within this unit. - pub fn bitfields(&self) -> &[Bitfield] { + pub(crate) fn bitfields(&self) -> &[Bitfield] { &self.bitfields } } /// A struct representing a C++ field. #[derive(Debug)] -pub enum Field { +pub(crate) enum Field { /// A normal data member. DataMember(FieldData), @@ -198,7 +199,7 @@ pub enum Field { impl Field { /// Get this field's layout. - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { match *self { Field::Bitfields(BitfieldUnit { layout, .. }) => Some(layout), Field::DataMember(ref data) => { @@ -307,7 +308,7 @@ impl DotAttributes for Bitfield { /// A logical bitfield within some physical bitfield allocation unit. #[derive(Debug)] -pub struct Bitfield { +pub(crate) struct Bitfield { /// Index of the bit within this bitfield's allocation unit where this /// bitfield's bits begin. offset_into_unit: usize, @@ -341,27 +342,12 @@ impl Bitfield { /// Get the index of the bit within this bitfield's allocation unit where /// this bitfield begins. - pub fn offset_into_unit(&self) -> usize { + pub(crate) fn offset_into_unit(&self) -> usize { self.offset_into_unit } - /// Get the mask value that when &'ed with this bitfield's allocation unit - /// produces this bitfield's value. - pub fn mask(&self) -> u64 { - use std::u64; - - let unoffseted_mask = - if self.width() as u64 == mem::size_of::() as u64 * 8 { - u64::MAX - } else { - (1u64 << self.width()) - 1u64 - }; - - unoffseted_mask << self.offset_into_unit() - } - /// Get the bit width of this bitfield. - pub fn width(&self) -> u32 { + pub(crate) fn width(&self) -> u32 { self.data.bitfield_width().unwrap() } @@ -369,7 +355,7 @@ impl Bitfield { /// /// Panics if called before assigning bitfield accessor names or if /// this bitfield have no name. - pub fn getter_name(&self) -> &str { + pub(crate) fn getter_name(&self) -> &str { assert!( self.name().is_some(), "`Bitfield::getter_name` called on anonymous field" @@ -384,7 +370,7 @@ impl Bitfield { /// /// Panics if called before assigning bitfield accessor names or if /// this bitfield have no name. - pub fn setter_name(&self) -> &str { + pub(crate) fn setter_name(&self) -> &str { assert!( self.name().is_some(), "`Bitfield::setter_name` called on anonymous field" @@ -510,7 +496,7 @@ where { let non_bitfields = raw_fields .by_ref() - .peeking_take_while(|f| f.bitfield_width().is_none()) + // .peeking_take_while(|f| f.bitfield_width().is_none()) .map(|f| Field::DataMember(f.0)); fields.extend(non_bitfields); } @@ -520,7 +506,7 @@ where // the Itanium C++ ABI. let mut bitfields = raw_fields .by_ref() - .peeking_take_while(|f| f.bitfield_width().is_some()) + // .peeking_take_while(|f| f.bitfield_width().is_some()) .peekable(); if bitfields.peek().is_none() { @@ -839,6 +825,23 @@ impl CompFields { } } } + + /// Return the flex array member for the struct/class, if any. + fn flex_array_member(&self, ctx: &BindgenContext) -> Option { + let fields = match self { + CompFields::Before(_) => panic!("raw fields"), + CompFields::After { fields, .. } => fields, + CompFields::Error => return None, // panic? + }; + + match fields.last()? { + Field::Bitfields(..) => None, + Field::DataMember(FieldData { ty, .. }) => ctx + .resolve_type(*ty) + .is_incomplete_array(ctx) + .map(|item| item.expect_type_id(ctx)), + } + } } impl Trace for CompFields { @@ -866,7 +869,7 @@ impl Trace for CompFields { /// Common data shared across different field types. #[derive(Clone, Debug)] -pub struct FieldData { +pub(crate) struct FieldData { /// The name of the field, empty if it's an unnamed bitfield width. name: Option, @@ -921,7 +924,7 @@ impl FieldMethods for FieldData { /// The kind of inheritance a base class is using. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum BaseKind { +pub(crate) enum BaseKind { /// Normal inheritance, like: /// /// ```cpp @@ -938,25 +941,25 @@ pub enum BaseKind { /// A base class. #[derive(Clone, Debug)] -pub struct Base { +pub(crate) struct Base { /// The type of this base class. - pub ty: TypeId, + pub(crate) ty: TypeId, /// The kind of inheritance we're doing. - pub kind: BaseKind, + pub(crate) kind: BaseKind, /// Name of the field in which this base should be stored. - pub field_name: String, - /// Whether this base is inherited from publically. - pub is_pub: bool, + pub(crate) field_name: String, + /// Whether this base is inherited from publicly. + pub(crate) is_pub: bool, } impl Base { /// Whether this base class is inheriting virtually. - pub fn is_virtual(&self) -> bool { + pub(crate) fn is_virtual(&self) -> bool { self.kind == BaseKind::Virtual } /// Whether this base class should have it's own field for storage. - pub fn requires_storage(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn requires_storage(&self, ctx: &BindgenContext) -> bool { // Virtual bases are already taken into account by the vtable // pointer. // @@ -975,8 +978,8 @@ impl Base { true } - /// Whether this base is inherited from publically. - pub fn is_public(&self) -> bool { + /// Whether this base is inherited from publicly. + pub(crate) fn is_public(&self) -> bool { self.is_pub } } @@ -987,7 +990,7 @@ impl Base { /// of fields which also are associated with their own (potentially compound) /// type. #[derive(Debug)] -pub struct CompInfo { +pub(crate) struct CompInfo { /// Whether this is a struct or a union. kind: CompKind, @@ -1067,7 +1070,7 @@ pub struct CompInfo { impl CompInfo { /// Construct a new compound type. - pub fn new(kind: CompKind) -> Self { + pub(crate) fn new(kind: CompKind) -> Self { CompInfo { kind, fields: CompFields::default(), @@ -1097,7 +1100,7 @@ impl CompInfo { /// If we're a union without known layout, we try to compute it from our /// members. This is not ideal, but clang fails to report the size for these /// kind of unions, see test/headers/template_union.hpp - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { // We can't do better than clang here, sorry. if self.kind == CompKind::Struct { return None; @@ -1126,7 +1129,7 @@ impl CompInfo { } /// Get this type's set of fields. - pub fn fields(&self) -> &[Field] { + pub(crate) fn fields(&self) -> &[Field] { match self.fields { CompFields::Error => &[], CompFields::After { ref fields, .. } => fields, @@ -1136,6 +1139,14 @@ impl CompInfo { } } + /// Return the flex array member and its element type if any + pub(crate) fn flex_array_member( + &self, + ctx: &BindgenContext, + ) -> Option { + self.fields.flex_array_member(ctx) + } + fn has_fields(&self) -> bool { match self.fields { CompFields::Error => false, @@ -1184,7 +1195,7 @@ impl CompInfo { /// Returns whether we have a too large bitfield unit, in which case we may /// not be able to derive some of the things we should be able to normally /// derive. - pub fn has_too_large_bitfield_unit(&self) -> bool { + pub(crate) fn has_too_large_bitfield_unit(&self) -> bool { if !self.has_bitfields() { return false; } @@ -1198,53 +1209,53 @@ impl CompInfo { /// Does this type have any template parameters that aren't types /// (e.g. int)? - pub fn has_non_type_template_params(&self) -> bool { + pub(crate) fn has_non_type_template_params(&self) -> bool { self.has_non_type_template_params } /// Do we see a virtual function during parsing? /// Get the has_own_virtual_method boolean. - pub fn has_own_virtual_method(&self) -> bool { + pub(crate) fn has_own_virtual_method(&self) -> bool { self.has_own_virtual_method } /// Did we see a destructor when parsing this type? - pub fn has_own_destructor(&self) -> bool { + pub(crate) fn has_own_destructor(&self) -> bool { self.has_destructor } /// Get this type's set of methods. - pub fn methods(&self) -> &[Method] { + pub(crate) fn methods(&self) -> &[Method] { &self.methods } /// Get this type's set of constructors. - pub fn constructors(&self) -> &[FunctionId] { + pub(crate) fn constructors(&self) -> &[FunctionId] { &self.constructors } /// Get this type's destructor. - pub fn destructor(&self) -> Option<(MethodKind, FunctionId)> { + pub(crate) fn destructor(&self) -> Option<(MethodKind, FunctionId)> { self.destructor } /// What kind of compound type is this? - pub fn kind(&self) -> CompKind { + pub(crate) fn kind(&self) -> CompKind { self.kind } /// Is this a union? - pub fn is_union(&self) -> bool { + pub(crate) fn is_union(&self) -> bool { self.kind() == CompKind::Union } /// The set of types that this one inherits from. - pub fn base_members(&self) -> &[Base] { + pub(crate) fn base_members(&self) -> &[Base] { &self.base_members } /// Construct a new compound type from a Clang type. - pub fn from_ty( + pub(crate) fn from_ty( potential_id: ItemId, ty: &clang::Type, location: Option, @@ -1438,7 +1449,7 @@ impl CompInfo { } CXCursor_TemplateTypeParameter => { let param = Item::type_param(None, cur, ctx).expect( - "Item::type_param should't fail when pointing \ + "Item::type_param shouldn't fail when pointing \ at a TemplateTypeParameter", ); ci.template_params.push(param); @@ -1611,23 +1622,23 @@ impl CompInfo { /// Get the set of types that were declared within this compound type /// (e.g. nested class definitions). - pub fn inner_types(&self) -> &[TypeId] { + pub(crate) fn inner_types(&self) -> &[TypeId] { &self.inner_types } /// Get the set of static variables declared within this compound type. - pub fn inner_vars(&self) -> &[VarId] { + pub(crate) fn inner_vars(&self) -> &[VarId] { &self.inner_vars } /// Have we found a field with an opaque type that could potentially mess up /// the layout of this compound type? - pub fn found_unknown_attr(&self) -> bool { + pub(crate) fn found_unknown_attr(&self) -> bool { self.found_unknown_attr } /// Is this compound type packed? - pub fn is_packed( + pub(crate) fn is_packed( &self, ctx: &BindgenContext, layout: Option<&Layout>, @@ -1656,13 +1667,33 @@ impl CompInfo { false } + /// Return true if a compound type is "naturally packed". This means we can exclude the + /// "packed" attribute without changing the layout. + /// This is useful for types that need an "align(N)" attribute since rustc won't compile + /// structs that have both of those attributes. + pub(crate) fn already_packed(&self, ctx: &BindgenContext) -> Option { + let mut total_size: usize = 0; + + for field in self.fields().iter() { + let layout = field.layout(ctx)?; + + if layout.align != 0 && total_size % layout.align != 0 { + return Some(false); + } + + total_size += layout.size; + } + + Some(true) + } + /// Returns true if compound type has been forward declared - pub fn is_forward_declaration(&self) -> bool { + pub(crate) fn is_forward_declaration(&self) -> bool { self.is_forward_declaration } /// Compute this compound structure's bitfield allocation units. - pub fn compute_bitfield_units( + pub(crate) fn compute_bitfield_units( &mut self, ctx: &BindgenContext, layout: Option<&Layout>, @@ -1672,7 +1703,7 @@ impl CompInfo { } /// Assign for each anonymous field a generated name. - pub fn deanonymize_fields(&mut self, ctx: &BindgenContext) { + pub(crate) fn deanonymize_fields(&mut self, ctx: &BindgenContext) { self.fields.deanonymize_fields(ctx, &self.methods); } @@ -1685,7 +1716,7 @@ impl CompInfo { /// /// Second boolean returns whether all fields can be copied (and thus /// ManuallyDrop is not needed). - pub fn is_rust_union( + pub(crate) fn is_rust_union( &self, ctx: &BindgenContext, layout: Option<&Layout>, @@ -1695,7 +1726,7 @@ impl CompInfo { return (false, false); } - if !ctx.options().rust_features().untagged_union { + if !ctx.options().untagged_union { return (false, false); } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index b693a7047e015d3c4597f2e6dc15c9c6abba63ea..ebf325aa166663e12818ce41d389ad979980f65a 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -19,28 +19,30 @@ use super::module::{Module, ModuleKind}; use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; -use crate::clang::{self, Cursor}; +use crate::clang::{self, ABIKind, Cursor}; use crate::codegen::CodegenError; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; -use cexpr; -use clang_sys; + use proc_macro2::{Ident, Span, TokenStream}; use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; -use std::iter::IntoIterator; +use std::fs::OpenOptions; +use std::io::Write; use std::mem; +use std::path::Path; /// An identifier for some kind of IR item. #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] -pub struct ItemId(usize); +pub(crate) struct ItemId(usize); +/// Declare a newtype around `ItemId` with conversion methods. macro_rules! item_id_newtype { ( $( #[$attr:meta] )* - pub struct $name:ident(ItemId) + pub(crate) struct $name:ident(ItemId) where $( #[$checked_attr:meta] )* checked = $checked:ident with $check_method:ident, @@ -51,11 +53,12 @@ macro_rules! item_id_newtype { ) => { $( #[$attr] )* #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] - pub struct $name(ItemId); + pub(crate) struct $name(ItemId); impl $name { - /// Create an `ItemResolver` from this id. - pub fn into_resolver(self) -> ItemResolver { + /// Create an `ItemResolver` from this ID. + #[allow(dead_code)] + pub(crate) fn into_resolver(self) -> ItemResolver { let id: ItemId = self.into(); id.into() } @@ -83,9 +86,10 @@ macro_rules! item_id_newtype { } } + #[allow(dead_code)] impl ItemId { $( #[$checked_attr] )* - pub fn $checked(&self, ctx: &BindgenContext) -> Option<$name> { + pub(crate) fn $checked(&self, ctx: &BindgenContext) -> Option<$name> { if ctx.resolve_item(*self).kind().$check_method() { Some($name(*self)) } else { @@ -94,7 +98,7 @@ macro_rules! item_id_newtype { } $( #[$expected_attr] )* - pub fn $expected(&self, ctx: &BindgenContext) -> $name { + pub(crate) fn $expected(&self, ctx: &BindgenContext) -> $name { self.$checked(ctx) .expect(concat!( stringify!($expected), @@ -103,7 +107,7 @@ macro_rules! item_id_newtype { } $( #[$unchecked_attr] )* - pub fn $unchecked(&self) -> $name { + pub(crate) fn $unchecked(&self) -> $name { $name(*self) } } @@ -113,7 +117,7 @@ macro_rules! item_id_newtype { item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Type`. - pub struct TypeId(ItemId) + pub(crate) struct TypeId(ItemId) where /// Convert this `ItemId` into a `TypeId` if its associated item is a type, /// otherwise return `None`. @@ -125,14 +129,14 @@ item_id_newtype! { expected = expect_type_id, /// Convert this `ItemId` into a `TypeId` without actually checking whether - /// this id actually points to a `Type`. + /// this ID actually points to a `Type`. unchecked = as_type_id_unchecked; } item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Module`. - pub struct ModuleId(ItemId) + pub(crate) struct ModuleId(ItemId) where /// Convert this `ItemId` into a `ModuleId` if its associated item is a /// module, otherwise return `None`. @@ -144,14 +148,14 @@ item_id_newtype! { expected = expect_module_id, /// Convert this `ItemId` into a `ModuleId` without actually checking - /// whether this id actually points to a `Module`. + /// whether this ID actually points to a `Module`. unchecked = as_module_id_unchecked; } item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Var`. - pub struct VarId(ItemId) + pub(crate) struct VarId(ItemId) where /// Convert this `ItemId` into a `VarId` if its associated item is a var, /// otherwise return `None`. @@ -163,14 +167,14 @@ item_id_newtype! { expected = expect_var_id, /// Convert this `ItemId` into a `VarId` without actually checking whether - /// this id actually points to a `Var`. + /// this ID actually points to a `Var`. unchecked = as_var_id_unchecked; } item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Function`. - pub struct FunctionId(ItemId) + pub(crate) struct FunctionId(ItemId) where /// Convert this `ItemId` into a `FunctionId` if its associated item is a function, /// otherwise return `None`. @@ -182,7 +186,7 @@ item_id_newtype! { expected = expect_function_id, /// Convert this `ItemId` into a `FunctionId` without actually checking whether - /// this id actually points to a `Function`. + /// this ID actually points to a `Function`. unchecked = as_function_id_unchecked; } @@ -193,8 +197,8 @@ impl From for usize { } impl ItemId { - /// Get a numeric representation of this id. - pub fn as_usize(&self) -> usize { + /// Get a numeric representation of this ID. + pub(crate) fn as_usize(&self) -> usize { (*self).into() } } @@ -305,7 +309,7 @@ enum TypeKey { /// A context used during parsing and generation of structs. #[derive(Debug)] -pub struct BindgenContext { +pub(crate) struct BindgenContext { /// The map of all the items parsed so far, keyed off ItemId. items: Vec>, @@ -313,7 +317,7 @@ pub struct BindgenContext { /// item ids during parsing. types: HashMap, - /// Maps from a cursor to the item id of the named template type parameter + /// Maps from a cursor to the item ID of the named template type parameter /// for that cursor. type_params: HashMap, @@ -326,7 +330,7 @@ pub struct BindgenContext { /// Current module being traversed. current_module: ModuleId, - /// A HashMap keyed on a type definition, and whose value is the parent id + /// A HashMap keyed on a type definition, and whose value is the parent ID /// of the declaration. /// /// This is used to handle the cases where the semantic and the lexical @@ -354,8 +358,16 @@ pub struct BindgenContext { /// This needs to be an std::HashMap because the cexpr API requires it. parsed_macros: StdHashMap, cexpr::expr::EvalResult>, + /// A map with all include locations. + /// + /// This is needed so that items are created in the order they are defined in. + /// + /// The key is the included file, the value is a pair of the source file and + /// the position of the `#include` directive in the source file. + includes: StdHashMap, + /// A set of all the included filenames. - deps: BTreeSet, + deps: BTreeSet>, /// The active replacements collected from replaces="xxx" annotations. replacements: HashMap, ItemId>, @@ -367,6 +379,9 @@ pub struct BindgenContext { /// The translation unit for parsing. translation_unit: clang::TranslationUnit, + /// The translation unit for macro fallback parsing. + fallback_tu: Option, + /// Target information that can be useful for some stuff. target_info: clang::TargetInfo, @@ -376,6 +391,9 @@ pub struct BindgenContext { /// Whether a bindgen complex was generated generated_bindgen_complex: Cell, + /// Whether a bindgen float16 was generated + generated_bindgen_float16: Cell, + /// The set of `ItemId`s that are allowlisted. This the very first thing /// computed after parsing our IR, and before running any of our analyses. allowlisted: Option, @@ -390,7 +408,7 @@ pub struct BindgenContext { /// It's computed right after computing the allowlisted items. codegen_items: Option, - /// Map from an item's id to the set of template parameter items that it + /// Map from an item's ID to the set of template parameter items that it /// uses. See `ir::named` for more details. Always `Some` during the codegen /// phase. used_template_parameters: Option>, @@ -475,9 +493,6 @@ pub struct BindgenContext { /// Populated when we enter codegen by `compute_has_float`; always `None` /// before that and `Some` after. has_float: Option>, - - /// The set of warnings raised during binding generation. - warnings: Vec, } /// A traversal of allowlisted items. @@ -504,7 +519,7 @@ impl<'ctx> Iterator for AllowlistedItemsTraversal<'ctx> { impl<'ctx> AllowlistedItemsTraversal<'ctx> { /// Construct a new allowlisted items traversal. - pub fn new( + pub(crate) fn new( ctx: &'ctx BindgenContext, roots: R, predicate: for<'a> fn(&'a BindgenContext, Edge) -> bool, @@ -561,6 +576,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" BindgenContext { items: vec![Some(root_module)], + includes: Default::default(), deps, types: Default::default(), type_params: Default::default(), @@ -574,9 +590,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" collected_typerefs: false, in_codegen: false, translation_unit, + fallback_tu: None, target_info, options, generated_bindgen_complex: Cell::new(false), + generated_bindgen_float16: Cell::new(false), allowlisted: None, blocklisted_types_implement_traits: Default::default(), codegen_items: None, @@ -593,59 +611,80 @@ If you encounter an error missing from this list, please file an issue or a PR!" have_destructor: None, has_type_param_in_array: None, has_float: None, - warnings: Vec::new(), } } /// Returns `true` if the target architecture is wasm32 - pub fn is_target_wasm32(&self) -> bool { + pub(crate) fn is_target_wasm32(&self) -> bool { self.target_info.triple.starts_with("wasm32-") } /// Creates a timer for the current bindgen phase. If time_phases is `true`, /// the timer will print to stderr when it is dropped, otherwise it will do /// nothing. - pub fn timer<'a>(&self, name: &'a str) -> Timer<'a> { + pub(crate) fn timer<'a>(&self, name: &'a str) -> Timer<'a> { Timer::new(name).with_output(self.options.time_phases) } /// Returns the pointer width to use for the target for the current /// translation. - pub fn target_pointer_size(&self) -> usize { + pub(crate) fn target_pointer_size(&self) -> usize { self.target_info.pointer_width / 8 } + /// Returns the ABI, which is mostly useful for determining the mangling kind. + pub(crate) fn abi_kind(&self) -> ABIKind { + self.target_info.abi + } + /// Get the stack of partially parsed types that we are in the middle of /// parsing. - pub fn currently_parsed_types(&self) -> &[PartialType] { + pub(crate) fn currently_parsed_types(&self) -> &[PartialType] { &self.currently_parsed_types[..] } /// Begin parsing the given partial type, and push it onto the /// `currently_parsed_types` stack so that we won't infinite recurse if we /// run into a reference to it while parsing it. - pub fn begin_parsing(&mut self, partial_ty: PartialType) { + pub(crate) fn begin_parsing(&mut self, partial_ty: PartialType) { self.currently_parsed_types.push(partial_ty); } /// Finish parsing the current partial type, pop it off the /// `currently_parsed_types` stack, and return it. - pub fn finish_parsing(&mut self) -> PartialType { + pub(crate) fn finish_parsing(&mut self) -> PartialType { self.currently_parsed_types.pop().expect( "should have been parsing a type, if we finished parsing a type", ) } - /// Add another path to the set of included files. - pub fn include_file(&mut self, filename: String) { - for cb in &self.options().parse_callbacks { - cb.include_file(&filename); - } - self.deps.insert(filename); + /// Add the location of the `#include` directive for the `included_file`. + pub(crate) fn add_include( + &mut self, + source_file: String, + included_file: String, + offset: usize, + ) { + self.includes + .entry(included_file) + .or_insert((source_file, offset)); + } + + /// Get the location of the first `#include` directive for the `included_file`. + pub(crate) fn included_file_location( + &self, + included_file: &str, + ) -> Option<(String, usize)> { + self.includes.get(included_file).cloned() + } + + /// Add an included file. + pub(crate) fn add_dep(&mut self, dep: Box) { + self.deps.insert(dep); } /// Get any included files. - pub fn deps(&self) -> &BTreeSet { + pub(crate) fn deps(&self) -> &BTreeSet> { &self.deps } @@ -653,7 +692,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// This inserts it into the internal items set, and its type into the /// internal types set. - pub fn add_item( + pub(crate) fn add_item( &mut self, item: Item, declaration: Option, @@ -778,7 +817,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Add a new named template type parameter to this context's item set. - pub fn add_type_param(&mut self, item: Item, definition: clang::Cursor) { + pub(crate) fn add_type_param( + &mut self, + item: Item, + definition: clang::Cursor, + ) { debug!( "BindgenContext::add_type_param: item = {:?}; definition = {:?}", item, definition @@ -813,7 +856,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get the named type defined at the given cursor location, if we've /// already added one. - pub fn get_type_param(&self, definition: &clang::Cursor) -> Option { + pub(crate) fn get_type_param( + &self, + definition: &clang::Cursor, + ) -> Option { assert_eq!( definition.kind(), clang_sys::CXCursor_TemplateTypeParameter @@ -825,7 +871,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Mangles a name so it doesn't conflict with any keyword. #[rustfmt::skip] - pub fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { + pub(crate) fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { if name.contains('@') || name.contains('?') || name.contains('$') || @@ -856,7 +902,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a mangled name as a rust identifier. - pub fn rust_ident(&self, name: S) -> Ident + pub(crate) fn rust_ident(&self, name: S) -> Ident where S: AsRef, { @@ -864,7 +910,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a mangled name as a rust identifier. - pub fn rust_ident_raw(&self, name: T) -> Ident + pub(crate) fn rust_ident_raw(&self, name: T) -> Ident where T: AsRef, { @@ -872,7 +918,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Iterate over all items that have been defined. - pub fn items(&self) -> impl Iterator { + pub(crate) fn items(&self) -> impl Iterator { self.items.iter().enumerate().filter_map(|(index, item)| { let item = item.as_ref()?; Some((ItemId(index), item)) @@ -880,7 +926,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Have we collected all unresolved type references yet? - pub fn collected_typerefs(&self) -> bool { + pub(crate) fn collected_typerefs(&self) -> bool { self.collected_typerefs } @@ -1077,7 +1123,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Relocate the replacement item from where it was declared, to // where the thing it is replacing was declared. // - // First, we'll make sure that its parent id is correct. + // First, we'll make sure that its parent ID is correct. let old_parent = self.resolve_item(replacement_id).parent_id(); if new_parent == old_parent { @@ -1147,7 +1193,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" pub(crate) fn gen( mut self, cb: F, - ) -> Result<(Out, BindgenOptions, Vec), CodegenError> + ) -> Result<(Out, BindgenOptions), CodegenError> where F: FnOnce(&Self) -> Result, { @@ -1185,14 +1231,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.compute_cannot_derive_partialord_partialeq_or_eq(); let ret = cb(&self)?; - Ok((ret, self.options, self.warnings)) + Ok((ret, self.options)) } - /// When the `testing_only_extra_assertions` feature is enabled, this + /// When the `__testing_only_extra_assertions` feature is enabled, this /// function walks the IR graph and asserts that we do not have any edges /// referencing an ItemId for which we do not have an associated IR item. fn assert_no_dangling_references(&self) { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { for _ in self.assert_no_dangling_item_traversal() { // The iterator's next method does the asserting for us. } @@ -1213,11 +1259,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) } - /// When the `testing_only_extra_assertions` feature is enabled, walk over + /// When the `__testing_only_extra_assertions` feature is enabled, walk over /// every item and ensure that it is in the children set of one of its /// module ancestors. fn assert_every_item_in_a_module(&self) { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); @@ -1263,8 +1309,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.sizedness = Some(analyze::(self)); } - /// Look up whether the type with the given id is sized or not. - pub fn lookup_sizedness(&self, id: TypeId) -> SizednessResult { + /// Look up whether the type with the given ID is sized or not. + pub(crate) fn lookup_sizedness(&self, id: TypeId) -> SizednessResult { assert!( self.in_codegen_phase(), "We only compute sizedness after we've entered codegen" @@ -1286,7 +1332,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has vtable or not. - pub fn lookup_has_vtable(&self, id: TypeId) -> HasVtableResult { + pub(crate) fn lookup_has_vtable(&self, id: TypeId) -> HasVtableResult { assert!( self.in_codegen_phase(), "We only compute vtables when we enter codegen" @@ -1310,7 +1356,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has a destructor. - pub fn lookup_has_destructor(&self, id: TypeId) -> bool { + pub(crate) fn lookup_has_destructor(&self, id: TypeId) -> bool { assert!( self.in_codegen_phase(), "We only compute destructors when we enter codegen" @@ -1354,7 +1400,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// manually provide a definition for them. To give them the most /// flexibility when doing that, we assume that they use every template /// parameter and always pass template arguments through in instantiations. - pub fn uses_template_parameter( + pub(crate) fn uses_template_parameter( &self, item: ItemId, template_param: TypeId, @@ -1386,7 +1432,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// `false` otherwise. /// /// Has the same restrictions that `uses_template_parameter` has. - pub fn uses_any_template_parameters(&self, item: ItemId) -> bool { + pub(crate) fn uses_any_template_parameters(&self, item: ItemId) -> bool { assert!( self.in_codegen_phase(), "We only compute template parameter usage as we enter codegen" @@ -1424,38 +1470,38 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the root module. - pub fn root_module(&self) -> ModuleId { + pub(crate) fn root_module(&self) -> ModuleId { self.root_module } - /// Resolve a type with the given id. + /// Resolve a type with the given ID. /// /// Panics if there is no item for the given `TypeId` or if the resolved /// item is not a `Type`. - pub fn resolve_type(&self, type_id: TypeId) -> &Type { + pub(crate) fn resolve_type(&self, type_id: TypeId) -> &Type { self.resolve_item(type_id).kind().expect_type() } - /// Resolve a function with the given id. + /// Resolve a function with the given ID. /// /// Panics if there is no item for the given `FunctionId` or if the resolved /// item is not a `Function`. - pub fn resolve_func(&self, func_id: FunctionId) -> &Function { + pub(crate) fn resolve_func(&self, func_id: FunctionId) -> &Function { self.resolve_item(func_id).kind().expect_function() } /// Resolve the given `ItemId` as a type, or `None` if there is no item with - /// the given id. + /// the given ID. /// - /// Panics if the id resolves to an item that is not a type. - pub fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> { + /// Panics if the ID resolves to an item that is not a type. + pub(crate) fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> { self.resolve_item_fallible(type_id) .map(|t| t.kind().expect_type()) } /// Resolve the given `ItemId` into an `Item`, or `None` if no such item /// exists. - pub fn resolve_item_fallible>( + pub(crate) fn resolve_item_fallible>( &self, id: Id, ) -> Option<&Item> { @@ -1464,8 +1510,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Resolve the given `ItemId` into an `Item`. /// - /// Panics if the given id does not resolve to any item. - pub fn resolve_item>(&self, item_id: Id) -> &Item { + /// Panics if the given ID does not resolve to any item. + pub(crate) fn resolve_item>(&self, item_id: Id) -> &Item { let item_id = item_id.into(); match self.resolve_item_fallible(item_id) { Some(item) => item, @@ -1474,7 +1520,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the current module. - pub fn current_module(&self) -> ModuleId { + pub(crate) fn current_module(&self) -> ModuleId { self.current_module } @@ -1486,7 +1532,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// TODO(emilio): We could consider doing this only when /// declaration.lexical_parent() != definition.lexical_parent(), but it's /// not sure it's worth it. - pub fn add_semantic_parent( + pub(crate) fn add_semantic_parent( &mut self, definition: clang::Cursor, parent_id: ItemId, @@ -1495,7 +1541,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a known semantic parent for a given definition. - pub fn known_semantic_parent( + pub(crate) fn known_semantic_parent( &self, definition: clang::Cursor, ) -> Option { @@ -1649,7 +1695,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" clang_sys::CXCursor_TypeRef | clang_sys::CXCursor_TypedefDecl | clang_sys::CXCursor_TypeAliasDecl => { - // The `with_id` id will potentially end up unused if we give up + // The `with_id` ID will potentially end up unused if we give up // on this type (for example, because it has const value // template args), so if we pass `with_id` as the parent, it is // potentially a dangling reference. Instead, use the canonical @@ -1808,7 +1854,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// If we have already resolved the type for the given type declaration, /// return its `ItemId`. Otherwise, return `None`. - pub fn get_resolved_type( + pub(crate) fn get_resolved_type( &self, decl: &clang::CanonicalTypeDeclaration, ) -> Option { @@ -1824,7 +1870,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Looks up for an already resolved type, either because it's builtin, or /// because we already have it in the map. - pub fn builtin_or_resolved_ty( + pub(crate) fn builtin_or_resolved_ty( &mut self, with_id: ItemId, parent_id: Option, @@ -1894,7 +1940,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// We should probably make the constness tracking separate, so it doesn't /// bloat that much, but hey, we already bloat the heck out of builtin /// types. - pub fn build_ty_wrapper( + pub(crate) fn build_ty_wrapper( &mut self, with_id: ItemId, wrapped_id: TypeId, @@ -1907,7 +1953,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// A wrapper over a type that adds a const qualifier explicitly. /// /// Needed to handle const methods in C++, wrapping the type . - pub fn build_const_wrapper( + pub(crate) fn build_const_wrapper( &mut self, with_id: ItemId, wrapped_id: TypeId, @@ -1944,8 +1990,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" with_id.as_type_id_unchecked() } - /// Returns the next item id to be used for an item. - pub fn next_item_id(&mut self) -> ItemId { + /// Returns the next item ID to be used for an item. + pub(crate) fn next_item_id(&mut self) -> ItemId { let ret = ItemId(self.items.len()); self.items.push(None); ret @@ -1974,6 +2020,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" CXType_ULongLong => TypeKind::Int(IntKind::ULongLong), CXType_Int128 => TypeKind::Int(IntKind::I128), CXType_UInt128 => TypeKind::Int(IntKind::U128), + CXType_Float16 | CXType_Half => TypeKind::Float(FloatKind::Float16), CXType_Float => TypeKind::Float(FloatKind::Float), CXType_Double => TypeKind::Float(FloatKind::Double), CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), @@ -1982,6 +2029,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let float_type = ty.elem_type().expect("Not able to resolve complex type?"); let float_kind = match float_type.kind() { + CXType_Float16 | CXType_Half => FloatKind::Float16, CXType_Float => FloatKind::Float, CXType_Double => FloatKind::Double, CXType_LongDouble => FloatKind::LongDouble, @@ -2015,17 +2063,124 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the current Clang translation unit that is being processed. - pub fn translation_unit(&self) -> &clang::TranslationUnit { + pub(crate) fn translation_unit(&self) -> &clang::TranslationUnit { &self.translation_unit } + /// Initialize fallback translation unit if it does not exist and + /// then return a mutable reference to the fallback translation unit. + pub(crate) fn try_ensure_fallback_translation_unit( + &mut self, + ) -> Option<&mut clang::FallbackTranslationUnit> { + if self.fallback_tu.is_none() { + let file = format!( + "{}/.macro_eval.c", + match self.options().clang_macro_fallback_build_dir { + Some(ref path) => path.as_os_str().to_str()?, + None => ".", + } + ); + + let index = clang::Index::new(false, false); + + let mut header_names_to_compile = Vec::new(); + let mut header_paths = Vec::new(); + let mut header_contents = String::new(); + for input_header in self.options.input_headers.iter() { + let path = Path::new(input_header.as_ref()); + if let Some(header_path) = path.parent() { + if header_path == Path::new("") { + header_paths.push("."); + } else { + header_paths.push(header_path.as_os_str().to_str()?); + } + } else { + header_paths.push("."); + } + let header_name = path.file_name()?.to_str()?; + header_names_to_compile + .push(header_name.split(".h").next()?.to_string()); + header_contents += + format!("\n#include <{header_name}>").as_str(); + } + let header_to_precompile = format!( + "{}/{}", + match self.options().clang_macro_fallback_build_dir { + Some(ref path) => path.as_os_str().to_str()?, + None => ".", + }, + header_names_to_compile.join("-") + "-precompile.h" + ); + let pch = header_to_precompile.clone() + ".pch"; + + let mut header_to_precompile_file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open(&header_to_precompile) + .ok()?; + header_to_precompile_file + .write_all(header_contents.as_bytes()) + .ok()?; + + let mut c_args = Vec::new(); + c_args.push("-x".to_string().into_boxed_str()); + c_args.push("c-header".to_string().into_boxed_str()); + for header_path in header_paths { + c_args.push(format!("-I{header_path}").into_boxed_str()); + } + c_args.extend( + self.options + .clang_args + .iter() + .filter(|next| { + !self.options.input_headers.contains(next) && + next.as_ref() != "-include" + }) + .cloned(), + ); + let mut tu = clang::TranslationUnit::parse( + &index, + &header_to_precompile, + &c_args, + &[], + clang_sys::CXTranslationUnit_ForSerialization, + )?; + tu.save(&pch).ok()?; + + let mut c_args = vec![ + "-include-pch".to_string().into_boxed_str(), + pch.clone().into_boxed_str(), + ]; + c_args.extend( + self.options + .clang_args + .clone() + .iter() + .filter(|next| { + !self.options.input_headers.contains(next) && + next.as_ref() != "-include" + }) + .cloned(), + ); + self.fallback_tu = Some(clang::FallbackTranslationUnit::new( + file, + header_to_precompile, + pch, + &c_args, + )?); + } + + self.fallback_tu.as_mut() + } + /// Have we parsed the macro named `macro_name` already? - pub fn parsed_macro(&self, macro_name: &[u8]) -> bool { + pub(crate) fn parsed_macro(&self, macro_name: &[u8]) -> bool { self.parsed_macros.contains_key(macro_name) } /// Get the currently parsed macros. - pub fn parsed_macros( + pub(crate) fn parsed_macros( &self, ) -> &StdHashMap, cexpr::expr::EvalResult> { debug_assert!(!self.in_codegen_phase()); @@ -2033,7 +2188,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Mark the macro named `macro_name` as parsed. - pub fn note_parsed_macro( + pub(crate) fn note_parsed_macro( &mut self, id: Vec, value: cexpr::expr::EvalResult, @@ -2042,16 +2197,16 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Are we in the codegen phase? - pub fn in_codegen_phase(&self) -> bool { + pub(crate) fn in_codegen_phase(&self) -> bool { self.in_codegen } - /// Mark the type with the given `name` as replaced by the type with id + /// Mark the type with the given `name` as replaced by the type with ID /// `potential_ty`. /// /// Replacement types are declared using the `replaces="xxx"` annotation, /// and implies that the original type is hidden. - pub fn replace(&mut self, name: &[String], potential_ty: ItemId) { + pub(crate) fn replace(&mut self, name: &[String], potential_ty: ItemId) { match self.replacements.entry(name.into()) { Entry::Vacant(entry) => { debug!( @@ -2074,7 +2229,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Has the item with the given `name` and `id` been replaced by another /// type? - pub fn is_replaced_type>( + pub(crate) fn is_replaced_type>( &self, path: &[String], id: Id, @@ -2084,7 +2239,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Is the type with the given `name` marked as opaque? - pub fn opaque_by_name(&self, path: &[String]) -> bool { + pub(crate) fn opaque_by_name(&self, path: &[String]) -> bool { debug_assert!( self.in_codegen_phase(), "You're not supposed to call this yet" @@ -2176,9 +2331,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" (module_name, kind) } - /// Given a CXCursor_Namespace cursor, return the item id of the + /// Given a CXCursor_Namespace cursor, return the item ID of the /// corresponding module, or create one on the fly. - pub fn module(&mut self, cursor: clang::Cursor) -> ModuleId { + pub(crate) fn module(&mut self, cursor: clang::Cursor) -> ModuleId { use clang_sys::*; assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person"); let cursor = cursor.canonical(); @@ -2209,7 +2364,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Start traversing the module with the given `module_id`, invoke the /// callback `cb`, and then return to traversing the original module. - pub fn with_module(&mut self, module_id: ModuleId, cb: F) + pub(crate) fn with_module(&mut self, module_id: ModuleId, cb: F) where F: FnOnce(&mut Self), { @@ -2227,7 +2382,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// If no items are explicitly allowlisted, then all items are considered /// allowlisted. - pub fn allowlisted_items(&self) -> &ItemSet { + pub(crate) fn allowlisted_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); @@ -2236,7 +2391,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Check whether a particular blocklisted type implements a trait or not. /// Results may be cached. - pub fn blocklisted_type_implements_trait( + pub(crate) fn blocklisted_type_implements_trait( &self, item: &Item, derive_trait: DeriveTrait, @@ -2277,7 +2432,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Is the given type a type from that corresponds to a Rust primitive type? - pub fn is_stdint_type(&self, name: &str) -> bool { + pub(crate) fn is_stdint_type(&self, name: &str) -> bool { match name { "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" | "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" | @@ -2288,7 +2443,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get a reference to the set of items we should generate. - pub fn codegen_items(&self) -> &ItemSet { + pub(crate) fn codegen_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); self.codegen_items.as_ref().unwrap() @@ -2312,7 +2467,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" if self.options().allowlisted_types.is_empty() && self.options().allowlisted_functions.is_empty() && self.options().allowlisted_vars.is_empty() && - self.options().allowlisted_files.is_empty() + self.options().allowlisted_files.is_empty() && + self.options().allowlisted_items.is_empty() { return true; } @@ -2342,6 +2498,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" let name = item.path_for_allowlisting(self)[1..].join("::"); debug!("allowlisted_items: testing {:?}", name); + + if self.options().allowlisted_items.matches(&name) { + return true; + } + match *item.kind() { ItemKind::Module(..) => true, ItemKind::Function(_) => { @@ -2407,7 +2568,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); let name = prefix_path[1..].join("::"); prefix_path.pop().unwrap(); - self.options().allowlisted_vars.matches(name) + self.options().allowlisted_vars.matches(&name) + || self + .options() + .allowlisted_items + .matches(name) }) } } @@ -2454,30 +2619,26 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.allowlisted = Some(allowlisted); self.codegen_items = Some(codegen_items); - let mut warnings = Vec::new(); - for item in self.options().allowlisted_functions.unmatched_items() { - warnings - .push(format!("unused option: --allowlist-function {}", item)); + unused_regex_diagnostic(item, "--allowlist-function", self); } for item in self.options().allowlisted_vars.unmatched_items() { - warnings.push(format!("unused option: --allowlist-var {}", item)); + unused_regex_diagnostic(item, "--allowlist-var", self); } for item in self.options().allowlisted_types.unmatched_items() { - warnings.push(format!("unused option: --allowlist-type {}", item)); + unused_regex_diagnostic(item, "--allowlist-type", self); } - for msg in warnings { - warn!("{}", msg); - self.warnings.push(msg); + for item in self.options().allowlisted_items.unmatched_items() { + unused_regex_diagnostic(item, "--allowlist-items", self); } } /// Convenient method for getting the prefix to use for most traits in /// codegen depending on the `use_core` option. - pub fn trait_prefix(&self) -> Ident { + pub(crate) fn trait_prefix(&self) -> Ident { if self.options().use_core { self.rust_ident_raw("core") } else { @@ -2486,15 +2647,25 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Call if a bindgen complex is generated - pub fn generated_bindgen_complex(&self) { + pub(crate) fn generated_bindgen_complex(&self) { self.generated_bindgen_complex.set(true) } /// Whether we need to generate the bindgen complex type - pub fn need_bindgen_complex_type(&self) -> bool { + pub(crate) fn need_bindgen_complex_type(&self) -> bool { self.generated_bindgen_complex.get() } + /// Call if a bindgen float16 is generated + pub(crate) fn generated_bindgen_float16(&self) { + self.generated_bindgen_float16.set(true) + } + + /// Whether we need to generate the bindgen float16 type + pub(crate) fn need_bindgen_float16_type(&self) -> bool { + self.generated_bindgen_float16.get() + } + /// Compute which `enum`s have an associated `typedef` definition. fn compute_enum_typedef_combos(&mut self) { let _t = self.timer("compute_enum_typedef_combos"); @@ -2530,7 +2701,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } - // Find enums in this module, and record the id of each one that + // Find enums in this module, and record the ID of each one that // has a typedef. for child_id in module.children() { if let Some(ItemKind::Type(ty)) = @@ -2551,7 +2722,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether `id` refers to an `enum` whose underlying type is /// defined by a `typedef`. - pub fn is_enum_typedef_combo(&self, id: ItemId) -> bool { + pub(crate) fn is_enum_typedef_combo(&self, id: ItemId) -> bool { assert!( self.in_codegen_phase(), "We only compute enum_typedef_combos when we enter codegen", @@ -2574,7 +2745,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive debug or not. - pub fn lookup_can_derive_debug>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_debug>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2601,7 +2775,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive default or not. - pub fn lookup_can_derive_default>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_default>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2639,7 +2816,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive hash or not. - pub fn lookup_can_derive_hash>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_hash>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2668,7 +2848,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` can derive `Partial{Eq,Ord}`. - pub fn lookup_can_derive_partialeq_or_partialord>( + pub(crate) fn lookup_can_derive_partialeq_or_partialord< + Id: Into, + >( &self, id: Id, ) -> CanDerive { @@ -2689,7 +2871,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` can derive `Copy` or not. - pub fn lookup_can_derive_copy>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_copy>( + &self, + id: Id, + ) -> bool { assert!( self.in_codegen_phase(), "We only compute can_derive_debug when we enter codegen" @@ -2712,7 +2897,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has type parameter in array or not. - pub fn lookup_has_type_param_in_array>( + pub(crate) fn lookup_has_type_param_in_array>( &self, id: Id, ) -> bool { @@ -2739,7 +2924,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has array or not. - pub fn lookup_has_float>(&self, id: Id) -> bool { + pub(crate) fn lookup_has_float>(&self, id: Id) -> bool { assert!( self.in_codegen_phase(), "We only compute has float when we enter codegen" @@ -2751,41 +2936,42 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Check if `--no-partialeq` flag is enabled for this item. - pub fn no_partialeq_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_partialeq_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_partialeq_types.matches(name) } /// Check if `--no-copy` flag is enabled for this item. - pub fn no_copy_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_copy_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_copy_types.matches(name) } /// Check if `--no-debug` flag is enabled for this item. - pub fn no_debug_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_debug_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_debug_types.matches(name) } /// Check if `--no-default` flag is enabled for this item. - pub fn no_default_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_default_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_default_types.matches(name) } /// Check if `--no-hash` flag is enabled for this item. - pub fn no_hash_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_hash_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_hash_types.matches(name) } /// Check if `--must-use-type` flag is enabled for this item. - pub fn must_use_type_by_name(&self, item: &Item) -> bool { + pub(crate) fn must_use_type_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().must_use_types.matches(name) } + /// Wrap some tokens in an `unsafe` block if the `--wrap-unsafe-ops` option is enabled. pub(crate) fn wrap_unsafe_ops(&self, tokens: impl ToTokens) -> TokenStream { if self.options.wrap_unsafe_ops { quote!(unsafe { #tokens }) @@ -2794,6 +2980,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + /// Get the suffix to be added to `static` functions if the `--wrap-static-fns` option is + /// enabled. pub(crate) fn wrap_static_fns_suffix(&self) -> &str { self.options() .wrap_static_fns_suffix @@ -2804,15 +2992,15 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// A builder struct for configuring item resolution options. #[derive(Debug, Copy, Clone)] -pub struct ItemResolver { +pub(crate) struct ItemResolver { id: ItemId, through_type_refs: bool, through_type_aliases: bool, } impl ItemId { - /// Create an `ItemResolver` from this item id. - pub fn into_resolver(self) -> ItemResolver { + /// Create an `ItemResolver` from this item ID. + pub(crate) fn into_resolver(self) -> ItemResolver { self.into() } } @@ -2827,8 +3015,8 @@ where } impl ItemResolver { - /// Construct a new `ItemResolver` from the given id. - pub fn new>(id: Id) -> ItemResolver { + /// Construct a new `ItemResolver` from the given ID. + pub(crate) fn new>(id: Id) -> ItemResolver { let id = id.into(); ItemResolver { id, @@ -2838,19 +3026,19 @@ impl ItemResolver { } /// Keep resolving through `Type::TypeRef` items. - pub fn through_type_refs(mut self) -> ItemResolver { + pub(crate) fn through_type_refs(mut self) -> ItemResolver { self.through_type_refs = true; self } /// Keep resolving through `Type::Alias` items. - pub fn through_type_aliases(mut self) -> ItemResolver { + pub(crate) fn through_type_aliases(mut self) -> ItemResolver { self.through_type_aliases = true; self } /// Finish configuring and perform the actual item resolution. - pub fn resolve(self, ctx: &BindgenContext) -> &Item { + pub(crate) fn resolve(self, ctx: &BindgenContext) -> &Item { assert!(ctx.collected_typerefs()); let mut id = self.id; @@ -2887,7 +3075,7 @@ impl ItemResolver { /// A type that we are in the middle of parsing. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct PartialType { +pub(crate) struct PartialType { decl: Cursor, // Just an ItemId, and not a TypeId, because we haven't finished this type // yet, so there's still time for things to go wrong. @@ -2896,19 +3084,19 @@ pub struct PartialType { impl PartialType { /// Construct a new `PartialType`. - pub fn new(decl: Cursor, id: ItemId) -> PartialType { + pub(crate) fn new(decl: Cursor, id: ItemId) -> PartialType { // assert!(decl == decl.canonical()); PartialType { decl, id } } /// The cursor pointing to this partial type's declaration location. - pub fn decl(&self) -> &Cursor { + pub(crate) fn decl(&self) -> &Cursor { &self.decl } /// The item ID allocated for this type. This is *NOT* a key for an entry in /// the context's item set yet! - pub fn id(&self) -> ItemId { + pub(crate) fn id(&self) -> ItemId { self.id } } @@ -2945,3 +3133,23 @@ impl TemplateParameters for PartialType { } } } + +fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { + warn!("unused option: {} {}", name, item); + + // #[cfg(feature = "experimental")] + // if _ctx.options().emit_diagnostics { + // use crate::diagnostics::{Diagnostic, Level}; + + // Diagnostic::default() + // .with_title( + // format!("Unused regular expression: `{}`.", item), + // Level::Warn, + // ) + // .add_annotation( + // format!("This regular expression was passed to `{}`.", name), + // Level::Note, + // ) + // .display(); + // } +} diff --git a/bindgen/ir/derive.rs b/bindgen/ir/derive.rs index 594ce2ab8fc652a1586522370e43717b4091a2cc..5475ffdb228e245d81d1683571bfe3c4088e3142 100644 --- a/bindgen/ir/derive.rs +++ b/bindgen/ir/derive.rs @@ -3,10 +3,10 @@ //! These traits tend to come in pairs: //! //! 1. A "trivial" version, whose implementations aren't allowed to recursively -//! look at other types or the results of fix point analyses. +//! look at other types or the results of fix point analyses. //! //! 2. A "normal" version, whose implementations simply query the results of a -//! fix point analysis. +//! fix point analysis. //! //! The former is used by the analyses when creating the results queried by the //! second. @@ -18,7 +18,7 @@ use std::ops; /// A trait that encapsulates the logic for whether or not we can derive `Debug` /// for a given thing. -pub trait CanDeriveDebug { +pub(crate) trait CanDeriveDebug { /// Return `true` if `Debug` can be derived for this thing, `false` /// otherwise. fn can_derive_debug(&self, ctx: &BindgenContext) -> bool; @@ -26,7 +26,7 @@ pub trait CanDeriveDebug { /// A trait that encapsulates the logic for whether or not we can derive `Copy` /// for a given thing. -pub trait CanDeriveCopy { +pub(crate) trait CanDeriveCopy { /// Return `true` if `Copy` can be derived for this thing, `false` /// otherwise. fn can_derive_copy(&self, ctx: &BindgenContext) -> bool; @@ -34,7 +34,7 @@ pub trait CanDeriveCopy { /// A trait that encapsulates the logic for whether or not we can derive /// `Default` for a given thing. -pub trait CanDeriveDefault { +pub(crate) trait CanDeriveDefault { /// Return `true` if `Default` can be derived for this thing, `false` /// otherwise. fn can_derive_default(&self, ctx: &BindgenContext) -> bool; @@ -42,7 +42,7 @@ pub trait CanDeriveDefault { /// A trait that encapsulates the logic for whether or not we can derive `Hash` /// for a given thing. -pub trait CanDeriveHash { +pub(crate) trait CanDeriveHash { /// Return `true` if `Hash` can be derived for this thing, `false` /// otherwise. fn can_derive_hash(&self, ctx: &BindgenContext) -> bool; @@ -50,7 +50,7 @@ pub trait CanDeriveHash { /// A trait that encapsulates the logic for whether or not we can derive /// `PartialEq` for a given thing. -pub trait CanDerivePartialEq { +pub(crate) trait CanDerivePartialEq { /// Return `true` if `PartialEq` can be derived for this thing, `false` /// otherwise. fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool; @@ -58,7 +58,7 @@ pub trait CanDerivePartialEq { /// A trait that encapsulates the logic for whether or not we can derive /// `PartialOrd` for a given thing. -pub trait CanDerivePartialOrd { +pub(crate) trait CanDerivePartialOrd { /// Return `true` if `PartialOrd` can be derived for this thing, `false` /// otherwise. fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool; @@ -66,14 +66,14 @@ pub trait CanDerivePartialOrd { /// A trait that encapsulates the logic for whether or not we can derive `Eq` /// for a given thing. -pub trait CanDeriveEq { +pub(crate) trait CanDeriveEq { /// Return `true` if `Eq` can be derived for this thing, `false` otherwise. fn can_derive_eq(&self, ctx: &BindgenContext) -> bool; } /// A trait that encapsulates the logic for whether or not we can derive `Ord` /// for a given thing. -pub trait CanDeriveOrd { +pub(crate) trait CanDeriveOrd { /// Return `true` if `Ord` can be derived for this thing, `false` otherwise. fn can_derive_ord(&self, ctx: &BindgenContext) -> bool; } @@ -92,9 +92,10 @@ pub trait CanDeriveOrd { /// /// Initially we assume that we can derive trait for all types and then /// update our understanding as we learn more about each type. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub enum CanDerive { /// Yes, we can derive automatically. + #[default] Yes, /// The only thing that stops us from automatically deriving is that @@ -107,15 +108,9 @@ pub enum CanDerive { No, } -impl Default for CanDerive { - fn default() -> CanDerive { - CanDerive::Yes - } -} - impl CanDerive { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index f7d07f19e200fa4913562497f74a7208f4e3533a..d5c1a42fdcd08eb7bce7b1a8f394c012bc0aeb7b 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -8,7 +8,7 @@ use std::path::Path; /// A trait for anything that can write attributes as `` rows to a dot /// file. -pub trait DotAttributes { +pub(crate) trait DotAttributes { /// Write this thing's attributes to the given output. Each attribute must /// be its own `...`. fn dot_attributes( @@ -21,7 +21,7 @@ pub trait DotAttributes { } /// Write a graphviz dot file containing our IR. -pub fn write_dot_file

(ctx: &BindgenContext, path: P) -> io::Result<()> +pub(crate) fn write_dot_file

(ctx: &BindgenContext, path: P) -> io::Result<()> where P: AsRef, { diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 63871fd465693e6c0481ce8764dc44f4dd8c7da2..70cf0eae88aeec472a60e1b4212a645096eec117 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -22,7 +22,7 @@ pub enum EnumVariantCustomBehavior { /// A C/C++ enumeration. #[derive(Debug)] -pub struct Enum { +pub(crate) struct Enum { /// The representation used for this enum; it should be an `IntKind` type or /// an alias to one. /// @@ -36,22 +36,25 @@ pub struct Enum { impl Enum { /// Construct a new `Enum` with the given representation and variants. - pub fn new(repr: Option, variants: Vec) -> Self { + pub(crate) fn new( + repr: Option, + variants: Vec, + ) -> Self { Enum { repr, variants } } /// Get this enumeration's representation. - pub fn repr(&self) -> Option { + pub(crate) fn repr(&self) -> Option { self.repr } /// Get this enumeration's variants. - pub fn variants(&self) -> &[EnumVariant] { + pub(crate) fn variants(&self) -> &[EnumVariant] { &self.variants } /// Construct an enumeration from the given Clang type. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, ctx: &mut BindgenContext, ) -> Result { @@ -169,7 +172,7 @@ impl Enum { } /// Returns the final representation of the enum. - pub fn computed_enum_variation( + pub(crate) fn computed_enum_variation( &self, ctx: &BindgenContext, item: &Item, @@ -236,7 +239,7 @@ impl Enum { /// A single enum variant, to be contained only in an enum. #[derive(Debug)] -pub struct EnumVariant { +pub(crate) struct EnumVariant { /// The name of the variant. name: String, @@ -268,7 +271,7 @@ pub enum EnumVariantValue { impl EnumVariant { /// Construct a new enumeration variant from the given parts. - pub fn new( + pub(crate) fn new( name: String, name_for_allowlisting: String, comment: Option, @@ -285,35 +288,35 @@ impl EnumVariant { } /// Get this variant's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this variant's name. - pub fn name_for_allowlisting(&self) -> &str { + pub(crate) fn name_for_allowlisting(&self) -> &str { &self.name_for_allowlisting } /// Get this variant's value. - pub fn val(&self) -> EnumVariantValue { + pub(crate) fn val(&self) -> EnumVariantValue { self.val } /// Get this variant's documentation. - pub fn comment(&self) -> Option<&str> { + pub(crate) fn comment(&self) -> Option<&str> { self.comment.as_deref() } /// Returns whether this variant should be enforced to be a constant by code /// generation. - pub fn force_constification(&self) -> bool { + pub(crate) fn force_constification(&self) -> bool { self.custom_behavior .map_or(false, |b| b == EnumVariantCustomBehavior::Constify) } /// Returns whether the current variant should be hidden completely from the /// resulting rust enum. - pub fn hidden(&self) -> bool { + pub(crate) fn hidden(&self) -> bool { self.custom_behavior .map_or(false, |b| b == EnumVariantCustomBehavior::Hide) } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index baa2c36ca424e6e5ba324105384b55f792c28d0e..1557843d03fb70fc56a526242acadb6a42a8e8ef 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -7,11 +7,10 @@ use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use crate::callbacks::{ItemInfo, ItemKind}; -use crate::clang::{self, Attribute}; +use crate::clang::{self, ABIKind, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use clang_sys::{self, CXCallingConv}; -use proc_macro2; -use quote; +use clang_sys::CXCallingConv; + use quote::TokenStreamExt; use std::io; use std::str::FromStr; @@ -20,7 +19,7 @@ const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; /// What kind of a function are we looking at? #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum FunctionKind { +pub(crate) enum FunctionKind { /// A plain, free function. Function, /// A method of some kind. @@ -30,7 +29,7 @@ pub enum FunctionKind { impl FunctionKind { /// Given a clang cursor, return the kind of function it represents, or /// `None` otherwise. - pub fn from_cursor(cursor: &clang::Cursor) -> Option { + pub(crate) fn from_cursor(cursor: &clang::Cursor) -> Option { // FIXME(emilio): Deduplicate logic with `ir::comp`. Some(match cursor.kind() { clang_sys::CXCursor_FunctionDecl => FunctionKind::Function, @@ -64,7 +63,7 @@ impl FunctionKind { /// The style of linkage #[derive(Debug, Clone, Copy)] -pub enum Linkage { +pub(crate) enum Linkage { /// Externally visible and can be linked against External, /// Not exposed externally. 'static inline' functions will have this kind of linkage @@ -76,18 +75,18 @@ pub enum Linkage { /// The argument names vector must be the same length as the ones in the /// signature. #[derive(Debug)] -pub struct Function { +pub(crate) struct Function { /// The name of this function. name: String, /// The mangled name, that is, the symbol. mangled_name: Option, - /// The id pointing to the current function signature. - signature: TypeId, + /// The link name. If specified, overwrite mangled_name. + link_name: Option, - /// The doc comment on the function, if any. - comment: Option, + /// The ID pointing to the current function signature. + signature: TypeId, /// The kind of function this is. kind: FunctionKind, @@ -98,51 +97,51 @@ pub struct Function { impl Function { /// Construct a new function. - pub fn new( + pub(crate) fn new( name: String, mangled_name: Option, + link_name: Option, signature: TypeId, - comment: Option, kind: FunctionKind, linkage: Linkage, ) -> Self { Function { name, mangled_name, + link_name, signature, - comment, kind, linkage, } } /// Get this function's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this function's name. - pub fn mangled_name(&self) -> Option<&str> { + pub(crate) fn mangled_name(&self) -> Option<&str> { self.mangled_name.as_deref() } - /// Get this function's signature type. - pub fn signature(&self) -> TypeId { - self.signature + /// Get this function's link name. + pub fn link_name(&self) -> Option<&str> { + self.link_name.as_deref() } - /// Get this function's comment. - pub fn comment(&self) -> Option<&str> { - self.comment.as_deref() + /// Get this function's signature type. + pub(crate) fn signature(&self) -> TypeId { + self.signature } /// Get this function's kind. - pub fn kind(&self) -> FunctionKind { + pub(crate) fn kind(&self) -> FunctionKind { self.kind } /// Get this function's linkage. - pub fn linkage(&self) -> Linkage { + pub(crate) fn linkage(&self) -> Linkage { self.linkage } } @@ -177,6 +176,8 @@ pub enum Abi { C, /// The "stdcall" ABI. Stdcall, + /// The "efiapi" ABI. + EfiApi, /// The "fastcall" ABI. Fastcall, /// The "thiscall" ABI. @@ -189,6 +190,8 @@ pub enum Abi { Win64, /// The "C-unwind" ABI. CUnwind, + /// The "system" ABI. + System, } impl FromStr for Abi { @@ -198,12 +201,14 @@ impl FromStr for Abi { match s { "C" => Ok(Self::C), "stdcall" => Ok(Self::Stdcall), + "efiapi" => Ok(Self::EfiApi), "fastcall" => Ok(Self::Fastcall), "thiscall" => Ok(Self::ThisCall), "vectorcall" => Ok(Self::Vectorcall), "aapcs" => Ok(Self::Aapcs), "win64" => Ok(Self::Win64), "C-unwind" => Ok(Self::CUnwind), + "system" => Ok(Self::System), _ => Err(format!("Invalid or unknown ABI {:?}", s)), } } @@ -214,12 +219,14 @@ impl std::fmt::Display for Abi { let s = match *self { Self::C => "C", Self::Stdcall => "stdcall", + Self::EfiApi => "efiapi", Self::Fastcall => "fastcall", Self::ThisCall => "thiscall", Self::Vectorcall => "vectorcall", Self::Aapcs => "aapcs", Self::Win64 => "win64", Self::CUnwind => "C-unwind", + Abi::System => "system", }; s.fmt(f) @@ -236,6 +243,7 @@ impl quote::ToTokens for Abi { /// An ABI extracted from a clang cursor. #[derive(Debug, Copy, Clone)] pub(crate) enum ClangAbi { + /// An ABI known by Rust. Known(Abi), /// An unknown or invalid ABI. Unknown(CXCallingConv), @@ -262,7 +270,10 @@ impl quote::ToTokens for ClangAbi { /// A function signature. #[derive(Debug)] -pub struct FunctionSig { +pub(crate) struct FunctionSig { + /// The name of this function signature. + name: String, + /// The return type of the function. return_type: TypeId, @@ -292,12 +303,13 @@ fn get_abi(cc: CXCallingConv) -> ClangAbi { CXCallingConv_X86VectorCall => ClangAbi::Known(Abi::Vectorcall), CXCallingConv_AAPCS => ClangAbi::Known(Abi::Aapcs), CXCallingConv_X86_64Win64 => ClangAbi::Known(Abi::Win64), + CXCallingConv_AArch64VectorCall => ClangAbi::Known(Abi::Vectorcall), other => ClangAbi::Unknown(other), } } /// Get the mangled name for the cursor's referent. -pub fn cursor_mangling( +pub(crate) fn cursor_mangling( ctx: &BindgenContext, cursor: &clang::Cursor, ) -> Option { @@ -312,11 +324,12 @@ pub fn cursor_mangling( return None; } + let is_itanium_abi = ctx.abi_kind() == ABIKind::GenericItanium; let is_destructor = cursor.kind() == clang_sys::CXCursor_Destructor; if let Ok(mut manglings) = cursor.cxx_manglings() { while let Some(m) = manglings.pop() { // Only generate the destructor group 1, see below. - if is_destructor && !m.ends_with("D1Ev") { + if is_itanium_abi && is_destructor && !m.ends_with("D1Ev") { continue; } @@ -329,7 +342,7 @@ pub fn cursor_mangling( return None; } - if is_destructor { + if is_itanium_abi && is_destructor { // With old (3.8-) libclang versions, and the Itanium ABI, clang returns // the "destructor group 0" symbol, which means that it'll try to free // memory, which definitely isn't what we want. @@ -398,8 +411,13 @@ fn args_from_ty_and_cursor( } impl FunctionSig { + /// Get the function name. + pub(crate) fn name(&self) -> &str { + &self.name + } + /// Construct a new function signature from the given Clang type. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, cursor: &clang::Cursor, ctx: &mut BindgenContext, @@ -487,10 +505,24 @@ impl FunctionSig { Default::default() }; - // This looks easy to break but the clang parser keeps the type spelling clean even if - // other attributes are added. - is_divergent = - is_divergent || ty.spelling().contains("__attribute__((noreturn))"); + // Check if the type contains __attribute__((noreturn)) outside of parentheses. This is + // somewhat fragile, but it seems to be the only way to get at this information as of + // libclang 9. + let ty_spelling = ty.spelling(); + let has_attribute_noreturn = ty_spelling + .match_indices("__attribute__((noreturn))") + .any(|(i, _)| { + let depth = ty_spelling[..i] + .bytes() + .filter_map(|ch| match ch { + b'(' => Some(1), + b')' => Some(-1), + _ => None, + }) + .sum::(); + depth == 0 + }); + is_divergent = is_divergent || has_attribute_noreturn; let is_method = kind == CXCursor_CXXMethod; let is_constructor = kind == CXCursor_Constructor; @@ -572,7 +604,8 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(FunctionSig { + Ok(Self { + name: spelling, return_type: ret, argument_types: args, is_variadic: ty.is_variadic(), @@ -583,12 +616,12 @@ impl FunctionSig { } /// Get this function signature's return type. - pub fn return_type(&self) -> TypeId { + pub(crate) fn return_type(&self) -> TypeId { self.return_type } /// Get this function signature's argument (name, type) pairs. - pub fn argument_types(&self) -> &[(Option, TypeId)] { + pub(crate) fn argument_types(&self) -> &[(Option, TypeId)] { &self.argument_types } @@ -597,10 +630,10 @@ impl FunctionSig { &self, ctx: &BindgenContext, name: Option<&str>, - ) -> ClangAbi { + ) -> crate::codegen::error::Result { // FIXME (pvdrz): Try to do this check lazily instead. Maybe store the ABI inside `ctx` // instead?. - if let Some(name) = name { + let abi = if let Some(name) = name { if let Some((abi, _)) = ctx .options() .abi_overrides @@ -611,13 +644,47 @@ impl FunctionSig { } else { self.abi } + } else if let Some((abi, _)) = ctx + .options() + .abi_overrides + .iter() + .find(|(_, regex_set)| regex_set.matches(&self.name)) + { + ClangAbi::Known(*abi) } else { self.abi + }; + + match abi { + ClangAbi::Known(Abi::ThisCall) + if !ctx.options().rust_features().thiscall_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("thiscall")) + } + ClangAbi::Known(Abi::Vectorcall) + if !ctx.options().rust_features().vectorcall_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("vectorcall")) + } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("C-unwind")) + } + ClangAbi::Known(Abi::EfiApi) + if !ctx.options().rust_features().abi_efiapi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("efiapi")) + } + ClangAbi::Known(Abi::Win64) if self.is_variadic() => { + Err(crate::codegen::error::Error::UnsupportedAbi("Win64")) + } + abi => Ok(abi), } } /// Is this function signature variadic? - pub fn is_variadic(&self) -> bool { + pub(crate) fn is_variadic(&self) -> bool { // Clang reports some functions as variadic when they *might* be // variadic. We do the argument check because rust doesn't codegen well // variadic functions without an initial argument. @@ -625,7 +692,7 @@ impl FunctionSig { } /// Must this function's return value be used? - pub fn must_use(&self) -> bool { + pub(crate) fn must_use(&self) -> bool { self.must_use } @@ -635,10 +702,10 @@ impl FunctionSig { /// /// For more details, see: /// - /// * https://github.com/rust-lang/rust-bindgen/issues/547, - /// * https://github.com/rust-lang/rust/issues/38848, - /// * and https://github.com/rust-lang/rust/issues/40158 - pub fn function_pointers_can_derive(&self) -> bool { + /// * , + /// * , + /// * and + pub(crate) fn function_pointers_can_derive(&self) -> bool { if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT { return false; } @@ -646,6 +713,7 @@ impl FunctionSig { matches!(self.abi, ClangAbi::Known(Abi::C) | ClangAbi::Unknown(..)) } + /// Whether this function has attributes marking it as divergent. pub(crate) fn is_divergent(&self) -> bool { self.is_divergent } @@ -734,10 +802,22 @@ impl ClangSubItemParser for Function { assert!(!name.is_empty(), "Empty function name."); let mangled_name = cursor_mangling(context, &cursor); - let comment = cursor.raw_comment(); - let function = - Self::new(name.clone(), mangled_name, sig, comment, kind, linkage); + let link_name = context.options().last_callback(|callbacks| { + callbacks.generated_link_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Function, + }) + }); + + let function = Self::new( + name.clone(), + mangled_name, + link_name, + sig, + kind, + linkage, + ); Ok(ParseResult::New(function, Some(cursor))) } diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 22838e897c089fadd52800c54d66d36371622c28..4251b3753ad453d1fe93f7a152d1136ffae259eb 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -12,7 +12,7 @@ pub enum IntKind { /// An `unsigned char`. UChar, - /// An `wchar_t`. + /// A `wchar_t`. WChar, /// A platform-dependent `char` type, with the signedness support. @@ -87,7 +87,7 @@ pub enum IntKind { impl IntKind { /// Is this integral type signed? - pub fn is_signed(&self) -> bool { + pub(crate) fn is_signed(&self) -> bool { use self::IntKind::*; match *self { // TODO(emilio): wchar_t can in theory be signed, but we have no way @@ -108,7 +108,7 @@ impl IntKind { /// If this type has a known size, return it (in bytes). This is to /// alleviate libclang sometimes not giving us a layout (like in the case /// when an enum is defined inside a class with template parameters). - pub fn known_size(&self) -> Option { + pub(crate) fn known_size(&self) -> Option { use self::IntKind::*; Some(match *self { Bool | UChar | SChar | U8 | I8 | Char { .. } => 1, @@ -121,7 +121,7 @@ impl IntKind { } /// Whether this type's signedness matches the value. - pub fn signedness_matches(&self, val: i64) -> bool { + pub(crate) fn signedness_matches(&self, val: i64) -> bool { val >= 0 || self.is_signed() } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 40f6f7d927c53608a9bb95747330140a1a5af990..94abe4a86bd11431d7a69210a3a397cda4952e14 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -19,14 +19,13 @@ use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use clang_sys; -use lazycell::LazyCell; -use regex; -use std::cell::Cell; + +use std::cell::{Cell, OnceCell}; use std::collections::BTreeSet; use std::fmt::Write; use std::io; use std::iter; +use std::sync::OnceLock; /// A trait to get the canonical name from an item. /// @@ -38,7 +37,7 @@ use std::iter; /// /// This name is required to be safe for Rust, that is, is not expected to /// return any rust keyword from here. -pub trait ItemCanonicalName { +pub(crate) trait ItemCanonicalName { /// Get the canonical name for this item. fn canonical_name(&self, ctx: &BindgenContext) -> String; } @@ -55,7 +54,7 @@ pub trait ItemCanonicalName { /// /// For bar, the canonical path is `vec!["foo", "BAR"]`, while the canonical /// name is just `"BAR"`. -pub trait ItemCanonicalPath { +pub(crate) trait ItemCanonicalPath { /// Get the namespace-aware canonical path for this item. This means that if /// namespaces are disabled, you'll get a single item, and otherwise you get /// the whole path. @@ -69,7 +68,7 @@ pub trait ItemCanonicalPath { } /// A trait for determining if some IR thing is opaque or not. -pub trait IsOpaque { +pub(crate) trait IsOpaque { /// Extra context the IR thing needs to determine if it is opaque or not. type Extra; @@ -80,31 +79,25 @@ pub trait IsOpaque { } /// A trait for determining if some IR thing has type parameter in array or not. -pub trait HasTypeParamInArray { +pub(crate) trait HasTypeParamInArray { /// Returns `true` if the thing has Array, and `false` otherwise. fn has_type_param_in_array(&self, ctx: &BindgenContext) -> bool; } -/// A trait for determining if some IR thing has float or not. -pub trait HasFloat { - /// Returns `true` if the thing has float, and `false` otherwise. - fn has_float(&self, ctx: &BindgenContext) -> bool; -} - /// A trait for iterating over an item and its parents and up its ancestor chain /// up to (but not including) the implicit root module. -pub trait ItemAncestors { +pub(crate) trait ItemAncestors { /// Get an iterable over this item's ancestors. fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>; } -#[cfg(testing_only_extra_assertions)] +#[cfg(feature = "__testing_only_extra_assertions")] type DebugOnlyItemSet = ItemSet; -#[cfg(not(testing_only_extra_assertions))] +#[cfg(not(feature = "__testing_only_extra_assertions"))] struct DebugOnlyItemSet; -#[cfg(not(testing_only_extra_assertions))] +#[cfg(not(feature = "__testing_only_extra_assertions"))] impl DebugOnlyItemSet { fn new() -> Self { DebugOnlyItemSet @@ -118,7 +111,7 @@ impl DebugOnlyItemSet { } /// An iterator over an item and its ancestors. -pub struct ItemAncestorsIter<'a> { +pub(crate) struct ItemAncestorsIter<'a> { item: ItemId, ctx: &'a BindgenContext, seen: DebugOnlyItemSet, @@ -362,7 +355,7 @@ impl CanDeriveOrd for Item { /// information). /// /// Items refer to each other by `ItemId`. Every item has its parent's -/// id. Depending on the kind of item this is, it may also refer to other items, +/// ID. Depending on the kind of item this is, it may also refer to other items, /// such as a compound type item referring to other types. Collectively, these /// references form a graph. /// @@ -375,42 +368,42 @@ impl CanDeriveOrd for Item { /// all of them apply to every item. Those rules are described in the /// `annotations` module. #[derive(Debug)] -pub struct Item { - /// This item's id. +pub(crate) struct Item { + /// This item's ID. id: ItemId, - /// The item's local id, unique only amongst its siblings. Only used for + /// The item's local ID, unique only amongst its siblings. Only used for /// anonymous items. /// /// Lazily initialized in local_id(). /// - /// Note that only structs, unions, and enums get a local type id. In any + /// Note that only structs, unions, and enums get a local type ID. In any /// case this is an implementation detail. - local_id: LazyCell, + local_id: OnceCell, - /// The next local id to use for a child or template instantiation. + /// The next local ID to use for a child or template instantiation. next_child_local_id: Cell, /// A cached copy of the canonical name, as returned by `canonical_name`. /// /// This is a fairly used operation during codegen so this makes bindgen /// considerably faster in those cases. - canonical_name: LazyCell, + canonical_name: OnceCell, /// The path to use for allowlisting and other name-based checks, as /// returned by `path_for_allowlisting`, lazily constructed. - path_for_allowlisting: LazyCell>, + path_for_allowlisting: OnceCell>, /// A doc comment over the item, if any. comment: Option, /// Annotations extracted from the doc comment, or the default ones /// otherwise. annotations: Annotations, - /// An item's parent id. This will most likely be a class where this item + /// An item's parent ID. This will most likely be a class where this item /// was declared, or a module, etc. /// /// All the items have a parent, except the root module, in which case the - /// parent id is its own id. + /// parent ID is its own ID. parent_id: ItemId, /// The item kind. kind: ItemKind, @@ -426,7 +419,7 @@ impl AsRef for Item { impl Item { /// Construct a new `Item`. - pub fn new( + pub(crate) fn new( id: ItemId, comment: Option, annotations: Option, @@ -437,10 +430,10 @@ impl Item { debug_assert!(id != parent_id || kind.is_module()); Item { id, - local_id: LazyCell::new(), + local_id: OnceCell::new(), next_child_local_id: Cell::new(1), - canonical_name: LazyCell::new(), - path_for_allowlisting: LazyCell::new(), + canonical_name: OnceCell::new(), + path_for_allowlisting: OnceCell::new(), parent_id, comment, annotations: annotations.unwrap_or_default(), @@ -450,7 +443,7 @@ impl Item { } /// Construct a new opaque item type. - pub fn new_opaque_type( + pub(crate) fn new_opaque_type( with_id: ItemId, ty: &clang::Type, ctx: &mut BindgenContext, @@ -468,28 +461,31 @@ impl Item { } /// Get this `Item`'s identifier. - pub fn id(&self) -> ItemId { + pub(crate) fn id(&self) -> ItemId { self.id } /// Get this `Item`'s parent's identifier. /// /// For the root module, the parent's ID is its own ID. - pub fn parent_id(&self) -> ItemId { + pub(crate) fn parent_id(&self) -> ItemId { self.parent_id } - /// Set this item's parent id. + /// Set this item's parent ID. /// /// This is only used so replacements get generated in the proper module. - pub fn set_parent_for_replacement>(&mut self, id: Id) { + pub(crate) fn set_parent_for_replacement>( + &mut self, + id: Id, + ) { self.parent_id = id.into(); } /// Returns the depth this item is indented to. /// /// FIXME(emilio): This may need fixes for the enums within modules stuff. - pub fn codegen_depth(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn codegen_depth(&self, ctx: &BindgenContext) -> usize { if !ctx.options().enable_cxx_namespaces { return 0; } @@ -507,7 +503,7 @@ impl Item { /// Get this `Item`'s comment, if it has any, already preprocessed and with /// the right indentation. - pub fn comment(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn comment(&self, ctx: &BindgenContext) -> Option { if !ctx.options().generate_comments { return None; } @@ -518,17 +514,17 @@ impl Item { } /// What kind of item is this? - pub fn kind(&self) -> &ItemKind { + pub(crate) fn kind(&self) -> &ItemKind { &self.kind } /// Get a mutable reference to this item's kind. - pub fn kind_mut(&mut self) -> &mut ItemKind { + pub(crate) fn kind_mut(&mut self) -> &mut ItemKind { &mut self.kind } /// Where in the source is this item located? - pub fn location(&self) -> Option<&clang::SourceLocation> { + pub(crate) fn location(&self) -> Option<&clang::SourceLocation> { self.location.as_ref() } @@ -537,8 +533,8 @@ impl Item { /// This should stay relatively stable in the face of code motion outside or /// below this item's lexical scope, meaning that this can be useful for /// generating relatively stable identifiers within a scope. - pub fn local_id(&self, ctx: &BindgenContext) -> usize { - *self.local_id.borrow_with(|| { + pub(crate) fn local_id(&self, ctx: &BindgenContext) -> usize { + *self.local_id.get_or_init(|| { let parent = ctx.resolve_item(self.parent_id); parent.next_child_local_id() }) @@ -550,7 +546,7 @@ impl Item { /// This is currently used for anonymous items, and template instantiation /// tests, in both cases in order to reduce noise when system headers are at /// place. - pub fn next_child_local_id(&self) -> usize { + pub(crate) fn next_child_local_id(&self) -> usize { let local_id = self.next_child_local_id.get(); self.next_child_local_id.set(local_id + 1); local_id @@ -574,7 +570,7 @@ impl Item { /// This function is used to determine when the codegen phase should call /// `codegen` on an item, since any item that is not top-level will be /// generated by its parent. - pub fn is_toplevel(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_toplevel(&self, ctx: &BindgenContext) -> bool { // FIXME: Workaround for some types falling behind when parsing weird // stl classes, for example. if ctx.options().enable_cxx_namespaces && @@ -605,36 +601,36 @@ impl Item { /// Get a reference to this item's underlying `Type`. Panic if this is some /// other kind of item. - pub fn expect_type(&self) -> &Type { + pub(crate) fn expect_type(&self) -> &Type { self.kind().expect_type() } /// Get a reference to this item's underlying `Type`, or `None` if this is /// some other kind of item. - pub fn as_type(&self) -> Option<&Type> { + pub(crate) fn as_type(&self) -> Option<&Type> { self.kind().as_type() } /// Get a reference to this item's underlying `Function`. Panic if this is /// some other kind of item. - pub fn expect_function(&self) -> &Function { + pub(crate) fn expect_function(&self) -> &Function { self.kind().expect_function() } /// Is this item a module? - pub fn is_module(&self) -> bool { + pub(crate) fn is_module(&self) -> bool { matches!(self.kind, ItemKind::Module(..)) } /// Get this item's annotations. - pub fn annotations(&self) -> &Annotations { + pub(crate) fn annotations(&self) -> &Annotations { &self.annotations } /// Whether this item should be blocklisted. /// /// This may be due to either annotations or to other kind of configuration. - pub fn is_blocklisted(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_blocklisted(&self, ctx: &BindgenContext) -> bool { debug_assert!( ctx.in_codegen_phase(), "You're not supposed to call this yet" @@ -665,27 +661,23 @@ impl Item { ItemKind::Function(..) => { ctx.options().blocklisted_functions.matches(&name) } - // TODO: Add constant / namespace blocklisting? - ItemKind::Var(..) | ItemKind::Module(..) => false, + ItemKind::Var(..) => { + ctx.options().blocklisted_vars.matches(&name) + } + // TODO: Add namespace blocklisting? + ItemKind::Module(..) => false, } } - /// Is this a reference to another type? - pub fn is_type_ref(&self) -> bool { - self.as_type().map_or(false, |ty| ty.is_type_ref()) - } - - /// Is this item a var type? - pub fn is_var(&self) -> bool { - matches!(*self.kind(), ItemKind::Var(..)) - } - /// Take out item NameOptions - pub fn name<'a>(&'a self, ctx: &'a BindgenContext) -> NameOptions<'a> { + pub(crate) fn name<'a>( + &'a self, + ctx: &'a BindgenContext, + ) -> NameOptions<'a> { NameOptions::new(self, ctx) } - /// Get the target item id for name generation. + /// Get the target item ID for name generation. fn name_target(&self, ctx: &BindgenContext) -> ItemId { let mut targets_seen = DebugOnlyItemSet::new(); let mut item = self; @@ -715,7 +707,10 @@ impl Item { /// Create a fully disambiguated name for an item, including template /// parameters if it is a type - pub fn full_disambiguated_name(&self, ctx: &BindgenContext) -> String { + pub(crate) fn full_disambiguated_name( + &self, + ctx: &BindgenContext, + ) -> String { let mut s = String::new(); let level = 0; self.push_disambiguated_name(ctx, &mut s, level); @@ -839,7 +834,7 @@ impl Item { /// If `BindgenOptions::disable_nested_struct_naming` is true then returned /// name is the inner most non-anonymous name plus all the anonymous base names /// that follows. - pub fn real_canonical_name( + pub(crate) fn real_canonical_name( &self, ctx: &BindgenContext, opt: &NameOptions, @@ -862,7 +857,7 @@ impl Item { return base_name; } - // Ancestors' id iter + // Ancestors' ID iter let mut ids_iter = target .parent_id() .ancestors(ctx) @@ -939,30 +934,30 @@ impl Item { ctx.rust_mangle(&name).into_owned() } - /// The exposed id that represents an unique id among the siblings of a + /// The exposed ID that represents an unique ID among the siblings of a /// given item. - pub fn exposed_id(&self, ctx: &BindgenContext) -> String { + pub(crate) fn exposed_id(&self, ctx: &BindgenContext) -> String { // Only use local ids for enums, classes, structs and union types. All - // other items use their global id. + // other items use their global ID. let ty_kind = self.kind().as_type().map(|t| t.kind()); - if let Some(ty_kind) = ty_kind { - match *ty_kind { - TypeKind::Comp(..) | - TypeKind::TemplateInstantiation(..) | - TypeKind::Enum(..) => return self.local_id(ctx).to_string(), - _ => {} - } + if let Some( + TypeKind::Comp(..) | + TypeKind::TemplateInstantiation(..) | + TypeKind::Enum(..), + ) = ty_kind + { + return self.local_id(ctx).to_string(); } // Note that this `id_` prefix prevents (really unlikely) collisions - // between the global id and the local id of an item with the same + // between the global ID and the local ID of an item with the same // parent. format!("id_{}", self.id().as_usize()) } /// Get a reference to this item's `Module`, or `None` if this is not a /// `Module` item. - pub fn as_module(&self) -> Option<&Module> { + pub(crate) fn as_module(&self) -> Option<&Module> { match self.kind { ItemKind::Module(ref module) => Some(module), _ => None, @@ -971,7 +966,7 @@ impl Item { /// Get a mutable reference to this item's `Module`, or `None` if this is /// not a `Module` item. - pub fn as_module_mut(&mut self) -> Option<&mut Module> { + pub(crate) fn as_module_mut(&mut self) -> Option<&mut Module> { match self.kind { ItemKind::Module(ref mut module) => Some(module), _ => None, @@ -1010,7 +1005,7 @@ impl Item { } /// Is this item of a kind that is enabled for code generation? - pub fn is_enabled_for_codegen(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_enabled_for_codegen(&self, ctx: &BindgenContext) -> bool { let cc = &ctx.options().codegen_config; match *self.kind() { ItemKind::Module(..) => true, @@ -1036,9 +1031,12 @@ impl Item { /// Returns the path we should use for allowlisting / blocklisting, which /// doesn't include user-mangling. - pub fn path_for_allowlisting(&self, ctx: &BindgenContext) -> &Vec { + pub(crate) fn path_for_allowlisting( + &self, + ctx: &BindgenContext, + ) -> &Vec { self.path_for_allowlisting - .borrow_with(|| self.compute_path(ctx, UserMangled::No)) + .get_or_init(|| self.compute_path(ctx, UserMangled::No)) } fn compute_path( @@ -1094,8 +1092,8 @@ impl Item { }) } - /// Whether this is a #[must_use] type. - pub fn must_use(&self, ctx: &BindgenContext) -> bool { + /// Whether this is a `#[must_use]` type. + pub(crate) fn must_use(&self, ctx: &BindgenContext) -> bool { self.annotations().must_use_type() || ctx.must_use_type_by_name(self) } } @@ -1198,31 +1196,8 @@ impl HasTypeParamInArray for Item { } } -impl HasFloat for T -where - T: Copy + Into, -{ - fn has_float(&self, ctx: &BindgenContext) -> bool { - debug_assert!( - ctx.in_codegen_phase(), - "You're not supposed to call this yet" - ); - ctx.lookup_has_float(*self) - } -} - -impl HasFloat for Item { - fn has_float(&self, ctx: &BindgenContext) -> bool { - debug_assert!( - ctx.in_codegen_phase(), - "You're not supposed to call this yet" - ); - ctx.lookup_has_float(self.id()) - } -} - /// A set of items. -pub type ItemSet = BTreeSet; +pub(crate) type ItemSet = BTreeSet; impl DotAttributes for Item { fn dot_attributes( @@ -1306,6 +1281,7 @@ fn visit_child( } impl Item { + /// Create a builtin type. pub(crate) fn builtin_type( kind: TypeKind, is_const: bool, @@ -1331,6 +1307,7 @@ impl Item { id.as_type_id_unchecked() } + /// Parse this item from the given Clang cursor. pub(crate) fn parse( cursor: clang::Cursor, parent_id: Option, @@ -1349,6 +1326,7 @@ impl Item { let current_module = ctx.current_module().into(); let relevant_parent_id = parent_id.unwrap_or(current_module); + #[allow(clippy::missing_docs_in_private_items)] macro_rules! try_parse { ($what:ident) => { match $what::parse(cursor, ctx) { @@ -1427,56 +1405,63 @@ impl Item { } } - // Guess how does clang treat extern "C" blocks? - if cursor.kind() == CXCursor_UnexposedDecl { - Err(ParseError::Recurse) - } else { + match cursor.kind() { + // On Clang 18+, extern "C" is reported accurately as a LinkageSpec. + // Older LLVM treat it as UnexposedDecl. + CXCursor_LinkageSpec | CXCursor_UnexposedDecl => { + Err(ParseError::Recurse) + } + // We allowlist cursors here known to be unhandled, to prevent being // too noisy about this. - match cursor.kind() { - CXCursor_MacroDefinition | - CXCursor_MacroExpansion | - CXCursor_UsingDeclaration | - CXCursor_UsingDirective | - CXCursor_StaticAssert | - CXCursor_FunctionTemplate => { - debug!( + CXCursor_MacroDefinition | + CXCursor_MacroExpansion | + CXCursor_UsingDeclaration | + CXCursor_UsingDirective | + CXCursor_StaticAssert | + CXCursor_FunctionTemplate => { + debug!( + "Unhandled cursor kind {:?}: {:?}", + cursor.kind(), + cursor + ); + Err(ParseError::Continue) + } + + CXCursor_InclusionDirective => { + let file = cursor.get_included_file_name(); + match file { + None => { + warn!("Inclusion of a nameless file in {:?}", cursor); + } + Some(included_file) => { + for cb in &ctx.options().parse_callbacks { + cb.include_file(&included_file); + } + + ctx.add_dep(included_file.into_boxed_str()); + } + } + Err(ParseError::Continue) + } + + _ => { + // ignore toplevel operator overloads + let spelling = cursor.spelling(); + if !spelling.starts_with("operator") { + warn!( "Unhandled cursor kind {:?}: {:?}", cursor.kind(), cursor ); } - CXCursor_InclusionDirective => { - let file = cursor.get_included_file_name(); - match file { - None => { - warn!( - "Inclusion of a nameless file in {:?}", - cursor - ); - } - Some(filename) => { - ctx.include_file(filename); - } - } - } - _ => { - // ignore toplevel operator overloads - let spelling = cursor.spelling(); - if !spelling.starts_with("operator") { - warn!( - "Unhandled cursor kind {:?}: {:?}", - cursor.kind(), - cursor - ); - } - } + Err(ParseError::Continue) } - - Err(ParseError::Continue) } } + /// Parse this item from the given Clang type, or if we haven't resolved all + /// the other items this one depends on, an unresolved reference. pub(crate) fn from_ty_or_ref( ty: clang::Type, location: clang::Cursor, @@ -1552,6 +1537,7 @@ impl Item { potential_id.as_type_id_unchecked() } + /// Parse this item from the given Clang type. See [`Item::from_ty_with_id`]. pub(crate) fn from_ty( ty: &clang::Type, location: clang::Cursor, @@ -1565,10 +1551,10 @@ impl Item { /// This is one of the trickiest methods you'll find (probably along with /// some of the ones that handle templates in `BindgenContext`). /// - /// This method parses a type, given the potential id of that type (if + /// This method parses a type, given the potential ID of that type (if /// parsing it was correct), an optional location we're scanning, which is - /// critical some times to obtain information, an optional parent item id, - /// that will, if it's `None`, become the current module id, and the + /// critical some times to obtain information, an optional parent item ID, + /// that will, if it's `None`, become the current module ID, and the /// context. pub(crate) fn from_ty_with_id( id: ItemId, @@ -1617,7 +1603,11 @@ impl Item { canonical_def.unwrap_or_else(|| ty.declaration()) }; - let comment = decl.raw_comment().or_else(|| location.raw_comment()); + let comment = location + .raw_comment() + .or_else(|| decl.raw_comment()) + .or_else(|| location.raw_comment()); + let annotations = Annotations::new(&decl).or_else(|| Annotations::new(&location)); @@ -1737,9 +1727,8 @@ impl Item { ret } - /// A named type is a template parameter, e.g., the "T" in Foo. They're - /// always local so it's the only exception when there's no declaration for - /// a type. + /// A named type is a template parameter, e.g., the `T` in `Foo`. They're always local so + /// it's the only exception when there's no declaration for a type. pub(crate) fn type_param( with_id: Option, location: clang::Cursor, @@ -1817,10 +1806,10 @@ impl Item { refd: &clang::Cursor, spelling: &str, ) -> bool { - lazy_static! { - static ref ANON_TYPE_PARAM_RE: regex::Regex = - regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap(); - } + static ANON_TYPE_PARAM_RE: OnceLock = OnceLock::new(); + let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| { + regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap() + }); if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter { return false; @@ -1829,7 +1818,7 @@ impl Item { let refd_spelling = refd.spelling(); refd_spelling == spelling || // Allow for anonymous template parameters. - (refd_spelling.is_empty() && ANON_TYPE_PARAM_RE.is_match(spelling.as_ref())) + (refd_spelling.is_empty() && anon_type_param_re.is_match(spelling.as_ref())) } let definition = if is_template_with_spelling(&location, &ty_spelling) { @@ -1919,7 +1908,7 @@ impl ItemCanonicalName for Item { "You're not supposed to call this yet" ); self.canonical_name - .borrow_with(|| { + .get_or_init(|| { let in_namespace = ctx.options().enable_cxx_namespaces || ctx.options().disable_name_namespacing; @@ -1978,7 +1967,7 @@ enum UserMangled { /// Builder struct for naming variations, which hold inside different /// flags for naming options. #[derive(Debug)] -pub struct NameOptions<'a> { +pub(crate) struct NameOptions<'a> { item: &'a Item, ctx: &'a BindgenContext, within_namespaces: bool, @@ -1987,7 +1976,7 @@ pub struct NameOptions<'a> { impl<'a> NameOptions<'a> { /// Construct a new `NameOptions` - pub fn new(item: &'a Item, ctx: &'a BindgenContext) -> Self { + pub(crate) fn new(item: &'a Item, ctx: &'a BindgenContext) -> Self { NameOptions { item, ctx, @@ -1998,7 +1987,7 @@ impl<'a> NameOptions<'a> { /// Construct the name without the item's containing C++ namespaces mangled /// into it. In other words, the item's name within the item's namespace. - pub fn within_namespaces(&mut self) -> &mut Self { + pub(crate) fn within_namespaces(&mut self) -> &mut Self { self.within_namespaces = true; self } @@ -2009,7 +1998,7 @@ impl<'a> NameOptions<'a> { } /// Construct a name `String` - pub fn get(&self) -> String { + pub(crate) fn get(&self) -> String { self.item.real_canonical_name(self.ctx, self) } } diff --git a/bindgen/ir/item_kind.rs b/bindgen/ir/item_kind.rs index 4a12fef40d17864ebe8babb4cac8b914cd5a64ae..9221b50579b5238cf01026ee5e6ae66d5bd7efee 100644 --- a/bindgen/ir/item_kind.rs +++ b/bindgen/ir/item_kind.rs @@ -10,7 +10,7 @@ use std::io; /// A item we parse and translate. #[derive(Debug)] -pub enum ItemKind { +pub(crate) enum ItemKind { /// A module, created implicitly once (the root module), or via C++ /// namespaces. Module(Module), @@ -26,9 +26,9 @@ pub enum ItemKind { } impl ItemKind { - /// Get a reference to this `ItemKind`'s underying `Module`, or `None` if it + /// Get a reference to this `ItemKind`'s underlying `Module`, or `None` if it /// is some other kind. - pub fn as_module(&self) -> Option<&Module> { + pub(crate) fn as_module(&self) -> Option<&Module> { match *self { ItemKind::Module(ref module) => Some(module), _ => None, @@ -36,7 +36,7 @@ impl ItemKind { } /// Transform our `ItemKind` into a string. - pub fn kind_name(&self) -> &'static str { + pub(crate) fn kind_name(&self) -> &'static str { match *self { ItemKind::Module(..) => "Module", ItemKind::Type(..) => "Type", @@ -46,19 +46,13 @@ impl ItemKind { } /// Is this a module? - pub fn is_module(&self) -> bool { + pub(crate) fn is_module(&self) -> bool { self.as_module().is_some() } - /// Get a reference to this `ItemKind`'s underying `Module`, or panic if it - /// is some other kind. - pub fn expect_module(&self) -> &Module { - self.as_module().expect("Not a module") - } - - /// Get a reference to this `ItemKind`'s underying `Function`, or `None` if + /// Get a reference to this `ItemKind`'s underlying `Function`, or `None` if /// it is some other kind. - pub fn as_function(&self) -> Option<&Function> { + pub(crate) fn as_function(&self) -> Option<&Function> { match *self { ItemKind::Function(ref func) => Some(func), _ => None, @@ -66,28 +60,28 @@ impl ItemKind { } /// Is this a function? - pub fn is_function(&self) -> bool { + pub(crate) fn is_function(&self) -> bool { self.as_function().is_some() } - /// Get a reference to this `ItemKind`'s underying `Function`, or panic if + /// Get a reference to this `ItemKind`'s underlying `Function`, or panic if /// it is some other kind. - pub fn expect_function(&self) -> &Function { + pub(crate) fn expect_function(&self) -> &Function { self.as_function().expect("Not a function") } - /// Get a reference to this `ItemKind`'s underying `Type`, or `None` if + /// Get a reference to this `ItemKind`'s underlying `Type`, or `None` if /// it is some other kind. - pub fn as_type(&self) -> Option<&Type> { + pub(crate) fn as_type(&self) -> Option<&Type> { match *self { ItemKind::Type(ref ty) => Some(ty), _ => None, } } - /// Get a mutable reference to this `ItemKind`'s underying `Type`, or `None` + /// Get a mutable reference to this `ItemKind`'s underlying `Type`, or `None` /// if it is some other kind. - pub fn as_type_mut(&mut self) -> Option<&mut Type> { + pub(crate) fn as_type_mut(&mut self) -> Option<&mut Type> { match *self { ItemKind::Type(ref mut ty) => Some(ty), _ => None, @@ -95,19 +89,19 @@ impl ItemKind { } /// Is this a type? - pub fn is_type(&self) -> bool { + pub(crate) fn is_type(&self) -> bool { self.as_type().is_some() } - /// Get a reference to this `ItemKind`'s underying `Type`, or panic if it is + /// Get a reference to this `ItemKind`'s underlying `Type`, or panic if it is /// some other kind. - pub fn expect_type(&self) -> &Type { + pub(crate) fn expect_type(&self) -> &Type { self.as_type().expect("Not a type") } - /// Get a reference to this `ItemKind`'s underying `Var`, or `None` if it is + /// Get a reference to this `ItemKind`'s underlying `Var`, or `None` if it is /// some other kind. - pub fn as_var(&self) -> Option<&Var> { + pub(crate) fn as_var(&self) -> Option<&Var> { match *self { ItemKind::Var(ref v) => Some(v), _ => None, @@ -115,15 +109,9 @@ impl ItemKind { } /// Is this a variable? - pub fn is_var(&self) -> bool { + pub(crate) fn is_var(&self) -> bool { self.as_var().is_some() } - - /// Get a reference to this `ItemKind`'s underying `Var`, or panic if it is - /// some other kind. - pub fn expect_var(&self) -> &Var { - self.as_var().expect("Not a var") - } } impl DotAttributes for ItemKind { diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index 6f4503070a8e43454f1ed2ae2b332a7f06e97411..85a553da31aa64b716633c9809d22924ebe3f085 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -8,13 +8,13 @@ use std::cmp; /// A type that represents the struct layout of a type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Layout { +pub(crate) struct Layout { /// The size (in bytes) of this layout. - pub size: usize, + pub(crate) size: usize, /// The alignment (in bytes) of this layout. - pub align: usize, + pub(crate) align: usize, /// Whether this layout's members are packed or not. - pub packed: bool, + pub(crate) packed: bool, } #[test] @@ -34,23 +34,25 @@ fn test_layout_for_size() { impl Layout { /// Gets the integer type name for a given known size. - pub fn known_type_for_size( + pub(crate) fn known_type_for_size( ctx: &BindgenContext, size: usize, - ) -> Option<&'static str> { + ) -> Option { Some(match size { - 16 if ctx.options().rust_features.i128_and_u128 => "u128", - 8 => "u64", - 4 => "u32", - 2 => "u16", - 1 => "u8", + 16 if ctx.options().rust_features.i128_and_u128 => { + syn::parse_quote! { u128 } + } + 8 => syn::parse_quote! { u64 }, + 4 => syn::parse_quote! { u32 }, + 2 => syn::parse_quote! { u16 }, + 1 => syn::parse_quote! { u8 }, _ => return None, }) } /// Construct a new `Layout` with the given `size` and `align`. It is not /// packed. - pub fn new(size: usize, align: usize) -> Self { + pub(crate) fn new(size: usize, align: usize) -> Self { Layout { size, align, @@ -72,33 +74,26 @@ impl Layout { /// Creates a non-packed layout for a given size, trying to use the maximum /// alignment possible. - pub fn for_size(ctx: &BindgenContext, size: usize) -> Self { + pub(crate) fn for_size(ctx: &BindgenContext, size: usize) -> Self { Self::for_size_internal(ctx.target_pointer_size(), size) } - /// Is this a zero-sized layout? - pub fn is_zero(&self) -> bool { - self.size == 0 && self.align == 0 - } - - /// Construct a zero-sized layout. - pub fn zero() -> Self { - Self::new(0, 0) - } - /// Get this layout as an opaque type. - pub fn opaque(&self) -> Opaque { + pub(crate) fn opaque(&self) -> Opaque { Opaque(*self) } } /// When we are treating a type as opaque, it is just a blob with a `Layout`. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Opaque(pub Layout); +pub(crate) struct Opaque(pub(crate) Layout); impl Opaque { /// Construct a new opaque type from the given clang type. - pub fn from_clang_ty(ty: &clang::Type, ctx: &BindgenContext) -> Type { + pub(crate) fn from_clang_ty( + ty: &clang::Type, + ctx: &BindgenContext, + ) -> Type { let layout = Layout::new(ty.size(ctx), ty.align(ctx)); let ty_kind = TypeKind::Opaque; let is_const = ty.is_const(); @@ -107,16 +102,16 @@ impl Opaque { /// Return the known rust type we should use to create a correctly-aligned /// field with this layout. - pub fn known_rust_type_for_array( + pub(crate) fn known_rust_type_for_array( &self, ctx: &BindgenContext, - ) -> Option<&'static str> { + ) -> Option { Layout::known_type_for_size(ctx, self.0.align) } /// Return the array size that an opaque type for this layout should have if /// we know the correct type for it, or `None` otherwise. - pub fn array_size(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn array_size(&self, ctx: &BindgenContext) -> Option { if self.known_rust_type_for_array(ctx).is_some() { Some(self.0.size / cmp::max(self.0.align, 1)) } else { @@ -127,7 +122,7 @@ impl Opaque { /// Return `true` if this opaque layout's array size will fit within the /// maximum number of array elements that Rust allows deriving traits /// with. Return `false` otherwise. - pub fn array_size_within_derive_limit( + pub(crate) fn array_size_within_derive_limit( &self, ctx: &BindgenContext, ) -> CanDerive { diff --git a/bindgen/ir/mod.rs b/bindgen/ir/mod.rs index 8f6a2dac88618d86d005d7bcf7d6ea7099838acd..acdb4896cda7cc6be605c2547fc697e64de15e65 100644 --- a/bindgen/ir/mod.rs +++ b/bindgen/ir/mod.rs @@ -2,23 +2,24 @@ //! //! Parsing C/C++ generates the IR, while code generation outputs Rust code from //! the IR. +#![deny(clippy::missing_docs_in_private_items)] -pub mod analysis; -pub mod annotations; -pub mod comment; -pub mod comp; -pub mod context; -pub mod derive; -pub mod dot; -pub mod enum_ty; -pub mod function; -pub mod int; -pub mod item; -pub mod item_kind; -pub mod layout; -pub mod module; -pub mod objc; -pub mod template; -pub mod traversal; -pub mod ty; -pub mod var; +pub(crate) mod analysis; +pub(crate) mod annotations; +pub(crate) mod comment; +pub(crate) mod comp; +pub(crate) mod context; +pub(crate) mod derive; +pub(crate) mod dot; +pub(crate) mod enum_ty; +pub(crate) mod function; +pub(crate) mod int; +pub(crate) mod item; +pub(crate) mod item_kind; +pub(crate) mod layout; +pub(crate) mod module; +pub(crate) mod objc; +pub(crate) mod template; +pub(crate) mod traversal; +pub(crate) mod ty; +pub(crate) mod var; diff --git a/bindgen/ir/module.rs b/bindgen/ir/module.rs index d5aca94a6eb50b7273de0f1bb9cb76fd609c90de..5ec55e904893e0e7e9bdb100480983fa2901c03d 100644 --- a/bindgen/ir/module.rs +++ b/bindgen/ir/module.rs @@ -6,11 +6,12 @@ use super::item::ItemSet; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use crate::parse_one; + use std::io; /// Whether this module is inline or not. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum ModuleKind { +pub(crate) enum ModuleKind { /// This module is not inline. Normal, /// This module is inline, as in `inline namespace foo {}`. @@ -19,7 +20,7 @@ pub enum ModuleKind { /// A module, as in, a C++ namespace. #[derive(Clone, Debug)] -pub struct Module { +pub(crate) struct Module { /// The name of the module, or none if it's anonymous. name: Option, /// The kind of module this is. @@ -30,7 +31,7 @@ pub struct Module { impl Module { /// Construct a new `Module`. - pub fn new(name: Option, kind: ModuleKind) -> Self { + pub(crate) fn new(name: Option, kind: ModuleKind) -> Self { Module { name, kind, @@ -39,22 +40,22 @@ impl Module { } /// Get this module's name. - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { self.name.as_deref() } /// Get a mutable reference to this module's children. - pub fn children_mut(&mut self) -> &mut ItemSet { + pub(crate) fn children_mut(&mut self) -> &mut ItemSet { &mut self.children } /// Get this module's children. - pub fn children(&self) -> &ItemSet { + pub(crate) fn children(&self) -> &ItemSet { &self.children } /// Whether this namespace is inline. - pub fn is_inline(&self) -> bool { + pub(crate) fn is_inline(&self) -> bool { self.kind == ModuleKind::Inline } } @@ -82,8 +83,8 @@ impl ClangSubItemParser for Module { CXCursor_Namespace => { let module_id = ctx.module(cursor); ctx.with_module(module_id, |ctx| { - cursor.visit(|cursor| { - parse_one(ctx, cursor, Some(module_id.into())) + cursor.visit_sorted(ctx, |ctx, child| { + parse_one(ctx, child, Some(module_id.into())) }) }); diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 4f340f6f7a7a5ce5737880ac7475d590297e02ff..d7f7cc65a6e13cffc7b3025c66148816834a3b99 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -21,7 +21,7 @@ use proc_macro2::{Ident, Span, TokenStream}; /// /// Also protocols and categories are parsed as this type #[derive(Debug)] -pub struct ObjCInterface { +pub(crate) struct ObjCInterface { /// The name /// like, NSObject name: String, @@ -31,15 +31,15 @@ pub struct ObjCInterface { is_protocol: bool, /// The list of template names almost always, ObjectType or KeyType - pub template_names: Vec, + pub(crate) template_names: Vec, /// The list of protocols that this interface conforms to. - pub conforms_to: Vec, + pub(crate) conforms_to: Vec, /// The direct parent for this interface. - pub parent_class: Option, + pub(crate) parent_class: Option, - /// List of the methods defined in this interfae + /// List of the methods defined in this interface methods: Vec, class_methods: Vec, @@ -47,7 +47,7 @@ pub struct ObjCInterface { /// The objective c methods #[derive(Debug)] -pub struct ObjCMethod { +pub(crate) struct ObjCMethod { /// The original method selector name /// like, dataWithBytes:length: name: String, @@ -78,14 +78,14 @@ impl ObjCInterface { /// The name /// like, NSObject - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { self.name.as_ref() } /// Formats the name for rust /// Can be like NSObject, but with categories might be like NSObject_NSCoderMethods /// and protocols are like PNSObject - pub fn rust_name(&self) -> String { + pub(crate) fn rust_name(&self) -> String { if let Some(ref cat) = self.category { format!("{}_{}", self.name(), cat) } else if self.is_protocol { @@ -96,32 +96,32 @@ impl ObjCInterface { } /// Is this a template interface? - pub fn is_template(&self) -> bool { + pub(crate) fn is_template(&self) -> bool { !self.template_names.is_empty() } /// List of the methods defined in this interface - pub fn methods(&self) -> &Vec { + pub(crate) fn methods(&self) -> &Vec { &self.methods } /// Is this a protocol? - pub fn is_protocol(&self) -> bool { + pub(crate) fn is_protocol(&self) -> bool { self.is_protocol } /// Is this a category? - pub fn is_category(&self) -> bool { + pub(crate) fn is_category(&self) -> bool { self.category.is_some() } /// List of the class methods defined in this interface - pub fn class_methods(&self) -> &Vec { + pub(crate) fn class_methods(&self) -> &Vec { &self.class_methods } /// Parses the Objective C interface from the cursor - pub fn from_ty( + pub(crate) fn from_ty( cursor: &clang::Cursor, ctx: &mut BindgenContext, ) -> Option { @@ -137,7 +137,7 @@ impl ObjCInterface { CXCursor_ObjCClassRef => { if cursor.kind() == CXCursor_ObjCCategoryDecl { // We are actually a category extension, and we found the reference - // to the original interface, so name this interface approriately + // to the original interface, so name this interface appropriately interface.name = c.spelling(); interface.category = Some(cursor.spelling()); } @@ -229,46 +229,62 @@ impl ObjCMethod { } } - /// The original method selector name - /// like, dataWithBytes:length: - pub fn name(&self) -> &str { - self.name.as_ref() - } - /// Method name as converted to rust /// like, dataWithBytes_length_ - pub fn rust_name(&self) -> &str { + pub(crate) fn rust_name(&self) -> &str { self.rust_name.as_ref() } /// Returns the methods signature as FunctionSig - pub fn signature(&self) -> &FunctionSig { + pub(crate) fn signature(&self) -> &FunctionSig { &self.signature } /// Is this a class method? - pub fn is_class_method(&self) -> bool { + pub(crate) fn is_class_method(&self) -> bool { self.is_class_method } /// Formats the method call - pub fn format_method_call(&self, args: &[TokenStream]) -> TokenStream { + pub(crate) fn format_method_call( + &self, + args: &[TokenStream], + ) -> TokenStream { let split_name: Vec> = self .name .split(':') - .map(|name| { + .enumerate() + .map(|(idx, name)| { if name.is_empty() { None + } else if idx == 0 { + // Try to parse the method name as an identifier. Having a keyword is ok + // unless it is `crate`, `self`, `super` or `Self`, so we try to add the `_` + // suffix to it and parse it. + if ["crate", "self", "super", "Self"].contains(&name) { + Some(Ident::new( + &format!("{}_", name), + Span::call_site(), + )) + } else { + Some(Ident::new(name, Span::call_site())) + } } else { - // Try to parse the current name as an identifier. This might fail if the - // name is a keyword so we try to prepend "r#" to it and parse again. If - // this also fails, we panic with the first error. + // Try to parse the current joining name as an identifier. This might fail if the name + // is a keyword, so we try to "r#" to it and parse again, this could also fail + // if the name is `crate`, `self`, `super` or `Self`, so we try to add the `_` + // suffix to it and parse again. If this also fails, we panic with the first + // error. Some( syn::parse_str::(name) .or_else(|err| { syn::parse_str::(&format!("r#{}", name)) .map_err(|_| err) }) + .or_else(|err| { + syn::parse_str::(&format!("{}_", name)) + .map_err(|_| err) + }) .expect("Invalid identifier"), ) } diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index e3ef6a9c9661ec7cf4b10beff5666170257df4a0..59bd4bfde4cd4491fe63d21399546e0dd4ce0835 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -4,7 +4,7 @@ //! brief definitions: //! //! * "Template definition": a class/struct/alias/function definition that takes -//! generic template parameters. For example: +//! generic template parameters. For example: //! //! ```c++ //! template @@ -14,11 +14,11 @@ //! ``` //! //! * "Template instantiation": an instantiation is a use of a template with -//! concrete template arguments. For example, `List`. +//! concrete template arguments. For example, `List`. //! //! * "Template specialization": an alternative template definition providing a -//! custom definition for instantiations with the matching template -//! arguments. This C++ feature is unsupported by bindgen. For example: +//! custom definition for instantiations with the matching template +//! arguments. This C++ feature is unsupported by bindgen. For example: //! //! ```c++ //! template<> @@ -77,28 +77,28 @@ use crate::clang; /// The following table depicts the results of each trait method when invoked on /// each of the declarations above: /// -/// +------+----------------------+--------------------------+------------------------+---- -/// |Decl. | self_template_params | num_self_template_params | all_template_parameters| ... -/// +------+----------------------+--------------------------+------------------------+---- -/// |Foo | [T, U] | 2 | [T, U] | ... -/// |Bar | [V] | 1 | [T, U, V] | ... -/// |Inner | [] | 0 | [T, U] | ... -/// |Lol | [W] | 1 | [T, U, W] | ... -/// |Wtf | [X] | 1 | [T, U, X] | ... -/// |Qux | [] | 0 | [] | ... +/// +------+----------------------+--------------------------+-------------------------+---- +/// |Decl. | self_template_params | num_self_template_params | all_template_parameters | ... +/// +------+----------------------+--------------------------+-------------------------+---- +/// |Foo | T, U | 2 | T, U | ... +/// |Bar | V | 1 | T, U, V | ... +/// |Inner | | 0 | T, U | ... +/// |Lol | W | 1 | T, U, W | ... +/// |Wtf | X | 1 | T, U, X | ... +/// |Qux | | 0 | | ... /// +------+----------------------+--------------------------+------------------------+---- /// /// ----+------+-----+----------------------+ /// ... |Decl. | ... | used_template_params | /// ----+------+-----+----------------------+ -/// ... |Foo | ... | [T, U] | -/// ... |Bar | ... | [V] | -/// ... |Inner | ... | [] | -/// ... |Lol | ... | [T] | -/// ... |Wtf | ... | [T] | -/// ... |Qux | ... | [] | +/// ... |Foo | ... | T, U | +/// ... |Bar | ... | V | +/// ... |Inner | ... | | +/// ... |Lol | ... | T | +/// ... |Wtf | ... | T | +/// ... |Qux | ... | | /// ----+------+-----+----------------------+ -pub trait TemplateParameters: Sized { +pub(crate) trait TemplateParameters: Sized { /// Get the set of `ItemId`s that make up this template declaration's free /// template parameters. /// @@ -163,11 +163,11 @@ pub trait TemplateParameters: Sized { } /// A trait for things which may or may not be a named template type parameter. -pub trait AsTemplateParam { +pub(crate) trait AsTemplateParam { /// Any extra information the implementor might need to make this decision. type Extra; - /// Convert this thing to the item id of a named template type parameter. + /// Convert this thing to the item ID of a named template type parameter. fn as_template_param( &self, ctx: &BindgenContext, @@ -186,7 +186,7 @@ pub trait AsTemplateParam { /// A concrete instantiation of a generic template. #[derive(Clone, Debug)] -pub struct TemplateInstantiation { +pub(crate) struct TemplateInstantiation { /// The template definition which this is instantiating. definition: TypeId, /// The concrete template arguments, which will be substituted in the @@ -196,7 +196,7 @@ pub struct TemplateInstantiation { impl TemplateInstantiation { /// Construct a new template instantiation from the given parts. - pub fn new(definition: TypeId, args: I) -> TemplateInstantiation + pub(crate) fn new(definition: TypeId, args: I) -> TemplateInstantiation where I: IntoIterator, { @@ -207,17 +207,17 @@ impl TemplateInstantiation { } /// Get the template definition for this instantiation. - pub fn template_definition(&self) -> TypeId { + pub(crate) fn template_definition(&self) -> TypeId { self.definition } /// Get the concrete template arguments used in this instantiation. - pub fn template_arguments(&self) -> &[TypeId] { + pub(crate) fn template_arguments(&self) -> &[TypeId] { &self.args[..] } /// Parse a `TemplateInstantiation` from a clang `Type`. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, ctx: &mut BindgenContext, ) -> Option { diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index f14483f295a8e31c20c4339db433e424bcdc9658..17e24f701ecf1d4b44d65bd08099247cd08d47d6 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -12,14 +12,14 @@ use std::collections::{BTreeMap, VecDeque}; /// The `from` is left implicit: it is the concrete `Trace` implementer which /// yielded this outgoing edge. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Edge { +pub(crate) struct Edge { to: ItemId, kind: EdgeKind, } impl Edge { /// Construct a new edge whose referent is `to` and is of the given `kind`. - pub fn new(to: ItemId, kind: EdgeKind) -> Edge { + pub(crate) fn new(to: ItemId, kind: EdgeKind) -> Edge { Edge { to, kind } } } @@ -33,7 +33,7 @@ impl From for ItemId { /// The kind of edge reference. This is useful when we wish to only consider /// certain kinds of edges for a particular traversal or analysis. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum EdgeKind { +pub(crate) enum EdgeKind { /// A generic, catch-all edge. Generic, @@ -182,12 +182,13 @@ pub enum EdgeKind { /// /// The predicate must return true if the traversal should follow this edge /// and visit everything that is reachable through it. -pub type TraversalPredicate = for<'a> fn(&'a BindgenContext, Edge) -> bool; +pub(crate) type TraversalPredicate = + for<'a> fn(&'a BindgenContext, Edge) -> bool; /// A `TraversalPredicate` implementation that follows all edges, and therefore /// traversals using this predicate will see the whole IR graph reachable from /// the traversal's roots. -pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { +pub(crate) fn all_edges(_: &BindgenContext, _: Edge) -> bool { true } @@ -196,14 +197,14 @@ pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { /// will only visit the traversal's roots and their inner types. This is used /// in no-recursive-allowlist mode, where inner types such as anonymous /// structs/unions still need to be processed. -pub fn only_inner_type_edges(_: &BindgenContext, edge: Edge) -> bool { +pub(crate) fn only_inner_type_edges(_: &BindgenContext, edge: Edge) -> bool { edge.kind == EdgeKind::InnerType } /// A `TraversalPredicate` implementation that only follows edges to items that /// are enabled for code generation. This lets us skip considering items for /// which are not reachable from code generation. -pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { +pub(crate) fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { let cc = &ctx.options().codegen_config; match edge.kind { EdgeKind::Generic => { @@ -233,7 +234,7 @@ pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { /// The storage for the set of items that have been seen (although their /// outgoing edges might not have been fully traversed yet) in an active /// traversal. -pub trait TraversalStorage<'ctx> { +pub(crate) trait TraversalStorage<'ctx> { /// Construct a new instance of this TraversalStorage, for a new traversal. fn new(ctx: &'ctx BindgenContext) -> Self; @@ -259,7 +260,7 @@ impl<'ctx> TraversalStorage<'ctx> for ItemSet { /// each item. This is useful for providing debug assertions with meaningful /// diagnostic messages about dangling items. #[derive(Debug)] -pub struct Paths<'ctx>(BTreeMap, &'ctx BindgenContext); +pub(crate) struct Paths<'ctx>(BTreeMap, &'ctx BindgenContext); impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { fn new(ctx: &'ctx BindgenContext) -> Self { @@ -300,7 +301,7 @@ impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { /// Using a FIFO queue with a traversal will yield a breadth-first traversal, /// while using a LIFO queue will result in a depth-first traversal of the IR /// graph. -pub trait TraversalQueue: Default { +pub(crate) trait TraversalQueue: Default { /// Add a newly discovered item to the queue. fn push(&mut self, item: ItemId); @@ -329,7 +330,7 @@ impl TraversalQueue for VecDeque { } /// Something that can receive edges from a `Trace` implementation. -pub trait Tracer { +pub(crate) trait Tracer { /// Note an edge between items. Called from within a `Trace` implementation. fn visit_kind(&mut self, item: ItemId, kind: EdgeKind); @@ -351,7 +352,7 @@ where /// Trace all of the outgoing edges to other items. Implementations should call /// one of `tracer.visit(edge)` or `tracer.visit_kind(edge, EdgeKind::Whatever)` /// for each of their outgoing edges. -pub trait Trace { +pub(crate) trait Trace { /// If a particular type needs extra information beyond what it has in /// `self` and `context` to find its referenced items, its implementation /// can define this associated type, forcing callers to pass the needed @@ -371,7 +372,7 @@ pub trait Trace { /// An graph traversal of the transitive closure of references between items. /// /// See `BindgenContext::allowlisted_items` for more information. -pub struct ItemTraversal<'ctx, Storage, Queue> +pub(crate) struct ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, @@ -397,7 +398,7 @@ where Queue: TraversalQueue, { /// Begin a new traversal, starting from the given roots. - pub fn new( + pub(crate) fn new( ctx: &'ctx BindgenContext, roots: R, predicate: TraversalPredicate, @@ -474,5 +475,5 @@ where /// /// See `BindgenContext::assert_no_dangling_item_traversal` for more /// information. -pub type AssertNoDanglingItemsTraversal<'ctx> = +pub(crate) type AssertNoDanglingItemsTraversal<'ctx> = ItemTraversal<'ctx, Paths<'ctx>, VecDeque>; diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fef340dee9b10d98f1af438ec4b90b7816d1f051..2a24dd0291426333ddbd9e517e09e731c9efb168 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -5,7 +5,6 @@ use super::context::{BindgenContext, ItemId, TypeId}; use super::dot::DotAttributes; use super::enum_ty::Enum; use super::function::FunctionSig; -use super::int::IntKind; use super::item::{IsOpaque, Item}; use super::layout::{Layout, Opaque}; use super::objc::ObjCInterface; @@ -18,13 +17,15 @@ use crate::parse::{ParseError, ParseResult}; use std::borrow::Cow; use std::io; +pub use super::int::IntKind; + /// The base representation of a type in bindgen. /// /// A type has an optional name, which if present cannot be empty, a `layout` /// (size, alignment and packedness) if known, a `Kind`, which determines which /// kind of type it is, and whether the type is const. #[derive(Debug)] -pub struct Type { +pub(crate) struct Type { /// The name of the type, or None if it was an unnamed struct or union. name: Option, /// The layout of the type, if known. @@ -39,21 +40,12 @@ pub struct Type { /// traits, and so if we have a type containing an array with more than this /// many items, we won't be able to derive common traits on that type. /// -pub const RUST_DERIVE_IN_ARRAY_LIMIT: usize = 32; +pub(crate) const RUST_DERIVE_IN_ARRAY_LIMIT: usize = 32; impl Type { - /// Get the underlying `CompInfo` for this type, or `None` if this is some - /// other kind of type. - pub fn as_comp(&self) -> Option<&CompInfo> { - match self.kind { - TypeKind::Comp(ref ci) => Some(ci), - _ => None, - } - } - /// Get the underlying `CompInfo` for this type as a mutable reference, or /// `None` if this is some other kind of type. - pub fn as_comp_mut(&mut self) -> Option<&mut CompInfo> { + pub(crate) fn as_comp_mut(&mut self) -> Option<&mut CompInfo> { match self.kind { TypeKind::Comp(ref mut ci) => Some(ci), _ => None, @@ -61,7 +53,7 @@ impl Type { } /// Construct a new `Type`. - pub fn new( + pub(crate) fn new( name: Option, layout: Option, kind: TypeKind, @@ -76,37 +68,37 @@ impl Type { } /// Which kind of type is this? - pub fn kind(&self) -> &TypeKind { + pub(crate) fn kind(&self) -> &TypeKind { &self.kind } /// Get a mutable reference to this type's kind. - pub fn kind_mut(&mut self) -> &mut TypeKind { + pub(crate) fn kind_mut(&mut self) -> &mut TypeKind { &mut self.kind } /// Get this type's name. - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { self.name.as_deref() } /// Whether this is a block pointer type. - pub fn is_block_pointer(&self) -> bool { + pub(crate) fn is_block_pointer(&self) -> bool { matches!(self.kind, TypeKind::BlockPointer(..)) } /// Is this an integer type, including `bool` or `char`? - pub fn is_int(&self) -> bool { + pub(crate) fn is_int(&self) -> bool { matches!(self.kind, TypeKind::Int(_)) } /// Is this a compound type? - pub fn is_comp(&self) -> bool { + pub(crate) fn is_comp(&self) -> bool { matches!(self.kind, TypeKind::Comp(..)) } /// Is this a union? - pub fn is_union(&self) -> bool { + pub(crate) fn is_union(&self) -> bool { match self.kind { TypeKind::Comp(ref comp) => comp.is_union(), _ => false, @@ -114,32 +106,31 @@ impl Type { } /// Is this type of kind `TypeKind::TypeParam`? - pub fn is_type_param(&self) -> bool { + pub(crate) fn is_type_param(&self) -> bool { matches!(self.kind, TypeKind::TypeParam) } /// Is this a template instantiation type? - pub fn is_template_instantiation(&self) -> bool { + pub(crate) fn is_template_instantiation(&self) -> bool { matches!(self.kind, TypeKind::TemplateInstantiation(..)) } - /// Is this a template alias type? - pub fn is_template_alias(&self) -> bool { - matches!(self.kind, TypeKind::TemplateAlias(..)) - } - /// Is this a function type? - pub fn is_function(&self) -> bool { + pub(crate) fn is_function(&self) -> bool { matches!(self.kind, TypeKind::Function(..)) } /// Is this an enum type? - pub fn is_enum(&self) -> bool { + pub(crate) fn is_enum(&self) -> bool { matches!(self.kind, TypeKind::Enum(..)) } + /// Is this void? + pub(crate) fn is_void(&self) -> bool { + matches!(self.kind, TypeKind::Void) + } /// Is this either a builtin or named type? - pub fn is_builtin_or_type_param(&self) -> bool { + pub(crate) fn is_builtin_or_type_param(&self) -> bool { matches!( self.kind, TypeKind::Void | @@ -155,29 +146,29 @@ impl Type { } /// Creates a new named type, with name `name`. - pub fn named(name: String) -> Self { + pub(crate) fn named(name: String) -> Self { let name = if name.is_empty() { None } else { Some(name) }; Self::new(name, None, TypeKind::TypeParam, false) } /// Is this a floating point type? - pub fn is_float(&self) -> bool { + pub(crate) fn is_float(&self) -> bool { matches!(self.kind, TypeKind::Float(..)) } /// Is this a boolean type? - pub fn is_bool(&self) -> bool { + pub(crate) fn is_bool(&self) -> bool { matches!(self.kind, TypeKind::Int(IntKind::Bool)) } /// Is this an integer type? - pub fn is_integer(&self) -> bool { + pub(crate) fn is_integer(&self) -> bool { matches!(self.kind, TypeKind::Int(..)) } /// Cast this type to an integer kind, or `None` if it is not an integer /// type. - pub fn as_integer(&self) -> Option { + pub(crate) fn as_integer(&self) -> Option { match self.kind { TypeKind::Int(int_kind) => Some(int_kind), _ => None, @@ -185,25 +176,20 @@ impl Type { } /// Is this a `const` qualified type? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } - /// Is this a reference to another type? - pub fn is_type_ref(&self) -> bool { - matches!( - self.kind, - TypeKind::ResolvedTypeRef(_) | TypeKind::UnresolvedTypeRef(_, _, _) - ) - } - /// Is this an unresolved reference? - pub fn is_unresolved_ref(&self) -> bool { + pub(crate) fn is_unresolved_ref(&self) -> bool { matches!(self.kind, TypeKind::UnresolvedTypeRef(_, _, _)) } /// Is this a incomplete array type? - pub fn is_incomplete_array(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn is_incomplete_array( + &self, + ctx: &BindgenContext, + ) -> Option { match self.kind { TypeKind::Array(item, len) => { if len == 0 { @@ -220,13 +206,14 @@ impl Type { } /// What is the layout of this type? - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { self.layout.or_else(|| { match self.kind { TypeKind::Comp(ref ci) => ci.layout(ctx), - TypeKind::Array(inner, length) if length == 0 => Some( - Layout::new(0, ctx.resolve_type(inner).layout(ctx)?.align), - ), + TypeKind::Array(inner, 0) => Some(Layout::new( + 0, + ctx.resolve_type(inner).layout(ctx)?.align, + )), // FIXME(emilio): This is a hack for anonymous union templates. // Use the actual pointer size! TypeKind::Pointer(..) => Some(Layout::new( @@ -245,7 +232,7 @@ impl Type { /// avoid generating invalid code with some cases we can't handle, see: /// /// tests/headers/381-decltype-alias.hpp - pub fn is_invalid_type_param(&self) -> bool { + pub(crate) fn is_invalid_type_param(&self) -> bool { match self.kind { TypeKind::TypeParam => { let name = self.name().expect("Unnamed named type?"); @@ -265,8 +252,8 @@ impl Type { Cow::Owned(name) } - /// Get this type's santizied name. - pub fn sanitized_name<'a>( + /// Get this type's sanitized name. + pub(crate) fn sanitized_name<'a>( &'a self, ctx: &BindgenContext, ) -> Option> { @@ -289,7 +276,7 @@ impl Type { } /// See safe_canonical_type. - pub fn canonical_type<'tr>( + pub(crate) fn canonical_type<'tr>( &'tr self, ctx: &'tr BindgenContext, ) -> &'tr Type { @@ -302,7 +289,7 @@ impl Type { /// For example, for a `typedef`, the canonical type would be the /// `typedef`ed type, for a template instantiation, would be the template /// its specializing, and so on. Return None if the type is unresolved. - pub fn safe_canonical_type<'tr>( + pub(crate) fn safe_canonical_type<'tr>( &'tr self, ctx: &'tr BindgenContext, ) -> Option<&'tr Type> { @@ -341,7 +328,7 @@ impl Type { /// There are some types we don't want to stop at when finding an opaque /// item, so we can arrive to the proper item that needs to be generated. - pub fn should_be_traced_unconditionally(&self) -> bool { + pub(crate) fn should_be_traced_unconditionally(&self) -> bool { matches!( self.kind, TypeKind::Comp(..) | @@ -511,7 +498,7 @@ fn is_invalid_type_param_invalid_start() { } #[test] -fn is_invalid_type_param_invalid_remaing() { +fn is_invalid_type_param_invalid_remaining() { let ty = Type::new(Some("foo-".into()), None, TypeKind::TypeParam, false); assert!(ty.is_invalid_type_param()) } @@ -570,7 +557,9 @@ impl TemplateParameters for TypeKind { /// The kind of float this type represents. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum FloatKind { +pub(crate) enum FloatKind { + /// A half (`_Float16` or `__fp16`) + Float16, /// A `float`. Float, /// A `double`. @@ -583,7 +572,7 @@ pub enum FloatKind { /// The different kinds of types that we can parse. #[derive(Debug)] -pub enum TypeKind { +pub(crate) enum TypeKind { /// The void type. Void, @@ -680,7 +669,7 @@ impl Type { /// /// It's sort of nasty and full of special-casing, but hopefully the /// comments in every special case justify why they're there. - pub fn from_clang_ty( + pub(crate) fn from_clang_ty( potential_id: ItemId, ty: &clang::Type, location: Cursor, @@ -730,7 +719,7 @@ impl Type { // Objective C template type parameter // FIXME: This is probably wrong, we are attempting to find the // objc template params, which seem to manifest as a typedef. - // We are rewriting them as id to suppress multiple conflicting + // We are rewriting them as ID to suppress multiple conflicting // typedefs at root level if ty_kind == CXType_Typedef { let is_template_type_param = @@ -1103,7 +1092,7 @@ impl Type { Item::from_ty_or_ref(inner, location, None, ctx); if inner_id == potential_id { warn!( - "Generating oqaque type instead of self-referential \ + "Generating opaque type instead of self-referential \ typedef"); // This can happen if we bail out of recursive situations // within the clang parsing. diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 903e1ff549df8518319c30445b1bba1c06b3d294..07ce3d784a0bcfa08267130ea8271e8418faea72 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -11,13 +11,13 @@ use crate::callbacks::{ItemInfo, ItemKind, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use cexpr; + use std::io; use std::num::Wrapping; /// The type for a constant variable. #[derive(Debug)] -pub enum VarType { +pub(crate) enum VarType { /// A boolean. Bool(bool), /// An integer. @@ -32,11 +32,13 @@ pub enum VarType { /// A `Var` is our intermediate representation of a variable. #[derive(Debug)] -pub struct Var { +pub(crate) struct Var { /// The name of the variable. name: String, /// The mangled name of the variable. mangled_name: Option, + /// The link name of the variable. + link_name: Option, /// The type of the variable. ty: TypeId, /// The value of the variable, that needs to be suitable for `ty`. @@ -47,9 +49,10 @@ pub struct Var { impl Var { /// Construct a new `Var`. - pub fn new( + pub(crate) fn new( name: String, mangled_name: Option, + link_name: Option, ty: TypeId, val: Option, is_const: bool, @@ -58,6 +61,7 @@ impl Var { Var { name, mangled_name, + link_name, ty, val, is_const, @@ -65,29 +69,34 @@ impl Var { } /// Is this variable `const` qualified? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } /// The value of this constant variable, if any. - pub fn val(&self) -> Option<&VarType> { + pub(crate) fn val(&self) -> Option<&VarType> { self.val.as_ref() } /// Get this variable's type. - pub fn ty(&self) -> TypeId { + pub(crate) fn ty(&self) -> TypeId { self.ty } /// Get this variable's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this variable's mangled name. - pub fn mangled_name(&self) -> Option<&str> { + pub(crate) fn mangled_name(&self) -> Option<&str> { self.mangled_name.as_deref() } + + /// Get this variable's link name. + pub fn link_name(&self) -> Option<&str> { + self.link_name.as_deref() + } } impl DotAttributes for Var { @@ -120,27 +129,23 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { ctx.options().default_macro_constant_type == MacroTypeVariation::Signed { - if value < i32::min_value() as i64 || value > i32::max_value() as i64 { + if value < i32::MIN as i64 || value > i32::MAX as i64 { IntKind::I64 } else if !ctx.options().fit_macro_constants || - value < i16::min_value() as i64 || - value > i16::max_value() as i64 + value < i16::MIN as i64 || + value > i16::MAX as i64 { IntKind::I32 - } else if value < i8::min_value() as i64 || - value > i8::max_value() as i64 - { + } else if value < i8::MIN as i64 || value > i8::MAX as i64 { IntKind::I16 } else { IntKind::I8 } - } else if value > u32::max_value() as i64 { + } else if value > u32::MAX as i64 { IntKind::U64 - } else if !ctx.options().fit_macro_constants || - value > u16::max_value() as i64 - { + } else if !ctx.options().fit_macro_constants || value > u16::MAX as i64 { IntKind::U32 - } else if value > u8::max_value() as i64 { + } else if value > u8::MAX as i64 { IntKind::U16 } else { IntKind::U8 @@ -213,7 +218,7 @@ impl ClangSubItemParser for Var { if previously_defined { let name = String::from_utf8(id).unwrap(); - warn!("Duplicated macro definition: {}", name); + duplicated_macro_diagnostic(&name, cursor.location(), ctx); return Err(ParseError::Continue); } @@ -234,7 +239,7 @@ impl ClangSubItemParser for Var { c as u8 } CChar::Raw(c) => { - assert!(c <= ::std::u8::MAX as u64); + assert!(c <= u8::MAX as u64); c as u8 } }; @@ -267,7 +272,7 @@ impl ClangSubItemParser for Var { let ty = Item::builtin_type(type_kind, true, ctx); Ok(ParseResult::New( - Var::new(name, None, ty, Some(val), true), + Var::new(name, None, None, ty, Some(val), true), Some(cursor), )) } @@ -291,6 +296,13 @@ impl ClangSubItemParser for Var { return Err(ParseError::Continue); } + let link_name = ctx.options().last_callback(|callbacks| { + callbacks.generated_link_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Var, + }) + }); + let ty = cursor.cur_type(); // TODO(emilio): do we have to special-case constant arrays in @@ -360,7 +372,8 @@ impl ClangSubItemParser for Var { }; let mangling = cursor_mangling(ctx, &cursor); - let var = Var::new(name, mangling, ty, value, is_const); + let var = + Var::new(name, mangling, link_name, ty, value, is_const); Ok(ParseResult::New(var, Some(cursor))) } @@ -372,9 +385,51 @@ impl ClangSubItemParser for Var { } } +/// This function uses a [`FallbackTranslationUnit`][clang::FallbackTranslationUnit] to parse each +/// macro that cannot be parsed by the normal bindgen process for `#define`s. +/// +/// To construct the [`FallbackTranslationUnit`][clang::FallbackTranslationUnit], first precompiled +/// headers are generated for all input headers. An empty temporary `.c` file is generated to pass +/// to the translation unit. On the evaluation of each macro, a [`String`] is generated with the +/// new contents of the empty file and passed in for reparsing. The precompiled headers and +/// preservation of the [`FallbackTranslationUnit`][clang::FallbackTranslationUnit] across macro +/// evaluations are both optimizations that have significantly improved the performance. +fn parse_macro_clang_fallback( + ctx: &mut BindgenContext, + cursor: &clang::Cursor, +) -> Option<(Vec, cexpr::expr::EvalResult)> { + if !ctx.options().clang_macro_fallback { + return None; + } + + let ftu = ctx.try_ensure_fallback_translation_unit()?; + let contents = format!("int main() {{ {}; }}", cursor.spelling(),); + ftu.reparse(&contents).ok()?; + // Children of root node of AST + let root_children = ftu.translation_unit().cursor().collect_children(); + // Last child in root is function declaration + // Should be FunctionDecl + let main_func = root_children.last()?; + // Children should all be statements in function declaration + let all_stmts = main_func.collect_children(); + // First child in all_stmts should be the statement containing the macro to evaluate + // Should be CompoundStmt + let macro_stmt = all_stmts.first()?; + // Children should all be expressions from the compound statement + let paren_exprs = macro_stmt.collect_children(); + // First child in all_exprs is the expression utilizing the given macro to be evaluated + // Should be ParenExpr + let paren = paren_exprs.first()?; + + Some(( + cursor.spelling().into_bytes(), + cexpr::expr::EvalResult::Int(Wrapping(paren.evaluate()?.as_int()?)), + )) +} + /// Try and parse a macro using all the macros parsed until now. fn parse_macro( - ctx: &BindgenContext, + ctx: &mut BindgenContext, cursor: &clang::Cursor, ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; @@ -385,7 +440,7 @@ fn parse_macro( match parser.macro_definition(&cexpr_tokens) { Ok((_, (id, val))) => Some((id.into(), val)), - _ => None, + _ => parse_macro_clang_fallback(ctx, cursor), } } @@ -423,3 +478,49 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { }); value } + +fn duplicated_macro_diagnostic( + macro_name: &str, + _location: crate::clang::SourceLocation, + _ctx: &BindgenContext, +) { + warn!("Duplicated macro definition: {}", macro_name); + + // #[cfg(feature = "experimental")] + // FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually + // useful. We have to change the logic where this function is called to be able to emit this + // message only when the duplication is an actual issue. + // + // If I understood correctly, `bindgen` ignores all `#undef` directives. Meaning that this: + // ```c + // #define FOO 1 + // #undef FOO + // #define FOO 2 + // ``` + // + // Will trigger this message even though there's nothing wrong with it. + // #[allow(clippy::overly_complex_bool_expr)] + // if false && _ctx.options().emit_diagnostics { + // use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + // use std::borrow::Cow; + + // let mut slice = Slice::default(); + // let mut source = Cow::from(macro_name); + + // let (file, line, col, _) = _location.location(); + // if let Some(filename) = file.name() { + // if let Ok(Some(code)) = get_line(&filename, line) { + // source = code.into(); + // } + // slice.with_location(filename, line, col); + // } + + // slice.with_source(source); + + // Diagnostic::default() + // .with_title("Duplicated macro definition.", Level::Warn) + // .add_slice(slice) + // .add_annotation("This macro had a duplicate.", Level::Note) + // .display(); + // } +} diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 537474201684377f3425f0017fe03a61fadf467f..affe38e4f306be134d8305e0677c449ebeffaf4f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -9,6 +9,7 @@ //! additional documentation. #![deny(missing_docs)] #![deny(unused_extern_crates)] +#![deny(clippy::disallowed_methods)] // To avoid rather annoying warnings when matching with CXCursor_xxx as a // constant. #![allow(non_upper_case_globals)] @@ -18,8 +19,6 @@ #[macro_use] extern crate bitflags; #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate quote; #[cfg(feature = "logging")] @@ -33,82 +32,58 @@ mod log_stubs; #[macro_use] mod extra_assertions; -// A macro to declare an internal module for which we *must* provide -// documentation for. If we are building with the "testing_only_docs" feature, -// then the module is declared public, and our `#![deny(missing_docs)]` pragma -// applies to it. This feature is used in CI, so we won't let anything slip by -// undocumented. Normal builds, however, will leave the module private, so that -// we don't expose internals to library consumers. -macro_rules! doc_mod { - ($m:ident, $doc_mod_name:ident) => { - #[cfg(feature = "testing_only_docs")] - pub mod $doc_mod_name { - //! Autogenerated documentation module. - pub use super::$m::*; - } - }; -} +mod codegen; +mod deps; +mod options; +mod time; -macro_rules! fn_with_regex_arg { - ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { - $(#[$attrs])* - /// Check the [regular expression arguments] section and the [regex] crate - /// documentation for further information. - /// - /// [regular expression arguments]: ./struct.Builder.html#regular-expression-arguments - /// [regex]: - pub fn $($tokens)* - }; -} +pub mod callbacks; mod clang; -mod codegen; -mod deps; +#[cfg(feature = "experimental")] +// mod diagnostics; mod features; -pub mod ir; +mod ir; mod parse; mod regex_set; -mod time; - -pub mod callbacks; -doc_mod!(clang, clang_docs); -doc_mod!(features, features_docs); -doc_mod!(ir, ir_docs); -doc_mod!(parse, parse_docs); -doc_mod!(regex_set, regex_set_docs); +pub use codegen::{ + AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, +}; +// #[cfg(feature = "__cli")] +pub use features::RUST_TARGET_STRINGS; +pub use features::{RustTarget, LATEST_STABLE_RUST}; +pub use ir::annotations::FieldVisibilityKind; +pub use ir::function::Abi; +pub use regex_set::RegexSet; use codegen::CodegenError; +use features::RustFeatures; use ir::comment; - -pub use crate::codegen::{ - AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, -}; -use crate::features::RustFeatures; -pub use crate::features::{ - RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, -}; -use crate::ir::context::{BindgenContext, ItemId}; -pub use crate::ir::function::Abi; -use crate::ir::item::Item; -use crate::parse::ParseError; -pub use crate::regex_set::RegexSet; +use ir::context::{BindgenContext, ItemId}; +use ir::item::Item; +use options::BindgenOptions; +use parse::ParseError; use std::borrow::Cow; +use std::collections::hash_map::Entry; use std::env; +use std::ffi::OsStr; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; +use std::str::FromStr; +use std::sync::{Arc, OnceLock}; // Some convenient typedefs for a fast hash map and hash set. -type HashMap = ::rustc_hash::FxHashMap; -type HashSet = ::rustc_hash::FxHashSet; -pub(crate) use std::collections::hash_map::Entry; +type HashMap = rustc_hash::FxHashMap; +type HashSet = rustc_hash::FxHashSet; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; + const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { @@ -118,15 +93,15 @@ fn file_is_cpp(name_file: &str) -> bool { name_file.ends_with(".h++") } -fn args_are_cpp(clang_args: &[String]) -> bool { +fn args_are_cpp(clang_args: &[Box]) -> bool { for w in clang_args.windows(2) { - if w[0] == "-xc++" || w[1] == "-xc++" { + if w[0].as_ref() == "-xc++" || w[1].as_ref() == "-xc++" { return true; } - if w[0] == "-x" && w[1] == "c++" { + if w[0].as_ref() == "-x" && w[1].as_ref() == "c++" { return true; } - if w[0] == "-include" && file_is_cpp(&w[1]) { + if w[0].as_ref() == "-include" && file_is_cpp(w[1].as_ref()) { return true; } } @@ -135,6 +110,7 @@ fn args_are_cpp(clang_args: &[String]) -> bool { bitflags! { /// A type used to indicate which kind of items we have to generate. + // #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CodegenConfig: u32 { /// Whether to generate functions. const FUNCTIONS = 1 << 0; @@ -167,7 +143,7 @@ impl CodegenConfig { self.contains(CodegenConfig::VARS) } - /// Returns true if methds should be generated. + /// Returns true if methods should be generated. pub fn methods(self) -> bool { self.contains(CodegenConfig::METHODS) } @@ -189,6 +165,52 @@ impl Default for CodegenConfig { } } +/// Formatting tools that can be used to format the bindings +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[non_exhaustive] +pub enum Formatter { + /// Do not format the bindings. + None, + /// Use `rustfmt` to format the bindings. + Rustfmt, + #[cfg(feature = "prettyplease")] + /// Use `prettyplease` to format the bindings. + Prettyplease, +} + +impl Default for Formatter { + fn default() -> Self { + Self::Rustfmt + } +} + +impl FromStr for Formatter { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "none" => Ok(Self::None), + "rustfmt" => Ok(Self::Rustfmt), + #[cfg(feature = "prettyplease")] + "prettyplease" => Ok(Self::Prettyplease), + _ => Err(format!("`{}` is not a valid formatter", s)), + } + } +} + +impl std::fmt::Display for Formatter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match self { + Self::None => "none", + Self::Rustfmt => "rustfmt", + #[cfg(feature = "prettyplease")] + Self::Prettyplease => "prettyplease", + }; + + s.fmt(f) + } +} + /// Configure and generate Rust bindings for a C/C++ header. /// /// This is the main entry point to the library. @@ -209,1990 +231,229 @@ impl Default for CodegenConfig { /// # Enums /// /// Bindgen can map C/C++ enums into Rust in different ways. The way bindgen maps enums depends on -/// the pattern passed to several methods: -/// -/// 1. [`constified_enum_module()`](#method.constified_enum_module) -/// 2. [`bitfield_enum()`](#method.bitfield_enum) -/// 3. [`newtype_enum()`](#method.newtype_enum) -/// 4. [`rustified_enum()`](#method.rustified_enum) -/// -/// For each C enum, bindgen tries to match the pattern in the following order: -/// -/// 1. Constified enum module -/// 2. Bitfield enum -/// 3. Newtype enum -/// 4. Rustified enum -/// -/// If none of the above patterns match, then bindgen will generate a set of Rust constants. -/// -/// # Clang arguments -/// -/// Extra arguments can be passed to with clang: -/// 1. [`clang_arg()`](#method.clang_arg): takes a single argument -/// 2. [`clang_args()`](#method.clang_args): takes an iterator of arguments -/// 3. `BINDGEN_EXTRA_CLANG_ARGS` environment variable: whitespace separate -/// environment variable of arguments -/// -/// Clang arguments specific to your crate should be added via the -/// `clang_arg()`/`clang_args()` methods. -/// -/// End-users of the crate may need to set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to -/// add additional arguments. For example, to build against a different sysroot a user could set -/// `BINDGEN_EXTRA_CLANG_ARGS` to `--sysroot=/path/to/sysroot`. -/// -/// # Regular expression arguments -/// -/// Some [`Builder`] methods like the `allowlist_*` and `blocklist_*` family of methods allow -/// regular expressions as arguments. These regular expressions will be parenthesized and wrapped -/// in `^` and `$`. So if `` is passed as argument, the regular expression to be stored will -/// be `^()$`. -/// -/// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard -/// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*` -/// pattern must be used instead. -#[derive(Debug, Default, Clone)] -pub struct Builder { - options: BindgenOptions, -} - -/// Construct a new [`Builder`](./struct.Builder.html). -pub fn builder() -> Builder { - Default::default() -} - -fn get_extra_clang_args() -> Vec { - // Add any extra arguments from the environment to the clang command line. - let extra_clang_args = - match get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") { - None => return vec![], - Some(s) => s, - }; - // Try to parse it with shell quoting. If we fail, make it one single big argument. - if let Some(strings) = shlex::split(&extra_clang_args) { - return strings; - } - vec![extra_clang_args] -} - -impl Builder { - /// Generates the command line flags use for creating `Builder`. - pub fn command_line_flags(&self) -> Vec { - let mut output_vector: Vec = Vec::new(); - - if let Some(header) = self.options.input_headers.last().cloned() { - // Positional argument 'header' - output_vector.push(header); - } - - output_vector.push("--rust-target".into()); - output_vector.push(self.options.rust_target.into()); - - // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the - // RustFeatures to store the "disable_untagged_union" call, and make it - // a different flag that we check elsewhere / in generate(). - if !self.options.rust_features.untagged_union && - RustFeatures::from(self.options.rust_target).untagged_union - { - output_vector.push("--disable-untagged-union".into()); - } - - if self.options.default_enum_style != Default::default() { - output_vector.push("--default-enum-style".into()); - output_vector.push( - match self.options.default_enum_style { - codegen::EnumVariation::Rust { - non_exhaustive: false, - } => "rust", - codegen::EnumVariation::Rust { - non_exhaustive: true, - } => "rust_non_exhaustive", - codegen::EnumVariation::NewType { - is_bitfield: true, - .. - } => "bitfield", - codegen::EnumVariation::NewType { - is_bitfield: false, - is_global, - } => { - if is_global { - "newtype_global" - } else { - "newtype" - } - } - codegen::EnumVariation::Consts => "consts", - codegen::EnumVariation::ModuleConsts => "moduleconsts", - } - .into(), - ) - } - - if self.options.default_macro_constant_type != Default::default() { - output_vector.push("--default-macro-constant-type".into()); - output_vector - .push(self.options.default_macro_constant_type.as_str().into()); - } - - if self.options.default_alias_style != Default::default() { - output_vector.push("--default-alias-style".into()); - output_vector - .push(self.options.default_alias_style.as_str().into()); - } - - if self.options.default_non_copy_union_style != Default::default() { - output_vector.push("--default-non-copy-union-style".into()); - output_vector.push( - self.options.default_non_copy_union_style.as_str().into(), - ); - } - - let regex_sets = &[ - (&self.options.bitfield_enums, "--bitfield-enum"), - (&self.options.newtype_enums, "--newtype-enum"), - (&self.options.newtype_global_enums, "--newtype-global-enum"), - (&self.options.rustified_enums, "--rustified-enum"), - ( - &self.options.rustified_non_exhaustive_enums, - "--rustified-enum-non-exhaustive", - ), - ( - &self.options.constified_enum_modules, - "--constified-enum-module", - ), - (&self.options.constified_enums, "--constified-enum"), - (&self.options.type_alias, "--type-alias"), - (&self.options.new_type_alias, "--new-type-alias"), - (&self.options.new_type_alias_deref, "--new-type-alias-deref"), - ( - &self.options.bindgen_wrapper_union, - "--bindgen-wrapper-union", - ), - (&self.options.manually_drop_union, "--manually-drop-union"), - (&self.options.blocklisted_types, "--blocklist-type"), - (&self.options.blocklisted_functions, "--blocklist-function"), - (&self.options.blocklisted_items, "--blocklist-item"), - (&self.options.blocklisted_files, "--blocklist-file"), - (&self.options.opaque_types, "--opaque-type"), - (&self.options.allowlisted_functions, "--allowlist-function"), - (&self.options.allowlisted_types, "--allowlist-type"), - (&self.options.allowlisted_vars, "--allowlist-var"), - (&self.options.allowlisted_files, "--allowlist-file"), - (&self.options.no_partialeq_types, "--no-partialeq"), - (&self.options.no_copy_types, "--no-copy"), - (&self.options.no_debug_types, "--no-debug"), - (&self.options.no_default_types, "--no-default"), - (&self.options.no_hash_types, "--no-hash"), - (&self.options.must_use_types, "--must-use-type"), - ]; - - for (set, flag) in regex_sets { - for item in set.get_items() { - output_vector.push((*flag).to_owned()); - output_vector.push(item.to_owned()); - } - } - - for (abi, set) in &self.options.abi_overrides { - for item in set.get_items() { - output_vector.push("--override-abi".to_owned()); - output_vector.push(format!("{}={}", item, abi)); - } - } - - if !self.options.layout_tests { - output_vector.push("--no-layout-tests".into()); - } - - if self.options.impl_debug { - output_vector.push("--impl-debug".into()); - } - - if self.options.impl_partialeq { - output_vector.push("--impl-partialeq".into()); - } - - if !self.options.derive_copy { - output_vector.push("--no-derive-copy".into()); - } - - if !self.options.derive_debug { - output_vector.push("--no-derive-debug".into()); - } - - if !self.options.derive_default { - output_vector.push("--no-derive-default".into()); - } else { - output_vector.push("--with-derive-default".into()); - } - - if self.options.derive_hash { - output_vector.push("--with-derive-hash".into()); - } - - if self.options.derive_partialord { - output_vector.push("--with-derive-partialord".into()); - } - - if self.options.derive_ord { - output_vector.push("--with-derive-ord".into()); - } - - if self.options.derive_partialeq { - output_vector.push("--with-derive-partialeq".into()); - } - - if self.options.derive_eq { - output_vector.push("--with-derive-eq".into()); - } - - if self.options.time_phases { - output_vector.push("--time-phases".into()); - } - - if !self.options.generate_comments { - output_vector.push("--no-doc-comments".into()); - } - - if !self.options.allowlist_recursively { - output_vector.push("--no-recursive-allowlist".into()); - } - - if self.options.objc_extern_crate { - output_vector.push("--objc-extern-crate".into()); - } - - if self.options.generate_block { - output_vector.push("--generate-block".into()); - } - - if self.options.block_extern_crate { - output_vector.push("--block-extern-crate".into()); - } - - if self.options.builtins { - output_vector.push("--builtins".into()); - } - - if let Some(ref prefix) = self.options.ctypes_prefix { - output_vector.push("--ctypes-prefix".into()); - output_vector.push(prefix.clone()); - } - - if self.options.anon_fields_prefix != DEFAULT_ANON_FIELDS_PREFIX { - output_vector.push("--anon-fields-prefix".into()); - output_vector.push(self.options.anon_fields_prefix.clone()); - } - - if self.options.emit_ast { - output_vector.push("--emit-clang-ast".into()); - } - - if self.options.emit_ir { - output_vector.push("--emit-ir".into()); - } - if let Some(ref graph) = self.options.emit_ir_graphviz { - output_vector.push("--emit-ir-graphviz".into()); - output_vector.push(graph.clone()) - } - if self.options.enable_cxx_namespaces { - output_vector.push("--enable-cxx-namespaces".into()); - } - if self.options.enable_function_attribute_detection { - output_vector.push("--enable-function-attribute-detection".into()); - } - if self.options.disable_name_namespacing { - output_vector.push("--disable-name-namespacing".into()); - } - if self.options.disable_nested_struct_naming { - output_vector.push("--disable-nested-struct-naming".into()); - } - - if self.options.disable_header_comment { - output_vector.push("--disable-header-comment".into()); - } - - if !self.options.codegen_config.functions() { - output_vector.push("--ignore-functions".into()); - } - - output_vector.push("--generate".into()); - - //Temporary placeholder for below 4 options - let mut options: Vec = Vec::new(); - if self.options.codegen_config.functions() { - options.push("functions".into()); - } - if self.options.codegen_config.types() { - options.push("types".into()); - } - if self.options.codegen_config.vars() { - options.push("vars".into()); - } - if self.options.codegen_config.methods() { - options.push("methods".into()); - } - if self.options.codegen_config.constructors() { - options.push("constructors".into()); - } - if self.options.codegen_config.destructors() { - options.push("destructors".into()); - } - - output_vector.push(options.join(",")); - - if !self.options.codegen_config.methods() { - output_vector.push("--ignore-methods".into()); - } - - if !self.options.convert_floats { - output_vector.push("--no-convert-floats".into()); - } - - if !self.options.prepend_enum_name { - output_vector.push("--no-prepend-enum-name".into()); - } - - if self.options.fit_macro_constants { - output_vector.push("--fit-macro-constant-types".into()); - } - - if self.options.array_pointers_in_arguments { - output_vector.push("--use-array-pointers-in-arguments".into()); - } - - if let Some(ref wasm_import_module_name) = - self.options.wasm_import_module_name - { - output_vector.push("--wasm-import-module-name".into()); - output_vector.push(wasm_import_module_name.clone()); - } - - for line in &self.options.raw_lines { - output_vector.push("--raw-line".into()); - output_vector.push(line.clone()); - } - - for (module, lines) in &self.options.module_lines { - for line in lines.iter() { - output_vector.push("--module-raw-line".into()); - output_vector.push(module.clone()); - output_vector.push(line.clone()); - } - } - - if self.options.use_core { - output_vector.push("--use-core".into()); - } - - if self.options.conservative_inline_namespaces { - output_vector.push("--conservative-inline-namespaces".into()); - } - - if self.options.generate_inline_functions { - output_vector.push("--generate-inline-functions".into()); - } - - if !self.options.record_matches { - output_vector.push("--no-record-matches".into()); - } - - if !self.options.size_t_is_usize { - output_vector.push("--no-size_t-is-usize".into()); - } - - if !self.options.rustfmt_bindings { - output_vector.push("--no-rustfmt-bindings".into()); - } - - if let Some(path) = self - .options - .rustfmt_configuration_file - .as_ref() - .and_then(|f| f.to_str()) - { - output_vector.push("--rustfmt-configuration-file".into()); - output_vector.push(path.into()); - } - - if let Some(ref name) = self.options.dynamic_library_name { - output_vector.push("--dynamic-loading".into()); - output_vector.push(name.clone()); - } - - if self.options.dynamic_link_require_all { - output_vector.push("--dynamic-link-require-all".into()); - } - - if self.options.respect_cxx_access_specs { - output_vector.push("--respect-cxx-access-specs".into()); - } - - if self.options.translate_enum_integer_types { - output_vector.push("--translate-enum-integer-types".into()); - } - - if self.options.c_naming { - output_vector.push("--c-naming".into()); - } - - if self.options.force_explicit_padding { - output_vector.push("--explicit-padding".into()); - } - - if self.options.vtable_generation { - output_vector.push("--vtable-generation".into()); - } - - if self.options.sort_semantically { - output_vector.push("--sort-semantically".into()); - } - - if self.options.merge_extern_blocks { - output_vector.push("--merge-extern-blocks".into()); - } - - if self.options.wrap_unsafe_ops { - output_vector.push("--wrap-unsafe-ops".into()); - } - - #[cfg(feature = "cli")] - for callbacks in &self.options.parse_callbacks { - output_vector.extend(callbacks.cli_args()); - } - if self.options.wrap_static_fns { - output_vector.push("--wrap-static-fns".into()) - } - - if let Some(ref path) = self.options.wrap_static_fns_path { - output_vector.push("--wrap-static-fns-path".into()); - output_vector.push(path.display().to_string()); - } - - if let Some(ref suffix) = self.options.wrap_static_fns_suffix { - output_vector.push("--wrap-static-fns-suffix".into()); - output_vector.push(suffix.clone()); - } - - if cfg!(feature = "experimental") { - output_vector.push("--experimental".into()); - } - - // Add clang arguments - - output_vector.push("--".into()); - - if !self.options.clang_args.is_empty() { - output_vector.extend(self.options.clang_args.iter().cloned()); - } - - // To pass more than one header, we need to pass all but the last - // header via the `-include` clang arg - for header in &self.options.input_headers - [..self.options.input_headers.len().saturating_sub(1)] - { - output_vector.push("-include".to_string()); - output_vector.push(header.clone()); - } - - output_vector - } - - /// Add an input C/C++ header to generate bindings for. - /// - /// This can be used to generate bindings to a single header: - /// - /// ```ignore - /// let bindings = bindgen::Builder::default() - /// .header("input.h") - /// .generate() - /// .unwrap(); - /// ``` - /// - /// Or you can invoke it multiple times to generate bindings to multiple - /// headers: - /// - /// ```ignore - /// let bindings = bindgen::Builder::default() - /// .header("first.h") - /// .header("second.h") - /// .header("third.h") - /// .generate() - /// .unwrap(); - /// ``` - pub fn header>(mut self, header: T) -> Builder { - self.options.input_headers.push(header.into()); - self - } - - /// Add a depfile output which will be written alongside the generated bindings. - pub fn depfile, D: Into>( - mut self, - output_module: H, - depfile: D, - ) -> Builder { - self.options.depfile = Some(deps::DepfileSpec { - output_module: output_module.into(), - depfile_path: depfile.into(), - }); - self - } - - /// Add `contents` as an input C/C++ header named `name`. - /// - /// The file `name` will be added to the clang arguments. - pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { - // Apparently clang relies on having virtual FS correspondent to - // the real one, so we need absolute paths here - let absolute_path = env::current_dir() - .expect("Cannot retrieve current directory") - .join(name) - .to_str() - .expect("Cannot convert current directory name to string") - .to_owned(); - self.options - .input_header_contents - .push((absolute_path, contents.into())); - self - } - - /// Specify the rust target - /// - /// The default is the latest stable Rust version - pub fn rust_target(mut self, rust_target: RustTarget) -> Self { - #[allow(deprecated)] - if rust_target <= RustTarget::Stable_1_30 { - warn!( - "The {} rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", - String::from(rust_target) - ); - } - self.options.set_rust_target(rust_target); - self - } - - /// Disable support for native Rust unions, if supported. - pub fn disable_untagged_union(mut self) -> Self { - self.options.rust_features.untagged_union = false; - self - } - - /// Disable insertion of bindgen's version identifier into generated - /// bindings. - pub fn disable_header_comment(mut self) -> Self { - self.options.disable_header_comment = true; - self - } - - /// Set the output graphviz file. - pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { - let path = path.into(); - self.options.emit_ir_graphviz = Some(path); - self - } - - /// Whether the generated bindings should contain documentation comments - /// (docstrings) or not. This is set to true by default. - /// - /// Note that clang by default excludes comments from system headers, pass - /// `-fretain-comments-from-system-headers` as - /// [`clang_arg`][Builder::clang_arg] to include them. It can also be told - /// to process all comments (not just documentation ones) using the - /// `-fparse-all-comments` flag. See [slides on clang comment parsing]( - /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for - /// background and examples. - pub fn generate_comments(mut self, doit: bool) -> Self { - self.options.generate_comments = doit; - self - } - - /// Whether to allowlist recursively or not. Defaults to true. - /// - /// Given that we have explicitly allowlisted the "initiate_dance_party" - /// function in this C header: - /// - /// ```c - /// typedef struct MoonBoots { - /// int bouncy_level; - /// } MoonBoots; - /// - /// void initiate_dance_party(MoonBoots* boots); - /// ``` - /// - /// We would normally generate bindings to both the `initiate_dance_party` - /// function and the `MoonBoots` struct that it transitively references. By - /// configuring with `allowlist_recursively(false)`, `bindgen` will not emit - /// bindings for anything except the explicitly allowlisted items, and there - /// would be no emitted struct definition for `MoonBoots`. However, the - /// `initiate_dance_party` function would still reference `MoonBoots`! - /// - /// **Disabling this feature will almost certainly cause `bindgen` to emit - /// bindings that will not compile!** If you disable this feature, then it - /// is *your* responsibility to provide definitions for every type that is - /// referenced from an explicitly allowlisted item. One way to provide the - /// definitions is by using the [`Builder::raw_line`](#method.raw_line) - /// method, another would be to define them in Rust and then `include!(...)` - /// the bindings immediately afterwards. - pub fn allowlist_recursively(mut self, doit: bool) -> Self { - self.options.allowlist_recursively = doit; - self - } - - /// Generate `#[macro_use] extern crate objc;` instead of `use objc;` - /// in the prologue of the files generated from objective-c files - pub fn objc_extern_crate(mut self, doit: bool) -> Self { - self.options.objc_extern_crate = doit; - self - } - - /// Generate proper block signatures instead of void pointers. - pub fn generate_block(mut self, doit: bool) -> Self { - self.options.generate_block = doit; - self - } - - /// Generate `#[macro_use] extern crate block;` instead of `use block;` - /// in the prologue of the files generated from apple block files - pub fn block_extern_crate(mut self, doit: bool) -> Self { - self.options.block_extern_crate = doit; - self - } - - /// Whether to use the clang-provided name mangling. This is true by default - /// and probably needed for C++ features. - /// - /// However, some old libclang versions seem to return incorrect results in - /// some cases for non-mangled functions, see [1], so we allow disabling it. - /// - /// [1]: https://github.com/rust-lang/rust-bindgen/issues/528 - pub fn trust_clang_mangling(mut self, doit: bool) -> Self { - self.options.enable_mangling = doit; - self - } - - fn_with_regex_arg! { - /// Hide the given type from the generated bindings. Regular expressions are - /// supported. - /// - /// To blocklist types prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_type>(mut self, arg: T) -> Builder { - self.options.blocklisted_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide the given function from the generated bindings. Regular expressions - /// are supported. - /// - /// Methods can be blocklisted by prefixing the name of the type implementing - /// them followed by an underscore. So if `Foo` has a method `bar`, it can - /// be blocklisted as `Foo_bar`. - /// - /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_function>(mut self, arg: T) -> Builder { - self.options.blocklisted_functions.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide the given item from the generated bindings, regardless of - /// whether it's a type, function, module, etc. Regular - /// expressions are supported. - /// - /// To blocklist items prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_item>(mut self, arg: T) -> Builder { - self.options.blocklisted_items.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide any contents of the given file from the generated bindings, - /// regardless of whether it's a type, function, module etc. - pub fn blocklist_file>(mut self, arg: T) -> Builder { - self.options.blocklisted_files.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Treat the given type as opaque in the generated bindings. Regular - /// expressions are supported. - /// - /// To change types prefixed with "mylib" into opaque, use `"mylib_.*"`. - pub fn opaque_type>(mut self, arg: T) -> Builder { - self.options.opaque_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given type so that it (and all types that it transitively - /// refers to) appears in the generated bindings. Regular expressions are - /// supported. - /// - /// To allowlist types prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_type>(mut self, arg: T) -> Builder { - self.options.allowlisted_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given function so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// Methods can be allowlisted by prefixing the name of the type - /// implementing them followed by an underscore. So if `Foo` has a method - /// `bar`, it can be allowlisted as `Foo_bar`. - /// - /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_function>(mut self, arg: T) -> Builder { - self.options.allowlisted_functions.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given variable so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// To allowlist variables prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_var>(mut self, arg: T) -> Builder { - self.options.allowlisted_vars.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given file so that its contents appear in the generated bindings. - pub fn allowlist_file>(mut self, arg: T) -> Builder { - self.options.allowlisted_files.insert(arg); - self - } - } - - /// Set the default style of code to generate for enums - pub fn default_enum_style( - mut self, - arg: codegen::EnumVariation, - ) -> Builder { - self.options.default_enum_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as being - /// bitfield-like. Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a rust `enum`. Regular - /// expressions are supported. - /// - /// This is similar to the newtype enum style, but with the bitwise - /// operators implemented. - pub fn bitfield_enum>(mut self, arg: T) -> Builder { - self.options.bitfield_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a newtype. - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_enum>(mut self, arg: T) -> Builder { - self.options.newtype_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a newtype - /// whose variants are exposed as global constants. - /// - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_global_enum>(mut self, arg: T) -> Builder { - self.options.newtype_global_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_enum>(mut self, arg: T) -> Builder { - self.options.rustified_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum with the `#[non_exhaustive]` attribute. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_non_exhaustive_enum>( - mut self, - arg: T, - ) -> Builder { - self.options.rustified_non_exhaustive_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that are not to be put into a module. - pub fn constified_enum>(mut self, arg: T) -> Builder { - self.options.constified_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that should be put into a module. - /// - /// This makes bindgen generate modules containing constants instead of - /// just constants. Regular expressions are supported. - pub fn constified_enum_module>(mut self, arg: T) -> Builder { - self.options.constified_enum_modules.insert(arg); - self - } - } - - /// Set the default type for macro constants - pub fn default_macro_constant_type( - mut self, - arg: codegen::MacroTypeVariation, - ) -> Builder { - self.options.default_macro_constant_type = arg; - self - } - - /// Set the default style of code to generate for typedefs - pub fn default_alias_style( - mut self, - arg: codegen::AliasVariation, - ) -> Builder { - self.options.default_alias_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// use regular Rust type aliasing. - /// - /// This is the default behavior and should be used if `default_alias_style` - /// was set to NewType or NewTypeDeref and you want to override it for a - /// set of typedefs. - pub fn type_alias>(mut self, arg: T) -> Builder { - self.options.type_alias.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct. - /// - /// Used to enforce stricter type checking. - pub fn new_type_alias>(mut self, arg: T) -> Builder { - self.options.new_type_alias.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct and also have an automatically generated - /// impl's of `Deref` and `DerefMut` to their aliased type. - pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { - self.options.new_type_alias_deref.insert(arg); - self - } - } - - /// Set the default style of code to generate for unions with a non-Copy member. - pub fn default_non_copy_union_style( - mut self, - arg: codegen::NonCopyUnionStyle, - ) -> Self { - self.options.default_non_copy_union_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given union (or set of union, if using a pattern) to use - /// a bindgen-generated wrapper for its members if at least one is non-Copy. - pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { - self.options.bindgen_wrapper_union.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given union (or set of union, if using a pattern) to use - /// [`::core::mem::ManuallyDrop`] for its members if at least one is non-Copy. - /// - /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your - /// MSRV is lower. - pub fn manually_drop_union>(mut self, arg: T) -> Self { - self.options.manually_drop_union.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Add a string to prepend to the generated bindings. The string is passed - /// through without any modification. - pub fn raw_line>(mut self, arg: T) -> Self { - self.options.raw_lines.push(arg.into()); - self - } - } - - /// Add a given line to the beginning of module `mod`. - pub fn module_raw_line(mut self, mod_: T, line: U) -> Self - where - T: Into, - U: Into, - { - self.options - .module_lines - .entry(mod_.into()) - .or_insert_with(Vec::new) - .push(line.into()); - self - } - - /// Add a given set of lines to the beginning of module `mod`. - pub fn module_raw_lines(mut self, mod_: T, lines: I) -> Self - where - T: Into, - I: IntoIterator, - I::Item: Into, - { - self.options - .module_lines - .entry(mod_.into()) - .or_insert_with(Vec::new) - .extend(lines.into_iter().map(Into::into)); - self - } - - /// Add an argument to be passed straight through to clang. - pub fn clang_arg>(mut self, arg: T) -> Builder { - self.options.clang_args.push(arg.into()); - self - } - - /// Add arguments to be passed straight through to clang. - pub fn clang_args(mut self, iter: I) -> Builder - where - I: IntoIterator, - I::Item: AsRef, - { - for arg in iter { - self = self.clang_arg(arg.as_ref()) - } - self - } - - /// Emit bindings for builtin definitions (for example `__builtin_va_list`) - /// in the generated Rust. - pub fn emit_builtins(mut self) -> Builder { - self.options.builtins = true; - self - } - - /// Avoid converting floats to `f32`/`f64` by default. - pub fn no_convert_floats(mut self) -> Self { - self.options.convert_floats = false; - self - } - - /// Set whether layout tests should be generated. - pub fn layout_tests(mut self, doit: bool) -> Self { - self.options.layout_tests = doit; - self - } - - /// Set whether `Debug` should be implemented, if it can not be derived automatically. - pub fn impl_debug(mut self, doit: bool) -> Self { - self.options.impl_debug = doit; - self - } - - /// Set whether `PartialEq` should be implemented, if it can not be derived automatically. - pub fn impl_partialeq(mut self, doit: bool) -> Self { - self.options.impl_partialeq = doit; - self - } - - /// Set whether `Copy` should be derived by default. - pub fn derive_copy(mut self, doit: bool) -> Self { - self.options.derive_copy = doit; - self - } - - /// Set whether `Debug` should be derived by default. - pub fn derive_debug(mut self, doit: bool) -> Self { - self.options.derive_debug = doit; - self - } - - /// Set whether `Default` should be derived by default. - pub fn derive_default(mut self, doit: bool) -> Self { - self.options.derive_default = doit; - self - } - - /// Set whether `Hash` should be derived by default. - pub fn derive_hash(mut self, doit: bool) -> Self { - self.options.derive_hash = doit; - self - } - - /// Set whether `PartialOrd` should be derived by default. - /// If we don't compute partialord, we also cannot compute - /// ord. Set the derive_ord to `false` when doit is `false`. - pub fn derive_partialord(mut self, doit: bool) -> Self { - self.options.derive_partialord = doit; - if !doit { - self.options.derive_ord = false; - } - self - } - - /// Set whether `Ord` should be derived by default. - /// We can't compute `Ord` without computing `PartialOrd`, - /// so we set the same option to derive_partialord. - pub fn derive_ord(mut self, doit: bool) -> Self { - self.options.derive_ord = doit; - self.options.derive_partialord = doit; - self - } - - /// Set whether `PartialEq` should be derived by default. - /// - /// If we don't derive `PartialEq`, we also cannot derive `Eq`, so deriving - /// `Eq` is also disabled when `doit` is `false`. - pub fn derive_partialeq(mut self, doit: bool) -> Self { - self.options.derive_partialeq = doit; - if !doit { - self.options.derive_eq = false; - } - self - } - - /// Set whether `Eq` should be derived by default. - /// - /// We can't derive `Eq` without also deriving `PartialEq`, so we also - /// enable deriving `PartialEq` when `doit` is `true`. - pub fn derive_eq(mut self, doit: bool) -> Self { - self.options.derive_eq = doit; - if doit { - self.options.derive_partialeq = doit; - } - self - } - - /// Set whether or not to time bindgen phases, and print information to - /// stderr. - pub fn time_phases(mut self, doit: bool) -> Self { - self.options.time_phases = doit; - self - } - - /// Emit Clang AST. - pub fn emit_clang_ast(mut self) -> Builder { - self.options.emit_ast = true; - self - } - - /// Emit IR. - pub fn emit_ir(mut self) -> Builder { - self.options.emit_ir = true; - self - } - - /// Enable C++ namespaces. - pub fn enable_cxx_namespaces(mut self) -> Builder { - self.options.enable_cxx_namespaces = true; - self - } - - /// Enable detecting must_use attributes on C functions. - /// - /// This is quite slow in some cases (see #1465), so it's disabled by - /// default. - /// - /// Note that for this to do something meaningful for now at least, the rust - /// target version has to have support for `#[must_use]`. - pub fn enable_function_attribute_detection(mut self) -> Self { - self.options.enable_function_attribute_detection = true; - self - } - - /// Disable name auto-namespacing. - /// - /// By default, bindgen mangles names like `foo::bar::Baz` to look like - /// `foo_bar_Baz` instead of just `Baz`. - /// - /// This method disables that behavior. - /// - /// Note that this intentionally does not change the names used for - /// allowlisting and blocklisting, which should still be mangled with the - /// namespaces. - /// - /// Note, also, that this option may cause bindgen to generate duplicate - /// names. - pub fn disable_name_namespacing(mut self) -> Builder { - self.options.disable_name_namespacing = true; - self - } - - /// Disable nested struct naming. - /// - /// The following structs have different names for C and C++. In case of C - /// they are visible as `foo` and `bar`. In case of C++ they are visible as - /// `foo` and `foo::bar`. - /// - /// ```c - /// struct foo { - /// struct bar { - /// } b; - /// }; - /// ``` - /// - /// Bindgen wants to avoid duplicate names by default so it follows C++ naming - /// and it generates `foo`/`foo_bar` instead of just `foo`/`bar`. - /// - /// This method disables this behavior and it is indented to be used only - /// for headers that were written for C. - pub fn disable_nested_struct_naming(mut self) -> Builder { - self.options.disable_nested_struct_naming = true; - self - } - - /// Treat inline namespaces conservatively. - /// - /// This is tricky, because in C++ is technically legal to override an item - /// defined in an inline namespace: - /// - /// ```cpp - /// inline namespace foo { - /// using Bar = int; - /// } - /// using Bar = long; - /// ``` - /// - /// Even though referencing `Bar` is a compiler error. - /// - /// We want to support this (arguably esoteric) use case, but we don't want - /// to make the rest of bindgen users pay an usability penalty for that. - /// - /// To support this, we need to keep all the inline namespaces around, but - /// then bindgen usage is a bit more difficult, because you cannot - /// reference, e.g., `std::string` (you'd need to use the proper inline - /// namespace). - /// - /// We could complicate a lot of the logic to detect name collisions, and if - /// not detected generate a `pub use inline_ns::*` or something like that. - /// - /// That's probably something we can do if we see this option is needed in a - /// lot of cases, to improve it's usability, but my guess is that this is - /// not going to be too useful. - pub fn conservative_inline_namespaces(mut self) -> Builder { - self.options.conservative_inline_namespaces = true; - self - } - - /// Whether inline functions should be generated or not. - /// - /// Note that they will usually not work. However you can use - /// `-fkeep-inline-functions` or `-fno-inline-functions` if you are - /// responsible of compiling the library to make them callable. - pub fn generate_inline_functions(mut self, doit: bool) -> Self { - self.options.generate_inline_functions = doit; - self - } - - /// Ignore functions. - pub fn ignore_functions(mut self) -> Builder { - self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); - self - } - - /// Ignore methods. - pub fn ignore_methods(mut self) -> Builder { - self.options.codegen_config.remove(CodegenConfig::METHODS); - self - } - - /// Use core instead of libstd in the generated bindings. - pub fn use_core(mut self) -> Builder { - self.options.use_core = true; - self - } - - /// Use the given prefix for the raw types instead of `::std::os::raw`. - pub fn ctypes_prefix>(mut self, prefix: T) -> Builder { - self.options.ctypes_prefix = Some(prefix.into()); - self - } - - /// Use the given prefix for the anon fields. - pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { - self.options.anon_fields_prefix = prefix.into(); - self - } - - /// Allows configuring types in different situations, see the - /// [`ParseCallbacks`](./callbacks/trait.ParseCallbacks.html) documentation. - pub fn parse_callbacks( - mut self, - cb: Box, - ) -> Self { - self.options.parse_callbacks.push(Rc::from(cb)); - self - } - - /// Choose what to generate using a - /// [`CodegenConfig`](./struct.CodegenConfig.html). - pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { - self.options.codegen_config = config; - self - } - - /// Whether to detect include paths using clang_sys. - pub fn detect_include_paths(mut self, doit: bool) -> Self { - self.options.detect_include_paths = doit; - self - } - - /// Whether to try to fit macro constants to types smaller than u32/i32 - pub fn fit_macro_constants(mut self, doit: bool) -> Self { - self.options.fit_macro_constants = doit; - self - } - - /// Prepend the enum name to constant or newtype variants. - pub fn prepend_enum_name(mut self, doit: bool) -> Self { - self.options.prepend_enum_name = doit; - self - } - - /// Set whether `size_t` should be translated to `usize` automatically. - pub fn size_t_is_usize(mut self, is: bool) -> Self { - self.options.size_t_is_usize = is; - self - } - - /// Set whether rustfmt should format the generated bindings. - pub fn rustfmt_bindings(mut self, doit: bool) -> Self { - self.options.rustfmt_bindings = doit; - self - } - - /// Set whether we should record matched items in our regex sets. - pub fn record_matches(mut self, doit: bool) -> Self { - self.options.record_matches = doit; - self - } - - /// Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt - /// options are used. - pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { - self = self.rustfmt_bindings(true); - self.options.rustfmt_configuration_file = path; - self - } - - /// Sets an explicit path to rustfmt, to be used when rustfmt is enabled. - pub fn with_rustfmt>(mut self, path: P) -> Self { - self.options.rustfmt_path = Some(path.into()); - self - } - - /// If true, always emit explicit padding fields. - /// - /// If a struct needs to be serialized in its native format (padding bytes - /// and all), for example writing it to a file or sending it on the network, - /// then this should be enabled, as anything reading the padding bytes of - /// a struct may lead to Undefined Behavior. - pub fn explicit_padding(mut self, doit: bool) -> Self { - self.options.force_explicit_padding = doit; - self - } - - /// If true, enables experimental support to generate vtable functions. - /// - /// Should mostly work, though some edge cases are likely to be broken. - pub fn vtable_generation(mut self, doit: bool) -> Self { - self.options.vtable_generation = doit; - self - } - - /// If true, enables the sorting of the output in a predefined manner. - /// - /// TODO: Perhaps move the sorting order out into a config - pub fn sort_semantically(mut self, doit: bool) -> Self { - self.options.sort_semantically = doit; - self - } - - /// If true, merges extern blocks. - pub fn merge_extern_blocks(mut self, doit: bool) -> Self { - self.options.merge_extern_blocks = doit; - self - } - - /// Generate the Rust bindings using the options built up thus far. - pub fn generate(mut self) -> Result { - // Add any extra arguments from the environment to the clang command line. - self.options.clang_args.extend(get_extra_clang_args()); - - // Transform input headers to arguments on the clang command line. - self.options.clang_args.extend( - self.options.input_headers - [..self.options.input_headers.len().saturating_sub(1)] - .iter() - .flat_map(|header| ["-include".into(), header.to_string()]), - ); - - let input_unsaved_files = - std::mem::take(&mut self.options.input_header_contents) - .into_iter() - .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) - .collect::>(); - - Bindings::generate(self.options, input_unsaved_files) - } - - /// Preprocess and dump the input header files to disk. - /// - /// This is useful when debugging bindgen, using C-Reduce, or when filing - /// issues. The resulting file will be named something like `__bindgen.i` or - /// `__bindgen.ii` - pub fn dump_preprocessed_input(&self) -> io::Result<()> { - let clang = - clang_sys::support::Clang::find(None, &[]).ok_or_else(|| { - io::Error::new( - io::ErrorKind::Other, - "Cannot find clang executable", - ) - })?; - - // The contents of a wrapper file that includes all the input header - // files. - let mut wrapper_contents = String::new(); - - // Whether we are working with C or C++ inputs. - let mut is_cpp = args_are_cpp(&self.options.clang_args); - - // For each input header, add `#include "$header"`. - for header in &self.options.input_headers { - is_cpp |= file_is_cpp(header); - - wrapper_contents.push_str("#include \""); - wrapper_contents.push_str(header); - wrapper_contents.push_str("\"\n"); - } - - // For each input header content, add a prefix line of `#line 0 "$name"` - // followed by the contents. - for (name, contents) in &self.options.input_header_contents { - is_cpp |= file_is_cpp(name); - - wrapper_contents.push_str("#line 0 \""); - wrapper_contents.push_str(name); - wrapper_contents.push_str("\"\n"); - wrapper_contents.push_str(contents); - } - - let wrapper_path = PathBuf::from(if is_cpp { - "__bindgen.cpp" - } else { - "__bindgen.c" - }); - - { - let mut wrapper_file = File::create(&wrapper_path)?; - wrapper_file.write_all(wrapper_contents.as_bytes())?; - } - - let mut cmd = Command::new(clang.path); - cmd.arg("-save-temps") - .arg("-E") - .arg("-C") - .arg("-c") - .arg(&wrapper_path) - .stdout(Stdio::piped()); - - for a in &self.options.clang_args { - cmd.arg(a); - } - - for a in get_extra_clang_args() { - cmd.arg(a); - } - - let mut child = cmd.spawn()?; - - let mut preprocessed = child.stdout.take().unwrap(); - let mut file = File::create(if is_cpp { - "__bindgen.ii" - } else { - "__bindgen.i" - })?; - io::copy(&mut preprocessed, &mut file)?; - - if child.wait()?.success() { - Ok(()) - } else { - Err(io::Error::new( - io::ErrorKind::Other, - "clang exited with non-zero status", - )) - } - } - - fn_with_regex_arg! { - /// Don't derive `PartialEq` for a given type. Regular - /// expressions are supported. - pub fn no_partialeq>(mut self, arg: T) -> Builder { - self.options.no_partialeq_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Copy` for a given type. Regular - /// expressions are supported. - pub fn no_copy>(mut self, arg: T) -> Self { - self.options.no_copy_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Debug` for a given type. Regular - /// expressions are supported. - pub fn no_debug>(mut self, arg: T) -> Self { - self.options.no_debug_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive/impl `Default` for a given type. Regular - /// expressions are supported. - pub fn no_default>(mut self, arg: T) -> Self { - self.options.no_default_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Hash` for a given type. Regular - /// expressions are supported. - pub fn no_hash>(mut self, arg: T) -> Builder { - self.options.no_hash_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Add `#[must_use]` for the given type. Regular - /// expressions are supported. - pub fn must_use_type>(mut self, arg: T) -> Builder { - self.options.must_use_types.insert(arg.into()); - self - } - } - - /// Set whether `arr[size]` should be treated as `*mut T` or `*mut [T; size]` (same for mut) - pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { - self.options.array_pointers_in_arguments = doit; - self - } - - /// Set the wasm import module name - pub fn wasm_import_module_name>( - mut self, - import_name: T, - ) -> Self { - self.options.wasm_import_module_name = Some(import_name.into()); - self - } - - /// Specify the dynamic library name if we are generating bindings for a shared library. - pub fn dynamic_library_name>( - mut self, - dynamic_library_name: T, - ) -> Self { - self.options.dynamic_library_name = Some(dynamic_library_name.into()); - self - } - - /// Require successful linkage for all routines in a shared library. - /// This allows us to optimize function calls by being able to safely assume function pointers - /// are valid. - pub fn dynamic_link_require_all(mut self, req: bool) -> Self { - self.options.dynamic_link_require_all = req; - self - } - - /// Generate bindings as `pub` only if the bound item is publically accessible by C++. - pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { - self.options.respect_cxx_access_specs = doit; - self - } - - /// Always translate enum integer types to native Rust integer types. - /// - /// This will result in enums having types such as `u32` and `i16` instead - /// of `c_uint` and `c_short`. Types for Rustified enums are always - /// translated. - pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { - self.options.translate_enum_integer_types = doit; - self - } - - /// Generate types with C style naming. - /// - /// This will add prefixes to the generated type names. For example instead of a struct `A` we - /// will generate struct `struct_A`. Currently applies to structs, unions, and enums. - pub fn c_naming(mut self, doit: bool) -> Self { - self.options.c_naming = doit; - self - } - - /// Override the ABI of a given function. Regular expressions are supported. - pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { - self.options - .abi_overrides - .entry(abi) - .or_default() - .insert(arg.into()); - self - } - - /// If true, wraps unsafe operations in unsafe blocks. - pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { - self.options.wrap_unsafe_ops = doit; - self - } - - #[cfg(feature = "experimental")] - /// Whether to generate extern wrappers for `static` and `static inline` functions. Defaults to - /// false. - pub fn wrap_static_fns(mut self, doit: bool) -> Self { - self.options.wrap_static_fns = doit; - self - } - - #[cfg(feature = "experimental")] - /// Set the path for the source code file that would be created if any wrapper functions must - /// be generated due to the presence of static functions. - /// - /// Bindgen will automatically add the right extension to the header and source code files. - pub fn wrap_static_fns_path>(mut self, path: T) -> Self { - self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); - self - } - - #[cfg(feature = "experimental")] - /// Set the suffix added to the extern wrapper functions generated for `static` and `static - /// inline` functions. - pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { - self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); - self - } -} - -/// Configuration options for generated bindings. -#[derive(Clone, Debug)] -struct BindgenOptions { - /// The set of types that have been blocklisted and should not appear - /// anywhere in the generated code. - blocklisted_types: RegexSet, - - /// The set of functions that have been blocklisted and should not appear - /// in the generated code. - blocklisted_functions: RegexSet, - - /// The set of items, regardless of item-type, that have been - /// blocklisted and should not appear in the generated code. - blocklisted_items: RegexSet, - - /// The set of files whose contents should be blocklisted and should not - /// appear in the generated code. - blocklisted_files: RegexSet, - - /// The set of types that should be treated as opaque structures in the - /// generated code. - opaque_types: RegexSet, - - /// The explicit rustfmt path. - rustfmt_path: Option, - - /// The path to which we should write a Makefile-syntax depfile (if any). - depfile: Option, - - /// The set of types that we should have bindings for in the generated - /// code. - /// - /// This includes all types transitively reachable from any type in this - /// set. One might think of allowlisted types/vars/functions as GC roots, - /// and the generated Rust code as including everything that gets marked. - allowlisted_types: RegexSet, - - /// Allowlisted functions. See docs for `allowlisted_types` for more. - allowlisted_functions: RegexSet, - - /// Allowlisted variables. See docs for `allowlisted_types` for more. - allowlisted_vars: RegexSet, - - /// The set of files whose contents should be allowlisted. - allowlisted_files: RegexSet, - - /// The default style of code to generate for enums - default_enum_style: codegen::EnumVariation, - - /// The enum patterns to mark an enum as a bitfield - /// (newtype with bitwise operations). - bitfield_enums: RegexSet, - - /// The enum patterns to mark an enum as a newtype. - newtype_enums: RegexSet, - - /// The enum patterns to mark an enum as a global newtype. - newtype_global_enums: RegexSet, - - /// The enum patterns to mark an enum as a Rust enum. - rustified_enums: RegexSet, - - /// The enum patterns to mark an enum as a non-exhaustive Rust enum. - rustified_non_exhaustive_enums: RegexSet, - - /// The enum patterns to mark an enum as a module of constants. - constified_enum_modules: RegexSet, - - /// The enum patterns to mark an enum as a set of constants. - constified_enums: RegexSet, - - /// The default type for C macro constants. - default_macro_constant_type: codegen::MacroTypeVariation, - - /// The default style of code to generate for typedefs. - default_alias_style: codegen::AliasVariation, - - /// Typedef patterns that will use regular type aliasing. - type_alias: RegexSet, - - /// Typedef patterns that will be aliased by creating a new struct. - new_type_alias: RegexSet, - - /// Typedef patterns that will be wrapped in a new struct and have - /// Deref and Deref to their aliased type. - new_type_alias_deref: RegexSet, - - /// The default style of code to generate for union containing non-Copy - /// members. - default_non_copy_union_style: codegen::NonCopyUnionStyle, - - /// The union patterns to mark an non-Copy union as using the bindgen - /// generated wrapper. - bindgen_wrapper_union: RegexSet, - - /// The union patterns to mark an non-Copy union as using the - /// `::core::mem::ManuallyDrop` wrapper. - manually_drop_union: RegexSet, - - /// Whether we should generate builtins or not. - builtins: bool, - - /// True if we should dump the Clang AST for debugging purposes. - emit_ast: bool, - - /// True if we should dump our internal IR for debugging purposes. - emit_ir: bool, - - /// Output graphviz dot file. - emit_ir_graphviz: Option, - - /// True if we should emulate C++ namespaces with Rust modules in the - /// generated bindings. - enable_cxx_namespaces: bool, - - /// True if we should try to find unexposed attributes in functions, in - /// order to be able to generate #[must_use] attributes in Rust. - enable_function_attribute_detection: bool, - - /// True if we should avoid mangling names with namespaces. - disable_name_namespacing: bool, - - /// True if we should avoid generating nested struct names. - disable_nested_struct_naming: bool, - - /// True if we should avoid embedding version identifiers into source code. - disable_header_comment: bool, - - /// True if we should generate layout tests for generated structures. - layout_tests: bool, - - /// True if we should implement the Debug trait for C/C++ structures and types - /// that do not support automatically deriving Debug. - impl_debug: bool, - - /// True if we should implement the PartialEq trait for C/C++ structures and types - /// that do not support automatically deriving PartialEq. - impl_partialeq: bool, - - /// True if we should derive Copy trait implementations for C/C++ structures - /// and types. - derive_copy: bool, - - /// True if we should derive Debug trait implementations for C/C++ structures - /// and types. - derive_debug: bool, - - /// True if we should derive Default trait implementations for C/C++ structures - /// and types. - derive_default: bool, - - /// True if we should derive Hash trait implementations for C/C++ structures - /// and types. - derive_hash: bool, - - /// True if we should derive PartialOrd trait implementations for C/C++ structures - /// and types. - derive_partialord: bool, - - /// True if we should derive Ord trait implementations for C/C++ structures - /// and types. - derive_ord: bool, - - /// True if we should derive PartialEq trait implementations for C/C++ structures - /// and types. - derive_partialeq: bool, - - /// True if we should derive Eq trait implementations for C/C++ structures - /// and types. - derive_eq: bool, - - /// True if we should avoid using libstd to use libcore instead. - use_core: bool, - - /// An optional prefix for the "raw" types, like `c_int`, `c_void`... - ctypes_prefix: Option, - - /// The prefix for the anon fields. - anon_fields_prefix: String, - - /// Whether to time the bindgen phases. - time_phases: bool, - - /// Whether we should convert float types to f32/f64 types. - convert_floats: bool, - - /// The set of raw lines to prepend to the top-level module of generated - /// Rust code. - raw_lines: Vec, - - /// The set of raw lines to prepend to each of the modules. - /// - /// This only makes sense if the `enable_cxx_namespaces` option is set. - module_lines: HashMap>, - - /// The set of arguments to pass straight through to Clang. - clang_args: Vec, - - /// The input header files. - input_headers: Vec, - - /// Tuples of unsaved file contents of the form (name, contents). - input_header_contents: Vec<(String, String)>, - - /// A user-provided visitor to allow customizing different kinds of - /// situations. - parse_callbacks: Vec>, - - /// Which kind of items should we generate? By default, we'll generate all - /// of them. - codegen_config: CodegenConfig, - - /// Whether to treat inline namespaces conservatively. - /// - /// See the builder method description for more details. - conservative_inline_namespaces: bool, - - /// Whether to keep documentation comments in the generated output. See the - /// documentation for more details. Defaults to true. - generate_comments: bool, - - /// Whether to generate inline functions. Defaults to false. - generate_inline_functions: bool, - - /// Whether to allowlist types recursively. Defaults to true. - allowlist_recursively: bool, - - /// Instead of emitting 'use objc;' to files generated from objective c files, - /// generate '#[macro_use] extern crate objc;' - objc_extern_crate: bool, +/// the pattern passed to several methods: +/// +/// 1. [`constified_enum_module()`](#method.constified_enum_module) +/// 2. [`bitfield_enum()`](#method.bitfield_enum) +/// 3. [`newtype_enum()`](#method.newtype_enum) +/// 4. [`rustified_enum()`](#method.rustified_enum) +/// 5. [`rustified_non_exhaustive_enum()`](#method.rustified_non_exhaustive_enum) +/// +/// For each C enum, bindgen tries to match the pattern in the following order: +/// +/// 1. Constified enum module +/// 2. Bitfield enum +/// 3. Newtype enum +/// 4. Rustified enum +/// +/// If none of the above patterns match, then bindgen will generate a set of Rust constants. +/// +/// # Clang arguments +/// +/// Extra arguments can be passed to with clang: +/// 1. [`clang_arg()`](#method.clang_arg): takes a single argument +/// 2. [`clang_args()`](#method.clang_args): takes an iterator of arguments +/// 3. `BINDGEN_EXTRA_CLANG_ARGS` environment variable: whitespace separate +/// environment variable of arguments +/// +/// Clang arguments specific to your crate should be added via the +/// `clang_arg()`/`clang_args()` methods. +/// +/// End-users of the crate may need to set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to +/// add additional arguments. For example, to build against a different sysroot a user could set +/// `BINDGEN_EXTRA_CLANG_ARGS` to `--sysroot=/path/to/sysroot`. +/// +/// # Regular expression arguments +/// +/// Some [`Builder`] methods, such as `allowlist_*` and `blocklist_*`, allow regular +/// expressions as arguments. These regular expressions will be enclosed in parentheses and +/// anchored with `^` and `$`. So, if the argument passed is ``, the regular expression to be +/// stored will be `^()$`. +/// +/// As a consequence, regular expressions passed to `bindgen` will try to match the whole name of +/// an item instead of a section of it, which means that to match any items with the prefix +/// `prefix`, the `prefix.*` regular expression must be used. +/// +/// Certain methods, like [`Builder::allowlist_function`], use regular expressions over function +/// names. To match C++ methods, prefix the name of the type where they belong, followed by an +/// underscore. So, if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar` +/// regular expression. +/// +/// Additionally, Objective-C interfaces can be matched by prefixing the regular expression with +/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface, and the `IFoo_foo` +/// regular expression matches the `foo` method of the `Foo` interface. +/// +/// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard +/// pattern `*` as a valid regular expression. This behavior has been deprecated, and the `.*` +/// regular expression must be used instead. +#[derive(Debug, Default, Clone)] +pub struct Builder { + options: BindgenOptions, +} - /// Instead of emitting 'use block;' to files generated from objective c files, - /// generate '#[macro_use] extern crate block;' - generate_block: bool, +/// Construct a new [`Builder`](./struct.Builder.html). +pub fn builder() -> Builder { + Default::default() +} - /// Instead of emitting 'use block;' to files generated from objective c files, - /// generate '#[macro_use] extern crate block;' - block_extern_crate: bool, +fn get_extra_clang_args( + parse_callbacks: &[Rc], +) -> Vec { + // Add any extra arguments from the environment to the clang command line. + let extra_clang_args = match get_target_dependent_env_var( + parse_callbacks, + "BINDGEN_EXTRA_CLANG_ARGS", + ) { + None => return vec![], + Some(s) => s, + }; - /// Whether to use the clang-provided name mangling. This is true and - /// probably needed for C++ features. - /// - /// However, some old libclang versions seem to return incorrect results in - /// some cases for non-mangled functions, see [1], so we allow disabling it. - /// - /// [1]: https://github.com/rust-lang/rust-bindgen/issues/528 - enable_mangling: bool, + // Try to parse it with shell quoting. If we fail, make it one single big argument. + if let Some(strings) = shlex::split(&extra_clang_args) { + return strings; + } + vec![extra_clang_args] +} - /// Whether to detect include paths using clang_sys. - detect_include_paths: bool, +impl Builder { + /// Generate the Rust bindings using the options built up thus far. + pub fn generate(mut self) -> Result { + // Add any extra arguments from the environment to the clang command line. + self.options.clang_args.extend( + get_extra_clang_args(&self.options.parse_callbacks) + .into_iter() + .map(String::into_boxed_str), + ); - /// Whether to try to fit macro constants into types smaller than u32/i32 - fit_macro_constants: bool, + for header in &self.options.input_headers { + self.options + .for_each_callback(|cb| cb.header_file(header.as_ref())); + } - /// Whether to prepend the enum name to constant or newtype variants. - prepend_enum_name: bool, + // Transform input headers to arguments on the clang command line. + self.options.clang_args.extend( + self.options.input_headers + [..self.options.input_headers.len().saturating_sub(1)] + .iter() + .flat_map(|header| ["-include".into(), header.clone()]), + ); - /// Version of the Rust compiler to target - rust_target: RustTarget, + let input_unsaved_files = + std::mem::take(&mut self.options.input_header_contents) + .into_iter() + .map(|(name, contents)| { + clang::UnsavedFile::new(name.as_ref(), contents.as_ref()) + }) + .collect::>(); - /// Features to enable, derived from `rust_target` - rust_features: RustFeatures, + Bindings::generate(self.options, input_unsaved_files) + } - /// Whether we should record which items in the regex sets ever matched. + /// Preprocess and dump the input header files to disk. /// - /// This may be a bit slower, but will enable reporting of unused allowlist - /// items via the `error!` log. - record_matches: bool, - - /// Whether `size_t` should be translated to `usize` automatically. - size_t_is_usize: bool, - - /// Whether rustfmt should format the generated bindings. - rustfmt_bindings: bool, - - /// The absolute path to the rustfmt configuration file, if None, the standard rustfmt - /// options are used. - rustfmt_configuration_file: Option, - - /// The set of types that we should not derive `PartialEq` for. - no_partialeq_types: RegexSet, - - /// The set of types that we should not derive `Copy` for. - no_copy_types: RegexSet, - - /// The set of types that we should not derive `Debug` for. - no_debug_types: RegexSet, - - /// The set of types that we should not derive/impl `Default` for. - no_default_types: RegexSet, - - /// The set of types that we should not derive `Hash` for. - no_hash_types: RegexSet, - - /// The set of types that we should be annotated with `#[must_use]`. - must_use_types: RegexSet, - - /// Decide if C arrays should be regular pointers in rust or array pointers - array_pointers_in_arguments: bool, - - /// Wasm import module name. - wasm_import_module_name: Option, + /// This is useful when debugging bindgen, using C-Reduce, or when filing + /// issues. The resulting file will be named something like `__bindgen.i` or + /// `__bindgen.ii` + pub fn dump_preprocessed_input(&self) -> io::Result<()> { + let clang = + clang_sys::support::Clang::find(None, &[]).ok_or_else(|| { + io::Error::new( + io::ErrorKind::Other, + "Cannot find clang executable", + ) + })?; - /// The name of the dynamic library (if we are generating bindings for a shared library). If - /// this is None, no dynamic bindings are created. - dynamic_library_name: Option, + // The contents of a wrapper file that includes all the input header + // files. + let mut wrapper_contents = String::new(); - /// Require successful linkage for all routines in a shared library. - /// This allows us to optimize function calls by being able to safely assume function pointers - /// are valid. No effect if `dynamic_library_name` is None. - dynamic_link_require_all: bool, + // Whether we are working with C or C++ inputs. + let mut is_cpp = args_are_cpp(&self.options.clang_args); - /// Only make generated bindings `pub` if the items would be publically accessible - /// by C++. - respect_cxx_access_specs: bool, + // For each input header, add `#include "$header"`. + for header in &self.options.input_headers { + is_cpp |= file_is_cpp(header); - /// Always translate enum integer types to native Rust integer types. - translate_enum_integer_types: bool, + wrapper_contents.push_str("#include \""); + wrapper_contents.push_str(header); + wrapper_contents.push_str("\"\n"); + } - /// Generate types with C style naming. - c_naming: bool, + // For each input header content, add a prefix line of `#line 0 "$name"` + // followed by the contents. + for (name, contents) in &self.options.input_header_contents { + is_cpp |= file_is_cpp(name); - /// Always output explicit padding fields - force_explicit_padding: bool, + wrapper_contents.push_str("#line 0 \""); + wrapper_contents.push_str(name); + wrapper_contents.push_str("\"\n"); + wrapper_contents.push_str(contents); + } - /// Emit vtable functions. - vtable_generation: bool, + let wrapper_path = PathBuf::from(if is_cpp { + "__bindgen.cpp" + } else { + "__bindgen.c" + }); - /// Sort the code generation. - sort_semantically: bool, + { + let mut wrapper_file = File::create(&wrapper_path)?; + wrapper_file.write_all(wrapper_contents.as_bytes())?; + } - /// Deduplicate `extern` blocks. - merge_extern_blocks: bool, + let mut cmd = Command::new(clang.path); + cmd.arg("-save-temps") + .arg("-E") + .arg("-C") + .arg("-c") + .arg(&wrapper_path) + .stdout(Stdio::piped()); - abi_overrides: HashMap, + for a in &self.options.clang_args { + cmd.arg(a.as_ref()); + } - /// Whether to wrap unsafe operations in unsafe blocks or not. - wrap_unsafe_ops: bool, + for a in get_extra_clang_args(&self.options.parse_callbacks) { + cmd.arg(a); + } - wrap_static_fns: bool, + let mut child = cmd.spawn()?; - wrap_static_fns_suffix: Option, + let mut preprocessed = child.stdout.take().unwrap(); + let mut file = File::create(if is_cpp { + "__bindgen.ii" + } else { + "__bindgen.i" + })?; + io::copy(&mut preprocessed, &mut file)?; - wrap_static_fns_path: Option, + if child.wait()?.success() { + Ok(()) + } else { + Err(io::Error::new( + io::ErrorKind::Other, + "clang exited with non-zero status", + )) + } + } } impl BindgenOptions { fn build(&mut self) { - let regex_sets = [ - &mut self.allowlisted_vars, - &mut self.allowlisted_types, - &mut self.allowlisted_functions, - &mut self.allowlisted_files, + const REGEX_SETS_LEN: usize = 29; + + let regex_sets: [_; REGEX_SETS_LEN] = [ &mut self.blocklisted_types, &mut self.blocklisted_functions, &mut self.blocklisted_items, &mut self.blocklisted_files, + &mut self.blocklisted_vars, &mut self.opaque_types, + &mut self.allowlisted_vars, + &mut self.allowlisted_types, + &mut self.allowlisted_functions, + &mut self.allowlisted_files, + &mut self.allowlisted_items, &mut self.bitfield_enums, &mut self.constified_enums, &mut self.constified_enum_modules, @@ -2212,10 +473,71 @@ impl BindgenOptions { &mut self.no_hash_types, &mut self.must_use_types, ]; + let record_matches = self.record_matches; + #[cfg(feature = "experimental")] + { + let sets_len = REGEX_SETS_LEN + self.abi_overrides.len(); + let names = if self.emit_diagnostics { + <[&str; REGEX_SETS_LEN]>::into_iter([ + "--blocklist-type", + "--blocklist-function", + "--blocklist-item", + "--blocklist-file", + "--blocklist-var", + "--opaque-type", + "--allowlist-type", + "--allowlist-function", + "--allowlist-var", + "--allowlist-file", + "--allowlist-item", + "--bitfield-enum", + "--newtype-enum", + "--newtype-global-enum", + "--rustified-enum", + "--rustified-enum-non-exhaustive", + "--constified-enum-module", + "--constified-enum", + "--type-alias", + "--new-type-alias", + "--new-type-alias-deref", + "--bindgen-wrapper-union", + "--manually-drop-union", + "--no-partialeq", + "--no-copy", + "--no-debug", + "--no-default", + "--no-hash", + "--must-use", + ]) + .chain((0..self.abi_overrides.len()).map(|_| "--override-abi")) + .map(Some) + .collect() + } else { + vec![None; sets_len] + }; + + for (regex_set, name) in + self.abi_overrides.values_mut().chain(regex_sets).zip(names) + { + regex_set.build_with_diagnostics(record_matches, name); + } + } + #[cfg(not(feature = "experimental"))] for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } + + let rust_target = self.rust_target; + #[allow(deprecated)] + if rust_target <= RustTarget::Stable_1_30 { + deprecated_target_diagnostic(rust_target, self); + } + + // Disable `untagged_union` if the target does not support it. + if !self.rust_features.untagged_union { + self.untagged_union = false; + } } /// Update rust target version @@ -2251,6 +573,10 @@ impl BindgenOptions { .collect() } + fn for_each_callback(&self, f: impl Fn(&dyn callbacks::ParseCallbacks)) { + self.parse_callbacks.iter().for_each(|cb| f(cb.as_ref())); + } + fn process_comment(&self, comment: &str) -> String { let comment = comment::preprocess(comment); self.parse_callbacks @@ -2260,122 +586,25 @@ impl BindgenOptions { } } -impl Default for BindgenOptions { - fn default() -> BindgenOptions { - macro_rules! options { - ($($field:ident $(: $value:expr)?,)* --default-fields-- $($default_field:ident,)*) => { - BindgenOptions { - $($field $(: $value)*,)* - $($default_field: Default::default(),)* - } - }; - } - - let rust_target = RustTarget::default(); - - options! { - rust_target, - rust_features: rust_target.into(), - layout_tests: true, - derive_copy: true, - derive_debug: true, - anon_fields_prefix: DEFAULT_ANON_FIELDS_PREFIX.into(), - convert_floats: true, - codegen_config: CodegenConfig::all(), - generate_comments: true, - allowlist_recursively: true, - enable_mangling: true, - detect_include_paths: true, - prepend_enum_name: true, - record_matches: true, - rustfmt_bindings: true, - size_t_is_usize: true, - - --default-fields-- - blocklisted_types, - blocklisted_functions, - blocklisted_items, - blocklisted_files, - opaque_types, - rustfmt_path, - depfile, - allowlisted_types, - allowlisted_functions, - allowlisted_vars, - allowlisted_files, - default_enum_style, - bitfield_enums, - newtype_enums, - newtype_global_enums, - rustified_enums, - rustified_non_exhaustive_enums, - constified_enums, - constified_enum_modules, - default_macro_constant_type, - default_alias_style, - type_alias, - new_type_alias, - new_type_alias_deref, - default_non_copy_union_style, - bindgen_wrapper_union, - manually_drop_union, - builtins, - emit_ast, - emit_ir, - emit_ir_graphviz, - impl_debug, - impl_partialeq, - derive_default, - derive_hash, - derive_partialord, - derive_ord, - derive_partialeq, - derive_eq, - enable_cxx_namespaces, - enable_function_attribute_detection, - disable_name_namespacing, - disable_nested_struct_naming, - disable_header_comment, - use_core, - ctypes_prefix, - raw_lines, - module_lines, - clang_args, - input_headers, - input_header_contents, - parse_callbacks, - conservative_inline_namespaces, - generate_inline_functions, - generate_block, - objc_extern_crate, - block_extern_crate, - fit_macro_constants, - time_phases, - rustfmt_configuration_file, - no_partialeq_types, - no_copy_types, - no_debug_types, - no_default_types, - no_hash_types, - must_use_types, - array_pointers_in_arguments, - wasm_import_module_name, - dynamic_library_name, - dynamic_link_require_all, - respect_cxx_access_specs, - translate_enum_integer_types, - c_naming, - force_explicit_padding, - vtable_generation, - sort_semantically, - merge_extern_blocks, - abi_overrides, - wrap_unsafe_ops, - wrap_static_fns, - wrap_static_fns_suffix, - wrap_static_fns_path, - } - } +fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { + // warn!("The {} Rust target is deprecated. If you have a need to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target); + + // #[cfg(feature = "experimental")] + // if _options.emit_diagnostics { + // use crate::diagnostics::{Diagnostic, Level}; + + // let mut diagnostic = Diagnostic::default(); + // diagnostic.with_title( + // format!("The {} Rust target is deprecated.", target), + // Level::Warn, + // ); + // diagnostic.add_annotation( + // "This Rust target was passed to `--rust-target`", + // Level::Info, + // ); + // diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help); + // diagnostic.display(); + // } } #[cfg(feature = "runtime")] @@ -2388,17 +617,14 @@ fn ensure_libclang_is_loaded() { // doesn't get dropped prematurely, nor is loaded multiple times // across different threads. - lazy_static! { - static ref LIBCLANG: std::sync::Arc = { - clang_sys::load().expect("Unable to find libclang"); - clang_sys::get_library().expect( - "We just loaded libclang and it had better still be \ - here!", - ) - }; - } + static LIBCLANG: OnceLock> = OnceLock::new(); + let libclang = LIBCLANG.get_or_init(|| { + clang_sys::load().expect("Unable to find libclang"); + clang_sys::get_library() + .expect("We just loaded libclang and it had better still be here!") + }); - clang_sys::set_library(Some(LIBCLANG.clone())); + clang_sys::set_library(Some(libclang.clone())); } #[cfg(not(feature = "runtime"))] @@ -2448,7 +674,6 @@ impl std::error::Error for BindgenError {} #[derive(Debug)] pub struct Bindings { options: BindgenOptions, - warnings: Vec, module: proc_macro2::TokenStream, } @@ -2457,41 +682,46 @@ pub(crate) const HOST_TARGET: &str = // Some architecture triplets are different between rust and libclang, see #1211 // and duplicates. -fn rust_to_clang_target(rust_target: &str) -> String { - if rust_target.starts_with("aarch64-apple-") { - let mut clang_target = "arm64-apple-".to_owned(); - clang_target - .push_str(rust_target.strip_prefix("aarch64-apple-").unwrap()); - return clang_target; - } else if rust_target.starts_with("riscv64gc-") { - let mut clang_target = "riscv64-".to_owned(); - clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); - return clang_target; - } else if rust_target.ends_with("-espidf") { - let mut clang_target = - rust_target.strip_suffix("-espidf").unwrap().to_owned(); - clang_target.push_str("-elf"); - if clang_target.starts_with("riscv32imc-") { - clang_target = "riscv32-".to_owned() + - clang_target.strip_prefix("riscv32imc-").unwrap(); - } - return clang_target; +fn rust_to_clang_target(rust_target: &str) -> Box { + const TRIPLE_HYPHENS_MESSAGE: &str = "Target triple should contain hyphens"; + + let mut clang_target = rust_target.to_owned(); + + if clang_target.starts_with("riscv32") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "riscv32"); + } else if clang_target.starts_with("riscv64") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "riscv64"); + } else if clang_target.starts_with("aarch64-apple-") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "arm64"); + } + + if clang_target.ends_with("-espidf") { + let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range((idx + 1).., "elf"); } - rust_target.to_owned() + + clang_target.into() } /// Returns the effective target, and whether it was explicitly specified on the /// clang flags. -fn find_effective_target(clang_args: &[String]) -> (String, bool) { +fn find_effective_target(clang_args: &[Box]) -> (Box, bool) { let mut args = clang_args.iter(); while let Some(opt) = args.next() { if opt.starts_with("--target=") { let mut split = opt.split('='); split.next(); - return (split.next().unwrap().to_owned(), true); + return (split.next().unwrap().into(), true); } - if opt == "-target" { + if opt.as_ref() == "-target" { if let Some(target) = args.next() { return (target.clone(), true); } @@ -2536,9 +766,10 @@ impl Bindings { // opening libclang.so, it has to be the same architecture and thus the // check is fine. if !explicit_target && !is_host_build { - options - .clang_args - .insert(0, format!("--target={}", effective_target)); + options.clang_args.insert( + 0, + format!("--target={}", effective_target).into_boxed_str(), + ); }; fn detect_include_paths(options: &mut BindgenOptions) { @@ -2559,7 +790,7 @@ impl Bindings { return false; } - let arg = &**arg; + let arg = arg.as_ref(); // https://clang.llvm.org/docs/ClangCommandLineReference.html // -isystem and -isystem-after are harmless. @@ -2576,7 +807,7 @@ impl Bindings { true }) - .cloned() + .map(|arg| arg.clone().into()) .collect::>() }; @@ -2608,8 +839,8 @@ impl Bindings { if let Some(search_paths) = search_paths { for path in search_paths.into_iter() { if let Ok(path) = path.into_os_string().into_string() { - options.clang_args.push("-isystem".to_owned()); - options.clang_args.push(path); + options.clang_args.push("-isystem".into()); + options.clang_args.push(path.into_boxed_str()); } } } @@ -2629,7 +860,7 @@ impl Bindings { } if let Some(h) = options.input_headers.last() { - let path = Path::new(h); + let path = Path::new(h.as_ref()); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { return Err(BindgenError::FolderAsHeader(path.into())); @@ -2639,8 +870,7 @@ impl Bindings { path.into(), )); } - let h = h.clone(); - options.clang_args.push(h); + options.clang_args.push(h.clone()); } else { return Err(BindgenError::NotExist(path.into())); } @@ -2648,9 +878,9 @@ impl Bindings { for (idx, f) in input_unsaved_files.iter().enumerate() { if idx != 0 || !options.input_headers.is_empty() { - options.clang_args.push("-include".to_owned()); + options.clang_args.push("-include".into()); } - options.clang_args.push(f.name.to_str().unwrap().to_owned()) + options.clang_args.push(f.name.to_str().unwrap().into()) } debug!("Fixed-up options: {:?}", options); @@ -2673,14 +903,10 @@ impl Bindings { parse(&mut context)?; } - let (module, options, warnings) = + let (module, options) = codegen::codegen(context).map_err(BindgenError::Codegen)?; - Ok(Bindings { - options, - warnings, - module, - }) + Ok(Bindings { options, module }) } /// Write these bindings as source text to a file. @@ -2696,36 +922,36 @@ impl Bindings { /// Write these bindings as source text to the given `Write`able. pub fn write<'a>(&self, mut writer: Box) -> io::Result<()> { + const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" }; + if !self.options.disable_header_comment { - let version = option_env!("CARGO_PKG_VERSION"); - let header = format!( - "/* automatically generated by rust-bindgen {} */\n\n", - version.unwrap_or("(unknown version)") - ); - writer.write_all(header.as_bytes())?; + let version = + option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)"); + writeln!( + writer, + "/* automatically generated by rust-bindgen {version} */{NL}", + )?; } for line in self.options.raw_lines.iter() { writer.write_all(line.as_bytes())?; - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } if !self.options.raw_lines.is_empty() { - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } - let bindings = self.module.to_string(); - - match self.rustfmt_generated_string(&bindings) { - Ok(rustfmt_bindings) => { - writer.write_all(rustfmt_bindings.as_bytes())?; + match self.format_tokens(&self.module) { + Ok(formatted_bindings) => { + writer.write_all(formatted_bindings.as_bytes())?; } Err(err) => { eprintln!( "Failed to run rustfmt: {} (non-fatal, continuing)", err ); - writer.write_all(bindings.as_bytes())?; + writer.write_all(self.module.to_string().as_bytes())?; } } Ok(()) @@ -2733,36 +959,33 @@ impl Bindings { /// Gets the rustfmt path to rustfmt the generated bindings. fn rustfmt_path(&self) -> io::Result> { - debug_assert!(self.options.rustfmt_bindings); + debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); } if let Ok(rustfmt) = env::var("RUSTFMT") { return Ok(Cow::Owned(rustfmt.into())); } - #[cfg(feature = "which-rustfmt")] - match which::which("rustfmt") { - Ok(p) => Ok(Cow::Owned(p)), - Err(e) => { - Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))) - } - } - #[cfg(not(feature = "which-rustfmt"))] // No rustfmt binary was specified, so assume that the binary is called // "rustfmt" and that it is in the user's PATH. Ok(Cow::Owned("rustfmt".into())) } - /// Checks if rustfmt_bindings is set and runs rustfmt on the string - fn rustfmt_generated_string<'a>( + /// Formats a token stream with the formatter set up in `BindgenOptions`. + fn format_tokens( &self, - source: &'a str, - ) -> io::Result> { + tokens: &proc_macro2::TokenStream, + ) -> io::Result { let _t = time::Timer::new("rustfmt_generated_string") .with_output(self.options.time_phases); - if !self.options.rustfmt_bindings { - return Ok(Cow::Borrowed(source)); + match self.options.formatter { + Formatter::None => return Ok(tokens.to_string()), + #[cfg(feature = "prettyplease")] + Formatter::Prettyplease => { + return Ok(prettyplease::unparse(&syn::parse_quote!(#tokens))); + } + Formatter::Rustfmt => (), } let rustfmt = self.rustfmt_path()?; @@ -2783,7 +1006,7 @@ impl Bindings { let mut child_stdin = child.stdin.take().unwrap(); let mut child_stdout = child.stdout.take().unwrap(); - let source = source.to_owned(); + let source = tokens.to_string(); // Write to stdin in a new thread, so that we can read from stdout on this // thread. This keeps the child from blocking on writing to its stdout which @@ -2804,40 +1027,43 @@ impl Bindings { match String::from_utf8(output) { Ok(bindings) => match status.code() { - Some(0) => Ok(Cow::Owned(bindings)), + Some(0) => Ok(bindings), Some(2) => Err(io::Error::new( io::ErrorKind::Other, "Rustfmt parsing errors.".to_string(), )), Some(3) => { - warn!("Rustfmt could not format some lines."); - Ok(Cow::Owned(bindings)) + rustfmt_non_fatal_error_diagnostic( + "Rustfmt could not format some lines", + &self.options, + ); + Ok(bindings) } _ => Err(io::Error::new( io::ErrorKind::Other, "Internal rustfmt error".to_string(), )), }, - _ => Ok(Cow::Owned(source)), - } - } - - /// Emit all the warning messages raised while generating the bindings in a build script. - /// - /// If you are using `bindgen` outside of a build script you should use [`Bindings::warnings`] - /// and handle the messages accordingly instead. - #[inline] - pub fn emit_warnings(&self) { - for message in &self.warnings { - println!("cargo:warning={}", message); + _ => Ok(source), } } +} - /// Return all the warning messages raised while generating the bindings. - #[inline] - pub fn warnings(&self) -> &[String] { - &self.warnings - } +fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { + warn!("{}", msg); + + // #[cfg(feature = "experimental")] + // if _options.emit_diagnostics { + // use crate::diagnostics::{Diagnostic, Level}; + + // Diagnostic::default() + // .with_title(msg, Level::Warn) + // .add_annotation( + // "The bindings will be generated but not formatted.", + // Level::Note, + // ) + // .display(); + // } } impl std::fmt::Display for Bindings { @@ -2863,20 +1089,19 @@ fn parse_one( ctx: &mut BindgenContext, cursor: clang::Cursor, parent: Option, -) -> clang_sys::CXChildVisitResult { +) { if !filter_builtins(ctx, &cursor) { - return CXChildVisit_Continue; + return; } - use clang_sys::CXChildVisit_Continue; match Item::parse(cursor, parent, ctx) { Ok(..) => {} Err(ParseError::Continue) => {} Err(ParseError::Recurse) => { - cursor.visit(|child| parse_one(ctx, child, parent)); + cursor + .visit_sorted(ctx, |ctx, child| parse_one(ctx, child, parent)); } } - CXChildVisit_Continue } /// Parse the Clang AST into our `Item` internal representation. @@ -2914,8 +1139,8 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { } let root = context.root_module(); - context.with_module(root, |context| { - cursor.visit(|cursor| parse_one(context, cursor, None)) + context.with_module(root, |ctx| { + cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None)) }); assert!( @@ -2962,22 +1187,38 @@ pub fn clang_version() -> ClangVersion { } } +fn env_var + AsRef>( + parse_callbacks: &[Rc], + key: K, +) -> Result { + for callback in parse_callbacks { + callback.read_env_var(key.as_ref()); + } + std::env::var(key) +} + /// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. -fn get_target_dependent_env_var(var: &str) -> Option { - if let Ok(target) = env::var("TARGET") { - if let Ok(v) = env::var(format!("{}_{}", var, target)) { +fn get_target_dependent_env_var( + parse_callbacks: &[Rc], + var: &str, +) -> Option { + if let Ok(target) = env_var(parse_callbacks, "TARGET") { + if let Ok(v) = env_var(parse_callbacks, format!("{}_{}", var, target)) { return Some(v); } - if let Ok(v) = env::var(format!("{}_{}", var, target.replace('-', "_"))) - { + if let Ok(v) = env_var( + parse_callbacks, + format!("{}_{}", var, target.replace('-', "_")), + ) { return Some(v); } } - env::var(var).ok() + + env_var(parse_callbacks, var).ok() } /// A ParseCallbacks implementation that will act on file includes by echoing a rerun-if-changed -/// line +/// line and on env variable usage by echoing a rerun-if-env-changed line /// /// When running inside a `build.rs` script, this can be used to make cargo invalidate the /// generated bindings whenever any of the files included from the header change: @@ -2985,16 +1226,61 @@ fn get_target_dependent_env_var(var: &str) -> Option { /// use bindgen::builder; /// let bindings = builder() /// .header("path/to/input/header") -/// .parse_callbacks(Box::new(bindgen::CargoCallbacks)) +/// .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) /// .generate(); /// ``` #[derive(Debug)] -pub struct CargoCallbacks; +pub struct CargoCallbacks { + rerun_on_header_files: bool, +} + +/// Create a new `CargoCallbacks` value with [`CargoCallbacks::rerun_on_header_files`] disabled. +/// +/// This constructor has been deprecated in favor of [`CargoCallbacks::new`] where +/// [`CargoCallbacks::rerun_on_header_files`] is enabled by default. +#[deprecated = "Use `CargoCallbacks::new()` instead. Please, check the documentation for further information."] +pub const CargoCallbacks: CargoCallbacks = CargoCallbacks { + rerun_on_header_files: false, +}; + +impl CargoCallbacks { + /// Create a new `CargoCallbacks` value. + pub fn new() -> Self { + Self { + rerun_on_header_files: true, + } + } + + /// Whether Cargo should re-run the build script if any of the input header files has changed. + /// + /// This option is enabled by default unless the deprecated [`const@CargoCallbacks`] + /// constructor is used. + pub fn rerun_on_header_files(mut self, doit: bool) -> Self { + self.rerun_on_header_files = doit; + self + } +} + +impl Default for CargoCallbacks { + fn default() -> Self { + Self::new() + } +} impl callbacks::ParseCallbacks for CargoCallbacks { + fn header_file(&self, filename: &str) { + if self.rerun_on_header_files { + println!("cargo:rerun-if-changed={}", filename); + } + } + fn include_file(&self, filename: &str) { println!("cargo:rerun-if-changed={}", filename); } + + fn read_env_var(&self, key: &str) { + println!("cargo:rerun-if-env-changed={}", key); + } } /// Test command_line_flag function. @@ -3004,7 +1290,7 @@ fn commandline_flag_unit_test_function() { let bindings = crate::builder(); let command_line_flags = bindings.command_line_flags(); - let test_cases = vec![ + let test_cases = [ "--rust-target", "--no-derive-default", "--generate", @@ -3023,7 +1309,7 @@ fn commandline_flag_unit_test_function() { .allowlist_function("safe_function"); let command_line_flags = bindings.command_line_flags(); - let test_cases = vec![ + let test_cases = [ "--rust-target", "input_header", "--no-derive-default", @@ -3044,25 +1330,48 @@ fn commandline_flag_unit_test_function() { #[test] fn test_rust_to_clang_target() { - assert_eq!(rust_to_clang_target("aarch64-apple-ios"), "arm64-apple-ios"); + assert_eq!( + rust_to_clang_target("aarch64-apple-ios").as_ref(), + "arm64-apple-ios" + ); } #[test] fn test_rust_to_clang_target_riscv() { assert_eq!( - rust_to_clang_target("riscv64gc-unknown-linux-gnu"), + rust_to_clang_target("riscv64gc-unknown-linux-gnu").as_ref(), "riscv64-unknown-linux-gnu" - ) + ); + assert_eq!( + rust_to_clang_target("riscv64imac-unknown-none-elf").as_ref(), + "riscv64-unknown-none-elf" + ); + assert_eq!( + rust_to_clang_target("riscv32imc-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); + assert_eq!( + rust_to_clang_target("riscv32imac-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); + assert_eq!( + rust_to_clang_target("riscv32imafc-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); + assert_eq!( + rust_to_clang_target("riscv32i-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); } #[test] fn test_rust_to_clang_target_espidf() { assert_eq!( - rust_to_clang_target("riscv32imc-esp-espidf"), + rust_to_clang_target("riscv32imc-esp-espidf").as_ref(), "riscv32-esp-elf" ); assert_eq!( - rust_to_clang_target("xtensa-esp32-espidf"), + rust_to_clang_target("xtensa-esp32-espidf").as_ref(), "xtensa-esp32-elf" ); } diff --git a/bindgen/options/as_args.rs b/bindgen/options/as_args.rs new file mode 100644 index 0000000000000000000000000000000000000000..6918ad9fecafdf203769bab32dcbc99cae5a9de6 --- /dev/null +++ b/bindgen/options/as_args.rs @@ -0,0 +1,52 @@ +use std::path::PathBuf; + +use crate::RegexSet; + +/// Trait used to turn [`crate::BindgenOptions`] fields into CLI args. +pub(super) trait AsArgs { + fn as_args(&self, args: &mut Vec, flag: &str); +} + +/// If the `bool` is `true`, `flag` is pushed into `args`. +/// +/// be careful about the truth value of the field as some options, like `--no-layout-tests`, are +/// actually negations of the fields. +impl AsArgs for bool { + fn as_args(&self, args: &mut Vec, flag: &str) { + if *self { + args.push(flag.to_string()); + } + } +} + +/// Iterate over all the items of the `RegexSet` and push `flag` followed by the item into `args` +/// for each item. +impl AsArgs for RegexSet { + fn as_args(&self, args: &mut Vec, flag: &str) { + for item in self.get_items() { + args.extend_from_slice(&[flag.to_owned(), item.clone().into()]); + } + } +} + +/// If the `Option` is `Some(value)`, push `flag` followed by `value`. +impl AsArgs for Option { + fn as_args(&self, args: &mut Vec, flag: &str) { + if let Some(string) = self { + args.extend_from_slice(&[flag.to_owned(), string.clone()]); + } + } +} + +/// If the `Option` is `Some(path)`, push `flag` followed by the [`std::path::Path::display`] +/// representation of `path`. +impl AsArgs for Option { + fn as_args(&self, args: &mut Vec, flag: &str) { + if let Some(path) = self { + args.extend_from_slice(&[ + flag.to_owned(), + path.display().to_string(), + ]); + } + } +} diff --git a/bindgen/options/helpers.rs b/bindgen/options/helpers.rs new file mode 100644 index 0000000000000000000000000000000000000000..1816c72b572b04bbc1053c0b750c32ad8dd88c35 --- /dev/null +++ b/bindgen/options/helpers.rs @@ -0,0 +1,43 @@ +/// Helper function that appends extra documentation to [`crate::Builder`] methods that support regular +/// expressions in their input. +macro_rules! regex_option { + ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { + $(#[$attrs])* + /// + /// Regular expressions are supported. Check the [regular expression + /// arguments](./struct.Builder.html#regular-expression-arguments) section and the + /// [regex](https://docs.rs/regex) crate documentation for further information. + pub fn $($tokens)* + }; +} + +/// Helper macro to set the default value of each option. +/// +/// This macro is an internal implementation detail of the `options` macro and should not be used +/// directly. +macro_rules! default { + () => { + Default::default() + }; + ($expr:expr) => { + $expr + }; +} + +/// Helper macro to set the conversion to CLI arguments for each option. +/// +/// This macro is an internal implementation detail of the `options` macro and should not be used +/// directly. +macro_rules! as_args { + ($flag:literal) => { + |field, args| AsArgs::as_args(field, args, $flag) + }; + ($expr:expr) => { + $expr + }; +} + +/// Helper function to ignore an option when converting it into CLI arguments. +/// +/// This function is only used inside `options` and should not be used in other contexts. +pub(super) fn ignore(_: &T, _: &mut Vec) {} diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..e4c03ecd4dae7f5373208a6d7ed76eda1cc8b4c2 --- /dev/null +++ b/bindgen/options/mod.rs @@ -0,0 +1,2155 @@ +//! Declarations and setter methods for `bindgen` options. +//! +//! The main entry point of this module is the `options` macro. +#[macro_use] +mod helpers; +mod as_args; + +use crate::callbacks::ParseCallbacks; +use crate::codegen::{ + AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, +}; +use crate::deps::DepfileSpec; +use crate::features::{RustFeatures, RustTarget}; +use crate::regex_set::RegexSet; +use crate::Abi; +use crate::Builder; +use crate::CodegenConfig; +use crate::FieldVisibilityKind; +use crate::Formatter; +use crate::HashMap; +use crate::DEFAULT_ANON_FIELDS_PREFIX; + +use std::env; +use std::path::{Path, PathBuf}; +use std::rc::Rc; + +use as_args::AsArgs; +use helpers::ignore; + +/// Macro used to generate the [`BindgenOptions`] type and the [`Builder`] setter methods for each +/// one of the fields of `BindgenOptions`. +/// +/// The input format of this macro resembles a `struct` pattern. Each field of the `BindgenOptions` +/// type is declared by adding the name of the field and its type using the `name: type` syntax and +/// a block of code with the following items: +/// +/// - `default`: The default value for the field. If this item is omitted, `Default::default()` is +/// used instead, meaning that the type of the field must implement `Default`. +/// - `methods`: A block of code containing methods for the `Builder` type. These methods should be +/// related to the field being declared. +/// - `as_args`: This item declares how the field should be converted into a valid CLI argument for +/// `bindgen` and is used in the [`Builder::command_line_flags`] method which is used to do a +/// roundtrip test of the CLI args in the `bindgen-test` crate. This item can take one of the +/// following: +/// - A string literal with the flag if the type of the field implements the [`AsArgs`] trait. +/// - A closure with the signature `|field, args: &mut Vec| -> ()` that pushes arguments +/// into the `args` buffer based on the value of the field. This is used if the field does not +/// implement `AsArgs` or if the implementation of the trait is not logically correct for the +/// option and a custom behavior must be taken into account. +/// - The `ignore` literal, which does not emit any CLI arguments for this field. This is useful +/// if the field cannot be used from the `bindgen` CLI. +/// +/// As an example, this would be the declaration of a `bool` field called `be_fun` whose default +/// value is `false` (the `Default` value for `bool`): +/// ```rust,ignore +/// be_fun: bool { +/// methods: { +/// /// Ask `bindgen` to be fun. This option is disabled by default. +/// fn be_fun(mut self) -> Self { +/// self.options.be_fun = true; +/// self +/// } +/// }, +/// as_args: "--be-fun", +/// } +/// ``` +/// +/// However, we could also set the `be_fun` field to `true` by default and use a `--not-fun` flag +/// instead. This means that we have to add the `default` item and use a closure in the `as_args` +/// item: +/// ```rust,ignore +/// be_fun: bool { +/// default: true, +/// methods: { +/// /// Ask `bindgen` to not be fun. `bindgen` is fun by default. +/// fn not_fun(mut self) -> Self { +/// self.options.be_fun = false; +/// self +/// } +/// }, +/// as_args: |be_fun, args| (!be_fun).as_args(args, "--not-fun"), +/// } +/// ``` +/// More complex examples can be found in the sole invocation of this macro. +macro_rules! options { + ($( + $(#[doc = $docs:literal])+ + $field:ident: $ty:ty { + $(default: $default:expr,)? + methods: {$($methods_tokens:tt)*}$(,)? + as_args: $as_args:expr$(,)? + }$(,)? + )*) => { + #[derive(Debug, Clone)] + pub(crate) struct BindgenOptions { + $($(#[doc = $docs])* pub(crate) $field: $ty,)* + } + + impl Default for BindgenOptions { + fn default() -> Self { + Self { + $($field: default!($($default)*),)* + } + } + } + + impl Builder { + /// Generates the command line flags used to create this [`Builder`]. + pub fn command_line_flags(&self) -> Vec { + let mut args = vec![]; + + let headers = match self.options.input_headers.split_last() { + Some((header, headers)) => { + // The last input header is passed as an argument in the first position. + args.push(header.clone().into()); + headers + }, + None => &[] + }; + + $({ + let func: fn(&$ty, &mut Vec) = as_args!($as_args); + func(&self.options.$field, &mut args); + })* + + // Add the `--experimental` flag if `bindgen` is built with the `experimental` + // feature. + if cfg!(feature = "experimental") { + args.push("--experimental".to_owned()); + } + + // Add all the clang arguments. + args.push("--".to_owned()); + + if !self.options.clang_args.is_empty() { + args.extend(self.options.clang_args.iter().map(|s| s.clone().into())); + } + + // We need to pass all but the last header via the `-include` clang argument. + for header in headers { + args.push("-include".to_owned()); + args.push(header.clone().into()); + } + + args + } + + $($($methods_tokens)*)* + } + }; +} + +options! { + /// Types that have been blocklisted and should not appear anywhere in the generated code. + blocklisted_types: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the given type. + /// + /// This option is not recursive, meaning that it will only block types whose names + /// explicitly match the argument of this method. + pub fn blocklist_type>(mut self, arg: T) -> Builder { + self.options.blocklisted_types.insert(arg); + self + } + } + }, + as_args: "--blocklist-type", + }, + /// Functions that have been blocklisted and should not appear in the generated code. + blocklisted_functions: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the given function. + /// + /// This option is not recursive, meaning that it will only block functions whose + /// names explicitly match the argument of this method. + pub fn blocklist_function>(mut self, arg: T) -> Builder { + self.options.blocklisted_functions.insert(arg); + self + } + } + }, + as_args: "--blocklist-function", + }, + /// Items that have been blocklisted and should not appear in the generated code. + blocklisted_items: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the given item, regardless of whether it is a + /// type, function, module, etc. + /// + /// This option is not recursive, meaning that it will only block items whose names + /// explicitly match the argument of this method. + pub fn blocklist_item>(mut self, arg: T) -> Builder { + self.options.blocklisted_items.insert(arg); + self + } + } + }, + as_args: "--blocklist-item", + }, + /// Files whose contents should be blocklisted and should not appear in the generated code. + blocklisted_files: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the contents of the given file, regardless of + /// whether the contents of the file are types, functions, modules, etc. + /// + /// This option is not recursive, meaning that it will only block files whose names + /// explicitly match the argument of this method. + /// + /// This method will use the argument to match the complete path of the file + /// instead of a section of it. + pub fn blocklist_file>(mut self, arg: T) -> Builder { + self.options.blocklisted_files.insert(arg); + self + } + } + }, + as_args: "--blocklist-file", + }, + /// Variables that have been blocklisted and should not appear in the generated code. + blocklisted_vars: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the given variable. + /// + /// This option is not recursive, meaning that it will only block variables whose + /// names explicitly match the argument of this method. + pub fn blocklist_var>(mut self, arg: T) -> Builder { + self.options.blocklisted_vars.insert(arg); + self + } + } + }, + as_args: "--blocklist-var", + }, + /// Types that should be treated as opaque structures in the generated code. + opaque_types: RegexSet { + methods: { + regex_option! { + /// Treat the given type as opaque in the generated bindings. + /// + /// Opaque in this context means that none of the generated bindings will contain + /// information about the inner representation of the type and the type itself will + /// be represented as a chunk of bytes with the alignment and size of the type. + pub fn opaque_type>(mut self, arg: T) -> Builder { + self.options.opaque_types.insert(arg); + self + } + } + }, + as_args: "--opaque-type", + }, + /// The explicit `rustfmt` path. + rustfmt_path: Option { + methods: { + /// Set an explicit path to the `rustfmt` binary. + /// + /// This option only comes into effect if `rustfmt` is set to be the formatter used by + /// `bindgen`. Check the documentation of the [`Builder::formatter`] method for more + /// information. + pub fn with_rustfmt>(mut self, path: P) -> Self { + self.options.rustfmt_path = Some(path.into()); + self + } + }, + // This option cannot be set from the CLI. + as_args: ignore, + }, + /// The path to which we should write a Makefile-syntax depfile (if any). + depfile: Option { + methods: { + /// Add a depfile output which will be written alongside the generated bindings. + pub fn depfile, D: Into>( + mut self, + output_module: H, + depfile: D, + ) -> Builder { + self.options.depfile = Some(DepfileSpec { + output_module: output_module.into(), + depfile_path: depfile.into(), + }); + self + } + }, + as_args: |depfile, args| { + if let Some(depfile) = depfile { + args.push("--depfile".into()); + args.push(depfile.depfile_path.display().to_string()); + } + }, + }, + /// Types that have been allowlisted and should appear in the generated code. + allowlisted_types: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the given type. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_type>(mut self, arg: T) -> Builder { + self.options.allowlisted_types.insert(arg); + self + } + } + }, + as_args: "--allowlist-type", + }, + /// Functions that have been allowlisted and should appear in the generated code. + allowlisted_functions: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the given function. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_function>(mut self, arg: T) -> Builder { + self.options.allowlisted_functions.insert(arg); + self + } + } + }, + as_args: "--allowlist-function", + }, + /// Variables that have been allowlisted and should appear in the generated code. + allowlisted_vars: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the given variable. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_var>(mut self, arg: T) -> Builder { + self.options.allowlisted_vars.insert(arg); + self + } + } + }, + as_args: "--allowlist-var", + }, + /// Files whose contents have been allowlisted and should appear in the generated code. + allowlisted_files: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the content of the given file. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + /// + /// This method will use the argument to match the complete path of the file + /// instead of a section of it. + pub fn allowlist_file>(mut self, arg: T) -> Builder { + self.options.allowlisted_files.insert(arg); + self + } + } + }, + as_args: "--allowlist-file", + }, + /// Items that have been allowlisted and should appear in the generated code. + allowlisted_items: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the given item, regardless of whether it is a type, + /// function, module, etc. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_item>(mut self, arg: T) -> Builder { + self.options.allowlisted_items.insert(arg); + self + } + } + }, + as_args: "--allowlist-item", + }, + /// The default style of for generated `enum`s. + default_enum_style: EnumVariation { + methods: { + /// Set the default style for generated `enum`s. + /// + /// If this method is not called, the [`EnumVariation::Consts`] style will be used by + /// default. + /// + /// To set the style for individual `enum`s, use [`Builder::bitfield_enum`], + /// [`Builder::newtype_enum`], [`Builder::newtype_global_enum`], + /// [`Builder::rustified_enum`], [`Builder::rustified_non_exhaustive_enum`], + /// [`Builder::constified_enum_module`] or [`Builder::constified_enum`]. + pub fn default_enum_style( + mut self, + arg: EnumVariation, + ) -> Builder { + self.options.default_enum_style = arg; + self + } + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-enum-style".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// `enum`s marked as bitfield-like. This is, newtypes with bitwise operations. + bitfield_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as being bitfield-like. + /// + /// This is similar to the [`Builder::newtype_enum`] style, but with the bitwise + /// operators implemented. + pub fn bitfield_enum>(mut self, arg: T) -> Builder { + self.options.bitfield_enums.insert(arg); + self + } + } + }, + as_args: "--bitfield-enum", + }, + /// `enum`s marked as newtypes. + newtype_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a newtype. + /// + /// This means that an integer newtype will be declared to represent the `enum` + /// type and its variants will be represented as constants inside of this type's + /// `impl` block. + pub fn newtype_enum>(mut self, arg: T) -> Builder { + self.options.newtype_enums.insert(arg); + self + } + } + }, + as_args: "--newtype-enum", + }, + /// `enum`s marked as global newtypes . + newtype_global_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a global newtype. + /// + /// This is similar to the [`Builder::newtype_enum`] style, but the constants for + /// each variant are free constants instead of being declared inside an `impl` + /// block for the newtype. + pub fn newtype_global_enum>(mut self, arg: T) -> Builder { + self.options.newtype_global_enums.insert(arg); + self + } + } + }, + as_args: "--newtype-global-enum", + }, + /// `enum`s marked as Rust `enum`s. + rustified_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a Rust `enum`. + /// + /// This means that each variant of the `enum` will be represented as a Rust `enum` + /// variant. + /// + /// **Use this with caution**, creating an instance of a Rust `enum` with an + /// invalid value will cause undefined behaviour. To avoid this, use the + /// [`Builder::newtype_enum`] style instead. + pub fn rustified_enum>(mut self, arg: T) -> Builder { + self.options.rustified_enums.insert(arg); + self + } + } + }, + as_args: "--rustified-enum", + }, + /// `enum`s marked as non-exhaustive Rust `enum`s. + rustified_non_exhaustive_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a non-exhaustive Rust `enum`. + /// + /// This is similar to the [`Builder::rustified_enum`] style, but the `enum` is + /// tagged with the `#[non_exhaustive]` attribute. + pub fn rustified_non_exhaustive_enum>(mut self, arg: T) -> Builder { + self.options.rustified_non_exhaustive_enums.insert(arg); + self + } + } + }, + as_args: "--rustified-non-exhaustive-enums", + }, + /// `enum`s marked as modules of constants. + constified_enum_modules: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a module with a set of integer constants. + pub fn constified_enum_module>(mut self, arg: T) -> Builder { + self.options.constified_enum_modules.insert(arg); + self + } + } + }, + as_args: "--constified-enum-module", + }, + /// `enum`s marked as a set of constants. + constified_enums: RegexSet { + methods: { + regex_option! { + /// Mark the given `enum` as a set of integer constants. + /// + /// This is similar to the [`Builder::constified_enum_module`] style, but the + /// constants are generated in the current module instead of in a new module. + pub fn constified_enum>(mut self, arg: T) -> Builder { + self.options.constified_enums.insert(arg); + self + } + } + }, + as_args: "--constified-enum", + }, + /// The default type signedness for C macro constants. + default_macro_constant_type: MacroTypeVariation { + methods: { + /// Set the default type signedness to be used for macro constants. + /// + /// If this method is not called, [`MacroTypeVariation::Unsigned`] is used by default. + /// + /// To set the type for individual macro constants, use the + /// [`ParseCallbacks::int_macro`] method. + pub fn default_macro_constant_type(mut self, arg: MacroTypeVariation) -> Builder { + self.options.default_macro_constant_type = arg; + self + } + + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-macro-constant-type".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// The default style of code generation for `typedef`s. + default_alias_style: AliasVariation { + methods: { + /// Set the default style of code generation for `typedef`s. + /// + /// If this method is not called, the [`AliasVariation::TypeAlias`] style is used by + /// default. + /// + /// To set the style for individual `typedefs`s, use [`Builder::type_alias`], + /// [`Builder::new_type_alias`] or [`Builder::new_type_alias_deref`]. + pub fn default_alias_style( + mut self, + arg: AliasVariation, + ) -> Builder { + self.options.default_alias_style = arg; + self + } + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-alias-style".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// `typedef` patterns that will use regular type aliasing. + type_alias: RegexSet { + methods: { + regex_option! { + /// Mark the given `typedef` as a regular Rust `type` alias. + /// + /// This is the default behavior, meaning that this method only comes into effect + /// if a style different from [`AliasVariation::TypeAlias`] was passed to the + /// [`Builder::default_alias_style`] method. + pub fn type_alias>(mut self, arg: T) -> Builder { + self.options.type_alias.insert(arg); + self + } + } + }, + as_args: "--type-alias", + }, + /// `typedef` patterns that will be aliased by creating a newtype. + new_type_alias: RegexSet { + methods: { + regex_option! { + /// Mark the given `typedef` as a Rust newtype by having the aliased + /// type be wrapped in a `struct` with `#[repr(transparent)]`. + /// + /// This method can be used to enforce stricter type checking. + pub fn new_type_alias>(mut self, arg: T) -> Builder { + self.options.new_type_alias.insert(arg); + self + } + } + }, + as_args: "--new-type-alias", + }, + /// `typedef` patterns that will be wrapped in a newtype implementing `Deref` and `DerefMut`. + new_type_alias_deref: RegexSet { + methods: { + regex_option! { + /// Mark the given `typedef` to be generated as a newtype that can be dereferenced. + /// + /// This is similar to the [`Builder::new_type_alias`] style, but the newtype + /// implements `Deref` and `DerefMut` with the aliased type as a target. + pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { + self.options.new_type_alias_deref.insert(arg); + self + } + } + }, + as_args: "--new-type-alias-deref", + }, + /// The default style of code to generate for `union`s containing non-`Copy` members. + default_non_copy_union_style: NonCopyUnionStyle { + methods: { + /// Set the default style of code to generate for `union`s with non-`Copy` members. + /// + /// If this method is not called, the [`NonCopyUnionStyle::BindgenWrapper`] style is + /// used by default. + /// + /// To set the style for individual `union`s, use [`Builder::bindgen_wrapper_union`] or + /// [`Builder::manually_drop_union`]. + pub fn default_non_copy_union_style(mut self, arg: NonCopyUnionStyle) -> Self { + self.options.default_non_copy_union_style = arg; + self + } + }, + as_args: |style, args| { + if *style != Default::default() { + args.push("--default-non-copy-union-style".to_owned()); + args.push(style.to_string()); + } + }, + }, + /// The patterns marking non-`Copy` `union`s as using the `bindgen` generated wrapper. + bindgen_wrapper_union: RegexSet { + methods: { + regex_option! { + /// Mark the given `union` to use a `bindgen`-generated wrapper for its members if at + /// least one them is not `Copy`. + /// + /// This is the default behavior, meaning that this method only comes into effect + /// if a style different from [`NonCopyUnionStyle::BindgenWrapper`] was passed to + /// the [`Builder::default_non_copy_union_style`] method. + pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { + self.options.bindgen_wrapper_union.insert(arg); + self + } + } + }, + as_args: "--bindgen-wrapper-union", + }, + /// The patterns marking non-`Copy` `union`s as using the `ManuallyDrop` wrapper. + manually_drop_union: RegexSet { + methods: { + regex_option! { + /// Mark the given `union` to use [`::core::mem::ManuallyDrop`] for its members if + /// at least one of them is not `Copy`. + /// + /// The `ManuallyDrop` type was stabilized in Rust 1.20.0, do not use this option + /// if your target version is lower than this. + pub fn manually_drop_union>(mut self, arg: T) -> Self { + self.options.manually_drop_union.insert(arg); + self + } + } + + }, + as_args: "--manually-drop-union", + }, + + + /// Whether we should generate built-in definitions. + builtins: bool { + methods: { + /// Generate Rust bindings for built-in definitions (for example `__builtin_va_list`). + /// + /// Bindings for built-in definitions are not emitted by default. + pub fn emit_builtins(mut self) -> Builder { + self.options.builtins = true; + self + } + }, + as_args: "--builtins", + }, + /// Whether we should dump the Clang AST for debugging purposes. + emit_ast: bool { + methods: { + /// Emit the Clang AST to `stdout` for debugging purposes. + /// + /// The Clang AST is not emitted by default. + pub fn emit_clang_ast(mut self) -> Builder { + self.options.emit_ast = true; + self + } + }, + as_args: "--emit-clang-ast", + }, + /// Whether we should dump our IR for debugging purposes. + emit_ir: bool { + methods: { + /// Emit the `bindgen` internal representation to `stdout` for debugging purposes. + /// + /// This internal representation is not emitted by default. + pub fn emit_ir(mut self) -> Builder { + self.options.emit_ir = true; + self + } + }, + as_args: "--emit-ir", + }, + /// Output path for the `graphviz` DOT file. + emit_ir_graphviz: Option { + methods: { + /// Set the path for the file where the`bindgen` internal representation will be + /// emitted as a graph using the `graphviz` DOT language. + /// + /// This graph representation is not emitted by default. + pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { + let path = path.into(); + self.options.emit_ir_graphviz = Some(path); + self + } + }, + as_args: "--emit-ir-graphviz", + }, + + /// Whether we should emulate C++ namespaces with Rust modules. + enable_cxx_namespaces: bool { + methods: { + /// Emulate C++ namespaces using Rust modules in the generated bindings. + /// + /// C++ namespaces are not emulated by default. + pub fn enable_cxx_namespaces(mut self) -> Builder { + self.options.enable_cxx_namespaces = true; + self + } + }, + as_args: "--enable-cxx-namespaces", + }, + /// Whether we should try to find unexposed attributes in functions. + enable_function_attribute_detection: bool { + methods: { + /// Enable detecting function attributes on C functions. + /// + /// This enables the following features: + /// - Add `#[must_use]` attributes to Rust items whose C counterparts are marked as so. + /// This feature also requires that the Rust target version supports the attribute. + /// - Set `!` as the return type for Rust functions whose C counterparts are marked as + /// diverging. + /// + /// This option can be quite slow in some cases (check [#1465]), so it is disabled by + /// default. + /// + /// [#1465]: https://github.com/rust-lang/rust-bindgen/issues/1465 + pub fn enable_function_attribute_detection(mut self) -> Self { + self.options.enable_function_attribute_detection = true; + self + } + + }, + as_args: "--enable-function-attribute-detection", + }, + /// Whether we should avoid mangling names with namespaces. + disable_name_namespacing: bool { + methods: { + /// Disable name auto-namespacing. + /// + /// By default, `bindgen` mangles names like `foo::bar::Baz` to look like `foo_bar_Baz` + /// instead of just `Baz`. This method disables that behavior. + /// + /// Note that this does not change the names used for allowlisting and blocklisting, + /// which should still be mangled with the namespaces. Additionally, this option may + /// cause `bindgen` to generate duplicate names. + pub fn disable_name_namespacing(mut self) -> Builder { + self.options.disable_name_namespacing = true; + self + } + }, + as_args: "--disable-name-namespacing", + }, + /// Whether we should avoid generating nested `struct` names. + disable_nested_struct_naming: bool { + methods: { + /// Disable nested `struct` naming. + /// + /// The following `struct`s have different names for C and C++. In C, they are visible + /// as `foo` and `bar`. In C++, they are visible as `foo` and `foo::bar`. + /// + /// ```c + /// struct foo { + /// struct bar { + /// } b; + /// }; + /// ``` + /// + /// `bindgen` tries to avoid duplicate names by default, so it follows the C++ naming + /// convention and it generates `foo` and `foo_bar` instead of just `foo` and `bar`. + /// + /// This method disables this behavior and it is indented to be used only for headers + /// that were written in C. + pub fn disable_nested_struct_naming(mut self) -> Builder { + self.options.disable_nested_struct_naming = true; + self + } + }, + as_args: "--disable-nested-struct-naming", + }, + /// Whether we should avoid embedding version identifiers into source code. + disable_header_comment: bool { + methods: { + /// Do not insert the `bindgen` version identifier into the generated bindings. + /// + /// This identifier is inserted by default. + pub fn disable_header_comment(mut self) -> Self { + self.options.disable_header_comment = true; + self + } + + }, + as_args: "--disable-header-comment", + }, + /// Whether we should generate layout tests for generated `struct`s. + layout_tests: bool { + default: true, + methods: { + /// Set whether layout tests should be generated. + /// + /// Layout tests are generated by default. + pub fn layout_tests(mut self, doit: bool) -> Self { + self.options.layout_tests = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-layout-tests"), + }, + /// Whether we should implement `Debug` for types that cannot derive it. + impl_debug: bool { + methods: { + /// Set whether `Debug` should be implemented for types that cannot derive it. + /// + /// This option is disabled by default. + pub fn impl_debug(mut self, doit: bool) -> Self { + self.options.impl_debug = doit; + self + } + + }, + as_args: "--impl-debug", + }, + /// Whether we should implement `PartialEq` types that cannot derive it. + impl_partialeq: bool { + methods: { + /// Set whether `PartialEq` should be implemented for types that cannot derive it. + /// + /// This option is disabled by default. + pub fn impl_partialeq(mut self, doit: bool) -> Self { + self.options.impl_partialeq = doit; + self + } + }, + as_args: "--impl-partialeq", + }, + /// Whether we should derive `Copy` when possible. + derive_copy: bool { + default: true, + methods: { + /// Set whether the `Copy` trait should be derived when possible. + /// + /// `Copy` is derived by default. + pub fn derive_copy(mut self, doit: bool) -> Self { + self.options.derive_copy = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-derive-copy"), + }, + + /// Whether we should derive `Debug` when possible. + derive_debug: bool { + default: true, + methods: { + /// Set whether the `Debug` trait should be derived when possible. + /// + /// The [`Builder::impl_debug`] method can be used to implement `Debug` for types that + /// cannot derive it. + /// + /// `Debug` is derived by default. + pub fn derive_debug(mut self, doit: bool) -> Self { + self.options.derive_debug = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-derive-debug"), + }, + + /// Whether we should derive `Default` when possible. + derive_default: bool { + methods: { + /// Set whether the `Default` trait should be derived when possible. + /// + /// `Default` is not derived by default. + pub fn derive_default(mut self, doit: bool) -> Self { + self.options.derive_default = doit; + self + } + }, + as_args: |&value, args| { + let arg = if value { + "--with-derive-default" + } else { + "--no-derive-default" + }; + + args.push(arg.to_owned()); + }, + }, + /// Whether we should derive `Hash` when possible. + derive_hash: bool { + methods: { + /// Set whether the `Hash` trait should be derived when possible. + /// + /// `Hash` is not derived by default. + pub fn derive_hash(mut self, doit: bool) -> Self { + self.options.derive_hash = doit; + self + } + }, + as_args: "--with-derive-hash", + }, + /// Whether we should derive `PartialOrd` when possible. + derive_partialord: bool { + methods: { + /// Set whether the `PartialOrd` trait should be derived when possible. + /// + /// Take into account that `Ord` cannot be derived for a type that does not implement + /// `PartialOrd`. For this reason, setting this method to `false` also sets + /// automatically [`Builder::derive_ord`] to `false`. + /// + /// `PartialOrd` is not derived by default. + pub fn derive_partialord(mut self, doit: bool) -> Self { + self.options.derive_partialord = doit; + if !doit { + self.options.derive_ord = false; + } + self + } + }, + as_args: "--with-derive-partialord", + }, + /// Whether we should derive `Ord` when possible. + derive_ord: bool { + methods: { + /// Set whether the `Ord` trait should be derived when possible. + /// + /// Take into account that `Ord` cannot be derived for a type that does not implement + /// `PartialOrd`. For this reason, the value set with this method will also be set + /// automatically for [`Builder::derive_partialord`]. + /// + /// `Ord` is not derived by default. + pub fn derive_ord(mut self, doit: bool) -> Self { + self.options.derive_ord = doit; + self.options.derive_partialord = doit; + self + } + }, + as_args: "--with-derive-ord", + }, + /// Whether we should derive `PartialEq` when possible. + derive_partialeq: bool { + methods: { + /// Set whether the `PartialEq` trait should be derived when possible. + /// + /// Take into account that `Eq` cannot be derived for a type that does not implement + /// `PartialEq`. For this reason, setting this method to `false` also sets + /// automatically [`Builder::derive_eq`] to `false`. + /// + /// The [`Builder::impl_partialeq`] method can be used to implement `PartialEq` for + /// types that cannot derive it. + /// + /// `PartialEq` is not derived by default. + pub fn derive_partialeq(mut self, doit: bool) -> Self { + self.options.derive_partialeq = doit; + if !doit { + self.options.derive_eq = false; + } + self + } + }, + as_args: "--with-derive-partialeq", + }, + /// Whether we should derive `Eq` when possible. + derive_eq: bool { + methods: { + /// Set whether the `Eq` trait should be derived when possible. + /// + /// Take into account that `Eq` cannot be derived for a type that does not implement + /// `PartialEq`. For this reason, the value set with this method will also be set + /// automatically for [`Builder::derive_partialeq`]. + /// + /// `Eq` is not derived by default. + pub fn derive_eq(mut self, doit: bool) -> Self { + self.options.derive_eq = doit; + if doit { + self.options.derive_partialeq = doit; + } + self + } + }, + as_args: "--with-derive-eq", + }, + /// Whether we should use `core` instead of `std`. + /// + /// If this option is enabled and the Rust target version is greater than 1.64, the prefix for + /// C platform-specific types will be `::core::ffi` instead of `::core::os::raw`. + use_core: bool { + methods: { + /// Use `core` instead of `std` in the generated bindings. + /// + /// `std` is used by default. + pub fn use_core(mut self) -> Builder { + self.options.use_core = true; + self + } + + }, + as_args: "--use-core", + }, + /// An optional prefix for the C platform-specific types. + ctypes_prefix: Option { + methods: { + /// Use the given prefix for the C platform-specific types instead of `::std::os::raw`. + /// + /// Alternatively, the [`Builder::use_core`] method can be used to set the prefix to + /// `::core::ffi` or `::core::os::raw`. + pub fn ctypes_prefix>(mut self, prefix: T) -> Builder { + self.options.ctypes_prefix = Some(prefix.into()); + self + } + }, + as_args: "--ctypes-prefix", + }, + /// The prefix for anonymous fields. + anon_fields_prefix: String { + default: DEFAULT_ANON_FIELDS_PREFIX.into(), + methods: { + /// Use the given prefix for the anonymous fields. + /// + /// An anonymous field, is a field of a C/C++ type that does not have a name. For + /// example, in the following C code: + /// ```c + /// struct integer { + /// struct { + /// int inner; + /// }; + /// } + /// ``` + /// + /// The only field of the `integer` `struct` is an anonymous field and its Rust + /// representation will be named using this prefix followed by an integer identifier. + /// + /// The default prefix is `__bindgen_anon_`. + pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { + self.options.anon_fields_prefix = prefix.into(); + self + } + }, + as_args: |prefix, args| { + if prefix != DEFAULT_ANON_FIELDS_PREFIX { + args.push("--anon-fields-prefix".to_owned()); + args.push(prefix.clone()); + } + }, + }, + /// Whether to measure the time for each one of the `bindgen` phases. + time_phases: bool { + methods: { + /// Set whether to measure the elapsed time for each one of the `bindgen` phases. This + /// information is printed to `stderr`. + /// + /// The elapsed time is not measured by default. + pub fn time_phases(mut self, doit: bool) -> Self { + self.options.time_phases = doit; + self + } + }, + as_args: "--time-phases", + }, + /// Whether to convert C float types to `f32` and `f64`. + convert_floats: bool { + default: true, + methods: { + /// Avoid converting C float types to `f32` and `f64`. + pub fn no_convert_floats(mut self) -> Self { + self.options.convert_floats = false; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-convert-floats"), + }, + /// The set of raw lines to be prepended to the top-level module of the generated Rust code. + raw_lines: Vec> { + methods: { + /// Add a line of Rust code at the beginning of the generated bindings. The string is + /// passed through without any modification. + pub fn raw_line>(mut self, arg: T) -> Self { + self.options.raw_lines.push(arg.into().into_boxed_str()); + self + } + }, + as_args: |raw_lines, args| { + for line in raw_lines { + args.push("--raw-line".to_owned()); + args.push(line.clone().into()); + } + }, + }, + /// The set of raw lines to prepend to different modules. + module_lines: HashMap, Vec>> { + methods: { + /// Add a given line to the beginning of a given module. + /// + /// This option only comes into effect if the [`Builder::enable_cxx_namespaces`] method + /// is also being called. + pub fn module_raw_line(mut self, module: T, line: U) -> Self + where + T: Into, + U: Into, + { + self.options + .module_lines + .entry(module.into().into_boxed_str()) + .or_default() + .push(line.into().into_boxed_str()); + self + } + }, + as_args: |module_lines, args| { + for (module, lines) in module_lines { + for line in lines.iter() { + args.push("--module-raw-line".to_owned()); + args.push(module.clone().into()); + args.push(line.clone().into()); + } + } + }, + }, + /// The input header files. + input_headers: Vec> { + methods: { + /// Add an input C/C++ header to generate bindings for. + /// + /// This can be used to generate bindings for a single header: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .header("input.h") + /// .generate() + /// .unwrap(); + /// ``` + /// + /// Or for multiple headers: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .header("first.h") + /// .header("second.h") + /// .header("third.h") + /// .generate() + /// .unwrap(); + /// ``` + pub fn header>(mut self, header: T) -> Builder { + self.options.input_headers.push(header.into().into_boxed_str()); + self + } + + /// Add input C/C++ header(s) to generate bindings for. + /// + /// This can be used to generate bindings for a single header: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .headers(["input.h"]) + /// .generate() + /// .unwrap(); + /// ``` + /// + /// Or for multiple headers: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .headers(["first.h", "second.h", "third.h"]) + /// .generate() + /// .unwrap(); + /// ``` + pub fn headers(mut self, headers: I) -> Builder + where + I::Item: Into, + { + self.options + .input_headers + .extend(headers.into_iter().map(Into::into).map(Into::into)); + self + } + }, + // This field is handled specially inside the macro. + as_args: ignore, + }, + /// The set of arguments to be passed straight through to Clang. + clang_args: Vec> { + methods: { + /// Add an argument to be passed straight through to Clang. + pub fn clang_arg>(self, arg: T) -> Builder { + self.clang_args([arg.into().into_boxed_str()]) + } + + /// Add several arguments to be passed straight through to Clang. + pub fn clang_args(mut self, args: I) -> Builder + where + I::Item: AsRef, + { + for arg in args { + self.options.clang_args.push(arg.as_ref().to_owned().into_boxed_str()); + } + self + } + }, + // This field is handled specially inside the macro. + as_args: ignore, + }, + /// Tuples of unsaved file contents of the form (name, contents). + input_header_contents: Vec<(Box, Box)> { + methods: { + /// Add `contents` as an input C/C++ header named `name`. + /// + /// This can be used to inject additional C/C++ code as an input without having to + /// create additional header files. + pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { + // Apparently clang relies on having virtual FS correspondent to + // the real one, so we need absolute paths here + let absolute_path = env::current_dir() + .expect("Cannot retrieve current directory") + .join(name) + .to_str() + .expect("Cannot convert current directory name to string") + .into(); + self.options + .input_header_contents + .push((absolute_path, contents.into())); + self + } + }, + // Header contents cannot be added from the CLI. + as_args: ignore, + }, + /// A user-provided visitor to allow customizing different kinds of situations. + parse_callbacks: Vec> { + methods: { + /// Add a new [`ParseCallbacks`] instance to configure types in different situations. + /// + /// This can also be used with [`CargoCallbacks`](struct@crate::CargoCallbacks) to emit + /// `cargo:rerun-if-changed=...` for all `#include`d header files. + pub fn parse_callbacks(mut self, cb: Box) -> Self { + self.options.parse_callbacks.push(Rc::from(cb)); + self + } + }, + as_args: |_callbacks, _args| { + #[cfg(feature = "__cli")] + for cb in _callbacks { + _args.extend(cb.cli_args()); + } + }, + }, + /// Which kind of items should we generate. We generate all of them by default. + codegen_config: CodegenConfig { + default: CodegenConfig::all(), + methods: { + /// Do not generate any functions. + /// + /// Functions are generated by default. + pub fn ignore_functions(mut self) -> Builder { + self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); + self + } + + /// Do not generate any methods. + /// + /// Methods are generated by default. + pub fn ignore_methods(mut self) -> Builder { + self.options.codegen_config.remove(CodegenConfig::METHODS); + self + } + + /// Choose what to generate using a [`CodegenConfig`]. + /// + /// This option overlaps with [`Builder::ignore_functions`] and + /// [`Builder::ignore_methods`]. + /// + /// All the items in `CodegenConfig` are generated by default. + pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { + self.options.codegen_config = config; + self + } + }, + as_args: |codegen_config, args| { + if !codegen_config.functions() { + args.push("--ignore-functions".to_owned()); + } + + args.push("--generate".to_owned()); + + //Temporary placeholder for the 4 options below. + let mut options: Vec = Vec::new(); + if codegen_config.functions() { + options.push("functions".to_owned()); + } + + if codegen_config.types() { + options.push("types".to_owned()); + } + + if codegen_config.vars() { + options.push("vars".to_owned()); + } + + if codegen_config.methods() { + options.push("methods".to_owned()); + } + + if codegen_config.constructors() { + options.push("constructors".to_owned()); + } + + if codegen_config.destructors() { + options.push("destructors".to_owned()); + } + + args.push(options.join(",")); + + if !codegen_config.methods() { + args.push("--ignore-methods".to_owned()); + } + }, + }, + /// Whether to treat inline namespaces conservatively. + conservative_inline_namespaces: bool { + methods: { + /// Treat inline namespaces conservatively. + /// + /// This is tricky, because in C++ is technically legal to override an item + /// defined in an inline namespace: + /// + /// ```cpp + /// inline namespace foo { + /// using Bar = int; + /// } + /// using Bar = long; + /// ``` + /// + /// Even though referencing `Bar` is a compiler error. + /// + /// We want to support this (arguably esoteric) use case, but we do not want to make + /// the rest of `bindgen` users pay an usability penalty for that. + /// + /// To support this, we need to keep all the inline namespaces around, but then using + /// `bindgen` becomes a bit more difficult, because you cannot reference paths like + /// `std::string` (you'd need to use the proper inline namespace). + /// + /// We could complicate a lot of the logic to detect name collisions and, in the + /// absence of collisions, generate a `pub use inline_ns::*` or something like that. + /// + /// That is probably something we can do to improve the usability of this option if we + /// realize it is needed way more often. Our guess is that this extra logic is not + /// going to be very useful. + /// + /// This option is disabled by default. + pub fn conservative_inline_namespaces(mut self) -> Builder { + self.options.conservative_inline_namespaces = true; + self + } + }, + as_args: "--conservative-inline-namespaces", + }, + /// Whether to keep documentation comments in the generated output. + generate_comments: bool { + default: true, + methods: { + /// Set whether the generated bindings should contain documentation comments. + /// + /// Documentation comments are included by default. + /// + /// Note that clang excludes comments from system headers by default, pass + /// `"-fretain-comments-from-system-headers"` to the [`Builder::clang_arg`] method to + /// include them. + /// + /// It is also possible to process all comments and not just documentation using the + /// `"-fparse-all-comments"` flag. Check [these slides on clang comment parsing]( + /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for more information + /// and examples. + pub fn generate_comments(mut self, doit: bool) -> Self { + self.options.generate_comments = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-doc-comments"), + }, + /// Whether to generate inline functions. + generate_inline_functions: bool { + methods: { + /// Set whether to generate inline functions. + /// + /// This option is disabled by default. + /// + /// Note that they will usually not work. However you can use `-fkeep-inline-functions` + /// or `-fno-inline-functions` if you are responsible of compiling the library to make + /// them callable. + #[cfg_attr( + feature = "experimental", + doc = "\nCheck the [`Builder::wrap_static_fns`] method for an alternative." + )] + pub fn generate_inline_functions(mut self, doit: bool) -> Self { + self.options.generate_inline_functions = doit; + self + } + }, + as_args: "--generate-inline-functions", + }, + /// Whether to allowlist types recursively. + allowlist_recursively: bool { + default: true, + methods: { + /// Set whether to recursively allowlist items. + /// + /// Items are allowlisted recursively by default. + /// + /// Given that we have explicitly allowlisted the `initiate_dance_party` function in + /// this C header: + /// + /// ```c + /// typedef struct MoonBoots { + /// int bouncy_level; + /// } MoonBoots; + /// + /// void initiate_dance_party(MoonBoots* boots); + /// ``` + /// + /// We would normally generate bindings to both the `initiate_dance_party` function and + /// the `MoonBoots` type that it transitively references. If `false` is passed to this + /// method, `bindgen` will not emit bindings for anything except the explicitly + /// allowlisted items, meaning that the definition for `MoonBoots` would not be + /// generated. However, the `initiate_dance_party` function would still reference + /// `MoonBoots`! + /// + /// **Disabling this feature will almost certainly cause `bindgen` to emit bindings + /// that will not compile!** If you disable this feature, then it is *your* + /// responsibility to provide definitions for every type that is referenced from an + /// explicitly allowlisted item. One way to provide the missing definitions is by using + /// the [`Builder::raw_line`] method, another would be to define them in Rust and then + /// `include!(...)` the bindings immediately afterwards. + pub fn allowlist_recursively(mut self, doit: bool) -> Self { + self.options.allowlist_recursively = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-recursive-allowlist"), + }, + /// Whether to emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of + /// the files generated from objective-c files. + objc_extern_crate: bool { + methods: { + /// Emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of + /// the files generated from objective-c files. + /// + /// `use objc;` is emitted by default. + pub fn objc_extern_crate(mut self, doit: bool) -> Self { + self.options.objc_extern_crate = doit; + self + } + }, + as_args: "--objc-extern-crate", + }, + /// Whether to generate proper block signatures instead of `void` pointers. + generate_block: bool { + methods: { + /// Generate proper block signatures instead of `void` pointers. + /// + /// `void` pointers are used by default. + pub fn generate_block(mut self, doit: bool) -> Self { + self.options.generate_block = doit; + self + } + }, + as_args: "--generate-block", + }, + /// Whether to generate strings as `CStr`. + generate_cstr: bool { + methods: { + /// Set whether string constants should be generated as `&CStr` instead of `&[u8]`. + /// + /// A minimum Rust target of 1.59 is required for this to have any effect as support + /// for `CStr::from_bytes_with_nul_unchecked` in `const` contexts is needed. + /// + /// This option is disabled by default but will become enabled by default in a future + /// release, so enabling this is recommended. + pub fn generate_cstr(mut self, doit: bool) -> Self { + self.options.generate_cstr = doit; + self + } + }, + as_args: "--generate-cstr", + }, + /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue + /// of the files generated from apple block files. + block_extern_crate: bool { + methods: { + /// Emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue of + /// the files generated from apple block files. + /// + /// `use block;` is emitted by default. + pub fn block_extern_crate(mut self, doit: bool) -> Self { + self.options.block_extern_crate = doit; + self + } + }, + as_args: "--block-extern-crate", + }, + /// Whether to use the clang-provided name mangling. + enable_mangling: bool { + default: true, + methods: { + /// Set whether to use the clang-provided name mangling. This is probably needed for + /// C++ features. + /// + /// The mangling provided by clang is used by default. + /// + /// We allow disabling this option because some old `libclang` versions seem to return + /// incorrect results in some cases for non-mangled functions, check [#528] for more + /// information. + /// + /// [#528]: https://github.com/rust-lang/rust-bindgen/issues/528 + pub fn trust_clang_mangling(mut self, doit: bool) -> Self { + self.options.enable_mangling = doit; + self + } + + }, + as_args: |value, args| (!value).as_args(args, "--distrust-clang-mangling"), + }, + /// Whether to detect include paths using `clang_sys`. + detect_include_paths: bool { + default: true, + methods: { + /// Set whether to detect include paths using `clang_sys`. + /// + /// `clang_sys` is used to detect include paths by default. + pub fn detect_include_paths(mut self, doit: bool) -> Self { + self.options.detect_include_paths = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-include-path-detection"), + }, + /// Whether we should try to fit macro constants into types smaller than `u32` and `i32`. + fit_macro_constants: bool { + methods: { + /// Set whether `bindgen` should try to fit macro constants into types smaller than `u32` + /// and `i32`. + /// + /// This option is disabled by default. + pub fn fit_macro_constants(mut self, doit: bool) -> Self { + self.options.fit_macro_constants = doit; + self + } + }, + as_args: "--fit-macro-constant-types", + }, + /// Whether to prepend the `enum` name to constant or newtype variants. + prepend_enum_name: bool { + default: true, + methods: { + /// Set whether to prepend the `enum` name to constant or newtype variants. + /// + /// The `enum` name is prepended by default. + pub fn prepend_enum_name(mut self, doit: bool) -> Self { + self.options.prepend_enum_name = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-prepend-enum-name"), + }, + /// Version of the Rust compiler to target. + rust_target: RustTarget { + methods: { + /// Specify the Rust target version. + /// + /// The default target is the latest stable Rust version. + pub fn rust_target(mut self, rust_target: RustTarget) -> Self { + self.options.set_rust_target(rust_target); + self + } + }, + as_args: |rust_target, args| { + args.push("--rust-target".to_owned()); + args.push(rust_target.to_string()); + }, + }, + /// Features to be enabled. They are derived from `rust_target`. + rust_features: RustFeatures { + default: RustTarget::default().into(), + methods: {}, + // This field cannot be set from the CLI, + as_args: ignore, + }, + /// Enable support for native Rust unions if they are supported. + untagged_union: bool { + default: true, + methods: { + /// Disable support for native Rust unions, if supported. + /// + /// The default value of this option is set based on the value passed to + /// [`Builder::rust_target`]. + pub fn disable_untagged_union(mut self) -> Self { + self.options.untagged_union = false; + self + } + } + as_args: |value, args| (!value).as_args(args, "--disable-untagged-union"), + }, + /// Whether we should record which items in the regex sets did match any C items. + record_matches: bool { + default: true, + methods: { + /// Set whether we should record which items in our regex sets did match any C items. + /// + /// Matches are recorded by default. + pub fn record_matches(mut self, doit: bool) -> Self { + self.options.record_matches = doit; + self + } + + }, + as_args: |value, args| (!value).as_args(args, "--no-record-matches"), + }, + /// Whether `size_t` should be translated to `usize` automatically. + size_t_is_usize: bool { + default: true, + methods: { + /// Set whether `size_t` should be translated to `usize`. + /// + /// If `size_t` is translated to `usize`, type definitions for `size_t` will not be + /// emitted. + /// + /// `size_t` is translated to `usize` by default. + pub fn size_t_is_usize(mut self, is: bool) -> Self { + self.options.size_t_is_usize = is; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-size_t-is-usize"), + }, + /// The tool that should be used to format the generated bindings. + formatter: Formatter { + methods: { + /// Set whether `rustfmt` should be used to format the generated bindings. + /// + /// `rustfmt` is used by default. + /// + /// This method overlaps in functionality with the more general [`Builder::formatter`]. + /// Thus, the latter should be preferred. + #[deprecated] + pub fn rustfmt_bindings(mut self, doit: bool) -> Self { + self.options.formatter = if doit { + Formatter::Rustfmt + } else { + Formatter::None + }; + self + } + + /// Set which tool should be used to format the generated bindings. + /// + /// The default formatter is [`Formatter::Rustfmt`]. + /// + /// To be able to use `prettyplease` as a formatter, the `"prettyplease"` feature for + /// `bindgen` must be enabled in the Cargo manifest. + pub fn formatter(mut self, formatter: Formatter) -> Self { + self.options.formatter = formatter; + self + } + }, + as_args: |formatter, args| { + if *formatter != Default::default() { + args.push("--formatter".to_owned()); + args.push(formatter.to_string()); + } + }, + }, + /// The absolute path to the `rustfmt` configuration file. + rustfmt_configuration_file: Option { + methods: { + /// Set the absolute path to the `rustfmt` configuration file. + /// + /// The default `rustfmt` options are used if `None` is passed to this method or if + /// this method is not called at all. + /// + /// Calling this method will set the [`Builder::rustfmt_bindings`] option to `true` + /// and the [`Builder::formatter`] option to [`Formatter::Rustfmt`]. + pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { + self = self.formatter(Formatter::Rustfmt); + self.options.rustfmt_configuration_file = path; + self + } + }, + as_args: "--rustfmt-configuration-file", + }, + /// Types that should not derive `PartialEq`. + no_partialeq_types: RegexSet { + methods: { + regex_option! { + /// Do not derive `PartialEq` for a given type. + pub fn no_partialeq>(mut self, arg: T) -> Builder { + self.options.no_partialeq_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-partialeq", + }, + /// Types that should not derive `Copy`. + no_copy_types: RegexSet { + methods: { + regex_option! { + /// Do not derive `Copy` and `Clone` for a given type. + pub fn no_copy>(mut self, arg: T) -> Self { + self.options.no_copy_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-copy", + }, + /// Types that should not derive `Debug`. + no_debug_types: RegexSet { + methods: { + regex_option! { + /// Do not derive `Debug` for a given type. + pub fn no_debug>(mut self, arg: T) -> Self { + self.options.no_debug_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-debug", + }, + /// Types that should not derive or implement `Default`. + no_default_types: RegexSet { + methods: { + regex_option! { + /// Do not derive or implement `Default` for a given type. + pub fn no_default>(mut self, arg: T) -> Self { + self.options.no_default_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-default", + }, + /// Types that should not derive `Hash`. + no_hash_types: RegexSet { + methods: { + regex_option! { + /// Do not derive `Hash` for a given type. + pub fn no_hash>(mut self, arg: T) -> Builder { + self.options.no_hash_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-hash", + }, + /// Types that should be annotated with `#[must_use]`. + must_use_types: RegexSet { + methods: { + regex_option! { + /// Annotate the given type with the `#[must_use]` attribute. + pub fn must_use_type>(mut self, arg: T) -> Builder { + self.options.must_use_types.insert(arg.into()); + self + } + } + }, + as_args: "--must-use-type", + }, + /// Whether C arrays should be regular pointers in rust or array pointers + array_pointers_in_arguments: bool { + methods: { + /// Translate arrays `T arr[size]` into array pointers `*mut [T; size]` instead of + /// translating them as `*mut T` which is the default. + /// + /// The same is done for `*const` pointers. + pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { + self.options.array_pointers_in_arguments = doit; + self + } + + }, + as_args: "--use-array-pointers-in-arguments", + }, + /// The name of the `wasm_import_module`. + wasm_import_module_name: Option { + methods: { + /// Adds the `#[link(wasm_import_module = import_name)]` attribute to all the `extern` + /// blocks generated by `bindgen`. + /// + /// This attribute is not added by default. + pub fn wasm_import_module_name>( + mut self, + import_name: T, + ) -> Self { + self.options.wasm_import_module_name = Some(import_name.into()); + self + } + }, + as_args: "--wasm-import-module-name", + }, + /// The name of the dynamic library (if we are generating bindings for a shared library). + dynamic_library_name: Option { + methods: { + /// Generate bindings for a shared library with the given name. + /// + /// This option is disabled by default. + pub fn dynamic_library_name>( + mut self, + dynamic_library_name: T, + ) -> Self { + self.options.dynamic_library_name = Some(dynamic_library_name.into()); + self + } + }, + as_args: "--dynamic-loading", + }, + /// Whether to require successful linkage for all routines in a shared library. + dynamic_link_require_all: bool { + methods: { + /// Set whether to require successful linkage for all routines in a shared library. + /// This allows us to optimize function calls by being able to safely assume function + /// pointers are valid. + /// + /// This option only comes into effect if the [`Builder::dynamic_library_name`] option + /// is set. + /// + /// This option is disabled by default. + pub fn dynamic_link_require_all(mut self, req: bool) -> Self { + self.options.dynamic_link_require_all = req; + self + } + }, + as_args: "--dynamic-link-require-all", + }, + /// Whether to only make generated bindings `pub` if the items would be publicly accessible by + /// C++. + respect_cxx_access_specs: bool { + methods: { + /// Set whether to respect the C++ access specifications. + /// + /// Passing `true` to this method will set the visibility of the generated Rust items + /// as `pub` only if the corresponding C++ items are publicly accessible instead of + /// marking all the items as public, which is the default. + pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { + self.options.respect_cxx_access_specs = doit; + self + } + + }, + as_args: "--respect-cxx-access-specs", + }, + /// Whether to translate `enum` integer types to native Rust integer types. + translate_enum_integer_types: bool { + methods: { + /// Set whether to always translate `enum` integer types to native Rust integer types. + /// + /// Passing `true` to this method will result in `enum`s having types such as `u32` and + /// `i16` instead of `c_uint` and `c_short` which is the default. The `#[repr]` types + /// of Rust `enum`s are always translated to Rust integer types. + pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { + self.options.translate_enum_integer_types = doit; + self + } + }, + as_args: "--translate-enum-integer-types", + }, + /// Whether to generate types with C style naming. + c_naming: bool { + methods: { + /// Set whether to generate types with C style naming. + /// + /// Passing `true` to this method will add prefixes to the generated type names. For + /// example, instead of a `struct` with name `A` we will generate a `struct` with + /// `struct_A`. Currently applies to `struct`s, `union`s, and `enum`s. + pub fn c_naming(mut self, doit: bool) -> Self { + self.options.c_naming = doit; + self + } + }, + as_args: "--c-naming", + }, + /// Whether to always emit explicit padding fields. + force_explicit_padding: bool { + methods: { + /// Set whether to always emit explicit padding fields. + /// + /// This option should be enabled if a `struct` needs to be serialized in its native + /// format (padding bytes and all). This could be required if such `struct` will be + /// written to a file or sent over the network, as anything reading the padding bytes + /// of a struct may cause undefined behavior. + /// + /// Padding fields are not emitted by default. + pub fn explicit_padding(mut self, doit: bool) -> Self { + self.options.force_explicit_padding = doit; + self + } + }, + as_args: "--explicit-padding", + }, + /// Whether to emit vtable functions. + vtable_generation: bool { + methods: { + /// Set whether to enable experimental support to generate virtual table functions. + /// + /// This option should mostly work, though some edge cases are likely to be broken. + /// + /// Virtual table generation is disabled by default. + pub fn vtable_generation(mut self, doit: bool) -> Self { + self.options.vtable_generation = doit; + self + } + }, + as_args: "--vtable-generation", + }, + /// Whether to sort the generated Rust items. + sort_semantically: bool { + methods: { + /// Set whether to sort the generated Rust items in a predefined manner. + /// + /// Items are not ordered by default. + pub fn sort_semantically(mut self, doit: bool) -> Self { + self.options.sort_semantically = doit; + self + } + }, + as_args: "--sort-semantically", + }, + /// Whether to deduplicate `extern` blocks. + merge_extern_blocks: bool { + methods: { + /// Merge all extern blocks under the same module into a single one. + /// + /// Extern blocks are not merged by default. + pub fn merge_extern_blocks(mut self, doit: bool) -> Self { + self.options.merge_extern_blocks = doit; + self + } + }, + as_args: "--merge-extern-blocks", + }, + /// Whether to wrap unsafe operations in unsafe blocks. + wrap_unsafe_ops: bool { + methods: { + /// Wrap all unsafe operations in unsafe blocks. + /// + /// Unsafe operations are not wrapped by default. + pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { + self.options.wrap_unsafe_ops = doit; + self + } + }, + as_args: "--wrap-unsafe-ops", + }, + /// Use DSTs to represent structures with flexible array members. + flexarray_dst: bool { + methods: { + /// Use DSTs to represent structures with flexible array members. + /// + /// This option is disabled by default. + pub fn flexarray_dst(mut self, doit: bool) -> Self { + self.options.flexarray_dst = doit; + self + } + }, + as_args: "--flexarray-dst", + }, + /// Patterns for functions whose ABI should be overridden. + abi_overrides: HashMap { + methods: { + regex_option! { + /// Override the ABI of a given function. + pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { + self.options + .abi_overrides + .entry(abi) + .or_default() + .insert(arg.into()); + self + } + } + }, + as_args: |overrides, args| { + for (abi, set) in overrides { + for item in set.get_items() { + args.push("--override-abi".to_owned()); + args.push(format!("{}={}", item, abi)); + } + } + }, + }, + /// Whether to generate wrappers for `static` functions. + wrap_static_fns: bool { + methods: { + #[cfg(feature = "experimental")] + /// Set whether to generate wrappers for `static`` functions. + /// + /// Passing `true` to this method will generate a C source file with non-`static` + /// functions that call the `static` functions found in the input headers and can be + /// called from Rust once the source file is compiled. + /// + /// The path of this source file can be set using the [`Builder::wrap_static_fns_path`] + /// method. + pub fn wrap_static_fns(mut self, doit: bool) -> Self { + self.options.wrap_static_fns = doit; + self + } + }, + as_args: "--wrap-static-fns", + }, + /// The suffix to be added to the function wrappers for `static` functions. + wrap_static_fns_suffix: Option { + methods: { + #[cfg(feature = "experimental")] + /// Set the suffix added to the wrappers for `static` functions. + /// + /// This option only comes into effect if `true` is passed to the + /// [`Builder::wrap_static_fns`] method. + /// + /// The default suffix is `__extern`. + pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { + self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); + self + } + }, + as_args: "--wrap-static-fns-suffix", + }, + /// The path of the file where the wrappers for `static` functions will be emitted. + wrap_static_fns_path: Option { + methods: { + #[cfg(feature = "experimental")] + /// Set the path for the source code file that would be created if any wrapper + /// functions must be generated due to the presence of `static` functions. + /// + /// `bindgen` will automatically add the right extension to the header and source code + /// files. + /// + /// This option only comes into effect if `true` is passed to the + /// [`Builder::wrap_static_fns`] method. + /// + /// The default path is `temp_dir/bindgen/extern`, where `temp_dir` is the path + /// returned by [`std::env::temp_dir`] . + pub fn wrap_static_fns_path>(mut self, path: T) -> Self { + self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); + self + } + }, + as_args: "--wrap-static-fns-path", + }, + /// Default visibility of fields. + default_visibility: FieldVisibilityKind { + methods: { + /// Set the default visibility of fields, including bitfields and accessor methods for + /// bitfields. + /// + /// This option only comes into effect if the [`Builder::respect_cxx_access_specs`] + /// option is disabled. + pub fn default_visibility( + mut self, + visibility: FieldVisibilityKind, + ) -> Self { + self.options.default_visibility = visibility; + self + } + }, + as_args: |visibility, args| { + if *visibility != Default::default() { + args.push("--default-visibility".to_owned()); + args.push(visibility.to_string()); + } + }, + }, + /// Whether to emit diagnostics or not. + emit_diagnostics: bool { + methods: { + #[cfg(feature = "experimental")] + /// Emit diagnostics. + /// + /// These diagnostics are emitted to `stderr` if you are using `bindgen-cli` or printed + /// using `cargo:warning=` if you are using `bindgen` as a `build-dependency`. + /// + /// Diagnostics are not emitted by default. + /// + /// The layout and contents of these diagnostic messages are not covered by versioning + /// and can change without notice. + pub fn emit_diagnostics(mut self) -> Self { + self.options.emit_diagnostics = true; + self + } + }, + as_args: "--emit-diagnostics", + }, + /// Whether to use Clang evaluation on temporary files as a fallback for macros that fail to + /// parse. + clang_macro_fallback: bool { + methods: { + /// Use Clang as a fallback for macros that fail to parse using `CExpr`. + /// + /// This uses a workaround to evaluate each macro in a temporary file. Because this + /// results in slower compilation, this option is opt-in. + pub fn clang_macro_fallback(mut self) -> Self { + self.options.clang_macro_fallback = true; + self + } + }, + as_args: "--clang-macro-fallback", + } + /// Path to use for temporary files created by clang macro fallback code like precompiled + /// headers. + clang_macro_fallback_build_dir: Option { + methods: { + /// Set a path to a directory to which `.c` and `.h.pch` files should be written for the + /// purpose of using clang to evaluate macros that can't be easily parsed. + /// + /// The default location for `.h.pch` files is the directory that the corresponding + /// `.h` file is located in. The default for the temporary `.c` file used for clang + /// parsing is the current working directory. Both of these defaults are overridden + /// by this option. + pub fn clang_macro_fallback_build_dir>(mut self, path: P) -> Self { + self.options.clang_macro_fallback_build_dir = Some(path.as_ref().to_owned()); + self + } + }, + as_args: "--clang-macro-fallback-build-dir", + } +} diff --git a/bindgen/parse.rs b/bindgen/parse.rs index 1fd83cddda17c7bb404c52814d4496d6f156f164..d29b090fcb6a8412440d2edbe3b41a70b3bd53b0 100644 --- a/bindgen/parse.rs +++ b/bindgen/parse.rs @@ -1,4 +1,5 @@ //! Common traits and types related to parsing our IR from Clang cursors. +#![deny(clippy::missing_docs_in_private_items)] use crate::clang; use crate::ir::context::{BindgenContext, ItemId}; @@ -6,7 +7,7 @@ use crate::ir::context::{BindgenContext, ItemId}; /// Not so much an error in the traditional sense, but a control flow message /// when walking over Clang's AST with a cursor. #[derive(Debug)] -pub enum ParseError { +pub(crate) enum ParseError { /// Recurse down the current AST node's children. Recurse, /// Continue on to the next sibling AST node, or back up to the parent's @@ -16,7 +17,7 @@ pub enum ParseError { /// The result of parsing a Clang AST node. #[derive(Debug)] -pub enum ParseResult { +pub(crate) enum ParseResult { /// We've already resolved this item before, here is the extant `ItemId` for /// it. AlreadyResolved(ItemId), @@ -28,7 +29,7 @@ pub enum ParseResult { /// An intermediate representation "sub-item" (i.e. one of the types contained /// inside an `ItemKind` variant) that can be parsed from a Clang cursor. -pub trait ClangSubItemParser: Sized { +pub(crate) trait ClangSubItemParser: Sized { /// Attempt to parse this type from the given cursor. /// /// The fact that is a reference guarantees it's held by the context, and diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 6246dd255b911ec443168c154250e1be14a4d9f2..426eca89016ddbf00d9d9e444ce183617a3372f9 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -1,4 +1,5 @@ //! A type that represents the union of a set of regular expressions. +#![deny(clippy::missing_docs_in_private_items)] use regex::RegexSet as RxSet; use std::cell::Cell; @@ -6,7 +7,7 @@ use std::cell::Cell; /// A dynamic set of regular expressions. #[derive(Clone, Debug, Default)] pub struct RegexSet { - items: Vec, + items: Vec>, /// Whether any of the items in the set was ever matched. The length of this /// vector is exactly the length of `items`. matched: Vec>, @@ -18,9 +19,7 @@ pub struct RegexSet { impl RegexSet { /// Create a new RegexSet pub fn new() -> RegexSet { - RegexSet { - ..Default::default() - } + RegexSet::default() } /// Is this set empty? @@ -33,29 +32,25 @@ impl RegexSet { where S: AsRef, { - let string = string.as_ref().to_owned(); - if string == "*" { - warn!("using wildcard patterns (`*`) is no longer considered valid. Use `.*` instead"); - } - self.items.push(string); + self.items.push(string.as_ref().to_owned().into_boxed_str()); self.matched.push(Cell::new(false)); self.set = None; } /// Returns slice of String from its field 'items' - pub fn get_items(&self) -> &[String] { - &self.items[..] + pub fn get_items(&self) -> &[Box] { + &self.items } /// Returns an iterator over regexes in the set which didn't match any /// strings yet. - pub fn unmatched_items(&self) -> impl Iterator { + pub fn unmatched_items(&self) -> impl Iterator { self.items.iter().enumerate().filter_map(move |(i, item)| { if !self.record_matches || self.matched[i].get() { return None; } - Some(item) + Some(item.as_ref()) }) } @@ -63,13 +58,56 @@ impl RegexSet { /// /// Must be called before calling `matches()`, or it will always return /// false. + #[inline] pub fn build(&mut self, record_matches: bool) { + self.build_inner(record_matches, None) + } + + // #[cfg(all(feature = "__cli", feature = "experimental"))] + /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the + /// name of the regex set is passed to it. + /// + /// Must be called before calling `matches()`, or it will always return + /// false. + #[inline] + pub fn build_with_diagnostics( + &mut self, + record_matches: bool, + name: Option<&'static str>, + ) { + self.build_inner(record_matches, name) + } + + // #[cfg(all(not(feature = "__cli"), feature = "experimental"))] + // /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the + // /// name of the regex set is passed to it. + // /// + // /// Must be called before calling `matches()`, or it will always return + // /// false. + // #[inline] + // pub(crate) fn build_with_diagnostics( + // &mut self, + // record_matches: bool, + // name: Option<&'static str>, + // ) { + // self.build_inner(record_matches, name) + // } + + fn build_inner( + &mut self, + record_matches: bool, + _name: Option<&'static str>, + ) { let items = self.items.iter().map(|item| format!("^({})$", item)); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { warn!("Invalid regex in {:?}: {:?}", self.items, e); + #[cfg(feature = "experimental")] + if let Some(name) = _name { + invalid_regex_warning(self, e, name); + } None } } @@ -101,3 +139,66 @@ impl RegexSet { true } } + +#[cfg(feature = "experimental")] +fn invalid_regex_warning( + set: &RegexSet, + err: regex::Error, + name: &'static str, +) { + // use crate::diagnostics::{Diagnostic, Level, Slice}; + + // let mut diagnostic = Diagnostic::default(); + + // match err { + // regex::Error::Syntax(string) => { + // if string.starts_with("regex parse error:\n") { + // let mut source = String::new(); + + // let mut parsing_source = true; + + // for line in string.lines().skip(1) { + // if parsing_source { + // if line.starts_with(' ') { + // source.push_str(line); + // source.push('\n'); + // continue; + // } + // parsing_source = false; + // } + // let error = "error: "; + // if line.starts_with(error) { + // let (_, msg) = line.split_at(error.len()); + // diagnostic.add_annotation(msg.to_owned(), Level::Error); + // } else { + // diagnostic.add_annotation(line.to_owned(), Level::Info); + // } + // } + // let mut slice = Slice::default(); + // slice.with_source(source); + // diagnostic.add_slice(slice); + + // diagnostic.with_title( + // "Error while parsing a regular expression.", + // Level::Warn, + // ); + // } else { + // diagnostic.with_title(string, Level::Warn); + // } + // } + // err => { + // let err = err.to_string(); + // diagnostic.with_title(err, Level::Warn); + // } + // } + + // diagnostic.add_annotation( + // format!("This regular expression was passed via `{}`.", name), + // Level::Note, + // ); + + // if set.items.iter().any(|item| item.as_ref() == "*") { + // diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help); + // } + // diagnostic.display(); +} diff --git a/book/book.toml b/book/book.toml index 340134a32e99c0f24e5c3c1b8b95addcd3b87838..3f55b78377927a1321c46844345366998ce6864d 100644 --- a/book/book.toml +++ b/book/book.toml @@ -1,4 +1,8 @@ [book] -title = "The `bindgen` User Guide" -author = "The Servo project developers" +title = "The bindgen User Guide" description = "`bindgen` automatically generates Rust FFI bindings to C and C++ libraries." + +[output.html] +git-repository-url = "https://github.com/rust-lang/rust-bindgen" +edit-url-template = "https://github.com/rust-lang/rust-bindgen/edit/main/book/{path}" +search.use-boolean-and = true diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index dbdf3f700c67a6f9de6039f40cfa780000451b9e..daaed04081cf43f541d10f54c65ec60447e915b5 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -27,4 +27,5 @@ - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) - [Using Bitfields](./using-bitfields.md) +- [Using Flexible Array Members](./using-fam.md) - [FAQ](./faq.md) diff --git a/book/src/allowlisting.md b/book/src/allowlisting.md index edf93df0ef6899ea2b0d3cb7521e4248ded26625..99dd1698657b0b7e1270ecc04cb39fbc16f0ffb0 100644 --- a/book/src/allowlisting.md +++ b/book/src/allowlisting.md @@ -20,6 +20,7 @@ transitively used by a definition that matches them. * [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_function) * [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_var) * [`bindgen::Builder::allowlist_file`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_file) +* [`bindgen::Builder::allowlist_item`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_item) ### Command Line @@ -27,6 +28,7 @@ transitively used by a definition that matches them. * `--allowlist-function ` * `--allowlist-var ` * `--allowlist-file ` +* `--allowlist-item ` ### Annotations diff --git a/book/src/blocklisting.md b/book/src/blocklisting.md index 6eb5786328d0762ef0689eee7377e5a934cafa68..535a08c8d53ed65bd612760234848520c74ca5fe 100644 --- a/book/src/blocklisting.md +++ b/book/src/blocklisting.md @@ -22,6 +22,7 @@ that are transitively included. * [`bindgen::Builder::blocklist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_function) * [`bindgen::Builder::blocklist_item`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_item) * [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_type) +* [`bindgen::Builder::blocklist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_var) ### Command Line @@ -29,6 +30,7 @@ that are transitively included. * `--blocklist-function ` * `--blocklist-item ` * `--blocklist-type ` +* `--blocklist-var ` ### Annotations diff --git a/book/src/code-formatting.md b/book/src/code-formatting.md index 9039984a167551ef0d5c55b843354086bfb8df73..9c82e83a32156d98b9a04238ffa9b341d09a3859 100644 --- a/book/src/code-formatting.md +++ b/book/src/code-formatting.md @@ -67,3 +67,38 @@ fn main() { ``` These two methods also apply to any other toolchain available in your system. + +## Using `prettyplease` + +The [`prettyplease`](https://github.com/dtolnay/prettyplease) crate is a +minimal formatter for generated code. To format bindings using `prettyplease` +you have to invoke `bindgen` with either the `--formatter=prettyplease` flag or +the `bindgen::Builder::formatter(bindgen::Formatter::Prettyplease)`. One of +its advantages is that `prettyplease` can be used in minimal environments where +the Rust toolchain is not installed. + +## How can I normalize `#[doc]` attributes? + +`bindgen` emits all the documentation using `#[doc]` attributes by default. If +you want to use the more user-friendly `///` syntax, you have two options: + +### Use `rustfmt` + +`rustfmt` can be configured to normalize documentation. To do so, you have to +create a `rustfmt.toml` file with the following contents: + +```toml +normalize_doc_attributes = true +``` + +Then, you have set up `bindgen` so it passes this file to `rustfmt`. Given that +the `normalize_doc_attributes` option is +[unstable](https://github.com/rust-lang/rustfmt/issues/3351), you also have to +set up bindgen to use a `nightly` release of `rustfmt`. + + +### Use `prettyplease` + +`prettyplease` normalizes documentation without any additional configuration. +Then you just have to tell `bindgen` to use `prettyplease` as the code +formatter. diff --git a/book/src/cpp.md b/book/src/cpp.md index f5091b355e9c19f493d08e25376a0beae9361fdc..db368f6787ec27c0155b64365a38af322bf8e14b 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -74,7 +74,7 @@ cannot translate into Rust: * Many C++ specific aspects of calling conventions. For example in the Itanium abi types that are "[non trivial for the purposes of calls](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial)" - should be passed by pointer, even if they are otherwise eligable to be passed in a register. + should be passed by pointer, even if they are otherwise eligible to be passed in a register. Similarly in both the Itanium and MSVC ABIs such types are returned by "hidden parameter", much like large structs in C that would not fit into a register. This also applies to types with any base classes in the MSVC ABI (see [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values)). @@ -154,6 +154,6 @@ instance.assume_init_mut().method(); ``` You can easily verify this fact if you provide a implementation for `MyClass` -and `method` that prints the the `this` pointer address. However, you can +and `method` that prints the `this` pointer address. However, you can ignore this fact if you know that the original C++ code does not rely on the instance address in its internal logic. diff --git a/book/src/faq.md b/book/src/faq.md index f133561d84e399e14af0e29b1943df90292e595f..e82b4a446a4221a2927f5788a3fe5c27200fb3e3 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -8,7 +8,6 @@ - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) - [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) - [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target) -- [How can I normalize `#[doc]` attributes?](#how-can-i-normalize-doc-attributes) @@ -54,6 +53,13 @@ Note that these functions and methods are usually marked inline for a reason: they tend to be hot. The above workaround makes them an out-of-line call, which might not provide acceptable performance. +As an alternative, you can invoke `bindgen` with either the +`bindgen::Builder::wrap_static_fns` method or the `--wrap-static-fns` flag. +Which generates a C source file that can be compiled against the input headers +to produce Rust headers for `static` and `static inline` functions. See [How to +handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405) +for further information. + ### Does `bindgen` support the C++ Standard Template Library (STL)? Sort of. A little. Depends what you mean by "support". @@ -109,19 +115,3 @@ $ bindgen -- --target=armv7a-none-eabi ``` If you are using `bindgen` as a library, you should call `builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`. - -### How can I normalize `#[doc]` attributes? - -`bindgen` emits all the documentation using `#[doc]` attributes by default. If -you want to use the more user-friendly `///` syntax, you have to create a -`rustfmt.toml` file with the following contents: - -```toml -normalize_doc_attributes = true -``` - -Then, you have set up bindgen so it passes this file to `rustfmt`. Given that -the `normalize_doc_attributes` option is -[unstable](https://github.com/rust-lang/rustfmt/issues/3351), you also have to -set up bindgen to use a `nightly` release of `rustfmt`. Please check the [code -formatting](./code-formatting.md) section for further information. diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index c724a2fc77f539d297a0964421b600c1eff744b4..b080db80d798c767a86974c18fbf7312095e68fd 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -1,23 +1,22 @@ Now let's suppose we want to generate bindings for a non-system library. We will be the same crate setup as the previous tutorial. First let's create a new -directory `hello` with two files inside it. A `c` source file `hello.c` +directory `hello` with two files inside it. A C source file `hello.c` containing ```c int hello() { return 42; } ``` -and a `c` header file `hello.h` containing +and a C header file `hello.h` containing ```c int hello(); ``` -given that the library has not been compiled yet, we need to modify the + +Given that the library has not been compiled yet, we need to modify the `build.rs` build script to compile the `hello.c` source file into a static -libary: +library: ```rust,ignore -extern crate bindgen; - use std::env; use std::path::PathBuf; @@ -47,9 +46,6 @@ fn main() { // automatically know it must look for a `libhello.a` file. println!("cargo:rustc-link-lib=hello"); - // Tell cargo to invalidate the built crate whenever the header changes. - println!("cargo:rerun-if-changed={}", headers_path_str); - // Run `clang` to compile the `hello.c` file into a `hello.o` object file. // Unwrap if it is not possible to spawn the process. if !std::process::Command::new("clang") @@ -90,7 +86,7 @@ fn main() { .header(headers_path_str) // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(CargoCallbacks)) + .parse_callbacks(Box::new(CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. @@ -103,4 +99,3 @@ fn main() { .expect("Couldn't write bindings!"); } ``` - diff --git a/book/src/objc.md b/book/src/objc.md index ce6d75676115f5aa98d165a320432f22f66f3848..ed6f2cb881f98759589ba77e8e062c72b50e6832 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -18,7 +18,7 @@ objc::runtime::Object` (the pointer to the objective-c instance). The trait `IFoo` is needed to allow for the generated inheritance. Functions that use or return objective-c pointers of instance `Foo` will return -`Foo`. The reason this works is beacuse `Foo` represented as `transparent`. +`Foo`. The reason this works is because `Foo` represented as `transparent`. This will be helpful for a lot of objective-c frameworks however there are some cases where functions return `instancetype` which is a type alias for `id` so an occasional `foo.0` may be required. An example of this would in the UIKit diff --git a/book/src/requirements.md b/book/src/requirements.md index 7cce87aed9494f3082357c2971f4728f641b477a..b701234fad8e114730d333fe8aeeac7459c5edb5 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -13,7 +13,12 @@ It is required to use Clang 5.0 or greater. #### Windows -Download and install the official pre-built binary from +If you use winget: +```powershell +winget install LLVM.LLVM +``` + +Alternatively, you can download and install the official pre-built binary from [LLVM download page](http://releases.llvm.org/download.html). You will also need to set `LIBCLANG_PATH` as an [environment diff --git a/book/src/tutorial-1.md b/book/src/tutorial-1.md index cac4f255c14e31e14bff2acb08b559203e238e94..464b6b9d71dc6607b3565c2b4ad713d946ddb137 100644 --- a/book/src/tutorial-1.md +++ b/book/src/tutorial-1.md @@ -3,13 +3,18 @@ First we need to declare a build-time dependency on `bindgen` by adding it to the `[build-dependencies]` section of our crate's `Cargo.toml` file. -Please always use the latest version of `bindgen`, it has the most fixes and -best compatibility. At the time of writing the latest bindgen is `0.53.1`, but -you can always check [the bindgen page of -crates.io](https://crates.io/crates/bindgen) to verify the latest version if -you're unsure. +Please always use the latest version of `bindgen`, as it has the most fixes and +best compatibility. +You can always check the latest version at +[the bindgen page in crates.io](https://crates.io/crates/bindgen). ```toml [build-dependencies] -bindgen = "0.53.1" +bindgen = "0.65.1" ``` + +> ⚠️ **Warning** +> +> `bindgen` needs to be added to the `[build-dependencies]` section, not the normal +> `[dependencies]` section. If you add it as a regular dependency, you will get +> errors like the following: `` error[E0463]: can't find crate for `bindgen` `` diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index dcd67c5ca8f50090222c9bd5f378648c878aeac1..3248f2847ff93a9e80485a2e256a20aad89ad277 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -10,8 +10,6 @@ like `./target/debug/build/bindgen-tutorial-bzip2-sys-afc7747d7eafd720/out/`. Note that the associated shared object to `bz2` is `libbz2.so`. In general, a `lib.so` should be referenced in the build file by ``. ```rust,ignore -extern crate bindgen; - use std::env; use std::path::PathBuf; @@ -23,9 +21,6 @@ fn main() { // shared library. println!("cargo:rustc-link-lib=bz2"); - // Tell cargo to invalidate the built crate whenever the wrapper changes - println!("cargo:rerun-if-changed=wrapper.h"); - // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. @@ -35,7 +30,7 @@ fn main() { .header("wrapper.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. @@ -52,6 +47,6 @@ fn main() { Now, when we run `cargo build`, our bindings to `bzip2` are generated on the fly! -[There's more info about `build.rs` files in the crates.io documentation.][build-rs] +[There's more info about `build.rs` files in the Cargo documentation.][build-rs] -[build-rs]: http://doc.crates.io/build-script.html +[build-rs]: https://doc.rust-lang.org/cargo/reference/build-scripts.html diff --git a/book/src/using-bitfields.md b/book/src/using-bitfields.md index 41e07ad70371b18984dc99653f7b75d5c54297e6..8929f7370561d2382ec6c7818f6635d741dbb8fc 100644 --- a/book/src/using-bitfields.md +++ b/book/src/using-bitfields.md @@ -5,9 +5,14 @@ As Rust does not support bitfields, Bindgen generates a struct for each with the following characteristics * Immutable getter functions for each bitfield named `````` * Setter functions for each contiguous block of bitfields named ```set_``` -* Far each contiguous block of bitfields, Bindgen emits an opaque physical field that contains one or more logical bitfields +* For each contiguous block of bitfields, Bindgen emits an opaque physical field that contains one or more logical bitfields * A static constructor ```new_bitfield_{1, 2, ...}``` with a parameter for each bitfield contained within the opaque physical field. +To keep bindgen from generating the bitfield unit struct, it can be blocklisted like any +other type, i.e. `--blocklist-type "__BindgenBitfieldUnit"`. This may be useful if +you want to define a custom implementation, or your generated bindings import a +pre-existing definition for the bitfield unit type. + ## Bitfield examples For this discussion, we will use the following C type definitions and functions. diff --git a/book/src/using-fam.md b/book/src/using-fam.md new file mode 100644 index 0000000000000000000000000000000000000000..aaf19c90fd948a9ccf53bcea45f770c2ef0fa9a3 --- /dev/null +++ b/book/src/using-fam.md @@ -0,0 +1,163 @@ +# Using C structures with Flexible Array Members + +Since time immemorial, C programmers have been using what was called "the struct +hack". This is a technique for packing a fixed-size structure and a +variable-sized tail within the same memory allocation. Typically this looks +like: + +```c +struct MyRecord { + time_t timestamp; + unsigned seq; + size_t len; + char payload[0]; +}; +``` + +Because this is so useful, it was standardized in C99 as "flexible array +members", using almost identical syntax: +```c +struct MyRecord { + time_t timestamp; + unsigned seq; + size_t len; + char payload[]; // NOTE: empty [] +}; +``` + +Bindgen supports these structures in two different ways. + +## `__IncompleteArrayField` + +By default, bindgen will generate the corresponding Rust structure: +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: __IncompleteArrayField<::std::os::raw::c_char>, +} +``` + +The `__IncompleteArrayField` type is zero-sized, so this structure represents +the prefix without any trailing data. In order to access that data, it provides +the `as_slice` unsafe method: +```rust,ignore + // SAFETY: there's at least `len` bytes allocated and initialized after `myrecord` + let payload = unsafe { myrecord.payload.as_slice(myrecord.len) }; +``` +There's also `as_mut_slice` which does the obvious. + +These are `unsafe` simply because it's up to you to provide the right length (in +elements of whatever type `payload` is) as there's no way for Rust or Bindgen to +know. In this example, the length is a very straightforward `len` field in the +structure, but it could be encoded in any number of ways within the structure, +or come from somewhere else entirely. + +One big caveat with this technique is that `std::mem::size_of` (or +`size_of_val`) will *only* include the size of the prefix structure. if you're +working out how much storage the whole structure is using, you'll need to add +the suffix yourself. + +## Using Dynamically Sized Types + +If you invoke bindgen with the `--flexarray-dst` option, it will generate +something not quite like this: + +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: [::std::os::raw::c_char], +} +``` +Rust has a set of types which are almost exact analogs for these Flexible Array +Member types: the Dynamically Sized Type ("DST"). + +This looks almost identical to a normal Rust structure, except that you'll note +the type of the `payload` field is a raw slice `[...]` rather than the usual +reference to slice `&[...]`. + +That `payload: [c_char]` is telling Rust that it can't directly know the total +size of this structure - the `payload` field takes an amount of space that's +determined at runtime. This means you can't directly use values of this type, +only references: `&MyRecord`. + +In practice, this is very awkward. So instead, bindgen generates: +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: FAM, +} +``` + +That is: +1. a type parameter `FAM` which represents the type of the `payload` field, +2. it's `?Sized` meaning it can be unsized (ie, a DST) +3. it has the default type of `[c_char; 0]` - that is a zero-sized array of characters + +This means that referencing plain `MyRecord` will be exactly like `MyRecord` +with `__IncompleteArrayField`: it is a fixed-sized structure which you can +manipulate like a normal Rust value. + +But how do you get to the DST part? + +Bindgen will also implement a set of helper methods for this: + +```rust,ignore +// Static sized variant +impl MyRecord<[::std::os::raw::c_char; 0]> { + pub unsafe fn flex_ref(&self, len: usize) -> &MyRecord<[::std::os::raw::c_char]> { ... } + pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut MyRecord<[::std::os::raw::c_char]> { ... } + // And some raw pointer variants +} +``` +These will take a sized `MyRecord<[c_char; 0]>` and a length in elements, and +return a reference to a DST `MyRecord<[c_char]>` where the `payload` field is a +fully usable slice of `len` characters. + +The magic here is that the reference is a fat pointer, which not only encodes +the address, but also the dynamic size of the final field, just like a reference +to a slice is. This means that you get full bounds checked access to the +`payload` field like any other Rust slice. + +It also means that doing `mem::size_of_val(myrecord)` will return the *complete* +size of this structure, including the suffix. + +You can go the other way: +```rust,ignore +// Dynamic sized variant +impl MyRecord<[::std::os::raw::c_char]> { + pub fn fixed(&self) -> (&MyRecord<[::std::os::raw::c_char; 0]>, usize) { ... } + pub fn fixed_mut(&mut self) -> (&mut MyRecord<[::std::os::raw::c_char; 0]>, usize) { ... } + pub fn layout(len: usize) -> std::alloc::Layout { ... } +} +``` +which takes the DST variant of the structure and returns the sized variant, +along with the number of elements are after it. These are all completely safe +because all the information needed is part of the fat `&self` reference. + +The `layout` function takes a length and returns the `Layout` - that is, size +and alignment, so that you can allocate memory for the structure (for example, +using `malloc` so you can pass it to a C function). + +Unfortunately the language features needed to support these methods are still unstable: +- [ptr_metadata](https://doc.rust-lang.org/beta/unstable-book/library-features/ptr-metadata.html), + which enables all the fixed<->DST conversions, and +- [layout_for_ptr](https://doc.rust-lang.org/beta/unstable-book/library-features/layout-for-ptr.html), + which allows he `layout` method + +As a result, if you don't specify `--rust-target nightly` you'll just get the +bare type definitions, but no real way to use them. It's often convenient to add +the +```bash +--raw-line '#![feature(ptr_metadata,layout_for_ptr)]' +``` +option if you're generating Rust as a stand-alone crate. Otherwise you'll need +to add the feature line to your containing crate. diff --git a/book/src/using-unions.md b/book/src/using-unions.md index 9e8e9b99d77776fc8c6a142d02a680f025d9cf64..5ae764a33dad7eb3690e51c096f8406975aff47d 100644 --- a/book/src/using-unions.md +++ b/book/src/using-unions.md @@ -66,11 +66,11 @@ When using the `union` builtin type, there are two choices for initialization: mod bindings_builtin_union; fn union_builtin() { - // Initalize the union to zero + // Initialize the union to zero let x = bindings_builtin_union::greek_t::default(); // If `--with-derive-default` option is not used, the following may be used - // to initalize the union to zero: + // to initialize the union to zero: let x = unsafe { std::mem::zeroed::() }; // Or, it is possible to initialize exactly one variant of the enum: diff --git a/ci/no-includes.sh b/ci/no-includes.sh index 97966cb0902da04a6ea975500b13d6f895f377d3..32c20059e0ef970e29e5cd3b92ec20ae86c441fe 100755 --- a/ci/no-includes.sh +++ b/ci/no-includes.sh @@ -1,13 +1,17 @@ #!/usr/bin/env bash # Don't allow any system include directives in tests. +# +# We make an exception for stdarg.h which is used for +# the wrapped va_list feature. stdarg.h is available since C89 +# therefor not having this header is a sign of a bigger issue. set -eu cd "$(dirname "$0")/.." echo "Checking for #include directives of system headers..." -grep -rn '#include\s*<.*>' bindgen-tests/tests/headers || { +grep -rn '#include\s*<(?!stdarg).*>' bindgen-tests/tests/headers || { echo "Found none; OK!" exit 0 } diff --git a/ci/test.bat b/ci/test.bat index 507537c08e0ebb6971411a01f028fa16a3fa93ff..d4a1c4a08a433e112d73cdee0108365821a7c85f 100644 --- a/ci/test.bat +++ b/ci/test.bat @@ -29,10 +29,10 @@ findstr /r /c:"#include *<.*>" tests\headers\* >nul 2>&1 && ( cargo test --features "%BINDGEN_FEATURES%" || exit /b 1 call .\ci\assert-no-diff.bat -cargo test --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1 +cargo test --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1 call .\ci\assert-no-diff.bat -cargo test --release --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1 +cargo test --release --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1 call .\ci\assert-no-diff.bat ::Now test the expectations' size and alignment tests. diff --git a/ci/test.sh b/ci/test.sh index 788c28fe271f60cdae6eb5fdde5a9da55f8fcb90..11e091f49f781a51eda03f45804d97f23b6a8bef 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -9,20 +9,22 @@ set -x set -o pipefail function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" + case "$1" in + 9.0.1) echo "x86_64-linux-gnu-ubuntu-16.04" ;; + *) echo "x86_64-linux-gnu-ubuntu-18.04" ;; + esac } function llvm_macos_target_triple() { case "$1" in - [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; - # Starting with 9.0.1, triple swapped ordering - *) echo "x86_64-apple-darwin" ;; + 9.0.1) echo "x86_64-apple-darwin" ;; + *) echo "arm64-apple-darwin22.0" ;; esac } function llvm_version_triple() { case "$1" in - 5.0) echo "5.0.1" ;; + 9.0) echo "9.0.1" ;; # By default, take the .0 patch release *) echo "$1.0" ;; esac @@ -30,16 +32,7 @@ function llvm_version_triple() { function llvm_base_url() { local llvm_version_triple=$1 - - case "$llvm_version_triple" in - [0-8].* | 9.0.0) - echo "http://releases.llvm.org/$llvm_version_triple" - ;; - # Starting with 9.0.1, releases are hosted on github - *) - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" - ;; - esac + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" } function llvm_download() { @@ -75,14 +68,6 @@ set_llvm_env() { fi } -# Need rustfmt to compare the test expectations. -set_rustfmt_env() { - local toolchain="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" - rustup update "$toolchain" - rustup component add rustfmt --toolchain "$toolchain" - export RUSTFMT="$(rustup which --toolchain "$toolchain" rustfmt)" -} - assert_no_diff() { git add -u git diff @ @@ -90,7 +75,6 @@ assert_no_diff() { } set_llvm_env -set_rustfmt_env get_cargo_args() { local args="" @@ -108,10 +92,7 @@ get_cargo_args() { features+="runtime" fi if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1" ]; then - features+=" testing_only_extra_assertions" - fi - if [ "$BINDGEN_FEATURE_TESTING_ONLY_DOCS" == "1" ]; then - features+=" testing_only_docs" + features+=" __testing_only_extra_assertions" fi if [ ! -z "$features" ]; then args+=" --features $(echo $features | tr ' ' ',')" diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000000000000000000000000000000000..26a0605343784014d3cf5ad737582c71cc45640b --- /dev/null +++ b/clippy.toml @@ -0,0 +1,5 @@ +disallowed-methods = [ + { path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"}, + { path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"} +] +missing-docs-in-crate-items = true diff --git a/triagebot.toml b/triagebot.toml new file mode 100644 index 0000000000000000000000000000000000000000..c196fb3d4d874be9e79a8272f269c421f1948ad2 --- /dev/null +++ b/triagebot.toml @@ -0,0 +1,28 @@ +[relabel] +allow-unauthenticated = [ + "A-*", + "C-*", + "E-*", + "I-*", + "S-*", + "bug", + "dependencies", + "enhancement", + "good first issue", + "hacktoberfest", + "help wanted", + "invalid", + "meta", + "msvc", + "next-release", + "question", + "This Week In Servo (TWiS)", + "windows", +] + +[autolabel."A-C++"] +trigger_files = [ + "**/*.cpp", + "**/*.cc", + "**/*.hpp", +] \ No newline at end of file