Merge from rustc
This commit is contained in:
commit
3e2164fef2
971 changed files with 12506 additions and 7835 deletions
241
.github/workflows/ci.yml
vendored
241
.github/workflows/ci.yml
vendored
|
|
@ -1,46 +1,53 @@
|
|||
#############################################################
|
||||
# WARNING: automatically generated file, DO NOT CHANGE! #
|
||||
#############################################################
|
||||
# This file defines our primary CI workflow that runs on pull requests
|
||||
# and also on pushes to special branches (auto, try).
|
||||
#
|
||||
# The actual definition of the executed jobs is calculated by a Python
|
||||
# script located at src/ci/github-actions/calculate-job-matrix.py, which
|
||||
# uses job definition data from src/ci/github-actions/jobs.yml.
|
||||
# You should primarily modify the `jobs.yml` file if you want to modify
|
||||
# what jobs are executed in CI.
|
||||
|
||||
# This file was automatically generated by the expand-yaml-anchors tool. The
|
||||
# source file that generated this one is:
|
||||
#
|
||||
# src/ci/github-actions/ci.yml
|
||||
#
|
||||
# Once you make changes to that file you need to run:
|
||||
#
|
||||
# ./x.py run src/tools/expand-yaml-anchors/
|
||||
#
|
||||
# The CI build will fail if the tool is not run after changes to this file.
|
||||
|
||||
---
|
||||
name: CI
|
||||
"on":
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- auto
|
||||
- try
|
||||
- try-perf
|
||||
- automation/bors/try
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- "**"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
defaults:
|
||||
run:
|
||||
# On Linux, macOS, and Windows, use the system-provided bash as the default
|
||||
# shell. (This should only make a difference on Windows, where the default
|
||||
# shell is PowerShell.)
|
||||
shell: bash
|
||||
|
||||
concurrency:
|
||||
group: "${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}"
|
||||
# For a given workflow, if we push to the same branch, cancel all previous builds on that branch.
|
||||
# We add an exception for try builds (try branch) and unrolled rollup builds (try-perf), which
|
||||
# are all triggered on the same branch, but which should be able to run concurrently.
|
||||
group: ${{ github.workflow }}-${{ ((github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.sha) || github.ref }}
|
||||
cancel-in-progress: true
|
||||
env:
|
||||
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
|
||||
jobs:
|
||||
# The job matrix for `calculate_matrix` is defined in src/ci/github-actions/jobs.yml.
|
||||
# It calculates which jobs should be executed, based on the data of the ${{ github }} context.
|
||||
# If you want to modify CI jobs, take a look at src/ci/github-actions/jobs.yml.
|
||||
calculate_matrix:
|
||||
name: Calculate job matrix
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
jobs: "${{ steps.jobs.outputs.jobs }}"
|
||||
jobs: ${{ steps.jobs.outputs.jobs }}
|
||||
run_type: ${{ steps.jobs.outputs.run_type }}
|
||||
steps:
|
||||
- name: Checkout the source code
|
||||
uses: actions/checkout@v4
|
||||
|
|
@ -48,171 +55,195 @@ jobs:
|
|||
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
|
||||
id: jobs
|
||||
job:
|
||||
name: "${{ matrix.name }}"
|
||||
needs:
|
||||
- calculate_matrix
|
||||
env:
|
||||
CI_JOB_NAME: "${{ matrix.image }}"
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
||||
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
|
||||
DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
SCCACHE_BUCKET: rust-lang-ci-sccache2
|
||||
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
|
||||
CACHE_DOMAIN: ci-caches.rust-lang.org
|
||||
continue-on-error: "${{ matrix.continue_on_error || false }}"
|
||||
strategy:
|
||||
matrix:
|
||||
include: "${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}"
|
||||
if: "fromJSON(needs.calculate_matrix.outputs.jobs)[0] != null"
|
||||
name: ${{ matrix.name }}
|
||||
needs: [ calculate_matrix ]
|
||||
runs-on: "${{ matrix.os }}"
|
||||
defaults:
|
||||
run:
|
||||
shell: "${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}"
|
||||
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
|
||||
timeout-minutes: 600
|
||||
runs-on: "${{ matrix.os }}"
|
||||
env:
|
||||
CI_JOB_NAME: ${{ matrix.image }}
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
||||
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
DOCKER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SCCACHE_BUCKET: rust-lang-ci-sccache2
|
||||
CACHE_DOMAIN: ci-caches.rust-lang.org
|
||||
continue-on-error: ${{ matrix.continue_on_error || false }}
|
||||
strategy:
|
||||
matrix:
|
||||
# Check the `calculate_matrix` job to see how is the matrix defined.
|
||||
include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}
|
||||
# GitHub Actions fails the workflow if an empty list of jobs is provided to
|
||||
# the workflow, so we need to skip this job if nothing was produced by
|
||||
# the Python script.
|
||||
#
|
||||
# Unfortunately checking whether a list is empty is not possible in a nice
|
||||
# way due to GitHub Actions expressions limits.
|
||||
# This hack is taken from https://github.com/ferrocene/ferrocene/blob/d43edc6b7697cf1719ec1c17c54904ab94825763/.github/workflows/release.yml#L75-L82
|
||||
if: fromJSON(needs.calculate_matrix.outputs.jobs)[0] != null
|
||||
steps:
|
||||
- if: "contains(matrix.os, 'windows')"
|
||||
- if: contains(matrix.os, 'windows')
|
||||
uses: msys2/setup-msys2@v2.22.0
|
||||
with:
|
||||
msystem: "${{ contains(matrix.name, 'i686') && 'mingw32' || 'mingw64' }}"
|
||||
# i686 jobs use mingw32. x86_64 and cross-compile jobs use mingw64.
|
||||
msystem: ${{ contains(matrix.name, 'i686') && 'mingw32' || 'mingw64' }}
|
||||
# don't try to download updates for already installed packages
|
||||
update: false
|
||||
# don't try to use the msys that comes built-in to the github runner,
|
||||
# so we can control what is installed (i.e. not python)
|
||||
release: true
|
||||
# Inherit the full path from the Windows environment, with MSYS2's */bin/
|
||||
# dirs placed in front. This lets us run Windows-native Python etc.
|
||||
path-type: inherit
|
||||
install: "make dos2unix diffutils\n"
|
||||
install: >
|
||||
make
|
||||
dos2unix
|
||||
diffutils
|
||||
|
||||
- name: disable git crlf conversion
|
||||
run: git config --global core.autocrlf false
|
||||
|
||||
- name: checkout the source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
# Rust Log Analyzer can't currently detect the PR number of a GitHub
|
||||
# Actions build on its own, so a hint in the log message is needed to
|
||||
# point it in the right direction.
|
||||
- name: configure the PR in which the error message will be posted
|
||||
run: "echo \"[CI_PR_NUMBER=$num]\""
|
||||
run: echo "[CI_PR_NUMBER=$num]"
|
||||
env:
|
||||
num: "${{ github.event.number }}"
|
||||
if: "success() && github.event_name == 'pull_request'"
|
||||
num: ${{ github.event.number }}
|
||||
if: needs.calculate_matrix.outputs.run_type == 'pr'
|
||||
|
||||
- name: add extra environment variables
|
||||
run: src/ci/scripts/setup-environment.sh
|
||||
env:
|
||||
EXTRA_VARIABLES: "${{ toJson(matrix.env) }}"
|
||||
# Since it's not possible to merge `${{ matrix.env }}` with the other
|
||||
# variables in `job.<name>.env`, the variables defined in the matrix
|
||||
# are passed to the `setup-environment.sh` script encoded in JSON,
|
||||
# which then uses log commands to actually set them.
|
||||
EXTRA_VARIABLES: ${{ toJson(matrix.env) }}
|
||||
|
||||
- name: ensure the channel matches the target branch
|
||||
run: src/ci/scripts/verify-channel.sh
|
||||
|
||||
- name: collect CPU statistics
|
||||
run: src/ci/scripts/collect-cpu-stats.sh
|
||||
|
||||
- name: show the current environment
|
||||
run: src/ci/scripts/dump-environment.sh
|
||||
|
||||
- name: install awscli
|
||||
run: src/ci/scripts/install-awscli.sh
|
||||
|
||||
- name: install sccache
|
||||
run: src/ci/scripts/install-sccache.sh
|
||||
|
||||
- name: select Xcode
|
||||
run: src/ci/scripts/select-xcode.sh
|
||||
|
||||
- name: install clang
|
||||
run: src/ci/scripts/install-clang.sh
|
||||
|
||||
- name: install tidy
|
||||
run: src/ci/scripts/install-tidy.sh
|
||||
|
||||
- name: install WIX
|
||||
run: src/ci/scripts/install-wix.sh
|
||||
|
||||
- name: disable git crlf conversion
|
||||
run: src/ci/scripts/disable-git-crlf-conversion.sh
|
||||
|
||||
- name: checkout submodules
|
||||
run: src/ci/scripts/checkout-submodules.sh
|
||||
|
||||
- name: install MSYS2
|
||||
run: src/ci/scripts/install-msys2.sh
|
||||
|
||||
- name: install MinGW
|
||||
run: src/ci/scripts/install-mingw.sh
|
||||
|
||||
- name: install ninja
|
||||
run: src/ci/scripts/install-ninja.sh
|
||||
|
||||
- name: enable ipv6 on Docker
|
||||
run: src/ci/scripts/enable-docker-ipv6.sh
|
||||
|
||||
# Disable automatic line ending conversion (again). On Windows, when we're
|
||||
# installing dependencies, something switches the git configuration directory or
|
||||
# re-enables autocrlf. We've not tracked down the exact cause -- and there may
|
||||
# be multiple -- but this should ensure submodules are checked out with the
|
||||
# appropriate line endings.
|
||||
- name: disable git crlf conversion
|
||||
run: src/ci/scripts/disable-git-crlf-conversion.sh
|
||||
|
||||
- name: ensure line endings are correct
|
||||
run: src/ci/scripts/verify-line-endings.sh
|
||||
|
||||
- name: ensure backported commits are in upstream branches
|
||||
run: src/ci/scripts/verify-backported-commits.sh
|
||||
|
||||
- name: ensure the stable version number is correct
|
||||
run: src/ci/scripts/verify-stable-version-number.sh
|
||||
|
||||
- name: run the build
|
||||
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
|
||||
run: src/ci/scripts/run-build-from-ci.sh 2>&1
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: "${{ env.CACHES_AWS_ACCESS_KEY_ID }}"
|
||||
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
|
||||
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
|
||||
AWS_ACCESS_KEY_ID: ${{ env.CACHES_AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}
|
||||
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
|
||||
|
||||
- name: create github artifacts
|
||||
run: src/ci/scripts/create-doc-artifacts.sh
|
||||
|
||||
- name: upload artifacts to github
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: "${{ env.DOC_ARTIFACT_NAME }}"
|
||||
# name is set in previous step
|
||||
name: ${{ env.DOC_ARTIFACT_NAME }}
|
||||
path: obj/artifacts/doc
|
||||
if-no-files-found: ignore
|
||||
retention-days: 5
|
||||
|
||||
- name: upload artifacts to S3
|
||||
run: src/ci/scripts/upload-artifacts.sh
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: "${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}"
|
||||
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}"
|
||||
if: "success() && (github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1')"
|
||||
master:
|
||||
name: master
|
||||
AWS_ACCESS_KEY_ID: ${{ env.ARTIFACTS_AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.ARTIFACTS_AWS_ACCESS_KEY_ID)] }}
|
||||
# Adding a condition on DEPLOY=1 or DEPLOY_ALT=1 is not needed as all deploy
|
||||
# builders *should* have the AWS credentials available. Still, explicitly
|
||||
# adding the condition is helpful as this way CI will not silently skip
|
||||
# deploying artifacts from a dist builder if the variables are misconfigured,
|
||||
# erroring about invalid credentials instead.
|
||||
if: github.event_name == 'push' || env.DEPLOY == '1' || env.DEPLOY_ALT == '1'
|
||||
|
||||
# This job isused to tell bors the final status of the build, as there is no practical way to detect
|
||||
# when a workflow is successful listening to webhooks only in our current bors implementation (homu).
|
||||
outcome:
|
||||
name: bors build finished
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
SCCACHE_BUCKET: rust-lang-ci-sccache2
|
||||
DEPLOY_BUCKET: rust-lang-ci2
|
||||
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
|
||||
TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues"
|
||||
TOOLSTATE_PUBLISH: 1
|
||||
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
|
||||
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
|
||||
AWS_REGION: us-west-1
|
||||
CACHE_DOMAIN: ci-caches.rust-lang.org
|
||||
if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'rust-lang-ci/rust'"
|
||||
needs: [ calculate_matrix, job ]
|
||||
# !cancelled() executes the job regardless of whether the previous jobs passed or failed
|
||||
if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }}
|
||||
steps:
|
||||
- name: checkout the source code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 2
|
||||
# Calculate the exit status of the whole CI workflow.
|
||||
# If all dependent jobs were successful, this exits with 0 (and the outcome job continues successfully).
|
||||
# If a some dependent job has failed, this exits with 1.
|
||||
- name: calculate the correct exit status
|
||||
run: jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJson(needs) }}'
|
||||
# Publish the toolstate if an auto build succeeds (just before push to master)
|
||||
- name: publish toolstate
|
||||
run: src/ci/publish_toolstate.sh
|
||||
shell: bash
|
||||
if: needs.calculate_matrix.outputs.run_type == 'auto'
|
||||
env:
|
||||
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
|
||||
try-success:
|
||||
needs:
|
||||
- job
|
||||
if: "success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
|
||||
steps:
|
||||
- name: mark the job as a success
|
||||
run: exit 0
|
||||
shell: bash
|
||||
name: bors build finished
|
||||
runs-on: ubuntu-latest
|
||||
try-failure:
|
||||
needs:
|
||||
- job
|
||||
if: "!success() && github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
|
||||
steps:
|
||||
- name: mark the job as a failure
|
||||
run: exit 1
|
||||
shell: bash
|
||||
name: bors build finished
|
||||
runs-on: ubuntu-latest
|
||||
auto-success:
|
||||
needs:
|
||||
- job
|
||||
if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
|
||||
steps:
|
||||
- name: mark the job as a success
|
||||
run: exit 0
|
||||
shell: bash
|
||||
name: bors build finished
|
||||
runs-on: ubuntu-latest
|
||||
auto-failure:
|
||||
needs:
|
||||
- job
|
||||
if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
|
||||
steps:
|
||||
- name: mark the job as a failure
|
||||
run: exit 1
|
||||
shell: bash
|
||||
name: bors build finished
|
||||
runs-on: ubuntu-latest
|
||||
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
|
||||
|
|
|
|||
84
Cargo.lock
84
Cargo.lock
|
|
@ -120,6 +120,16 @@ dependencies = [
|
|||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "annotate-snippets"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5a59f105fb9635e9eebdc1e29d53e764fa5795b9cf899a638a53e61567ef61"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
|
|
@ -574,7 +584,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
|
|||
|
||||
[[package]]
|
||||
name = "clippy"
|
||||
version = "0.1.79"
|
||||
version = "0.1.80"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"clippy_config",
|
||||
|
|
@ -595,13 +605,13 @@ dependencies = [
|
|||
"termize",
|
||||
"tokio",
|
||||
"toml 0.7.8",
|
||||
"ui_test 0.22.3",
|
||||
"ui_test 0.23.0",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clippy_config"
|
||||
version = "0.1.79"
|
||||
version = "0.1.80"
|
||||
dependencies = [
|
||||
"rustc-semver",
|
||||
"serde",
|
||||
|
|
@ -624,7 +634,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clippy_lints"
|
||||
version = "0.1.79"
|
||||
version = "0.1.80"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"cargo_metadata 0.18.1",
|
||||
|
|
@ -649,7 +659,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clippy_utils"
|
||||
version = "0.1.79"
|
||||
version = "0.1.80"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"clippy_config",
|
||||
|
|
@ -760,11 +770,9 @@ dependencies = [
|
|||
"glob",
|
||||
"home",
|
||||
"indexmap",
|
||||
"lazycell",
|
||||
"libc",
|
||||
"miow",
|
||||
"miropt-test-tools",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"rustfix 0.8.1",
|
||||
"serde",
|
||||
|
|
@ -970,7 +978,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
|
|||
|
||||
[[package]]
|
||||
name = "declare_clippy_lint"
|
||||
version = "0.1.79"
|
||||
version = "0.1.80"
|
||||
dependencies = [
|
||||
"itertools 0.12.1",
|
||||
"quote",
|
||||
|
|
@ -1256,14 +1264,6 @@ dependencies = [
|
|||
"mdbook",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "expand-yaml-anchors"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"yaml-merge-keys",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "expect-test"
|
||||
version = "1.5.0"
|
||||
|
|
@ -2115,7 +2115,6 @@ dependencies = [
|
|||
"fs-err",
|
||||
"getopts",
|
||||
"jsonpath_lib",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"serde_json",
|
||||
"shlex",
|
||||
|
|
@ -2151,12 +2150,6 @@ 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 = "leb128"
|
||||
version = "0.2.5"
|
||||
|
|
@ -2240,16 +2233,9 @@ name = "linkchecker"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"html5ever",
|
||||
"once_cell",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
|
||||
|
||||
[[package]]
|
||||
name = "lint-docs"
|
||||
version = "0.1.0"
|
||||
|
|
@ -2499,7 +2485,6 @@ dependencies = [
|
|||
"directories",
|
||||
"getrandom",
|
||||
"jemalloc-sys",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"libffi",
|
||||
"libloading",
|
||||
|
|
@ -3343,6 +3328,7 @@ dependencies = [
|
|||
name = "run_make_support"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
"object 0.34.0",
|
||||
"regex",
|
||||
"similar",
|
||||
|
|
@ -4799,12 +4785,10 @@ dependencies = [
|
|||
"arrayvec",
|
||||
"askama",
|
||||
"base64",
|
||||
"byteorder",
|
||||
"expect-test",
|
||||
"indexmap",
|
||||
"itertools 0.12.1",
|
||||
"minifier",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"rustdoc-json-types",
|
||||
"serde",
|
||||
|
|
@ -5186,9 +5170,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "spanned"
|
||||
version = "0.1.6"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad48ded9f0734eca7058107cc170767b8758e41e4088fb0020e7ff7ec6b0d92d"
|
||||
checksum = "ccdf4f5590b7e6fbd4f2e80d442789079a6fff7c12ef921a9de358b7b353098e"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"color-eyre",
|
||||
|
|
@ -5359,7 +5343,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"build_helper",
|
||||
"glob",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -5604,7 +5587,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"cargo_metadata 0.15.4",
|
||||
"ignore",
|
||||
"lazy_static",
|
||||
"miropt-test-tools",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
|
|
@ -5928,11 +5910,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ui_test"
|
||||
version = "0.22.3"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa577a42db0e211a73c069d7dbcae54bc7473a7c5535a564842cbd8a13c0441e"
|
||||
checksum = "29e5f4ffcbab82453958fbf59990e981b8e8a177dcd60c2bd8f9b52c3036a6e1"
|
||||
dependencies = [
|
||||
"annotate-snippets 0.10.2",
|
||||
"annotate-snippets 0.11.2",
|
||||
"anyhow",
|
||||
"bstr",
|
||||
"cargo-platform",
|
||||
|
|
@ -5947,7 +5929,7 @@ dependencies = [
|
|||
"prettydiff",
|
||||
"regex",
|
||||
"rustc_version",
|
||||
"rustfix 0.6.1",
|
||||
"rustfix 0.8.1",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"spanned",
|
||||
|
|
@ -6555,26 +6537,6 @@ dependencies = [
|
|||
"lzma-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-merge-keys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd236a7dc9bb598f349fe4a8754f49181fee50284daa15cd1ba652d722280004"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"thiserror",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yansi-term"
|
||||
version = "0.1.2"
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ members = [
|
|||
"src/tools/miri/cargo-miri",
|
||||
"src/tools/rustdoc-themes",
|
||||
"src/tools/unicode-table-generator",
|
||||
"src/tools/expand-yaml-anchors",
|
||||
"src/tools/jsondocck",
|
||||
"src/tools/jsondoclint",
|
||||
"src/tools/llvm-bitcode-linker",
|
||||
|
|
@ -112,6 +111,3 @@ strip = true
|
|||
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
|
||||
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
|
||||
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
|
||||
|
||||
[patch."https://github.com/rust-lang/rust-clippy"]
|
||||
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
|
||||
|
|
|
|||
120
RELEASES.md
120
RELEASES.md
|
|
@ -1,3 +1,123 @@
|
|||
Version 1.78.0 (2024-05-02)
|
||||
==========================
|
||||
|
||||
<a id="1.78.0-Language"></a>
|
||||
|
||||
Language
|
||||
--------
|
||||
- [Stabilize `#[cfg(target_abi = ...)]`](https://github.com/rust-lang/rust/pull/119590/)
|
||||
- [Stabilize the `#[diagnostic]` namespace and `#[diagnostic::on_unimplemented]` attribute](https://github.com/rust-lang/rust/pull/119888/)
|
||||
- [Make async-fn-in-trait implementable with concrete signatures](https://github.com/rust-lang/rust/pull/120103/)
|
||||
- [Make matching on NaN a hard error, and remove the rest of `illegal_floating_point_literal_pattern`](https://github.com/rust-lang/rust/pull/116284/)
|
||||
- [static mut: allow mutable reference to arbitrary types, not just slices and arrays](https://github.com/rust-lang/rust/pull/117614/)
|
||||
- [Extend `invalid_reference_casting` to include references casting to bigger memory layout](https://github.com/rust-lang/rust/pull/118983/)
|
||||
- [Add `non_contiguous_range_endpoints` lint for singleton gaps after exclusive ranges](https://github.com/rust-lang/rust/pull/118879/)
|
||||
- [Add `wasm_c_abi` lint for use of older wasm-bindgen versions](https://github.com/rust-lang/rust/pull/117918/)
|
||||
This lint currently only works when using Cargo.
|
||||
- [Update `indirect_structural_match` and `pointer_structural_match` lints to match RFC](https://github.com/rust-lang/rust/pull/120423/)
|
||||
- [Make non-`PartialEq`-typed consts as patterns a hard error](https://github.com/rust-lang/rust/pull/120805/)
|
||||
- [Split `refining_impl_trait` lint into `_reachable`, `_internal` variants](https://github.com/rust-lang/rust/pull/121720/)
|
||||
- [Remove unnecessary type inference when using associated types inside of higher ranked `where`-bounds](https://github.com/rust-lang/rust/pull/119849)
|
||||
- [Weaken eager detection of cyclic types during type inference](https://github.com/rust-lang/rust/pull/119989)
|
||||
- [`trait Trait: Auto {}`: allow upcasting from `dyn Trait` to `dyn Auto`](https://github.com/rust-lang/rust/pull/119338)
|
||||
|
||||
<a id="1.78.0-Compiler"></a>
|
||||
|
||||
Compiler
|
||||
--------
|
||||
|
||||
- [Made `INVALID_DOC_ATTRIBUTES` lint deny by default](https://github.com/rust-lang/rust/pull/111505/)
|
||||
- [Increase accuracy of redundant `use` checking](https://github.com/rust-lang/rust/pull/117772/)
|
||||
- [Suggest moving definition if non-found macro_rules! is defined later](https://github.com/rust-lang/rust/pull/121130/)
|
||||
- [Lower transmutes from int to pointer type as gep on null](https://github.com/rust-lang/rust/pull/121282/)
|
||||
|
||||
Target changes:
|
||||
|
||||
- [Windows tier 1 targets now require at least Windows 10](https://github.com/rust-lang/rust/pull/115141/)
|
||||
- [Enable CMPXCHG16B, SSE3, SAHF/LAHF and 128-bit Atomics in tier 1 Windows](https://github.com/rust-lang/rust/pull/120820/)
|
||||
- [Add `wasm32-wasip1` tier 2 (without host tools) target](https://github.com/rust-lang/rust/pull/120468/)
|
||||
- [Add `wasm32-wasip2` tier 3 target](https://github.com/rust-lang/rust/pull/119616/)
|
||||
- [Rename `wasm32-wasi-preview1-threads` to `wasm32-wasip1-threads`](https://github.com/rust-lang/rust/pull/122170/)
|
||||
- [Add `arm64ec-pc-windows-msvc` tier 3 target](https://github.com/rust-lang/rust/pull/119199/)
|
||||
- [Add `armv8r-none-eabihf` tier 3 target for the Cortex-R52](https://github.com/rust-lang/rust/pull/110482/)
|
||||
- [Add `loongarch64-unknown-linux-musl` tier 3 target](https://github.com/rust-lang/rust/pull/121832/)
|
||||
|
||||
Refer to Rust's [platform support page][platform-support-doc]
|
||||
for more information on Rust's tiered platform support.
|
||||
|
||||
<a id="1.78.0-Libraries"></a>
|
||||
|
||||
Libraries
|
||||
---------
|
||||
|
||||
- [Bump Unicode to version 15.1.0, regenerate tables](https://github.com/rust-lang/rust/pull/120777/)
|
||||
- [Make align_offset, align_to well-behaved in all cases](https://github.com/rust-lang/rust/pull/121201/)
|
||||
- [PartialEq, PartialOrd: document expectations for transitive chains](https://github.com/rust-lang/rust/pull/115386/)
|
||||
- [Optimize away poison guards when std is built with panic=abort](https://github.com/rust-lang/rust/pull/100603/)
|
||||
- [Replace pthread `RwLock` with custom implementation](https://github.com/rust-lang/rust/pull/110211/)
|
||||
- [Implement unwind safety for Condvar on all platforms](https://github.com/rust-lang/rust/pull/121768/)
|
||||
- [Add ASCII fast-path for `char::is_grapheme_extended`](https://github.com/rust-lang/rust/pull/121138/)
|
||||
|
||||
<a id="1.78.0-Stabilized-APIs"></a>
|
||||
|
||||
Stabilized APIs
|
||||
---------------
|
||||
|
||||
- [`impl Read for &Stdin`](https://doc.rust-lang.org/stable/std/io/struct.Stdin.html#impl-Read-for-%26Stdin)
|
||||
- [Accept non `'static` lifetimes for several `std::error::Error` related implementations](https://github.com/rust-lang/rust/pull/113833/)
|
||||
- [Make `impl<Fd: AsFd>` impl take `?Sized`](https://github.com/rust-lang/rust/pull/114655/)
|
||||
- [`impl From<TryReserveError> for io::Error`](https://doc.rust-lang.org/stable/std/io/struct.Error.html#impl-From%3CTryReserveError%3E-for-Error)
|
||||
|
||||
These APIs are now stable in const contexts:
|
||||
|
||||
- [`Barrier::new()`](https://doc.rust-lang.org/stable/std/sync/struct.Barrier.html#method.new)
|
||||
|
||||
<a id="1.78.0-Cargo"></a>
|
||||
|
||||
Cargo
|
||||
-----
|
||||
|
||||
- [Stabilize lockfile v4](https://github.com/rust-lang/cargo/pull/12852/)
|
||||
- [Respect `rust-version` when generating lockfile](https://github.com/rust-lang/cargo/pull/12861/)
|
||||
- [Control `--charset` via auto-detecting config value](https://github.com/rust-lang/cargo/pull/13337/)
|
||||
- [Support `target.<triple>.rustdocflags` officially](https://github.com/rust-lang/cargo/pull/13197/)
|
||||
- [Stabilize global cache data tracking](https://github.com/rust-lang/cargo/pull/13492/)
|
||||
|
||||
<a id="1.78.0-Misc"></a>
|
||||
|
||||
Misc
|
||||
----
|
||||
|
||||
- [rustdoc: add `--test-builder-wrapper` arg to support wrappers such as RUSTC_WRAPPER when building doctests](https://github.com/rust-lang/rust/pull/114651/)
|
||||
|
||||
<a id="1.78.0-Compatibility-Notes"></a>
|
||||
|
||||
Compatibility Notes
|
||||
-------------------
|
||||
|
||||
- [Many unsafe precondition checks now run for user code with debug assertions enabled](https://github.com/rust-lang/rust/pull/120594/)
|
||||
This change helps users catch undefined behavior in their code, though the details of how much is checked are generally not stable.
|
||||
- [riscv only supports split_debuginfo=off for now](https://github.com/rust-lang/rust/pull/120518/)
|
||||
- [Consistently check bounds on hidden types of `impl Trait`](https://github.com/rust-lang/rust/pull/121679)
|
||||
- [Change equality of higher ranked types to not rely on subtyping](https://github.com/rust-lang/rust/pull/118247)
|
||||
- [When called, additionally check bounds on normalized function return type](https://github.com/rust-lang/rust/pull/118882)
|
||||
- [Expand coverage for `arithmetic_overflow` lint](https://github.com/rust-lang/rust/pull/119432/)
|
||||
|
||||
<a id="1.78.0-Internal-Changes"></a>
|
||||
|
||||
Internal Changes
|
||||
----------------
|
||||
|
||||
These changes do not affect any public interfaces of Rust, but they represent
|
||||
significant improvements to the performance or internals of rustc and related
|
||||
tools.
|
||||
|
||||
- [Update to LLVM 18](https://github.com/rust-lang/rust/pull/120055/)
|
||||
- [Build `rustc` with 1CGU on `x86_64-pc-windows-msvc`](https://github.com/rust-lang/rust/pull/112267/)
|
||||
- [Build `rustc` with 1CGU on `x86_64-apple-darwin`](https://github.com/rust-lang/rust/pull/112268/)
|
||||
- [Introduce `run-make` V2 infrastructure, a `run_make_support` library and port over 2 tests as example](https://github.com/rust-lang/rust/pull/113026/)
|
||||
- [Windows: Implement condvar, mutex and rwlock using futex](https://github.com/rust-lang/rust/pull/121956/)
|
||||
|
||||
Version 1.77.2 (2024-04-09)
|
||||
===========================
|
||||
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ pub trait LayoutCalculator {
|
|||
// If all the non-ZST fields have the same ABI and union ABI optimizations aren't
|
||||
// disabled, we can use that common ABI for the union as a whole.
|
||||
struct AbiMismatch;
|
||||
let mut common_non_zst_abi_and_align = if repr.inhibit_union_abi_opt() {
|
||||
let mut common_non_zst_abi_and_align = if repr.inhibits_union_abi_opt() {
|
||||
// Can't optimize
|
||||
Err(AbiMismatch)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ impl ReprOptions {
|
|||
}
|
||||
|
||||
/// Returns `true` if this `#[repr()]` should inhibit union ABI optimisations.
|
||||
pub fn inhibit_union_abi_opt(&self) -> bool {
|
||||
pub fn inhibits_union_abi_opt(&self) -> bool {
|
||||
self.c()
|
||||
}
|
||||
}
|
||||
|
|
@ -742,11 +742,21 @@ impl Align {
|
|||
1 << self.pow2
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bytes_usize(self) -> usize {
|
||||
self.bytes().try_into().unwrap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bits(self) -> u64 {
|
||||
self.bytes() * 8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bits_usize(self) -> usize {
|
||||
self.bits().try_into().unwrap()
|
||||
}
|
||||
|
||||
/// Computes the best alignment possible for the given offset
|
||||
/// (the largest power of two that the offset is a multiple of).
|
||||
///
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ use rustc_data_structures::packed::Pu128;
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||
|
|
@ -1390,7 +1390,7 @@ pub struct StructExpr {
|
|||
// Adding a new variant? Please update `test_expr` in `tests/ui/macros/stringify.rs`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ExprKind {
|
||||
/// An array (`[a, b, c, d]`)
|
||||
/// An array (e.g, `[a, b, c, d]`).
|
||||
Array(ThinVec<P<Expr>>),
|
||||
/// Allow anonymous constants from an inline `const` block
|
||||
ConstBlock(AnonConst),
|
||||
|
|
@ -1401,7 +1401,7 @@ pub enum ExprKind {
|
|||
/// This also represents calling the constructor of
|
||||
/// tuple-like ADTs such as tuple structs and enum variants.
|
||||
Call(P<Expr>, ThinVec<P<Expr>>),
|
||||
/// A method call (e.g. `x.foo::<Bar, Baz>(a, b, c)`).
|
||||
/// A method call (e.g., `x.foo::<Bar, Baz>(a, b, c)`).
|
||||
MethodCall(Box<MethodCall>),
|
||||
/// A tuple (e.g., `(a, b, c, d)`).
|
||||
Tup(ThinVec<P<Expr>>),
|
||||
|
|
@ -1413,7 +1413,10 @@ pub enum ExprKind {
|
|||
Lit(token::Lit),
|
||||
/// A cast (e.g., `foo as f64`).
|
||||
Cast(P<Expr>, P<Ty>),
|
||||
/// A type ascription (e.g., `42: usize`).
|
||||
/// A type ascription (e.g., `builtin # type_ascribe(42, usize)`).
|
||||
///
|
||||
/// Usually not written directly in user code but
|
||||
/// indirectly via the macro `type_ascribe!(...)`.
|
||||
Type(P<Expr>, P<Ty>),
|
||||
/// A `let pat = expr` expression that is only semantically allowed in the condition
|
||||
/// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`).
|
||||
|
|
@ -1488,7 +1491,10 @@ pub enum ExprKind {
|
|||
/// Output of the `asm!()` macro.
|
||||
InlineAsm(P<InlineAsm>),
|
||||
|
||||
/// Output of the `offset_of!()` macro.
|
||||
/// An `offset_of` expression (e.g., `builtin # offset_of(Struct, field)`).
|
||||
///
|
||||
/// Usually not written directly in user code but
|
||||
/// indirectly via the macro `core::mem::offset_of!(...)`.
|
||||
OffsetOf(P<Ty>, P<[Ident]>),
|
||||
|
||||
/// A macro invocation; pre-expansion.
|
||||
|
|
@ -3126,6 +3132,35 @@ pub struct StaticItem {
|
|||
pub expr: Option<P<Expr>>,
|
||||
}
|
||||
|
||||
/// A static item in `extern` block.
|
||||
// This struct is identical to StaticItem for now but it's going to have a safety attribute.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct StaticForeignItem {
|
||||
pub ty: P<Ty>,
|
||||
pub mutability: Mutability,
|
||||
pub expr: Option<P<Expr>>,
|
||||
}
|
||||
|
||||
impl From<StaticItem> for StaticForeignItem {
|
||||
fn from(static_item: StaticItem) -> StaticForeignItem {
|
||||
StaticForeignItem {
|
||||
ty: static_item.ty,
|
||||
mutability: static_item.mutability,
|
||||
expr: static_item.expr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StaticForeignItem> for StaticItem {
|
||||
fn from(static_item: StaticForeignItem) -> StaticItem {
|
||||
StaticItem {
|
||||
ty: static_item.ty,
|
||||
mutability: static_item.mutability,
|
||||
expr: static_item.expr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct ConstItem {
|
||||
pub defaultness: Defaultness,
|
||||
|
|
@ -3329,7 +3364,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
|
|||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum ForeignItemKind {
|
||||
/// A foreign static item (`static FOO: u8`).
|
||||
Static(P<Ty>, Mutability, Option<P<Expr>>),
|
||||
Static(Box<StaticForeignItem>),
|
||||
/// An foreign function.
|
||||
Fn(Box<Fn>),
|
||||
/// An foreign type.
|
||||
|
|
@ -3341,8 +3376,8 @@ pub enum ForeignItemKind {
|
|||
impl From<ForeignItemKind> for ItemKind {
|
||||
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
|
||||
match foreign_item_kind {
|
||||
ForeignItemKind::Static(a, b, c) => {
|
||||
ItemKind::Static(StaticItem { ty: a, mutability: b, expr: c }.into())
|
||||
ForeignItemKind::Static(box static_foreign_item) => {
|
||||
ItemKind::Static(Box::new(static_foreign_item.into()))
|
||||
}
|
||||
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
|
||||
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
|
||||
|
|
@ -3356,8 +3391,8 @@ impl TryFrom<ItemKind> for ForeignItemKind {
|
|||
|
||||
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
|
||||
Ok(match item_kind {
|
||||
ItemKind::Static(box StaticItem { ty: a, mutability: b, expr: c }) => {
|
||||
ForeignItemKind::Static(a, b, c)
|
||||
ItemKind::Static(box static_item) => {
|
||||
ForeignItemKind::Static(Box::new(static_item.into()))
|
||||
}
|
||||
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
|
||||
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
|
||||
|
|
@ -3382,8 +3417,8 @@ mod size_asserts {
|
|||
static_assert_size!(Expr, 72);
|
||||
static_assert_size!(ExprKind, 40);
|
||||
static_assert_size!(Fn, 160);
|
||||
static_assert_size!(ForeignItem, 96);
|
||||
static_assert_size!(ForeignItemKind, 24);
|
||||
static_assert_size!(ForeignItem, 88);
|
||||
static_assert_size!(ForeignItemKind, 16);
|
||||
static_assert_size!(GenericArg, 24);
|
||||
static_assert_size!(GenericBound, 88);
|
||||
static_assert_size!(Generics, 40);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
#[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable_Generic)]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`.
|
||||
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::{def_id::DefId, symbol::Ident};
|
||||
|
||||
use crate::MetaItem;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::ptr::P;
|
||||
use crate::Expr;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_macros::{Decodable, Encodable};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#![doc(rust_logo)]
|
||||
#![allow(internal_features)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
|
||||
#![feature(associated_type_defaults)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(if_let_guard)]
|
||||
|
|
@ -20,12 +19,6 @@
|
|||
#![feature(negative_impls)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
pub mod util {
|
||||
pub mod case;
|
||||
pub mod classify;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ impl<A: Array> ExpectOne<A> for SmallVec<A> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait NoopVisitItemKind {
|
||||
fn noop_visit(&mut self, visitor: &mut impl MutVisitor);
|
||||
}
|
||||
|
||||
pub trait MutVisitor: Sized {
|
||||
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
|
||||
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
|
||||
|
|
@ -90,7 +94,7 @@ pub trait MutVisitor: Sized {
|
|||
}
|
||||
|
||||
fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
|
||||
noop_flat_map_foreign_item(ni, self)
|
||||
noop_flat_map_item(ni, self)
|
||||
}
|
||||
|
||||
fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
|
||||
|
|
@ -105,16 +109,12 @@ pub trait MutVisitor: Sized {
|
|||
noop_flat_map_field_def(fd, self)
|
||||
}
|
||||
|
||||
fn visit_item_kind(&mut self, i: &mut ItemKind) {
|
||||
noop_visit_item_kind(i, self);
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
|
||||
noop_flat_map_assoc_item(i, self)
|
||||
noop_flat_map_item(i, self)
|
||||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
|
||||
noop_flat_map_assoc_item(i, self)
|
||||
noop_flat_map_item(i, self)
|
||||
}
|
||||
|
||||
fn visit_fn_decl(&mut self, d: &mut P<FnDecl>) {
|
||||
|
|
@ -1068,149 +1068,151 @@ pub fn noop_visit_block<T: MutVisitor>(block: &mut P<Block>, vis: &mut T) {
|
|||
visit_lazy_tts(tokens, vis);
|
||||
}
|
||||
|
||||
pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
|
||||
match kind {
|
||||
ItemKind::ExternCrate(_orig_name) => {}
|
||||
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
|
||||
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
|
||||
vis.visit_ty(ty);
|
||||
visit_opt(expr, |expr| vis.visit_expr(expr));
|
||||
}
|
||||
ItemKind::Const(item) => {
|
||||
visit_const_item(item, vis);
|
||||
}
|
||||
ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
visit_fn_sig(sig, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_opt(body, |body| vis.visit_block(body));
|
||||
}
|
||||
ItemKind::Mod(unsafety, mod_kind) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
match mod_kind {
|
||||
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
|
||||
vis.visit_span(inner_span);
|
||||
vis.visit_span(inject_use_span);
|
||||
items.flat_map_in_place(|item| vis.flat_map_item(item));
|
||||
pub fn noop_visit_item_kind(kind: &mut impl NoopVisitItemKind, vis: &mut impl MutVisitor) {
|
||||
kind.noop_visit(vis)
|
||||
}
|
||||
|
||||
impl NoopVisitItemKind for ItemKind {
|
||||
fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
||||
match self {
|
||||
ItemKind::ExternCrate(_orig_name) => {}
|
||||
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
|
||||
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
|
||||
vis.visit_ty(ty);
|
||||
visit_opt(expr, |expr| vis.visit_expr(expr));
|
||||
}
|
||||
ItemKind::Const(item) => {
|
||||
visit_const_item(item, vis);
|
||||
}
|
||||
ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
visit_fn_sig(sig, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_opt(body, |body| vis.visit_block(body));
|
||||
}
|
||||
ItemKind::Mod(unsafety, mod_kind) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
match mod_kind {
|
||||
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
|
||||
vis.visit_span(inner_span);
|
||||
vis.visit_span(inject_use_span);
|
||||
items.flat_map_in_place(|item| vis.flat_map_item(item));
|
||||
}
|
||||
ModKind::Unloaded => {}
|
||||
}
|
||||
ModKind::Unloaded => {}
|
||||
}
|
||||
}
|
||||
ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
|
||||
ItemKind::GlobalAsm(asm) => vis.visit_inline_asm(asm),
|
||||
ItemKind::TyAlias(box TyAlias {
|
||||
defaultness, generics, where_clauses, bounds, ty, ..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
vis.visit_generics(generics);
|
||||
vis.visit_span(&mut where_clauses.before.span);
|
||||
vis.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, vis);
|
||||
visit_opt(ty, |ty| vis.visit_ty(ty));
|
||||
}
|
||||
ItemKind::Enum(EnumDef { variants }, generics) => {
|
||||
variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
|
||||
vis.visit_generics(generics);
|
||||
}
|
||||
ItemKind::Struct(variant_data, generics) | ItemKind::Union(variant_data, generics) => {
|
||||
vis.visit_variant_data(variant_data);
|
||||
vis.visit_generics(generics);
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness,
|
||||
unsafety,
|
||||
generics,
|
||||
constness,
|
||||
polarity,
|
||||
of_trait,
|
||||
self_ty,
|
||||
items,
|
||||
}) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
visit_unsafety(unsafety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_constness(constness, vis);
|
||||
visit_polarity(polarity, vis);
|
||||
visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref));
|
||||
vis.visit_ty(self_ty);
|
||||
items.flat_map_in_place(|item| vis.flat_map_impl_item(item));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety, is_auto: _, generics, bounds, items }) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_bounds(bounds, vis);
|
||||
items.flat_map_in_place(|item| vis.flat_map_trait_item(item));
|
||||
}
|
||||
ItemKind::TraitAlias(generics, bounds) => {
|
||||
vis.visit_generics(generics);
|
||||
visit_bounds(bounds, vis);
|
||||
}
|
||||
ItemKind::MacCall(m) => vis.visit_mac_call(m),
|
||||
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
|
||||
ItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
vis.visit_id(id);
|
||||
vis.visit_qself(qself);
|
||||
vis.visit_path(path);
|
||||
if let Some(rename) = rename {
|
||||
vis.visit_ident(rename);
|
||||
ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
|
||||
ItemKind::GlobalAsm(asm) => vis.visit_inline_asm(asm),
|
||||
ItemKind::TyAlias(box TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
bounds,
|
||||
ty,
|
||||
..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
vis.visit_generics(generics);
|
||||
vis.visit_span(&mut where_clauses.before.span);
|
||||
vis.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, vis);
|
||||
visit_opt(ty, |ty| vis.visit_ty(ty));
|
||||
}
|
||||
if let Some(body) = body {
|
||||
vis.visit_block(body);
|
||||
ItemKind::Enum(EnumDef { variants }, generics) => {
|
||||
variants.flat_map_in_place(|variant| vis.flat_map_variant(variant));
|
||||
vis.visit_generics(generics);
|
||||
}
|
||||
ItemKind::Struct(variant_data, generics) | ItemKind::Union(variant_data, generics) => {
|
||||
vis.visit_variant_data(variant_data);
|
||||
vis.visit_generics(generics);
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness,
|
||||
unsafety,
|
||||
generics,
|
||||
constness,
|
||||
polarity,
|
||||
of_trait,
|
||||
self_ty,
|
||||
items,
|
||||
}) => {
|
||||
visit_defaultness(defaultness, vis);
|
||||
visit_unsafety(unsafety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_constness(constness, vis);
|
||||
visit_polarity(polarity, vis);
|
||||
visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref));
|
||||
vis.visit_ty(self_ty);
|
||||
items.flat_map_in_place(|item| vis.flat_map_impl_item(item));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety, is_auto: _, generics, bounds, items }) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
vis.visit_generics(generics);
|
||||
visit_bounds(bounds, vis);
|
||||
items.flat_map_in_place(|item| vis.flat_map_trait_item(item));
|
||||
}
|
||||
ItemKind::TraitAlias(generics, bounds) => {
|
||||
vis.visit_generics(generics);
|
||||
visit_bounds(bounds, vis);
|
||||
}
|
||||
ItemKind::MacCall(m) => vis.visit_mac_call(m),
|
||||
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
|
||||
ItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
vis.visit_id(id);
|
||||
vis.visit_qself(qself);
|
||||
vis.visit_path(path);
|
||||
if let Some(rename) = rename {
|
||||
vis.visit_ident(rename);
|
||||
}
|
||||
if let Some(body) = body {
|
||||
vis.visit_block(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_flat_map_assoc_item<T: MutVisitor>(
|
||||
mut item: P<AssocItem>,
|
||||
visitor: &mut T,
|
||||
) -> SmallVec<[P<AssocItem>; 1]> {
|
||||
let Item { id, ident, vis, attrs, kind, span, tokens } = item.deref_mut();
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_vis(vis);
|
||||
visit_attrs(attrs, visitor);
|
||||
match kind {
|
||||
AssocItemKind::Const(item) => {
|
||||
visit_const_item(item, visitor);
|
||||
}
|
||||
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visit_fn_sig(sig, visitor);
|
||||
visit_opt(body, |body| visitor.visit_block(body));
|
||||
}
|
||||
AssocItemKind::Type(box TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
bounds,
|
||||
ty,
|
||||
..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_span(&mut where_clauses.before.span);
|
||||
visitor.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, visitor);
|
||||
visit_opt(ty, |ty| visitor.visit_ty(ty));
|
||||
}
|
||||
AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
|
||||
AssocItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_qself(qself);
|
||||
visitor.visit_path(path);
|
||||
if let Some(rename) = rename {
|
||||
visitor.visit_ident(rename);
|
||||
impl NoopVisitItemKind for AssocItemKind {
|
||||
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
|
||||
match self {
|
||||
AssocItemKind::Const(item) => {
|
||||
visit_const_item(item, visitor);
|
||||
}
|
||||
if let Some(body) = body {
|
||||
visitor.visit_block(body);
|
||||
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visit_fn_sig(sig, visitor);
|
||||
visit_opt(body, |body| visitor.visit_block(body));
|
||||
}
|
||||
AssocItemKind::Type(box TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
bounds,
|
||||
ty,
|
||||
..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_span(&mut where_clauses.before.span);
|
||||
visitor.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, visitor);
|
||||
visit_opt(ty, |ty| visitor.visit_ty(ty));
|
||||
}
|
||||
AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
|
||||
AssocItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_qself(qself);
|
||||
visitor.visit_path(path);
|
||||
if let Some(rename) = rename {
|
||||
visitor.visit_ident(rename);
|
||||
}
|
||||
if let Some(body) = body {
|
||||
visitor.visit_block(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
visitor.visit_span(span);
|
||||
visit_lazy_tts(tokens, visitor);
|
||||
smallvec![item]
|
||||
}
|
||||
|
||||
fn visit_const_item<T: MutVisitor>(
|
||||
|
|
@ -1241,62 +1243,52 @@ pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
|||
}
|
||||
|
||||
// Mutates one item into possibly many items.
|
||||
pub fn noop_flat_map_item<T: MutVisitor>(
|
||||
mut item: P<Item>,
|
||||
visitor: &mut T,
|
||||
) -> SmallVec<[P<Item>; 1]> {
|
||||
pub fn noop_flat_map_item<K: NoopVisitItemKind>(
|
||||
mut item: P<Item<K>>,
|
||||
visitor: &mut impl MutVisitor,
|
||||
) -> SmallVec<[P<Item<K>>; 1]> {
|
||||
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
|
||||
visitor.visit_ident(ident);
|
||||
visit_attrs(attrs, visitor);
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_item_kind(kind);
|
||||
visit_attrs(attrs, visitor);
|
||||
visitor.visit_vis(vis);
|
||||
visitor.visit_ident(ident);
|
||||
kind.noop_visit(visitor);
|
||||
visitor.visit_span(span);
|
||||
visit_lazy_tts(tokens, visitor);
|
||||
|
||||
smallvec![item]
|
||||
}
|
||||
|
||||
pub fn noop_flat_map_foreign_item<T: MutVisitor>(
|
||||
mut item: P<ForeignItem>,
|
||||
visitor: &mut T,
|
||||
) -> SmallVec<[P<ForeignItem>; 1]> {
|
||||
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
|
||||
visitor.visit_id(id);
|
||||
visitor.visit_ident(ident);
|
||||
visitor.visit_vis(vis);
|
||||
visit_attrs(attrs, visitor);
|
||||
match kind {
|
||||
ForeignItemKind::Static(ty, _, expr) => {
|
||||
visitor.visit_ty(ty);
|
||||
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
||||
impl NoopVisitItemKind for ForeignItemKind {
|
||||
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
|
||||
match self {
|
||||
ForeignItemKind::Static(box StaticForeignItem { ty, mutability: _, expr }) => {
|
||||
visitor.visit_ty(ty);
|
||||
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
||||
}
|
||||
ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visit_fn_sig(sig, visitor);
|
||||
visit_opt(body, |body| visitor.visit_block(body));
|
||||
}
|
||||
ForeignItemKind::TyAlias(box TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
bounds,
|
||||
ty,
|
||||
..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_span(&mut where_clauses.before.span);
|
||||
visitor.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, visitor);
|
||||
visit_opt(ty, |ty| visitor.visit_ty(ty));
|
||||
}
|
||||
ForeignItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
|
||||
}
|
||||
ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visit_fn_sig(sig, visitor);
|
||||
visit_opt(body, |body| visitor.visit_block(body));
|
||||
}
|
||||
ForeignItemKind::TyAlias(box TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
where_clauses,
|
||||
bounds,
|
||||
ty,
|
||||
..
|
||||
}) => {
|
||||
visit_defaultness(defaultness, visitor);
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_span(&mut where_clauses.before.span);
|
||||
visitor.visit_span(&mut where_clauses.after.span);
|
||||
visit_bounds(bounds, visitor);
|
||||
visit_opt(ty, |ty| visitor.visit_ty(ty));
|
||||
}
|
||||
ForeignItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
|
||||
}
|
||||
visitor.visit_span(span);
|
||||
visit_lazy_tts(tokens, visitor);
|
||||
smallvec![item]
|
||||
}
|
||||
|
||||
pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::util::case::Case;
|
|||
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
|
||||
#[allow(hidden_glob_reexports)]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use crate::AttrVec;
|
|||
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::{self, Lrc};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::{sym, Span, SpanDecoder, SpanEncoder, Symbol, DUMMY_SP};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use rustc_lexer::unescape::{
|
|||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use std::{ascii, fmt, str};
|
||||
use tracing::debug;
|
||||
|
||||
// Escapes a string, represented as a symbol. Reuses the original symbol,
|
||||
// avoiding interning, if no changes are required.
|
||||
|
|
|
|||
|
|
@ -102,6 +102,15 @@ pub enum LifetimeCtxt {
|
|||
GenericArg,
|
||||
}
|
||||
|
||||
pub trait WalkItemKind: Sized {
|
||||
fn walk<'a, V: Visitor<'a>>(
|
||||
&'a self,
|
||||
item: &'a Item<Self>,
|
||||
ctxt: AssocCtxt,
|
||||
visitor: &mut V,
|
||||
) -> V::Result;
|
||||
}
|
||||
|
||||
/// Each method of the `Visitor` trait is a hook to be potentially
|
||||
/// overridden. Each method's default implementation recursively visits
|
||||
/// the substructure of the input via the corresponding `walk` method;
|
||||
|
|
@ -120,7 +129,7 @@ pub trait Visitor<'ast>: Sized {
|
|||
Self::Result::output()
|
||||
}
|
||||
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result {
|
||||
walk_foreign_item(self, i)
|
||||
walk_item(self, i)
|
||||
}
|
||||
fn visit_item(&mut self, i: &'ast Item) -> Self::Result {
|
||||
walk_item(self, i)
|
||||
|
|
@ -312,87 +321,98 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
|
|||
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
||||
}
|
||||
|
||||
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) -> V::Result {
|
||||
try_visit!(visitor.visit_vis(&item.vis));
|
||||
try_visit!(visitor.visit_ident(item.ident));
|
||||
match &item.kind {
|
||||
ItemKind::ExternCrate(_) => {}
|
||||
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, item.id, false)),
|
||||
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind =
|
||||
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, item.span, item.id));
|
||||
}
|
||||
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
|
||||
ModKind::Loaded(items, _inline, _inner_span) => {
|
||||
walk_list!(visitor, visit_item, items);
|
||||
impl WalkItemKind for ItemKind {
|
||||
fn walk<'a, V: Visitor<'a>>(
|
||||
&'a self,
|
||||
item: &'a Item<Self>,
|
||||
_ctxt: AssocCtxt,
|
||||
visitor: &mut V,
|
||||
) -> V::Result {
|
||||
match self {
|
||||
ItemKind::ExternCrate(_) => {}
|
||||
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, item.id, false)),
|
||||
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ModKind::Unloaded => {}
|
||||
},
|
||||
ItemKind::ForeignMod(foreign_module) => {
|
||||
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
|
||||
}
|
||||
ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
|
||||
ItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
ItemKind::Enum(enum_definition, generics) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_enum_def(enum_definition));
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness: _,
|
||||
unsafety: _,
|
||||
generics,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
of_trait,
|
||||
self_ty,
|
||||
items,
|
||||
}) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
visit_opt!(visitor, visit_trait_ref, of_trait);
|
||||
try_visit!(visitor.visit_ty(self_ty));
|
||||
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
|
||||
}
|
||||
ItemKind::Struct(struct_definition, generics)
|
||||
| ItemKind::Union(struct_definition, generics) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_variant_data(struct_definition));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
|
||||
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
|
||||
}
|
||||
ItemKind::TraitAlias(generics, bounds) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
}
|
||||
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
||||
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, item.id)),
|
||||
ItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
if let Some(qself) = qself {
|
||||
try_visit!(visitor.visit_ty(&qself.ty));
|
||||
ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind =
|
||||
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, item.span, item.id));
|
||||
}
|
||||
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
|
||||
ModKind::Loaded(items, _inline, _inner_span) => {
|
||||
walk_list!(visitor, visit_item, items);
|
||||
}
|
||||
ModKind::Unloaded => {}
|
||||
},
|
||||
ItemKind::ForeignMod(foreign_module) => {
|
||||
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
|
||||
}
|
||||
ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
|
||||
ItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
ItemKind::Enum(enum_definition, generics) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_enum_def(enum_definition));
|
||||
}
|
||||
ItemKind::Impl(box Impl {
|
||||
defaultness: _,
|
||||
unsafety: _,
|
||||
generics,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
of_trait,
|
||||
self_ty,
|
||||
items,
|
||||
}) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
visit_opt!(visitor, visit_trait_ref, of_trait);
|
||||
try_visit!(visitor.visit_ty(self_ty));
|
||||
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
|
||||
}
|
||||
ItemKind::Struct(struct_definition, generics)
|
||||
| ItemKind::Union(struct_definition, generics) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_variant_data(struct_definition));
|
||||
}
|
||||
ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
|
||||
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
|
||||
}
|
||||
ItemKind::TraitAlias(generics, bounds) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
}
|
||||
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
||||
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, item.id)),
|
||||
ItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
if let Some(qself) = qself {
|
||||
try_visit!(visitor.visit_ty(&qself.ty));
|
||||
}
|
||||
try_visit!(visitor.visit_path(path, *id));
|
||||
visit_opt!(visitor, visit_ident, *rename);
|
||||
visit_opt!(visitor, visit_block, body);
|
||||
}
|
||||
try_visit!(visitor.visit_path(path, *id));
|
||||
visit_opt!(visitor, visit_ident, *rename);
|
||||
visit_opt!(visitor, visit_block, body);
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
walk_list!(visitor, visit_attribute, &item.attrs);
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
pub fn walk_item<'a, V: Visitor<'a>>(
|
||||
visitor: &mut V,
|
||||
item: &'a Item<impl WalkItemKind>,
|
||||
) -> V::Result {
|
||||
walk_assoc_item(visitor, item, AssocCtxt::Trait /*ignored*/)
|
||||
}
|
||||
|
||||
pub fn walk_enum_def<'a, V: Visitor<'a>>(
|
||||
|
|
@ -613,30 +633,34 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
|
|||
V::Result::output()
|
||||
}
|
||||
|
||||
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) -> V::Result {
|
||||
let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
|
||||
try_visit!(visitor.visit_vis(vis));
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
walk_list!(visitor, visit_attribute, attrs);
|
||||
match kind {
|
||||
ForeignItemKind::Static(ty, _, expr) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, span, id));
|
||||
}
|
||||
ForeignItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
ForeignItemKind::MacCall(mac) => {
|
||||
try_visit!(visitor.visit_mac_call(mac));
|
||||
impl WalkItemKind for ForeignItemKind {
|
||||
fn walk<'a, V: Visitor<'a>>(
|
||||
&'a self,
|
||||
item: &'a Item<Self>,
|
||||
_ctxt: AssocCtxt,
|
||||
visitor: &mut V,
|
||||
) -> V::Result {
|
||||
let &Item { id, span, ident, ref vis, .. } = item;
|
||||
match self {
|
||||
ForeignItemKind::Static(box StaticForeignItem { ty, mutability: _, expr }) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, span, id));
|
||||
}
|
||||
ForeignItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
ForeignItemKind::MacCall(mac) => {
|
||||
try_visit!(visitor.visit_mac_call(mac));
|
||||
}
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) -> V::Result {
|
||||
|
|
@ -756,42 +780,56 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
|
|||
V::Result::output()
|
||||
}
|
||||
|
||||
impl WalkItemKind for AssocItemKind {
|
||||
fn walk<'a, V: Visitor<'a>>(
|
||||
&'a self,
|
||||
item: &'a Item<Self>,
|
||||
ctxt: AssocCtxt,
|
||||
visitor: &mut V,
|
||||
) -> V::Result {
|
||||
let &Item { id, span, ident, ref vis, .. } = item;
|
||||
match self {
|
||||
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind =
|
||||
FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, span, id));
|
||||
}
|
||||
AssocItemKind::Type(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
AssocItemKind::MacCall(mac) => {
|
||||
try_visit!(visitor.visit_mac_call(mac));
|
||||
}
|
||||
AssocItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
if let Some(qself) = qself {
|
||||
try_visit!(visitor.visit_ty(&qself.ty));
|
||||
}
|
||||
try_visit!(visitor.visit_path(path, *id));
|
||||
visit_opt!(visitor, visit_ident, *rename);
|
||||
visit_opt!(visitor, visit_block, body);
|
||||
}
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
|
||||
visitor: &mut V,
|
||||
item: &'a AssocItem,
|
||||
item: &'a Item<impl WalkItemKind>,
|
||||
ctxt: AssocCtxt,
|
||||
) -> V::Result {
|
||||
let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
|
||||
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
|
||||
walk_list!(visitor, visit_attribute, attrs);
|
||||
try_visit!(visitor.visit_vis(vis));
|
||||
try_visit!(visitor.visit_ident(ident));
|
||||
walk_list!(visitor, visit_attribute, attrs);
|
||||
match kind {
|
||||
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
visit_opt!(visitor, visit_expr, expr);
|
||||
}
|
||||
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
|
||||
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
|
||||
try_visit!(visitor.visit_fn(kind, span, id));
|
||||
}
|
||||
AssocItemKind::Type(box TyAlias { generics, bounds, ty, .. }) => {
|
||||
try_visit!(visitor.visit_generics(generics));
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
visit_opt!(visitor, visit_ty, ty);
|
||||
}
|
||||
AssocItemKind::MacCall(mac) => {
|
||||
try_visit!(visitor.visit_mac_call(mac));
|
||||
}
|
||||
AssocItemKind::Delegation(box Delegation { id, qself, path, rename, body }) => {
|
||||
if let Some(qself) = qself {
|
||||
try_visit!(visitor.visit_ty(&qself.ty));
|
||||
}
|
||||
try_visit!(visitor.visit_path(path, *id));
|
||||
visit_opt!(visitor, visit_ident, *rename);
|
||||
visit_opt!(visitor, visit_block, body);
|
||||
}
|
||||
}
|
||||
try_visit!(kind.walk(item, ctxt, visitor));
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_NoContext};
|
||||
|
||||
pub mod visit;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ ast_lowering_abi_specified_multiple_times =
|
|||
|
||||
ast_lowering_arbitrary_expression_in_pattern =
|
||||
arbitrary expressions aren't allowed in patterns
|
||||
.pattern_from_macro_note = the `expr` fragment specifier forces the metavariable's content to be an expression
|
||||
|
||||
ast_lowering_argument = argument
|
||||
|
||||
|
|
|
|||
|
|
@ -368,6 +368,8 @@ pub struct NeverPatternWithGuard {
|
|||
pub struct ArbitraryExpressionInPattern {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[note(ast_lowering_pattern_from_macro_note)]
|
||||
pub pattern_from_macro_note: bool,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use rustc_index::IndexVec;
|
|||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
|
||||
struct NodeCollector<'a, 'hir> {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use rustc_span::{DesugaringKind, Span, Symbol};
|
|||
use rustc_target::spec::abi;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use thin_vec::ThinVec;
|
||||
use tracing::instrument;
|
||||
|
||||
pub(super) struct ItemLowerer<'a, 'hir> {
|
||||
pub(super) tcx: TyCtxt<'hir>,
|
||||
|
|
@ -662,10 +663,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
|
||||
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
|
||||
}
|
||||
ForeignItemKind::Static(t, m, _) => {
|
||||
let ty =
|
||||
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
|
||||
hir::ForeignItemKind::Static(ty, *m)
|
||||
ForeignItemKind::Static(box StaticForeignItem { ty, mutability, expr: _ }) => {
|
||||
let ty = self
|
||||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
|
||||
hir::ForeignItemKind::Static(ty, *mutability)
|
||||
}
|
||||
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
|
||||
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
|
||||
|
|
|
|||
|
|
@ -37,11 +37,7 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
|
||||
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, *};
|
||||
|
|
@ -69,6 +65,7 @@ use rustc_span::{DesugaringKind, Span, DUMMY_SP};
|
|||
use smallvec::{smallvec, SmallVec};
|
||||
use std::collections::hash_map::Entry;
|
||||
use thin_vec::ThinVec;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
macro_rules! arena_vec {
|
||||
($this:expr; $($x:expr),*) => (
|
||||
|
|
@ -394,7 +391,7 @@ fn index_crate<'a>(
|
|||
let def_id = self.node_id_to_def_id[&item.id];
|
||||
*self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
|
||||
AstOwner::ForeignItem(item);
|
||||
visit::walk_foreign_item(self, item);
|
||||
visit::walk_item(self, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,7 +339,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
ExprKind::Path(..) if allow_paths => {}
|
||||
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
|
||||
_ => {
|
||||
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern { span: expr.span });
|
||||
let pattern_from_macro = expr.is_approximately_pattern();
|
||||
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
|
||||
span: expr.span,
|
||||
pattern_from_macro_note: pattern_from_macro,
|
||||
});
|
||||
return self.arena.alloc(self.expr_err(expr.span, guar));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use rustc_span::symbol::{kw, sym, Ident};
|
|||
use rustc_span::{BytePos, DesugaringKind, Span, Symbol, DUMMY_SP};
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
|
|
|
|||
|
|
@ -632,20 +632,19 @@ impl<'a> AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn emit_e0568(&self, span: Span, ident: Span) {
|
||||
self.dcx().emit_err(errors::AutoTraitBounds { span, ident });
|
||||
}
|
||||
|
||||
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
|
||||
if let [.., last] = &bounds[..] {
|
||||
let span = ident_span.shrink_to_hi().to(last.span());
|
||||
self.emit_e0568(span, ident_span);
|
||||
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
|
||||
}
|
||||
}
|
||||
|
||||
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
|
||||
if !where_clause.predicates.is_empty() {
|
||||
self.emit_e0568(where_clause.span, ident_span);
|
||||
// FIXME: The current diagnostic is misleading since it only talks about
|
||||
// super trait and lifetime bounds while we should just say “bounds”.
|
||||
self.dcx()
|
||||
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1185,14 +1184,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
self.check_foreign_ty_genericless(generics, where_clauses);
|
||||
self.check_foreign_item_ascii_only(fi.ident);
|
||||
}
|
||||
ForeignItemKind::Static(_, _, body) => {
|
||||
self.check_foreign_kind_bodyless(fi.ident, "static", body.as_ref().map(|b| b.span));
|
||||
ForeignItemKind::Static(box StaticForeignItem { ty: _, mutability: _, expr }) => {
|
||||
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|b| b.span));
|
||||
self.check_foreign_item_ascii_only(fi.ident);
|
||||
}
|
||||
ForeignItemKind::MacCall(..) => {}
|
||||
}
|
||||
|
||||
visit::walk_foreign_item(self, fi)
|
||||
visit::walk_item(self, fi)
|
||||
}
|
||||
|
||||
// Mirrors `visit::walk_generic_args`, but tracks relevant state.
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
ast::ForeignItemKind::MacCall(..) => {}
|
||||
}
|
||||
|
||||
visit::walk_foreign_item(self, i)
|
||||
visit::walk_item(self, i)
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'a ast::Ty) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
|||
}
|
||||
fn visit_foreign_item(&mut self, i: &ForeignItem) {
|
||||
self.count += 1;
|
||||
walk_foreign_item(self, i)
|
||||
walk_item(self, i)
|
||||
}
|
||||
fn visit_item(&mut self, i: &Item) {
|
||||
self.count += 1;
|
||||
|
|
|
|||
|
|
@ -422,7 +422,8 @@ impl<'a> State<'a> {
|
|||
self.print_type(ty);
|
||||
}
|
||||
ast::ExprKind::Type(expr, ty) => {
|
||||
self.word("type_ascribe!(");
|
||||
self.word("builtin # type_ascribe");
|
||||
self.popen();
|
||||
self.ibox(0);
|
||||
self.print_expr(expr, FixupContext::default());
|
||||
|
||||
|
|
@ -431,7 +432,7 @@ impl<'a> State<'a> {
|
|||
self.print_type(ty);
|
||||
|
||||
self.end();
|
||||
self.word(")");
|
||||
self.pclose();
|
||||
}
|
||||
ast::ExprKind::Let(pat, scrutinee, _, _) => {
|
||||
self.print_let(pat, scrutinee, fixup);
|
||||
|
|
@ -488,7 +489,7 @@ impl<'a> State<'a> {
|
|||
self.space();
|
||||
}
|
||||
MatchKind::Postfix => {
|
||||
self.print_expr_as_cond(expr);
|
||||
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
|
||||
self.word_nbsp(".match");
|
||||
}
|
||||
}
|
||||
|
|
@ -657,15 +658,15 @@ impl<'a> State<'a> {
|
|||
);
|
||||
}
|
||||
ast::ExprKind::InlineAsm(a) => {
|
||||
// FIXME: This should have its own syntax, distinct from a macro invocation.
|
||||
// FIXME: Print `builtin # asm` once macro `asm` uses `builtin_syntax`.
|
||||
self.word("asm!");
|
||||
self.print_inline_asm(a);
|
||||
}
|
||||
ast::ExprKind::FormatArgs(fmt) => {
|
||||
// FIXME: This should have its own syntax, distinct from a macro invocation.
|
||||
// FIXME: Print `builtin # format_args` once macro `format_args` uses `builtin_syntax`.
|
||||
self.word("format_args!");
|
||||
self.popen();
|
||||
self.rbox(0, Inconsistent);
|
||||
self.ibox(0);
|
||||
self.word(reconstruct_format_args_template_string(&fmt.template));
|
||||
for arg in fmt.arguments.all_args() {
|
||||
self.word_space(",");
|
||||
|
|
@ -677,7 +678,7 @@ impl<'a> State<'a> {
|
|||
ast::ExprKind::OffsetOf(container, fields) => {
|
||||
self.word("builtin # offset_of");
|
||||
self.popen();
|
||||
self.rbox(0, Inconsistent);
|
||||
self.ibox(0);
|
||||
self.print_type(container);
|
||||
self.word(",");
|
||||
self.space();
|
||||
|
|
@ -690,8 +691,8 @@ impl<'a> State<'a> {
|
|||
self.print_ident(field);
|
||||
}
|
||||
}
|
||||
self.pclose();
|
||||
self.end();
|
||||
self.pclose();
|
||||
}
|
||||
ast::ExprKind::MacCall(m) => self.print_mac(m),
|
||||
ast::ExprKind::Paren(e) => {
|
||||
|
|
|
|||
|
|
@ -30,15 +30,17 @@ impl<'a> State<'a> {
|
|||
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
|
||||
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
|
||||
}
|
||||
ast::ForeignItemKind::Static(ty, mutbl, body) => self.print_item_const(
|
||||
ident,
|
||||
Some(*mutbl),
|
||||
&ast::Generics::default(),
|
||||
ty,
|
||||
body.as_deref(),
|
||||
vis,
|
||||
ast::Defaultness::Final,
|
||||
),
|
||||
ast::ForeignItemKind::Static(box ast::StaticForeignItem { ty, mutability, expr }) => {
|
||||
self.print_item_const(
|
||||
ident,
|
||||
Some(*mutability),
|
||||
&ast::Generics::default(),
|
||||
ty,
|
||||
expr.as_deref(),
|
||||
vis,
|
||||
ast::Defaultness::Final,
|
||||
)
|
||||
}
|
||||
ast::ForeignItemKind::TyAlias(box ast::TyAlias {
|
||||
defaultness,
|
||||
generics,
|
||||
|
|
@ -236,6 +238,7 @@ impl<'a> State<'a> {
|
|||
self.bclose(item.span, empty);
|
||||
}
|
||||
ast::ItemKind::GlobalAsm(asm) => {
|
||||
// FIXME: Print `builtin # global_asm` once macro `global_asm` uses `builtin_syntax`.
|
||||
self.head(visibility_qualified(&item.vis, "global_asm!"));
|
||||
self.print_inline_asm(asm);
|
||||
self.word(";");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use rustc_ast::{Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedM
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_session::config::ExpectedValues;
|
||||
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@
|
|||
#![doc(rust_logo)]
|
||||
#![feature(let_chains)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
||||
mod builtin;
|
||||
mod session_diagnostics;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::num::IntErrorKind;
|
|||
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use rustc_index::bit_set::BitSet;
|
|||
use rustc_middle::mir::traversal;
|
||||
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{self, Body, Local, Location};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use std::fmt;
|
||||
|
|
@ -109,9 +110,7 @@ impl LocalsStateAtExit {
|
|||
has_storage_dead.visit_body(body);
|
||||
let mut has_storage_dead_or_moved = has_storage_dead.0;
|
||||
for move_out in &move_data.moves {
|
||||
if let Some(index) = move_data.base_local(move_out.path) {
|
||||
has_storage_dead_or_moved.insert(index);
|
||||
}
|
||||
has_storage_dead_or_moved.insert(move_data.base_local(move_out.path));
|
||||
}
|
||||
LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Diag, DiagCtxt};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::visit::{
|
||||
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_hir::intravisit::{walk_block, walk_expr, Map, Visitor};
|
||||
use rustc_hir::{CoroutineDesugaring, PatField};
|
||||
use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::mir::{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use rustc_hir::CoroutineKind;
|
|||
use rustc_index::IndexSlice;
|
||||
use rustc_infer::infer::BoundRegionConversionTime;
|
||||
use rustc_infer::traits::{FulfillmentErrorCode, SelectionError};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::mir::{
|
||||
AggregateKind, CallSource, ConstOperand, FakeReadCause, Local, LocalInfo, LocalKind, Location,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::{CaptureBy, ExprKind, HirId, Node};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use rustc_errors::{Applicability, Diag};
|
|||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
|
||||
use rustc_infer::traits;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
|
||||
use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_middle::{
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use rustc_infer::infer::{
|
|||
error_reporting::unexpected_hidden_region_diagnostic,
|
||||
NllRegionVariableOrigin, RelateParamBound,
|
||||
};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::place::PlaceBase;
|
||||
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
|
||||
use rustc_middle::ty::GenericArgs;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_middle::ty::print::RegionHighlightMode;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty};
|
||||
use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#![feature(rustdoc_internals)]
|
||||
#![doc(rust_logo)]
|
||||
#![feature(assert_matches)]
|
||||
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(let_chains)]
|
||||
|
|
@ -14,8 +13,6 @@
|
|||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(try_blocks)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
|
|
@ -33,6 +30,7 @@ use rustc_middle::mir::tcx::PlaceTy;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint::builtin::UNUSED_MUT;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ use crate::ArtificialField;
|
|||
use crate::Overlap;
|
||||
use crate::{AccessDepth, Deep, Shallow};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{
|
||||
Body, BorrowKind, FakeBorrowKind, MutBorrowKind, Place, PlaceElem, PlaceRef, ProjectionElem,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::{
|
||||
self, BasicBlock, Body, FakeBorrowKind, Location, NonDivergingIntrinsic, Place, Rvalue,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use rustc_index::{IndexSlice, IndexVec};
|
|||
use rustc_infer::infer::outlives::test_type_match;
|
||||
use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq};
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{
|
||||
BasicBlock, Body, ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureOutlivesSubjectTy,
|
||||
ClosureRegionRequirements, ConstraintCategory, Local, Location, ReturnConstraint,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use std::fmt;
|
|||
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_infer::infer::canonical::Canonical;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
|
|||
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
|
||||
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
|
||||
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use itertools::{Either, Itertools};
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::mir::visit::{TyContext, Visitor};
|
||||
use rustc_middle::mir::{Body, Local, Location, SourceInfo};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use rustc_middle::ty::{
|
|||
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgsRef, UserArgs};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::source_map::Spanned;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use rustc_infer::infer::NllRegionVariableOrigin;
|
|||
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
|
||||
use rustc_infer::traits::{Obligation, PredicateObligations};
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::fold::FnMutDelegate;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use rustc_middle::ty::fold::TypeFoldable;
|
|||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::Symbol;
|
||||
use std::iter;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,8 @@ builtin_macros_env_not_unicode = environment variable `{$var}` is not a valid Un
|
|||
|
||||
builtin_macros_env_takes_args = `env!()` takes 1 or 2 arguments
|
||||
|
||||
builtin_macros_expected_comma_in_list = expected token: `,`
|
||||
|
||||
builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern
|
||||
|
||||
builtin_macros_expected_register_class_or_explicit_register = expected register class or explicit register
|
||||
|
|
@ -219,12 +221,16 @@ builtin_macros_non_exhaustive_default = default variant must be exhaustive
|
|||
builtin_macros_non_unit_default = the `#[default]` attribute may only be used on unit enum variants
|
||||
.help = consider a manual implementation of `Default`
|
||||
|
||||
builtin_macros_only_one_argument = {$name} takes 1 argument
|
||||
|
||||
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
||||
|
||||
builtin_macros_requires_cfg_pattern =
|
||||
macro requires a cfg-pattern as an argument
|
||||
.label = cfg-pattern required
|
||||
|
||||
builtin_macros_takes_no_arguments = {$name} takes no arguments
|
||||
|
||||
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
|
||||
.label = `{$kind}` because of this
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use rustc_span::symbol::{kw, sym, Ident};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand(
|
||||
pub(crate) fn expand(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
_span: Span,
|
||||
meta_item: &ast::MetaItem,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::errors;
|
||||
use crate::util::expr_to_spanned_string;
|
||||
use ast::token::IdentIsRaw;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
|
|
@ -16,8 +18,6 @@ use rustc_span::{ErrorGuaranteed, InnerSpan, Span};
|
|||
use rustc_target::asm::InlineAsmArch;
|
||||
use smallvec::smallvec;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
pub struct AsmArgs {
|
||||
pub templates: Vec<P<ast::Expr>>,
|
||||
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
|||
use rustc_span::{Span, DUMMY_SP};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_assert<'cx>(
|
||||
pub(crate) fn expand_assert<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
span: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use rustc_errors::PResult;
|
|||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub fn expand_cfg(
|
||||
pub(crate) fn expand_cfg(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use rustc_session::Session;
|
|||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::instrument;
|
||||
|
||||
pub(crate) fn expand(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
|
|
@ -246,18 +247,18 @@ impl MutVisitor for CfgEval<'_, '_> {
|
|||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
mut_visit::noop_flat_map_assoc_item(configure!(self, item), self)
|
||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
mut_visit::noop_flat_map_assoc_item(configure!(self, item), self)
|
||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||
}
|
||||
|
||||
fn flat_map_foreign_item(
|
||||
&mut self,
|
||||
foreign_item: P<ast::ForeignItem>,
|
||||
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
|
||||
mut_visit::noop_flat_map_foreign_item(configure!(self, foreign_item), self)
|
||||
mut_visit::noop_flat_map_item(configure!(self, foreign_item), self)
|
||||
}
|
||||
|
||||
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// The compiler code necessary to support the compile_error! extension.
|
||||
|
||||
use crate::util::get_single_str_from_tts;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_expand::base::get_single_str_from_tts;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub fn expand_compile_error<'cx>(
|
||||
pub(crate) fn expand_compile_error<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use crate::errors;
|
||||
use crate::util::get_exprs_from_tts;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{ExprKind, LitKind, UnOp};
|
||||
use rustc_expand::base::get_exprs_from_tts;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
pub fn expand_concat(
|
||||
pub(crate) fn expand_concat(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: rustc_span::Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
use crate::errors;
|
||||
use crate::util::get_exprs_from_tts;
|
||||
use rustc_ast::{ptr::P, token, tokenstream::TokenStream, ExprKind, LitIntType, LitKind, UintTy};
|
||||
use rustc_expand::base::get_exprs_from_tts;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
||||
use crate::errors;
|
||||
|
||||
/// Emits errors for literal expressions that are invalid inside and outside of an array.
|
||||
fn invalid_type_err(
|
||||
cx: &ExtCtxt<'_>,
|
||||
|
|
@ -108,7 +107,7 @@ fn handle_array_element(
|
|||
None
|
||||
}
|
||||
|
||||
pub fn expand_concat_bytes(
|
||||
pub(crate) fn expand_concat_bytes(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_span::Span;
|
|||
|
||||
use crate::errors;
|
||||
|
||||
pub fn expand_concat_idents<'cx>(
|
||||
pub(crate) fn expand_concat_idents<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -3,14 +3,18 @@ use crate::errors;
|
|||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::{GenericParamKind, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
|
||||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
|
||||
use rustc_expand::base::{
|
||||
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
|
||||
};
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
||||
pub(crate) struct Expander(pub bool);
|
||||
pub(crate) struct Expander {
|
||||
pub is_const: bool,
|
||||
}
|
||||
|
||||
impl MultiItemModifier for Expander {
|
||||
fn expand(
|
||||
|
|
@ -58,7 +62,12 @@ impl MultiItemModifier for Expander {
|
|||
report_path_args(sess, meta);
|
||||
meta.path.clone()
|
||||
})
|
||||
.map(|path| (path, dummy_annotatable(), None, self.0))
|
||||
.map(|path| DeriveResolution {
|
||||
path,
|
||||
item: dummy_annotatable(),
|
||||
exts: None,
|
||||
is_const: self.is_const,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
_ => vec![],
|
||||
|
|
@ -67,15 +76,15 @@ impl MultiItemModifier for Expander {
|
|||
// Do not configure or clone items unless necessary.
|
||||
match &mut resolutions[..] {
|
||||
[] => {}
|
||||
[(_, first_item, ..), others @ ..] => {
|
||||
*first_item = cfg_eval(
|
||||
[first, others @ ..] => {
|
||||
first.item = cfg_eval(
|
||||
sess,
|
||||
features,
|
||||
item.clone(),
|
||||
ecx.current_expansion.lint_node_id,
|
||||
);
|
||||
for (_, item, _, _) in others {
|
||||
*item = first_item.clone();
|
||||
for other in others {
|
||||
other.item = first.item.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use rustc_ast::MetaItem;
|
|||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub fn expand_deriving_copy(
|
||||
pub(crate) fn expand_deriving_copy(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
@ -28,7 +28,7 @@ pub fn expand_deriving_copy(
|
|||
trait_def.expand(cx, mitem, item, push);
|
||||
}
|
||||
|
||||
pub fn expand_deriving_const_param_ty(
|
||||
pub(crate) fn expand_deriving_const_param_ty(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_span::symbol::{kw, sym, Ident};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_clone(
|
||||
pub(crate) fn expand_deriving_clone(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_eq(
|
||||
pub(crate) fn expand_deriving_eq(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Ident};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_deriving_ord(
|
||||
pub(crate) fn expand_deriving_ord(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
@ -39,7 +39,7 @@ pub fn expand_deriving_ord(
|
|||
trait_def.expand(cx, mitem, item, push)
|
||||
}
|
||||
|
||||
pub fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
|
||||
pub(crate) fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
|
||||
let test_id = Ident::new(sym::cmp, span);
|
||||
let equal_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
|
||||
let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_span::symbol::sym;
|
|||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_deriving_partial_eq(
|
||||
pub(crate) fn expand_deriving_partial_eq(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Ident};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_deriving_partial_ord(
|
||||
pub(crate) fn expand_deriving_partial_ord(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_debug(
|
||||
pub(crate) fn expand_deriving_debug(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_rustc_decodable(
|
||||
pub(crate) fn expand_deriving_rustc_decodable(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use rustc_span::{ErrorGuaranteed, Span};
|
|||
use smallvec::SmallVec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_default(
|
||||
pub(crate) fn expand_deriving_default(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &ast::MetaItem,
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_rustc_encodable(
|
||||
pub(crate) fn expand_deriving_rustc_encodable(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -174,8 +174,8 @@
|
|||
//! )
|
||||
//! ```
|
||||
|
||||
pub use StaticFields::*;
|
||||
pub use SubstructureFields::*;
|
||||
pub(crate) use StaticFields::*;
|
||||
pub(crate) use SubstructureFields::*;
|
||||
|
||||
use crate::{deriving, errors};
|
||||
use rustc_ast::ptr::P;
|
||||
|
|
@ -195,9 +195,9 @@ use std::vec;
|
|||
use thin_vec::{thin_vec, ThinVec};
|
||||
use ty::{Bounds, Path, Ref, Self_, Ty};
|
||||
|
||||
pub mod ty;
|
||||
pub(crate) mod ty;
|
||||
|
||||
pub struct TraitDef<'a> {
|
||||
pub(crate) struct TraitDef<'a> {
|
||||
/// The span for the current #[derive(Foo)] header.
|
||||
pub span: Span,
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ pub struct TraitDef<'a> {
|
|||
pub is_const: bool,
|
||||
}
|
||||
|
||||
pub struct MethodDef<'a> {
|
||||
pub(crate) struct MethodDef<'a> {
|
||||
/// name of the method
|
||||
pub name: Symbol,
|
||||
/// List of generics, e.g., `R: rand::Rng`
|
||||
|
|
@ -248,7 +248,7 @@ pub struct MethodDef<'a> {
|
|||
|
||||
/// How to handle fieldless enum variants.
|
||||
#[derive(PartialEq)]
|
||||
pub enum FieldlessVariantsStrategy {
|
||||
pub(crate) enum FieldlessVariantsStrategy {
|
||||
/// Combine fieldless variants into a single match arm.
|
||||
/// This assumes that relevant information has been handled
|
||||
/// by looking at the enum's discriminant.
|
||||
|
|
@ -263,7 +263,7 @@ pub enum FieldlessVariantsStrategy {
|
|||
}
|
||||
|
||||
/// All the data about the data structure/method being derived upon.
|
||||
pub struct Substructure<'a> {
|
||||
pub(crate) struct Substructure<'a> {
|
||||
/// ident of self
|
||||
pub type_ident: Ident,
|
||||
/// Verbatim access to any non-selflike arguments, i.e. arguments that
|
||||
|
|
@ -273,7 +273,7 @@ pub struct Substructure<'a> {
|
|||
}
|
||||
|
||||
/// Summary of the relevant parts of a struct/enum field.
|
||||
pub struct FieldInfo {
|
||||
pub(crate) struct FieldInfo {
|
||||
pub span: Span,
|
||||
/// None for tuple structs/normal enum variants, Some for normal
|
||||
/// structs/struct enum variants.
|
||||
|
|
@ -287,13 +287,13 @@ pub struct FieldInfo {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum IsTuple {
|
||||
pub(crate) enum IsTuple {
|
||||
No,
|
||||
Yes,
|
||||
}
|
||||
|
||||
/// Fields for a static method
|
||||
pub enum StaticFields {
|
||||
pub(crate) enum StaticFields {
|
||||
/// Tuple and unit structs/enum variants like this.
|
||||
Unnamed(Vec<Span>, IsTuple),
|
||||
/// Normal structs/struct variants.
|
||||
|
|
@ -301,7 +301,7 @@ pub enum StaticFields {
|
|||
}
|
||||
|
||||
/// A summary of the possible sets of fields.
|
||||
pub enum SubstructureFields<'a> {
|
||||
pub(crate) enum SubstructureFields<'a> {
|
||||
/// A non-static method where `Self` is a struct.
|
||||
Struct(&'a ast::VariantData, Vec<FieldInfo>),
|
||||
|
||||
|
|
@ -329,10 +329,10 @@ pub enum SubstructureFields<'a> {
|
|||
|
||||
/// Combine the values of all the fields together. The last argument is
|
||||
/// all the fields of all the structures.
|
||||
pub type CombineSubstructureFunc<'a> =
|
||||
pub(crate) type CombineSubstructureFunc<'a> =
|
||||
Box<dyn FnMut(&ExtCtxt<'_>, Span, &Substructure<'_>) -> BlockOrExpr + 'a>;
|
||||
|
||||
pub fn combine_substructure(
|
||||
pub(crate) fn combine_substructure(
|
||||
f: CombineSubstructureFunc<'_>,
|
||||
) -> RefCell<CombineSubstructureFunc<'_>> {
|
||||
RefCell::new(f)
|
||||
|
|
@ -349,7 +349,7 @@ struct TypeParameter {
|
|||
/// avoiding the insertion of any unnecessary blocks.
|
||||
///
|
||||
/// The statements come before the expression.
|
||||
pub struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
|
||||
pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
|
||||
|
||||
impl BlockOrExpr {
|
||||
pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
|
||||
|
|
@ -1647,7 +1647,7 @@ impl<'a> TraitDef<'a> {
|
|||
/// The function passed to `cs_fold` is called repeatedly with a value of this
|
||||
/// type. It describes one part of the code generation. The result is always an
|
||||
/// expression.
|
||||
pub enum CsFold<'a> {
|
||||
pub(crate) enum CsFold<'a> {
|
||||
/// The basic case: a field expression for one or more selflike args. E.g.
|
||||
/// for `PartialEq::eq` this is something like `self.x == other.x`.
|
||||
Single(&'a FieldInfo),
|
||||
|
|
@ -1662,7 +1662,7 @@ pub enum CsFold<'a> {
|
|||
|
||||
/// Folds over fields, combining the expressions for each field in a sequence.
|
||||
/// Statics may not be folded over.
|
||||
pub fn cs_fold<F>(
|
||||
pub(crate) fn cs_fold<F>(
|
||||
use_foldl: bool,
|
||||
cx: &ExtCtxt<'_>,
|
||||
trait_span: Span,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use
|
||||
//! when specifying impls to be derived.
|
||||
|
||||
pub use Ty::*;
|
||||
pub(crate) use Ty::*;
|
||||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind};
|
||||
|
|
@ -14,14 +14,14 @@ use thin_vec::ThinVec;
|
|||
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
|
||||
/// for type parameters.
|
||||
#[derive(Clone)]
|
||||
pub struct Path {
|
||||
pub(crate) struct Path {
|
||||
path: Vec<Symbol>,
|
||||
params: Vec<Box<Ty>>,
|
||||
kind: PathKind,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum PathKind {
|
||||
pub(crate) enum PathKind {
|
||||
Local,
|
||||
Global,
|
||||
Std,
|
||||
|
|
@ -72,7 +72,7 @@ impl Path {
|
|||
|
||||
/// A type. Supports pointers, Self, and literals.
|
||||
#[derive(Clone)]
|
||||
pub enum Ty {
|
||||
pub(crate) enum Ty {
|
||||
Self_,
|
||||
/// A reference.
|
||||
Ref(Box<Ty>, ast::Mutability),
|
||||
|
|
@ -83,7 +83,7 @@ pub enum Ty {
|
|||
Unit,
|
||||
}
|
||||
|
||||
pub fn self_ref() -> Ty {
|
||||
pub(crate) fn self_ref() -> Ty {
|
||||
Ref(Box::new(Self_), ast::Mutability::Not)
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ fn mk_ty_param(
|
|||
|
||||
/// Bounds on type parameters.
|
||||
#[derive(Clone)]
|
||||
pub struct Bounds {
|
||||
pub(crate) struct Bounds {
|
||||
pub bounds: Vec<(Symbol, Vec<Path>)>,
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ impl Bounds {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_explicit_self(cx: &ExtCtxt<'_>, span: Span) -> (P<Expr>, ast::ExplicitSelf) {
|
||||
pub(crate) fn get_explicit_self(cx: &ExtCtxt<'_>, span: Span) -> (P<Expr>, ast::ExplicitSelf) {
|
||||
// This constructs a fresh `self` path.
|
||||
let self_path = cx.expr_self(span);
|
||||
let self_ty = respan(span, SelfKind::Region(None, ast::Mutability::Not));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_span::symbol::sym;
|
|||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_deriving_hash(
|
||||
pub(crate) fn expand_deriving_hash(
|
||||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
mitem: &MetaItem,
|
||||
|
|
|
|||
|
|
@ -20,24 +20,24 @@ macro path_std($($x:tt)*) {
|
|||
generic::ty::Path::new( pathvec_std!( $($x)* ) )
|
||||
}
|
||||
|
||||
pub mod bounds;
|
||||
pub mod clone;
|
||||
pub mod debug;
|
||||
pub mod decodable;
|
||||
pub mod default;
|
||||
pub mod encodable;
|
||||
pub mod hash;
|
||||
pub(crate) mod bounds;
|
||||
pub(crate) mod clone;
|
||||
pub(crate) mod debug;
|
||||
pub(crate) mod decodable;
|
||||
pub(crate) mod default;
|
||||
pub(crate) mod encodable;
|
||||
pub(crate) mod hash;
|
||||
|
||||
#[path = "cmp/eq.rs"]
|
||||
pub mod eq;
|
||||
pub(crate) mod eq;
|
||||
#[path = "cmp/ord.rs"]
|
||||
pub mod ord;
|
||||
pub(crate) mod ord;
|
||||
#[path = "cmp/partial_eq.rs"]
|
||||
pub mod partial_eq;
|
||||
pub(crate) mod partial_eq;
|
||||
#[path = "cmp/partial_ord.rs"]
|
||||
pub mod partial_ord;
|
||||
pub(crate) mod partial_ord;
|
||||
|
||||
pub mod generic;
|
||||
pub(crate) mod generic;
|
||||
|
||||
pub(crate) type BuiltinDeriveFn =
|
||||
fn(&ExtCtxt<'_>, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable), bool);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use rustc_span::Span;
|
|||
///
|
||||
/// `$crate` will refer to either the `std` or `core` crate depending on which
|
||||
/// one we're expanding from.
|
||||
pub fn expand_panic<'cx>(
|
||||
pub(crate) fn expand_panic<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -29,7 +29,7 @@ pub fn expand_panic<'cx>(
|
|||
/// - `$crate::panic::unreachable_2015!(...)` or
|
||||
/// - `$crate::panic::unreachable_2021!(...)`
|
||||
/// depending on the edition.
|
||||
pub fn expand_unreachable<'cx>(
|
||||
pub(crate) fn expand_unreachable<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -69,7 +69,7 @@ fn expand<'cx>(
|
|||
))
|
||||
}
|
||||
|
||||
pub fn use_panic_2021(mut span: Span) -> bool {
|
||||
pub(crate) fn use_panic_2021(mut span: Span) -> bool {
|
||||
// To determine the edition, we check the first span up the expansion
|
||||
// stack that does not have #[allow_internal_unstable(edition_panic)].
|
||||
// (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@
|
|||
// interface.
|
||||
//
|
||||
|
||||
use crate::errors;
|
||||
use crate::util::{expr_to_string, get_exprs_from_tts, get_single_str_from_tts};
|
||||
use rustc_ast::token::{self, LitKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{AstDeref, ExprKind, GenericArg, Mutability};
|
||||
use rustc_expand::base::{expr_to_string, get_exprs_from_tts, get_single_str_from_tts};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
|
@ -14,8 +15,6 @@ use std::env;
|
|||
use std::env::VarError;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Result<Symbol, VarError> {
|
||||
let var = var.as_str();
|
||||
if let Some(value) = cx.sess.opts.logical_env.get(var) {
|
||||
|
|
@ -26,7 +25,7 @@ fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Result<Symbol, VarError
|
|||
Ok(Symbol::intern(&env::var(var)?))
|
||||
}
|
||||
|
||||
pub fn expand_option_env<'cx>(
|
||||
pub(crate) fn expand_option_env<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -66,7 +65,7 @@ pub fn expand_option_env<'cx>(
|
|||
ExpandResult::Ready(MacEager::expr(e))
|
||||
}
|
||||
|
||||
pub fn expand_env<'cx>(
|
||||
pub(crate) fn expand_env<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ pub(crate) struct FormatUnknownTrait<'a> {
|
|||
style = "tool-only",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub struct FormatUnknownTraitSugg {
|
||||
pub(crate) struct FormatUnknownTraitSugg {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub fmt: &'static str,
|
||||
|
|
@ -842,3 +842,26 @@ pub(crate) struct ExpectedRegisterClassOrExplicitRegister {
|
|||
#[primary_span]
|
||||
pub(crate) span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(builtin_macros_expected_comma_in_list)]
|
||||
pub(crate) struct ExpectedCommaInList {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(builtin_macros_only_one_argument)]
|
||||
pub(crate) struct OnlyOneArgument<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(builtin_macros_takes_no_arguments)]
|
||||
pub(crate) struct TakesNoArguments<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub name: &'a str,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::errors;
|
||||
use crate::util::expr_to_spanned_string;
|
||||
use parse::Position::ArgumentNamed;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
|
|
@ -10,14 +12,13 @@ use rustc_ast::{
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
|
||||
use rustc_expand::base::*;
|
||||
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
|
||||
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId};
|
||||
use rustc_parse::parser::Recovered;
|
||||
use rustc_parse_format as parse;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{BytePos, ErrorGuaranteed, InnerSpan, Span};
|
||||
|
||||
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
|
||||
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId};
|
||||
|
||||
// The format_args!() macro is expanded in three steps:
|
||||
// 1. First, `parse_args` will parse the `(literal, arg, arg, name=arg, name=arg)` syntax,
|
||||
// but doesn't parse the template (the literal) itself.
|
||||
|
|
@ -38,8 +39,6 @@ enum PositionUsedAs {
|
|||
}
|
||||
use PositionUsedAs::*;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MacroInput {
|
||||
fmtstr: P<Expr>,
|
||||
|
|
@ -1001,7 +1000,7 @@ fn expand_format_args_impl<'cx>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn expand_format_args<'cx>(
|
||||
pub(crate) fn expand_format_args<'cx>(
|
||||
ecx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -1009,7 +1008,7 @@ pub fn expand_format_args<'cx>(
|
|||
expand_format_args_impl(ecx, sp, tts, false)
|
||||
}
|
||||
|
||||
pub fn expand_format_args_nl<'cx>(
|
||||
pub(crate) fn expand_format_args_nl<'cx>(
|
||||
ecx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
|||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand(
|
||||
pub(crate) fn expand(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
_span: Span,
|
||||
meta_item: &ast::MetaItem,
|
||||
|
|
|
|||
|
|
@ -19,11 +19,7 @@
|
|||
|
||||
extern crate proc_macro;
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use crate::deriving::*;
|
||||
|
||||
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
|
||||
use rustc_expand::proc_macro::BangProcMacro;
|
||||
use rustc_span::symbol::sym;
|
||||
|
|
@ -50,13 +46,13 @@ mod pattern_type;
|
|||
mod source_util;
|
||||
mod test;
|
||||
mod trace_macros;
|
||||
mod util;
|
||||
|
||||
pub mod asm;
|
||||
pub mod cmdline_attrs;
|
||||
pub mod proc_macro_harness;
|
||||
pub mod standard_library_imports;
|
||||
pub mod test_harness;
|
||||
pub mod util;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
||||
|
|
@ -109,8 +105,8 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
|||
bench: test::expand_bench,
|
||||
cfg_accessible: cfg_accessible::Expander,
|
||||
cfg_eval: cfg_eval::expand,
|
||||
derive: derive::Expander(false),
|
||||
derive_const: derive::Expander(true),
|
||||
derive: derive::Expander { is_const: false },
|
||||
derive_const: derive::Expander { is_const: true },
|
||||
global_allocator: global_allocator::expand,
|
||||
test: test::expand_test,
|
||||
test_case: test::expand_test_case,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use rustc_ast::tokenstream::TokenStream;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
|
||||
|
||||
pub fn expand_log_syntax<'cx>(
|
||||
pub(crate) fn expand_log_syntax<'cx>(
|
||||
_cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: rustc_span::Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use rustc_errors::PResult;
|
|||
use rustc_expand::base::{self, DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
|
||||
use rustc_span::{sym, Span};
|
||||
|
||||
pub fn expand<'cx>(
|
||||
pub(crate) fn expand<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
use crate::util::{
|
||||
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token;
|
||||
|
|
@ -5,11 +8,8 @@ use rustc_ast::tokenstream::TokenStream;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_expand::base::{
|
||||
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
|
||||
resolve_path,
|
||||
resolve_path, DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult,
|
||||
};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt};
|
||||
use rustc_expand::base::{MacEager, MacResult, MacroExpanderResult};
|
||||
use rustc_expand::module::DirOwnership;
|
||||
use rustc_parse::new_parser_from_file;
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
|
|
@ -26,7 +26,7 @@ use std::rc::Rc;
|
|||
// a given file into the current one.
|
||||
|
||||
/// line!(): expands to the current line number
|
||||
pub fn expand_line(
|
||||
pub(crate) fn expand_line(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -41,7 +41,7 @@ pub fn expand_line(
|
|||
}
|
||||
|
||||
/* column!(): expands to the current column number */
|
||||
pub fn expand_column(
|
||||
pub(crate) fn expand_column(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -58,7 +58,7 @@ pub fn expand_column(
|
|||
/// file!(): expands to the current filename */
|
||||
/// The source_file (`loc.file`) contains a bunch more information we could spit
|
||||
/// out if we wanted.
|
||||
pub fn expand_file(
|
||||
pub(crate) fn expand_file(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -78,7 +78,7 @@ pub fn expand_file(
|
|||
)))
|
||||
}
|
||||
|
||||
pub fn expand_stringify(
|
||||
pub(crate) fn expand_stringify(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -88,7 +88,7 @@ pub fn expand_stringify(
|
|||
ExpandResult::Ready(MacEager::expr(cx.expr_str(sp, Symbol::intern(&s))))
|
||||
}
|
||||
|
||||
pub fn expand_mod(
|
||||
pub(crate) fn expand_mod(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -104,7 +104,7 @@ pub fn expand_mod(
|
|||
/// include! : parse the given file as an expr
|
||||
/// This is generally a bad idea because it's going to behave
|
||||
/// unhygienically.
|
||||
pub fn expand_include<'cx>(
|
||||
pub(crate) fn expand_include<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -181,7 +181,7 @@ pub fn expand_include<'cx>(
|
|||
}
|
||||
|
||||
/// `include_str!`: read the given file, insert it as a literal string expr
|
||||
pub fn expand_include_str(
|
||||
pub(crate) fn expand_include_str(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
@ -210,7 +210,7 @@ pub fn expand_include_str(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn expand_include_bytes(
|
||||
pub(crate) fn expand_include_bytes(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
|
|||
use std::assert_matches::assert_matches;
|
||||
use std::iter;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use tracing::debug;
|
||||
|
||||
/// #[test_case] is used by custom test authors to mark tests
|
||||
/// When building for test, it needs to make the item public and gensym the name
|
||||
|
|
@ -20,7 +21,7 @@ use thin_vec::{thin_vec, ThinVec};
|
|||
///
|
||||
/// We mark item with an inert attribute "rustc_test_marker" which the test generation
|
||||
/// logic will pick up on.
|
||||
pub fn expand_test_case(
|
||||
pub(crate) fn expand_test_case(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
attr_sp: Span,
|
||||
meta_item: &ast::MetaItem,
|
||||
|
|
@ -73,7 +74,7 @@ pub fn expand_test_case(
|
|||
vec![ret]
|
||||
}
|
||||
|
||||
pub fn expand_test(
|
||||
pub(crate) fn expand_test(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
attr_sp: Span,
|
||||
meta_item: &ast::MetaItem,
|
||||
|
|
@ -84,7 +85,7 @@ pub fn expand_test(
|
|||
expand_test_or_bench(cx, attr_sp, item, false)
|
||||
}
|
||||
|
||||
pub fn expand_bench(
|
||||
pub(crate) fn expand_bench(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
attr_sp: Span,
|
||||
meta_item: &ast::MetaItem,
|
||||
|
|
@ -95,7 +96,7 @@ pub fn expand_bench(
|
|||
expand_test_or_bench(cx, attr_sp, item, true)
|
||||
}
|
||||
|
||||
pub fn expand_test_or_bench(
|
||||
pub(crate) fn expand_test_or_bench(
|
||||
cx: &ExtCtxt<'_>,
|
||||
attr_sp: Span,
|
||||
item: Annotatable,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult
|
|||
use rustc_span::symbol::kw;
|
||||
use rustc_span::Span;
|
||||
|
||||
pub fn expand_trace_macros(
|
||||
pub(crate) fn expand_trace_macros(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tt: TokenStream,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
use rustc_ast::{attr, AttrStyle, Attribute, MetaItem};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use crate::errors;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{self as ast, attr, ptr::P, token, AttrStyle, Attribute, MetaItem};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
|
||||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
|
||||
use rustc_expand::expand::AstFragment;
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_parse::{parser, validate_attr};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
|
||||
pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
|
||||
pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
|
||||
// All the built-in macro attributes are "words" at the moment.
|
||||
let template = AttributeTemplate { word: true, ..Default::default() };
|
||||
validate_attr::check_builtin_meta_item(
|
||||
|
|
@ -19,7 +24,7 @@ pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, na
|
|||
|
||||
/// Emit a warning if the item is annotated with the given attribute. This is used to diagnose when
|
||||
/// an attribute may have been mistakenly duplicated.
|
||||
pub fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
|
||||
pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
|
||||
let attrs: Option<&[Attribute]> = match item {
|
||||
Annotatable::Item(item) => Some(&item.attrs),
|
||||
Annotatable::TraitItem(item) => Some(&item.attrs),
|
||||
|
|
@ -46,3 +51,178 @@ pub fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `Ok` represents successfully retrieving the string literal at the correct
|
||||
/// position, e.g., `println("abc")`.
|
||||
type ExprToSpannedStringResult<'a> = Result<(Symbol, ast::StrStyle, Span), UnexpectedExprKind<'a>>;
|
||||
|
||||
/// - `Ok` is returned when the conversion to a string literal is unsuccessful,
|
||||
/// but another type of expression is obtained instead.
|
||||
/// - `Err` is returned when the conversion process fails.
|
||||
type UnexpectedExprKind<'a> = Result<(Diag<'a>, bool /* has_suggestions */), ErrorGuaranteed>;
|
||||
|
||||
/// Extracts a string literal from the macro expanded version of `expr`,
|
||||
/// returning a diagnostic error of `err_msg` if `expr` is not a string literal.
|
||||
/// The returned bool indicates whether an applicable suggestion has already been
|
||||
/// added to the diagnostic to avoid emitting multiple suggestions. `Err(Err(ErrorGuaranteed))`
|
||||
/// indicates that an ast error was encountered.
|
||||
// FIXME(Nilstrieb) Make this function setup translatable
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub(crate) fn expr_to_spanned_string<'a>(
|
||||
cx: &'a mut ExtCtxt<'_>,
|
||||
expr: P<ast::Expr>,
|
||||
err_msg: &'static str,
|
||||
) -> ExpandResult<ExprToSpannedStringResult<'a>, ()> {
|
||||
if !cx.force_mode
|
||||
&& let ast::ExprKind::MacCall(m) = &expr.kind
|
||||
&& cx.resolver.macro_accessible(cx.current_expansion.id, &m.path).is_err()
|
||||
{
|
||||
return ExpandResult::Retry(());
|
||||
}
|
||||
|
||||
// Perform eager expansion on the expression.
|
||||
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
||||
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
||||
|
||||
ExpandResult::Ready(Err(match expr.kind {
|
||||
ast::ExprKind::Lit(token_lit) => match ast::LitKind::from_token_lit(token_lit) {
|
||||
Ok(ast::LitKind::Str(s, style)) => {
|
||||
return ExpandResult::Ready(Ok((s, style, expr.span)));
|
||||
}
|
||||
Ok(ast::LitKind::ByteStr(..)) => {
|
||||
let mut err = cx.dcx().struct_span_err(expr.span, err_msg);
|
||||
let span = expr.span.shrink_to_lo();
|
||||
err.span_suggestion(
|
||||
span.with_hi(span.lo() + BytePos(1)),
|
||||
"consider removing the leading `b`",
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
Ok((err, true))
|
||||
}
|
||||
Ok(ast::LitKind::Err(guar)) => Err(guar),
|
||||
Err(err) => Err(report_lit_error(&cx.sess.psess, err, token_lit, expr.span)),
|
||||
_ => Ok((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
||||
},
|
||||
ast::ExprKind::Err(guar) => Err(guar),
|
||||
ast::ExprKind::Dummy => {
|
||||
cx.dcx().span_bug(expr.span, "tried to get a string literal from `ExprKind::Dummy`")
|
||||
}
|
||||
_ => Ok((cx.dcx().struct_span_err(expr.span, err_msg), false)),
|
||||
}))
|
||||
}
|
||||
|
||||
/// Extracts a string literal from the macro expanded version of `expr`,
|
||||
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
|
||||
/// compilation on error, merely emits a non-fatal error and returns `Err`.
|
||||
pub(crate) fn expr_to_string(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
expr: P<ast::Expr>,
|
||||
err_msg: &'static str,
|
||||
) -> ExpandResult<Result<(Symbol, ast::StrStyle), ErrorGuaranteed>, ()> {
|
||||
expr_to_spanned_string(cx, expr, err_msg).map(|res| {
|
||||
res.map_err(|err| match err {
|
||||
Ok((err, _)) => err.emit(),
|
||||
Err(guar) => guar,
|
||||
})
|
||||
.map(|(symbol, style, _)| (symbol, style))
|
||||
})
|
||||
}
|
||||
|
||||
/// Non-fatally assert that `tts` is empty. Note that this function
|
||||
/// returns even when `tts` is non-empty, macros that *need* to stop
|
||||
/// compilation should call `cx.diagnostic().abort_if_errors()`
|
||||
/// (this should be done as rarely as possible).
|
||||
pub(crate) fn check_zero_tts(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream, name: &str) {
|
||||
if !tts.is_empty() {
|
||||
cx.dcx().emit_err(errors::TakesNoArguments { span, name });
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse an expression. On error, emit it, advancing to `Eof`, and return `Err`.
|
||||
pub(crate) fn parse_expr(p: &mut parser::Parser<'_>) -> Result<P<ast::Expr>, ErrorGuaranteed> {
|
||||
let guar = match p.parse_expr() {
|
||||
Ok(expr) => return Ok(expr),
|
||||
Err(err) => err.emit(),
|
||||
};
|
||||
while p.token != token::Eof {
|
||||
p.bump();
|
||||
}
|
||||
Err(guar)
|
||||
}
|
||||
|
||||
/// Interpreting `tts` as a comma-separated sequence of expressions,
|
||||
/// expect exactly one string literal, or emit an error and return `Err`.
|
||||
pub(crate) fn get_single_str_from_tts(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
span: Span,
|
||||
tts: TokenStream,
|
||||
name: &str,
|
||||
) -> ExpandResult<Result<Symbol, ErrorGuaranteed>, ()> {
|
||||
get_single_str_spanned_from_tts(cx, span, tts, name).map(|res| res.map(|(s, _)| s))
|
||||
}
|
||||
|
||||
pub(crate) fn get_single_str_spanned_from_tts(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
span: Span,
|
||||
tts: TokenStream,
|
||||
name: &str,
|
||||
) -> ExpandResult<Result<(Symbol, Span), ErrorGuaranteed>, ()> {
|
||||
let mut p = cx.new_parser_from_tts(tts);
|
||||
if p.token == token::Eof {
|
||||
let guar = cx.dcx().emit_err(errors::OnlyOneArgument { span, name });
|
||||
return ExpandResult::Ready(Err(guar));
|
||||
}
|
||||
let ret = match parse_expr(&mut p) {
|
||||
Ok(ret) => ret,
|
||||
Err(guar) => return ExpandResult::Ready(Err(guar)),
|
||||
};
|
||||
let _ = p.eat(&token::Comma);
|
||||
|
||||
if p.token != token::Eof {
|
||||
cx.dcx().emit_err(errors::OnlyOneArgument { span, name });
|
||||
}
|
||||
expr_to_spanned_string(cx, ret, "argument must be a string literal").map(|res| {
|
||||
res.map_err(|err| match err {
|
||||
Ok((err, _)) => err.emit(),
|
||||
Err(guar) => guar,
|
||||
})
|
||||
.map(|(symbol, _style, span)| (symbol, span))
|
||||
})
|
||||
}
|
||||
|
||||
/// Extracts comma-separated expressions from `tts`.
|
||||
/// On error, emit it, and return `Err`.
|
||||
pub(crate) fn get_exprs_from_tts(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
tts: TokenStream,
|
||||
) -> ExpandResult<Result<Vec<P<ast::Expr>>, ErrorGuaranteed>, ()> {
|
||||
let mut p = cx.new_parser_from_tts(tts);
|
||||
let mut es = Vec::new();
|
||||
while p.token != token::Eof {
|
||||
let expr = match parse_expr(&mut p) {
|
||||
Ok(expr) => expr,
|
||||
Err(guar) => return ExpandResult::Ready(Err(guar)),
|
||||
};
|
||||
if !cx.force_mode
|
||||
&& let ast::ExprKind::MacCall(m) = &expr.kind
|
||||
&& cx.resolver.macro_accessible(cx.current_expansion.id, &m.path).is_err()
|
||||
{
|
||||
return ExpandResult::Retry(());
|
||||
}
|
||||
|
||||
// Perform eager expansion on the expression.
|
||||
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
||||
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
||||
|
||||
es.push(expr);
|
||||
if p.eat(&token::Comma) {
|
||||
continue;
|
||||
}
|
||||
if p.token != token::Eof {
|
||||
let guar = cx.dcx().emit_err(errors::ExpectedCommaInList { span: p.token.span });
|
||||
return ExpandResult::Ready(Err(guar));
|
||||
}
|
||||
}
|
||||
ExpandResult::Ready(Ok(es))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -420,7 +420,6 @@ pub fn panic(_msg: &'static str) -> ! {
|
|||
|
||||
macro_rules! panic_const {
|
||||
($($lang:ident = $message:expr,)+) => {
|
||||
#[cfg(not(bootstrap))]
|
||||
pub mod panic_const {
|
||||
use super::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -1223,7 +1223,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
|
|||
tcx,
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
iter::once(i8p),
|
||||
Ty::new_unit(tcx),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
rustc_hir::Unsafety::Unsafe,
|
||||
Abi::Rust,
|
||||
|
|
@ -1234,7 +1234,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
|
|||
tcx,
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[i8p, i8p].iter().cloned(),
|
||||
Ty::new_unit(tcx),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
rustc_hir::Unsafety::Unsafe,
|
||||
Abi::Rust,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
trusted_len,
|
||||
hash_raw_entry
|
||||
)]
|
||||
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
|
||||
#![allow(broken_intra_doc_links)]
|
||||
#![recursion_limit = "256"]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
|
|||
use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target};
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::CString;
|
||||
use std::iter;
|
||||
use std::ops::Deref;
|
||||
use std::ptr;
|
||||
|
|
@ -1709,7 +1710,8 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
|
|||
fn_name: &'ll Value,
|
||||
hash: &'ll Value,
|
||||
bitmap_bytes: &'ll Value,
|
||||
) -> &'ll Value {
|
||||
max_decision_depth: u32,
|
||||
) -> Vec<&'ll Value> {
|
||||
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);
|
||||
|
||||
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
|
||||
|
|
@ -1722,6 +1724,8 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
|
|||
let args = &[fn_name, hash, bitmap_bytes];
|
||||
let args = self.check_call("call", llty, llfn, args);
|
||||
|
||||
let mut cond_bitmaps = vec![];
|
||||
|
||||
unsafe {
|
||||
let _ = llvm::LLVMRustBuildCall(
|
||||
self.llbuilder,
|
||||
|
|
@ -1733,17 +1737,22 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
|
|||
0 as c_uint,
|
||||
);
|
||||
// Create condition bitmap named `mcdc.addr`.
|
||||
let mut bx = Builder::with_cx(self.cx);
|
||||
bx.position_at_start(llvm::LLVMGetFirstBasicBlock(self.llfn()));
|
||||
let cond_bitmap = {
|
||||
let alloca =
|
||||
llvm::LLVMBuildAlloca(bx.llbuilder, bx.cx.type_i32(), c"mcdc.addr".as_ptr());
|
||||
llvm::LLVMSetAlignment(alloca, 4);
|
||||
alloca
|
||||
};
|
||||
bx.store(self.const_i32(0), cond_bitmap, self.tcx().data_layout.i32_align.abi);
|
||||
cond_bitmap
|
||||
for i in 0..=max_decision_depth {
|
||||
let mut bx = Builder::with_cx(self.cx);
|
||||
bx.position_at_start(llvm::LLVMGetFirstBasicBlock(self.llfn()));
|
||||
|
||||
let name = CString::new(format!("mcdc.addr.{i}")).unwrap();
|
||||
let cond_bitmap = {
|
||||
let alloca =
|
||||
llvm::LLVMBuildAlloca(bx.llbuilder, bx.cx.type_i32(), name.as_ptr());
|
||||
llvm::LLVMSetAlignment(alloca, 4);
|
||||
alloca
|
||||
};
|
||||
bx.store(self.const_i32(0), cond_bitmap, self.tcx().data_layout.i32_align.abi);
|
||||
cond_bitmaps.push(cond_bitmap);
|
||||
}
|
||||
}
|
||||
cond_bitmaps
|
||||
}
|
||||
|
||||
pub(crate) fn mcdc_tvbitmap_update(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub struct CrateCoverageContext<'ll, 'tcx> {
|
|||
pub(crate) function_coverage_map:
|
||||
RefCell<FxIndexMap<Instance<'tcx>, FunctionCoverageCollector<'tcx>>>,
|
||||
pub(crate) pgo_func_name_var_map: RefCell<FxHashMap<Instance<'tcx>, &'ll llvm::Value>>,
|
||||
pub(crate) mcdc_condition_bitmap_map: RefCell<FxHashMap<Instance<'tcx>, &'ll llvm::Value>>,
|
||||
pub(crate) mcdc_condition_bitmap_map: RefCell<FxHashMap<Instance<'tcx>, Vec<&'ll llvm::Value>>>,
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> CrateCoverageContext<'ll, 'tcx> {
|
||||
|
|
@ -49,9 +49,20 @@ impl<'ll, 'tcx> CrateCoverageContext<'ll, 'tcx> {
|
|||
}
|
||||
|
||||
/// LLVM use a temp value to record evaluated mcdc test vector of each decision, which is called condition bitmap.
|
||||
/// This value is named `mcdc.addr` (same as clang) and is a 32-bit integer.
|
||||
fn try_get_mcdc_condition_bitmap(&self, instance: &Instance<'tcx>) -> Option<&'ll llvm::Value> {
|
||||
self.mcdc_condition_bitmap_map.borrow().get(instance).copied()
|
||||
/// In order to handle nested decisions, several condition bitmaps can be
|
||||
/// allocated for a function body.
|
||||
/// These values are named `mcdc.addr.{i}` and are a 32-bit integers.
|
||||
/// They respectively hold the condition bitmaps for decisions with a depth of `i`.
|
||||
fn try_get_mcdc_condition_bitmap(
|
||||
&self,
|
||||
instance: &Instance<'tcx>,
|
||||
decision_depth: u16,
|
||||
) -> Option<&'ll llvm::Value> {
|
||||
self.mcdc_condition_bitmap_map
|
||||
.borrow()
|
||||
.get(instance)
|
||||
.and_then(|bitmap_map| bitmap_map.get(decision_depth as usize))
|
||||
.copied() // Dereference Option<&&Value> to Option<&Value>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +154,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
|||
CoverageKind::ExpressionUsed { id } => {
|
||||
func_coverage.mark_expression_id_seen(id);
|
||||
}
|
||||
CoverageKind::CondBitmapUpdate { id, value, .. } => {
|
||||
CoverageKind::CondBitmapUpdate { id, value, decision_depth } => {
|
||||
drop(coverage_map);
|
||||
assert_ne!(
|
||||
id.as_u32(),
|
||||
|
|
@ -151,7 +162,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
|||
"ConditionId of evaluated conditions should never be zero"
|
||||
);
|
||||
let cond_bitmap = coverage_context
|
||||
.try_get_mcdc_condition_bitmap(&instance)
|
||||
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
|
||||
.expect("mcdc cond bitmap should have been allocated for updating");
|
||||
let cond_loc = bx.const_i32(id.as_u32() as i32 - 1);
|
||||
let bool_value = bx.const_bool(value);
|
||||
|
|
@ -159,10 +170,10 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
|||
let hash = bx.const_u64(function_coverage_info.function_source_hash);
|
||||
bx.mcdc_condbitmap_update(fn_name, hash, cond_loc, cond_bitmap, bool_value);
|
||||
}
|
||||
CoverageKind::TestVectorBitmapUpdate { bitmap_idx } => {
|
||||
CoverageKind::TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
|
||||
drop(coverage_map);
|
||||
let cond_bitmap = coverage_context
|
||||
.try_get_mcdc_condition_bitmap(&instance)
|
||||
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
|
||||
.expect("mcdc cond bitmap should have been allocated for merging into the global bitmap");
|
||||
let bitmap_bytes = bx.tcx().coverage_ids_info(instance.def).mcdc_bitmap_bytes;
|
||||
assert!(bitmap_idx < bitmap_bytes, "bitmap index of the decision out of range");
|
||||
|
|
@ -195,7 +206,8 @@ fn ensure_mcdc_parameters<'ll, 'tcx>(
|
|||
let fn_name = bx.get_pgo_func_name_var(instance);
|
||||
let hash = bx.const_u64(function_coverage_info.function_source_hash);
|
||||
let bitmap_bytes = bx.const_u32(function_coverage_info.mcdc_bitmap_bytes);
|
||||
let cond_bitmap = bx.mcdc_parameters(fn_name, hash, bitmap_bytes);
|
||||
let max_decision_depth = function_coverage_info.mcdc_max_decision_depth;
|
||||
let cond_bitmap = bx.mcdc_parameters(fn_name, hash, bitmap_bytes, max_decision_depth as u32);
|
||||
bx.coverage_context()
|
||||
.expect("already checked above")
|
||||
.mcdc_condition_bitmap_map
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use rustc_data_structures::{
|
|||
fx::FxHashMap,
|
||||
stable_hasher::{HashStable, StableHasher},
|
||||
};
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_middle::{
|
||||
bug,
|
||||
ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt},
|
||||
|
|
@ -23,6 +24,8 @@ use crate::{
|
|||
use super::{unknown_file_metadata, SmallVec, UNKNOWN_LINE_NUMBER};
|
||||
|
||||
mod private {
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
// This type cannot be constructed outside of this module because
|
||||
// it has a private field. We make use of this in order to prevent
|
||||
// `UniqueTypeId` from being constructed directly, without asserting
|
||||
|
|
|
|||
|
|
@ -984,7 +984,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
|
|||
tcx,
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[i8p],
|
||||
Ty::new_unit(tcx),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Unsafe,
|
||||
Abi::Rust,
|
||||
|
|
@ -995,7 +995,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
|
|||
tcx,
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[i8p, i8p],
|
||||
Ty::new_unit(tcx),
|
||||
tcx.types.unit,
|
||||
false,
|
||||
hir::Unsafety::Unsafe,
|
||||
Abi::Rust,
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@
|
|||
#![feature(let_chains)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
|
|||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc_metadata::find_native_static_library;
|
||||
use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use std::{env, mem, str};
|
|||
|
||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc_metadata::find_native_static_library;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols;
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
|
|||
use rustc_metadata::creader::MetadataLoader;
|
||||
use rustc_metadata::fs::METADATA_FILENAME;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::bug;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::sym;
|
||||
use rustc_target::abi::Endian;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE}
|
|||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::middle::exported_symbols::{
|
||||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue