Filter and test predicates using `normalize_and_test_predicates` for const-prop
Fixes #68264
Previously, I attempted to use
`substitute_normalize_and_test_predicates` to detect unsatisfiable
bounds. Unfortunately, since const-prop runs in a generic environment
(we don't have any of the function's generic parameters substituted),
this could lead to cycle errors when attempting to normalize predicates.
This check is replaced with a more precise check. We now only call
`normalize_and_test_predicates` on predicates that have the possibility
of being proved unsatisfiable - that is, predicates that don't depend
on anything local to the function (e.g. generic parameters). This
ensures that we don't hit cycle errors when we normalize said
predicates, while still ensuring that we detect unsatisfiable
predicates.
I haven't been able to come up with a minimization of the Diesel issue - however, I've verified that it compiles successfully.
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
- branch = rustc/9.0-2019-09-19
+ branch = rustc/9.0-2019-12-19
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
url = https://github.com/rust-embedded/book.git
"rustc-rayon-core",
"rustc_apfloat",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_hir",
"log",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_index",
dependencies = [
"log",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_parse",
"fmt_macros",
"log",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_feature",
"rustc_apfloat",
"rustc_codegen_utils",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_fs_util",
"rustc_hir",
"log",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_hir",
"memmap",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_hir",
"rustc",
"rustc_apfloat",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc",
"rustc_apfloat",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_index",
"bitflags",
"log",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"log",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_hir",
version = "0.0.0"
dependencies = [
"rustc",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_lint",
"log",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_span",
"rustc",
"rustc_ast_lowering",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_feature",
"log",
"num_cpus",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_fs_util",
"log",
"rustc",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_hir",
"rustc_index",
dependencies = [
"log",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_index",
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
-
-APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
-Copyright [yyyy] [name of copyright owner]
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
+ automake \
+ bison \
+ bzip2 \
+ flex \
+ help2man \
+ libtool-bin \
+ texinfo \
+ unzip \
+ wget \
+ xz-utils \
+ libncurses-dev \
+ gawk \
make \
file \
curl \
ca-certificates \
python2.7 \
+ python3 \
git \
cmake \
sudo \
apt-get update && \
apt-get install -y --no-install-recommends gcc-arm-embedded
+COPY scripts/rustbuild-setup.sh dist-various-1/build-riscv-toolchain.sh dist-various-1/riscv64-unknown-linux-gnu.config dist-various-1/crosstool-ng.sh /build/
+RUN ./crosstool-ng.sh
+
+# Crosstool-ng will refuse to build as root
+RUN sh ./rustbuild-setup.sh
+USER rustbuild
+
+RUN ./build-riscv-toolchain.sh
+
+USER root
+ENV PATH=/x-tools/riscv64-unknown-linux-gnu/bin:$PATH
+
COPY dist-various-1/build-rumprun.sh /build
RUN ./build-rumprun.sh
ENV TARGETS=$TARGETS,riscv32imac-unknown-none-elf
ENV TARGETS=$TARGETS,riscv64imac-unknown-none-elf
ENV TARGETS=$TARGETS,riscv64gc-unknown-none-elf
+ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-gnu
ENV TARGETS=$TARGETS,armebv7r-none-eabi
ENV TARGETS=$TARGETS,armebv7r-none-eabihf
ENV TARGETS=$TARGETS,armv7r-none-eabi
CC_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
AR_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \
CXX_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
+ CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
+ AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
+ CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++ \
CC_riscv32i_unknown_none_elf=false \
CC_riscv32imc_unknown_none_elf=false \
CC_riscv32imac_unknown_none_elf=false \
--- /dev/null
+#!/usr/bin/env bash
+
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ $@ &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir -p /tmp/build-riscv
+cp riscv64-unknown-linux-gnu.config /tmp/build-riscv/.config
+cd /tmp/build-riscv
+hide_output ct-ng build
+cd ..
+rm -rf build-riscv
--- /dev/null
+#!/bin/bash
+set -ex
+
+# Mirrored from https://github.com/crosstool-ng/crosstool-ng/archive/crosstool-ng-1.24.0.tar.gz
+url="https://ci-mirrors.rust-lang.org/rustc/crosstool-ng-1.24.0.tar.gz"
+curl -Lf $url | tar xzf -
+cd crosstool-ng-crosstool-ng-1.24.0
+./bootstrap
+./configure --prefix=/usr/local
+make -j$(nproc)
+make install
+cd ..
+rm -rf crosstool-ng-crosstool-ng-1.24.0
--- /dev/null
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_dtc=y
+CT_CONFIGURE_has_svn=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+CT_EXPERIMENTAL=y
+# CT_ALLOW_BUILD_AS_ROOT is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+# CT_USE_MIRROR is not set
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+CT_PATCH_BUNDLED=y
+# CT_PATCH_LOCAL is not set
+# CT_PATCH_BUNDLED_LOCAL is not set
+# CT_PATCH_LOCAL_BUNDLED is not set
+# CT_PATCH_NONE is not set
+CT_PATCH_ORDER="bundled"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+# CT_LOG_EXTRA is not set
+CT_LOG_ALL=y
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="ALL"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+# CT_ARCH_MICROBLAZE is not set
+# CT_ARCH_MIPS is not set
+# CT_ARCH_MOXIE is not set
+# CT_ARCH_MSP430 is not set
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+CT_ARCH_RISCV=y
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+# CT_ARCH_X86 is not set
+# CT_ARCH_XTENSA is not set
+CT_ARCH="riscv"
+CT_ARCH_CHOICE_KSYM="RISCV"
+CT_ARCH_TUNE=""
+CT_ARCH_RISCV_SHOW=y
+
+#
+# Options for riscv
+#
+CT_ARCH_RISCV_PKG_KSYM=""
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+# CT_DEMULTILIB is not set
+CT_ARCH_SUPPORTS_BOTH_MMU=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=64
+# CT_ARCH_32 is not set
+CT_ARCH_64=y
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_ABI=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_ARCH="rv64gc"
+CT_ARCH_ABI=""
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+# CT_NATIVE is not set
+CT_CROSS=y
+# CT_CROSS_NATIVE is not set
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+# CT_LINUX_SRC_DEVEL is not set
+# CT_LINUX_SRC_CUSTOM is not set
+CT_LINUX_PATCH_GLOBAL=y
+# CT_LINUX_PATCH_BUNDLED is not set
+# CT_LINUX_PATCH_LOCAL is not set
+# CT_LINUX_PATCH_BUNDLED_LOCAL is not set
+# CT_LINUX_PATCH_LOCAL_BUNDLED is not set
+# CT_LINUX_PATCH_NONE is not set
+CT_LINUX_PATCH_ORDER="global"
+CT_LINUX_V_4_20=y
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+# CT_LINUX_V_4_4 is not set
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+# CT_LINUX_V_3_2 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="4.20.8"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_later_than_4_8=y
+CT_LINUX_4_8_or_later=y
+CT_LINUX_later_than_3_7=y
+CT_LINUX_3_7_or_later=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_LINUX_REQUIRE_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+# CT_BINUTILS_SRC_DEVEL is not set
+# CT_BINUTILS_SRC_CUSTOM is not set
+CT_BINUTILS_PATCH_GLOBAL=y
+# CT_BINUTILS_PATCH_BUNDLED is not set
+# CT_BINUTILS_PATCH_LOCAL is not set
+# CT_BINUTILS_PATCH_BUNDLED_LOCAL is not set
+# CT_BINUTILS_PATCH_LOCAL_BUNDLED is not set
+# CT_BINUTILS_PATCH_NONE is not set
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_REQUIRE_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_MUSL is not set
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+# CT_GLIBC_SRC_DEVEL is not set
+# CT_GLIBC_SRC_CUSTOM is not set
+CT_GLIBC_PATCH_GLOBAL=y
+# CT_GLIBC_PATCH_BUNDLED is not set
+# CT_GLIBC_PATCH_LOCAL is not set
+# CT_GLIBC_PATCH_BUNDLED_LOCAL is not set
+# CT_GLIBC_PATCH_LOCAL_BUNDLED is not set
+# CT_GLIBC_PATCH_NONE is not set
+CT_GLIBC_PATCH_ORDER="global"
+CT_GLIBC_V_2_29=y
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.29"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_later=y
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_REQUIRE_2_29_or_later=y
+CT_GLIBC_later_than_2_27=y
+CT_GLIBC_2_27_or_later=y
+CT_GLIBC_later_than_2_26=y
+CT_GLIBC_2_26_or_later=y
+CT_GLIBC_later_than_2_25=y
+CT_GLIBC_2_25_or_later=y
+CT_GLIBC_later_than_2_24=y
+CT_GLIBC_2_24_or_later=y
+CT_GLIBC_later_than_2_23=y
+CT_GLIBC_2_23_or_later=y
+CT_GLIBC_later_than_2_20=y
+CT_GLIBC_2_20_or_later=y
+CT_GLIBC_later_than_2_17=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_BUILD_SSP=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_NO_SPARC_V8=y
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_ENABLE_FORTIFIED_BUILD is not set
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+CT_GLIBC_KERNEL_VERSION_NONE=y
+# CT_GLIBC_KERNEL_VERSION_AS_HEADERS is not set
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL=""
+CT_GLIBC_SSP_DEFAULT=y
+# CT_GLIBC_SSP_NO is not set
+# CT_GLIBC_SSP_YES is not set
+# CT_GLIBC_SSP_ALL is not set
+# CT_GLIBC_SSP_STRONG is not set
+# CT_GLIBC_ENABLE_WERROR is not set
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+# CT_GCC_USE_LINARO is not set
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+# CT_GCC_SRC_DEVEL is not set
+# CT_GCC_SRC_CUSTOM is not set
+CT_GCC_PATCH_GLOBAL=y
+# CT_GCC_PATCH_BUNDLED is not set
+# CT_GCC_PATCH_LOCAL is not set
+# CT_GCC_PATCH_BUNDLED_LOCAL is not set
+# CT_GCC_PATCH_LOCAL_BUNDLED is not set
+# CT_GCC_PATCH_NONE is not set
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_REQUIRE_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_REQUIRE_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_REQUIRE_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+# CT_CC_LANG_ADA is not set
+# CT_CC_LANG_OBJC is not set
+# CT_CC_LANG_OBJCXX is not set
+# CT_CC_LANG_GOLANG is not set
+CT_CC_LANG_OTHERS=""
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+CT_DEBUG_GDB=y
+CT_DEBUG_GDB_PKG_KSYM="GDB"
+CT_GDB_DIR_NAME="gdb"
+CT_GDB_USE_GNU=y
+CT_GDB_USE="GDB"
+CT_GDB_PKG_NAME="gdb"
+CT_GDB_SRC_RELEASE=y
+# CT_GDB_SRC_DEVEL is not set
+# CT_GDB_SRC_CUSTOM is not set
+CT_GDB_PATCH_GLOBAL=y
+# CT_GDB_PATCH_BUNDLED is not set
+# CT_GDB_PATCH_LOCAL is not set
+# CT_GDB_PATCH_BUNDLED_LOCAL is not set
+# CT_GDB_PATCH_LOCAL_BUNDLED is not set
+# CT_GDB_PATCH_NONE is not set
+CT_GDB_PATCH_ORDER="global"
+CT_GDB_V_8_2=y
+# CT_GDB_V_8_1 is not set
+# CT_GDB_V_8_0 is not set
+# CT_GDB_NO_VERSIONS is not set
+CT_GDB_VERSION="8.2.1"
+CT_GDB_MIRRORS="$(CT_Mirrors GNU gdb) $(CT_Mirrors sourceware gdb/releases)"
+CT_GDB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GDB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GDB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GDB_SIGNATURE_FORMAT=""
+CT_GDB_later_than_8_0=y
+CT_GDB_8_0_or_later=y
+CT_GDB_REQUIRE_8_0_or_later=y
+CT_GDB_later_than_7_12=y
+CT_GDB_7_12_or_later=y
+CT_GDB_later_than_7_2=y
+CT_GDB_7_2_or_later=y
+CT_GDB_later_than_7_0=y
+CT_GDB_7_0_or_later=y
+CT_GDB_CROSS=y
+# CT_GDB_CROSS_STATIC is not set
+# CT_GDB_CROSS_SIM is not set
+# CT_GDB_CROSS_PYTHON is not set
+CT_GDB_CROSS_EXTRA_CONFIG_ARRAY=""
+# CT_GDB_NATIVE is not set
+# CT_GDB_GDBSERVER is not set
+CT_GDB_HAS_PKGVERSION_BUGURL=y
+CT_GDB_HAS_PYTHON=y
+CT_GDB_INSTALL_GDBINIT=y
+CT_GDB_HAS_IPA_LIB=y
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+CT_COMP_LIBS_EXPAT=y
+CT_COMP_LIBS_EXPAT_PKG_KSYM="EXPAT"
+CT_EXPAT_DIR_NAME="expat"
+CT_EXPAT_PKG_NAME="expat"
+CT_EXPAT_SRC_RELEASE=y
+# CT_EXPAT_SRC_DEVEL is not set
+# CT_EXPAT_SRC_CUSTOM is not set
+CT_EXPAT_PATCH_GLOBAL=y
+# CT_EXPAT_PATCH_BUNDLED is not set
+# CT_EXPAT_PATCH_LOCAL is not set
+# CT_EXPAT_PATCH_BUNDLED_LOCAL is not set
+# CT_EXPAT_PATCH_LOCAL_BUNDLED is not set
+# CT_EXPAT_PATCH_NONE is not set
+CT_EXPAT_PATCH_ORDER="global"
+CT_EXPAT_V_2_2=y
+# CT_EXPAT_NO_VERSIONS is not set
+CT_EXPAT_VERSION="2.2.6"
+CT_EXPAT_MIRRORS="http://downloads.sourceforge.net/project/expat/expat/${CT_EXPAT_VERSION}"
+CT_EXPAT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_EXPAT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_EXPAT_ARCHIVE_FORMATS=".tar.bz2"
+CT_EXPAT_SIGNATURE_FORMAT=""
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+# CT_GETTEXT_SRC_DEVEL is not set
+# CT_GETTEXT_SRC_CUSTOM is not set
+CT_GETTEXT_PATCH_GLOBAL=y
+# CT_GETTEXT_PATCH_BUNDLED is not set
+# CT_GETTEXT_PATCH_LOCAL is not set
+# CT_GETTEXT_PATCH_BUNDLED_LOCAL is not set
+# CT_GETTEXT_PATCH_LOCAL_BUNDLED is not set
+# CT_GETTEXT_PATCH_NONE is not set
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+# CT_GMP_SRC_DEVEL is not set
+# CT_GMP_SRC_CUSTOM is not set
+CT_GMP_PATCH_GLOBAL=y
+# CT_GMP_PATCH_BUNDLED is not set
+# CT_GMP_PATCH_LOCAL is not set
+# CT_GMP_PATCH_BUNDLED_LOCAL is not set
+# CT_GMP_PATCH_LOCAL_BUNDLED is not set
+# CT_GMP_PATCH_NONE is not set
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+# CT_ISL_SRC_DEVEL is not set
+# CT_ISL_SRC_CUSTOM is not set
+CT_ISL_PATCH_GLOBAL=y
+# CT_ISL_PATCH_BUNDLED is not set
+# CT_ISL_PATCH_LOCAL is not set
+# CT_ISL_PATCH_BUNDLED_LOCAL is not set
+# CT_ISL_PATCH_LOCAL_BUNDLED is not set
+# CT_ISL_PATCH_NONE is not set
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="http://isl.gforge.inria.fr"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+# CT_LIBICONV_SRC_DEVEL is not set
+# CT_LIBICONV_SRC_CUSTOM is not set
+CT_LIBICONV_PATCH_GLOBAL=y
+# CT_LIBICONV_PATCH_BUNDLED is not set
+# CT_LIBICONV_PATCH_LOCAL is not set
+# CT_LIBICONV_PATCH_BUNDLED_LOCAL is not set
+# CT_LIBICONV_PATCH_LOCAL_BUNDLED is not set
+# CT_LIBICONV_PATCH_NONE is not set
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+# CT_MPC_SRC_DEVEL is not set
+# CT_MPC_SRC_CUSTOM is not set
+CT_MPC_PATCH_GLOBAL=y
+# CT_MPC_PATCH_BUNDLED is not set
+# CT_MPC_PATCH_LOCAL is not set
+# CT_MPC_PATCH_BUNDLED_LOCAL is not set
+# CT_MPC_PATCH_LOCAL_BUNDLED is not set
+# CT_MPC_PATCH_NONE is not set
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+# CT_MPFR_SRC_DEVEL is not set
+# CT_MPFR_SRC_CUSTOM is not set
+CT_MPFR_PATCH_GLOBAL=y
+# CT_MPFR_PATCH_BUNDLED is not set
+# CT_MPFR_PATCH_LOCAL is not set
+# CT_MPFR_PATCH_BUNDLED_LOCAL is not set
+# CT_MPFR_PATCH_LOCAL_BUNDLED is not set
+# CT_MPFR_PATCH_NONE is not set
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+# CT_NCURSES_SRC_DEVEL is not set
+# CT_NCURSES_SRC_CUSTOM is not set
+CT_NCURSES_PATCH_GLOBAL=y
+# CT_NCURSES_PATCH_BUNDLED is not set
+# CT_NCURSES_PATCH_LOCAL is not set
+# CT_NCURSES_PATCH_BUNDLED_LOCAL is not set
+# CT_NCURSES_PATCH_LOCAL_BUNDLED is not set
+# CT_NCURSES_PATCH_NONE is not set
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+# CT_NCURSES_NEW_ABI is not set
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+# CT_ZLIB_SRC_DEVEL is not set
+# CT_ZLIB_SRC_CUSTOM is not set
+CT_ZLIB_PATCH_GLOBAL=y
+# CT_ZLIB_PATCH_BUNDLED is not set
+# CT_ZLIB_PATCH_LOCAL is not set
+# CT_ZLIB_PATCH_BUNDLED_LOCAL is not set
+# CT_ZLIB_PATCH_LOCAL_BUNDLED is not set
+# CT_ZLIB_PATCH_NONE is not set
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_EXPAT_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_EXPAT=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
+
+#
+# Test suite
+#
+# CT_TEST_SUITE_GCC is not set
-Subproject commit b5c6babcdd4ce1fa90458b7827a5fde082e79e87
+Subproject commit 92baf7293dd2d418d2ac4b141b0faa822075d9f7
+++ /dev/null
-# `slice_patterns`
-
-The tracking issue for this feature is: [#62254]
-
-[#62254]: https://github.com/rust-lang/rust/issues/62254
-
-------------------------
-
-The `slice_patterns` feature gate lets you use `..` to indicate any number of
-elements inside a pattern matching a slice. This wildcard can only be used once
-for a given array. If there's an pattern before the `..`, the subslice will be
-matched against that pattern. For example:
-
-```rust
-#![feature(slice_patterns)]
-
-fn is_symmetric(list: &[u32]) -> bool {
- match list {
- &[] | &[_] => true,
- &[x, ref inside @ .., y] if x == y => is_symmetric(inside),
- &[..] => false,
- }
-}
-
-fn main() {
- let sym = &[0, 1, 4, 2, 4, 1, 0];
- assert!(is_symmetric(sym));
-
- let not_sym = &[0, 1, 7, 2, 4, 1, 0];
- assert!(!is_symmetric(not_sym));
-}
-```
use std::iter::repeat;
-use test::Bencher;
+use test::{black_box, Bencher};
#[bench]
fn bench_with_capacity(b: &mut Bencher) {
use std::fmt::Debug;
use std::iter::FromIterator;
use std::ops::Bound::{self, Excluded, Included, Unbounded};
+use std::ops::RangeBounds;
use std::rc::Rc;
use super::DeterministicRng;
assert_eq!(map.last_key_value(), None);
assert_eq!(map.keys().count(), 0);
assert_eq!(map.values().count(), 0);
+ assert_eq!(map.range(..).next(), None);
+ assert_eq!(map.range(..1).next(), None);
+ assert_eq!(map.range(1..).next(), None);
+ assert_eq!(map.range(1..=1).next(), None);
+ assert_eq!(map.range(1..2).next(), None);
assert_eq!(map.insert(1, 1), None);
// 1 key-value pair:
assert_eq!(map.last_key_value(), None);
assert_eq!(map.keys().count(), 0);
assert_eq!(map.values().count(), 0);
+ assert_eq!(map.range(..).next(), None);
+ assert_eq!(map.range(..1).next(), None);
+ assert_eq!(map.range(1..).next(), None);
+ assert_eq!(map.range(1..=1).next(), None);
+ assert_eq!(map.range(1..2).next(), None);
assert_eq!(map.remove(&1), None);
}
#[cfg(miri)]
let size = 200;
- // Forwards
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T)
#[cfg(miri)]
let size = 200;
- // Forwards
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T)
#[cfg(miri)]
let size = 200;
- // Forwards
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T)
test(size, map.into_iter());
}
-#[test]
-fn test_range_small() {
- let size = 5;
-
- // Forwards
- let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
-
- let mut j = 0;
- for ((&k, &v), i) in map.range(2..).zip(2..size) {
- assert_eq!(k, i);
- assert_eq!(v, i);
- j += 1;
- }
- assert_eq!(j, size - 2);
+fn range_keys(map: &BTreeMap<i32, i32>, range: impl RangeBounds<i32>) -> Vec<i32> {
+ map.range(range)
+ .map(|(&k, &v)| {
+ assert_eq!(k, v);
+ k
+ })
+ .collect()
}
#[test]
-fn test_range_inclusive() {
- let size = 500;
+fn test_range_small() {
+ let size = 4;
+
+ let map: BTreeMap<_, _> = (1..=size).map(|i| (i, i)).collect();
+ let all: Vec<_> = (1..=size).collect();
+ let (first, last) = (vec![all[0]], vec![all[size as usize - 1]]);
+
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(size))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(0), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(0), Included(size))), all);
+ assert_eq!(range_keys(&map, (Included(0), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Included(1), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(1), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(1), Included(size))), all);
+ assert_eq!(range_keys(&map, (Included(1), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Unbounded, Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Unbounded, Included(size))), all);
+ assert_eq!(range_keys(&map, ..), all);
+
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Included(0), Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Unbounded, Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(1))), first);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Included(0), Included(1))), first);
+ assert_eq!(range_keys(&map, (Included(1), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Included(1), Included(1))), first);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Unbounded, Included(1))), first);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Excluded(size + 1))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Included(size + 1))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Included(size))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Unbounded)), last);
+ assert_eq!(range_keys(&map, (Included(size), Excluded(size + 1))), last);
+ assert_eq!(range_keys(&map, (Included(size), Included(size + 1))), last);
+ assert_eq!(range_keys(&map, (Included(size), Included(size))), last);
+ assert_eq!(range_keys(&map, (Included(size), Unbounded)), last);
+ assert_eq!(range_keys(&map, (Excluded(size), Excluded(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(size), Included(size))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(size), Unbounded)), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Excluded(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Included(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Unbounded)), vec![]);
+
+ assert_eq!(range_keys(&map, ..3), vec![1, 2]);
+ assert_eq!(range_keys(&map, 3..), vec![3, 4]);
+ assert_eq!(range_keys(&map, 2..=3), vec![2, 3]);
+}
+
+#[test]
+fn test_range_depth_2() {
+ // Assuming that node.CAPACITY is 11, having 12 pairs implies a depth 2 tree
+ // with 2 leaves. Depending on details we don't want or need to rely upon,
+ // the single key at the root will be 6 or 7.
+
+ let map: BTreeMap<_, _> = (1..=12).map(|i| (i, i)).collect();
+ for &root in &[6, 7] {
+ assert_eq!(range_keys(&map, (Excluded(root), Excluded(root + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(root), Included(root + 1))), vec![root + 1]);
+ assert_eq!(range_keys(&map, (Included(root), Excluded(root + 1))), vec![root]);
+ assert_eq!(range_keys(&map, (Included(root), Included(root + 1))), vec![root, root + 1]);
+
+ assert_eq!(range_keys(&map, (Excluded(root - 1), Excluded(root))), vec![]);
+ assert_eq!(range_keys(&map, (Included(root - 1), Excluded(root))), vec![root - 1]);
+ assert_eq!(range_keys(&map, (Excluded(root - 1), Included(root))), vec![root]);
+ assert_eq!(range_keys(&map, (Included(root - 1), Included(root))), vec![root - 1, root]);
+ }
+}
+
+#[test]
+fn test_range_large() {
+ let size = 200;
- let map: BTreeMap<_, _> = (0..=size).map(|i| (i, i)).collect();
+ let map: BTreeMap<_, _> = (1..=size).map(|i| (i, i)).collect();
+ let all: Vec<_> = (1..=size).collect();
+ let (first, last) = (vec![all[0]], vec![all[size as usize - 1]]);
+
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(size))), all);
+ assert_eq!(range_keys(&map, (Excluded(0), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(0), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(0), Included(size))), all);
+ assert_eq!(range_keys(&map, (Included(0), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Included(1), Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(1), Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Included(1), Included(size))), all);
+ assert_eq!(range_keys(&map, (Included(1), Unbounded)), all);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(size + 1))), all);
+ assert_eq!(range_keys(&map, (Unbounded, Included(size + 1))), all);
+ assert_eq!(range_keys(&map, (Unbounded, Included(size))), all);
+ assert_eq!(range_keys(&map, ..), all);
+
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Included(0), Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(1))), vec![]);
+ assert_eq!(range_keys(&map, (Unbounded, Included(0))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(0), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Excluded(0), Included(1))), first);
+ assert_eq!(range_keys(&map, (Included(0), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Included(0), Included(1))), first);
+ assert_eq!(range_keys(&map, (Included(1), Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Included(1), Included(1))), first);
+ assert_eq!(range_keys(&map, (Unbounded, Excluded(2))), first);
+ assert_eq!(range_keys(&map, (Unbounded, Included(1))), first);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Excluded(size + 1))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Included(size + 1))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Included(size))), last);
+ assert_eq!(range_keys(&map, (Excluded(size - 1), Unbounded)), last);
+ assert_eq!(range_keys(&map, (Included(size), Excluded(size + 1))), last);
+ assert_eq!(range_keys(&map, (Included(size), Included(size + 1))), last);
+ assert_eq!(range_keys(&map, (Included(size), Included(size))), last);
+ assert_eq!(range_keys(&map, (Included(size), Unbounded)), last);
+ assert_eq!(range_keys(&map, (Excluded(size), Excluded(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(size), Included(size))), vec![]);
+ assert_eq!(range_keys(&map, (Excluded(size), Unbounded)), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Excluded(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Included(size + 1))), vec![]);
+ assert_eq!(range_keys(&map, (Included(size + 1), Unbounded)), vec![]);
fn check<'a, L, R>(lhs: L, rhs: R)
where
assert_eq!(lhs, rhs);
}
- check(map.range(size + 1..=size + 1), vec![]);
- check(map.range(size..=size), vec![(&size, &size)]);
- check(map.range(size..=size + 1), vec![(&size, &size)]);
- check(map.range(0..=0), vec![(&0, &0)]);
- check(map.range(0..=size - 1), map.range(..size));
- check(map.range(-1..=-1), vec![]);
- check(map.range(-1..=size), map.range(..));
- check(map.range(..=size), map.range(..));
- check(map.range(..=200), map.range(..201));
+ check(map.range(..=100), map.range(..101));
check(map.range(5..=8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
- check(map.range(-1..=0), vec![(&0, &0)]);
- check(map.range(-1..=2), vec![(&0, &0), (&1, &1), (&2, &2)]);
+ check(map.range(-1..=2), vec![(&1, &1), (&2, &2)]);
}
#[test]
extern crate alloc;
use rustc_data_structures::cold_path;
-use rustc_data_structures::sync::MTLock;
use smallvec::SmallVec;
use std::cell::{Cell, RefCell};
}
impl<T> TypedArena<T> {
- pub fn in_arena(&self, ptr: *const T) -> bool {
- let ptr = ptr as *const T as *mut T;
-
- self.chunks.borrow().iter().any(|chunk| chunk.start() <= ptr && ptr < chunk.end())
- }
/// Allocates an object in the `TypedArena`, returning a reference to it.
#[inline]
pub fn alloc(&self, object: T) -> &mut T {
}
impl DroplessArena {
- pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
- let ptr = ptr as *const u8 as *mut u8;
-
- self.chunks.borrow().iter().any(|chunk| chunk.start() <= ptr && ptr < chunk.end())
- }
-
#[inline]
fn align(&self, align: usize) {
let final_address = ((self.ptr.get() as usize) + align - 1) & !(align - 1);
}
}
-#[derive(Default)]
-// FIXME(@Zoxc): this type is entirely unused in rustc
-pub struct SyncTypedArena<T> {
- lock: MTLock<TypedArena<T>>,
-}
-
-impl<T> SyncTypedArena<T> {
- #[inline(always)]
- pub fn alloc(&self, object: T) -> &mut T {
- // Extend the lifetime of the result since it's limited to the lock guard
- unsafe { &mut *(self.lock.lock().alloc(object) as *mut T) }
- }
-
- #[inline(always)]
- pub fn alloc_slice(&self, slice: &[T]) -> &mut [T]
- where
- T: Copy,
- {
- // Extend the lifetime of the result since it's limited to the lock guard
- unsafe { &mut *(self.lock.lock().alloc_slice(slice) as *mut [T]) }
- }
-
- #[inline(always)]
- pub fn clear(&mut self) {
- self.lock.get_mut().clear();
- }
-}
-
-#[derive(Default)]
-pub struct SyncDroplessArena {
- lock: MTLock<DroplessArena>,
-}
-
-impl SyncDroplessArena {
- #[inline(always)]
- pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
- self.lock.lock().in_arena(ptr)
- }
-
- #[inline(always)]
- pub fn alloc_raw(&self, bytes: usize, align: usize) -> &mut [u8] {
- // Extend the lifetime of the result since it's limited to the lock guard
- unsafe { &mut *(self.lock.lock().alloc_raw(bytes, align) as *mut [u8]) }
- }
-
- #[inline(always)]
- pub fn alloc<T>(&self, object: T) -> &mut T {
- // Extend the lifetime of the result since it's limited to the lock guard
- unsafe { &mut *(self.lock.lock().alloc(object) as *mut T) }
- }
-
- #[inline(always)]
- pub fn alloc_slice<T>(&self, slice: &[T]) -> &mut [T]
- where
- T: Copy,
- {
- // Extend the lifetime of the result since it's limited to the lock guard
- unsafe { &mut *(self.lock.lock().alloc_slice(slice) as *mut [T]) }
- }
-}
-
#[cfg(test)]
mod tests;
///
/// This is intended for diagnostic use. The exact contents and format of the
/// string are not specified, other than being a best-effort description of the
-/// type. For example, `type_name_of::<Option<String>>(None)` could return
+/// type. For example, `type_name_of_val::<Option<String>>(None)` could return
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
/// `"foobar"`. In addition, the output may change between versions of the
/// compiler.
///
+/// This function does not resolve trait objects,
+/// meaning that `type_name_of_val(&7u32 as &dyn Debug)`
+/// may return `"dyn Debug"`, but not `"u32"`.
+///
/// The type name should not be considered a unique identifier of a type;
/// multiple types may share the same type name.
///
//! ```
//!
-// ignore-tidy-undocumented-unsafe
-
#![stable(feature = "rust1", since = "1.0.0")]
use crate::cmp::Ordering;
if ptr::eq(self, other) {
return;
}
+ // SAFETY: This can be risky if called from separate threads, but `Cell`
+ // is `!Sync` so this won't happen. This also won't invalidate any
+ // pointers since `Cell` makes sure nothing else will be pointing into
+ // either of these `Cell`s.
unsafe {
ptr::swap(self.value.get(), other.value.get());
}
/// ```
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn replace(&self, val: T) -> T {
+ // SAFETY: This can cause data races if called from a separate thread,
+ // but `Cell` is `!Sync` so this won't happen.
mem::replace(unsafe { &mut *self.value.get() }, val)
}
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self) -> T {
+ // SAFETY: This can cause data races if called from a separate thread,
+ // but `Cell` is `!Sync` so this won't happen.
unsafe { *self.value.get() }
}
#[inline]
#[stable(feature = "cell_get_mut", since = "1.11.0")]
pub fn get_mut(&mut self) -> &mut T {
+ // SAFETY: This can cause data races if called from a separate thread,
+ // but `Cell` is `!Sync` so this won't happen, and `&mut` guarantees
+ // unique access.
unsafe { &mut *self.value.get() }
}
#[inline]
#[stable(feature = "as_cell", since = "1.37.0")]
pub fn from_mut(t: &mut T) -> &Cell<T> {
+ // SAFETY: `&mut` ensures unique access.
unsafe { &*(t as *mut T as *const Cell<T>) }
}
}
/// ```
#[stable(feature = "as_cell", since = "1.37.0")]
pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
+ // SAFETY: `Cell<T>` has the same memory layout as `T`.
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
}
}
#[inline]
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError> {
match BorrowRef::new(&self.borrow) {
+ // SAFETY: `BorrowRef` ensures that there is only immutable access
+ // to the value while borrowed.
Some(b) => Ok(Ref { value: unsafe { &*self.value.get() }, borrow: b }),
None => Err(BorrowError { _private: () }),
}
#[inline]
pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError> {
match BorrowRefMut::new(&self.borrow) {
+ // SAFETY: `BorrowRef` guarantees unique access.
Some(b) => Ok(RefMut { value: unsafe { &mut *self.value.get() }, borrow: b }),
None => Err(BorrowMutError { _private: () }),
}
#[inline]
#[stable(feature = "cell_get_mut", since = "1.11.0")]
pub fn get_mut(&mut self) -> &mut T {
+ // SAFETY: `&mut` guarantees unique access.
unsafe { &mut *self.value.get() }
}
self
}
+ /// Marks the struct as non-exhaustive, indicating to the reader that there are some other
+ /// fields that are not shown in the debug representation.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # #![feature(debug_non_exhaustive)]
+ /// use std::fmt;
+ ///
+ /// struct Bar {
+ /// bar: i32,
+ /// hidden: f32,
+ /// }
+ ///
+ /// impl fmt::Debug for Bar {
+ /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ /// fmt.debug_struct("Bar")
+ /// .field("bar", &self.bar)
+ /// .finish_non_exhaustive() // Show that some other field(s) exist.
+ /// }
+ /// }
+ ///
+ /// assert_eq!(
+ /// format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
+ /// "Bar { bar: 10, .. }",
+ /// );
+ /// ```
+ #[unstable(feature = "debug_non_exhaustive", issue = "67364")]
+ pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
+ self.result = self.result.and_then(|_| {
+ // Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).
+ if self.is_pretty() {
+ if !self.has_fields {
+ self.fmt.write_str(" {\n")?;
+ }
+ let mut slot = None;
+ let mut state = Default::default();
+ let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
+ writer.write_str("..\n")?;
+ } else {
+ if self.has_fields {
+ self.fmt.write_str(", ..")?;
+ } else {
+ self.fmt.write_str(" { ..")?;
+ }
+ }
+ if self.is_pretty() {
+ self.fmt.write_str("}")?
+ } else {
+ self.fmt.write_str(" }")?;
+ }
+ Ok(())
+ });
+ self.result
+ }
+
/// Finishes output and returns any error encountered.
///
/// # Examples
use crate::num::flt2dec;
use crate::ops::Deref;
use crate::result;
-use crate::slice;
use crate::str;
mod builders;
precision: Option<usize>,
buf: &'a mut (dyn Write + 'a),
- curarg: slice::Iter<'a, ArgumentV1<'a>>,
- args: &'a [ArgumentV1<'a>],
}
// NB. Argument is essentially an optimized partially applied formatting function,
buf: output,
align: rt::v1::Alignment::Unknown,
fill: ' ',
- args: args.args,
- curarg: args.args.iter(),
};
let mut idx = 0;
// a string piece.
for (arg, piece) in fmt.iter().zip(args.pieces.iter()) {
formatter.buf.write_str(*piece)?;
- formatter.run(arg)?;
+ run(&mut formatter, arg, &args.args)?;
idx += 1;
}
}
Ok(())
}
+fn run(fmt: &mut Formatter<'_>, arg: &rt::v1::Argument, args: &[ArgumentV1<'_>]) -> Result {
+ fmt.fill = arg.format.fill;
+ fmt.align = arg.format.align;
+ fmt.flags = arg.format.flags;
+ fmt.width = getcount(args, &arg.format.width);
+ fmt.precision = getcount(args, &arg.format.precision);
+
+ // Extract the correct argument
+ let value = {
+ #[cfg(bootstrap)]
+ {
+ match arg.position {
+ rt::v1::Position::At(i) => args[i],
+ }
+ }
+ #[cfg(not(bootstrap))]
+ {
+ args[arg.position]
+ }
+ };
+
+ // Then actually do some printing
+ (value.formatter)(value.value, fmt)
+}
+
+fn getcount(args: &[ArgumentV1<'_>], cnt: &rt::v1::Count) -> Option<usize> {
+ match *cnt {
+ rt::v1::Count::Is(n) => Some(n),
+ rt::v1::Count::Implied => None,
+ rt::v1::Count::Param(i) => args[i].as_usize(),
+ }
+}
+
/// Padding after the end of something. Returned by `Formatter::padding`.
#[must_use = "don't forget to write the post padding"]
struct PostPadding {
align: self.align,
width: self.width,
precision: self.precision,
-
- // These only exist in the struct for the `run` method,
- // which won’t be used together with this method.
- curarg: self.curarg.clone(),
- args: self.args,
- }
- }
-
- // First up is the collection of functions used to execute a format string
- // at runtime. This consumes all of the compile-time statics generated by
- // the format! syntax extension.
- fn run(&mut self, arg: &rt::v1::Argument) -> Result {
- // Fill in the format parameters into the formatter
- self.fill = arg.format.fill;
- self.align = arg.format.align;
- self.flags = arg.format.flags;
- self.width = self.getcount(&arg.format.width);
- self.precision = self.getcount(&arg.format.precision);
-
- // Extract the correct argument
- let value = match arg.position {
- rt::v1::Position::Next => *self.curarg.next().unwrap(),
- rt::v1::Position::At(i) => self.args[i],
- };
-
- // Then actually do some printing
- (value.formatter)(value.value, self)
- }
-
- fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
- match *cnt {
- rt::v1::Count::Is(n) => Some(n),
- rt::v1::Count::Implied => None,
- rt::v1::Count::Param(i) => self.args[i].as_usize(),
- rt::v1::Count::NextParam => self.curarg.next()?.as_usize(),
}
}
#[derive(Copy, Clone)]
pub struct Argument {
+ #[cfg(bootstrap)]
pub position: Position,
+ #[cfg(not(bootstrap))]
+ pub position: usize,
pub format: FormatSpec,
}
pub enum Count {
Is(usize),
Param(usize),
- NextParam,
Implied,
}
+#[cfg(bootstrap)]
#[derive(Copy, Clone)]
pub enum Position {
- Next,
At(usize),
}
#[stable(feature = "iter_empty", since = "1.2.0")]
pub struct Empty<T>(marker::PhantomData<T>);
+#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
+unsafe impl<T> Send for Empty<T> {}
+#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
+unsafe impl<T> Sync for Empty<T> {}
+
#[stable(feature = "core_impl_debug", since = "1.9.0")]
impl<T> fmt::Debug for Empty<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#[prelude_import]
#[allow(unused)]
/// i.e., you do not usually have to worry about such issues unless you call `drop_in_place`
/// manually.
#[stable(feature = "drop_in_place", since = "1.8.0")]
-#[inline(always)]
-pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
- real_drop_in_place(&mut *to_drop)
-}
-
-// The real `drop_in_place` -- the one that gets called implicitly when variables go
-// out of scope -- should have a safe reference and not a raw pointer as argument
-// type. When we drop a local variable, we access it with a pointer that behaves
-// like a safe reference; transmuting that to a raw pointer does not mean we can
-// actually access it with raw pointers.
#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
-unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
+pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.
- real_drop_in_place(to_drop)
+ drop_in_place(to_drop)
}
/// Creates a null raw pointer.
use crate::mem;
use crate::str as core_str;
-// ignore-tidy-undocumented-unsafe
-
/// Lossy UTF-8 string.
#[unstable(feature = "str_internals", issue = "none")]
pub struct Utf8Lossy {
}
pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy {
+ // SAFETY: Both use the same memory layout, and UTF-8 correctness isn't required.
unsafe { mem::transmute(bytes) }
}
while i < self.source.len() {
let i_ = i;
+ // SAFETY: `i` starts at `0`, is less than `self.source.len()`, and
+ // only increases, so `0 <= i < self.source.len()`.
let byte = unsafe { *self.source.get_unchecked(i) };
i += 1;
macro_rules! error {
() => {{
+ // SAFETY: We have checked up to `i` that source is valid UTF-8.
unsafe {
let r = Utf8LossyChunk {
valid: core_str::from_utf8_unchecked(&self.source[0..i_]),
}
let r = Utf8LossyChunk {
+ // SAFETY: We have checked that the entire source is valid UTF-8.
valid: unsafe { core_str::from_utf8_unchecked(self.source) },
broken: &[],
};
// ignore-tidy-filelength
-// ignore-tidy-undocumented-unsafe
//! String manipulation.
//!
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
run_utf8_validation(v)?;
+ // SAFETY: Just ran validation.
Ok(unsafe { from_utf8_unchecked(v) })
}
#[stable(feature = "str_mut_extras", since = "1.20.0")]
pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
run_utf8_validation(v)?;
+ // SAFETY: Just ran validation.
Ok(unsafe { from_utf8_unchecked_mut(v) })
}
#[inline]
fn next(&mut self) -> Option<char> {
next_code_point(&mut self.iter).map(|ch| {
- // str invariant says `ch` is a valid Unicode Scalar Value
+ // SAFETY: `str` invariant says `ch` is a valid Unicode Scalar Value.
unsafe { char::from_u32_unchecked(ch) }
})
}
#[inline]
fn next_back(&mut self) -> Option<char> {
next_code_point_reverse(&mut self.iter).map(|ch| {
- // str invariant says `ch` is a valid Unicode Scalar Value
+ // SAFETY: `str` invariant says `ch` is a valid Unicode Scalar Value.
unsafe { char::from_u32_unchecked(ch) }
})
}
#[stable(feature = "iter_to_slice", since = "1.4.0")]
#[inline]
pub fn as_str(&self) -> &'a str {
+ // SAFETY: `Chars` is only made from a str, which guarantees the iter is valid UTF-8.
unsafe { from_utf8_unchecked(self.iter.as_slice()) }
}
}
fn get_end(&mut self) -> Option<&'a str> {
if !self.finished && (self.allow_trailing_empty || self.end - self.start > 0) {
self.finished = true;
+ // SAFETY: `self.start` and `self.end` always lie on unicode boundaries.
unsafe {
let string = self.matcher.haystack().get_unchecked(self.start..self.end);
Some(string)
let haystack = self.matcher.haystack();
match self.matcher.next_match() {
+ // SAFETY: `Searcher` guarantees that `a` and `b` lie on unicode boundaries.
Some((a, b)) => unsafe {
let elt = haystack.get_unchecked(self.start..a);
self.start = b;
let haystack = self.matcher.haystack();
match self.matcher.next_match_back() {
+ // SAFETY: `Searcher` guarantees that `a` and `b` lie on unicode boundaries.
Some((a, b)) => unsafe {
let elt = haystack.get_unchecked(b..self.end);
self.end = a;
Some(elt)
},
+ // SAFETY: `self.start` and `self.end` always lie on unicode boundaries.
None => unsafe {
self.finished = true;
Some(haystack.get_unchecked(self.start..self.end))
fn next(&mut self) -> Option<(usize, &'a str)> {
self.0
.next_match()
+ // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries.
.map(|(start, end)| unsafe { (start, self.0.haystack().get_unchecked(start..end)) })
}
{
self.0
.next_match_back()
+ // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries.
.map(|(start, end)| unsafe { (start, self.0.haystack().get_unchecked(start..end)) })
}
}
impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> {
#[inline]
fn next(&mut self) -> Option<&'a str> {
+ // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries.
self.0.next_match().map(|(a, b)| unsafe {
// Indices are known to be on utf8 boundaries
self.0.haystack().get_unchecked(a..b)
where
P::Searcher: ReverseSearcher<'a>,
{
+ // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries.
self.0.next_match_back().map(|(a, b)| unsafe {
// Indices are known to be on utf8 boundaries
self.0.haystack().get_unchecked(a..b)
if align != usize::max_value() && align.wrapping_sub(index) % usize_bytes == 0 {
let ptr = v.as_ptr();
while index < blocks_end {
+ // SAFETY: since `align - index` and `ascii_block_size` are
+ // multiples of `usize_bytes`, `block = ptr.add(index)` is
+ // always aligned with a `usize` so it's safe to dereference
+ // both `block` and `block.offset(1)`.
unsafe {
let block = ptr.add(index) as *const usize;
// break if there is a nonascii byte
&& slice.is_char_boundary(self.start)
&& slice.is_char_boundary(self.end)
{
+ // SAFETY: just checked that `start` and `end` are on a char boundary.
Some(unsafe { self.get_unchecked(slice) })
} else {
None
&& slice.is_char_boundary(self.start)
&& slice.is_char_boundary(self.end)
{
+ // SAFETY: just checked that `start` and `end` are on a char boundary.
Some(unsafe { self.get_unchecked_mut(slice) })
} else {
None
&& slice.is_char_boundary(self.start)
&& slice.is_char_boundary(self.end)
{
+ // SAFETY: just checked that `start` and `end` are on a char boundary.
unsafe { self.get_unchecked_mut(slice) }
} else {
super::slice_error_fail(slice, self.start, self.end)
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
if slice.is_char_boundary(self.end) {
+ // SAFETY: just checked that `end` is on a char boundary.
Some(unsafe { self.get_unchecked(slice) })
} else {
None
#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
if slice.is_char_boundary(self.end) {
+ // SAFETY: just checked that `end` is on a char boundary.
Some(unsafe { self.get_unchecked_mut(slice) })
} else {
None
}
#[inline]
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
- // is_char_boundary checks that the index is in [0, .len()]
if slice.is_char_boundary(self.end) {
+ // SAFETY: just checked that `end` is on a char boundary.
unsafe { self.get_unchecked_mut(slice) }
} else {
super::slice_error_fail(slice, 0, self.end)
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
if slice.is_char_boundary(self.start) {
+ // SAFETY: just checked that `start` is on a char boundary.
Some(unsafe { self.get_unchecked(slice) })
} else {
None
#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
if slice.is_char_boundary(self.start) {
+ // SAFETY: just checked that `start` is on a char boundary.
Some(unsafe { self.get_unchecked_mut(slice) })
} else {
None
}
#[inline]
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
- // is_char_boundary checks that the index is in [0, .len()]
if slice.is_char_boundary(self.start) {
+ // SAFETY: just checked that `start` is on a char boundary.
unsafe { self.get_unchecked_mut(slice) }
} else {
super::slice_error_fail(slice, self.start, slice.len())
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "str_as_bytes", since = "1.32.0")]
#[inline(always)]
- // SAFETY: const sound because we transmute two types with the same layout
#[allow(unused_attributes)]
#[allow_internal_unstable(const_fn_union)]
pub const fn as_bytes(&self) -> &[u8] {
str: &'a str,
slice: &'a [u8],
}
+ // SAFETY: const sound because we transmute two types with the same layout
unsafe { Slices { str: self }.slice }
}
pub fn split_at(&self, mid: usize) -> (&str, &str) {
// is_char_boundary checks that the index is in [0, .len()]
if self.is_char_boundary(mid) {
+ // SAFETY: just checked that `mid` is on a char boundary.
unsafe { (self.get_unchecked(0..mid), self.get_unchecked(mid..self.len())) }
} else {
slice_error_fail(self, 0, mid)
if self.is_char_boundary(mid) {
let len = self.len();
let ptr = self.as_mut_ptr();
+ // SAFETY: just checked that `mid` is on a char boundary.
unsafe {
(
from_utf8_unchecked_mut(slice::from_raw_parts_mut(ptr, mid)),
if let Some((_, b)) = matcher.next_reject_back() {
j = b;
}
- unsafe {
- // Searcher is known to return valid indices
- self.get_unchecked(i..j)
- }
+ // SAFETY: `Searcher` is known to return valid indices.
+ unsafe { self.get_unchecked(i..j) }
}
/// Returns a string slice with all prefixes that match a pattern
if let Some((a, _)) = matcher.next_reject() {
i = a;
}
- unsafe {
- // Searcher is known to return valid indices
- self.get_unchecked(i..self.len())
- }
+ // SAFETY: `Searcher` is known to return valid indices.
+ unsafe { self.get_unchecked(i..self.len()) }
}
/// Returns a string slice with the prefix removed.
"The first search step from Searcher \
must include the first character"
);
- unsafe {
- // Searcher is known to return valid indices.
- Some(self.get_unchecked(len..))
- }
+ // SAFETY: `Searcher` is known to return valid indices.
+ unsafe { Some(self.get_unchecked(len..)) }
} else {
None
}
"The first search step from ReverseSearcher \
must include the last character"
);
- unsafe {
- // Searcher is known to return valid indices.
- Some(self.get_unchecked(..start))
- }
+ // SAFETY: `Searcher` is known to return valid indices.
+ unsafe { Some(self.get_unchecked(..start)) }
} else {
None
}
if let Some((_, b)) = matcher.next_reject_back() {
j = b;
}
- unsafe {
- // Searcher is known to return valid indices
- self.get_unchecked(0..j)
- }
+ // SAFETY: `Searcher` is known to return valid indices.
+ unsafe { self.get_unchecked(0..j) }
}
/// Returns a string slice with all prefixes that match a pattern
/// ```
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
pub fn make_ascii_uppercase(&mut self) {
+ // SAFETY: safe because we transmute two types with the same layout.
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_uppercase()
}
/// ```
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
pub fn make_ascii_lowercase(&mut self) {
+ // SAFETY: safe because we transmute two types with the same layout.
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_lowercase()
}
impl Default for &mut str {
/// Creates an empty mutable str
fn default() -> Self {
+ // SAFETY: The empty string is valid UTF-8.
unsafe { from_utf8_unchecked_mut(&mut []) }
}
}
#[derive(Clone)]
struct UnsafeBytesToStr impl<'a> Fn = |bytes: &'a [u8]| -> &'a str {
+ // SAFETY: not safe
unsafe { from_utf8_unchecked(bytes) }
};
}
//! For more details, see the traits [`Pattern`], [`Searcher`],
//! [`ReverseSearcher`], and [`DoubleEndedSearcher`].
-// ignore-tidy-undocumented-unsafe
-
#![unstable(
feature = "pattern",
reason = "API not fully fleshed out and ready to be stabilized",
#[inline]
fn next(&mut self) -> SearchStep {
let old_finger = self.finger;
+ // SAFETY: 1-4 guarantee safety of `get_unchecked`
+ // 1. `self.finger` and `self.finger_back` are kept on unicode boundaries
+ // (this is invariant)
+ // 2. `self.finger >= 0` since it starts at 0 and only increases
+ // 3. `self.finger < self.finger_back` because otherwise the char `iter`
+ // would return `SearchStep::Done`
+ // 4. `self.finger` comes before the end of the haystack because `self.finger_back`
+ // starts at the end and only decreases
let slice = unsafe { self.haystack.get_unchecked(old_finger..self.finger_back) };
let mut iter = slice.chars();
let old_len = iter.iter.len();
// get the haystack after the last character found
let bytes = self.haystack.as_bytes().get(self.finger..self.finger_back)?;
// the last byte of the utf8 encoded needle
+ // SAFETY: we have an invariant that `utf8_size < 5`
let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
if let Some(index) = memchr::memchr(last_byte, bytes) {
// The new finger is the index of the byte we found,
#[inline]
fn next_back(&mut self) -> SearchStep {
let old_finger = self.finger_back;
+ // SAFETY: see the comment for next() above
let slice = unsafe { self.haystack.get_unchecked(self.finger..old_finger) };
let mut iter = slice.chars();
let old_len = iter.iter.len();
return None;
};
// the last byte of the utf8 encoded needle
+ // SAFETY: we have an invariant that `utf8_size < 5`
let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
if let Some(index) = memchr::memrchr(last_byte, bytes) {
// we searched a slice that was offset by self.finger,
//! println!("live threads: {}", old_thread_count + 1);
//! ```
-// ignore-tidy-undocumented-unsafe
-
#![stable(feature = "rust1", since = "1.0.0")]
#![cfg_attr(not(target_has_atomic_load_store = "8"), allow(dead_code))]
#![cfg_attr(not(target_has_atomic_load_store = "8"), allow(unused_imports))]
#[inline]
#[stable(feature = "atomic_access", since = "1.15.0")]
pub fn get_mut(&mut self) -> &mut bool {
+ // SAFETY: the mutable reference guarantees unique ownership.
unsafe { &mut *(self.v.get() as *mut bool) }
}
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn load(&self, order: Ordering) -> bool {
+ // SAFETY: any data races are prevented by atomic intrinsics and the raw
+ // pointer passed in is valid because we got it from a reference.
unsafe { atomic_load(self.v.get(), order) != 0 }
}
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn store(&self, val: bool, order: Ordering) {
+ // SAFETY: any data races are prevented by atomic intrinsics and the raw
+ // pointer passed in is valid because we got it from a reference.
unsafe {
atomic_store(self.v.get(), val as u8, order);
}
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "8")]
pub fn swap(&self, val: bool, order: Ordering) -> bool {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_swap(self.v.get(), val as u8, order) != 0 }
}
success: Ordering,
failure: Ordering,
) -> Result<bool, bool> {
+ // SAFETY: data races are prevented by atomic intrinsics.
match unsafe {
atomic_compare_exchange(self.v.get(), current as u8, new as u8, success, failure)
} {
success: Ordering,
failure: Ordering,
) -> Result<bool, bool> {
+ // SAFETY: data races are prevented by atomic intrinsics.
match unsafe {
atomic_compare_exchange_weak(self.v.get(), current as u8, new as u8, success, failure)
} {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "8")]
pub fn fetch_and(&self, val: bool, order: Ordering) -> bool {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_and(self.v.get(), val as u8, order) != 0 }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "8")]
pub fn fetch_or(&self, val: bool, order: Ordering) -> bool {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_or(self.v.get(), val as u8, order) != 0 }
}
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "8")]
pub fn fetch_xor(&self, val: bool, order: Ordering) -> bool {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_xor(self.v.get(), val as u8, order) != 0 }
}
#[inline]
#[stable(feature = "atomic_access", since = "1.15.0")]
pub fn get_mut(&mut self) -> &mut *mut T {
+ // SAFETY: the mutable reference guarantees unique ownership.
unsafe { &mut *self.p.get() }
}
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn load(&self, order: Ordering) -> *mut T {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_load(self.p.get() as *mut usize, order) as *mut T }
}
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn store(&self, ptr: *mut T, order: Ordering) {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe {
atomic_store(self.p.get() as *mut usize, ptr as usize, order);
}
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "ptr")]
pub fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_swap(self.p.get() as *mut usize, ptr as usize, order) as *mut T }
}
success: Ordering,
failure: Ordering,
) -> Result<*mut T, *mut T> {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe {
let res = atomic_compare_exchange(
self.p.get() as *mut usize,
success: Ordering,
failure: Ordering,
) -> Result<*mut T, *mut T> {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe {
let res = atomic_compare_exchange_weak(
self.p.get() as *mut usize,
#[inline]
#[$stable_access]
pub fn get_mut(&mut self) -> &mut $int_type {
+ // SAFETY: the mutable reference guarantees unique ownership.
unsafe { &mut *self.v.get() }
}
}
#[inline]
#[$stable]
pub fn load(&self, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_load(self.v.get(), order) }
}
}
#[inline]
#[$stable]
pub fn store(&self, val: $int_type, order: Ordering) {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_store(self.v.get(), val, order); }
}
}
#[$stable]
#[$cfg_cas]
pub fn swap(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_swap(self.v.get(), val, order) }
}
}
new: $int_type,
success: Ordering,
failure: Ordering) -> Result<$int_type, $int_type> {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_compare_exchange(self.v.get(), current, new, success, failure) }
}
}
new: $int_type,
success: Ordering,
failure: Ordering) -> Result<$int_type, $int_type> {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe {
atomic_compare_exchange_weak(self.v.get(), current, new, success, failure)
}
#[$stable]
#[$cfg_cas]
pub fn fetch_add(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_add(self.v.get(), val, order) }
}
}
#[$stable]
#[$cfg_cas]
pub fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_sub(self.v.get(), val, order) }
}
}
#[$stable]
#[$cfg_cas]
pub fn fetch_and(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_and(self.v.get(), val, order) }
}
}
#[$stable_nand]
#[$cfg_cas]
pub fn fetch_nand(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_nand(self.v.get(), val, order) }
}
}
#[$stable]
#[$cfg_cas]
pub fn fetch_or(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_or(self.v.get(), val, order) }
}
}
#[$stable]
#[$cfg_cas]
pub fn fetch_xor(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_xor(self.v.get(), val, order) }
}
}
issue = "48655")]
#[$cfg_cas]
pub fn fetch_max(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { $max_fn(self.v.get(), val, order) }
}
}
issue = "48655")]
#[$cfg_cas]
pub fn fetch_min(&self, val: $int_type, order: Ordering) -> $int_type {
+ // SAFETY: data races are prevented by atomic intrinsics.
unsafe { $min_fn(self.v.get(), val, order) }
}
}
}
let mut atomic = ", stringify!($atomic_type), "::new(1);
-unsafe {
+",
+// SAFETY: Safe as long as `my_atomic_op` is atomic.
+"unsafe {
my_atomic_op(atomic.as_mut_ptr());
}
# }
// https://github.com/WebAssembly/tool-conventions/issues/59. We should
// follow that discussion and implement a solution when one comes about!
#[cfg(not(target_arch = "wasm32"))]
+ // SAFETY: using an atomic fence is safe.
unsafe {
match order {
Acquire => intrinsics::atomic_fence_acq(),
#[inline]
#[stable(feature = "compiler_fences", since = "1.21.0")]
pub fn compiler_fence(order: Ordering) {
+ // SAFETY: using an atomic fence is safe.
unsafe {
match order {
Acquire => intrinsics::atomic_singlethreadfence_acq(),
baz: 10/20,
},
hello: \"world\",
+}",
+ format!("{:#?}", Bar)
+ );
+ }
+
+ #[test]
+ fn test_only_non_exhaustive() {
+ struct Foo;
+
+ impl fmt::Debug for Foo {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt.debug_struct("Foo").finish_non_exhaustive()
+ }
+ }
+
+ assert_eq!("Foo { .. }", format!("{:?}", Foo));
+ assert_eq!(
+ "Foo {
+ ..
+}",
+ format!("{:#?}", Foo)
+ );
+ }
+
+ #[test]
+ fn test_multiple_and_non_exhaustive() {
+ struct Foo;
+
+ impl fmt::Debug for Foo {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt.debug_struct("Foo")
+ .field("bar", &true)
+ .field("baz", &format_args!("{}/{}", 10, 20))
+ .finish_non_exhaustive()
+ }
+ }
+
+ assert_eq!("Foo { bar: true, baz: 10/20, .. }", format!("{:?}", Foo));
+ assert_eq!(
+ "Foo {
+ bar: true,
+ baz: 10/20,
+ ..
+}",
+ format!("{:#?}", Foo)
+ );
+ }
+
+ #[test]
+ fn test_nested_non_exhaustive() {
+ struct Foo;
+
+ impl fmt::Debug for Foo {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt.debug_struct("Foo")
+ .field("bar", &true)
+ .field("baz", &format_args!("{}/{}", 10, 20))
+ .finish_non_exhaustive()
+ }
+ }
+
+ struct Bar;
+
+ impl fmt::Debug for Bar {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt.debug_struct("Bar")
+ .field("foo", &Foo)
+ .field("hello", &"world")
+ .finish_non_exhaustive()
+ }
+ }
+
+ assert_eq!(
+ "Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \"world\", .. }",
+ format!("{:?}", Bar)
+ );
+ assert_eq!(
+ "Bar {
+ foo: Foo {
+ bar: true,
+ baz: 10/20,
+ ..
+ },
+ hello: \"world\",
+ ..
}",
format!("{:#?}", Bar)
);
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(debug_map_key_value)]
+#![feature(debug_non_exhaustive)]
#![feature(dec2flt)]
#![feature(exact_size_is_empty)]
#![feature(fixed_size_array)]
#![feature(range_is_empty)]
#![feature(raw)]
#![feature(saturating_neg)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(specialization)]
chalk-engine = { version = "0.9.0", default-features=false }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.7.1"
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
+ // Interned types
+ [] tys: rustc::ty::TyS<$tcx>,
+
// HIR types
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
[] arm: rustc_hir::Arm<$tcx>,
([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
#[derive(Default)]
pub struct Arena<$tcx> {
- dropless: DroplessArena,
+ pub dropless: DroplessArena,
drop: DropArena,
$($name: arena_for_type!($a[$ty]),)*
}
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(test)]
extern crate test;
use crate::ty::query::Providers;
use crate::ty::TyCtxt;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
ItemKind::Union(..) => Target::Union,
ItemKind::Trait(..) => Target::Trait,
ItemKind::TraitAlias(..) => Target::TraitAlias,
- ItemKind::Impl(..) => Target::Impl,
+ ItemKind::Impl { .. } => Target::Impl,
}
}
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
let containing_item = tcx.hir().expect_item(parent_hir_id);
let containing_impl_is_for_trait = match &containing_item.kind {
- hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
+ hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
_ => bug!("parent of an ImplItem must be an Impl"),
};
if containing_impl_is_for_trait {
| ItemKind::Use(..)
| ItemKind::ForeignMod(..)
| ItemKind::GlobalAsm(..)
- | ItemKind::Impl(..) => return None,
+ | ItemKind::Impl { .. } => return None,
},
Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(..) => DefKind::Fn,
| ItemKind::Union(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..)
| ItemKind::TraitAlias(ref generics, _)
- | ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics),
+ | ItemKind::Impl { ref generics, .. } => Some(generics),
_ => None,
},
_ => None,
| ItemKind::Struct(..)
| ItemKind::Union(..)
| ItemKind::Trait(..)
- | ItemKind::Impl(..) => true,
+ | ItemKind::Impl { .. } => true,
_ => false,
},
Node::ForeignItem(fi) => match fi.kind {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
- ItemKind::Impl(..) => "impl",
+ ItemKind::Impl { .. } => "impl",
};
format!("{} {}{}", item_str, path_str(), id_str)
}
Region, Ty, TyCtxt, TypeFoldable,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_error_codes::*;
use rustc_errors::{pluralize, struct_span_err};
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use rustc_hir as hir;
fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
match item.kind {
- hir::ItemKind::Impl(..) => "impl",
+ hir::ItemKind::Impl { .. } => "impl",
hir::ItemKind::Struct(..) => "struct",
hir::ItemKind::Union(..) => "union",
hir::ItemKind::Enum(..) => "enum",
TypeError::IntrinsicCast => {
Error0308("cannot coerce intrinsics to function pointers")
}
- TypeError::ObjectUnsafeCoercion(did) => Error0038(did.clone()),
+ TypeError::ObjectUnsafeCoercion(did) => Error0038(*did),
_ => Error0308("mismatched types"),
},
}
use rustc_span::Span;
use std::borrow::Cow;
-use rustc_error_codes::*;
-
struct FindLocalByTypeVisitor<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
target_ty: Ty<'tcx>,
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::util::common::ErrorReported;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir::{FunctionRetTy, TyKind};
-use rustc_error_codes::*;
-
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
/// an anonymous region, emit an descriptive diagnostic error.
use crate::ty::{self, Region};
use rustc_errors::{struct_span_err, DiagnosticBuilder};
-use rustc_error_codes::*;
-
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub(super) fn note_region_origin(
&self,
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
};
use rustc_hir::def_id::DefId;
-use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_span::Span;
use std::fmt;
}
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
- let mut process_constraint = |constraint: &Constraint<'tcx>| {
- let (a_region, b_vid, b_data, retain) = match *constraint {
+ let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len());
+ let mut changes = Vec::new();
+ for constraint in self.data.constraints.keys() {
+ let (a_vid, a_region, b_vid, b_data) = match *constraint {
Constraint::RegSubVar(a_region, b_vid) => {
let b_data = var_values.value_mut(b_vid);
- (a_region, b_vid, b_data, false)
+ (None, a_region, b_vid, b_data)
}
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
- VarValue::ErrorValue => return (false, false),
+ VarValue::ErrorValue => continue,
VarValue::Value(a_region) => {
let b_data = var_values.value_mut(b_vid);
- let retain = match *b_data {
- VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
- _ => true,
- };
- (a_region, b_vid, b_data, retain)
+ (Some(a_vid), a_region, b_vid, b_data)
}
},
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
// These constraints are checked after expansion
// is done, in `collect_errors`.
- return (false, false);
+ continue;
}
};
-
- let changed = self.expand_node(a_region, b_vid, b_data);
- (changed, retain)
- };
-
- // Using bitsets to track the remaining elements is faster than using a
- // `Vec` by itself (which requires removing elements, which requires
- // element shuffling, which is slow).
- let constraints: Vec<_> = self.data.constraints.keys().collect();
- let mut live_indices: BitSet<usize> = BitSet::new_filled(constraints.len());
- let mut killed_indices: BitSet<usize> = BitSet::new_empty(constraints.len());
- let mut changed = true;
- while changed {
- changed = false;
- for index in live_indices.iter() {
- let constraint = constraints[index];
- let (edge_changed, retain) = process_constraint(constraint);
- changed |= edge_changed;
- if !retain {
- let changed = killed_indices.insert(index);
- debug_assert!(changed);
+ if self.expand_node(a_region, b_vid, b_data) {
+ changes.push(b_vid);
+ }
+ if let Some(a_vid) = a_vid {
+ match *b_data {
+ VarValue::Value(ReStatic) | VarValue::ErrorValue => (),
+ _ => {
+ constraints[a_vid].push((a_vid, b_vid));
+ constraints[b_vid].push((a_vid, b_vid));
+ }
}
}
- live_indices.subtract(&killed_indices);
+ }
- // We could clear `killed_indices` here, but we don't need to and
- // it's cheaper not to.
+ while let Some(vid) = changes.pop() {
+ constraints[vid].retain(|&(a_vid, b_vid)| {
+ let a_region = match *var_values.value(a_vid) {
+ VarValue::ErrorValue => return false,
+ VarValue::Value(a_region) => a_region,
+ };
+ let b_data = var_values.value_mut(b_vid);
+ if self.expand_node(a_region, b_vid, b_data) {
+ changes.push(b_vid);
+ }
+ match *b_data {
+ VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
+ _ => true,
+ }
+ });
}
}
- // This function is very hot in some workloads. There's a single callsite
- // so always inlining is ok even though it's large.
- #[inline(always)]
fn expand_node(
&self,
a_region: Region<'tcx>,
self.var_infos[node_idx].origin.span(),
&format!(
"collect_error_for_expanding_node() could not find \
- error for var {:?} in universe {:?}, lower_bounds={:#?}, \
- upper_bounds={:#?}",
+ error for var {:?} in universe {:?}, lower_bounds={:#?}, \
+ upper_bounds={:#?}",
node_idx, node_universe, lower_bounds, upper_bounds
),
);
use rustc_hir::Node;
use rustc_span::Span;
-use rustc_error_codes::*;
-
pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
/// Information about the opaque types whose values we
#![feature(optin_builtin_traits)]
#![feature(option_expect_none)]
#![feature(range_is_empty)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(thread_local)]
}
impl<'tcx> ExportedSymbol<'tcx> {
- pub fn symbol_name(&self, tcx: TyCtxt<'tcx>) -> ty::SymbolName {
+ /// This is the symbol name of an instance if it is instantiated in the
+ /// local crate.
+ pub fn symbol_name_for_local_instance(&self, tcx: TyCtxt<'tcx>) -> ty::SymbolName {
match *self {
ExportedSymbol::NonGeneric(def_id) => tcx.symbol_name(ty::Instance::mono(tcx, def_id)),
ExportedSymbol::Generic(def_id, substs) => {
}
ExportedSymbol::Generic(..) | ExportedSymbol::NoDefId(_) => cmp::Ordering::Less,
},
- ExportedSymbol::Generic(..) => match *other {
+ ExportedSymbol::Generic(self_def_id, self_substs) => match *other {
ExportedSymbol::NonGeneric(_) => cmp::Ordering::Greater,
- ExportedSymbol::Generic(..) => self.symbol_name(tcx).cmp(&other.symbol_name(tcx)),
+ ExportedSymbol::Generic(other_def_id, other_substs) => {
+ // We compare the symbol names because they are cached as query
+ // results which makes them relatively cheap to access repeatedly.
+ //
+ // It might be even faster to build a local cache of stable IDs
+ // for sorting. Exported symbols are really only sorted once
+ // in order to make the `exported_symbols` query result stable.
+ let self_symbol_name =
+ tcx.symbol_name(ty::Instance::new(self_def_id, self_substs));
+ let other_symbol_name =
+ tcx.symbol_name(ty::Instance::new(other_def_id, other_substs));
+
+ self_symbol_name.cmp(&other_symbol_name)
+ }
ExportedSymbol::NoDefId(_) => cmp::Ordering::Less,
},
ExportedSymbol::NoDefId(self_symbol_name) => match *other {
use rustc_span::Span;
use syntax::ast;
-use rustc_error_codes::*;
-
// The actual lang items defined come at the end of this file in one handy table.
// So you probably just want to nip down to the end.
macro_rules! language_item_table {
use rustc_target::spec::PanicStrategy;
use syntax::ast;
-use rustc_error_codes::*;
-
macro_rules! weak_lang_items {
($($name:ident, $item:ident, $sym:ident;)*) => (
use rustc_target::spec::abi::Abi;
use std::{any::Any, env, fmt};
-use rustc_error_codes::*;
-
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
pub enum ErrorHandled {
/// Already reported a lint or an error for this evaluation.
ErrorHandled::Reported => {}
ErrorHandled::TooGeneric => bug!(
"MIR interpretation failed without reporting an error \
- even though it was fully monomorphized"
+ even though it was fully monomorphized"
),
}
}
let next = self.next_id;
self.next_id.0 = self.next_id.0.checked_add(1).expect(
"You overflowed a u64 by incrementing by 1... \
- You've just earned yourself a free drink if we ever meet. \
- Seriously, how did you do that?!",
+ You've just earned yourself a free drink if we ever meet. \
+ Seriously, how did you do that?!",
);
next
}
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
}
+ /// The `symbol_name` query provides the symbol name for calling a
+ /// given instance from the local crate. In particular, it will also
+ /// look up the correct symbol name of instances from upstream crates.
query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName {
no_force
desc { "computing the symbol for `{}`", key }
}
Linking {
+ /// The list of symbols exported from the given crate.
+ ///
+ /// - All names contained in `exported_symbols(cnum)` are guaranteed to
+ /// correspond to a publicly visible symbol in `cnum` machine code.
+ /// - The `exported_symbols` sets of different crates do not intersect.
query exported_symbols(_: CrateNum)
-> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>> {
desc { "exported_symbols" }
+++ /dev/null
-use super::{
- ConstEvalFailure, EvaluationResult, FulfillmentError, FulfillmentErrorCode,
- MismatchedProjectionTypes, ObjectSafetyViolation, Obligation, ObligationCause,
- ObligationCauseCode, OnUnimplementedDirective, OnUnimplementedNote,
- OutputTypeParameterMismatch, Overflow, PredicateObligation, SelectionContext, SelectionError,
- TraitNotObjectSafe,
-};
-
-use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
-use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use crate::infer::{self, InferCtxt};
-use crate::mir::interpret::ErrorHandled;
-use crate::session::DiagnosticMessageId;
-use crate::traits::object_safety_violations;
-use crate::ty::error::ExpectedFound;
-use crate::ty::fast_reject;
-use crate::ty::fold::TypeFolder;
-use crate::ty::subst::Subst;
-use crate::ty::GenericParamDefKind;
-use crate::ty::SubtypePredicate;
-use crate::ty::TypeckTables;
-use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
-
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style};
-use rustc_hir as hir;
-use rustc_hir::def_id::{DefId, LOCAL_CRATE};
-use rustc_hir::Node;
-use rustc_span::source_map::SourceMap;
-use rustc_span::symbol::{kw, sym};
-use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP};
-use std::fmt;
-use syntax::ast;
-
-use rustc_error_codes::*;
-
-impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
- pub fn report_fulfillment_errors(
- &self,
- errors: &[FulfillmentError<'tcx>],
- body_id: Option<hir::BodyId>,
- fallback_has_occurred: bool,
- ) {
- #[derive(Debug)]
- struct ErrorDescriptor<'tcx> {
- predicate: ty::Predicate<'tcx>,
- index: Option<usize>, // None if this is an old error
- }
-
- let mut error_map: FxHashMap<_, Vec<_>> = self
- .reported_trait_errors
- .borrow()
- .iter()
- .map(|(&span, predicates)| {
- (
- span,
- predicates
- .iter()
- .map(|predicate| ErrorDescriptor {
- predicate: predicate.clone(),
- index: None,
- })
- .collect(),
- )
- })
- .collect();
-
- for (index, error) in errors.iter().enumerate() {
- // We want to ignore desugarings here: spans are equivalent even
- // if one is the result of a desugaring and the other is not.
- let mut span = error.obligation.cause.span;
- let expn_data = span.ctxt().outer_expn_data();
- if let ExpnKind::Desugaring(_) = expn_data.kind {
- span = expn_data.call_site;
- }
-
- error_map.entry(span).or_default().push(ErrorDescriptor {
- predicate: error.obligation.predicate.clone(),
- index: Some(index),
- });
-
- self.reported_trait_errors
- .borrow_mut()
- .entry(span)
- .or_default()
- .push(error.obligation.predicate.clone());
- }
-
- // We do this in 2 passes because we want to display errors in order, though
- // maybe it *is* better to sort errors by span or something.
- let mut is_suppressed = vec![false; errors.len()];
- for (_, error_set) in error_map.iter() {
- // We want to suppress "duplicate" errors with the same span.
- for error in error_set {
- if let Some(index) = error.index {
- // Suppress errors that are either:
- // 1) strictly implied by another error.
- // 2) implied by an error with a smaller index.
- for error2 in error_set {
- if error2.index.map_or(false, |index2| is_suppressed[index2]) {
- // Avoid errors being suppressed by already-suppressed
- // errors, to prevent all errors from being suppressed
- // at once.
- continue;
- }
-
- if self.error_implies(&error2.predicate, &error.predicate)
- && !(error2.index >= error.index
- && self.error_implies(&error.predicate, &error2.predicate))
- {
- info!("skipping {:?} (implied by {:?})", error, error2);
- is_suppressed[index] = true;
- break;
- }
- }
- }
- }
- }
-
- for (error, suppressed) in errors.iter().zip(is_suppressed) {
- if !suppressed {
- self.report_fulfillment_error(error, body_id, fallback_has_occurred);
- }
- }
- }
-
- // returns if `cond` not occurring implies that `error` does not occur - i.e., that
- // `error` occurring implies that `cond` occurs.
- fn error_implies(&self, cond: &ty::Predicate<'tcx>, error: &ty::Predicate<'tcx>) -> bool {
- if cond == error {
- return true;
- }
-
- let (cond, error) = match (cond, error) {
- (&ty::Predicate::Trait(..), &ty::Predicate::Trait(ref error)) => (cond, error),
- _ => {
- // FIXME: make this work in other cases too.
- return false;
- }
- };
-
- for implication in super::elaborate_predicates(self.tcx, vec![cond.clone()]) {
- if let ty::Predicate::Trait(implication) = implication {
- let error = error.to_poly_trait_ref();
- let implication = implication.to_poly_trait_ref();
- // FIXME: I'm just not taking associated types at all here.
- // Eventually I'll need to implement param-env-aware
- // `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
- let param_env = ty::ParamEnv::empty();
- if self.can_sub(param_env, error, implication).is_ok() {
- debug!("error_implies: {:?} -> {:?} -> {:?}", cond, error, implication);
- return true;
- }
- }
- }
-
- false
- }
-
- fn report_fulfillment_error(
- &self,
- error: &FulfillmentError<'tcx>,
- body_id: Option<hir::BodyId>,
- fallback_has_occurred: bool,
- ) {
- debug!("report_fulfillment_error({:?})", error);
- match error.code {
- FulfillmentErrorCode::CodeSelectionError(ref selection_error) => {
- self.report_selection_error(
- &error.obligation,
- selection_error,
- fallback_has_occurred,
- error.points_at_arg_span,
- );
- }
- FulfillmentErrorCode::CodeProjectionError(ref e) => {
- self.report_projection_error(&error.obligation, e);
- }
- FulfillmentErrorCode::CodeAmbiguity => {
- self.maybe_report_ambiguity(&error.obligation, body_id);
- }
- FulfillmentErrorCode::CodeSubtypeError(ref expected_found, ref err) => {
- self.report_mismatched_types(
- &error.obligation.cause,
- expected_found.expected,
- expected_found.found,
- err.clone(),
- )
- .emit();
- }
- }
- }
-
- fn report_projection_error(
- &self,
- obligation: &PredicateObligation<'tcx>,
- error: &MismatchedProjectionTypes<'tcx>,
- ) {
- let predicate = self.resolve_vars_if_possible(&obligation.predicate);
-
- if predicate.references_error() {
- return;
- }
-
- self.probe(|_| {
- let err_buf;
- let mut err = &error.err;
- let mut values = None;
-
- // try to find the mismatched types to report the error with.
- //
- // this can fail if the problem was higher-ranked, in which
- // cause I have no idea for a good error message.
- if let ty::Predicate::Projection(ref data) = predicate {
- let mut selcx = SelectionContext::new(self);
- let (data, _) = self.replace_bound_vars_with_fresh_vars(
- obligation.cause.span,
- infer::LateBoundRegionConversionTime::HigherRankedType,
- data,
- );
- let mut obligations = vec![];
- let normalized_ty = super::normalize_projection_type(
- &mut selcx,
- obligation.param_env,
- data.projection_ty,
- obligation.cause.clone(),
- 0,
- &mut obligations,
- );
-
- debug!(
- "report_projection_error obligation.cause={:?} obligation.param_env={:?}",
- obligation.cause, obligation.param_env
- );
-
- debug!(
- "report_projection_error normalized_ty={:?} data.ty={:?}",
- normalized_ty, data.ty
- );
-
- let is_normalized_ty_expected = match &obligation.cause.code {
- ObligationCauseCode::ItemObligation(_)
- | ObligationCauseCode::BindingObligation(_, _)
- | ObligationCauseCode::ObjectCastObligation(_) => false,
- _ => true,
- };
-
- if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
- is_normalized_ty_expected,
- normalized_ty,
- data.ty,
- ) {
- values = Some(infer::ValuePairs::Types(ExpectedFound::new(
- is_normalized_ty_expected,
- normalized_ty,
- data.ty,
- )));
-
- err_buf = error;
- err = &err_buf;
- }
- }
-
- let msg = format!("type mismatch resolving `{}`", predicate);
- let error_id = (DiagnosticMessageId::ErrorId(271), Some(obligation.cause.span), msg);
- let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
- if fresh {
- let mut diag = struct_span_err!(
- self.tcx.sess,
- obligation.cause.span,
- E0271,
- "type mismatch resolving `{}`",
- predicate
- );
- self.note_type_err(&mut diag, &obligation.cause, None, values, err);
- self.note_obligation_cause(&mut diag, obligation);
- diag.emit();
- }
- });
- }
-
- fn fuzzy_match_tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
- /// returns the fuzzy category of a given type, or None
- /// if the type can be equated to any type.
- fn type_category(t: Ty<'_>) -> Option<u32> {
- match t.kind {
- ty::Bool => Some(0),
- ty::Char => Some(1),
- ty::Str => Some(2),
- ty::Int(..) | ty::Uint(..) | ty::Infer(ty::IntVar(..)) => Some(3),
- ty::Float(..) | ty::Infer(ty::FloatVar(..)) => Some(4),
- ty::Ref(..) | ty::RawPtr(..) => Some(5),
- ty::Array(..) | ty::Slice(..) => Some(6),
- ty::FnDef(..) | ty::FnPtr(..) => Some(7),
- ty::Dynamic(..) => Some(8),
- ty::Closure(..) => Some(9),
- ty::Tuple(..) => Some(10),
- ty::Projection(..) => Some(11),
- ty::Param(..) => Some(12),
- ty::Opaque(..) => Some(13),
- ty::Never => Some(14),
- ty::Adt(adt, ..) => match adt.adt_kind() {
- AdtKind::Struct => Some(15),
- AdtKind::Union => Some(16),
- AdtKind::Enum => Some(17),
- },
- ty::Generator(..) => Some(18),
- ty::Foreign(..) => Some(19),
- ty::GeneratorWitness(..) => Some(20),
- ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error => None,
- ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
- }
- }
-
- match (type_category(a), type_category(b)) {
- (Some(cat_a), Some(cat_b)) => match (&a.kind, &b.kind) {
- (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => def_a == def_b,
- _ => cat_a == cat_b,
- },
- // infer and error can be equated to all types
- _ => true,
- }
- }
-
- fn impl_similar_to(
- &self,
- trait_ref: ty::PolyTraitRef<'tcx>,
- obligation: &PredicateObligation<'tcx>,
- ) -> Option<DefId> {
- let tcx = self.tcx;
- let param_env = obligation.param_env;
- let trait_ref = tcx.erase_late_bound_regions(&trait_ref);
- let trait_self_ty = trait_ref.self_ty();
-
- let mut self_match_impls = vec![];
- let mut fuzzy_match_impls = vec![];
-
- self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| {
- let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
- let impl_trait_ref = tcx.impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs);
-
- let impl_self_ty = impl_trait_ref.self_ty();
-
- if let Ok(..) = self.can_eq(param_env, trait_self_ty, impl_self_ty) {
- self_match_impls.push(def_id);
-
- if trait_ref
- .substs
- .types()
- .skip(1)
- .zip(impl_trait_ref.substs.types().skip(1))
- .all(|(u, v)| self.fuzzy_match_tys(u, v))
- {
- fuzzy_match_impls.push(def_id);
- }
- }
- });
-
- let impl_def_id = if self_match_impls.len() == 1 {
- self_match_impls[0]
- } else if fuzzy_match_impls.len() == 1 {
- fuzzy_match_impls[0]
- } else {
- return None;
- };
-
- tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).then_some(impl_def_id)
- }
-
- fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> {
- self.tcx.hir().body(body_id).generator_kind.map(|gen_kind| match gen_kind {
- hir::GeneratorKind::Gen => "a generator",
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) => "an async block",
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn) => "an async function",
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure) => "an async closure",
- })
- }
-
- /// Used to set on_unimplemented's `ItemContext`
- /// to be the enclosing (async) block/function/closure
- fn describe_enclosure(&self, hir_id: hir::HirId) -> Option<&'static str> {
- let hir = &self.tcx.hir();
- let node = hir.find(hir_id)?;
- if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = &node {
- self.describe_generator(*body_id).or_else(|| {
- Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
- "an async function"
- } else {
- "a function"
- })
- })
- } else if let hir::Node::Expr(hir::Expr {
- kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
- ..
- }) = &node
- {
- self.describe_generator(*body_id).or_else(|| {
- Some(if gen_movability.is_some() { "an async closure" } else { "a closure" })
- })
- } else if let hir::Node::Expr(hir::Expr { .. }) = &node {
- let parent_hid = hir.get_parent_node(hir_id);
- if parent_hid != hir_id {
- return self.describe_enclosure(parent_hid);
- } else {
- None
- }
- } else {
- None
- }
- }
-
- fn on_unimplemented_note(
- &self,
- trait_ref: ty::PolyTraitRef<'tcx>,
- obligation: &PredicateObligation<'tcx>,
- ) -> OnUnimplementedNote {
- let def_id =
- self.impl_similar_to(trait_ref, obligation).unwrap_or_else(|| trait_ref.def_id());
- let trait_ref = *trait_ref.skip_binder();
-
- let mut flags = vec![];
- flags.push((
- sym::item_context,
- self.describe_enclosure(obligation.cause.body_id).map(|s| s.to_owned()),
- ));
-
- match obligation.cause.code {
- ObligationCauseCode::BuiltinDerivedObligation(..)
- | ObligationCauseCode::ImplDerivedObligation(..) => {}
- _ => {
- // this is a "direct", user-specified, rather than derived,
- // obligation.
- flags.push((sym::direct, None));
- }
- }
-
- if let ObligationCauseCode::ItemObligation(item) = obligation.cause.code {
- // FIXME: maybe also have some way of handling methods
- // from other traits? That would require name resolution,
- // which we might want to be some sort of hygienic.
- //
- // Currently I'm leaving it for what I need for `try`.
- if self.tcx.trait_of_item(item) == Some(trait_ref.def_id) {
- let method = self.tcx.item_name(item);
- flags.push((sym::from_method, None));
- flags.push((sym::from_method, Some(method.to_string())));
- }
- }
- if let Some((t, _)) = self.get_parent_trait_ref(&obligation.cause.code) {
- flags.push((sym::parent_trait, Some(t)));
- }
-
- if let Some(k) = obligation.cause.span.desugaring_kind() {
- flags.push((sym::from_desugaring, None));
- flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
- }
- let generics = self.tcx.generics_of(def_id);
- let self_ty = trait_ref.self_ty();
- // This is also included through the generics list as `Self`,
- // but the parser won't allow you to use it
- flags.push((sym::_Self, Some(self_ty.to_string())));
- if let Some(def) = self_ty.ty_adt_def() {
- // We also want to be able to select self's original
- // signature with no type arguments resolved
- flags.push((sym::_Self, Some(self.tcx.type_of(def.did).to_string())));
- }
-
- for param in generics.params.iter() {
- let value = match param.kind {
- GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
- trait_ref.substs[param.index as usize].to_string()
- }
- GenericParamDefKind::Lifetime => continue,
- };
- let name = param.name;
- flags.push((name, Some(value)));
- }
-
- if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) {
- flags.push((sym::crate_local, None));
- }
-
- // Allow targeting all integers using `{integral}`, even if the exact type was resolved
- if self_ty.is_integral() {
- flags.push((sym::_Self, Some("{integral}".to_owned())));
- }
-
- if let ty::Array(aty, len) = self_ty.kind {
- flags.push((sym::_Self, Some("[]".to_owned())));
- flags.push((sym::_Self, Some(format!("[{}]", aty))));
- if let Some(def) = aty.ty_adt_def() {
- // We also want to be able to select the array's type's original
- // signature with no type arguments resolved
- flags.push((
- sym::_Self,
- Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
- ));
- let tcx = self.tcx;
- if let Some(len) = len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
- flags.push((
- sym::_Self,
- Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
- ));
- } else {
- flags.push((
- sym::_Self,
- Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
- ));
- }
- }
- }
-
- if let Ok(Some(command)) =
- OnUnimplementedDirective::of_item(self.tcx, trait_ref.def_id, def_id)
- {
- command.evaluate(self.tcx, trait_ref, &flags[..])
- } else {
- OnUnimplementedNote::default()
- }
- }
-
- fn find_similar_impl_candidates(
- &self,
- trait_ref: ty::PolyTraitRef<'tcx>,
- ) -> Vec<ty::TraitRef<'tcx>> {
- let simp = fast_reject::simplify_type(self.tcx, trait_ref.skip_binder().self_ty(), true);
- let all_impls = self.tcx.all_impls(trait_ref.def_id());
-
- match simp {
- Some(simp) => all_impls
- .iter()
- .filter_map(|&def_id| {
- let imp = self.tcx.impl_trait_ref(def_id).unwrap();
- let imp_simp = fast_reject::simplify_type(self.tcx, imp.self_ty(), true);
- if let Some(imp_simp) = imp_simp {
- if simp != imp_simp {
- return None;
- }
- }
-
- Some(imp)
- })
- .collect(),
- None => {
- all_impls.iter().map(|&def_id| self.tcx.impl_trait_ref(def_id).unwrap()).collect()
- }
- }
- }
-
- fn report_similar_impl_candidates(
- &self,
- impl_candidates: Vec<ty::TraitRef<'tcx>>,
- err: &mut DiagnosticBuilder<'_>,
- ) {
- if impl_candidates.is_empty() {
- return;
- }
-
- let len = impl_candidates.len();
- let end = if impl_candidates.len() <= 5 { impl_candidates.len() } else { 4 };
-
- let normalize = |candidate| {
- self.tcx.infer_ctxt().enter(|ref infcx| {
- let normalized = infcx
- .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
- .normalize(candidate)
- .ok();
- match normalized {
- Some(normalized) => format!("\n {:?}", normalized.value),
- None => format!("\n {:?}", candidate),
- }
- })
- };
-
- // Sort impl candidates so that ordering is consistent for UI tests.
- let mut normalized_impl_candidates =
- impl_candidates.iter().map(normalize).collect::<Vec<String>>();
-
- // Sort before taking the `..end` range,
- // because the ordering of `impl_candidates` may not be deterministic:
- // https://github.com/rust-lang/rust/pull/57475#issuecomment-455519507
- normalized_impl_candidates.sort();
-
- err.help(&format!(
- "the following implementations were found:{}{}",
- normalized_impl_candidates[..end].join(""),
- if len > 5 { format!("\nand {} others", len - 4) } else { String::new() }
- ));
- }
-
- /// Reports that an overflow has occurred and halts compilation. We
- /// halt compilation unconditionally because it is important that
- /// overflows never be masked -- they basically represent computations
- /// whose result could not be truly determined and thus we can't say
- /// if the program type checks or not -- and they are unusual
- /// occurrences in any case.
- pub fn report_overflow_error<T>(
- &self,
- obligation: &Obligation<'tcx, T>,
- suggest_increasing_limit: bool,
- ) -> !
- where
- T: fmt::Display + TypeFoldable<'tcx>,
- {
- let predicate = self.resolve_vars_if_possible(&obligation.predicate);
- let mut err = struct_span_err!(
- self.tcx.sess,
- obligation.cause.span,
- E0275,
- "overflow evaluating the requirement `{}`",
- predicate
- );
-
- if suggest_increasing_limit {
- self.suggest_new_overflow_limit(&mut err);
- }
-
- self.note_obligation_cause_code(
- &mut err,
- &obligation.predicate,
- &obligation.cause.code,
- &mut vec![],
- );
-
- err.emit();
- self.tcx.sess.abort_if_errors();
- bug!();
- }
-
- /// Reports that a cycle was detected which led to overflow and halts
- /// compilation. This is equivalent to `report_overflow_error` except
- /// that we can give a more helpful error message (and, in particular,
- /// we do not suggest increasing the overflow limit, which is not
- /// going to help).
- pub fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! {
- let cycle = self.resolve_vars_if_possible(&cycle.to_owned());
- assert!(cycle.len() > 0);
-
- debug!("report_overflow_error_cycle: cycle={:?}", cycle);
-
- self.report_overflow_error(&cycle[0], false);
- }
-
- pub fn report_extra_impl_obligation(
- &self,
- error_span: Span,
- item_name: ast::Name,
- _impl_item_def_id: DefId,
- trait_item_def_id: DefId,
- requirement: &dyn fmt::Display,
- ) -> DiagnosticBuilder<'tcx> {
- let msg = "impl has stricter requirements than trait";
- let sp = self.tcx.sess.source_map().def_span(error_span);
-
- let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
-
- if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
- let span = self.tcx.sess.source_map().def_span(trait_item_span);
- err.span_label(span, format!("definition of `{}` from trait", item_name));
- }
-
- err.span_label(sp, format!("impl has extra requirement {}", requirement));
-
- err
- }
-
- /// Gets the parent trait chain start
- fn get_parent_trait_ref(
- &self,
- code: &ObligationCauseCode<'tcx>,
- ) -> Option<(String, Option<Span>)> {
- match code {
- &ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
- let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
- match self.get_parent_trait_ref(&data.parent_code) {
- Some(t) => Some(t),
- None => {
- let ty = parent_trait_ref.skip_binder().self_ty();
- let span =
- TyCategory::from_ty(ty).map(|(_, def_id)| self.tcx.def_span(def_id));
- Some((ty.to_string(), span))
- }
- }
- }
- _ => None,
- }
- }
-
- pub fn report_selection_error(
- &self,
- obligation: &PredicateObligation<'tcx>,
- error: &SelectionError<'tcx>,
- fallback_has_occurred: bool,
- points_at_arg: bool,
- ) {
- let tcx = self.tcx;
- let span = obligation.cause.span;
-
- let mut err = match *error {
- SelectionError::Unimplemented => {
- if let ObligationCauseCode::CompareImplMethodObligation {
- item_name,
- impl_item_def_id,
- trait_item_def_id,
- }
- | ObligationCauseCode::CompareImplTypeObligation {
- item_name,
- impl_item_def_id,
- trait_item_def_id,
- } = obligation.cause.code
- {
- self.report_extra_impl_obligation(
- span,
- item_name,
- impl_item_def_id,
- trait_item_def_id,
- &format!("`{}`", obligation.predicate),
- )
- .emit();
- return;
- }
- match obligation.predicate {
- ty::Predicate::Trait(ref trait_predicate) => {
- let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
-
- if self.tcx.sess.has_errors() && trait_predicate.references_error() {
- return;
- }
- let trait_ref = trait_predicate.to_poly_trait_ref();
- let (post_message, pre_message, type_def) = self
- .get_parent_trait_ref(&obligation.cause.code)
- .map(|(t, s)| {
- (
- format!(" in `{}`", t),
- format!("within `{}`, ", t),
- s.map(|s| (format!("within this `{}`", t), s)),
- )
- })
- .unwrap_or_default();
-
- let OnUnimplementedNote { message, label, note, enclosing_scope } =
- self.on_unimplemented_note(trait_ref, obligation);
- let have_alt_message = message.is_some() || label.is_some();
- let is_try = self
- .tcx
- .sess
- .source_map()
- .span_to_snippet(span)
- .map(|s| &s == "?")
- .unwrap_or(false);
- let is_from = format!("{}", trait_ref.print_only_trait_path())
- .starts_with("std::convert::From<");
- let (message, note) = if is_try && is_from {
- (
- Some(format!(
- "`?` couldn't convert the error to `{}`",
- trait_ref.self_ty(),
- )),
- Some(
- "the question mark operation (`?`) implicitly performs a \
- conversion on the error value using the `From` trait"
- .to_owned(),
- ),
- )
- } else {
- (message, note)
- };
-
- let mut err = struct_span_err!(
- self.tcx.sess,
- span,
- E0277,
- "{}",
- message.unwrap_or_else(|| format!(
- "the trait bound `{}` is not satisfied{}",
- trait_ref.to_predicate(),
- post_message,
- ))
- );
-
- let explanation =
- if obligation.cause.code == ObligationCauseCode::MainFunctionType {
- "consider using `()`, or a `Result`".to_owned()
- } else {
- format!(
- "{}the trait `{}` is not implemented for `{}`",
- pre_message,
- trait_ref.print_only_trait_path(),
- trait_ref.self_ty(),
- )
- };
-
- if self.suggest_add_reference_to_arg(
- &obligation,
- &mut err,
- &trait_ref,
- points_at_arg,
- have_alt_message,
- ) {
- self.note_obligation_cause(&mut err, obligation);
- err.emit();
- return;
- }
- if let Some(ref s) = label {
- // If it has a custom `#[rustc_on_unimplemented]`
- // error message, let's display it as the label!
- err.span_label(span, s.as_str());
- err.help(&explanation);
- } else {
- err.span_label(span, explanation);
- }
- if let Some((msg, span)) = type_def {
- err.span_label(span, &msg);
- }
- if let Some(ref s) = note {
- // If it has a custom `#[rustc_on_unimplemented]` note, let's display it
- err.note(s.as_str());
- }
- if let Some(ref s) = enclosing_scope {
- let enclosing_scope_span = tcx.def_span(
- tcx.hir()
- .opt_local_def_id(obligation.cause.body_id)
- .unwrap_or_else(|| {
- tcx.hir().body_owner_def_id(hir::BodyId {
- hir_id: obligation.cause.body_id,
- })
- }),
- );
-
- err.span_label(enclosing_scope_span, s.as_str());
- }
-
- self.suggest_borrow_on_unsized_slice(&obligation.cause.code, &mut err);
- self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);
- self.suggest_remove_reference(&obligation, &mut err, &trait_ref);
- self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref);
- self.note_version_mismatch(&mut err, &trait_ref);
-
- // Try to report a help message
- if !trait_ref.has_infer_types()
- && self.predicate_can_apply(obligation.param_env, trait_ref)
- {
- // If a where-clause may be useful, remind the
- // user that they can add it.
- //
- // don't display an on-unimplemented note, as
- // these notes will often be of the form
- // "the type `T` can't be frobnicated"
- // which is somewhat confusing.
- self.suggest_restricting_param_bound(
- &mut err,
- &trait_ref,
- obligation.cause.body_id,
- );
- } else {
- if !have_alt_message {
- // Can't show anything else useful, try to find similar impls.
- let impl_candidates = self.find_similar_impl_candidates(trait_ref);
- self.report_similar_impl_candidates(impl_candidates, &mut err);
- }
- self.suggest_change_mut(
- &obligation,
- &mut err,
- &trait_ref,
- points_at_arg,
- );
- }
-
- // If this error is due to `!: Trait` not implemented but `(): Trait` is
- // implemented, and fallback has occurred, then it could be due to a
- // variable that used to fallback to `()` now falling back to `!`. Issue a
- // note informing about the change in behaviour.
- if trait_predicate.skip_binder().self_ty().is_never()
- && fallback_has_occurred
- {
- let predicate = trait_predicate.map_bound(|mut trait_pred| {
- trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
- self.tcx.mk_unit(),
- &trait_pred.trait_ref.substs[1..],
- );
- trait_pred
- });
- let unit_obligation = Obligation {
- predicate: ty::Predicate::Trait(predicate),
- ..obligation.clone()
- };
- if self.predicate_may_hold(&unit_obligation) {
- err.note(
- "the trait is implemented for `()`. \
- Possibly this error has been caused by changes to \
- Rust's type-inference algorithm \
- (see: https://github.com/rust-lang/rust/issues/48950 \
- for more info). Consider whether you meant to use the \
- type `()` here instead.",
- );
- }
- }
-
- err
- }
-
- ty::Predicate::Subtype(ref predicate) => {
- // Errors for Subtype predicates show up as
- // `FulfillmentErrorCode::CodeSubtypeError`,
- // not selection error.
- span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
- }
-
- ty::Predicate::RegionOutlives(ref predicate) => {
- let predicate = self.resolve_vars_if_possible(predicate);
- let err = self
- .region_outlives_predicate(&obligation.cause, &predicate)
- .err()
- .unwrap();
- struct_span_err!(
- self.tcx.sess,
- span,
- E0279,
- "the requirement `{}` is not satisfied (`{}`)",
- predicate,
- err,
- )
- }
-
- ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
- let predicate = self.resolve_vars_if_possible(&obligation.predicate);
- struct_span_err!(
- self.tcx.sess,
- span,
- E0280,
- "the requirement `{}` is not satisfied",
- predicate
- )
- }
-
- ty::Predicate::ObjectSafe(trait_def_id) => {
- let violations = object_safety_violations(self.tcx, trait_def_id);
- report_object_safety_error(self.tcx, span, trait_def_id, violations)
- }
-
- ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
- let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
- let closure_span = self
- .tcx
- .sess
- .source_map()
- .def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
- let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap();
- let mut err = struct_span_err!(
- self.tcx.sess,
- closure_span,
- E0525,
- "expected a closure that implements the `{}` trait, \
- but this closure only implements `{}`",
- kind,
- found_kind
- );
-
- err.span_label(
- closure_span,
- format!("this closure implements `{}`, not `{}`", found_kind, kind),
- );
- err.span_label(
- obligation.cause.span,
- format!("the requirement to implement `{}` derives from here", kind),
- );
-
- // Additional context information explaining why the closure only implements
- // a particular trait.
- if let Some(tables) = self.in_progress_tables {
- let tables = tables.borrow();
- match (found_kind, tables.closure_kind_origins().get(hir_id)) {
- (ty::ClosureKind::FnOnce, Some((span, name))) => {
- err.span_label(
- *span,
- format!(
- "closure is `FnOnce` because it moves the \
- variable `{}` out of its environment",
- name
- ),
- );
- }
- (ty::ClosureKind::FnMut, Some((span, name))) => {
- err.span_label(
- *span,
- format!(
- "closure is `FnMut` because it mutates the \
- variable `{}` here",
- name
- ),
- );
- }
- _ => {}
- }
- }
-
- err.emit();
- return;
- }
-
- ty::Predicate::WellFormed(ty) => {
- if !self.tcx.sess.opts.debugging_opts.chalk {
- // WF predicates cannot themselves make
- // errors. They can only block due to
- // ambiguity; otherwise, they always
- // degenerate into other obligations
- // (which may fail).
- span_bug!(span, "WF predicate not satisfied for {:?}", ty);
- } else {
- // FIXME: we'll need a better message which takes into account
- // which bounds actually failed to hold.
- self.tcx.sess.struct_span_err(
- span,
- &format!("the type `{}` is not well-formed (chalk)", ty),
- )
- }
- }
-
- ty::Predicate::ConstEvaluatable(..) => {
- // Errors for `ConstEvaluatable` predicates show up as
- // `SelectionError::ConstEvalFailure`,
- // not `Unimplemented`.
- span_bug!(
- span,
- "const-evaluatable requirement gave wrong error: `{:?}`",
- obligation
- )
- }
- }
- }
-
- OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => {
- let found_trait_ref = self.resolve_vars_if_possible(&*found_trait_ref);
- let expected_trait_ref = self.resolve_vars_if_possible(&*expected_trait_ref);
-
- if expected_trait_ref.self_ty().references_error() {
- return;
- }
-
- let found_trait_ty = found_trait_ref.self_ty();
-
- let found_did = match found_trait_ty.kind {
- ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
- ty::Adt(def, _) => Some(def.did),
- _ => None,
- };
-
- let found_span = found_did
- .and_then(|did| self.tcx.hir().span_if_local(did))
- .map(|sp| self.tcx.sess.source_map().def_span(sp)); // the sp could be an fn def
-
- if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
- // We check closures twice, with obligations flowing in different directions,
- // but we want to complain about them only once.
- return;
- }
-
- self.reported_closure_mismatch.borrow_mut().insert((span, found_span));
-
- let found = match found_trait_ref.skip_binder().substs.type_at(1).kind {
- ty::Tuple(ref tys) => vec![ArgKind::empty(); tys.len()],
- _ => vec![ArgKind::empty()],
- };
-
- let expected_ty = expected_trait_ref.skip_binder().substs.type_at(1);
- let expected = match expected_ty.kind {
- ty::Tuple(ref tys) => tys
- .iter()
- .map(|t| ArgKind::from_expected_ty(t.expect_ty(), Some(span)))
- .collect(),
- _ => vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())],
- };
-
- if found.len() == expected.len() {
- self.report_closure_arg_mismatch(
- span,
- found_span,
- found_trait_ref,
- expected_trait_ref,
- )
- } else {
- let (closure_span, found) = found_did
- .and_then(|did| self.tcx.hir().get_if_local(did))
- .map(|node| {
- let (found_span, found) = self.get_fn_like_arguments(node);
- (Some(found_span), found)
- })
- .unwrap_or((found_span, found));
-
- self.report_arg_count_mismatch(
- span,
- closure_span,
- expected,
- found,
- found_trait_ty.is_closure(),
- )
- }
- }
-
- TraitNotObjectSafe(did) => {
- let violations = object_safety_violations(self.tcx, did);
- report_object_safety_error(self.tcx, span, did, violations)
- }
-
- // already reported in the query
- ConstEvalFailure(err) => {
- if let ErrorHandled::TooGeneric = err {
- // Silence this error, as it can be produced during intermediate steps
- // when a constant is not yet able to be evaluated (but will be later).
- return;
- }
- self.tcx.sess.delay_span_bug(
- span,
- &format!("constant in type had an ignored error: {:?}", err),
- );
- return;
- }
-
- Overflow => {
- bug!("overflow should be handled before the `report_selection_error` path");
- }
- };
-
- self.note_obligation_cause(&mut err, obligation);
-
- err.emit();
- }
-
- /// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
- /// with the same path as `trait_ref`, a help message about
- /// a probable version mismatch is added to `err`
- fn note_version_mismatch(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- trait_ref: &ty::PolyTraitRef<'tcx>,
- ) {
- let get_trait_impl = |trait_def_id| {
- let mut trait_impl = None;
- self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
- if trait_impl.is_none() {
- trait_impl = Some(impl_def_id);
- }
- });
- trait_impl
- };
- let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
- let all_traits = self.tcx.all_traits(LOCAL_CRATE);
- let traits_with_same_path: std::collections::BTreeSet<_> = all_traits
- .iter()
- .filter(|trait_def_id| **trait_def_id != trait_ref.def_id())
- .filter(|trait_def_id| self.tcx.def_path_str(**trait_def_id) == required_trait_path)
- .collect();
- for trait_with_same_path in traits_with_same_path {
- if let Some(impl_def_id) = get_trait_impl(*trait_with_same_path) {
- let impl_span = self.tcx.def_span(impl_def_id);
- err.span_help(impl_span, "trait impl with same name found");
- let trait_crate = self.tcx.crate_name(trait_with_same_path.krate);
- let crate_msg = format!(
- "perhaps two different versions of crate `{}` are being used?",
- trait_crate
- );
- err.note(&crate_msg);
- }
- }
- }
- fn suggest_restricting_param_bound(
- &self,
- mut err: &mut DiagnosticBuilder<'_>,
- trait_ref: &ty::PolyTraitRef<'_>,
- body_id: hir::HirId,
- ) {
- let self_ty = trait_ref.self_ty();
- let (param_ty, projection) = match &self_ty.kind {
- ty::Param(_) => (true, None),
- ty::Projection(projection) => (false, Some(projection)),
- _ => return,
- };
-
- let suggest_restriction =
- |generics: &hir::Generics<'_>, msg, err: &mut DiagnosticBuilder<'_>| {
- let span = generics.where_clause.span_for_predicates_or_empty_place();
- if !span.from_expansion() && span.desugaring_kind().is_none() {
- err.span_suggestion(
- generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
- &format!("consider further restricting {}", msg),
- format!(
- "{} {} ",
- if !generics.where_clause.predicates.is_empty() {
- ","
- } else {
- " where"
- },
- trait_ref.to_predicate(),
- ),
- Applicability::MachineApplicable,
- );
- }
- };
-
- // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
- // don't suggest `T: Sized + ?Sized`.
- let mut hir_id = body_id;
- while let Some(node) = self.tcx.hir().find(hir_id) {
- match node {
- hir::Node::TraitItem(hir::TraitItem {
- generics,
- kind: hir::TraitItemKind::Method(..),
- ..
- }) if param_ty && self_ty == self.tcx.types.self_param => {
- // Restricting `Self` for a single method.
- suggest_restriction(&generics, "`Self`", err);
- return;
- }
-
- hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
- | hir::Node::TraitItem(hir::TraitItem {
- generics,
- kind: hir::TraitItemKind::Method(..),
- ..
- })
- | hir::Node::ImplItem(hir::ImplItem {
- generics,
- kind: hir::ImplItemKind::Method(..),
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Trait(_, _, generics, _, _),
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Impl(_, _, _, generics, ..),
- ..
- }) if projection.is_some() => {
- // Missing associated type bound.
- suggest_restriction(&generics, "the associated type", err);
- return;
- }
-
- hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Struct(_, generics),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Enum(_, generics), span, ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Union(_, generics),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Trait(_, _, generics, ..),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Impl(_, _, _, generics, ..),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Fn(_, generics, _),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::TyAlias(_, generics),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::TraitAlias(generics, _),
- span,
- ..
- })
- | hir::Node::Item(hir::Item {
- kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }),
- span,
- ..
- })
- | hir::Node::TraitItem(hir::TraitItem { generics, span, .. })
- | hir::Node::ImplItem(hir::ImplItem { generics, span, .. })
- if param_ty =>
- {
- // Missing generic type parameter bound.
- let param_name = self_ty.to_string();
- let constraint = trait_ref.print_only_trait_path().to_string();
- if suggest_constraining_type_param(
- generics,
- &mut err,
- ¶m_name,
- &constraint,
- self.tcx.sess.source_map(),
- *span,
- ) {
- return;
- }
- }
-
- hir::Node::Crate => return,
-
- _ => {}
- }
-
- hir_id = self.tcx.hir().get_parent_item(hir_id);
- }
- }
-
- /// When encountering an assignment of an unsized trait, like `let x = ""[..];`, provide a
- /// suggestion to borrow the initializer in order to use have a slice instead.
- fn suggest_borrow_on_unsized_slice(
- &self,
- code: &ObligationCauseCode<'tcx>,
- err: &mut DiagnosticBuilder<'tcx>,
- ) {
- if let &ObligationCauseCode::VariableType(hir_id) = code {
- let parent_node = self.tcx.hir().get_parent_node(hir_id);
- if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
- if let Some(ref expr) = local.init {
- if let hir::ExprKind::Index(_, _) = expr.kind {
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
- err.span_suggestion(
- expr.span,
- "consider borrowing here",
- format!("&{}", snippet),
- Applicability::MachineApplicable,
- );
- }
- }
- }
- }
- }
- }
-
- fn mk_obligation_for_def_id(
- &self,
- def_id: DefId,
- output_ty: Ty<'tcx>,
- cause: ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- ) -> PredicateObligation<'tcx> {
- let new_trait_ref =
- ty::TraitRef { def_id, substs: self.tcx.mk_substs_trait(output_ty, &[]) };
- Obligation::new(cause, param_env, new_trait_ref.to_predicate())
- }
-
- /// Given a closure's `DefId`, return the given name of the closure.
- ///
- /// This doesn't account for reassignments, but it's only used for suggestions.
- fn get_closure_name(
- &self,
- def_id: DefId,
- err: &mut DiagnosticBuilder<'_>,
- msg: &str,
- ) -> Option<String> {
- let get_name =
- |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
- // Get the local name of this closure. This can be inaccurate because
- // of the possibility of reassignment, but this should be good enough.
- match &kind {
- hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
- Some(format!("{}", name))
- }
- _ => {
- err.note(&msg);
- None
- }
- }
- };
-
- let hir = self.tcx.hir();
- let hir_id = hir.as_local_hir_id(def_id)?;
- let parent_node = hir.get_parent_node(hir_id);
- match hir.find(parent_node) {
- Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => {
- get_name(err, &local.pat.kind)
- }
- // Different to previous arm because one is `&hir::Local` and the other
- // is `P<hir::Local>`.
- Some(hir::Node::Local(local)) => get_name(err, &local.pat.kind),
- _ => return None,
- }
- }
-
- /// We tried to apply the bound to an `fn` or closure. Check whether calling it would
- /// evaluate to a type that *would* satisfy the trait binding. If it would, suggest calling
- /// it: `bar(foo)` → `bar(foo())`. This case is *very* likely to be hit if `foo` is `async`.
- fn suggest_fn_call(
- &self,
- obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'_>,
- trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
- points_at_arg: bool,
- ) {
- let self_ty = trait_ref.self_ty();
- let (def_id, output_ty, callable) = match self_ty.kind {
- ty::Closure(def_id, substs) => {
- (def_id, self.closure_sig(def_id, substs).output(), "closure")
- }
- ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
- _ => return,
- };
- let msg = format!("use parentheses to call the {}", callable);
-
- let obligation = self.mk_obligation_for_def_id(
- trait_ref.def_id(),
- output_ty.skip_binder(),
- obligation.cause.clone(),
- obligation.param_env,
- );
-
- match self.evaluate_obligation(&obligation) {
- Ok(EvaluationResult::EvaluatedToOk)
- | Ok(EvaluationResult::EvaluatedToOkModuloRegions)
- | Ok(EvaluationResult::EvaluatedToAmbig) => {}
- _ => return,
- }
- let hir = self.tcx.hir();
- // Get the name of the callable and the arguments to be used in the suggestion.
- let snippet = match hir.get_if_local(def_id) {
- Some(hir::Node::Expr(hir::Expr {
- kind: hir::ExprKind::Closure(_, decl, _, span, ..),
- ..
- })) => {
- err.span_label(*span, "consider calling this closure");
- let name = match self.get_closure_name(def_id, err, &msg) {
- Some(name) => name,
- None => return,
- };
- let args = decl.inputs.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
- format!("{}({})", name, args)
- }
- Some(hir::Node::Item(hir::Item {
- ident,
- kind: hir::ItemKind::Fn(.., body_id),
- ..
- })) => {
- err.span_label(ident.span, "consider calling this function");
- let body = hir.body(*body_id);
- let args = body
- .params
- .iter()
- .map(|arg| match &arg.pat.kind {
- hir::PatKind::Binding(_, _, ident, None)
- // FIXME: provide a better suggestion when encountering `SelfLower`, it
- // should suggest a method call.
- if ident.name != kw::SelfLower => ident.to_string(),
- _ => "_".to_string(),
- })
- .collect::<Vec<_>>()
- .join(", ");
- format!("{}({})", ident, args)
- }
- _ => return,
- };
- if points_at_arg {
- // When the obligation error has been ensured to have been caused by
- // an argument, the `obligation.cause.span` points at the expression
- // of the argument, so we can provide a suggestion. This is signaled
- // by `points_at_arg`. Otherwise, we give a more general note.
- err.span_suggestion(
- obligation.cause.span,
- &msg,
- snippet,
- Applicability::HasPlaceholders,
- );
- } else {
- err.help(&format!("{}: `{}`", msg, snippet));
- }
- }
-
- fn suggest_add_reference_to_arg(
- &self,
- obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'tcx>,
- trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
- points_at_arg: bool,
- has_custom_message: bool,
- ) -> bool {
- if !points_at_arg {
- return false;
- }
-
- let span = obligation.cause.span;
- let param_env = obligation.param_env;
- let trait_ref = trait_ref.skip_binder();
-
- if let ObligationCauseCode::ImplDerivedObligation(obligation) = &obligation.cause.code {
- // Try to apply the original trait binding obligation by borrowing.
- let self_ty = trait_ref.self_ty();
- let found = self_ty.to_string();
- let new_self_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, self_ty);
- let substs = self.tcx.mk_substs_trait(new_self_ty, &[]);
- let new_trait_ref = ty::TraitRef::new(obligation.parent_trait_ref.def_id(), substs);
- let new_obligation =
- Obligation::new(ObligationCause::dummy(), param_env, new_trait_ref.to_predicate());
- if self.predicate_must_hold_modulo_regions(&new_obligation) {
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
- // We have a very specific type of error, where just borrowing this argument
- // might solve the problem. In cases like this, the important part is the
- // original type obligation, not the last one that failed, which is arbitrary.
- // Because of this, we modify the error to refer to the original obligation and
- // return early in the caller.
- let msg = format!(
- "the trait bound `{}: {}` is not satisfied",
- found,
- obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
- );
- if has_custom_message {
- err.note(&msg);
- } else {
- err.message = vec![(msg, Style::NoStyle)];
- }
- if snippet.starts_with('&') {
- // This is already a literal borrow and the obligation is failing
- // somewhere else in the obligation chain. Do not suggest non-sense.
- return false;
- }
- err.span_label(
- span,
- &format!(
- "expected an implementor of trait `{}`",
- obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
- ),
- );
- err.span_suggestion(
- span,
- "consider borrowing here",
- format!("&{}", snippet),
- Applicability::MaybeIncorrect,
- );
- return true;
- }
- }
- }
- false
- }
-
- /// Whenever references are used by mistake, like `for (i, e) in &vec.iter().enumerate()`,
- /// suggest removing these references until we reach a type that implements the trait.
- fn suggest_remove_reference(
- &self,
- obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'tcx>,
- trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
- ) {
- let trait_ref = trait_ref.skip_binder();
- let span = obligation.cause.span;
-
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
- let refs_number =
- snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
- if let Some('\'') =
- snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
- {
- // Do not suggest removal of borrow from type arguments.
- return;
- }
-
- let mut trait_type = trait_ref.self_ty();
-
- for refs_remaining in 0..refs_number {
- if let ty::Ref(_, t_type, _) = trait_type.kind {
- trait_type = t_type;
-
- let new_obligation = self.mk_obligation_for_def_id(
- trait_ref.def_id,
- trait_type,
- ObligationCause::dummy(),
- obligation.param_env,
- );
-
- if self.predicate_may_hold(&new_obligation) {
- let sp = self
- .tcx
- .sess
- .source_map()
- .span_take_while(span, |c| c.is_whitespace() || *c == '&');
-
- let remove_refs = refs_remaining + 1;
- let format_str =
- format!("consider removing {} leading `&`-references", remove_refs);
-
- err.span_suggestion_short(
- sp,
- &format_str,
- String::new(),
- Applicability::MachineApplicable,
- );
- break;
- }
- } else {
- break;
- }
- }
- }
- }
-
- /// Check if the trait bound is implemented for a different mutability and note it in the
- /// final error.
- fn suggest_change_mut(
- &self,
- obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'tcx>,
- trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
- points_at_arg: bool,
- ) {
- let span = obligation.cause.span;
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
- let refs_number =
- snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
- if let Some('\'') =
- snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
- {
- // Do not suggest removal of borrow from type arguments.
- return;
- }
- let trait_ref = self.resolve_vars_if_possible(trait_ref);
- if trait_ref.has_infer_types() {
- // Do not ICE while trying to find if a reborrow would succeed on a trait with
- // unresolved bindings.
- return;
- }
-
- if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
- let trait_type = match mutability {
- hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
- hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
- };
-
- let new_obligation = self.mk_obligation_for_def_id(
- trait_ref.skip_binder().def_id,
- trait_type,
- ObligationCause::dummy(),
- obligation.param_env,
- );
-
- if self.evaluate_obligation_no_overflow(&new_obligation).must_apply_modulo_regions()
- {
- let sp = self
- .tcx
- .sess
- .source_map()
- .span_take_while(span, |c| c.is_whitespace() || *c == '&');
- if points_at_arg && mutability == hir::Mutability::Not && refs_number > 0 {
- err.span_suggestion(
- sp,
- "consider changing this borrow's mutability",
- "&mut ".to_string(),
- Applicability::MachineApplicable,
- );
- } else {
- err.note(&format!(
- "`{}` is implemented for `{:?}`, but not for `{:?}`",
- trait_ref.print_only_trait_path(),
- trait_type,
- trait_ref.skip_binder().self_ty(),
- ));
- }
- }
- }
- }
- }
-
- fn suggest_semicolon_removal(
- &self,
- obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'tcx>,
- span: Span,
- trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
- ) {
- let hir = self.tcx.hir();
- let parent_node = hir.get_parent_node(obligation.cause.body_id);
- let node = hir.find(parent_node);
- if let Some(hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Fn(sig, _, body_id), ..
- })) = node
- {
- let body = hir.body(*body_id);
- if let hir::ExprKind::Block(blk, _) = &body.value.kind {
- if sig.decl.output.span().overlaps(span)
- && blk.expr.is_none()
- && "()" == &trait_ref.self_ty().to_string()
- {
- // FIXME(estebank): When encountering a method with a trait
- // bound not satisfied in the return type with a body that has
- // no return, suggest removal of semicolon on last statement.
- // Once that is added, close #54771.
- if let Some(ref stmt) = blk.stmts.last() {
- let sp = self.tcx.sess.source_map().end_point(stmt.span);
- err.span_label(sp, "consider removing this semicolon");
- }
- }
- }
- }
- }
-
- /// Given some node representing a fn-like thing in the HIR map,
- /// returns a span and `ArgKind` information that describes the
- /// arguments it expects. This can be supplied to
- /// `report_arg_count_mismatch`.
- pub fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>) {
- match node {
- Node::Expr(&hir::Expr {
- kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
- ..
- }) => (
- self.tcx.sess.source_map().def_span(span),
- self.tcx
- .hir()
- .body(id)
- .params
- .iter()
- .map(|arg| {
- if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
- *arg.pat
- {
- ArgKind::Tuple(
- Some(span),
- args.iter()
- .map(|pat| {
- let snippet = self
- .tcx
- .sess
- .source_map()
- .span_to_snippet(pat.span)
- .unwrap();
- (snippet, "_".to_owned())
- })
- .collect::<Vec<_>>(),
- )
- } else {
- let name =
- self.tcx.sess.source_map().span_to_snippet(arg.pat.span).unwrap();
- ArgKind::Arg(name, "_".to_owned())
- }
- })
- .collect::<Vec<ArgKind>>(),
- ),
- Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
- | Node::ImplItem(&hir::ImplItem {
- span,
- kind: hir::ImplItemKind::Method(ref sig, _),
- ..
- })
- | Node::TraitItem(&hir::TraitItem {
- span,
- kind: hir::TraitItemKind::Method(ref sig, _),
- ..
- }) => (
- self.tcx.sess.source_map().def_span(span),
- sig.decl
- .inputs
- .iter()
- .map(|arg| match arg.clone().kind {
- hir::TyKind::Tup(ref tys) => ArgKind::Tuple(
- Some(arg.span),
- vec![("_".to_owned(), "_".to_owned()); tys.len()],
- ),
- _ => ArgKind::empty(),
- })
- .collect::<Vec<ArgKind>>(),
- ),
- Node::Ctor(ref variant_data) => {
- let span = variant_data
- .ctor_hir_id()
- .map(|hir_id| self.tcx.hir().span(hir_id))
- .unwrap_or(DUMMY_SP);
- let span = self.tcx.sess.source_map().def_span(span);
-
- (span, vec![ArgKind::empty(); variant_data.fields().len()])
- }
- _ => panic!("non-FnLike node found: {:?}", node),
- }
- }
-
- /// Reports an error when the number of arguments needed by a
- /// trait match doesn't match the number that the expression
- /// provides.
- pub fn report_arg_count_mismatch(
- &self,
- span: Span,
- found_span: Option<Span>,
- expected_args: Vec<ArgKind>,
- found_args: Vec<ArgKind>,
- is_closure: bool,
- ) -> DiagnosticBuilder<'tcx> {
- let kind = if is_closure { "closure" } else { "function" };
-
- let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
- let arg_length = arguments.len();
- let distinct = match &other[..] {
- &[ArgKind::Tuple(..)] => true,
- _ => false,
- };
- match (arg_length, arguments.get(0)) {
- (1, Some(&ArgKind::Tuple(_, ref fields))) => {
- format!("a single {}-tuple as argument", fields.len())
- }
- _ => format!(
- "{} {}argument{}",
- arg_length,
- if distinct && arg_length > 1 { "distinct " } else { "" },
- pluralize!(arg_length)
- ),
- }
- };
-
- let expected_str = args_str(&expected_args, &found_args);
- let found_str = args_str(&found_args, &expected_args);
-
- let mut err = struct_span_err!(
- self.tcx.sess,
- span,
- E0593,
- "{} is expected to take {}, but it takes {}",
- kind,
- expected_str,
- found_str,
- );
-
- err.span_label(span, format!("expected {} that takes {}", kind, expected_str));
-
- if let Some(found_span) = found_span {
- err.span_label(found_span, format!("takes {}", found_str));
-
- // move |_| { ... }
- // ^^^^^^^^-- def_span
- //
- // move |_| { ... }
- // ^^^^^-- prefix
- let prefix_span = self.tcx.sess.source_map().span_until_non_whitespace(found_span);
- // move |_| { ... }
- // ^^^-- pipe_span
- let pipe_span =
- if let Some(span) = found_span.trim_start(prefix_span) { span } else { found_span };
-
- // Suggest to take and ignore the arguments with expected_args_length `_`s if
- // found arguments is empty (assume the user just wants to ignore args in this case).
- // For example, if `expected_args_length` is 2, suggest `|_, _|`.
- if found_args.is_empty() && is_closure {
- let underscores = vec!["_"; expected_args.len()].join(", ");
- err.span_suggestion(
- pipe_span,
- &format!(
- "consider changing the closure to take and ignore the expected argument{}",
- if expected_args.len() < 2 { "" } else { "s" }
- ),
- format!("|{}|", underscores),
- Applicability::MachineApplicable,
- );
- }
-
- if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] {
- if fields.len() == expected_args.len() {
- let sugg = fields
- .iter()
- .map(|(name, _)| name.to_owned())
- .collect::<Vec<String>>()
- .join(", ");
- err.span_suggestion(
- found_span,
- "change the closure to take multiple arguments instead of a single tuple",
- format!("|{}|", sugg),
- Applicability::MachineApplicable,
- );
- }
- }
- if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
- if fields.len() == found_args.len() && is_closure {
- let sugg = format!(
- "|({}){}|",
- found_args
- .iter()
- .map(|arg| match arg {
- ArgKind::Arg(name, _) => name.to_owned(),
- _ => "_".to_owned(),
- })
- .collect::<Vec<String>>()
- .join(", "),
- // add type annotations if available
- if found_args.iter().any(|arg| match arg {
- ArgKind::Arg(_, ty) => ty != "_",
- _ => false,
- }) {
- format!(
- ": ({})",
- fields
- .iter()
- .map(|(_, ty)| ty.to_owned())
- .collect::<Vec<String>>()
- .join(", ")
- )
- } else {
- String::new()
- },
- );
- err.span_suggestion(
- found_span,
- "change the closure to accept a tuple instead of individual arguments",
- sugg,
- Applicability::MachineApplicable,
- );
- }
- }
- }
-
- err
- }
-
- fn report_closure_arg_mismatch(
- &self,
- span: Span,
- found_span: Option<Span>,
- expected_ref: ty::PolyTraitRef<'tcx>,
- found: ty::PolyTraitRef<'tcx>,
- ) -> DiagnosticBuilder<'tcx> {
- fn build_fn_sig_string<'tcx>(tcx: TyCtxt<'tcx>, trait_ref: &ty::TraitRef<'tcx>) -> String {
- let inputs = trait_ref.substs.type_at(1);
- let sig = if let ty::Tuple(inputs) = inputs.kind {
- tcx.mk_fn_sig(
- inputs.iter().map(|k| k.expect_ty()),
- tcx.mk_ty_infer(ty::TyVar(ty::TyVid { index: 0 })),
- false,
- hir::Unsafety::Normal,
- ::rustc_target::spec::abi::Abi::Rust,
- )
- } else {
- tcx.mk_fn_sig(
- ::std::iter::once(inputs),
- tcx.mk_ty_infer(ty::TyVar(ty::TyVid { index: 0 })),
- false,
- hir::Unsafety::Normal,
- ::rustc_target::spec::abi::Abi::Rust,
- )
- };
- ty::Binder::bind(sig).to_string()
- }
-
- let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
- let mut err = struct_span_err!(
- self.tcx.sess,
- span,
- E0631,
- "type mismatch in {} arguments",
- if argument_is_closure { "closure" } else { "function" }
- );
-
- let found_str = format!(
- "expected signature of `{}`",
- build_fn_sig_string(self.tcx, found.skip_binder())
- );
- err.span_label(span, found_str);
-
- let found_span = found_span.unwrap_or(span);
- let expected_str = format!(
- "found signature of `{}`",
- build_fn_sig_string(self.tcx, expected_ref.skip_binder())
- );
- err.span_label(found_span, expected_str);
-
- err
- }
-}
-
-pub fn recursive_type_with_infinite_size_error(
- tcx: TyCtxt<'tcx>,
- type_def_id: DefId,
-) -> DiagnosticBuilder<'tcx> {
- assert!(type_def_id.is_local());
- let span = tcx.hir().span_if_local(type_def_id).unwrap();
- let span = tcx.sess.source_map().def_span(span);
- let mut err = struct_span_err!(
- tcx.sess,
- span,
- E0072,
- "recursive type `{}` has infinite size",
- tcx.def_path_str(type_def_id)
- );
- err.span_label(span, "recursive type has infinite size");
- err.help(&format!(
- "insert indirection (e.g., a `Box`, `Rc`, or `&`) \
- at some point to make `{}` representable",
- tcx.def_path_str(type_def_id)
- ));
- err
-}
-
-pub fn report_object_safety_error(
- tcx: TyCtxt<'tcx>,
- span: Span,
- trait_def_id: DefId,
- violations: Vec<ObjectSafetyViolation>,
-) -> DiagnosticBuilder<'tcx> {
- let trait_str = tcx.def_path_str(trait_def_id);
- let span = tcx.sess.source_map().def_span(span);
- let mut err = struct_span_err!(
- tcx.sess,
- span,
- E0038,
- "the trait `{}` cannot be made into an object",
- trait_str
- );
- err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));
-
- let mut reported_violations = FxHashSet::default();
- for violation in violations {
- if reported_violations.insert(violation.clone()) {
- match violation.span() {
- Some(span) => err.span_label(span, violation.error_msg()),
- None => err.note(&violation.error_msg()),
- };
- }
- }
-
- if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
- // Avoid emitting error caused by non-existing method (#58734)
- err.cancel();
- }
-
- err
-}
-
-impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
- fn maybe_report_ambiguity(
- &self,
- obligation: &PredicateObligation<'tcx>,
- body_id: Option<hir::BodyId>,
- ) {
- // Unable to successfully determine, probably means
- // insufficient type information, but could mean
- // ambiguous impls. The latter *ought* to be a
- // coherence violation, so we don't report it here.
-
- let predicate = self.resolve_vars_if_possible(&obligation.predicate);
- let span = obligation.cause.span;
-
- debug!(
- "maybe_report_ambiguity(predicate={:?}, obligation={:?} body_id={:?}, code={:?})",
- predicate, obligation, body_id, obligation.cause.code,
- );
-
- // Ambiguity errors are often caused as fallout from earlier
- // errors. So just ignore them if this infcx is tainted.
- if self.is_tainted_by_errors() {
- return;
- }
-
- let mut err = match predicate {
- ty::Predicate::Trait(ref data) => {
- let trait_ref = data.to_poly_trait_ref();
- let self_ty = trait_ref.self_ty();
- debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
-
- if predicate.references_error() {
- return;
- }
- // Typically, this ambiguity should only happen if
- // there are unresolved type inference variables
- // (otherwise it would suggest a coherence
- // failure). But given #21974 that is not necessarily
- // the case -- we can have multiple where clauses that
- // are only distinguished by a region, which results
- // in an ambiguity even when all types are fully
- // known, since we don't dispatch based on region
- // relationships.
-
- // This is kind of a hack: it frequently happens that some earlier
- // error prevents types from being fully inferred, and then we get
- // a bunch of uninteresting errors saying something like "<generic
- // #0> doesn't implement Sized". It may even be true that we
- // could just skip over all checks where the self-ty is an
- // inference variable, but I was afraid that there might be an
- // inference variable created, registered as an obligation, and
- // then never forced by writeback, and hence by skipping here we'd
- // be ignoring the fact that we don't KNOW the type works
- // out. Though even that would probably be harmless, given that
- // we're only talking about builtin traits, which are known to be
- // inhabited. We used to check for `self.tcx.sess.has_errors()` to
- // avoid inundating the user with unnecessary errors, but we now
- // check upstream for type errors and dont add the obligations to
- // begin with in those cases.
- if self
- .tcx
- .lang_items()
- .sized_trait()
- .map_or(false, |sized_id| sized_id == trait_ref.def_id())
- {
- self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0282).emit();
- return;
- }
- let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0283);
- err.note(&format!("cannot resolve `{}`", predicate));
- if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
- self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
- } else if let (
- Ok(ref snippet),
- ObligationCauseCode::BindingObligation(ref def_id, _),
- ) =
- (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code)
- {
- let generics = self.tcx.generics_of(*def_id);
- if !generics.params.is_empty() && !snippet.ends_with('>') {
- // FIXME: To avoid spurious suggestions in functions where type arguments
- // where already supplied, we check the snippet to make sure it doesn't
- // end with a turbofish. Ideally we would have access to a `PathSegment`
- // instead. Otherwise we would produce the following output:
- //
- // error[E0283]: type annotations needed
- // --> $DIR/issue-54954.rs:3:24
- // |
- // LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
- // | ^^^^^^^^^^^^^^^^^^^^^^^^^^
- // | |
- // | cannot infer type
- // | help: consider specifying the type argument
- // | in the function call:
- // | `Tt::const_val::<[i8; 123]>::<T>`
- // ...
- // LL | const fn const_val<T: Sized>() -> usize {
- // | --------- - required by this bound in `Tt::const_val`
- // |
- // = note: cannot resolve `_: Tt`
-
- err.span_suggestion(
- span,
- &format!(
- "consider specifying the type argument{} in the function call",
- if generics.params.len() > 1 { "s" } else { "" },
- ),
- format!(
- "{}::<{}>",
- snippet,
- generics
- .params
- .iter()
- .map(|p| p.name.to_string())
- .collect::<Vec<String>>()
- .join(", ")
- ),
- Applicability::HasPlaceholders,
- );
- }
- }
- err
- }
-
- ty::Predicate::WellFormed(ty) => {
- // Same hacky approach as above to avoid deluging user
- // with error messages.
- if ty.references_error() || self.tcx.sess.has_errors() {
- return;
- }
- self.need_type_info_err(body_id, span, ty, ErrorCode::E0282)
- }
-
- ty::Predicate::Subtype(ref data) => {
- if data.references_error() || self.tcx.sess.has_errors() {
- // no need to overload user in such cases
- return;
- }
- let &SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder();
- // both must be type variables, or the other would've been instantiated
- assert!(a.is_ty_var() && b.is_ty_var());
- self.need_type_info_err(body_id, span, a, ErrorCode::E0282)
- }
- ty::Predicate::Projection(ref data) => {
- let trait_ref = data.to_poly_trait_ref(self.tcx);
- let self_ty = trait_ref.self_ty();
- if predicate.references_error() {
- return;
- }
- let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284);
- err.note(&format!("cannot resolve `{}`", predicate));
- err
- }
-
- _ => {
- if self.tcx.sess.has_errors() {
- return;
- }
- let mut err = struct_span_err!(
- self.tcx.sess,
- span,
- E0284,
- "type annotations needed: cannot resolve `{}`",
- predicate,
- );
- err.span_label(span, &format!("cannot resolve `{}`", predicate));
- err
- }
- };
- self.note_obligation_cause(&mut err, obligation);
- err.emit();
- }
-
- fn suggest_fully_qualified_path(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- def_id: DefId,
- span: Span,
- trait_ref: DefId,
- ) {
- if let Some(assoc_item) = self.tcx.opt_associated_item(def_id) {
- if let ty::AssocKind::Const | ty::AssocKind::Type = assoc_item.kind {
- err.note(&format!(
- "{}s cannot be accessed directly on a `trait`, they can only be \
- accessed through a specific `impl`",
- assoc_item.kind.suggestion_descr(),
- ));
- err.span_suggestion(
- span,
- "use the fully qualified path to an implementation",
- format!("<Type as {}>::{}", self.tcx.def_path_str(trait_ref), assoc_item.ident),
- Applicability::HasPlaceholders,
- );
- }
- }
- }
-
- /// Returns `true` if the trait predicate may apply for *some* assignment
- /// to the type parameters.
- fn predicate_can_apply(
- &self,
- param_env: ty::ParamEnv<'tcx>,
- pred: ty::PolyTraitRef<'tcx>,
- ) -> bool {
- struct ParamToVarFolder<'a, 'tcx> {
- infcx: &'a InferCtxt<'a, 'tcx>,
- var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>,
- }
-
- impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx> {
- fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
- self.infcx.tcx
- }
-
- fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
- if let ty::Param(ty::ParamTy { name, .. }) = ty.kind {
- let infcx = self.infcx;
- self.var_map.entry(ty).or_insert_with(|| {
- infcx.next_ty_var(TypeVariableOrigin {
- kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
- span: DUMMY_SP,
- })
- })
- } else {
- ty.super_fold_with(self)
- }
- }
- }
-
- self.probe(|_| {
- let mut selcx = SelectionContext::new(self);
-
- let cleaned_pred =
- pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
-
- let cleaned_pred = super::project::normalize(
- &mut selcx,
- param_env,
- ObligationCause::dummy(),
- &cleaned_pred,
- )
- .value;
-
- let obligation =
- Obligation::new(ObligationCause::dummy(), param_env, cleaned_pred.to_predicate());
-
- self.predicate_may_hold(&obligation)
- })
- }
-
- fn note_obligation_cause(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- obligation: &PredicateObligation<'tcx>,
- ) {
- // First, attempt to add note to this error with an async-await-specific
- // message, and fall back to regular note otherwise.
- if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
- self.note_obligation_cause_code(
- err,
- &obligation.predicate,
- &obligation.cause.code,
- &mut vec![],
- );
- }
- }
-
- /// Adds an async-await specific note to the diagnostic when the future does not implement
- /// an auto trait because of a captured type.
- ///
- /// ```ignore (diagnostic)
- /// note: future does not implement `Qux` as this value is used across an await
- /// --> $DIR/issue-64130-3-other.rs:17:5
- /// |
- /// LL | let x = Foo;
- /// | - has type `Foo`
- /// LL | baz().await;
- /// | ^^^^^^^^^^^ await occurs here, with `x` maybe used later
- /// LL | }
- /// | - `x` is later dropped here
- /// ```
- ///
- /// When the diagnostic does not implement `Send` or `Sync` specifically, then the diagnostic
- /// is "replaced" with a different message and a more specific error.
- ///
- /// ```ignore (diagnostic)
- /// error: future cannot be sent between threads safely
- /// --> $DIR/issue-64130-2-send.rs:21:5
- /// |
- /// LL | fn is_send<T: Send>(t: T) { }
- /// | ------- ---- required by this bound in `is_send`
- /// ...
- /// LL | is_send(bar());
- /// | ^^^^^^^ future returned by `bar` is not send
- /// |
- /// = help: within `impl std::future::Future`, the trait `std::marker::Send` is not
- /// implemented for `Foo`
- /// note: future is not send as this value is used across an await
- /// --> $DIR/issue-64130-2-send.rs:15:5
- /// |
- /// LL | let x = Foo;
- /// | - has type `Foo`
- /// LL | baz().await;
- /// | ^^^^^^^^^^^ await occurs here, with `x` maybe used later
- /// LL | }
- /// | - `x` is later dropped here
- /// ```
- ///
- /// Returns `true` if an async-await specific note was added to the diagnostic.
- fn maybe_note_obligation_cause_for_async_await(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- obligation: &PredicateObligation<'tcx>,
- ) -> bool {
- debug!(
- "maybe_note_obligation_cause_for_async_await: obligation.predicate={:?} \
- obligation.cause.span={:?}",
- obligation.predicate, obligation.cause.span
- );
- let source_map = self.tcx.sess.source_map();
-
- // Attempt to detect an async-await error by looking at the obligation causes, looking
- // for a generator to be present.
- //
- // When a future does not implement a trait because of a captured type in one of the
- // generators somewhere in the call stack, then the result is a chain of obligations.
- //
- // Given a `async fn` A that calls a `async fn` B which captures a non-send type and that
- // future is passed as an argument to a function C which requires a `Send` type, then the
- // chain looks something like this:
- //
- // - `BuiltinDerivedObligation` with a generator witness (B)
- // - `BuiltinDerivedObligation` with a generator (B)
- // - `BuiltinDerivedObligation` with `std::future::GenFuture` (B)
- // - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
- // - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
- // - `BuiltinDerivedObligation` with a generator witness (A)
- // - `BuiltinDerivedObligation` with a generator (A)
- // - `BuiltinDerivedObligation` with `std::future::GenFuture` (A)
- // - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
- // - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
- // - `BindingObligation` with `impl_send (Send requirement)
- //
- // The first obligation in the chain is the most useful and has the generator that captured
- // the type. The last generator has information about where the bound was introduced. At
- // least one generator should be present for this diagnostic to be modified.
- let (mut trait_ref, mut target_ty) = match obligation.predicate {
- ty::Predicate::Trait(p) => {
- (Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
- }
- _ => (None, None),
- };
- let mut generator = None;
- let mut last_generator = None;
- let mut next_code = Some(&obligation.cause.code);
- while let Some(code) = next_code {
- debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
- match code {
- ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
- | ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
- let ty = derived_obligation.parent_trait_ref.self_ty();
- debug!(
- "maybe_note_obligation_cause_for_async_await: \
- parent_trait_ref={:?} self_ty.kind={:?}",
- derived_obligation.parent_trait_ref, ty.kind
- );
-
- match ty.kind {
- ty::Generator(did, ..) => {
- generator = generator.or(Some(did));
- last_generator = Some(did);
- }
- ty::GeneratorWitness(..) => {}
- _ if generator.is_none() => {
- trait_ref = Some(*derived_obligation.parent_trait_ref.skip_binder());
- target_ty = Some(ty);
- }
- _ => {}
- }
-
- next_code = Some(derived_obligation.parent_code.as_ref());
- }
- _ => break,
- }
- }
-
- // Only continue if a generator was found.
- debug!(
- "maybe_note_obligation_cause_for_async_await: generator={:?} trait_ref={:?} \
- target_ty={:?}",
- generator, trait_ref, target_ty
- );
- let (generator_did, trait_ref, target_ty) = match (generator, trait_ref, target_ty) {
- (Some(generator_did), Some(trait_ref), Some(target_ty)) => {
- (generator_did, trait_ref, target_ty)
- }
- _ => return false,
- };
-
- let span = self.tcx.def_span(generator_did);
-
- // Do not ICE on closure typeck (#66868).
- if self.tcx.hir().as_local_hir_id(generator_did).is_none() {
- return false;
- }
-
- // Get the tables from the infcx if the generator is the function we are
- // currently type-checking; otherwise, get them by performing a query.
- // This is needed to avoid cycles.
- let in_progress_tables = self.in_progress_tables.map(|t| t.borrow());
- let generator_did_root = self.tcx.closure_base_def_id(generator_did);
- debug!(
- "maybe_note_obligation_cause_for_async_await: generator_did={:?} \
- generator_did_root={:?} in_progress_tables.local_id_root={:?} span={:?}",
- generator_did,
- generator_did_root,
- in_progress_tables.as_ref().map(|t| t.local_id_root),
- span
- );
- let query_tables;
- let tables: &TypeckTables<'tcx> = match &in_progress_tables {
- Some(t) if t.local_id_root == Some(generator_did_root) => t,
- _ => {
- query_tables = self.tcx.typeck_tables_of(generator_did);
- &query_tables
- }
- };
-
- // Look for a type inside the generator interior that matches the target type to get
- // a span.
- let target_ty_erased = self.tcx.erase_regions(&target_ty);
- let target_span = tables
- .generator_interior_types
- .iter()
- .find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
- // Careful: the regions for types that appear in the
- // generator interior are not generally known, so we
- // want to erase them when comparing (and anyway,
- // `Send` and other bounds are generally unaffected by
- // the choice of region). When erasing regions, we
- // also have to erase late-bound regions. This is
- // because the types that appear in the generator
- // interior generally contain "bound regions" to
- // represent regions that are part of the suspended
- // generator frame. Bound regions are preserved by
- // `erase_regions` and so we must also call
- // `erase_late_bound_regions`.
- let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(*ty));
- let ty_erased = self.tcx.erase_regions(&ty_erased);
- let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
- debug!(
- "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
- target_ty_erased={:?} eq={:?}",
- ty_erased, target_ty_erased, eq
- );
- eq
- })
- .map(|ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. }| {
- (span, source_map.span_to_snippet(*span), scope_span, expr)
- });
-
- debug!(
- "maybe_note_obligation_cause_for_async_await: target_ty={:?} \
- generator_interior_types={:?} target_span={:?}",
- target_ty, tables.generator_interior_types, target_span
- );
- if let Some((target_span, Ok(snippet), scope_span, expr)) = target_span {
- self.note_obligation_cause_for_async_await(
- err,
- *target_span,
- scope_span,
- *expr,
- snippet,
- generator_did,
- last_generator,
- trait_ref,
- target_ty,
- tables,
- obligation,
- next_code,
- );
- true
- } else {
- false
- }
- }
-
- /// Unconditionally adds the diagnostic note described in
- /// `maybe_note_obligation_cause_for_async_await`'s documentation comment.
- fn note_obligation_cause_for_async_await(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- target_span: Span,
- scope_span: &Option<Span>,
- expr: Option<hir::HirId>,
- snippet: String,
- first_generator: DefId,
- last_generator: Option<DefId>,
- trait_ref: ty::TraitRef<'_>,
- target_ty: Ty<'tcx>,
- tables: &ty::TypeckTables<'_>,
- obligation: &PredicateObligation<'tcx>,
- next_code: Option<&ObligationCauseCode<'tcx>>,
- ) {
- let source_map = self.tcx.sess.source_map();
-
- let is_async_fn = self
- .tcx
- .parent(first_generator)
- .map(|parent_did| self.tcx.asyncness(parent_did))
- .map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
- .unwrap_or(false);
- let is_async_move = self
- .tcx
- .hir()
- .as_local_hir_id(first_generator)
- .and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
- .map(|body_id| self.tcx.hir().body(body_id))
- .and_then(|body| body.generator_kind())
- .map(|generator_kind| match generator_kind {
- hir::GeneratorKind::Async(..) => true,
- _ => false,
- })
- .unwrap_or(false);
- let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
-
- // Special case the primary error message when send or sync is the trait that was
- // not implemented.
- let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id);
- let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id);
- let hir = self.tcx.hir();
- let trait_explanation = if is_send || is_sync {
- let (trait_name, trait_verb) =
- if is_send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
-
- err.clear_code();
- err.set_primary_message(format!(
- "future cannot be {} between threads safely",
- trait_verb
- ));
-
- let original_span = err.span.primary_span().unwrap();
- let mut span = MultiSpan::from_span(original_span);
-
- let message = if let Some(name) = last_generator
- .and_then(|generator_did| self.tcx.parent(generator_did))
- .and_then(|parent_did| hir.as_local_hir_id(parent_did))
- .and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
- {
- format!("future returned by `{}` is not {}", name, trait_name)
- } else {
- format!("future is not {}", trait_name)
- };
-
- span.push_span_label(original_span, message);
- err.set_span(span);
-
- format!("is not {}", trait_name)
- } else {
- format!("does not implement `{}`", trait_ref.print_only_trait_path())
- };
-
- // Look at the last interior type to get a span for the `.await`.
- let await_span = tables.generator_interior_types.iter().map(|t| t.span).last().unwrap();
- let mut span = MultiSpan::from_span(await_span);
- span.push_span_label(
- await_span,
- format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
- );
-
- span.push_span_label(target_span, format!("has type `{}`", target_ty));
-
- // If available, use the scope span to annotate the drop location.
- if let Some(scope_span) = scope_span {
- span.push_span_label(
- source_map.end_point(*scope_span),
- format!("`{}` is later dropped here", snippet),
- );
- }
-
- err.span_note(
- span,
- &format!(
- "future {} as this value is used across an {}",
- trait_explanation, await_or_yield,
- ),
- );
-
- if let Some(expr_id) = expr {
- let expr = hir.expect_expr(expr_id);
- let is_ref = tables.expr_adjustments(expr).iter().any(|adj| adj.is_region_borrow());
- let parent = hir.get_parent_node(expr_id);
- if let Some(hir::Node::Expr(e)) = hir.find(parent) {
- let method_span = hir.span(parent);
- if tables.is_method_call(e) && is_ref {
- err.span_help(
- method_span,
- "consider moving this method call into a `let` \
- binding to create a shorter lived borrow",
- );
- }
- }
- }
-
- // Add a note for the item obligation that remains - normally a note pointing to the
- // bound that introduced the obligation (e.g. `T: Send`).
- debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code);
- self.note_obligation_cause_code(
- err,
- &obligation.predicate,
- next_code.unwrap(),
- &mut Vec::new(),
- );
- }
-
- fn note_obligation_cause_code<T>(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- predicate: &T,
- cause_code: &ObligationCauseCode<'tcx>,
- obligated_types: &mut Vec<&ty::TyS<'tcx>>,
- ) where
- T: fmt::Display,
- {
- let tcx = self.tcx;
- match *cause_code {
- ObligationCauseCode::ExprAssignable
- | ObligationCauseCode::MatchExpressionArm { .. }
- | ObligationCauseCode::Pattern { .. }
- | ObligationCauseCode::IfExpression { .. }
- | ObligationCauseCode::IfExpressionWithNoElse
- | ObligationCauseCode::MainFunctionType
- | ObligationCauseCode::StartFunctionType
- | ObligationCauseCode::IntrinsicType
- | ObligationCauseCode::MethodReceiver
- | ObligationCauseCode::ReturnNoExpression
- | ObligationCauseCode::MiscObligation => {}
- ObligationCauseCode::SliceOrArrayElem => {
- err.note("slice and array elements must have `Sized` type");
- }
- ObligationCauseCode::TupleElem => {
- err.note("only the last element of a tuple may have a dynamically sized type");
- }
- ObligationCauseCode::ProjectionWf(data) => {
- err.note(&format!("required so that the projection `{}` is well-formed", data,));
- }
- ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
- err.note(&format!(
- "required so that reference `{}` does not outlive its referent",
- ref_ty,
- ));
- }
- ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
- err.note(&format!(
- "required so that the lifetime bound of `{}` for `{}` is satisfied",
- region, object_ty,
- ));
- }
- ObligationCauseCode::ItemObligation(item_def_id) => {
- let item_name = tcx.def_path_str(item_def_id);
- let msg = format!("required by `{}`", item_name);
-
- if let Some(sp) = tcx.hir().span_if_local(item_def_id) {
- let sp = tcx.sess.source_map().def_span(sp);
- err.span_label(sp, &msg);
- } else {
- err.note(&msg);
- }
- }
- ObligationCauseCode::BindingObligation(item_def_id, span) => {
- let item_name = tcx.def_path_str(item_def_id);
- let msg = format!("required by this bound in `{}`", item_name);
- if let Some(ident) = tcx.opt_item_name(item_def_id) {
- err.span_label(ident.span, "");
- }
- if span != DUMMY_SP {
- err.span_label(span, &msg);
- } else {
- err.note(&msg);
- }
- }
- ObligationCauseCode::ObjectCastObligation(object_ty) => {
- err.note(&format!(
- "required for the cast to the object type `{}`",
- self.ty_to_string(object_ty)
- ));
- }
- ObligationCauseCode::Coercion { source: _, target } => {
- err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
- }
- ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expressions) => {
- err.note(
- "the `Copy` trait is required because the \
- repeated element will be copied",
- );
- if suggest_const_in_array_repeat_expressions {
- err.note(
- "this array initializer can be evaluated at compile-time, for more \
- information, see issue \
- https://github.com/rust-lang/rust/issues/49147",
- );
- if tcx.sess.opts.unstable_features.is_nightly_build() {
- err.help(
- "add `#![feature(const_in_array_repeat_expressions)]` to the \
- crate attributes to enable",
- );
- }
- }
- }
- ObligationCauseCode::VariableType(_) => {
- err.note("all local variables must have a statically known size");
- if !self.tcx.features().unsized_locals {
- err.help("unsized locals are gated as an unstable feature");
- }
- }
- ObligationCauseCode::SizedArgumentType => {
- err.note("all function arguments must have a statically known size");
- if !self.tcx.features().unsized_locals {
- err.help("unsized locals are gated as an unstable feature");
- }
- }
- ObligationCauseCode::SizedReturnType => {
- err.note(
- "the return type of a function must have a \
- statically known size",
- );
- }
- ObligationCauseCode::SizedYieldType => {
- err.note(
- "the yield type of a generator must have a \
- statically known size",
- );
- }
- ObligationCauseCode::AssignmentLhsSized => {
- err.note("the left-hand-side of an assignment must have a statically known size");
- }
- ObligationCauseCode::TupleInitializerSized => {
- err.note("tuples must have a statically known size to be initialized");
- }
- ObligationCauseCode::StructInitializerSized => {
- err.note("structs must have a statically known size to be initialized");
- }
- ObligationCauseCode::FieldSized { adt_kind: ref item, last } => match *item {
- AdtKind::Struct => {
- if last {
- err.note(
- "the last field of a packed struct may only have a \
- dynamically sized type if it does not need drop to be run",
- );
- } else {
- err.note(
- "only the last field of a struct may have a dynamically \
- sized type",
- );
- }
- }
- AdtKind::Union => {
- err.note("no field of a union may have a dynamically sized type");
- }
- AdtKind::Enum => {
- err.note("no field of an enum variant may have a dynamically sized type");
- }
- },
- ObligationCauseCode::ConstSized => {
- err.note("constant expressions must have a statically known size");
- }
- ObligationCauseCode::ConstPatternStructural => {
- err.note("constants used for pattern-matching must derive `PartialEq` and `Eq`");
- }
- ObligationCauseCode::SharedStatic => {
- err.note("shared static variables must have a type that implements `Sync`");
- }
- ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
- let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
- let ty = parent_trait_ref.skip_binder().self_ty();
- err.note(&format!("required because it appears within the type `{}`", ty));
- obligated_types.push(ty);
-
- let parent_predicate = parent_trait_ref.to_predicate();
- if !self.is_recursive_obligation(obligated_types, &data.parent_code) {
- self.note_obligation_cause_code(
- err,
- &parent_predicate,
- &data.parent_code,
- obligated_types,
- );
- }
- }
- ObligationCauseCode::ImplDerivedObligation(ref data) => {
- let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
- err.note(&format!(
- "required because of the requirements on the impl of `{}` for `{}`",
- parent_trait_ref.print_only_trait_path(),
- parent_trait_ref.skip_binder().self_ty()
- ));
- let parent_predicate = parent_trait_ref.to_predicate();
- self.note_obligation_cause_code(
- err,
- &parent_predicate,
- &data.parent_code,
- obligated_types,
- );
- }
- ObligationCauseCode::CompareImplMethodObligation { .. } => {
- err.note(&format!(
- "the requirement `{}` appears on the impl method \
- but not on the corresponding trait method",
- predicate
- ));
- }
- ObligationCauseCode::CompareImplTypeObligation { .. } => {
- err.note(&format!(
- "the requirement `{}` appears on the associated impl type\
- but not on the corresponding associated trait type",
- predicate
- ));
- }
- ObligationCauseCode::ReturnType
- | ObligationCauseCode::ReturnValue(_)
- | ObligationCauseCode::BlockTailExpression(_) => (),
- ObligationCauseCode::TrivialBound => {
- err.help("see issue #48214");
- if tcx.sess.opts.unstable_features.is_nightly_build() {
- err.help(
- "add `#![feature(trivial_bounds)]` to the \
- crate attributes to enable",
- );
- }
- }
- ObligationCauseCode::AssocTypeBound(ref data) => {
- err.span_label(data.original, "associated type defined here");
- if let Some(sp) = data.impl_span {
- err.span_label(sp, "in this `impl` item");
- }
- for sp in &data.bounds {
- err.span_label(*sp, "restricted in this bound");
- }
- }
- }
- }
-
- fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
- let current_limit = self.tcx.sess.recursion_limit.get();
- let suggested_limit = current_limit * 2;
- err.help(&format!(
- "consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
- suggested_limit
- ));
- }
-
- fn is_recursive_obligation(
- &self,
- obligated_types: &mut Vec<&ty::TyS<'tcx>>,
- cause_code: &ObligationCauseCode<'tcx>,
- ) -> bool {
- if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
- let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
-
- if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) {
- return true;
- }
- }
- false
- }
-}
-
-/// Summarizes information
-#[derive(Clone)]
-pub enum ArgKind {
- /// An argument of non-tuple type. Parameters are (name, ty)
- Arg(String, String),
-
- /// An argument of tuple type. For a "found" argument, the span is
- /// the locationo in the source of the pattern. For a "expected"
- /// argument, it will be None. The vector is a list of (name, ty)
- /// strings for the components of the tuple.
- Tuple(Option<Span>, Vec<(String, String)>),
-}
-
-impl ArgKind {
- fn empty() -> ArgKind {
- ArgKind::Arg("_".to_owned(), "_".to_owned())
- }
-
- /// Creates an `ArgKind` from the expected type of an
- /// argument. It has no name (`_`) and an optional source span.
- pub fn from_expected_ty(t: Ty<'_>, span: Option<Span>) -> ArgKind {
- match t.kind {
- ty::Tuple(ref tys) => ArgKind::Tuple(
- span,
- tys.iter().map(|ty| ("_".to_owned(), ty.to_string())).collect::<Vec<_>>(),
- ),
- _ => ArgKind::Arg("_".to_owned(), t.to_string()),
- }
- }
-}
-
-/// Suggest restricting a type param with a new bound.
-pub fn suggest_constraining_type_param(
- generics: &hir::Generics<'_>,
- err: &mut DiagnosticBuilder<'_>,
- param_name: &str,
- constraint: &str,
- source_map: &SourceMap,
- span: Span,
-) -> bool {
- let restrict_msg = "consider further restricting this bound";
- if let Some(param) =
- generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next()
- {
- if param_name.starts_with("impl ") {
- // `impl Trait` in argument:
- // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
- err.span_suggestion(
- param.span,
- restrict_msg,
- // `impl CurrentTrait + MissingTrait`
- format!("{} + {}", param_name, constraint),
- Applicability::MachineApplicable,
- );
- } else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() {
- // If there are no bounds whatsoever, suggest adding a constraint
- // to the type parameter:
- // `fn foo<T>(t: T) {}` → `fn foo<T: Trait>(t: T) {}`
- err.span_suggestion(
- param.span,
- "consider restricting this bound",
- format!("{}: {}", param_name, constraint),
- Applicability::MachineApplicable,
- );
- } else if !generics.where_clause.predicates.is_empty() {
- // There is a `where` clause, so suggest expanding it:
- // `fn foo<T>(t: T) where T: Debug {}` →
- // `fn foo<T>(t: T) where T: Debug, T: Trait {}`
- err.span_suggestion(
- generics.where_clause.span().unwrap().shrink_to_hi(),
- &format!("consider further restricting type parameter `{}`", param_name),
- format!(", {}: {}", param_name, constraint),
- Applicability::MachineApplicable,
- );
- } else {
- // If there is no `where` clause lean towards constraining to the
- // type parameter:
- // `fn foo<X: Bar, T>(t: T, x: X) {}` → `fn foo<T: Trait>(t: T) {}`
- // `fn foo<T: Bar>(t: T) {}` → `fn foo<T: Bar + Trait>(t: T) {}`
- let sp = param.span.with_hi(span.hi());
- let span = source_map.span_through_char(sp, ':');
- if sp != param.span && sp != span {
- // Only suggest if we have high certainty that the span
- // covers the colon in `foo<T: Trait>`.
- err.span_suggestion(
- span,
- restrict_msg,
- format!("{}: {} + ", param_name, constraint),
- Applicability::MachineApplicable,
- );
- } else {
- err.span_label(
- param.span,
- &format!("consider adding a `where {}: {}` bound", param_name, constraint),
- );
- }
- }
- return true;
- }
- false
-}
--- /dev/null
+pub mod on_unimplemented;
+pub mod suggestions;
+
+use super::{
+ ConstEvalFailure, EvaluationResult, FulfillmentError, FulfillmentErrorCode,
+ MismatchedProjectionTypes, ObjectSafetyViolation, Obligation, ObligationCause,
+ ObligationCauseCode, OnUnimplementedDirective, OnUnimplementedNote,
+ OutputTypeParameterMismatch, Overflow, PredicateObligation, SelectionContext, SelectionError,
+ TraitNotObjectSafe,
+};
+
+use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
+use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
+use crate::infer::{self, InferCtxt};
+use crate::mir::interpret::ErrorHandled;
+use crate::session::DiagnosticMessageId;
+use crate::traits::object_safety_violations;
+use crate::ty::error::ExpectedFound;
+use crate::ty::fast_reject;
+use crate::ty::fold::TypeFolder;
+use crate::ty::SubtypePredicate;
+use crate::ty::{self, AdtKind, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
+
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
+use rustc_hir as hir;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
+use rustc_span::source_map::SourceMap;
+use rustc_span::{ExpnKind, Span, DUMMY_SP};
+use std::fmt;
+use syntax::ast;
+
+impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
+ pub fn report_fulfillment_errors(
+ &self,
+ errors: &[FulfillmentError<'tcx>],
+ body_id: Option<hir::BodyId>,
+ fallback_has_occurred: bool,
+ ) {
+ #[derive(Debug)]
+ struct ErrorDescriptor<'tcx> {
+ predicate: ty::Predicate<'tcx>,
+ index: Option<usize>, // None if this is an old error
+ }
+
+ let mut error_map: FxHashMap<_, Vec<_>> = self
+ .reported_trait_errors
+ .borrow()
+ .iter()
+ .map(|(&span, predicates)| {
+ (
+ span,
+ predicates
+ .iter()
+ .map(|predicate| ErrorDescriptor {
+ predicate: predicate.clone(),
+ index: None,
+ })
+ .collect(),
+ )
+ })
+ .collect();
+
+ for (index, error) in errors.iter().enumerate() {
+ // We want to ignore desugarings here: spans are equivalent even
+ // if one is the result of a desugaring and the other is not.
+ let mut span = error.obligation.cause.span;
+ let expn_data = span.ctxt().outer_expn_data();
+ if let ExpnKind::Desugaring(_) = expn_data.kind {
+ span = expn_data.call_site;
+ }
+
+ error_map.entry(span).or_default().push(ErrorDescriptor {
+ predicate: error.obligation.predicate.clone(),
+ index: Some(index),
+ });
+
+ self.reported_trait_errors
+ .borrow_mut()
+ .entry(span)
+ .or_default()
+ .push(error.obligation.predicate.clone());
+ }
+
+ // We do this in 2 passes because we want to display errors in order, though
+ // maybe it *is* better to sort errors by span or something.
+ let mut is_suppressed = vec![false; errors.len()];
+ for (_, error_set) in error_map.iter() {
+ // We want to suppress "duplicate" errors with the same span.
+ for error in error_set {
+ if let Some(index) = error.index {
+ // Suppress errors that are either:
+ // 1) strictly implied by another error.
+ // 2) implied by an error with a smaller index.
+ for error2 in error_set {
+ if error2.index.map_or(false, |index2| is_suppressed[index2]) {
+ // Avoid errors being suppressed by already-suppressed
+ // errors, to prevent all errors from being suppressed
+ // at once.
+ continue;
+ }
+
+ if self.error_implies(&error2.predicate, &error.predicate)
+ && !(error2.index >= error.index
+ && self.error_implies(&error.predicate, &error2.predicate))
+ {
+ info!("skipping {:?} (implied by {:?})", error, error2);
+ is_suppressed[index] = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ for (error, suppressed) in errors.iter().zip(is_suppressed) {
+ if !suppressed {
+ self.report_fulfillment_error(error, body_id, fallback_has_occurred);
+ }
+ }
+ }
+
+ // returns if `cond` not occurring implies that `error` does not occur - i.e., that
+ // `error` occurring implies that `cond` occurs.
+ fn error_implies(&self, cond: &ty::Predicate<'tcx>, error: &ty::Predicate<'tcx>) -> bool {
+ if cond == error {
+ return true;
+ }
+
+ let (cond, error) = match (cond, error) {
+ (&ty::Predicate::Trait(..), &ty::Predicate::Trait(ref error)) => (cond, error),
+ _ => {
+ // FIXME: make this work in other cases too.
+ return false;
+ }
+ };
+
+ for implication in super::elaborate_predicates(self.tcx, vec![cond.clone()]) {
+ if let ty::Predicate::Trait(implication) = implication {
+ let error = error.to_poly_trait_ref();
+ let implication = implication.to_poly_trait_ref();
+ // FIXME: I'm just not taking associated types at all here.
+ // Eventually I'll need to implement param-env-aware
+ // `Γ₁ ⊦ φ₁ => Γ₂ ⊦ φ₂` logic.
+ let param_env = ty::ParamEnv::empty();
+ if self.can_sub(param_env, error, implication).is_ok() {
+ debug!("error_implies: {:?} -> {:?} -> {:?}", cond, error, implication);
+ return true;
+ }
+ }
+ }
+
+ false
+ }
+
+ fn report_fulfillment_error(
+ &self,
+ error: &FulfillmentError<'tcx>,
+ body_id: Option<hir::BodyId>,
+ fallback_has_occurred: bool,
+ ) {
+ debug!("report_fulfillment_error({:?})", error);
+ match error.code {
+ FulfillmentErrorCode::CodeSelectionError(ref selection_error) => {
+ self.report_selection_error(
+ &error.obligation,
+ selection_error,
+ fallback_has_occurred,
+ error.points_at_arg_span,
+ );
+ }
+ FulfillmentErrorCode::CodeProjectionError(ref e) => {
+ self.report_projection_error(&error.obligation, e);
+ }
+ FulfillmentErrorCode::CodeAmbiguity => {
+ self.maybe_report_ambiguity(&error.obligation, body_id);
+ }
+ FulfillmentErrorCode::CodeSubtypeError(ref expected_found, ref err) => {
+ self.report_mismatched_types(
+ &error.obligation.cause,
+ expected_found.expected,
+ expected_found.found,
+ err.clone(),
+ )
+ .emit();
+ }
+ }
+ }
+
+ fn report_projection_error(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ error: &MismatchedProjectionTypes<'tcx>,
+ ) {
+ let predicate = self.resolve_vars_if_possible(&obligation.predicate);
+
+ if predicate.references_error() {
+ return;
+ }
+
+ self.probe(|_| {
+ let err_buf;
+ let mut err = &error.err;
+ let mut values = None;
+
+ // try to find the mismatched types to report the error with.
+ //
+ // this can fail if the problem was higher-ranked, in which
+ // cause I have no idea for a good error message.
+ if let ty::Predicate::Projection(ref data) = predicate {
+ let mut selcx = SelectionContext::new(self);
+ let (data, _) = self.replace_bound_vars_with_fresh_vars(
+ obligation.cause.span,
+ infer::LateBoundRegionConversionTime::HigherRankedType,
+ data,
+ );
+ let mut obligations = vec![];
+ let normalized_ty = super::normalize_projection_type(
+ &mut selcx,
+ obligation.param_env,
+ data.projection_ty,
+ obligation.cause.clone(),
+ 0,
+ &mut obligations,
+ );
+
+ debug!(
+ "report_projection_error obligation.cause={:?} obligation.param_env={:?}",
+ obligation.cause, obligation.param_env
+ );
+
+ debug!(
+ "report_projection_error normalized_ty={:?} data.ty={:?}",
+ normalized_ty, data.ty
+ );
+
+ let is_normalized_ty_expected = match &obligation.cause.code {
+ ObligationCauseCode::ItemObligation(_)
+ | ObligationCauseCode::BindingObligation(_, _)
+ | ObligationCauseCode::ObjectCastObligation(_) => false,
+ _ => true,
+ };
+
+ if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
+ is_normalized_ty_expected,
+ normalized_ty,
+ data.ty,
+ ) {
+ values = Some(infer::ValuePairs::Types(ExpectedFound::new(
+ is_normalized_ty_expected,
+ normalized_ty,
+ data.ty,
+ )));
+
+ err_buf = error;
+ err = &err_buf;
+ }
+ }
+
+ let msg = format!("type mismatch resolving `{}`", predicate);
+ let error_id = (DiagnosticMessageId::ErrorId(271), Some(obligation.cause.span), msg);
+ let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
+ if fresh {
+ let mut diag = struct_span_err!(
+ self.tcx.sess,
+ obligation.cause.span,
+ E0271,
+ "type mismatch resolving `{}`",
+ predicate
+ );
+ self.note_type_err(&mut diag, &obligation.cause, None, values, err);
+ self.note_obligation_cause(&mut diag, obligation);
+ diag.emit();
+ }
+ });
+ }
+
+ fn fuzzy_match_tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
+ /// returns the fuzzy category of a given type, or None
+ /// if the type can be equated to any type.
+ fn type_category(t: Ty<'_>) -> Option<u32> {
+ match t.kind {
+ ty::Bool => Some(0),
+ ty::Char => Some(1),
+ ty::Str => Some(2),
+ ty::Int(..) | ty::Uint(..) | ty::Infer(ty::IntVar(..)) => Some(3),
+ ty::Float(..) | ty::Infer(ty::FloatVar(..)) => Some(4),
+ ty::Ref(..) | ty::RawPtr(..) => Some(5),
+ ty::Array(..) | ty::Slice(..) => Some(6),
+ ty::FnDef(..) | ty::FnPtr(..) => Some(7),
+ ty::Dynamic(..) => Some(8),
+ ty::Closure(..) => Some(9),
+ ty::Tuple(..) => Some(10),
+ ty::Projection(..) => Some(11),
+ ty::Param(..) => Some(12),
+ ty::Opaque(..) => Some(13),
+ ty::Never => Some(14),
+ ty::Adt(adt, ..) => match adt.adt_kind() {
+ AdtKind::Struct => Some(15),
+ AdtKind::Union => Some(16),
+ AdtKind::Enum => Some(17),
+ },
+ ty::Generator(..) => Some(18),
+ ty::Foreign(..) => Some(19),
+ ty::GeneratorWitness(..) => Some(20),
+ ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error => None,
+ ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
+ }
+ }
+
+ match (type_category(a), type_category(b)) {
+ (Some(cat_a), Some(cat_b)) => match (&a.kind, &b.kind) {
+ (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => def_a == def_b,
+ _ => cat_a == cat_b,
+ },
+ // infer and error can be equated to all types
+ _ => true,
+ }
+ }
+
+ fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> {
+ self.tcx.hir().body(body_id).generator_kind.map(|gen_kind| match gen_kind {
+ hir::GeneratorKind::Gen => "a generator",
+ hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) => "an async block",
+ hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn) => "an async function",
+ hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure) => "an async closure",
+ })
+ }
+
+ fn find_similar_impl_candidates(
+ &self,
+ trait_ref: ty::PolyTraitRef<'tcx>,
+ ) -> Vec<ty::TraitRef<'tcx>> {
+ let simp = fast_reject::simplify_type(self.tcx, trait_ref.skip_binder().self_ty(), true);
+ let all_impls = self.tcx.all_impls(trait_ref.def_id());
+
+ match simp {
+ Some(simp) => all_impls
+ .iter()
+ .filter_map(|&def_id| {
+ let imp = self.tcx.impl_trait_ref(def_id).unwrap();
+ let imp_simp = fast_reject::simplify_type(self.tcx, imp.self_ty(), true);
+ if let Some(imp_simp) = imp_simp {
+ if simp != imp_simp {
+ return None;
+ }
+ }
+
+ Some(imp)
+ })
+ .collect(),
+ None => {
+ all_impls.iter().map(|&def_id| self.tcx.impl_trait_ref(def_id).unwrap()).collect()
+ }
+ }
+ }
+
+ fn report_similar_impl_candidates(
+ &self,
+ impl_candidates: Vec<ty::TraitRef<'tcx>>,
+ err: &mut DiagnosticBuilder<'_>,
+ ) {
+ if impl_candidates.is_empty() {
+ return;
+ }
+
+ let len = impl_candidates.len();
+ let end = if impl_candidates.len() <= 5 { impl_candidates.len() } else { 4 };
+
+ let normalize = |candidate| {
+ self.tcx.infer_ctxt().enter(|ref infcx| {
+ let normalized = infcx
+ .at(&ObligationCause::dummy(), ty::ParamEnv::empty())
+ .normalize(candidate)
+ .ok();
+ match normalized {
+ Some(normalized) => format!("\n {:?}", normalized.value),
+ None => format!("\n {:?}", candidate),
+ }
+ })
+ };
+
+ // Sort impl candidates so that ordering is consistent for UI tests.
+ let mut normalized_impl_candidates =
+ impl_candidates.iter().map(normalize).collect::<Vec<String>>();
+
+ // Sort before taking the `..end` range,
+ // because the ordering of `impl_candidates` may not be deterministic:
+ // https://github.com/rust-lang/rust/pull/57475#issuecomment-455519507
+ normalized_impl_candidates.sort();
+
+ err.help(&format!(
+ "the following implementations were found:{}{}",
+ normalized_impl_candidates[..end].join(""),
+ if len > 5 { format!("\nand {} others", len - 4) } else { String::new() }
+ ));
+ }
+
+ /// Reports that an overflow has occurred and halts compilation. We
+ /// halt compilation unconditionally because it is important that
+ /// overflows never be masked -- they basically represent computations
+ /// whose result could not be truly determined and thus we can't say
+ /// if the program type checks or not -- and they are unusual
+ /// occurrences in any case.
+ pub fn report_overflow_error<T>(
+ &self,
+ obligation: &Obligation<'tcx, T>,
+ suggest_increasing_limit: bool,
+ ) -> !
+ where
+ T: fmt::Display + TypeFoldable<'tcx>,
+ {
+ let predicate = self.resolve_vars_if_possible(&obligation.predicate);
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ obligation.cause.span,
+ E0275,
+ "overflow evaluating the requirement `{}`",
+ predicate
+ );
+
+ if suggest_increasing_limit {
+ self.suggest_new_overflow_limit(&mut err);
+ }
+
+ self.note_obligation_cause_code(
+ &mut err,
+ &obligation.predicate,
+ &obligation.cause.code,
+ &mut vec![],
+ );
+
+ err.emit();
+ self.tcx.sess.abort_if_errors();
+ bug!();
+ }
+
+ /// Reports that a cycle was detected which led to overflow and halts
+ /// compilation. This is equivalent to `report_overflow_error` except
+ /// that we can give a more helpful error message (and, in particular,
+ /// we do not suggest increasing the overflow limit, which is not
+ /// going to help).
+ pub fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! {
+ let cycle = self.resolve_vars_if_possible(&cycle.to_owned());
+ assert!(cycle.len() > 0);
+
+ debug!("report_overflow_error_cycle: cycle={:?}", cycle);
+
+ self.report_overflow_error(&cycle[0], false);
+ }
+
+ pub fn report_extra_impl_obligation(
+ &self,
+ error_span: Span,
+ item_name: ast::Name,
+ _impl_item_def_id: DefId,
+ trait_item_def_id: DefId,
+ requirement: &dyn fmt::Display,
+ ) -> DiagnosticBuilder<'tcx> {
+ let msg = "impl has stricter requirements than trait";
+ let sp = self.tcx.sess.source_map().def_span(error_span);
+
+ let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
+
+ if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
+ let span = self.tcx.sess.source_map().def_span(trait_item_span);
+ err.span_label(span, format!("definition of `{}` from trait", item_name));
+ }
+
+ err.span_label(sp, format!("impl has extra requirement {}", requirement));
+
+ err
+ }
+
+ /// Gets the parent trait chain start
+ fn get_parent_trait_ref(
+ &self,
+ code: &ObligationCauseCode<'tcx>,
+ ) -> Option<(String, Option<Span>)> {
+ match code {
+ &ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
+ let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
+ match self.get_parent_trait_ref(&data.parent_code) {
+ Some(t) => Some(t),
+ None => {
+ let ty = parent_trait_ref.skip_binder().self_ty();
+ let span =
+ TyCategory::from_ty(ty).map(|(_, def_id)| self.tcx.def_span(def_id));
+ Some((ty.to_string(), span))
+ }
+ }
+ }
+ _ => None,
+ }
+ }
+
+ pub fn report_selection_error(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ error: &SelectionError<'tcx>,
+ fallback_has_occurred: bool,
+ points_at_arg: bool,
+ ) {
+ let tcx = self.tcx;
+ let span = obligation.cause.span;
+
+ let mut err = match *error {
+ SelectionError::Unimplemented => {
+ if let ObligationCauseCode::CompareImplMethodObligation {
+ item_name,
+ impl_item_def_id,
+ trait_item_def_id,
+ }
+ | ObligationCauseCode::CompareImplTypeObligation {
+ item_name,
+ impl_item_def_id,
+ trait_item_def_id,
+ } = obligation.cause.code
+ {
+ self.report_extra_impl_obligation(
+ span,
+ item_name,
+ impl_item_def_id,
+ trait_item_def_id,
+ &format!("`{}`", obligation.predicate),
+ )
+ .emit();
+ return;
+ }
+ match obligation.predicate {
+ ty::Predicate::Trait(ref trait_predicate) => {
+ let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
+
+ if self.tcx.sess.has_errors() && trait_predicate.references_error() {
+ return;
+ }
+ let trait_ref = trait_predicate.to_poly_trait_ref();
+ let (post_message, pre_message, type_def) = self
+ .get_parent_trait_ref(&obligation.cause.code)
+ .map(|(t, s)| {
+ (
+ format!(" in `{}`", t),
+ format!("within `{}`, ", t),
+ s.map(|s| (format!("within this `{}`", t), s)),
+ )
+ })
+ .unwrap_or_default();
+
+ let OnUnimplementedNote { message, label, note, enclosing_scope } =
+ self.on_unimplemented_note(trait_ref, obligation);
+ let have_alt_message = message.is_some() || label.is_some();
+ let is_try = self
+ .tcx
+ .sess
+ .source_map()
+ .span_to_snippet(span)
+ .map(|s| &s == "?")
+ .unwrap_or(false);
+ let is_from = format!("{}", trait_ref.print_only_trait_path())
+ .starts_with("std::convert::From<");
+ let (message, note) = if is_try && is_from {
+ (
+ Some(format!(
+ "`?` couldn't convert the error to `{}`",
+ trait_ref.self_ty(),
+ )),
+ Some(
+ "the question mark operation (`?`) implicitly performs a \
+ conversion on the error value using the `From` trait"
+ .to_owned(),
+ ),
+ )
+ } else {
+ (message, note)
+ };
+
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0277,
+ "{}",
+ message.unwrap_or_else(|| format!(
+ "the trait bound `{}` is not satisfied{}",
+ trait_ref.to_predicate(),
+ post_message,
+ ))
+ );
+
+ let explanation =
+ if obligation.cause.code == ObligationCauseCode::MainFunctionType {
+ "consider using `()`, or a `Result`".to_owned()
+ } else {
+ format!(
+ "{}the trait `{}` is not implemented for `{}`",
+ pre_message,
+ trait_ref.print_only_trait_path(),
+ trait_ref.self_ty(),
+ )
+ };
+
+ if self.suggest_add_reference_to_arg(
+ &obligation,
+ &mut err,
+ &trait_ref,
+ points_at_arg,
+ have_alt_message,
+ ) {
+ self.note_obligation_cause(&mut err, obligation);
+ err.emit();
+ return;
+ }
+ if let Some(ref s) = label {
+ // If it has a custom `#[rustc_on_unimplemented]`
+ // error message, let's display it as the label!
+ err.span_label(span, s.as_str());
+ err.help(&explanation);
+ } else {
+ err.span_label(span, explanation);
+ }
+ if let Some((msg, span)) = type_def {
+ err.span_label(span, &msg);
+ }
+ if let Some(ref s) = note {
+ // If it has a custom `#[rustc_on_unimplemented]` note, let's display it
+ err.note(s.as_str());
+ }
+ if let Some(ref s) = enclosing_scope {
+ let enclosing_scope_span = tcx.def_span(
+ tcx.hir()
+ .opt_local_def_id(obligation.cause.body_id)
+ .unwrap_or_else(|| {
+ tcx.hir().body_owner_def_id(hir::BodyId {
+ hir_id: obligation.cause.body_id,
+ })
+ }),
+ );
+
+ err.span_label(enclosing_scope_span, s.as_str());
+ }
+
+ self.suggest_borrow_on_unsized_slice(&obligation.cause.code, &mut err);
+ self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);
+ self.suggest_remove_reference(&obligation, &mut err, &trait_ref);
+ self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref);
+ self.note_version_mismatch(&mut err, &trait_ref);
+ if self.suggest_impl_trait(&mut err, span, &obligation, &trait_ref) {
+ err.emit();
+ return;
+ }
+
+ // Try to report a help message
+ if !trait_ref.has_infer_types()
+ && self.predicate_can_apply(obligation.param_env, trait_ref)
+ {
+ // If a where-clause may be useful, remind the
+ // user that they can add it.
+ //
+ // don't display an on-unimplemented note, as
+ // these notes will often be of the form
+ // "the type `T` can't be frobnicated"
+ // which is somewhat confusing.
+ self.suggest_restricting_param_bound(
+ &mut err,
+ &trait_ref,
+ obligation.cause.body_id,
+ );
+ } else {
+ if !have_alt_message {
+ // Can't show anything else useful, try to find similar impls.
+ let impl_candidates = self.find_similar_impl_candidates(trait_ref);
+ self.report_similar_impl_candidates(impl_candidates, &mut err);
+ }
+ self.suggest_change_mut(
+ &obligation,
+ &mut err,
+ &trait_ref,
+ points_at_arg,
+ );
+ }
+
+ // If this error is due to `!: Trait` not implemented but `(): Trait` is
+ // implemented, and fallback has occurred, then it could be due to a
+ // variable that used to fallback to `()` now falling back to `!`. Issue a
+ // note informing about the change in behaviour.
+ if trait_predicate.skip_binder().self_ty().is_never()
+ && fallback_has_occurred
+ {
+ let predicate = trait_predicate.map_bound(|mut trait_pred| {
+ trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
+ self.tcx.mk_unit(),
+ &trait_pred.trait_ref.substs[1..],
+ );
+ trait_pred
+ });
+ let unit_obligation = Obligation {
+ predicate: ty::Predicate::Trait(predicate),
+ ..obligation.clone()
+ };
+ if self.predicate_may_hold(&unit_obligation) {
+ err.note(
+ "the trait is implemented for `()`. \
+ Possibly this error has been caused by changes to \
+ Rust's type-inference algorithm \
+ (see: https://github.com/rust-lang/rust/issues/48950 \
+ for more info). Consider whether you meant to use the \
+ type `()` here instead.",
+ );
+ }
+ }
+
+ err
+ }
+
+ ty::Predicate::Subtype(ref predicate) => {
+ // Errors for Subtype predicates show up as
+ // `FulfillmentErrorCode::CodeSubtypeError`,
+ // not selection error.
+ span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
+ }
+
+ ty::Predicate::RegionOutlives(ref predicate) => {
+ let predicate = self.resolve_vars_if_possible(predicate);
+ let err = self
+ .region_outlives_predicate(&obligation.cause, &predicate)
+ .err()
+ .unwrap();
+ struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0279,
+ "the requirement `{}` is not satisfied (`{}`)",
+ predicate,
+ err,
+ )
+ }
+
+ ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => {
+ let predicate = self.resolve_vars_if_possible(&obligation.predicate);
+ struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0280,
+ "the requirement `{}` is not satisfied",
+ predicate
+ )
+ }
+
+ ty::Predicate::ObjectSafe(trait_def_id) => {
+ let violations = object_safety_violations(self.tcx, trait_def_id);
+ report_object_safety_error(self.tcx, span, trait_def_id, violations)
+ }
+
+ ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
+ let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
+ let closure_span = self
+ .tcx
+ .sess
+ .source_map()
+ .def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
+ let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap();
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ closure_span,
+ E0525,
+ "expected a closure that implements the `{}` trait, \
+ but this closure only implements `{}`",
+ kind,
+ found_kind
+ );
+
+ err.span_label(
+ closure_span,
+ format!("this closure implements `{}`, not `{}`", found_kind, kind),
+ );
+ err.span_label(
+ obligation.cause.span,
+ format!("the requirement to implement `{}` derives from here", kind),
+ );
+
+ // Additional context information explaining why the closure only implements
+ // a particular trait.
+ if let Some(tables) = self.in_progress_tables {
+ let tables = tables.borrow();
+ match (found_kind, tables.closure_kind_origins().get(hir_id)) {
+ (ty::ClosureKind::FnOnce, Some((span, name))) => {
+ err.span_label(
+ *span,
+ format!(
+ "closure is `FnOnce` because it moves the \
+ variable `{}` out of its environment",
+ name
+ ),
+ );
+ }
+ (ty::ClosureKind::FnMut, Some((span, name))) => {
+ err.span_label(
+ *span,
+ format!(
+ "closure is `FnMut` because it mutates the \
+ variable `{}` here",
+ name
+ ),
+ );
+ }
+ _ => {}
+ }
+ }
+
+ err.emit();
+ return;
+ }
+
+ ty::Predicate::WellFormed(ty) => {
+ if !self.tcx.sess.opts.debugging_opts.chalk {
+ // WF predicates cannot themselves make
+ // errors. They can only block due to
+ // ambiguity; otherwise, they always
+ // degenerate into other obligations
+ // (which may fail).
+ span_bug!(span, "WF predicate not satisfied for {:?}", ty);
+ } else {
+ // FIXME: we'll need a better message which takes into account
+ // which bounds actually failed to hold.
+ self.tcx.sess.struct_span_err(
+ span,
+ &format!("the type `{}` is not well-formed (chalk)", ty),
+ )
+ }
+ }
+
+ ty::Predicate::ConstEvaluatable(..) => {
+ // Errors for `ConstEvaluatable` predicates show up as
+ // `SelectionError::ConstEvalFailure`,
+ // not `Unimplemented`.
+ span_bug!(
+ span,
+ "const-evaluatable requirement gave wrong error: `{:?}`",
+ obligation
+ )
+ }
+ }
+ }
+
+ OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => {
+ let found_trait_ref = self.resolve_vars_if_possible(&*found_trait_ref);
+ let expected_trait_ref = self.resolve_vars_if_possible(&*expected_trait_ref);
+
+ if expected_trait_ref.self_ty().references_error() {
+ return;
+ }
+
+ let found_trait_ty = found_trait_ref.self_ty();
+
+ let found_did = match found_trait_ty.kind {
+ ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
+ ty::Adt(def, _) => Some(def.did),
+ _ => None,
+ };
+
+ let found_span = found_did
+ .and_then(|did| self.tcx.hir().span_if_local(did))
+ .map(|sp| self.tcx.sess.source_map().def_span(sp)); // the sp could be an fn def
+
+ if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
+ // We check closures twice, with obligations flowing in different directions,
+ // but we want to complain about them only once.
+ return;
+ }
+
+ self.reported_closure_mismatch.borrow_mut().insert((span, found_span));
+
+ let found = match found_trait_ref.skip_binder().substs.type_at(1).kind {
+ ty::Tuple(ref tys) => vec![ArgKind::empty(); tys.len()],
+ _ => vec![ArgKind::empty()],
+ };
+
+ let expected_ty = expected_trait_ref.skip_binder().substs.type_at(1);
+ let expected = match expected_ty.kind {
+ ty::Tuple(ref tys) => tys
+ .iter()
+ .map(|t| ArgKind::from_expected_ty(t.expect_ty(), Some(span)))
+ .collect(),
+ _ => vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())],
+ };
+
+ if found.len() == expected.len() {
+ self.report_closure_arg_mismatch(
+ span,
+ found_span,
+ found_trait_ref,
+ expected_trait_ref,
+ )
+ } else {
+ let (closure_span, found) = found_did
+ .and_then(|did| self.tcx.hir().get_if_local(did))
+ .map(|node| {
+ let (found_span, found) = self.get_fn_like_arguments(node);
+ (Some(found_span), found)
+ })
+ .unwrap_or((found_span, found));
+
+ self.report_arg_count_mismatch(
+ span,
+ closure_span,
+ expected,
+ found,
+ found_trait_ty.is_closure(),
+ )
+ }
+ }
+
+ TraitNotObjectSafe(did) => {
+ let violations = object_safety_violations(self.tcx, did);
+ report_object_safety_error(self.tcx, span, did, violations)
+ }
+
+ // already reported in the query
+ ConstEvalFailure(err) => {
+ if let ErrorHandled::TooGeneric = err {
+ // Silence this error, as it can be produced during intermediate steps
+ // when a constant is not yet able to be evaluated (but will be later).
+ return;
+ }
+ self.tcx.sess.delay_span_bug(
+ span,
+ &format!("constant in type had an ignored error: {:?}", err),
+ );
+ return;
+ }
+
+ Overflow => {
+ bug!("overflow should be handled before the `report_selection_error` path");
+ }
+ };
+
+ self.note_obligation_cause(&mut err, obligation);
+ self.point_at_returns_when_relevant(&mut err, &obligation);
+
+ err.emit();
+ }
+
+ /// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
+ /// with the same path as `trait_ref`, a help message about
+ /// a probable version mismatch is added to `err`
+ fn note_version_mismatch(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ trait_ref: &ty::PolyTraitRef<'tcx>,
+ ) {
+ let get_trait_impl = |trait_def_id| {
+ let mut trait_impl = None;
+ self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
+ if trait_impl.is_none() {
+ trait_impl = Some(impl_def_id);
+ }
+ });
+ trait_impl
+ };
+ let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
+ let all_traits = self.tcx.all_traits(LOCAL_CRATE);
+ let traits_with_same_path: std::collections::BTreeSet<_> = all_traits
+ .iter()
+ .filter(|trait_def_id| **trait_def_id != trait_ref.def_id())
+ .filter(|trait_def_id| self.tcx.def_path_str(**trait_def_id) == required_trait_path)
+ .collect();
+ for trait_with_same_path in traits_with_same_path {
+ if let Some(impl_def_id) = get_trait_impl(*trait_with_same_path) {
+ let impl_span = self.tcx.def_span(impl_def_id);
+ err.span_help(impl_span, "trait impl with same name found");
+ let trait_crate = self.tcx.crate_name(trait_with_same_path.krate);
+ let crate_msg = format!(
+ "perhaps two different versions of crate `{}` are being used?",
+ trait_crate
+ );
+ err.note(&crate_msg);
+ }
+ }
+ }
+
+ fn mk_obligation_for_def_id(
+ &self,
+ def_id: DefId,
+ output_ty: Ty<'tcx>,
+ cause: ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ ) -> PredicateObligation<'tcx> {
+ let new_trait_ref =
+ ty::TraitRef { def_id, substs: self.tcx.mk_substs_trait(output_ty, &[]) };
+ Obligation::new(cause, param_env, new_trait_ref.to_predicate())
+ }
+}
+
+pub fn recursive_type_with_infinite_size_error(
+ tcx: TyCtxt<'tcx>,
+ type_def_id: DefId,
+) -> DiagnosticBuilder<'tcx> {
+ assert!(type_def_id.is_local());
+ let span = tcx.hir().span_if_local(type_def_id).unwrap();
+ let span = tcx.sess.source_map().def_span(span);
+ let mut err = struct_span_err!(
+ tcx.sess,
+ span,
+ E0072,
+ "recursive type `{}` has infinite size",
+ tcx.def_path_str(type_def_id)
+ );
+ err.span_label(span, "recursive type has infinite size");
+ err.help(&format!(
+ "insert indirection (e.g., a `Box`, `Rc`, or `&`) \
+ at some point to make `{}` representable",
+ tcx.def_path_str(type_def_id)
+ ));
+ err
+}
+
+pub fn report_object_safety_error(
+ tcx: TyCtxt<'tcx>,
+ span: Span,
+ trait_def_id: DefId,
+ violations: Vec<ObjectSafetyViolation>,
+) -> DiagnosticBuilder<'tcx> {
+ let trait_str = tcx.def_path_str(trait_def_id);
+ let span = tcx.sess.source_map().def_span(span);
+ let mut err = struct_span_err!(
+ tcx.sess,
+ span,
+ E0038,
+ "the trait `{}` cannot be made into an object",
+ trait_str
+ );
+ err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));
+
+ let mut reported_violations = FxHashSet::default();
+ for violation in violations {
+ if reported_violations.insert(violation.clone()) {
+ match violation.span() {
+ Some(span) => err.span_label(span, violation.error_msg()),
+ None => err.note(&violation.error_msg()),
+ };
+ }
+ }
+
+ if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
+ // Avoid emitting error caused by non-existing method (#58734)
+ err.cancel();
+ }
+
+ err
+}
+
+impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
+ fn maybe_report_ambiguity(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ body_id: Option<hir::BodyId>,
+ ) {
+ // Unable to successfully determine, probably means
+ // insufficient type information, but could mean
+ // ambiguous impls. The latter *ought* to be a
+ // coherence violation, so we don't report it here.
+
+ let predicate = self.resolve_vars_if_possible(&obligation.predicate);
+ let span = obligation.cause.span;
+
+ debug!(
+ "maybe_report_ambiguity(predicate={:?}, obligation={:?} body_id={:?}, code={:?})",
+ predicate, obligation, body_id, obligation.cause.code,
+ );
+
+ // Ambiguity errors are often caused as fallout from earlier
+ // errors. So just ignore them if this infcx is tainted.
+ if self.is_tainted_by_errors() {
+ return;
+ }
+
+ let mut err = match predicate {
+ ty::Predicate::Trait(ref data) => {
+ let trait_ref = data.to_poly_trait_ref();
+ let self_ty = trait_ref.self_ty();
+ debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
+
+ if predicate.references_error() {
+ return;
+ }
+ // Typically, this ambiguity should only happen if
+ // there are unresolved type inference variables
+ // (otherwise it would suggest a coherence
+ // failure). But given #21974 that is not necessarily
+ // the case -- we can have multiple where clauses that
+ // are only distinguished by a region, which results
+ // in an ambiguity even when all types are fully
+ // known, since we don't dispatch based on region
+ // relationships.
+
+ // This is kind of a hack: it frequently happens that some earlier
+ // error prevents types from being fully inferred, and then we get
+ // a bunch of uninteresting errors saying something like "<generic
+ // #0> doesn't implement Sized". It may even be true that we
+ // could just skip over all checks where the self-ty is an
+ // inference variable, but I was afraid that there might be an
+ // inference variable created, registered as an obligation, and
+ // then never forced by writeback, and hence by skipping here we'd
+ // be ignoring the fact that we don't KNOW the type works
+ // out. Though even that would probably be harmless, given that
+ // we're only talking about builtin traits, which are known to be
+ // inhabited. We used to check for `self.tcx.sess.has_errors()` to
+ // avoid inundating the user with unnecessary errors, but we now
+ // check upstream for type errors and dont add the obligations to
+ // begin with in those cases.
+ if self
+ .tcx
+ .lang_items()
+ .sized_trait()
+ .map_or(false, |sized_id| sized_id == trait_ref.def_id())
+ {
+ self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0282).emit();
+ return;
+ }
+ let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0283);
+ err.note(&format!("cannot resolve `{}`", predicate));
+ if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
+ self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
+ } else if let (
+ Ok(ref snippet),
+ ObligationCauseCode::BindingObligation(ref def_id, _),
+ ) =
+ (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code)
+ {
+ let generics = self.tcx.generics_of(*def_id);
+ if !generics.params.is_empty() && !snippet.ends_with('>') {
+ // FIXME: To avoid spurious suggestions in functions where type arguments
+ // where already supplied, we check the snippet to make sure it doesn't
+ // end with a turbofish. Ideally we would have access to a `PathSegment`
+ // instead. Otherwise we would produce the following output:
+ //
+ // error[E0283]: type annotations needed
+ // --> $DIR/issue-54954.rs:3:24
+ // |
+ // LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
+ // | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ // | |
+ // | cannot infer type
+ // | help: consider specifying the type argument
+ // | in the function call:
+ // | `Tt::const_val::<[i8; 123]>::<T>`
+ // ...
+ // LL | const fn const_val<T: Sized>() -> usize {
+ // | --------- - required by this bound in `Tt::const_val`
+ // |
+ // = note: cannot resolve `_: Tt`
+
+ err.span_suggestion(
+ span,
+ &format!(
+ "consider specifying the type argument{} in the function call",
+ if generics.params.len() > 1 { "s" } else { "" },
+ ),
+ format!(
+ "{}::<{}>",
+ snippet,
+ generics
+ .params
+ .iter()
+ .map(|p| p.name.to_string())
+ .collect::<Vec<String>>()
+ .join(", ")
+ ),
+ Applicability::HasPlaceholders,
+ );
+ }
+ }
+ err
+ }
+
+ ty::Predicate::WellFormed(ty) => {
+ // Same hacky approach as above to avoid deluging user
+ // with error messages.
+ if ty.references_error() || self.tcx.sess.has_errors() {
+ return;
+ }
+ self.need_type_info_err(body_id, span, ty, ErrorCode::E0282)
+ }
+
+ ty::Predicate::Subtype(ref data) => {
+ if data.references_error() || self.tcx.sess.has_errors() {
+ // no need to overload user in such cases
+ return;
+ }
+ let &SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder();
+ // both must be type variables, or the other would've been instantiated
+ assert!(a.is_ty_var() && b.is_ty_var());
+ self.need_type_info_err(body_id, span, a, ErrorCode::E0282)
+ }
+ ty::Predicate::Projection(ref data) => {
+ let trait_ref = data.to_poly_trait_ref(self.tcx);
+ let self_ty = trait_ref.self_ty();
+ if predicate.references_error() {
+ return;
+ }
+ let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284);
+ err.note(&format!("cannot resolve `{}`", predicate));
+ err
+ }
+
+ _ => {
+ if self.tcx.sess.has_errors() {
+ return;
+ }
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0284,
+ "type annotations needed: cannot resolve `{}`",
+ predicate,
+ );
+ err.span_label(span, &format!("cannot resolve `{}`", predicate));
+ err
+ }
+ };
+ self.note_obligation_cause(&mut err, obligation);
+ err.emit();
+ }
+
+ /// Returns `true` if the trait predicate may apply for *some* assignment
+ /// to the type parameters.
+ fn predicate_can_apply(
+ &self,
+ param_env: ty::ParamEnv<'tcx>,
+ pred: ty::PolyTraitRef<'tcx>,
+ ) -> bool {
+ struct ParamToVarFolder<'a, 'tcx> {
+ infcx: &'a InferCtxt<'a, 'tcx>,
+ var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>,
+ }
+
+ impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx> {
+ fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
+ self.infcx.tcx
+ }
+
+ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
+ if let ty::Param(ty::ParamTy { name, .. }) = ty.kind {
+ let infcx = self.infcx;
+ self.var_map.entry(ty).or_insert_with(|| {
+ infcx.next_ty_var(TypeVariableOrigin {
+ kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
+ span: DUMMY_SP,
+ })
+ })
+ } else {
+ ty.super_fold_with(self)
+ }
+ }
+ }
+
+ self.probe(|_| {
+ let mut selcx = SelectionContext::new(self);
+
+ let cleaned_pred =
+ pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() });
+
+ let cleaned_pred = super::project::normalize(
+ &mut selcx,
+ param_env,
+ ObligationCause::dummy(),
+ &cleaned_pred,
+ )
+ .value;
+
+ let obligation =
+ Obligation::new(ObligationCause::dummy(), param_env, cleaned_pred.to_predicate());
+
+ self.predicate_may_hold(&obligation)
+ })
+ }
+
+ fn note_obligation_cause(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ obligation: &PredicateObligation<'tcx>,
+ ) {
+ // First, attempt to add note to this error with an async-await-specific
+ // message, and fall back to regular note otherwise.
+ if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
+ self.note_obligation_cause_code(
+ err,
+ &obligation.predicate,
+ &obligation.cause.code,
+ &mut vec![],
+ );
+ }
+ }
+
+ fn is_recursive_obligation(
+ &self,
+ obligated_types: &mut Vec<&ty::TyS<'tcx>>,
+ cause_code: &ObligationCauseCode<'tcx>,
+ ) -> bool {
+ if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
+ let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
+
+ if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) {
+ return true;
+ }
+ }
+ false
+ }
+}
+
+/// Summarizes information
+#[derive(Clone)]
+pub enum ArgKind {
+ /// An argument of non-tuple type. Parameters are (name, ty)
+ Arg(String, String),
+
+ /// An argument of tuple type. For a "found" argument, the span is
+ /// the locationo in the source of the pattern. For a "expected"
+ /// argument, it will be None. The vector is a list of (name, ty)
+ /// strings for the components of the tuple.
+ Tuple(Option<Span>, Vec<(String, String)>),
+}
+
+impl ArgKind {
+ fn empty() -> ArgKind {
+ ArgKind::Arg("_".to_owned(), "_".to_owned())
+ }
+
+ /// Creates an `ArgKind` from the expected type of an
+ /// argument. It has no name (`_`) and an optional source span.
+ pub fn from_expected_ty(t: Ty<'_>, span: Option<Span>) -> ArgKind {
+ match t.kind {
+ ty::Tuple(ref tys) => ArgKind::Tuple(
+ span,
+ tys.iter().map(|ty| ("_".to_owned(), ty.to_string())).collect::<Vec<_>>(),
+ ),
+ _ => ArgKind::Arg("_".to_owned(), t.to_string()),
+ }
+ }
+}
+
+/// Suggest restricting a type param with a new bound.
+pub fn suggest_constraining_type_param(
+ generics: &hir::Generics<'_>,
+ err: &mut DiagnosticBuilder<'_>,
+ param_name: &str,
+ constraint: &str,
+ source_map: &SourceMap,
+ span: Span,
+) -> bool {
+ let restrict_msg = "consider further restricting this bound";
+ if let Some(param) =
+ generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next()
+ {
+ if param_name.starts_with("impl ") {
+ // `impl Trait` in argument:
+ // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
+ err.span_suggestion(
+ param.span,
+ restrict_msg,
+ // `impl CurrentTrait + MissingTrait`
+ format!("{} + {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() {
+ // If there are no bounds whatsoever, suggest adding a constraint
+ // to the type parameter:
+ // `fn foo<T>(t: T) {}` → `fn foo<T: Trait>(t: T) {}`
+ err.span_suggestion(
+ param.span,
+ "consider restricting this bound",
+ format!("{}: {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else if !generics.where_clause.predicates.is_empty() {
+ // There is a `where` clause, so suggest expanding it:
+ // `fn foo<T>(t: T) where T: Debug {}` →
+ // `fn foo<T>(t: T) where T: Debug, T: Trait {}`
+ err.span_suggestion(
+ generics.where_clause.span().unwrap().shrink_to_hi(),
+ &format!("consider further restricting type parameter `{}`", param_name),
+ format!(", {}: {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else {
+ // If there is no `where` clause lean towards constraining to the
+ // type parameter:
+ // `fn foo<X: Bar, T>(t: T, x: X) {}` → `fn foo<T: Trait>(t: T) {}`
+ // `fn foo<T: Bar>(t: T) {}` → `fn foo<T: Bar + Trait>(t: T) {}`
+ let sp = param.span.with_hi(span.hi());
+ let span = source_map.span_through_char(sp, ':');
+ if sp != param.span && sp != span {
+ // Only suggest if we have high certainty that the span
+ // covers the colon in `foo<T: Trait>`.
+ err.span_suggestion(
+ span,
+ restrict_msg,
+ format!("{}: {} + ", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else {
+ err.span_label(
+ param.span,
+ &format!("consider adding a `where {}: {}` bound", param_name, constraint),
+ );
+ }
+ }
+ return true;
+ }
+ false
+}
--- /dev/null
+use super::{
+ ObligationCauseCode, OnUnimplementedDirective, OnUnimplementedNote, PredicateObligation,
+};
+use crate::infer::InferCtxt;
+use crate::ty::subst::Subst;
+use crate::ty::{self, GenericParamDefKind};
+use rustc_hir as hir;
+use rustc_hir::def_id::DefId;
+use rustc_span::symbol::sym;
+
+impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
+ fn impl_similar_to(
+ &self,
+ trait_ref: ty::PolyTraitRef<'tcx>,
+ obligation: &PredicateObligation<'tcx>,
+ ) -> Option<DefId> {
+ let tcx = self.tcx;
+ let param_env = obligation.param_env;
+ let trait_ref = tcx.erase_late_bound_regions(&trait_ref);
+ let trait_self_ty = trait_ref.self_ty();
+
+ let mut self_match_impls = vec![];
+ let mut fuzzy_match_impls = vec![];
+
+ self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| {
+ let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
+ let impl_trait_ref = tcx.impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs);
+
+ let impl_self_ty = impl_trait_ref.self_ty();
+
+ if let Ok(..) = self.can_eq(param_env, trait_self_ty, impl_self_ty) {
+ self_match_impls.push(def_id);
+
+ if trait_ref
+ .substs
+ .types()
+ .skip(1)
+ .zip(impl_trait_ref.substs.types().skip(1))
+ .all(|(u, v)| self.fuzzy_match_tys(u, v))
+ {
+ fuzzy_match_impls.push(def_id);
+ }
+ }
+ });
+
+ let impl_def_id = if self_match_impls.len() == 1 {
+ self_match_impls[0]
+ } else if fuzzy_match_impls.len() == 1 {
+ fuzzy_match_impls[0]
+ } else {
+ return None;
+ };
+
+ tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).then_some(impl_def_id)
+ }
+
+ /// Used to set on_unimplemented's `ItemContext`
+ /// to be the enclosing (async) block/function/closure
+ fn describe_enclosure(&self, hir_id: hir::HirId) -> Option<&'static str> {
+ let hir = &self.tcx.hir();
+ let node = hir.find(hir_id)?;
+ if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = &node {
+ self.describe_generator(*body_id).or_else(|| {
+ Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
+ "an async function"
+ } else {
+ "a function"
+ })
+ })
+ } else if let hir::Node::Expr(hir::Expr {
+ kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
+ ..
+ }) = &node
+ {
+ self.describe_generator(*body_id).or_else(|| {
+ Some(if gen_movability.is_some() { "an async closure" } else { "a closure" })
+ })
+ } else if let hir::Node::Expr(hir::Expr { .. }) = &node {
+ let parent_hid = hir.get_parent_node(hir_id);
+ if parent_hid != hir_id {
+ return self.describe_enclosure(parent_hid);
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ }
+
+ crate fn on_unimplemented_note(
+ &self,
+ trait_ref: ty::PolyTraitRef<'tcx>,
+ obligation: &PredicateObligation<'tcx>,
+ ) -> OnUnimplementedNote {
+ let def_id =
+ self.impl_similar_to(trait_ref, obligation).unwrap_or_else(|| trait_ref.def_id());
+ let trait_ref = *trait_ref.skip_binder();
+
+ let mut flags = vec![];
+ flags.push((
+ sym::item_context,
+ self.describe_enclosure(obligation.cause.body_id).map(|s| s.to_owned()),
+ ));
+
+ match obligation.cause.code {
+ ObligationCauseCode::BuiltinDerivedObligation(..)
+ | ObligationCauseCode::ImplDerivedObligation(..) => {}
+ _ => {
+ // this is a "direct", user-specified, rather than derived,
+ // obligation.
+ flags.push((sym::direct, None));
+ }
+ }
+
+ if let ObligationCauseCode::ItemObligation(item) = obligation.cause.code {
+ // FIXME: maybe also have some way of handling methods
+ // from other traits? That would require name resolution,
+ // which we might want to be some sort of hygienic.
+ //
+ // Currently I'm leaving it for what I need for `try`.
+ if self.tcx.trait_of_item(item) == Some(trait_ref.def_id) {
+ let method = self.tcx.item_name(item);
+ flags.push((sym::from_method, None));
+ flags.push((sym::from_method, Some(method.to_string())));
+ }
+ }
+ if let Some((t, _)) = self.get_parent_trait_ref(&obligation.cause.code) {
+ flags.push((sym::parent_trait, Some(t)));
+ }
+
+ if let Some(k) = obligation.cause.span.desugaring_kind() {
+ flags.push((sym::from_desugaring, None));
+ flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
+ }
+ let generics = self.tcx.generics_of(def_id);
+ let self_ty = trait_ref.self_ty();
+ // This is also included through the generics list as `Self`,
+ // but the parser won't allow you to use it
+ flags.push((sym::_Self, Some(self_ty.to_string())));
+ if let Some(def) = self_ty.ty_adt_def() {
+ // We also want to be able to select self's original
+ // signature with no type arguments resolved
+ flags.push((sym::_Self, Some(self.tcx.type_of(def.did).to_string())));
+ }
+
+ for param in generics.params.iter() {
+ let value = match param.kind {
+ GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
+ trait_ref.substs[param.index as usize].to_string()
+ }
+ GenericParamDefKind::Lifetime => continue,
+ };
+ let name = param.name;
+ flags.push((name, Some(value)));
+ }
+
+ if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) {
+ flags.push((sym::crate_local, None));
+ }
+
+ // Allow targeting all integers using `{integral}`, even if the exact type was resolved
+ if self_ty.is_integral() {
+ flags.push((sym::_Self, Some("{integral}".to_owned())));
+ }
+
+ if let ty::Array(aty, len) = self_ty.kind {
+ flags.push((sym::_Self, Some("[]".to_owned())));
+ flags.push((sym::_Self, Some(format!("[{}]", aty))));
+ if let Some(def) = aty.ty_adt_def() {
+ // We also want to be able to select the array's type's original
+ // signature with no type arguments resolved
+ flags.push((
+ sym::_Self,
+ Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
+ ));
+ let tcx = self.tcx;
+ if let Some(len) = len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
+ flags.push((
+ sym::_Self,
+ Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
+ ));
+ } else {
+ flags.push((
+ sym::_Self,
+ Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
+ ));
+ }
+ }
+ }
+
+ if let Ok(Some(command)) =
+ OnUnimplementedDirective::of_item(self.tcx, trait_ref.def_id, def_id)
+ {
+ command.evaluate(self.tcx, trait_ref, &flags[..])
+ } else {
+ OnUnimplementedNote::default()
+ }
+ }
+}
--- /dev/null
+use super::{
+ ArgKind, EvaluationResult, Obligation, ObligationCause, ObligationCauseCode,
+ PredicateObligation,
+};
+
+use crate::infer::InferCtxt;
+use crate::traits::object_safety::object_safety_violations;
+use crate::ty::TypeckTables;
+use crate::ty::{self, AdtKind, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable};
+
+use rustc_errors::{
+ error_code, pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style,
+};
+use rustc_hir as hir;
+use rustc_hir::def_id::DefId;
+use rustc_hir::intravisit::Visitor;
+use rustc_hir::Node;
+use rustc_span::source_map::SourceMap;
+use rustc_span::symbol::{kw, sym};
+use rustc_span::{MultiSpan, Span, DUMMY_SP};
+use std::fmt;
+
+impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
+ crate fn suggest_restricting_param_bound(
+ &self,
+ mut err: &mut DiagnosticBuilder<'_>,
+ trait_ref: &ty::PolyTraitRef<'_>,
+ body_id: hir::HirId,
+ ) {
+ let self_ty = trait_ref.self_ty();
+ let (param_ty, projection) = match &self_ty.kind {
+ ty::Param(_) => (true, None),
+ ty::Projection(projection) => (false, Some(projection)),
+ _ => return,
+ };
+
+ let suggest_restriction =
+ |generics: &hir::Generics<'_>, msg, err: &mut DiagnosticBuilder<'_>| {
+ let span = generics.where_clause.span_for_predicates_or_empty_place();
+ if !span.from_expansion() && span.desugaring_kind().is_none() {
+ err.span_suggestion(
+ generics.where_clause.span_for_predicates_or_empty_place().shrink_to_hi(),
+ &format!("consider further restricting {}", msg),
+ format!(
+ "{} {} ",
+ if !generics.where_clause.predicates.is_empty() {
+ ","
+ } else {
+ " where"
+ },
+ trait_ref.to_predicate(),
+ ),
+ Applicability::MachineApplicable,
+ );
+ }
+ };
+
+ // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
+ // don't suggest `T: Sized + ?Sized`.
+ let mut hir_id = body_id;
+ while let Some(node) = self.tcx.hir().find(hir_id) {
+ match node {
+ hir::Node::TraitItem(hir::TraitItem {
+ generics,
+ kind: hir::TraitItemKind::Method(..),
+ ..
+ }) if param_ty && self_ty == self.tcx.types.self_param => {
+ // Restricting `Self` for a single method.
+ suggest_restriction(&generics, "`Self`", err);
+ return;
+ }
+
+ hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. })
+ | hir::Node::TraitItem(hir::TraitItem {
+ generics,
+ kind: hir::TraitItemKind::Method(..),
+ ..
+ })
+ | hir::Node::ImplItem(hir::ImplItem {
+ generics,
+ kind: hir::ImplItemKind::Method(..),
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Trait(_, _, generics, _, _),
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Impl { generics, .. }, ..
+ }) if projection.is_some() => {
+ // Missing associated type bound.
+ suggest_restriction(&generics, "the associated type", err);
+ return;
+ }
+
+ hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Struct(_, generics),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Enum(_, generics), span, ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Union(_, generics),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Trait(_, _, generics, ..),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Impl { generics, .. },
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Fn(_, generics, _),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::TyAlias(_, generics),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::TraitAlias(generics, _),
+ span,
+ ..
+ })
+ | hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }),
+ span,
+ ..
+ })
+ | hir::Node::TraitItem(hir::TraitItem { generics, span, .. })
+ | hir::Node::ImplItem(hir::ImplItem { generics, span, .. })
+ if param_ty =>
+ {
+ // Missing generic type parameter bound.
+ let param_name = self_ty.to_string();
+ let constraint = trait_ref.print_only_trait_path().to_string();
+ if suggest_constraining_type_param(
+ generics,
+ &mut err,
+ ¶m_name,
+ &constraint,
+ self.tcx.sess.source_map(),
+ *span,
+ ) {
+ return;
+ }
+ }
+
+ hir::Node::Crate => return,
+
+ _ => {}
+ }
+
+ hir_id = self.tcx.hir().get_parent_item(hir_id);
+ }
+ }
+
+ /// When encountering an assignment of an unsized trait, like `let x = ""[..];`, provide a
+ /// suggestion to borrow the initializer in order to use have a slice instead.
+ crate fn suggest_borrow_on_unsized_slice(
+ &self,
+ code: &ObligationCauseCode<'tcx>,
+ err: &mut DiagnosticBuilder<'tcx>,
+ ) {
+ if let &ObligationCauseCode::VariableType(hir_id) = code {
+ let parent_node = self.tcx.hir().get_parent_node(hir_id);
+ if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
+ if let Some(ref expr) = local.init {
+ if let hir::ExprKind::Index(_, _) = expr.kind {
+ if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {
+ err.span_suggestion(
+ expr.span,
+ "consider borrowing here",
+ format!("&{}", snippet),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /// Given a closure's `DefId`, return the given name of the closure.
+ ///
+ /// This doesn't account for reassignments, but it's only used for suggestions.
+ crate fn get_closure_name(
+ &self,
+ def_id: DefId,
+ err: &mut DiagnosticBuilder<'_>,
+ msg: &str,
+ ) -> Option<String> {
+ let get_name =
+ |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
+ // Get the local name of this closure. This can be inaccurate because
+ // of the possibility of reassignment, but this should be good enough.
+ match &kind {
+ hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
+ Some(format!("{}", name))
+ }
+ _ => {
+ err.note(&msg);
+ None
+ }
+ }
+ };
+
+ let hir = self.tcx.hir();
+ let hir_id = hir.as_local_hir_id(def_id)?;
+ let parent_node = hir.get_parent_node(hir_id);
+ match hir.find(parent_node) {
+ Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => {
+ get_name(err, &local.pat.kind)
+ }
+ // Different to previous arm because one is `&hir::Local` and the other
+ // is `P<hir::Local>`.
+ Some(hir::Node::Local(local)) => get_name(err, &local.pat.kind),
+ _ => return None,
+ }
+ }
+
+ /// We tried to apply the bound to an `fn` or closure. Check whether calling it would
+ /// evaluate to a type that *would* satisfy the trait binding. If it would, suggest calling
+ /// it: `bar(foo)` → `bar(foo())`. This case is *very* likely to be hit if `foo` is `async`.
+ crate fn suggest_fn_call(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'_>,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ points_at_arg: bool,
+ ) {
+ let self_ty = trait_ref.self_ty();
+ let (def_id, output_ty, callable) = match self_ty.kind {
+ ty::Closure(def_id, substs) => {
+ (def_id, self.closure_sig(def_id, substs).output(), "closure")
+ }
+ ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
+ _ => return,
+ };
+ let msg = format!("use parentheses to call the {}", callable);
+
+ let obligation = self.mk_obligation_for_def_id(
+ trait_ref.def_id(),
+ output_ty.skip_binder(),
+ obligation.cause.clone(),
+ obligation.param_env,
+ );
+
+ match self.evaluate_obligation(&obligation) {
+ Ok(EvaluationResult::EvaluatedToOk)
+ | Ok(EvaluationResult::EvaluatedToOkModuloRegions)
+ | Ok(EvaluationResult::EvaluatedToAmbig) => {}
+ _ => return,
+ }
+ let hir = self.tcx.hir();
+ // Get the name of the callable and the arguments to be used in the suggestion.
+ let snippet = match hir.get_if_local(def_id) {
+ Some(hir::Node::Expr(hir::Expr {
+ kind: hir::ExprKind::Closure(_, decl, _, span, ..),
+ ..
+ })) => {
+ err.span_label(*span, "consider calling this closure");
+ let name = match self.get_closure_name(def_id, err, &msg) {
+ Some(name) => name,
+ None => return,
+ };
+ let args = decl.inputs.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
+ format!("{}({})", name, args)
+ }
+ Some(hir::Node::Item(hir::Item {
+ ident,
+ kind: hir::ItemKind::Fn(.., body_id),
+ ..
+ })) => {
+ err.span_label(ident.span, "consider calling this function");
+ let body = hir.body(*body_id);
+ let args = body
+ .params
+ .iter()
+ .map(|arg| match &arg.pat.kind {
+ hir::PatKind::Binding(_, _, ident, None)
+ // FIXME: provide a better suggestion when encountering `SelfLower`, it
+ // should suggest a method call.
+ if ident.name != kw::SelfLower => ident.to_string(),
+ _ => "_".to_string(),
+ })
+ .collect::<Vec<_>>()
+ .join(", ");
+ format!("{}({})", ident, args)
+ }
+ _ => return,
+ };
+ if points_at_arg {
+ // When the obligation error has been ensured to have been caused by
+ // an argument, the `obligation.cause.span` points at the expression
+ // of the argument, so we can provide a suggestion. This is signaled
+ // by `points_at_arg`. Otherwise, we give a more general note.
+ err.span_suggestion(
+ obligation.cause.span,
+ &msg,
+ snippet,
+ Applicability::HasPlaceholders,
+ );
+ } else {
+ err.help(&format!("{}: `{}`", msg, snippet));
+ }
+ }
+
+ crate fn suggest_add_reference_to_arg(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'tcx>,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ points_at_arg: bool,
+ has_custom_message: bool,
+ ) -> bool {
+ if !points_at_arg {
+ return false;
+ }
+
+ let span = obligation.cause.span;
+ let param_env = obligation.param_env;
+ let trait_ref = trait_ref.skip_binder();
+
+ if let ObligationCauseCode::ImplDerivedObligation(obligation) = &obligation.cause.code {
+ // Try to apply the original trait binding obligation by borrowing.
+ let self_ty = trait_ref.self_ty();
+ let found = self_ty.to_string();
+ let new_self_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, self_ty);
+ let substs = self.tcx.mk_substs_trait(new_self_ty, &[]);
+ let new_trait_ref = ty::TraitRef::new(obligation.parent_trait_ref.def_id(), substs);
+ let new_obligation =
+ Obligation::new(ObligationCause::dummy(), param_env, new_trait_ref.to_predicate());
+ if self.predicate_must_hold_modulo_regions(&new_obligation) {
+ if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
+ // We have a very specific type of error, where just borrowing this argument
+ // might solve the problem. In cases like this, the important part is the
+ // original type obligation, not the last one that failed, which is arbitrary.
+ // Because of this, we modify the error to refer to the original obligation and
+ // return early in the caller.
+ let msg = format!(
+ "the trait bound `{}: {}` is not satisfied",
+ found,
+ obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
+ );
+ if has_custom_message {
+ err.note(&msg);
+ } else {
+ err.message = vec![(msg, Style::NoStyle)];
+ }
+ if snippet.starts_with('&') {
+ // This is already a literal borrow and the obligation is failing
+ // somewhere else in the obligation chain. Do not suggest non-sense.
+ return false;
+ }
+ err.span_label(
+ span,
+ &format!(
+ "expected an implementor of trait `{}`",
+ obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
+ ),
+ );
+ err.span_suggestion(
+ span,
+ "consider borrowing here",
+ format!("&{}", snippet),
+ Applicability::MaybeIncorrect,
+ );
+ return true;
+ }
+ }
+ }
+ false
+ }
+
+ /// Whenever references are used by mistake, like `for (i, e) in &vec.iter().enumerate()`,
+ /// suggest removing these references until we reach a type that implements the trait.
+ crate fn suggest_remove_reference(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'tcx>,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ ) {
+ let trait_ref = trait_ref.skip_binder();
+ let span = obligation.cause.span;
+
+ if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
+ let refs_number =
+ snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
+ if let Some('\'') =
+ snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
+ {
+ // Do not suggest removal of borrow from type arguments.
+ return;
+ }
+
+ let mut trait_type = trait_ref.self_ty();
+
+ for refs_remaining in 0..refs_number {
+ if let ty::Ref(_, t_type, _) = trait_type.kind {
+ trait_type = t_type;
+
+ let new_obligation = self.mk_obligation_for_def_id(
+ trait_ref.def_id,
+ trait_type,
+ ObligationCause::dummy(),
+ obligation.param_env,
+ );
+
+ if self.predicate_may_hold(&new_obligation) {
+ let sp = self
+ .tcx
+ .sess
+ .source_map()
+ .span_take_while(span, |c| c.is_whitespace() || *c == '&');
+
+ let remove_refs = refs_remaining + 1;
+ let format_str =
+ format!("consider removing {} leading `&`-references", remove_refs);
+
+ err.span_suggestion_short(
+ sp,
+ &format_str,
+ String::new(),
+ Applicability::MachineApplicable,
+ );
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ /// Check if the trait bound is implemented for a different mutability and note it in the
+ /// final error.
+ crate fn suggest_change_mut(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'tcx>,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ points_at_arg: bool,
+ ) {
+ let span = obligation.cause.span;
+ if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
+ let refs_number =
+ snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
+ if let Some('\'') =
+ snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
+ {
+ // Do not suggest removal of borrow from type arguments.
+ return;
+ }
+ let trait_ref = self.resolve_vars_if_possible(trait_ref);
+ if trait_ref.has_infer_types() {
+ // Do not ICE while trying to find if a reborrow would succeed on a trait with
+ // unresolved bindings.
+ return;
+ }
+
+ if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
+ let trait_type = match mutability {
+ hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
+ hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
+ };
+
+ let new_obligation = self.mk_obligation_for_def_id(
+ trait_ref.skip_binder().def_id,
+ trait_type,
+ ObligationCause::dummy(),
+ obligation.param_env,
+ );
+
+ if self.evaluate_obligation_no_overflow(&new_obligation).must_apply_modulo_regions()
+ {
+ let sp = self
+ .tcx
+ .sess
+ .source_map()
+ .span_take_while(span, |c| c.is_whitespace() || *c == '&');
+ if points_at_arg && mutability == hir::Mutability::Not && refs_number > 0 {
+ err.span_suggestion(
+ sp,
+ "consider changing this borrow's mutability",
+ "&mut ".to_string(),
+ Applicability::MachineApplicable,
+ );
+ } else {
+ err.note(&format!(
+ "`{}` is implemented for `{:?}`, but not for `{:?}`",
+ trait_ref.print_only_trait_path(),
+ trait_type,
+ trait_ref.skip_binder().self_ty(),
+ ));
+ }
+ }
+ }
+ }
+ }
+
+ crate fn suggest_semicolon_removal(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'tcx>,
+ span: Span,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ ) {
+ let hir = self.tcx.hir();
+ let parent_node = hir.get_parent_node(obligation.cause.body_id);
+ let node = hir.find(parent_node);
+ if let Some(hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Fn(sig, _, body_id), ..
+ })) = node
+ {
+ let body = hir.body(*body_id);
+ if let hir::ExprKind::Block(blk, _) = &body.value.kind {
+ if sig.decl.output.span().overlaps(span)
+ && blk.expr.is_none()
+ && "()" == &trait_ref.self_ty().to_string()
+ {
+ // FIXME(estebank): When encountering a method with a trait
+ // bound not satisfied in the return type with a body that has
+ // no return, suggest removal of semicolon on last statement.
+ // Once that is added, close #54771.
+ if let Some(ref stmt) = blk.stmts.last() {
+ let sp = self.tcx.sess.source_map().end_point(stmt.span);
+ err.span_label(sp, "consider removing this semicolon");
+ }
+ }
+ }
+ }
+ }
+
+ /// If all conditions are met to identify a returned `dyn Trait`, suggest using `impl Trait` if
+ /// applicable and signal that the error has been expanded appropriately and needs to be
+ /// emitted.
+ crate fn suggest_impl_trait(
+ &self,
+ err: &mut DiagnosticBuilder<'tcx>,
+ span: Span,
+ obligation: &PredicateObligation<'tcx>,
+ trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
+ ) -> bool {
+ match obligation.cause.code.peel_derives() {
+ // Only suggest `impl Trait` if the return type is unsized because it is `dyn Trait`.
+ ObligationCauseCode::SizedReturnType => {}
+ _ => return false,
+ }
+
+ let hir = self.tcx.hir();
+ let parent_node = hir.get_parent_node(obligation.cause.body_id);
+ let node = hir.find(parent_node);
+ let (sig, body_id) = if let Some(hir::Node::Item(hir::Item {
+ kind: hir::ItemKind::Fn(sig, _, body_id),
+ ..
+ })) = node
+ {
+ (sig, body_id)
+ } else {
+ return false;
+ };
+ let body = hir.body(*body_id);
+ let trait_ref = self.resolve_vars_if_possible(trait_ref);
+ let ty = trait_ref.skip_binder().self_ty();
+ let is_object_safe = match ty.kind {
+ ty::Dynamic(predicates, _) => {
+ // If the `dyn Trait` is not object safe, do not suggest `Box<dyn Trait>`.
+ predicates
+ .principal_def_id()
+ .map_or(true, |def_id| object_safety_violations(self.tcx, def_id).is_empty())
+ }
+ // We only want to suggest `impl Trait` to `dyn Trait`s.
+ // For example, `fn foo() -> str` needs to be filtered out.
+ _ => return false,
+ };
+
+ let ret_ty = if let hir::FunctionRetTy::Return(ret_ty) = sig.decl.output {
+ ret_ty
+ } else {
+ return false;
+ };
+
+ // Use `TypeVisitor` instead of the output type directly to find the span of `ty` for
+ // cases like `fn foo() -> (dyn Trait, i32) {}`.
+ // Recursively look for `TraitObject` types and if there's only one, use that span to
+ // suggest `impl Trait`.
+
+ // Visit to make sure there's a single `return` type to suggest `impl Trait`,
+ // otherwise suggest using `Box<dyn Trait>` or an enum.
+ let mut visitor = ReturnsVisitor(vec![]);
+ visitor.visit_body(&body);
+
+ let tables = self.in_progress_tables.map(|t| t.borrow()).unwrap();
+
+ let mut ret_types = visitor.0.iter().filter_map(|expr| tables.node_type_opt(expr.hir_id));
+ let (last_ty, all_returns_have_same_type) =
+ ret_types.clone().fold((None, true), |(last_ty, mut same), returned_ty| {
+ same &= last_ty.map_or(true, |ty| ty == returned_ty);
+ (Some(returned_ty), same)
+ });
+ let all_returns_conform_to_trait =
+ if let Some(ty_ret_ty) = tables.node_type_opt(ret_ty.hir_id) {
+ match ty_ret_ty.kind {
+ ty::Dynamic(predicates, _) => {
+ let cause = ObligationCause::misc(ret_ty.span, ret_ty.hir_id);
+ let param_env = ty::ParamEnv::empty();
+ ret_types.all(|returned_ty| {
+ predicates.iter().all(|predicate| {
+ let pred = predicate.with_self_ty(self.tcx, returned_ty);
+ let obl = Obligation::new(cause.clone(), param_env, pred);
+ self.predicate_may_hold(&obl)
+ })
+ })
+ }
+ _ => true,
+ }
+ } else {
+ true
+ };
+
+ let (snippet, last_ty) =
+ if let (true, hir::TyKind::TraitObject(..), Ok(snippet), true, Some(last_ty)) = (
+ // Verify that we're dealing with a return `dyn Trait`
+ ret_ty.span.overlaps(span),
+ &ret_ty.kind,
+ self.tcx.sess.source_map().span_to_snippet(ret_ty.span),
+ // If any of the return types does not conform to the trait, then we can't
+ // suggest `impl Trait` nor trait objects, it is a type mismatch error.
+ all_returns_conform_to_trait,
+ last_ty,
+ ) {
+ (snippet, last_ty)
+ } else {
+ return false;
+ };
+ err.code(error_code!(E0746));
+ err.set_primary_message("return type cannot have an unboxed trait object");
+ err.children.clear();
+ let impl_trait_msg = "for information on `impl Trait`, see \
+ <https://doc.rust-lang.org/book/ch10-02-traits.html\
+ #returning-types-that-implement-traits>";
+ let trait_obj_msg = "for information on trait objects, see \
+ <https://doc.rust-lang.org/book/ch17-02-trait-objects.html\
+ #using-trait-objects-that-allow-for-values-of-different-types>";
+ let has_dyn = snippet.split_whitespace().next().map_or(false, |s| s == "dyn");
+ let trait_obj = if has_dyn { &snippet[4..] } else { &snippet[..] };
+ if all_returns_have_same_type {
+ // Suggest `-> impl Trait`.
+ err.span_suggestion(
+ ret_ty.span,
+ &format!(
+ "return `impl {1}` instead, as all return paths are of type `{}`, \
+ which implements `{1}`",
+ last_ty, trait_obj,
+ ),
+ format!("impl {}", trait_obj),
+ Applicability::MachineApplicable,
+ );
+ err.note(impl_trait_msg);
+ } else {
+ if is_object_safe {
+ // Suggest `-> Box<dyn Trait>` and `Box::new(returned_value)`.
+ // Get all the return values and collect their span and suggestion.
+ let mut suggestions = visitor
+ .0
+ .iter()
+ .map(|expr| {
+ (
+ expr.span,
+ format!(
+ "Box::new({})",
+ self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap()
+ ),
+ )
+ })
+ .collect::<Vec<_>>();
+ // Add the suggestion for the return type.
+ suggestions.push((
+ ret_ty.span,
+ format!("Box<{}{}>", if has_dyn { "" } else { "dyn " }, snippet),
+ ));
+ err.multipart_suggestion(
+ "return a boxed trait object instead",
+ suggestions,
+ Applicability::MaybeIncorrect,
+ );
+ } else {
+ // This is currently not possible to trigger because E0038 takes precedence, but
+ // leave it in for completeness in case anything changes in an earlier stage.
+ err.note(&format!(
+ "if trait `{}` was object safe, you could return a trait object",
+ trait_obj,
+ ));
+ }
+ err.note(trait_obj_msg);
+ err.note(&format!(
+ "if all the returned values were of the same type you could use \
+ `impl {}` as the return type",
+ trait_obj,
+ ));
+ err.note(impl_trait_msg);
+ err.note("you can create a new `enum` with a variant for each returned type");
+ }
+ true
+ }
+
+ crate fn point_at_returns_when_relevant(
+ &self,
+ err: &mut DiagnosticBuilder<'tcx>,
+ obligation: &PredicateObligation<'tcx>,
+ ) {
+ match obligation.cause.code.peel_derives() {
+ ObligationCauseCode::SizedReturnType => {}
+ _ => return,
+ }
+
+ let hir = self.tcx.hir();
+ let parent_node = hir.get_parent_node(obligation.cause.body_id);
+ let node = hir.find(parent_node);
+ if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) =
+ node
+ {
+ let body = hir.body(*body_id);
+ // Point at all the `return`s in the function as they have failed trait bounds.
+ let mut visitor = ReturnsVisitor(vec![]);
+ visitor.visit_body(&body);
+ let tables = self.in_progress_tables.map(|t| t.borrow()).unwrap();
+ for expr in &visitor.0 {
+ if let Some(returned_ty) = tables.node_type_opt(expr.hir_id) {
+ let ty = self.resolve_vars_if_possible(&returned_ty);
+ err.span_label(expr.span, &format!("this returned value is of type `{}`", ty));
+ }
+ }
+ }
+ }
+
+ /// Given some node representing a fn-like thing in the HIR map,
+ /// returns a span and `ArgKind` information that describes the
+ /// arguments it expects. This can be supplied to
+ /// `report_arg_count_mismatch`.
+ pub fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>) {
+ match node {
+ Node::Expr(&hir::Expr {
+ kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
+ ..
+ }) => (
+ self.tcx.sess.source_map().def_span(span),
+ self.tcx
+ .hir()
+ .body(id)
+ .params
+ .iter()
+ .map(|arg| {
+ if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
+ *arg.pat
+ {
+ ArgKind::Tuple(
+ Some(span),
+ args.iter()
+ .map(|pat| {
+ let snippet = self
+ .tcx
+ .sess
+ .source_map()
+ .span_to_snippet(pat.span)
+ .unwrap();
+ (snippet, "_".to_owned())
+ })
+ .collect::<Vec<_>>(),
+ )
+ } else {
+ let name =
+ self.tcx.sess.source_map().span_to_snippet(arg.pat.span).unwrap();
+ ArgKind::Arg(name, "_".to_owned())
+ }
+ })
+ .collect::<Vec<ArgKind>>(),
+ ),
+ Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
+ | Node::ImplItem(&hir::ImplItem {
+ span,
+ kind: hir::ImplItemKind::Method(ref sig, _),
+ ..
+ })
+ | Node::TraitItem(&hir::TraitItem {
+ span,
+ kind: hir::TraitItemKind::Method(ref sig, _),
+ ..
+ }) => (
+ self.tcx.sess.source_map().def_span(span),
+ sig.decl
+ .inputs
+ .iter()
+ .map(|arg| match arg.clone().kind {
+ hir::TyKind::Tup(ref tys) => ArgKind::Tuple(
+ Some(arg.span),
+ vec![("_".to_owned(), "_".to_owned()); tys.len()],
+ ),
+ _ => ArgKind::empty(),
+ })
+ .collect::<Vec<ArgKind>>(),
+ ),
+ Node::Ctor(ref variant_data) => {
+ let span = variant_data
+ .ctor_hir_id()
+ .map(|hir_id| self.tcx.hir().span(hir_id))
+ .unwrap_or(DUMMY_SP);
+ let span = self.tcx.sess.source_map().def_span(span);
+
+ (span, vec![ArgKind::empty(); variant_data.fields().len()])
+ }
+ _ => panic!("non-FnLike node found: {:?}", node),
+ }
+ }
+
+ /// Reports an error when the number of arguments needed by a
+ /// trait match doesn't match the number that the expression
+ /// provides.
+ pub fn report_arg_count_mismatch(
+ &self,
+ span: Span,
+ found_span: Option<Span>,
+ expected_args: Vec<ArgKind>,
+ found_args: Vec<ArgKind>,
+ is_closure: bool,
+ ) -> DiagnosticBuilder<'tcx> {
+ let kind = if is_closure { "closure" } else { "function" };
+
+ let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
+ let arg_length = arguments.len();
+ let distinct = match &other[..] {
+ &[ArgKind::Tuple(..)] => true,
+ _ => false,
+ };
+ match (arg_length, arguments.get(0)) {
+ (1, Some(&ArgKind::Tuple(_, ref fields))) => {
+ format!("a single {}-tuple as argument", fields.len())
+ }
+ _ => format!(
+ "{} {}argument{}",
+ arg_length,
+ if distinct && arg_length > 1 { "distinct " } else { "" },
+ pluralize!(arg_length)
+ ),
+ }
+ };
+
+ let expected_str = args_str(&expected_args, &found_args);
+ let found_str = args_str(&found_args, &expected_args);
+
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0593,
+ "{} is expected to take {}, but it takes {}",
+ kind,
+ expected_str,
+ found_str,
+ );
+
+ err.span_label(span, format!("expected {} that takes {}", kind, expected_str));
+
+ if let Some(found_span) = found_span {
+ err.span_label(found_span, format!("takes {}", found_str));
+
+ // move |_| { ... }
+ // ^^^^^^^^-- def_span
+ //
+ // move |_| { ... }
+ // ^^^^^-- prefix
+ let prefix_span = self.tcx.sess.source_map().span_until_non_whitespace(found_span);
+ // move |_| { ... }
+ // ^^^-- pipe_span
+ let pipe_span =
+ if let Some(span) = found_span.trim_start(prefix_span) { span } else { found_span };
+
+ // Suggest to take and ignore the arguments with expected_args_length `_`s if
+ // found arguments is empty (assume the user just wants to ignore args in this case).
+ // For example, if `expected_args_length` is 2, suggest `|_, _|`.
+ if found_args.is_empty() && is_closure {
+ let underscores = vec!["_"; expected_args.len()].join(", ");
+ err.span_suggestion(
+ pipe_span,
+ &format!(
+ "consider changing the closure to take and ignore the expected argument{}",
+ if expected_args.len() < 2 { "" } else { "s" }
+ ),
+ format!("|{}|", underscores),
+ Applicability::MachineApplicable,
+ );
+ }
+
+ if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] {
+ if fields.len() == expected_args.len() {
+ let sugg = fields
+ .iter()
+ .map(|(name, _)| name.to_owned())
+ .collect::<Vec<String>>()
+ .join(", ");
+ err.span_suggestion(
+ found_span,
+ "change the closure to take multiple arguments instead of a single tuple",
+ format!("|{}|", sugg),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
+ if fields.len() == found_args.len() && is_closure {
+ let sugg = format!(
+ "|({}){}|",
+ found_args
+ .iter()
+ .map(|arg| match arg {
+ ArgKind::Arg(name, _) => name.to_owned(),
+ _ => "_".to_owned(),
+ })
+ .collect::<Vec<String>>()
+ .join(", "),
+ // add type annotations if available
+ if found_args.iter().any(|arg| match arg {
+ ArgKind::Arg(_, ty) => ty != "_",
+ _ => false,
+ }) {
+ format!(
+ ": ({})",
+ fields
+ .iter()
+ .map(|(_, ty)| ty.to_owned())
+ .collect::<Vec<String>>()
+ .join(", ")
+ )
+ } else {
+ String::new()
+ },
+ );
+ err.span_suggestion(
+ found_span,
+ "change the closure to accept a tuple instead of individual arguments",
+ sugg,
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ }
+
+ err
+ }
+
+ crate fn report_closure_arg_mismatch(
+ &self,
+ span: Span,
+ found_span: Option<Span>,
+ expected_ref: ty::PolyTraitRef<'tcx>,
+ found: ty::PolyTraitRef<'tcx>,
+ ) -> DiagnosticBuilder<'tcx> {
+ crate fn build_fn_sig_string<'tcx>(
+ tcx: TyCtxt<'tcx>,
+ trait_ref: &ty::TraitRef<'tcx>,
+ ) -> String {
+ let inputs = trait_ref.substs.type_at(1);
+ let sig = if let ty::Tuple(inputs) = inputs.kind {
+ tcx.mk_fn_sig(
+ inputs.iter().map(|k| k.expect_ty()),
+ tcx.mk_ty_infer(ty::TyVar(ty::TyVid { index: 0 })),
+ false,
+ hir::Unsafety::Normal,
+ ::rustc_target::spec::abi::Abi::Rust,
+ )
+ } else {
+ tcx.mk_fn_sig(
+ ::std::iter::once(inputs),
+ tcx.mk_ty_infer(ty::TyVar(ty::TyVid { index: 0 })),
+ false,
+ hir::Unsafety::Normal,
+ ::rustc_target::spec::abi::Abi::Rust,
+ )
+ };
+ ty::Binder::bind(sig).to_string()
+ }
+
+ let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
+ let mut err = struct_span_err!(
+ self.tcx.sess,
+ span,
+ E0631,
+ "type mismatch in {} arguments",
+ if argument_is_closure { "closure" } else { "function" }
+ );
+
+ let found_str = format!(
+ "expected signature of `{}`",
+ build_fn_sig_string(self.tcx, found.skip_binder())
+ );
+ err.span_label(span, found_str);
+
+ let found_span = found_span.unwrap_or(span);
+ let expected_str = format!(
+ "found signature of `{}`",
+ build_fn_sig_string(self.tcx, expected_ref.skip_binder())
+ );
+ err.span_label(found_span, expected_str);
+
+ err
+ }
+}
+
+impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
+ crate fn suggest_fully_qualified_path(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ def_id: DefId,
+ span: Span,
+ trait_ref: DefId,
+ ) {
+ if let Some(assoc_item) = self.tcx.opt_associated_item(def_id) {
+ if let ty::AssocKind::Const | ty::AssocKind::Type = assoc_item.kind {
+ err.note(&format!(
+ "{}s cannot be accessed directly on a `trait`, they can only be \
+ accessed through a specific `impl`",
+ assoc_item.kind.suggestion_descr(),
+ ));
+ err.span_suggestion(
+ span,
+ "use the fully qualified path to an implementation",
+ format!("<Type as {}>::{}", self.tcx.def_path_str(trait_ref), assoc_item.ident),
+ Applicability::HasPlaceholders,
+ );
+ }
+ }
+ }
+
+ /// Adds an async-await specific note to the diagnostic when the future does not implement
+ /// an auto trait because of a captured type.
+ ///
+ /// ```ignore (diagnostic)
+ /// note: future does not implement `Qux` as this value is used across an await
+ /// --> $DIR/issue-64130-3-other.rs:17:5
+ /// |
+ /// LL | let x = Foo;
+ /// | - has type `Foo`
+ /// LL | baz().await;
+ /// | ^^^^^^^^^^^ await occurs here, with `x` maybe used later
+ /// LL | }
+ /// | - `x` is later dropped here
+ /// ```
+ ///
+ /// When the diagnostic does not implement `Send` or `Sync` specifically, then the diagnostic
+ /// is "replaced" with a different message and a more specific error.
+ ///
+ /// ```ignore (diagnostic)
+ /// error: future cannot be sent between threads safely
+ /// --> $DIR/issue-64130-2-send.rs:21:5
+ /// |
+ /// LL | fn is_send<T: Send>(t: T) { }
+ /// | ------- ---- required by this bound in `is_send`
+ /// ...
+ /// LL | is_send(bar());
+ /// | ^^^^^^^ future returned by `bar` is not send
+ /// |
+ /// = help: within `impl std::future::Future`, the trait `std::marker::Send` is not
+ /// implemented for `Foo`
+ /// note: future is not send as this value is used across an await
+ /// --> $DIR/issue-64130-2-send.rs:15:5
+ /// |
+ /// LL | let x = Foo;
+ /// | - has type `Foo`
+ /// LL | baz().await;
+ /// | ^^^^^^^^^^^ await occurs here, with `x` maybe used later
+ /// LL | }
+ /// | - `x` is later dropped here
+ /// ```
+ ///
+ /// Returns `true` if an async-await specific note was added to the diagnostic.
+ crate fn maybe_note_obligation_cause_for_async_await(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ obligation: &PredicateObligation<'tcx>,
+ ) -> bool {
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: obligation.predicate={:?} \
+ obligation.cause.span={:?}",
+ obligation.predicate, obligation.cause.span
+ );
+ let source_map = self.tcx.sess.source_map();
+
+ // Attempt to detect an async-await error by looking at the obligation causes, looking
+ // for a generator to be present.
+ //
+ // When a future does not implement a trait because of a captured type in one of the
+ // generators somewhere in the call stack, then the result is a chain of obligations.
+ //
+ // Given a `async fn` A that calls a `async fn` B which captures a non-send type and that
+ // future is passed as an argument to a function C which requires a `Send` type, then the
+ // chain looks something like this:
+ //
+ // - `BuiltinDerivedObligation` with a generator witness (B)
+ // - `BuiltinDerivedObligation` with a generator (B)
+ // - `BuiltinDerivedObligation` with `std::future::GenFuture` (B)
+ // - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
+ // - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
+ // - `BuiltinDerivedObligation` with a generator witness (A)
+ // - `BuiltinDerivedObligation` with a generator (A)
+ // - `BuiltinDerivedObligation` with `std::future::GenFuture` (A)
+ // - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
+ // - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
+ // - `BindingObligation` with `impl_send (Send requirement)
+ //
+ // The first obligation in the chain is the most useful and has the generator that captured
+ // the type. The last generator has information about where the bound was introduced. At
+ // least one generator should be present for this diagnostic to be modified.
+ let (mut trait_ref, mut target_ty) = match obligation.predicate {
+ ty::Predicate::Trait(p) => {
+ (Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
+ }
+ _ => (None, None),
+ };
+ let mut generator = None;
+ let mut last_generator = None;
+ let mut next_code = Some(&obligation.cause.code);
+ while let Some(code) = next_code {
+ debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
+ match code {
+ ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
+ | ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
+ let ty = derived_obligation.parent_trait_ref.self_ty();
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: \
+ parent_trait_ref={:?} self_ty.kind={:?}",
+ derived_obligation.parent_trait_ref, ty.kind
+ );
+
+ match ty.kind {
+ ty::Generator(did, ..) => {
+ generator = generator.or(Some(did));
+ last_generator = Some(did);
+ }
+ ty::GeneratorWitness(..) => {}
+ _ if generator.is_none() => {
+ trait_ref = Some(*derived_obligation.parent_trait_ref.skip_binder());
+ target_ty = Some(ty);
+ }
+ _ => {}
+ }
+
+ next_code = Some(derived_obligation.parent_code.as_ref());
+ }
+ _ => break,
+ }
+ }
+
+ // Only continue if a generator was found.
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: generator={:?} trait_ref={:?} \
+ target_ty={:?}",
+ generator, trait_ref, target_ty
+ );
+ let (generator_did, trait_ref, target_ty) = match (generator, trait_ref, target_ty) {
+ (Some(generator_did), Some(trait_ref), Some(target_ty)) => {
+ (generator_did, trait_ref, target_ty)
+ }
+ _ => return false,
+ };
+
+ let span = self.tcx.def_span(generator_did);
+
+ // Do not ICE on closure typeck (#66868).
+ if self.tcx.hir().as_local_hir_id(generator_did).is_none() {
+ return false;
+ }
+
+ // Get the tables from the infcx if the generator is the function we are
+ // currently type-checking; otherwise, get them by performing a query.
+ // This is needed to avoid cycles.
+ let in_progress_tables = self.in_progress_tables.map(|t| t.borrow());
+ let generator_did_root = self.tcx.closure_base_def_id(generator_did);
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: generator_did={:?} \
+ generator_did_root={:?} in_progress_tables.local_id_root={:?} span={:?}",
+ generator_did,
+ generator_did_root,
+ in_progress_tables.as_ref().map(|t| t.local_id_root),
+ span
+ );
+ let query_tables;
+ let tables: &TypeckTables<'tcx> = match &in_progress_tables {
+ Some(t) if t.local_id_root == Some(generator_did_root) => t,
+ _ => {
+ query_tables = self.tcx.typeck_tables_of(generator_did);
+ &query_tables
+ }
+ };
+
+ // Look for a type inside the generator interior that matches the target type to get
+ // a span.
+ let target_ty_erased = self.tcx.erase_regions(&target_ty);
+ let target_span = tables
+ .generator_interior_types
+ .iter()
+ .find(|ty::GeneratorInteriorTypeCause { ty, .. }| {
+ // Careful: the regions for types that appear in the
+ // generator interior are not generally known, so we
+ // want to erase them when comparing (and anyway,
+ // `Send` and other bounds are generally unaffected by
+ // the choice of region). When erasing regions, we
+ // also have to erase late-bound regions. This is
+ // because the types that appear in the generator
+ // interior generally contain "bound regions" to
+ // represent regions that are part of the suspended
+ // generator frame. Bound regions are preserved by
+ // `erase_regions` and so we must also call
+ // `erase_late_bound_regions`.
+ let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(*ty));
+ let ty_erased = self.tcx.erase_regions(&ty_erased);
+ let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
+ target_ty_erased={:?} eq={:?}",
+ ty_erased, target_ty_erased, eq
+ );
+ eq
+ })
+ .map(|ty::GeneratorInteriorTypeCause { span, scope_span, expr, .. }| {
+ (span, source_map.span_to_snippet(*span), scope_span, expr)
+ });
+
+ debug!(
+ "maybe_note_obligation_cause_for_async_await: target_ty={:?} \
+ generator_interior_types={:?} target_span={:?}",
+ target_ty, tables.generator_interior_types, target_span
+ );
+ if let Some((target_span, Ok(snippet), scope_span, expr)) = target_span {
+ self.note_obligation_cause_for_async_await(
+ err,
+ *target_span,
+ scope_span,
+ *expr,
+ snippet,
+ generator_did,
+ last_generator,
+ trait_ref,
+ target_ty,
+ tables,
+ obligation,
+ next_code,
+ );
+ true
+ } else {
+ false
+ }
+ }
+
+ /// Unconditionally adds the diagnostic note described in
+ /// `maybe_note_obligation_cause_for_async_await`'s documentation comment.
+ crate fn note_obligation_cause_for_async_await(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ target_span: Span,
+ scope_span: &Option<Span>,
+ expr: Option<hir::HirId>,
+ snippet: String,
+ first_generator: DefId,
+ last_generator: Option<DefId>,
+ trait_ref: ty::TraitRef<'_>,
+ target_ty: Ty<'tcx>,
+ tables: &ty::TypeckTables<'_>,
+ obligation: &PredicateObligation<'tcx>,
+ next_code: Option<&ObligationCauseCode<'tcx>>,
+ ) {
+ let source_map = self.tcx.sess.source_map();
+
+ let is_async_fn = self
+ .tcx
+ .parent(first_generator)
+ .map(|parent_did| self.tcx.asyncness(parent_did))
+ .map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
+ .unwrap_or(false);
+ let is_async_move = self
+ .tcx
+ .hir()
+ .as_local_hir_id(first_generator)
+ .and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
+ .map(|body_id| self.tcx.hir().body(body_id))
+ .and_then(|body| body.generator_kind())
+ .map(|generator_kind| match generator_kind {
+ hir::GeneratorKind::Async(..) => true,
+ _ => false,
+ })
+ .unwrap_or(false);
+ let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
+
+ // Special case the primary error message when send or sync is the trait that was
+ // not implemented.
+ let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id);
+ let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id);
+ let hir = self.tcx.hir();
+ let trait_explanation = if is_send || is_sync {
+ let (trait_name, trait_verb) =
+ if is_send { ("`Send`", "sent") } else { ("`Sync`", "shared") };
+
+ err.clear_code();
+ err.set_primary_message(format!(
+ "future cannot be {} between threads safely",
+ trait_verb
+ ));
+
+ let original_span = err.span.primary_span().unwrap();
+ let mut span = MultiSpan::from_span(original_span);
+
+ let message = if let Some(name) = last_generator
+ .and_then(|generator_did| self.tcx.parent(generator_did))
+ .and_then(|parent_did| hir.as_local_hir_id(parent_did))
+ .and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
+ {
+ format!("future returned by `{}` is not {}", name, trait_name)
+ } else {
+ format!("future is not {}", trait_name)
+ };
+
+ span.push_span_label(original_span, message);
+ err.set_span(span);
+
+ format!("is not {}", trait_name)
+ } else {
+ format!("does not implement `{}`", trait_ref.print_only_trait_path())
+ };
+
+ // Look at the last interior type to get a span for the `.await`.
+ let await_span = tables.generator_interior_types.iter().map(|t| t.span).last().unwrap();
+ let mut span = MultiSpan::from_span(await_span);
+ span.push_span_label(
+ await_span,
+ format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
+ );
+
+ span.push_span_label(target_span, format!("has type `{}`", target_ty));
+
+ // If available, use the scope span to annotate the drop location.
+ if let Some(scope_span) = scope_span {
+ span.push_span_label(
+ source_map.end_point(*scope_span),
+ format!("`{}` is later dropped here", snippet),
+ );
+ }
+
+ err.span_note(
+ span,
+ &format!(
+ "future {} as this value is used across an {}",
+ trait_explanation, await_or_yield,
+ ),
+ );
+
+ if let Some(expr_id) = expr {
+ let expr = hir.expect_expr(expr_id);
+ let is_ref = tables.expr_adjustments(expr).iter().any(|adj| adj.is_region_borrow());
+ let parent = hir.get_parent_node(expr_id);
+ if let Some(hir::Node::Expr(e)) = hir.find(parent) {
+ let method_span = hir.span(parent);
+ if tables.is_method_call(e) && is_ref {
+ err.span_help(
+ method_span,
+ "consider moving this method call into a `let` \
+ binding to create a shorter lived borrow",
+ );
+ }
+ }
+ }
+
+ // Add a note for the item obligation that remains - normally a note pointing to the
+ // bound that introduced the obligation (e.g. `T: Send`).
+ debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code);
+ self.note_obligation_cause_code(
+ err,
+ &obligation.predicate,
+ next_code.unwrap(),
+ &mut Vec::new(),
+ );
+ }
+
+ crate fn note_obligation_cause_code<T>(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ predicate: &T,
+ cause_code: &ObligationCauseCode<'tcx>,
+ obligated_types: &mut Vec<&ty::TyS<'tcx>>,
+ ) where
+ T: fmt::Display,
+ {
+ let tcx = self.tcx;
+ match *cause_code {
+ ObligationCauseCode::ExprAssignable
+ | ObligationCauseCode::MatchExpressionArm { .. }
+ | ObligationCauseCode::Pattern { .. }
+ | ObligationCauseCode::IfExpression { .. }
+ | ObligationCauseCode::IfExpressionWithNoElse
+ | ObligationCauseCode::MainFunctionType
+ | ObligationCauseCode::StartFunctionType
+ | ObligationCauseCode::IntrinsicType
+ | ObligationCauseCode::MethodReceiver
+ | ObligationCauseCode::ReturnNoExpression
+ | ObligationCauseCode::MiscObligation => {}
+ ObligationCauseCode::SliceOrArrayElem => {
+ err.note("slice and array elements must have `Sized` type");
+ }
+ ObligationCauseCode::TupleElem => {
+ err.note("only the last element of a tuple may have a dynamically sized type");
+ }
+ ObligationCauseCode::ProjectionWf(data) => {
+ err.note(&format!("required so that the projection `{}` is well-formed", data,));
+ }
+ ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
+ err.note(&format!(
+ "required so that reference `{}` does not outlive its referent",
+ ref_ty,
+ ));
+ }
+ ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
+ err.note(&format!(
+ "required so that the lifetime bound of `{}` for `{}` is satisfied",
+ region, object_ty,
+ ));
+ }
+ ObligationCauseCode::ItemObligation(item_def_id) => {
+ let item_name = tcx.def_path_str(item_def_id);
+ let msg = format!("required by `{}`", item_name);
+
+ if let Some(sp) = tcx.hir().span_if_local(item_def_id) {
+ let sp = tcx.sess.source_map().def_span(sp);
+ err.span_label(sp, &msg);
+ } else {
+ err.note(&msg);
+ }
+ }
+ ObligationCauseCode::BindingObligation(item_def_id, span) => {
+ let item_name = tcx.def_path_str(item_def_id);
+ let msg = format!("required by this bound in `{}`", item_name);
+ if let Some(ident) = tcx.opt_item_name(item_def_id) {
+ err.span_label(ident.span, "");
+ }
+ if span != DUMMY_SP {
+ err.span_label(span, &msg);
+ } else {
+ err.note(&msg);
+ }
+ }
+ ObligationCauseCode::ObjectCastObligation(object_ty) => {
+ err.note(&format!(
+ "required for the cast to the object type `{}`",
+ self.ty_to_string(object_ty)
+ ));
+ }
+ ObligationCauseCode::Coercion { source: _, target } => {
+ err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
+ }
+ ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expressions) => {
+ err.note(
+ "the `Copy` trait is required because the repeated element will be copied",
+ );
+ if suggest_const_in_array_repeat_expressions {
+ err.note(
+ "this array initializer can be evaluated at compile-time, for more \
+ information, see issue \
+ https://github.com/rust-lang/rust/issues/49147",
+ );
+ if tcx.sess.opts.unstable_features.is_nightly_build() {
+ err.help(
+ "add `#![feature(const_in_array_repeat_expressions)]` to the \
+ crate attributes to enable",
+ );
+ }
+ }
+ }
+ ObligationCauseCode::VariableType(_) => {
+ err.note("all local variables must have a statically known size");
+ if !self.tcx.features().unsized_locals {
+ err.help("unsized locals are gated as an unstable feature");
+ }
+ }
+ ObligationCauseCode::SizedArgumentType => {
+ err.note("all function arguments must have a statically known size");
+ if !self.tcx.features().unsized_locals {
+ err.help("unsized locals are gated as an unstable feature");
+ }
+ }
+ ObligationCauseCode::SizedReturnType => {
+ err.note("the return type of a function must have a statically known size");
+ }
+ ObligationCauseCode::SizedYieldType => {
+ err.note("the yield type of a generator must have a statically known size");
+ }
+ ObligationCauseCode::AssignmentLhsSized => {
+ err.note("the left-hand-side of an assignment must have a statically known size");
+ }
+ ObligationCauseCode::TupleInitializerSized => {
+ err.note("tuples must have a statically known size to be initialized");
+ }
+ ObligationCauseCode::StructInitializerSized => {
+ err.note("structs must have a statically known size to be initialized");
+ }
+ ObligationCauseCode::FieldSized { adt_kind: ref item, last } => match *item {
+ AdtKind::Struct => {
+ if last {
+ err.note(
+ "the last field of a packed struct may only have a \
+ dynamically sized type if it does not need drop to be run",
+ );
+ } else {
+ err.note(
+ "only the last field of a struct may have a dynamically sized type",
+ );
+ }
+ }
+ AdtKind::Union => {
+ err.note("no field of a union may have a dynamically sized type");
+ }
+ AdtKind::Enum => {
+ err.note("no field of an enum variant may have a dynamically sized type");
+ }
+ },
+ ObligationCauseCode::ConstSized => {
+ err.note("constant expressions must have a statically known size");
+ }
+ ObligationCauseCode::ConstPatternStructural => {
+ err.note("constants used for pattern-matching must derive `PartialEq` and `Eq`");
+ }
+ ObligationCauseCode::SharedStatic => {
+ err.note("shared static variables must have a type that implements `Sync`");
+ }
+ ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
+ let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
+ let ty = parent_trait_ref.skip_binder().self_ty();
+ err.note(&format!("required because it appears within the type `{}`", ty));
+ obligated_types.push(ty);
+
+ let parent_predicate = parent_trait_ref.to_predicate();
+ if !self.is_recursive_obligation(obligated_types, &data.parent_code) {
+ self.note_obligation_cause_code(
+ err,
+ &parent_predicate,
+ &data.parent_code,
+ obligated_types,
+ );
+ }
+ }
+ ObligationCauseCode::ImplDerivedObligation(ref data) => {
+ let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
+ err.note(&format!(
+ "required because of the requirements on the impl of `{}` for `{}`",
+ parent_trait_ref.print_only_trait_path(),
+ parent_trait_ref.skip_binder().self_ty()
+ ));
+ let parent_predicate = parent_trait_ref.to_predicate();
+ self.note_obligation_cause_code(
+ err,
+ &parent_predicate,
+ &data.parent_code,
+ obligated_types,
+ );
+ }
+ ObligationCauseCode::CompareImplMethodObligation { .. } => {
+ err.note(&format!(
+ "the requirement `{}` appears on the impl method \
+ but not on the corresponding trait method",
+ predicate
+ ));
+ }
+ ObligationCauseCode::CompareImplTypeObligation { .. } => {
+ err.note(&format!(
+ "the requirement `{}` appears on the associated impl type \
+ but not on the corresponding associated trait type",
+ predicate
+ ));
+ }
+ ObligationCauseCode::ReturnType
+ | ObligationCauseCode::ReturnValue(_)
+ | ObligationCauseCode::BlockTailExpression(_) => (),
+ ObligationCauseCode::TrivialBound => {
+ err.help("see issue #48214");
+ if tcx.sess.opts.unstable_features.is_nightly_build() {
+ err.help("add `#![feature(trivial_bounds)]` to the crate attributes to enable");
+ }
+ }
+ ObligationCauseCode::AssocTypeBound(ref data) => {
+ err.span_label(data.original, "associated type defined here");
+ if let Some(sp) = data.impl_span {
+ err.span_label(sp, "in this `impl` item");
+ }
+ for sp in &data.bounds {
+ err.span_label(*sp, "restricted in this bound");
+ }
+ }
+ }
+ }
+
+ crate fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
+ let current_limit = self.tcx.sess.recursion_limit.get();
+ let suggested_limit = current_limit * 2;
+ err.help(&format!(
+ "consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
+ suggested_limit
+ ));
+ }
+}
+
+/// Suggest restricting a type param with a new bound.
+pub fn suggest_constraining_type_param(
+ generics: &hir::Generics<'_>,
+ err: &mut DiagnosticBuilder<'_>,
+ param_name: &str,
+ constraint: &str,
+ source_map: &SourceMap,
+ span: Span,
+) -> bool {
+ let restrict_msg = "consider further restricting this bound";
+ if let Some(param) =
+ generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next()
+ {
+ if param_name.starts_with("impl ") {
+ // `impl Trait` in argument:
+ // `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
+ err.span_suggestion(
+ param.span,
+ restrict_msg,
+ // `impl CurrentTrait + MissingTrait`
+ format!("{} + {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() {
+ // If there are no bounds whatsoever, suggest adding a constraint
+ // to the type parameter:
+ // `fn foo<T>(t: T) {}` → `fn foo<T: Trait>(t: T) {}`
+ err.span_suggestion(
+ param.span,
+ "consider restricting this bound",
+ format!("{}: {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else if !generics.where_clause.predicates.is_empty() {
+ // There is a `where` clause, so suggest expanding it:
+ // `fn foo<T>(t: T) where T: Debug {}` →
+ // `fn foo<T>(t: T) where T: Debug, T: Trait {}`
+ err.span_suggestion(
+ generics.where_clause.span().unwrap().shrink_to_hi(),
+ &format!("consider further restricting type parameter `{}`", param_name),
+ format!(", {}: {}", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else {
+ // If there is no `where` clause lean towards constraining to the
+ // type parameter:
+ // `fn foo<X: Bar, T>(t: T, x: X) {}` → `fn foo<T: Trait>(t: T) {}`
+ // `fn foo<T: Bar>(t: T) {}` → `fn foo<T: Bar + Trait>(t: T) {}`
+ let sp = param.span.with_hi(span.hi());
+ let span = source_map.span_through_char(sp, ':');
+ if sp != param.span && sp != span {
+ // Only suggest if we have high certainty that the span
+ // covers the colon in `foo<T: Trait>`.
+ err.span_suggestion(
+ span,
+ restrict_msg,
+ format!("{}: {} + ", param_name, constraint),
+ Applicability::MachineApplicable,
+ );
+ } else {
+ err.span_label(
+ param.span,
+ &format!("consider adding a `where {}: {}` bound", param_name, constraint),
+ );
+ }
+ }
+ return true;
+ }
+ false
+}
+
+/// Collect all the returned expressions within the input expression.
+/// Used to point at the return spans when we want to suggest some change to them.
+struct ReturnsVisitor<'v>(Vec<&'v hir::Expr<'v>>);
+
+impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
+ type Map = rustc::hir::map::Map<'v>;
+
+ fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap<'_, Self::Map> {
+ hir::intravisit::NestedVisitorMap::None
+ }
+
+ fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
+ if let hir::ExprKind::Ret(Some(ex)) = ex.kind {
+ self.0.push(ex);
+ }
+ hir::intravisit::walk_expr(self, ex);
+ }
+
+ fn visit_body(&mut self, body: &'v hir::Body<'v>) {
+ if body.generator_kind().is_none() {
+ if let hir::ExprKind::Block(block, None) = body.value.kind {
+ if let Some(expr) = block.expr {
+ self.0.push(expr);
+ }
+ }
+ }
+ hir::intravisit::walk_body(self, body);
+ }
+}
pub code: ObligationCauseCode<'tcx>,
}
-impl<'tcx> ObligationCause<'tcx> {
- pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span {
+impl ObligationCause<'_> {
+ pub fn span(&self, tcx: TyCtxt<'_>) -> Span {
match self.code {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
}
}
+impl ObligationCauseCode<'_> {
+ // Return the base obligation, ignoring derived obligations.
+ pub fn peel_derives(&self) -> &Self {
+ let mut base_cause = self;
+ while let BuiltinDerivedObligation(cause) | ImplDerivedObligation(cause) = base_cause {
+ base_cause = &cause.parent_code;
+ }
+ base_cause
+ }
+}
+
impl<'tcx, N> Vtable<'tcx, N> {
pub fn nested_obligations(self) -> Vec<N> {
match self {
use syntax::ast::{MetaItem, NestedMetaItem};
use syntax::attr;
-use rustc_error_codes::*;
-
#[derive(Clone, Debug)]
pub struct OnUnimplementedFormatString(Symbol);
use rustc_span::source_map::Span;
use std::iter::FromIterator;
-use rustc_error_codes::*;
-
impl<'cx, 'tcx> At<'cx, 'tcx> {
/// Given a type `ty` of some value being dropped, computes a set
/// of "kinds" (types, regions) that must be outlive the execution
debug!("winnowed to {} candidates for {:?}: {:?}", candidates.len(), stack, candidates);
+ let needs_infer = stack.obligation.predicate.needs_infer();
+
// If there are STILL multiple candidates, we can further
// reduce the list by dropping duplicates -- including
// resolving specializations.
let mut i = 0;
while i < candidates.len() {
let is_dup = (0..candidates.len()).filter(|&j| i != j).any(|j| {
- self.candidate_should_be_dropped_in_favor_of(&candidates[i], &candidates[j])
+ self.candidate_should_be_dropped_in_favor_of(
+ &candidates[i],
+ &candidates[j],
+ needs_infer,
+ )
});
if is_dup {
debug!("Dropping candidate #{}/{}: {:?}", i, candidates.len(), candidates[i]);
&mut self,
victim: &EvaluatedCandidate<'tcx>,
other: &EvaluatedCandidate<'tcx>,
+ needs_infer: bool,
) -> bool {
if victim.candidate == other.candidate {
return true;
match victim.candidate {
ImplCandidate(victim_def) => {
let tcx = self.tcx();
- return tcx.specializes((other_def, victim_def))
- || tcx
- .impls_are_allowed_to_overlap(other_def, victim_def)
- .is_some();
+ if tcx.specializes((other_def, victim_def)) {
+ return true;
+ }
+ return match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
+ Some(ty::ImplOverlapKind::Permitted { marker: true }) => {
+ // Subtle: If the predicate we are evaluating has inference
+ // variables, do *not* allow discarding candidates due to
+ // marker trait impls.
+ //
+ // Without this restriction, we could end up accidentally
+ // constrainting inference variables based on an arbitrarily
+ // chosen trait impl.
+ //
+ // Imagine we have the following code:
+ //
+ // ```rust
+ // #[marker] trait MyTrait {}
+ // impl MyTrait for u8 {}
+ // impl MyTrait for bool {}
+ // ```
+ //
+ // And we are evaluating the predicate `<_#0t as MyTrait>`.
+ //
+ // During selection, we will end up with one candidate for each
+ // impl of `MyTrait`. If we were to discard one impl in favor
+ // of the other, we would be left with one candidate, causing
+ // us to "successfully" select the predicate, unifying
+ // _#0t with (for example) `u8`.
+ //
+ // However, we have no reason to believe that this unification
+ // is correct - we've essentially just picked an arbitrary
+ // *possibility* for _#0t, and required that this be the *only*
+ // possibility.
+ //
+ // Eventually, we will either:
+ // 1) Unify all inference variables in the predicate through
+ // some other means (e.g. type-checking of a function). We will
+ // then be in a position to drop marker trait candidates
+ // without constraining inference variables (since there are
+ // none left to constrin)
+ // 2) Be left with some unconstrained inference variables. We
+ // will then correctly report an inference error, since the
+ // existence of multiple marker trait impls tells us nothing
+ // about which one should actually apply.
+ !needs_infer
+ }
+ Some(_) => true,
+ None => false,
+ };
}
ParamCandidate(ref cand) => {
// Prefer the impl to a global where clause candidate.
use super::util::impl_trait_ref_and_oblig;
use super::{FulfillmentContext, SelectionContext};
-use rustc_error_codes::*;
-
/// Information pertinent to an overlapping impl error.
#[derive(Debug)]
pub struct OverlapError {
tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling)
{
match overlap_kind {
- ty::ImplOverlapKind::Permitted => {}
+ ty::ImplOverlapKind::Permitted { marker: _ } => {}
ty::ImplOverlapKind::Issue33140 => {
last_lint = Some(FutureCompatOverlapError {
error: overlap_error(overlap),
match tcx.hir().as_local_hir_id(node_item_def_id) {
Some(hir_id) => {
let item = tcx.hir().expect_item(hir_id);
- if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.kind {
+ if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
defaultness.is_default()
} else {
false
// |
// = note: expected type `u32`
// found type `()`
- if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
+ if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
- if let Some(impl_item) = impl_items
+ if let Some(impl_item) = items
.iter()
.filter(|item| item.ident == trait_assoc_item.ident)
.next()
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
if let (
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
- Some(hir::ItemKind::Impl(.., impl_items)),
+ Some(hir::ItemKind::Impl { items, .. }),
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
{
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
.filter(|i| i.def_id == *item_def_id)
.next()
.and_then(|trait_assoc_item| {
- impl_items
+ items
.iter()
.filter(|i| i.ident == trait_assoc_item.ident)
.next()
use rustc_session::config::{BorrowckMode, OutputFilenames};
use rustc_session::Session;
-use arena::SyncDroplessArena;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::SelfProfilerRef;
-use rustc_data_structures::sharded::ShardedHashMap;
+use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{
hash_stable_hashmap, HashStable, StableHasher, StableVec,
};
use syntax::attr;
use syntax::expand::allocator::AllocatorKind;
-pub struct AllArenas {
- pub interner: SyncDroplessArena,
-}
-
-impl AllArenas {
- pub fn new() -> Self {
- AllArenas { interner: SyncDroplessArena::default() }
- }
-}
-
type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;
pub struct CtxtInterners<'tcx> {
/// The arena that types, regions, etc. are allocated from.
- arena: &'tcx SyncDroplessArena,
+ arena: &'tcx WorkerLocal<Arena<'tcx>>,
/// Specifically use a speedy hash algorithm for these hash sets, since
/// they're accessed quite often.
}
impl<'tcx> CtxtInterners<'tcx> {
- fn new(arena: &'tcx SyncDroplessArena) -> CtxtInterners<'tcx> {
+ fn new(arena: &'tcx WorkerLocal<Arena<'tcx>>) -> CtxtInterners<'tcx> {
CtxtInterners {
arena,
type_: Default::default(),
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
local_providers: ty::query::Providers<'tcx>,
extern_providers: ty::query::Providers<'tcx>,
- arenas: &'tcx AllArenas,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
resolutions: ty::ResolverOutputs,
hir: hir_map::Map<'tcx>,
let data_layout = TargetDataLayout::parse(&s.target.target).unwrap_or_else(|err| {
s.fatal(&err);
});
- let interners = CtxtInterners::new(&arenas.interner);
+ let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(&interners);
let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types);
}
macro_rules! nop_lift {
- ($ty:ty => $lifted:ty) => {
+ ($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for $ty {
type Lifted = $lifted;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
- if tcx.interners.arena.in_arena(*self as *const _) {
+ if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
Some(unsafe { mem::transmute(*self) })
} else {
None
}
macro_rules! nop_list_lift {
- ($ty:ty => $lifted:ty) => {
+ ($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
type Lifted = &'tcx List<$lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
if self.is_empty() {
return Some(List::empty());
}
- if tcx.interners.arena.in_arena(*self as *const _) {
+ if tcx.interners.$set.contains_pointer_to(&Interned(*self)) {
Some(unsafe { mem::transmute(*self) })
} else {
None
};
}
-nop_lift! {Ty<'a> => Ty<'tcx>}
-nop_lift! {Region<'a> => Region<'tcx>}
-nop_lift! {Goal<'a> => Goal<'tcx>}
-nop_lift! {&'a Const<'a> => &'tcx Const<'tcx>}
+nop_lift! {type_; Ty<'a> => Ty<'tcx>}
+nop_lift! {region; Region<'a> => Region<'tcx>}
+nop_lift! {goal; Goal<'a> => Goal<'tcx>}
+nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
-nop_list_lift! {Goal<'a> => Goal<'tcx>}
-nop_list_lift! {Clause<'a> => Clause<'tcx>}
-nop_list_lift! {Ty<'a> => Ty<'tcx>}
-nop_list_lift! {ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
-nop_list_lift! {Predicate<'a> => Predicate<'tcx>}
-nop_list_lift! {CanonicalVarInfo => CanonicalVarInfo}
-nop_list_lift! {ProjectionKind => ProjectionKind}
+nop_list_lift! {goal_list; Goal<'a> => Goal<'tcx>}
+nop_list_lift! {clauses; Clause<'a> => Clause<'tcx>}
+nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
+nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
+nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
+nop_list_lift! {canonical_var_infos; CanonicalVarInfo => CanonicalVarInfo}
+nop_list_lift! {projs; ProjectionKind => ProjectionKind}
// This is the impl for `&'a InternalSubsts<'a>`.
-nop_list_lift! {GenericArg<'a> => GenericArg<'tcx>}
+nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
pub mod tls {
use super::{ptr_eq, GlobalCtxt, TyCtxt};
}
impl<'tcx, T: 'tcx + ?Sized> Copy for Interned<'tcx, T> {}
+impl<'tcx, T: 'tcx + ?Sized> IntoPointer for Interned<'tcx, T> {
+ fn into_pointer(&self) -> *const () {
+ self.0 as *const _ as *const ()
+ }
+}
// N.B., an `Interned<Ty>` compares and hashes as a `TyKind`.
impl<'tcx> PartialEq for Interned<'tcx, TyS<'tcx>> {
fn eq(&self, other: &Interned<'tcx, TyS<'tcx>>) -> bool {
$(impl<'tcx> TyCtxt<'tcx> {
pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
self.interners.$field.intern_ref(v, || {
- Interned(List::from_arena(&self.interners.arena, v))
+ Interned(List::from_arena(&*self.arena, v))
}).0
}
})+
ty::FnPtr(_) => "fn pointer".into(),
ty::Dynamic(ref inner, ..) => {
if let Some(principal) = inner.principal() {
- format!("trait `{}`", tcx.def_path_str(principal.def_id())).into()
+ format!("trait object `dyn {}`", tcx.def_path_str(principal.def_id())).into()
} else {
- "trait".into()
+ "trait object".into()
}
}
ty::Closure(..) => "closure".into(),
pub use self::IntVarValue::*;
pub use self::Variance::*;
+use crate::arena::Arena;
use crate::hir::exports::ExportMap;
use crate::hir::map as hir_map;
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
use crate::ty::util::{Discr, IntTypeExt};
use crate::ty::walk::TypeWalker;
-use arena::SyncDroplessArena;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::FxIndexMap;
pub use self::binding::BindingMode;
pub use self::binding::BindingMode::*;
-pub use self::context::{keep_local, tls, AllArenas, FreeRegionInfo, TyCtxt};
+pub use self::context::{keep_local, tls, FreeRegionInfo, TyCtxt};
pub use self::context::{
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
UserType, UserTypeAnnotationIndex,
impl<T: Copy> List<T> {
#[inline]
- fn from_arena<'tcx>(arena: &'tcx SyncDroplessArena, slice: &[T]) -> &'tcx List<T> {
+ fn from_arena<'tcx>(arena: &'tcx Arena<'tcx>, slice: &[T]) -> &'tcx List<T> {
assert!(!mem::needs_drop::<T>());
assert!(mem::size_of::<T>() != 0);
assert!(slice.len() != 0);
let size = offset + slice.len() * mem::size_of::<T>();
- let mem = arena.alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>()));
+ let mem = arena
+ .dropless
+ .alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>()));
unsafe {
let result = &mut *(mem.as_mut_ptr() as *mut List<T>);
// Write the length
#[derive(Debug, PartialEq, Eq)]
pub enum ImplOverlapKind {
/// These impls are always allowed to overlap.
- Permitted,
+ Permitted {
+ /// Whether or not the impl is permitted due to the trait being
+ /// a marker trait (a trait with #[marker], or a trait with
+ /// no associated items and #![feature(overlapping_marker_traits)] enabled)
+ marker: bool,
+ },
/// These impls are allowed to overlap, but that raises
/// an issue #33140 future-compatibility warning.
///
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error())
|| self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error())
{
- return Some(ImplOverlapKind::Permitted);
+ return Some(ImplOverlapKind::Permitted { marker: false });
}
match (self.impl_polarity(def_id1), self.impl_polarity(def_id2)) {
"impls_are_allowed_to_overlap({:?}, {:?}) = Some(Permitted) (reservations)",
def_id1, def_id2
);
- return Some(ImplOverlapKind::Permitted);
+ return Some(ImplOverlapKind::Permitted { marker: false });
}
(ImplPolarity::Positive, ImplPolarity::Negative)
| (ImplPolarity::Negative, ImplPolarity::Positive) => {
"impls_are_allowed_to_overlap({:?}, {:?}) = Some(Permitted) (marker overlap)",
def_id1, def_id2
);
- Some(ImplOverlapKind::Permitted)
+ Some(ImplOverlapKind::Permitted { marker: true })
} else {
if let Some(self_ty1) = self.issue33140_self_ty(def_id1) {
if let Some(self_ty2) = self.issue33140_self_ty(def_id2) {
use std::mem;
use std::ptr;
-use rustc_error_codes::*;
-
pub struct QueryCache<'tcx, D: QueryConfig<'tcx> + ?Sized> {
pub(super) results: FxHashMap<D::Key, QueryValue<D::Value>>,
pub(super) active: FxHashMap<D::Key, QueryResult<'tcx>>,
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_index = { path = "../librustc_index" }
rustc_span = { path = "../librustc_span" }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_errors = { path = "../librustc_errors" }
rustc_session = { path = "../librustc_session" }
syntax = { path = "../libsyntax" }
use rustc::bug;
use rustc_data_structures::thin_vec::ThinVec;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::Res;
fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind<'hir> {
let inner = hir::InlineAsmInner {
- inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
+ inputs: asm.inputs.iter().map(|&(c, _)| c).collect(),
outputs: asm
.outputs
.iter()
.map(|out| hir::InlineAsmOutput {
- constraint: out.constraint.clone(),
+ constraint: out.constraint,
is_rw: out.is_rw,
is_indirect: out.is_indirect,
span: out.expr.span,
})
.collect(),
- asm: asm.asm.clone(),
+ asm: asm.asm,
asm_str_style: asm.asm_str_style,
clobbers: asm.clobbers.clone().into(),
volatile: asm.volatile,
use rustc::arena::Arena;
use rustc::bug;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
if let Some(hir_id) = item_hir_id {
self.lctx.with_parent_item_lifetime_defs(hir_id, |this| {
let this = &mut ItemLowerer { lctx: this };
- if let ItemKind::Impl(.., ref opt_trait_ref, _, _) = item.kind {
- if opt_trait_ref.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
+ if let ItemKind::Impl { ref of_trait, .. } = item.kind {
+ if of_trait.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
+ this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
this.lctx
.diagnostic()
.span_err(item.span, "const trait impls are not yet implemented");
}
- this.with_trait_impl_ref(opt_trait_ref, |this| visit::walk_item(this, item));
+ this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
} else {
visit::walk_item(this, item);
}
let old_len = self.in_scope_lifetimes.len();
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
- hir::ItemKind::Impl(_, _, _, ref generics, ..)
+ hir::ItemKind::Impl { ref generics, .. }
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
_ => &[],
};
vec
}
ItemKind::MacroDef(..) => SmallVec::new(),
- ItemKind::Fn(..) | ItemKind::Impl(.., None, _, _) => smallvec![i.id],
+ ItemKind::Fn(..) | ItemKind::Impl { of_trait: None, .. } => smallvec![i.id],
ItemKind::Static(ref ty, ..) => {
let mut ids = smallvec![i.id];
if self.sess.features_untracked().impl_trait_in_bindings {
self.lower_generics(generics, ImplTraitContext::disallowed()),
)
}
- ItemKind::Impl(
+ ItemKind::Impl {
unsafety,
polarity,
defaultness,
- ref ast_generics,
- ref trait_ref,
- ref ty,
- ref impl_items,
- ) => {
+ generics: ref ast_generics,
+ of_trait: ref trait_ref,
+ self_ty: ref ty,
+ items: ref impl_items,
+ } => {
let def_id = self.resolver.definitions().local_def_id(id);
// Lower the "impl header" first. This ordering is important
)
});
- hir::ItemKind::Impl(
+ hir::ItemKind::Impl {
unsafety,
polarity,
- self.lower_defaultness(defaultness, true /* [1] */),
+ defaultness: self.lower_defaultness(defaultness, true /* [1] */),
generics,
- trait_ref,
- lowered_ty,
- new_impl_items,
- )
+ of_trait: trait_ref,
+ self_ty: lowered_ty,
+ items: new_impl_items,
+ }
}
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
use rustc::lint::builtin::ELIDED_LIFETIMES_IN_PATHS;
use rustc::span_bug;
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, PartialRes, Res};
log = "0.4"
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_feature = { path = "../librustc_feature" }
rustc_parse = { path = "../librustc_parse" }
rustc_session = { path = "../librustc_session" }
use syntax::visit::{self, Visitor};
use syntax::walk_list;
-use rustc_error_codes::*;
-
/// A syntactic context that disallows certain kinds of bounds (e.g., `?Trait` or `?const Trait`).
#[derive(Clone, Copy)]
enum BoundContext {
}
match item.kind {
- ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
+ ItemKind::Impl {
+ unsafety,
+ polarity,
+ defaultness: _,
+ generics: _,
+ of_trait: Some(_),
+ ref self_ty,
+ ref items,
+ } => {
self.invalid_visibility(&item.vis, None);
- if let TyKind::Err = ty.kind {
+ if let TyKind::Err = self_ty.kind {
self.err_handler()
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
.help("use `auto trait Trait {}` instead")
)
.emit();
}
- for impl_item in impl_items {
+ for impl_item in items {
self.invalid_visibility(&impl_item.vis, None);
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
self.check_trait_fn_not_const(sig.header.constness);
}
}
}
- ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
+ ItemKind::Impl {
+ unsafety,
+ polarity,
+ defaultness,
+ generics: _,
+ of_trait: None,
+ self_ty: _,
+ items: _,
+ } => {
self.invalid_visibility(
&item.vis,
Some("place qualifiers on individual impl items instead"),
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Handler};
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
use rustc_feature::{Features, GateIssue, UnstableFeatures};
}
}
- ast::ItemKind::Impl(_, polarity, defaultness, ..) => {
+ ast::ItemKind::Impl { polarity, defaultness, .. } => {
if polarity == ast::ImplPolarity::Negative {
gate_feature_post!(
&self,
visit::walk_expr(self, e)
}
- fn visit_arm(&mut self, arm: &'a ast::Arm) {
- visit::walk_arm(self, arm)
- }
-
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
match &pattern.kind {
- PatKind::Slice(pats) => {
- for pat in &*pats {
- let span = pat.span;
- let inner_pat = match &pat.kind {
- PatKind::Ident(.., Some(pat)) => pat,
- _ => pat,
- };
- if inner_pat.is_rest() {
- gate_feature_post!(
- &self,
- slice_patterns,
- span,
- "subslice patterns are unstable"
- );
- }
- }
- }
PatKind::Box(..) => {
gate_feature_post!(
&self,
//! parsed by `rustc_parse` and then lowered, after the passes in this crate,
//! by `rustc_ast_lowering`.
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
pub mod ast_validation;
pub mod feature_gate;
syntax = { path = "../libsyntax" }
rustc_expand = { path = "../librustc_expand" }
rustc_span = { path = "../librustc_span" }
-rustc_error_codes = { path = "../librustc_error_codes" }
use syntax::token::{self, Token};
use syntax::tokenstream::{self, TokenStream};
-use rustc_error_codes::*;
-
enum State {
Asm,
Outputs,
use syntax::ast::{Expr, MetaItem};
use syntax::ptr::P;
-use rustc_error_codes::*;
-
pub fn expand_deriving_default(
cx: &mut ExtCtxt<'_>,
span: Span,
self.span,
Ident::invalid(),
a,
- ast::ItemKind::Impl(
+ ast::ItemKind::Impl {
unsafety,
- ast::ImplPolarity::Positive,
- ast::Defaultness::Final,
- trait_generics,
- opt_trait_ref,
- self_type,
- methods.into_iter().chain(associated_types).collect(),
- ),
+ polarity: ast::ImplPolarity::Positive,
+ defaultness: ast::Defaultness::Final,
+ generics: trait_generics,
+ of_trait: opt_trait_ref,
+ self_ty: self_type,
+ items: methods.into_iter().chain(associated_types).collect(),
+ },
)
}
} else {
ast::BindingMode::ByRef(mutbl)
};
- cx.pat(path.span, PatKind::Ident(binding_mode, (*path).clone(), None))
+ cx.pat(path.span, PatKind::Ident(binding_mode, *path, None))
})
.collect()
}
span,
ast::Ident::invalid(),
attrs,
- ItemKind::Impl(
- ast::Unsafety::Normal,
- ast::ImplPolarity::Positive,
- ast::Defaultness::Final,
+ ItemKind::Impl {
+ unsafety: ast::Unsafety::Normal,
+ polarity: ast::ImplPolarity::Positive,
+ defaultness: ast::Defaultness::Final,
generics,
- Some(trait_ref),
- self_type,
- Vec::new(),
- ),
+ of_trait: Some(trait_ref),
+ self_ty: self_type,
+ items: Vec::new(),
+ },
);
push(Annotatable::Item(newitem));
parse::NextArgument(ref arg) => {
// Build the position
let pos = {
- let pos = |c, arg| {
- let mut path = Context::rtpath(self.ecx, "Position");
- path.push(self.ecx.ident_of(c, sp));
- match arg {
- Some(i) => {
- let arg = self.ecx.expr_usize(sp, i);
- self.ecx.expr_call_global(sp, path, vec![arg])
- }
- None => self.ecx.expr_path(self.ecx.path_global(sp, path)),
- }
- };
match arg.position {
parse::ArgumentIs(i) | parse::ArgumentImplicitlyIs(i) => {
// Map to index in final generated argument array
arg_idx
}
};
- pos("At", Some(arg_idx))
+ self.ecx.expr_usize(sp, arg_idx)
}
// should never be the case, because names are already
rustc_incremental = { path = "../librustc_incremental" }
rustc_index = { path = "../librustc_index" }
rustc_target = { path = "../librustc_target" }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for &(symbol, level) in tcx.exported_symbols(LOCAL_CRATE).iter() {
if level.is_below_threshold(export_threshold) {
- symbols.push(symbol.symbol_name(tcx).to_string());
+ symbols.push(symbol_export::symbol_name_for_instance_in_crate(
+ tcx,
+ symbol,
+ LOCAL_CRATE,
+ ));
}
}
continue;
}
- // FIXME rust-lang/rust#64319, rust-lang/rust#64872:
- // We want to block export of generics from dylibs,
- // but we must fix rust-lang/rust#65890 before we can
- // do that robustly.
-
- symbols.push(symbol.symbol_name(tcx).to_string());
+ symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
}
}
}
use rustc::ty::subst::SubstsRef;
use rustc::ty::Instance;
use rustc::ty::{SymbolName, TyCtxt};
+use rustc_codegen_utils::symbol_names;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
SymbolExportLevel::Rust
}
}
+
+/// This is the symbol name of the given instance instantiated in a specific crate.
+pub fn symbol_name_for_instance_in_crate<'tcx>(
+ tcx: TyCtxt<'tcx>,
+ symbol: ExportedSymbol<'tcx>,
+ instantiating_crate: CrateNum,
+) -> String {
+ // If this is something instantiated in the local crate then we might
+ // already have cached the name as a query result.
+ if instantiating_crate == LOCAL_CRATE {
+ return symbol.symbol_name_for_local_instance(tcx).to_string();
+ }
+
+ // This is something instantiated in an upstream crate, so we have to use
+ // the slower (because uncached) version of computing the symbol name.
+ match symbol {
+ ExportedSymbol::NonGeneric(def_id) => symbol_names::symbol_name_for_instance_in_crate(
+ tcx,
+ Instance::mono(tcx, def_id),
+ instantiating_crate,
+ ),
+ ExportedSymbol::Generic(def_id, substs) => symbol_names::symbol_name_for_instance_in_crate(
+ tcx,
+ Instance::new(def_id, substs),
+ instantiating_crate,
+ ),
+ ExportedSymbol::NoDefId(symbol_name) => symbol_name.to_string(),
+ }
+}
use super::link::{self, get_linker, remove};
use super::linker::LinkerInfo;
use super::lto::{self, SerializedModule};
-use super::symbol_export::ExportedSymbols;
+use super::symbol_export::{symbol_name_for_instance_in_crate, ExportedSymbols};
use crate::{
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind,
RLIB_BYTECODE_EXTENSION,
let symbols = tcx
.exported_symbols(cnum)
.iter()
- .map(|&(s, lvl)| (s.symbol_name(tcx).to_string(), lvl))
+ .map(|&(s, lvl)| (symbol_name_for_instance_in_crate(tcx, s, cnum), lvl))
.collect();
Arc::new(symbols)
};
use crate::traits::BuilderMethods;
use rustc_hir as hir;
-use rustc_error_codes::*;
-
pub enum IntPredicate {
IntEQ,
IntNE,
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(libc)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(stmt_expr_attributes)]
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
use crate::traits::BuilderMethods;
use crate::traits::*;
-use rustc_error_codes::*;
-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx>) -> Bx {
debug!("codegen_statement(statement={:?})", statement);
use rustc::mir::mono::{InstantiationMode, MonoItem};
use rustc::session::config::SymbolManglingVersion;
use rustc::ty::query::Providers;
+use rustc::ty::subst::SubstsRef;
use rustc::ty::{self, Instance, TyCtxt};
-use rustc_hir::def_id::LOCAL_CRATE;
+use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_hir::Node;
use rustc_span::symbol::Symbol;
mod legacy;
mod v0;
+/// This function computes the symbol name for the given `instance` and the
+/// given instantiating crate. That is, if you know that instance X is
+/// instantiated in crate Y, this is the symbol name this instance would have.
+pub fn symbol_name_for_instance_in_crate(
+ tcx: TyCtxt<'tcx>,
+ instance: Instance<'tcx>,
+ instantiating_crate: CrateNum,
+) -> String {
+ compute_symbol_name(tcx, instance, || instantiating_crate)
+}
+
pub fn provide(providers: &mut Providers<'_>) {
- *providers = Providers {
- symbol_name: |tcx, instance| ty::SymbolName { name: symbol_name(tcx, instance) },
+ *providers = Providers { symbol_name: symbol_name_provider, ..*providers };
+}
- ..*providers
- };
+// The `symbol_name` query provides the symbol name for calling a given
+// instance from the local crate. In particular, it will also look up the
+// correct symbol name of instances from upstream crates.
+fn symbol_name_provider(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
+ let symbol_name = compute_symbol_name(tcx, instance, || {
+ // This closure determines the instantiating crate for instances that
+ // need an instantiating-crate-suffix for their symbol name, in order
+ // to differentiate between local copies.
+ //
+ // For generics we might find re-usable upstream instances. For anything
+ // else we rely on their being a local copy available.
+
+ if is_generic(instance.substs) {
+ let def_id = instance.def_id();
+
+ if !def_id.is_local() && tcx.sess.opts.share_generics() {
+ // If we are re-using a monomorphization from another crate,
+ // we have to compute the symbol hash accordingly.
+ let upstream_monomorphizations = tcx.upstream_monomorphizations_for(def_id);
+
+ upstream_monomorphizations
+ .and_then(|monos| monos.get(&instance.substs).cloned())
+ // If there is no instance available upstream, there'll be
+ // one in the current crate.
+ .unwrap_or(LOCAL_CRATE)
+ } else {
+ // For generic functions defined in the current crate, there
+ // can be no upstream instances. Also, if we don't share
+ // generics, we'll instantiate a local copy too.
+ LOCAL_CRATE
+ }
+ } else {
+ // For non-generic things that need to avoid naming conflicts, we
+ // always instantiate a copy in the local crate.
+ LOCAL_CRATE
+ }
+ });
+
+ ty::SymbolName { name: Symbol::intern(&symbol_name) }
}
-fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Symbol {
+/// Computes the symbol name for the given instance. This function will call
+/// `compute_instantiating_crate` if it needs to factor the instantiating crate
+/// into the symbol name.
+fn compute_symbol_name(
+ tcx: TyCtxt<'tcx>,
+ instance: Instance<'tcx>,
+ compute_instantiating_crate: impl FnOnce() -> CrateNum,
+) -> String {
let def_id = instance.def_id();
let substs = instance.substs;
if def_id.is_local() {
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
- return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
+ return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
}
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
- return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
+ return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
}
}
|| !tcx.wasm_import_module_map(def_id.krate).contains_key(&def_id)
{
if let Some(name) = attrs.link_name {
- return name;
+ return name.to_string();
}
- return tcx.item_name(def_id);
+ return tcx.item_name(def_id).to_string();
}
}
if let Some(name) = attrs.export_name {
// Use provided name
- return name;
+ return name.to_string();
}
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
// Don't mangle
- return tcx.item_name(def_id);
+ return tcx.item_name(def_id).to_string();
}
- let is_generic = substs.non_erasable_generics().next().is_some();
let avoid_cross_crate_conflicts =
// If this is an instance of a generic function, we also hash in
// the ID of the instantiating crate. This avoids symbol conflicts
// in case the same instances is emitted in two crates of the same
// project.
- is_generic ||
+ is_generic(substs) ||
// If we're dealing with an instance of a function that's inlined from
// another crate but we're marking it as globally shared to our
_ => false,
};
- let instantiating_crate = if avoid_cross_crate_conflicts {
- Some(if is_generic {
- if !def_id.is_local() && tcx.sess.opts.share_generics() {
- // If we are re-using a monomorphization from another crate,
- // we have to compute the symbol hash accordingly.
- let upstream_monomorphizations = tcx.upstream_monomorphizations_for(def_id);
-
- upstream_monomorphizations
- .and_then(|monos| monos.get(&substs).cloned())
- .unwrap_or(LOCAL_CRATE)
- } else {
- LOCAL_CRATE
- }
- } else {
- LOCAL_CRATE
- })
- } else {
- None
- };
+ let instantiating_crate =
+ if avoid_cross_crate_conflicts { Some(compute_instantiating_crate()) } else { None };
// Pick the crate responsible for the symbol mangling version, which has to:
// 1. be stable for each instance, whether it's being defined or imported
tcx.symbol_mangling_version(mangling_version_crate)
};
- let mangled = match mangling_version {
+ match mangling_version {
SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate),
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate),
- };
+ }
+}
- Symbol::intern(&mangled)
+fn is_generic(substs: SubstsRef<'_>) -> bool {
+ substs.non_erasable_generics().next().is_some()
}
}
}
+// keep this in sync with the `-Z self-profile-events` help message in librustc_session/options.rs
const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
("none", EventFilter::NONE),
("all", EventFilter::ALL),
+ ("default", EventFilter::DEFAULT),
("generic-activity", EventFilter::GENERIC_ACTIVITIES),
("query-provider", EventFilter::QUERY_PROVIDERS),
("query-cache-hit", EventFilter::QUERY_CACHE_HITS),
}
}
+pub trait IntoPointer {
+ /// Returns a pointer which outlives `self`.
+ fn into_pointer(&self) -> *const ();
+}
+
+impl<K: Eq + Hash + Copy + IntoPointer> ShardedHashMap<K, ()> {
+ pub fn contains_pointer_to<T: Hash + IntoPointer>(&self, value: &T) -> bool {
+ let hash = make_hash(&value);
+ let shard = self.get_shard_by_hash(hash).lock();
+ let value = value.into_pointer();
+ shard.raw_entry().from_hash(hash, |entry| entry.into_pointer() == value).is_some()
+ }
+}
+
#[inline]
fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
let mut state = FxHasher::default();
E0743: include_str!("./error_codes/E0743.md"),
E0744: include_str!("./error_codes/E0744.md"),
E0745: include_str!("./error_codes/E0745.md"),
+E0746: include_str!("./error_codes/E0746.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
-Your method's lifetime parameters do not match the trait declaration.
+The lifetime parameters of the method do not match the trait declaration.
+
Erroneous code example:
```compile_fail,E0195
}
```
-The lifetime constraint `'b` for bar() implementation does not match the
+The lifetime constraint `'b` for `bar()` implementation does not match the
trait declaration. Ensure lifetime declarations match exactly in both trait
declaration and implementation. Example:
+An inherent implementation was marked unsafe.
+
+Erroneous code example:
+
+```compile_fail,E0197
+struct Foo;
+
+unsafe impl Foo { } // error!
+```
+
Inherent implementations (one that do not implement a trait but provide
methods associated with a type) are always safe because they are not
implementing an unsafe trait. Removing the `unsafe` keyword from the inherent
implementation will resolve this error.
-```compile_fail,E0197
+```
struct Foo;
-// this will cause this error
-unsafe impl Foo { }
-// converting it to this will fix it
-impl Foo { }
+impl Foo { } // ok!
```
-A negative implementation is one that excludes a type from implementing a
-particular trait. Not being able to use a trait is always a safe operation,
-so negative implementations are always safe and never need to be marked as
-unsafe.
+A negative implementation was marked as unsafe.
-```compile_fail
-#![feature(optin_builtin_traits)]
+Erroneous code example:
+```compile_fail
struct Foo;
-// unsafe is unnecessary
-unsafe impl !Clone for Foo { }
+unsafe impl !Clone for Foo { } // error!
```
+A negative implementation is one that excludes a type from implementing a
+particular trait. Not being able to use a trait is always a safe operation,
+so negative implementations are always safe and never need to be marked as
+unsafe.
+
This will compile:
```ignore (ignore auto_trait future compatibility warning)
+A trait implementation was marked as unsafe while the trait is safe.
+
+Erroneous code example:
+
+```compile_fail,E0199
+struct Foo;
+
+trait Bar { }
+
+unsafe impl Bar for Foo { } // error!
+```
+
Safe traits should not have unsafe implementations, therefore marking an
implementation for a safe trait unsafe will cause a compiler error. Removing
-the unsafe marker on the trait noted in the error will resolve this problem.
+the unsafe marker on the trait noted in the error will resolve this problem:
-```compile_fail,E0199
+```
struct Foo;
trait Bar { }
-// this won't compile because Bar is safe
-unsafe impl Bar for Foo { }
-// this will compile
-impl Bar for Foo { }
+impl Bar for Foo { } // ok!
```
+An unsafe trait was implemented without an unsafe implementation.
+
+Erroneous code example:
+
+```compile_fail,E0200
+struct Foo;
+
+unsafe trait Bar { }
+
+impl Bar for Foo { } // error!
+```
+
Unsafe traits must have unsafe implementations. This error occurs when an
implementation for an unsafe trait isn't marked as unsafe. This may be resolved
by marking the unsafe implementation as unsafe.
-```compile_fail,E0200
+```
struct Foo;
unsafe trait Bar { }
-// this won't compile because Bar is unsafe and impl isn't unsafe
-impl Bar for Foo { }
-// this will compile
-unsafe impl Bar for Foo { }
+unsafe impl Bar for Foo { } // ok!
```
-It is an error to define two associated items (like methods, associated types,
-associated functions, etc.) with the same identifier.
+Two associated items (like methods, associated types, associated functions,
+etc.) were defined with the same identifier.
-For example:
+Erroneous code example:
```compile_fail,E0201
struct Foo(u8);
-An attempt to implement the `Copy` trait for a struct failed because one of the
-fields does not implement `Copy`. To fix this, you must implement `Copy` for the
-mentioned field. Note that this may not be possible, as in the example of
+The `Copy` trait was implemented on a type which contains a field that doesn't
+implement the `Copy` trait.
+
+Erroneous code example:
```compile_fail,E0204
struct Foo {
- foo : Vec<u32>,
+ foo: Vec<u32>,
}
-impl Copy for Foo { }
+impl Copy for Foo { } // error!
```
-This fails because `Vec<T>` does not implement `Copy` for any `T`.
+The `Copy` trait is implemented by default only on primitive types. If your
+type only contains primitive types, you'll be able to implement `Copy` on it.
+Otherwise, it won't be possible.
Here's another example that will fail:
```compile_fail,E0204
-#[derive(Copy)]
+#[derive(Copy)] // error!
struct Foo<'a> {
ty: &'a mut bool,
}
array. Additional elements can be matched with `..`:
```
-#![feature(slice_patterns)]
-
let r = &[1, 2, 3, 4];
match r {
&[a, b, ..] => { // ok!
Example of erroneous code:
```compile_fail,E0528
-#![feature(slice_patterns)]
-
let r = &[1, 2];
match r {
&[a, b, c, rest @ ..] => { // error: pattern requires at least 3
requires. You can match an arbitrary number of remaining elements with `..`:
```
-#![feature(slice_patterns)]
-
let r = &[1, 2, 3, 4, 5];
match r {
&[a, b, c, rest @ ..] => { // ok!
array. Additional elements can be matched with `..`:
```
-#![feature(slice_patterns)]
-
let r = &[1, 2, 3, 4];
match r {
&[a, b, ..] => { // ok!
--- /dev/null
+Return types cannot be `dyn Trait`s as they must be `Sized`.
+
+Erroneous code example:
+
+```compile_fail,E0277
+# // FIXME: after E0746 is in beta, change the above
+trait T {
+ fn bar(&self);
+}
+struct S(usize);
+impl T for S {
+ fn bar(&self) {}
+}
+
+// Having the trait `T` as return type is invalid because
+// unboxed trait objects do not have a statically known size:
+fn foo() -> dyn T {
+ S(42)
+}
+```
+
+To avoid the error there are a couple of options.
+
+If there is a single type involved, you can use [`impl Trait`]:
+
+```
+# trait T {
+# fn bar(&self);
+# }
+# struct S(usize);
+# impl T for S {
+# fn bar(&self) {}
+# }
+// The compiler will select `S(usize)` as the materialized return type of this
+// function, but callers will only know that the return type implements `T`.
+fn foo() -> impl T {
+ S(42)
+}
+```
+
+If there are multiple types involved, the only way you care to interact with
+them is through the trait's interface, and having to rely on dynamic dispatch
+is acceptable, then you can use [trait objects] with `Box`, or other container
+types like `Rc` or `Arc`:
+
+```
+# trait T {
+# fn bar(&self);
+# }
+# struct S(usize);
+# impl T for S {
+# fn bar(&self) {}
+# }
+struct O(&'static str);
+impl T for O {
+ fn bar(&self) {}
+}
+
+// This now returns a "trait object" and callers are only be able to access
+// associated items from `T`.
+fn foo(x: bool) -> Box<dyn T> {
+ if x {
+ Box::new(S(42))
+ } else {
+ Box::new(O("val"))
+ }
+}
+```
+
+Finally, if you wish to still be able to access the original type, you can
+create a new `enum` with a variant for each type:
+
+```
+# trait T {
+# fn bar(&self);
+# }
+# struct S(usize);
+# impl T for S {
+# fn bar(&self) {}
+# }
+# struct O(&'static str);
+# impl T for O {
+# fn bar(&self) {}
+# }
+enum E {
+ S(S),
+ O(O),
+}
+
+// The caller can access the original types directly, but it needs to match on
+// the returned `enum E`.
+fn foo(x: bool) -> E {
+ if x {
+ E::S(S(42))
+ } else {
+ E::O(O("val"))
+ }
+}
+```
+
+You can even implement the `trait` on the returned `enum` so the callers
+*don't* have to match on the returned value to invoke the associated items:
+
+```
+# trait T {
+# fn bar(&self);
+# }
+# struct S(usize);
+# impl T for S {
+# fn bar(&self) {}
+# }
+# struct O(&'static str);
+# impl T for O {
+# fn bar(&self) {}
+# }
+# enum E {
+# S(S),
+# O(O),
+# }
+impl T for E {
+ fn bar(&self) {
+ match self {
+ E::S(s) => s.bar(),
+ E::O(o) => o.bar(),
+ }
+ }
+}
+```
+
+If you decide to use trait objects, be aware that these rely on
+[dynamic dispatch], which has performance implications, as the compiler needs
+to emit code that will figure out which method to call *at runtime* instead of
+during compilation. Using trait objects we are trading flexibility for
+performance.
+
+[`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits
+[trait objects]: https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types
+[dynamic dispatch]: https://doc.rust-lang.org/book/ch17-02-trait-objects.html#trait-objects-perform-dynamic-dispatch
pub static DIAGNOSTICS: &[(&str, &str)] = &[
$( (stringify!($ecode), $message), )*
];
-
- $(
- pub const $ecode: () = ();
- )*
- $(
- pub const $code: () = ();
- )*
)
}
mod error_codes;
-
-pub use error_codes::*;
+pub use error_codes::DIAGNOSTICS;
) {
let converter = DiagnosticConverter {
source_map: self.source_map.clone(),
- level: level.clone(),
+ level: *level,
message,
code: code.clone(),
msp: msp.clone(),
#[macro_export]
macro_rules! error_code {
- ($code:ident) => {{
- let _ = $code;
- $crate::DiagnosticId::Error(stringify!($code).to_owned())
- }};
+ ($code:ident) => {{ $crate::DiagnosticId::Error(stringify!($code).to_owned()) }};
}
None => return Ok(()),
};
+ // Render the replacements for each suggestion
+ let suggestions = suggestion.splice_lines(&**sm);
+
+ if suggestions.is_empty() {
+ // Suggestions coming from macros can have malformed spans. This is a heavy handed
+ // approach to avoid ICEs by ignoring the suggestion outright.
+ return Ok(());
+ }
+
let mut buffer = StyledBuffer::new();
// Render the suggestion message
Some(Style::HeaderMsg),
);
- // Render the replacements for each suggestion
- let suggestions = suggestion.splice_lines(&**sm);
-
let mut row_num = 2;
let mut notice_capitalization = false;
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {
let show_underline = !(parts.len() == 1 && parts[0].snippet.trim() == complete.trim())
&& complete.lines().count() == 1;
- let lines = sm.span_to_lines(parts[0].span).unwrap();
+ let lines = sm
+ .span_to_lines(parts[0].span)
+ .expect("span_to_lines failed when emitting suggestion");
assert!(!lines.lines.is_empty());
pub use emitter::ColorConfig;
+use log::debug;
use Level::*;
use emitter::{is_case_difference, Emitter, EmitterWriter};
self.substitutions
.iter()
+ .filter(|subst| {
+ // Suggestions coming from macros can have malformed spans. This is a heavy
+ // handed approach to avoid ICEs by ignoring the suggestion outright.
+ let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
+ if invalid {
+ debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
+ }
+ !invalid
+ })
.cloned()
.map(|mut substitution| {
// Assumption: all spans are in the same file, and all spans
/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),
+ /// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
+ (accepted, slice_patterns, "1.42.0", Some(62254), None),
// -------------------------------------------------------------------------
// feature-group-end: accepted features
/// Allows using non lexical lifetimes (RFC 2094).
(active, nll, "1.0.0", Some(43234), None),
- /// Allows using slice patterns.
- (active, slice_patterns, "1.0.0", Some(62254), None),
-
/// Allows the definition of `const` functions with some advanced features.
(active, const_fn, "1.2.0", Some(57563), None),
}
impl GenericBound<'_> {
+ pub fn trait_def_id(&self) -> Option<DefId> {
+ match self {
+ GenericBound::Trait(data, _) => Some(data.trait_ref.trait_def_id()),
+ _ => None,
+ }
+ }
+
pub fn span(&self) -> Span {
match self {
&GenericBound::Trait(ref t, ..) => t.span,
TraitAlias(Generics<'hir>, GenericBounds<'hir>),
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
- Impl(
- Unsafety,
- ImplPolarity,
- Defaultness,
- Generics<'hir>,
- Option<TraitRef<'hir>>, // (optional) trait this impl implements
- &'hir Ty<'hir>, // self
- &'hir [ImplItemRef<'hir>],
- ),
+ Impl {
+ unsafety: Unsafety,
+ polarity: ImplPolarity,
+ defaultness: Defaultness,
+ generics: Generics<'hir>,
+
+ /// The trait being implemented, if any.
+ of_trait: Option<TraitRef<'hir>>,
+
+ self_ty: &'hir Ty<'hir>,
+ items: &'hir [ImplItemRef<'hir>],
+ },
}
impl ItemKind<'_> {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
- ItemKind::Impl(..) => "impl",
+ ItemKind::Impl { .. } => "impl",
}
}
| ItemKind::Struct(_, ref generics)
| ItemKind::Union(_, ref generics)
| ItemKind::Trait(_, _, ref generics, _, _)
- | ItemKind::Impl(_, _, _, ref generics, _, _, _) => generics,
+ | ItemKind::Impl { ref generics, .. } => generics,
_ => return None,
})
}
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
}
- ItemKind::Impl(.., ref generics, ref opt_trait_reference, ref typ, impl_item_refs) => {
+ ItemKind::Impl {
+ unsafety: _,
+ defaultness: _,
+ polarity: _,
+ ref generics,
+ ref of_trait,
+ ref self_ty,
+ items,
+ } => {
visitor.visit_id(item.hir_id);
visitor.visit_generics(generics);
- walk_list!(visitor, visit_trait_ref, opt_trait_reference);
- visitor.visit_ty(typ);
- walk_list!(visitor, visit_impl_item_ref, impl_item_refs);
+ walk_list!(visitor, visit_trait_ref, of_trait);
+ visitor.visit_ty(self_ty);
+ walk_list!(visitor, visit_impl_item_ref, items);
}
ItemKind::Struct(ref struct_definition, ref generics)
| ItemKind::Union(ref struct_definition, ref generics) => {
self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
}
- hir::ItemKind::Impl(
+ hir::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
- ref opt_trait,
- ref ty,
- impl_items,
- ) => {
+ ref of_trait,
+ ref self_ty,
+ items,
+ } => {
self.head("");
self.print_visibility(&item.vis);
self.print_defaultness(defaultness);
self.s.word("!");
}
- if let Some(ref t) = opt_trait {
+ if let Some(ref t) = of_trait {
self.print_trait_ref(t);
self.s.space();
self.word_space("for");
}
- self.print_type(&ty);
+ self.print_type(&self_ty);
self.print_where_clause(&generics.where_clause);
self.s.space();
self.bopen();
self.print_inner_attributes(&item.attrs);
- for impl_item in impl_items {
+ for impl_item in items {
self.ann.nested(self, Nested::ImplItem(impl_item.id));
}
self.bclose(item.span);
//HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT),
// An implementation, eg `impl<A> Trait for Foo { .. }`
- HirItem::Impl(..) => ("ItemKind::Impl", LABELS_IMPL),
+ HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL),
_ => self.tcx.sess.span_fatal(
attr.span,
let serialized_products: Vec<_> = work_products
.iter()
.map(|(id, work_product)| SerializedWorkProduct {
- id: id.clone(),
+ id: *id,
work_product: work_product.clone(),
})
.collect();
use rustc::session::Session;
use rustc::traits;
use rustc::ty::steal::Steal;
-use rustc::ty::{self, AllArenas, GlobalCtxt, ResolverOutputs, TyCtxt};
+use rustc::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
use rustc::util::common::ErrorReported;
use rustc_builtin_macros;
use rustc_codegen_ssa::back::link::emit_metadata;
outputs: OutputFilenames,
crate_name: &str,
global_ctxt: &'tcx Once<GlobalCtxt<'tcx>>,
- all_arenas: &'tcx AllArenas,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
) -> QueryContext<'tcx> {
let sess = &compiler.session();
lint_store,
local_providers,
extern_providers,
- &all_arenas,
arena,
resolver_outputs,
hir_map,
use rustc::session::config::{OutputFilenames, OutputType};
use rustc::session::Session;
use rustc::ty::steal::Steal;
-use rustc::ty::{AllArenas, GlobalCtxt, ResolverOutputs};
+use rustc::ty::{GlobalCtxt, ResolverOutputs};
use rustc::util::common::ErrorReported;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::sync::{Lrc, Once, WorkerLocal};
compiler: &'tcx Compiler,
gcx: Once<GlobalCtxt<'tcx>>,
- all_arenas: AllArenas,
arena: WorkerLocal<Arena<'tcx>>,
dep_graph_future: Query<Option<DepGraphFuture>>,
Queries {
compiler,
gcx: Once::new(),
- all_arenas: AllArenas::new(),
arena: WorkerLocal::new(|_| Arena::default()),
dep_graph_future: Default::default(),
parse: Default::default(),
outputs,
&crate_name,
&self.gcx,
- &self.all_arenas,
&self.arena,
))
})
unicode-security = "0.0.2"
rustc = { path = "../librustc" }
rustc_errors = { path = "../librustc_errors" }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_hir = { path = "../librustc_hir" }
rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }
self.report_unsafe(cx, it.span, "declaration of an `unsafe` trait")
}
- ast::ItemKind::Impl(ast::Unsafety::Unsafe, ..) => {
+ ast::ItemKind::Impl { unsafety: ast::Unsafety::Unsafe, .. } => {
self.report_unsafe(cx, it.span, "implementation of an `unsafe` trait")
}
"a trait"
}
hir::ItemKind::TyAlias(..) => "a type alias",
- hir::ItemKind::Impl(.., Some(ref trait_ref), _, impl_item_refs) => {
+ hir::ItemKind::Impl { of_trait: Some(ref trait_ref), items, .. } => {
// If the trait is private, add the impl items to `private_traits` so they don't get
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
match cx.tcx.hir().find(hir_id) {
Some(Node::Item(item)) => {
if let hir::VisibilityKind::Inherited = item.vis.node {
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
self.private_traits.insert(impl_item_ref.id.hir_id);
}
}
use rustc::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync;
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId};
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
let target = match self.by_name.get(new_name) {
- Some(&Id(lint_id)) => lint_id.clone(),
+ Some(&Id(lint_id)) => lint_id,
_ => bug!("invalid lint renaming of {} to {}", old_name, new_name),
};
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
impl EarlyLintPass for LintPassImpl {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
- if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.kind {
+ if let ItemKind::Impl { of_trait: Some(lint_pass), .. } = &item.kind {
if let Some(last) = lint_pass.path.segments.last() {
if last.ident.name == sym::LintPass {
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc_data_structures::fx::FxHashMap;
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
}
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
- if let &PatKind::Binding(_, _, ident, _) = &p.kind {
+ if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
+ if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
+ {
+ if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {
+ for field in field_pats.iter() {
+ if field.ident != ident {
+ // Only check if a new name has been introduced, to avoid warning
+ // on both the struct definition and this pattern.
+ self.check_snake_case(cx, "variable", &ident);
+ }
+ }
+ return;
+ }
+ }
self.check_snake_case(cx, "variable", &ident);
}
}
rustc_expand = { path = "../librustc_expand" }
rustc_parse = { path = "../librustc_parse" }
rustc_span = { path = "../librustc_span" }
-rustc_error_codes = { path = "../librustc_error_codes" }
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "libloaderapi"] }
use rustc::ty::TyCtxt;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::Lrc;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_expand::base::SyntaxExtension;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]
#![feature(rustc_private)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(specialization)]
#![feature(stmt_expr_attributes)]
#![recursion_limit = "256"]
use log::{debug, info, warn};
-use rustc_error_codes::*;
-
#[derive(Clone)]
struct CrateMismatch {
path: PathBuf,
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_data_structures::fx::FxHashSet;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
fn get_stability(&self, id: DefIndex) -> Option<attr::Stability> {
match self.is_proc_macro(id) {
- true => self.root.proc_macro_stability.clone(),
+ true => self.root.proc_macro_stability,
false => self.root.per_def.stability.get(self, id).map(|stab| stab.decode(self)),
}
}
},
proc_macro_data,
proc_macro_stability: if is_proc_macro {
- tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| stab.clone())
+ tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| *stab)
} else {
None
},
ctor: None,
}), adt_def.repr)
}
- hir::ItemKind::Impl(_, _, defaultness, ..) => {
+ hir::ItemKind::Impl { defaultness, .. } => {
let trait_ref = self.tcx.impl_trait_ref(def_id);
let polarity = self.tcx.impl_polarity(def_id);
let parent = if let Some(trait_ref) = trait_ref {
})
)
}
- hir::ItemKind::Impl(..) | hir::ItemKind::Trait(..) => {
+ hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
record!(self.per_def.children[def_id] <-
associated_item_def_ids.iter().map(|&def_id| {
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
- | hir::ItemKind::Impl(..) => self.encode_item_type(def_id),
+ | hir::ItemKind::Impl { .. } => self.encode_item_type(def_id),
_ => {}
}
if let hir::ItemKind::Fn(..) = item.kind {
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
}
- if let hir::ItemKind::Impl(..) = item.kind {
+ if let hir::ItemKind::Impl { .. } = item.kind {
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
record!(self.per_def.impl_trait_ref[def_id] <- trait_ref);
}
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
- | hir::ItemKind::Impl(..)
+ | hir::ItemKind::Impl { .. }
| hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..) => {
hir::ItemKind::Union(..) => {
self.encode_fields(def_id);
}
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
for &trait_item_def_id in self.tcx.associated_item_def_ids(def_id).iter() {
self.encode_info_for_impl_item(trait_item_def_id);
}
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
- if let hir::ItemKind::Impl(..) = item.kind {
+ if let hir::ItemKind::Impl { .. } = item.kind {
let impl_id = self.tcx.hir().local_def_id(item.hir_id);
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
self.impls.entry(trait_ref.def_id).or_default().push(impl_id.index);
rustc_span = { path = "../librustc_span" }
rustc_apfloat = { path = "../librustc_apfloat" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
-rustc_error_codes = { path = "../librustc_error_codes" }
region,
reserve_location: location,
activation_location: TwoPhaseActivation::NotTwoPhase,
- borrowed_place: borrowed_place.clone(),
- assigned_place: assigned_place.clone(),
+ borrowed_place: *borrowed_place,
+ assigned_place: *assigned_place,
};
let idx = self.idx_vec.push(borrow);
self.location_map.insert(location, idx);
use std::collections::VecDeque;
+use rustc::infer::NLLRegionVariableOrigin;
use rustc::mir::{
Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue,
Statement, StatementKind, TerminatorKind,
};
use rustc::ty::adjustment::PointerCast;
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, RegionVid, TyCtxt};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_index::vec::IndexVec;
}
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
+ fn free_region_constraint_info(
+ &self,
+ borrow_region: RegionVid,
+ outlived_region: RegionVid,
+ ) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
+ let (category, from_closure, span) = self.regioncx.best_blame_constraint(
+ &self.body,
+ borrow_region,
+ NLLRegionVariableOrigin::FreeRegion,
+ |r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
+ );
+
+ let outlived_fr_name = self.give_region_a_name(outlived_region);
+
+ (category, from_closure, span, outlived_fr_name)
+ }
+
/// Returns structured explanation for *why* the borrow contains the
/// point from `location`. This is key for the "3-point errors"
/// [described in the NLL RFC][d].
location, borrow, kind_place
);
- let regioncx = &self.nonlexical_regioncx;
+ let regioncx = &self.regioncx;
let body: &Body<'_> = &self.body;
let tcx = self.infcx.tcx;
let borrow_region_vid = borrow.region;
debug!("explain_why_borrow_contains_point: borrow_region_vid={:?}", borrow_region_vid);
- let region_sub = regioncx.find_sub_region_live_at(borrow_region_vid, location);
+ let region_sub = self.regioncx.find_sub_region_live_at(borrow_region_vid, location);
debug!("explain_why_borrow_contains_point: region_sub={:?}", region_sub);
match find_use::find(body, regioncx, tcx, region_sub, location) {
}
None => {
- if let Some(region) = regioncx.to_error_region_vid(borrow_region_vid) {
- let (category, from_closure, span, region_name) = self
- .nonlexical_regioncx
- .free_region_constraint_info(self, borrow_region_vid, region);
+ if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
+ let (category, from_closure, span, region_name) =
+ self.free_region_constraint_info(borrow_region_vid, region);
if let Some(region_name) = region_name {
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
BorrowExplanation::MustBeValidFor {
} else {
debug!(
"explain_why_borrow_contains_point: \
- Could not generate a region name"
+ Could not generate a region name"
);
BorrowExplanation::Unexplained
}
} else {
debug!(
"explain_why_borrow_contains_point: \
- Could not generate an error region vid"
+ Could not generate an error region vid"
);
BorrowExplanation::Unexplained
}
crate use mutability_errors::AccessKind;
crate use outlives_suggestion::OutlivesSuggestionBuilder;
crate use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
-crate use region_name::{RegionErrorNamingCtx, RegionName, RegionNameSource};
+crate use region_name::{RegionName, RegionNameSource};
pub(super) struct IncludingDowncast(pub(super) bool);
use crate::borrow_check::MirBorrowckCtxt;
-use super::{ErrorConstraintInfo, RegionErrorNamingCtx, RegionName, RegionNameSource};
+use super::{ErrorConstraintInfo, RegionName, RegionNameSource};
/// The different things we could suggest.
enum SuggestedConstraint {
fn region_vid_to_name(
&self,
mbcx: &MirBorrowckCtxt<'_, '_>,
- renctx: &mut RegionErrorNamingCtx,
region: RegionVid,
) -> Option<RegionName> {
- mbcx.nonlexical_regioncx
- .give_region_a_name(mbcx, renctx, region)
- .filter(Self::region_name_is_suggestable)
+ mbcx.give_region_a_name(region).filter(Self::region_name_is_suggestable)
}
/// Compiles a list of all suggestions to be printed in the final big suggestion.
fn compile_all_suggestions(
&self,
mbcx: &MirBorrowckCtxt<'_, '_>,
- renctx: &mut RegionErrorNamingCtx,
) -> SmallVec<[SuggestedConstraint; 2]> {
let mut suggested = SmallVec::new();
let mut unified_already = FxHashSet::default();
for (fr, outlived) in &self.constraints_to_add {
- let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, renctx, *fr) {
+ let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) {
fr_name
} else {
continue;
let outlived = outlived
.iter()
// if there is a `None`, we will just omit that constraint
- .filter_map(|fr| {
- self.region_vid_to_name(mbcx, renctx, *fr).map(|rname| (fr, rname))
- })
+ .filter_map(|fr| self.region_vid_to_name(mbcx, *fr).map(|rname| (fr, rname)))
.collect::<Vec<_>>();
// No suggestable outlived lifetimes.
&mut self,
mbcx: &MirBorrowckCtxt<'_, '_>,
errci: &ErrorConstraintInfo,
- renctx: &mut RegionErrorNamingCtx,
diag: &mut DiagnosticBuilder<'_>,
) {
// Emit an intermediate note.
- let fr_name = self.region_vid_to_name(mbcx, renctx, errci.fr);
- let outlived_fr_name = self.region_vid_to_name(mbcx, renctx, errci.outlived_fr);
+ let fr_name = self.region_vid_to_name(mbcx, errci.fr);
+ let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr);
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) {
if let RegionNameSource::Static = outlived_fr_name.source {
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
/// suggestion including all collected constraints.
- crate fn add_suggestion(
- &self,
- mbcx: &mut MirBorrowckCtxt<'_, '_>,
- renctx: &mut RegionErrorNamingCtx,
- ) {
+ crate fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_>) {
// No constraints to add? Done.
if self.constraints_to_add.is_empty() {
debug!("No constraints to suggest.");
}
// Get all suggestable constraints.
- let suggested = self.compile_all_suggestions(mbcx, renctx);
+ let suggested = self.compile_all_suggestions(mbcx);
// If there are no suggestable constraints...
if suggested.is_empty() {
//! Error reporting machinery for lifetime errors.
use rustc::infer::{
- error_reporting::nice_region_error::NiceRegionError, region_constraints::GenericKind,
- InferCtxt, NLLRegionVariableOrigin,
+ error_reporting::nice_region_error::NiceRegionError, opaque_types, NLLRegionVariableOrigin,
};
-use rustc::mir::{Body, ConstraintCategory, Location};
+use rustc::mir::ConstraintCategory;
use rustc::ty::{self, RegionVid, Ty};
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir::def_id::DefId;
-use rustc_index::vec::IndexVec;
use rustc_span::symbol::kw;
use rustc_span::Span;
-use std::collections::VecDeque;
use crate::util::borrowck_errors;
use crate::borrow_check::{
- constraints::OutlivesConstraint, nll::ConstraintDescription,
- region_infer::RegionInferenceContext, type_check::Locations, universal_regions::DefiningTy,
+ nll::ConstraintDescription,
+ region_infer::{values::RegionElement, TypeTest},
+ universal_regions::DefiningTy,
MirBorrowckCtxt,
};
-use super::{OutlivesSuggestionBuilder, RegionErrorNamingCtx, RegionName, RegionNameSource};
+use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
impl ConstraintDescription for ConstraintCategory {
fn description(&self) -> &'static str {
}
}
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-enum Trace {
- StartRegion,
- FromOutlivesConstraint(OutlivesConstraint),
- NotVisited,
-}
-
/// A collection of errors encountered during region inference. This is needed to efficiently
/// report errors after borrow checking.
///
#[derive(Clone, Debug)]
crate enum RegionErrorKind<'tcx> {
- /// An error for a type test: `T: 'a` does not live long enough.
- TypeTestDoesNotLiveLongEnough {
- /// The span of the type test.
- span: Span,
- /// The generic type of the type test.
- generic: GenericKind<'tcx>,
- },
-
- /// A generic bound failure for a type test.
- TypeTestGenericBoundError {
- /// The span of the type test.
- span: Span,
- /// The generic type of the type test.
- generic: GenericKind<'tcx>,
- /// The lower bound region.
- lower_bound_region: ty::Region<'tcx>,
- },
+ /// A generic bound failure for a type test (`T: 'a`).
+ TypeTestError { type_test: TypeTest<'tcx> },
/// An unexpected hidden region for an opaque type.
UnexpectedHiddenRegion {
BoundUniversalRegionError {
/// The placeholder free region.
longer_fr: RegionVid,
- /// The region that erroneously must be outlived by `longer_fr`.
- error_region: RegionVid,
+ /// The region element that erroneously must be outlived by `longer_fr`.
+ error_element: RegionElement,
/// The origin of the placeholder region.
fr_origin: NLLRegionVariableOrigin,
},
pub(super) span: Span,
}
-impl<'tcx> RegionInferenceContext<'tcx> {
+impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// Converts a region inference variable into a `ty::Region` that
/// we can use for error reporting. If `r` is universally bound,
/// then we use the name that we have on record for it. If `r` is
/// existentially bound, then we check its inferred value and try
/// to find a good name from that. Returns `None` if we can't find
/// one (e.g., this is just some random part of the CFG).
- pub fn to_error_region(&self, r: RegionVid) -> Option<ty::Region<'tcx>> {
- self.to_error_region_vid(r).and_then(|r| self.definitions[r].external_name)
+ pub(super) fn to_error_region(&self, r: RegionVid) -> Option<ty::Region<'tcx>> {
+ self.to_error_region_vid(r).and_then(|r| self.regioncx.region_definition(r).external_name)
}
- /// Returns the [RegionVid] corresponding to the region returned by
+ /// Returns the `RegionVid` corresponding to the region returned by
/// `to_error_region`.
- pub fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid> {
- if self.universal_regions.is_universal_region(r) {
+ pub(super) fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid> {
+ if self.regioncx.universal_regions().is_universal_region(r) {
Some(r)
} else {
- let r_scc = self.constraint_sccs.scc(r);
- let upper_bound = self.universal_upper_bound(r);
- if self.scc_values.contains(r_scc, upper_bound) {
+ let upper_bound = self.regioncx.universal_upper_bound(r);
+
+ if self.regioncx.upper_bound_in_region_scc(r, upper_bound) {
self.to_error_region_vid(upper_bound)
} else {
None
}
}
- /// Tries to find the best constraint to blame for the fact that
- /// `R: from_region`, where `R` is some region that meets
- /// `target_test`. This works by following the constraint graph,
- /// creating a constraint path that forces `R` to outlive
- /// `from_region`, and then finding the best choices within that
- /// path to blame.
- fn best_blame_constraint(
- &self,
- body: &Body<'tcx>,
- from_region: RegionVid,
- from_region_origin: NLLRegionVariableOrigin,
- target_test: impl Fn(RegionVid) -> bool,
- ) -> (ConstraintCategory, bool, Span) {
- debug!(
- "best_blame_constraint(from_region={:?}, from_region_origin={:?})",
- from_region, from_region_origin
- );
-
- // Find all paths
- let (path, target_region) =
- self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
- debug!(
- "best_blame_constraint: path={:#?}",
- path.iter()
- .map(|&c| format!(
- "{:?} ({:?}: {:?})",
- c,
- self.constraint_sccs.scc(c.sup),
- self.constraint_sccs.scc(c.sub),
- ))
- .collect::<Vec<_>>()
- );
-
- // Classify each of the constraints along the path.
- let mut categorized_path: Vec<(ConstraintCategory, bool, Span)> = path
- .iter()
- .map(|constraint| {
- if constraint.category == ConstraintCategory::ClosureBounds {
- self.retrieve_closure_constraint_info(body, &constraint)
- } else {
- (constraint.category, false, constraint.locations.span(body))
- }
- })
- .collect();
- debug!("best_blame_constraint: categorized_path={:#?}", categorized_path);
-
- // To find the best span to cite, we first try to look for the
- // final constraint that is interesting and where the `sup` is
- // not unified with the ultimate target region. The reason
- // for this is that we have a chain of constraints that lead
- // from the source to the target region, something like:
- //
- // '0: '1 ('0 is the source)
- // '1: '2
- // '2: '3
- // '3: '4
- // '4: '5
- // '5: '6 ('6 is the target)
- //
- // Some of those regions are unified with `'6` (in the same
- // SCC). We want to screen those out. After that point, the
- // "closest" constraint we have to the end is going to be the
- // most likely to be the point where the value escapes -- but
- // we still want to screen for an "interesting" point to
- // highlight (e.g., a call site or something).
- let target_scc = self.constraint_sccs.scc(target_region);
- let mut range = 0..path.len();
-
- // As noted above, when reporting an error, there is typically a chain of constraints
- // leading from some "source" region which must outlive some "target" region.
- // In most cases, we prefer to "blame" the constraints closer to the target --
- // but there is one exception. When constraints arise from higher-ranked subtyping,
- // we generally prefer to blame the source value,
- // as the "target" in this case tends to be some type annotation that the user gave.
- // Therefore, if we find that the region origin is some instantiation
- // of a higher-ranked region, we start our search from the "source" point
- // rather than the "target", and we also tweak a few other things.
- //
- // An example might be this bit of Rust code:
- //
- // ```rust
- // let x: fn(&'static ()) = |_| {};
- // let y: for<'a> fn(&'a ()) = x;
- // ```
- //
- // In MIR, this will be converted into a combination of assignments and type ascriptions.
- // In particular, the 'static is imposed through a type ascription:
- //
- // ```rust
- // x = ...;
- // AscribeUserType(x, fn(&'static ())
- // y = x;
- // ```
- //
- // We wind up ultimately with constraints like
- //
- // ```rust
- // !a: 'temp1 // from the `y = x` statement
- // 'temp1: 'temp2
- // 'temp2: 'static // from the AscribeUserType
- // ```
- //
- // and here we prefer to blame the source (the y = x statement).
- let blame_source = match from_region_origin {
- NLLRegionVariableOrigin::FreeRegion
- | NLLRegionVariableOrigin::Existential { from_forall: false } => true,
- NLLRegionVariableOrigin::Placeholder(_)
- | NLLRegionVariableOrigin::Existential { from_forall: true } => false,
- };
-
- let find_region = |i: &usize| {
- let constraint = path[*i];
-
- let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup);
-
- if blame_source {
- match categorized_path[*i].0 {
- ConstraintCategory::OpaqueType
- | ConstraintCategory::Boring
- | ConstraintCategory::BoringNoLocation
- | ConstraintCategory::Internal => false,
- ConstraintCategory::TypeAnnotation
- | ConstraintCategory::Return
- | ConstraintCategory::Yield => true,
- _ => constraint_sup_scc != target_scc,
- }
- } else {
- match categorized_path[*i].0 {
- ConstraintCategory::OpaqueType
- | ConstraintCategory::Boring
- | ConstraintCategory::BoringNoLocation
- | ConstraintCategory::Internal => false,
- _ => true,
- }
- }
- };
-
- let best_choice =
- if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
-
- debug!(
- "best_blame_constraint: best_choice={:?} blame_source={}",
- best_choice, blame_source
- );
-
- if let Some(i) = best_choice {
- if let Some(next) = categorized_path.get(i + 1) {
- if categorized_path[i].0 == ConstraintCategory::Return
- && next.0 == ConstraintCategory::OpaqueType
+ /// Returns `true` if a closure is inferred to be an `FnMut` closure.
+ fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
+ if let Some(ty::ReFree(free_region)) = self.to_error_region(fr) {
+ if let ty::BoundRegion::BrEnv = free_region.bound_region {
+ if let DefiningTy::Closure(def_id, substs) =
+ self.regioncx.universal_regions().defining_ty
{
- // The return expression is being influenced by the return type being
- // impl Trait, point at the return type and not the return expr.
- return *next;
+ return substs.as_closure().kind(def_id, self.infcx.tcx)
+ == ty::ClosureKind::FnMut;
}
}
- return categorized_path[i];
}
- // If that search fails, that is.. unusual. Maybe everything
- // is in the same SCC or something. In that case, find what
- // appears to be the most interesting point to report to the
- // user via an even more ad-hoc guess.
- categorized_path.sort_by(|p0, p1| p0.0.cmp(&p1.0));
- debug!("`: sorted_path={:#?}", categorized_path);
-
- *categorized_path.first().unwrap()
+ false
}
- /// Walks the graph of constraints (where `'a: 'b` is considered
- /// an edge `'a -> 'b`) to find all paths from `from_region` to
- /// `to_region`. The paths are accumulated into the vector
- /// `results`. The paths are stored as a series of
- /// `ConstraintIndex` values -- in other words, a list of *edges*.
- ///
- /// Returns: a series of constraints as well as the region `R`
- /// that passed the target test.
- fn find_constraint_paths_between_regions(
- &self,
- from_region: RegionVid,
- target_test: impl Fn(RegionVid) -> bool,
- ) -> Option<(Vec<OutlivesConstraint>, RegionVid)> {
- let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions);
- context[from_region] = Trace::StartRegion;
-
- // Use a deque so that we do a breadth-first search. We will
- // stop at the first match, which ought to be the shortest
- // path (fewest constraints).
- let mut deque = VecDeque::new();
- deque.push_back(from_region);
-
- while let Some(r) = deque.pop_front() {
- debug!(
- "find_constraint_paths_between_regions: from_region={:?} r={:?} value={}",
- from_region,
- r,
- self.region_value_str(r),
- );
-
- // Check if we reached the region we were looking for. If so,
- // we can reconstruct the path that led to it and return it.
- if target_test(r) {
- let mut result = vec![];
- let mut p = r;
- loop {
- match context[p] {
- Trace::NotVisited => {
- bug!("found unvisited region {:?} on path to {:?}", p, r)
- }
-
- Trace::FromOutlivesConstraint(c) => {
- result.push(c);
- p = c.sup;
- }
-
- Trace::StartRegion => {
- result.reverse();
- return Some((result, r));
- }
+ /// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
+ pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) {
+ // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are
+ // buffered in the `MirBorrowckCtxt`.
+
+ let mut outlives_suggestion = OutlivesSuggestionBuilder::default();
+
+ for nll_error in nll_errors.into_iter() {
+ match nll_error {
+ RegionErrorKind::TypeTestError { type_test } => {
+ // Try to convert the lower-bound region into something named we can print for the user.
+ let lower_bound_region = self.to_error_region(type_test.lower_bound);
+
+ let type_test_span = type_test.locations.span(&self.body);
+
+ if let Some(lower_bound_region) = lower_bound_region {
+ let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
+ self.infcx
+ .construct_generic_bound_failure(
+ region_scope_tree,
+ type_test_span,
+ None,
+ type_test.generic_kind,
+ lower_bound_region,
+ )
+ .buffer(&mut self.errors_buffer);
+ } else {
+ // FIXME. We should handle this case better. It
+ // indicates that we have e.g., some region variable
+ // whose value is like `'a+'b` where `'a` and `'b` are
+ // distinct unrelated univesal regions that are not
+ // known to outlive one another. It'd be nice to have
+ // some examples where this arises to decide how best
+ // to report it; we could probably handle it by
+ // iterating over the universal regions and reporting
+ // an error that multiple bounds are required.
+ self.infcx
+ .tcx
+ .sess
+ .struct_span_err(
+ type_test_span,
+ &format!("`{}` does not live long enough", type_test.generic_kind),
+ )
+ .buffer(&mut self.errors_buffer);
}
}
- }
- // Otherwise, walk over the outgoing constraints and
- // enqueue any regions we find, keeping track of how we
- // reached them.
-
- // A constraint like `'r: 'x` can come from our constraint
- // graph.
- let fr_static = self.universal_regions.fr_static;
- let outgoing_edges_from_graph =
- self.constraint_graph.outgoing_edges(r, &self.constraints, fr_static);
-
- // Always inline this closure because it can be hot.
- let mut handle_constraint = #[inline(always)]
- |constraint: OutlivesConstraint| {
- debug_assert_eq!(constraint.sup, r);
- let sub_region = constraint.sub;
- if let Trace::NotVisited = context[sub_region] {
- context[sub_region] = Trace::FromOutlivesConstraint(constraint);
- deque.push_back(sub_region);
+ RegionErrorKind::UnexpectedHiddenRegion {
+ opaque_type_def_id,
+ hidden_ty,
+ member_region,
+ } => {
+ let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
+ opaque_types::unexpected_hidden_region_diagnostic(
+ self.infcx.tcx,
+ Some(region_scope_tree),
+ opaque_type_def_id,
+ hidden_ty,
+ member_region,
+ )
+ .buffer(&mut self.errors_buffer);
}
- };
- // This loop can be hot.
- for constraint in outgoing_edges_from_graph {
- handle_constraint(constraint);
- }
+ RegionErrorKind::BoundUniversalRegionError {
+ longer_fr,
+ fr_origin,
+ error_element,
+ } => {
+ let error_region = self.regioncx.region_from_element(longer_fr, error_element);
+
+ // Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
+ let (_, span) = self.regioncx.find_outlives_blame_span(
+ &self.body,
+ longer_fr,
+ fr_origin,
+ error_region,
+ );
+
+ // FIXME: improve this error message
+ self.infcx
+ .tcx
+ .sess
+ .struct_span_err(span, "higher-ranked subtype error")
+ .buffer(&mut self.errors_buffer);
+ }
- // Member constraints can also give rise to `'r: 'x` edges that
- // were not part of the graph initially, so watch out for those.
- // (But they are extremely rare; this loop is very cold.)
- for constraint in self.applied_member_constraints(r) {
- let p_c = &self.member_constraints[constraint.member_constraint_index];
- let constraint = OutlivesConstraint {
- sup: r,
- sub: constraint.min_choice,
- locations: Locations::All(p_c.definition_span),
- category: ConstraintCategory::OpaqueType,
- };
- handle_constraint(constraint);
+ RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {
+ if is_reported {
+ self.report_region_error(
+ longer_fr,
+ fr_origin,
+ shorter_fr,
+ &mut outlives_suggestion,
+ );
+ } else {
+ // We only report the first error, so as not to overwhelm the user. See
+ // `RegRegionErrorKind` docs.
+ //
+ // FIXME: currently we do nothing with these, but perhaps we can do better?
+ // FIXME: try collecting these constraints on the outlives suggestion
+ // builder. Does it make the suggestions any better?
+ debug!(
+ "Unreported region error: can't prove that {:?}: {:?}",
+ longer_fr, shorter_fr
+ );
+ }
+ }
}
}
- None
+ // Emit one outlives suggestions for each MIR def we borrowck
+ outlives_suggestion.add_suggestion(self);
}
/// Report an error because the universal region `fr` was required to outlive
/// ```
///
/// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`.
- pub(in crate::borrow_check) fn report_error<'a>(
- &'a self,
- mbcx: &MirBorrowckCtxt<'a, 'tcx>,
+ pub(in crate::borrow_check) fn report_region_error(
+ &mut self,
fr: RegionVid,
fr_origin: NLLRegionVariableOrigin,
outlived_fr: RegionVid,
outlives_suggestion: &mut OutlivesSuggestionBuilder,
- renctx: &mut RegionErrorNamingCtx,
- ) -> DiagnosticBuilder<'a> {
- debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
+ ) {
+ debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
- let (category, _, span) = self.best_blame_constraint(&mbcx.body, fr, fr_origin, |r| {
- self.provides_universal_region(r, fr, outlived_fr)
- });
+ let (category, _, span) =
+ self.regioncx.best_blame_constraint(&self.body, fr, fr_origin, |r| {
+ self.regioncx.provides_universal_region(r, fr, outlived_fr)
+ });
- debug!("report_error: category={:?} {:?}", category, span);
+ debug!("report_region_error: category={:?} {:?}", category, span);
// Check if we can use one of the "nice region errors".
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
- let tables = mbcx.infcx.tcx.typeck_tables_of(mbcx.mir_def_id);
- let nice = NiceRegionError::new_from_span(mbcx.infcx, span, o, f, Some(tables));
+ let tables = self.infcx.tcx.typeck_tables_of(self.mir_def_id);
+ let nice = NiceRegionError::new_from_span(self.infcx, span, o, f, Some(tables));
if let Some(diag) = nice.try_report_from_nll() {
- return diag;
+ diag.buffer(&mut self.errors_buffer);
+ return;
}
}
let (fr_is_local, outlived_fr_is_local): (bool, bool) = (
- self.universal_regions.is_local_free_region(fr),
- self.universal_regions.is_local_free_region(outlived_fr),
+ self.regioncx.universal_regions().is_local_free_region(fr),
+ self.regioncx.universal_regions().is_local_free_region(outlived_fr),
);
debug!(
- "report_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}",
+ "report_region_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}",
fr_is_local, outlived_fr_is_local, category
);
span,
};
- match (category, fr_is_local, outlived_fr_is_local) {
- (ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(mbcx.infcx, fr) => {
- self.report_fnmut_error(mbcx, &errci, renctx)
+ let diag = match (category, fr_is_local, outlived_fr_is_local) {
+ (ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(fr) => {
+ self.report_fnmut_error(&errci)
}
(ConstraintCategory::Assignment, true, false)
| (ConstraintCategory::CallArgument, true, false) => {
- let mut db = self.report_escaping_data_error(mbcx, &errci, renctx);
+ let mut db = self.report_escaping_data_error(&errci);
- outlives_suggestion.intermediate_suggestion(mbcx, &errci, renctx, &mut db);
+ outlives_suggestion.intermediate_suggestion(self, &errci, &mut db);
outlives_suggestion.collect_constraint(fr, outlived_fr);
db
}
_ => {
- let mut db = self.report_general_error(mbcx, &errci, renctx);
+ let mut db = self.report_general_error(&errci);
- outlives_suggestion.intermediate_suggestion(mbcx, &errci, renctx, &mut db);
+ outlives_suggestion.intermediate_suggestion(self, &errci, &mut db);
outlives_suggestion.collect_constraint(fr, outlived_fr);
db
}
- }
- }
-
- /// We have a constraint `fr1: fr2` that is not satisfied, where
- /// `fr2` represents some universal region. Here, `r` is some
- /// region where we know that `fr1: r` and this function has the
- /// job of determining whether `r` is "to blame" for the fact that
- /// `fr1: fr2` is required.
- ///
- /// This is true under two conditions:
- ///
- /// - `r == fr2`
- /// - `fr2` is `'static` and `r` is some placeholder in a universe
- /// that cannot be named by `fr1`; in that case, we will require
- /// that `fr1: 'static` because it is the only way to `fr1: r` to
- /// be satisfied. (See `add_incompatible_universe`.)
- fn provides_universal_region(&self, r: RegionVid, fr1: RegionVid, fr2: RegionVid) -> bool {
- debug!("provides_universal_region(r={:?}, fr1={:?}, fr2={:?})", r, fr1, fr2);
- let result = {
- r == fr2 || {
- fr2 == self.universal_regions.fr_static && self.cannot_name_placeholder(fr1, r)
- }
};
- debug!("provides_universal_region: result = {:?}", result);
- result
+
+ diag.buffer(&mut self.errors_buffer);
}
/// Report a specialized error when `FnMut` closures return a reference to a captured variable.
/// executing...
/// = note: ...therefore, returned references to captured variables will escape the closure
/// ```
- fn report_fnmut_error(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- errci: &ErrorConstraintInfo,
- renctx: &mut RegionErrorNamingCtx,
- ) -> DiagnosticBuilder<'_> {
+ fn report_fnmut_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
- let mut diag = mbcx
+ let mut diag = self
.infcx
.tcx
.sess
// We should check if the return type of this closure is in fact a closure - in that
// case, we can special case the error further.
- let return_type_is_closure = self.universal_regions.unnormalized_output_ty.is_closure();
+ let return_type_is_closure =
+ self.regioncx.universal_regions().unnormalized_output_ty.is_closure();
let message = if return_type_is_closure {
"returns a closure that contains a reference to a captured variable, which then \
escapes the closure body"
diag.span_label(*span, message);
- match self.give_region_a_name(mbcx, renctx, *outlived_fr).unwrap().source {
+ match self.give_region_a_name(*outlived_fr).unwrap().source {
RegionNameSource::NamedEarlyBoundRegion(fr_span)
| RegionNameSource::NamedFreeRegion(fr_span)
| RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _)
/// LL | ref_obj(x)
/// | ^^^^^^^^^^ `x` escapes the function body here
/// ```
- fn report_escaping_data_error(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- errci: &ErrorConstraintInfo,
- renctx: &mut RegionErrorNamingCtx,
- ) -> DiagnosticBuilder<'_> {
+ fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
let ErrorConstraintInfo { span, category, .. } = errci;
- let fr_name_and_span = self.get_var_name_and_span_for_region(
- mbcx.infcx.tcx,
- &mbcx.body,
- &mbcx.local_names,
- &mbcx.upvars,
+ let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
+ self.infcx.tcx,
+ &self.body,
+ &self.local_names,
+ &self.upvars,
errci.fr,
);
- let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(
- mbcx.infcx.tcx,
- &mbcx.body,
- &mbcx.local_names,
- &mbcx.upvars,
+ let outlived_fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
+ self.infcx.tcx,
+ &self.body,
+ &self.local_names,
+ &self.upvars,
errci.outlived_fr,
);
- let escapes_from = match self.universal_regions.defining_ty {
+ let escapes_from = match self.regioncx.universal_regions().defining_ty {
DefiningTy::Closure(..) => "closure",
DefiningTy::Generator(..) => "generator",
DefiningTy::FnDef(..) => "function",
|| (*category == ConstraintCategory::Assignment && escapes_from == "function")
|| escapes_from == "const"
{
- return self.report_general_error(
- mbcx,
- &ErrorConstraintInfo { fr_is_local: true, outlived_fr_is_local: false, ..*errci },
- renctx,
- );
+ return self.report_general_error(&ErrorConstraintInfo {
+ fr_is_local: true,
+ outlived_fr_is_local: false,
+ ..*errci
+ });
}
let mut diag =
- borrowck_errors::borrowed_data_escapes_closure(mbcx.infcx.tcx, *span, escapes_from);
+ borrowck_errors::borrowed_data_escapes_closure(self.infcx.tcx, *span, escapes_from);
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
diag.span_label(
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
/// | is returning data with lifetime `'b`
/// ```
- fn report_general_error(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- errci: &ErrorConstraintInfo,
- renctx: &mut RegionErrorNamingCtx,
- ) -> DiagnosticBuilder<'_> {
+ fn report_general_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
let ErrorConstraintInfo {
fr,
fr_is_local,
} = errci;
let mut diag =
- mbcx.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
+ self.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
let mir_def_name =
- if mbcx.infcx.tcx.is_closure(mbcx.mir_def_id) { "closure" } else { "function" };
+ if self.infcx.tcx.is_closure(self.mir_def_id) { "closure" } else { "function" };
- let fr_name = self.give_region_a_name(mbcx, renctx, *fr).unwrap();
+ let fr_name = self.give_region_a_name(*fr).unwrap();
fr_name.highlight_region_name(&mut diag);
- let outlived_fr_name = self.give_region_a_name(mbcx, renctx, *outlived_fr).unwrap();
+ let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);
match (category, outlived_fr_is_local, fr_is_local) {
}
}
- self.add_static_impl_trait_suggestion(mbcx.infcx, &mut diag, *fr, fr_name, *outlived_fr);
+ self.add_static_impl_trait_suggestion(&mut diag, *fr, fr_name, *outlived_fr);
diag
}
/// ```
fn add_static_impl_trait_suggestion(
&self,
- infcx: &InferCtxt<'_, 'tcx>,
- diag: &mut DiagnosticBuilder<'_>,
+ diag: &mut DiagnosticBuilder<'tcx>,
fr: RegionVid,
// We need to pass `fr_name` - computing it again will label it twice.
fr_name: RegionName,
if let (Some(f), Some(ty::RegionKind::ReStatic)) =
(self.to_error_region(fr), self.to_error_region(outlived_fr))
{
- if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = infcx
+ if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
+ .infcx
.tcx
.is_suitable_region(f)
.map(|r| r.def_id)
- .map(|id| infcx.tcx.return_type_impl_trait(id))
+ .map(|id| self.infcx.tcx.return_type_impl_trait(id))
.unwrap_or(None)
{
// Check whether or not the impl trait return type is intended to capture
//
// eg. check for `impl Trait + 'static` instead of `impl Trait`.
let has_static_predicate = {
- let predicates_of = infcx.tcx.predicates_of(*did);
- let bounds = predicates_of.instantiate(infcx.tcx, substs);
+ let predicates_of = self.infcx.tcx.predicates_of(*did);
+ let bounds = predicates_of.instantiate(self.infcx.tcx, substs);
let mut found = false;
for predicate in bounds.predicates {
diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str));
} else {
// Otherwise, we should suggest adding a constraint on the return type.
- let span = infcx.tcx.def_span(*did);
- if let Ok(snippet) = infcx.tcx.sess.source_map().span_to_snippet(span) {
+ let span = self.infcx.tcx.def_span(*did);
+ if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
let suggestable_fr_name = if fr_name.was_named() {
fr_name.to_string()
} else {
}
}
}
-
- crate fn free_region_constraint_info(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- borrow_region: RegionVid,
- outlived_region: RegionVid,
- ) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
- let (category, from_closure, span) = self.best_blame_constraint(
- &mbcx.body,
- borrow_region,
- NLLRegionVariableOrigin::FreeRegion,
- |r| self.provides_universal_region(r, borrow_region, outlived_region),
- );
-
- let mut renctx = RegionErrorNamingCtx::new();
- let outlived_fr_name = self.give_region_a_name(mbcx, &mut renctx, outlived_region);
-
- (category, from_closure, span, outlived_fr_name)
- }
-
- // Finds some region R such that `fr1: R` and `R` is live at
- // `elem`.
- crate fn find_sub_region_live_at(&self, fr1: RegionVid, elem: Location) -> RegionVid {
- debug!("find_sub_region_live_at(fr1={:?}, elem={:?})", fr1, elem);
- self.find_constraint_paths_between_regions(fr1, |r| {
- // First look for some `r` such that `fr1: r` and `r` is live at `elem`
- debug!(
- "find_sub_region_live_at: liveness_constraints for {:?} are {:?}",
- r,
- self.liveness_constraints.region_value_str(r),
- );
- self.liveness_constraints.contains(r, elem)
- })
- .or_else(|| {
- // If we fail to find that, we may find some `r` such that
- // `fr1: r` and `r` is a placeholder from some universe
- // `fr1` cannot name. This would force `fr1` to be
- // `'static`.
- self.find_constraint_paths_between_regions(fr1, |r| {
- self.cannot_name_placeholder(fr1, r)
- })
- })
- .or_else(|| {
- // If we fail to find THAT, it may be that `fr1` is a
- // placeholder that cannot "fit" into its SCC. In that
- // case, there should be some `r` where `fr1: r`, both
- // `fr1` and `r` are in the same SCC, and `fr1` is a
- // placeholder that `r` cannot name. We can blame that
- // edge.
- self.find_constraint_paths_between_regions(fr1, |r| {
- self.constraint_sccs.scc(fr1) == self.constraint_sccs.scc(r)
- && self.cannot_name_placeholder(r, fr1)
- })
- })
- .map(|(_path, r)| r)
- .unwrap()
- }
-
- // Finds a good span to blame for the fact that `fr1` outlives `fr2`.
- crate fn find_outlives_blame_span(
- &self,
- body: &Body<'tcx>,
- fr1: RegionVid,
- fr1_origin: NLLRegionVariableOrigin,
- fr2: RegionVid,
- ) -> (ConstraintCategory, Span) {
- let (category, _, span) = self.best_blame_constraint(body, fr1, fr1_origin, |r| {
- self.provides_universal_region(r, fr1, fr2)
- });
- (category, span)
- }
-
- fn retrieve_closure_constraint_info(
- &self,
- body: &Body<'tcx>,
- constraint: &OutlivesConstraint,
- ) -> (ConstraintCategory, bool, Span) {
- let loc = match constraint.locations {
- Locations::All(span) => return (constraint.category, false, span),
- Locations::Single(loc) => loc,
- };
-
- let opt_span_category =
- self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub));
- opt_span_category.map(|&(category, span)| (category, true, span)).unwrap_or((
- constraint.category,
- false,
- body.source_info(loc).span,
- ))
- }
-
- /// Returns `true` if a closure is inferred to be an `FnMut` closure.
- crate fn is_closure_fn_mut(&self, infcx: &InferCtxt<'_, 'tcx>, fr: RegionVid) -> bool {
- if let Some(ty::ReFree(free_region)) = self.to_error_region(fr) {
- if let ty::BoundRegion::BrEnv = free_region.bound_region {
- if let DefiningTy::Closure(def_id, substs) = self.universal_regions.defining_ty {
- let closure_kind_ty = substs.as_closure().kind_ty(def_id, infcx.tcx);
- return Some(ty::ClosureKind::FnMut) == closure_kind_ty.to_opt_closure_kind();
- }
- }
- }
-
- false
- }
-
- /// If `r2` represents a placeholder region, then this returns
- /// `true` if `r1` cannot name that placeholder in its
- /// value; otherwise, returns `false`.
- fn cannot_name_placeholder(&self, r1: RegionVid, r2: RegionVid) -> bool {
- debug!("cannot_name_value_of(r1={:?}, r2={:?})", r1, r2);
-
- match self.definitions[r2].origin {
- NLLRegionVariableOrigin::Placeholder(placeholder) => {
- let universe1 = self.definitions[r1].universe;
- debug!(
- "cannot_name_value_of: universe1={:?} placeholder={:?}",
- universe1, placeholder
- );
- universe1.cannot_name(placeholder.universe)
- }
-
- NLLRegionVariableOrigin::FreeRegion | NLLRegionVariableOrigin::Existential { .. } => {
- false
- }
- }
- }
}
use rustc::ty::print::RegionHighlightMode;
use rustc::ty::subst::{GenericArgKind, SubstsRef};
-use rustc::ty::{self, RegionVid, Ty, TyCtxt};
-use rustc_data_structures::fx::FxHashMap;
+use rustc::ty::{self, RegionVid, Ty};
use rustc_errors::DiagnosticBuilder;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_span::symbol::kw;
use rustc_span::{symbol::Symbol, Span, DUMMY_SP};
-use crate::borrow_check::{
- nll::ToRegionVid, region_infer::RegionInferenceContext, universal_regions::DefiningTy,
- MirBorrowckCtxt,
-};
+use crate::borrow_check::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt};
/// A name for a particular region used in emitting diagnostics. This name could be a generated
/// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
AnonRegionFromAsyncFn(Span),
}
-/// Records region names that have been assigned before so that we can use the same ones in later
-/// diagnostics.
-#[derive(Debug, Clone)]
-crate struct RegionErrorNamingCtx {
- /// Record the region names generated for each region in the given
- /// MIR def so that we can reuse them later in help/error messages.
- renctx: FxHashMap<RegionVid, RegionName>,
-
- /// The counter for generating new region names.
- counter: usize,
-}
-
-impl RegionErrorNamingCtx {
- crate fn new() -> Self {
- Self { counter: 1, renctx: FxHashMap::default() }
- }
-
- /// Get the name of `region` if it has previously been named.
- crate fn get(&self, region: &RegionVid) -> Option<&RegionName> {
- self.renctx.get(region)
- }
-
- /// Give `region` the name `name`.
- crate fn insert(&mut self, region: RegionVid, name: RegionName) {
- self.renctx.insert(region, name);
- }
-
- /// Creates a synthetic region named `'N`, where `N` is the next value of the counter. Then,
- /// increment the counter.
- ///
- /// The name is not memoized. A separate call to `insert` should be made later. (Currently,
- /// this happens at the end of `give_region_a_name`).
- crate fn synthesize_region_name(&mut self) -> Symbol {
- let c = self.counter;
- self.counter += 1;
-
- Symbol::intern(&format!("'{:?}", c))
- }
-}
-
impl RegionName {
crate fn was_named(&self) -> bool {
match self.source {
}
}
-impl<'tcx> RegionInferenceContext<'tcx> {
+impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
+ /// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
+ /// increment the counter.
+ ///
+ /// This is _not_ idempotent. Call `give_region_a_name` when possible.
+ fn synthesize_region_name(&self) -> Symbol {
+ let c = self.next_region_name.replace_with(|counter| *counter + 1);
+ Symbol::intern(&format!("'{:?}", c))
+ }
+
/// Maps from an internal MIR region vid to something that we can
/// report to the user. In some cases, the region vids will map
/// directly to lifetimes that the user has a name for (e.g.,
/// that end, this function takes a "diagnostic" so that it can
/// create auxiliary notes as needed.
///
+ /// The names are memoized, so this is both cheap to recompute and idempotent.
+ ///
/// Example (function arguments):
///
/// Suppose we are trying to give a name to the lifetime of the
/// ```
///
/// and then return the name `'1` for us to use.
- crate fn give_region_a_name(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- renctx: &mut RegionErrorNamingCtx,
- fr: RegionVid,
- ) -> Option<RegionName> {
- debug!("give_region_a_name(fr={:?}, counter={:?})", fr, renctx.counter);
+ crate fn give_region_a_name(&self, fr: RegionVid) -> Option<RegionName> {
+ debug!(
+ "give_region_a_name(fr={:?}, counter={:?})",
+ fr,
+ self.next_region_name.try_borrow().unwrap()
+ );
- assert!(self.universal_regions.is_universal_region(fr));
+ assert!(self.regioncx.universal_regions().is_universal_region(fr));
- if let Some(value) = renctx.get(&fr) {
+ if let Some(value) = self.region_names.try_borrow_mut().unwrap().get(&fr) {
return Some(value.clone());
}
let value = self
- .give_name_from_error_region(mbcx, fr, renctx)
- .or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(mbcx, fr, renctx))
- .or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(mbcx, fr, renctx))
- .or_else(|| self.give_name_if_anonymous_region_appears_in_output(mbcx, fr, renctx))
- .or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(mbcx, fr, renctx));
+ .give_name_from_error_region(fr)
+ .or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(fr))
+ .or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr))
+ .or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
+ .or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr));
if let Some(ref value) = value {
- renctx.insert(fr, value.clone());
+ self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
}
debug!("give_region_a_name: gave name {:?}", value);
/// *user* has a name for. In that case, we'll be able to map
/// `fr` to a `Region<'tcx>`, and that region will be one of
/// named variants.
- fn give_name_from_error_region(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- fr: RegionVid,
- renctx: &mut RegionErrorNamingCtx,
- ) -> Option<RegionName> {
+ fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
let error_region = self.to_error_region(fr)?;
- let tcx = mbcx.infcx.tcx;
+ let tcx = self.infcx.tcx;
debug!("give_region_a_name: error_region = {:?}", error_region);
match error_region {
// happen if we have an elided name in an async fn for example: the
// compiler will generate a region named `'_`, but reporting such a name is
// not actually useful, so we synthesize a name for it instead.
- let name = renctx.synthesize_region_name();
+ let name = self.synthesize_region_name();
Some(RegionName {
name,
source: RegionNameSource::AnonRegionFromAsyncFn(span),
}
ty::BoundRegion::BrEnv => {
- let mir_hir_id = mbcx
+ let mir_hir_id = self
.infcx
.tcx
.hir()
- .as_local_hir_id(mbcx.mir_def_id)
+ .as_local_hir_id(self.mir_def_id)
.expect("non-local mir");
- let def_ty = self.universal_regions.defining_ty;
+ let def_ty = self.regioncx.universal_regions().defining_ty;
if let DefiningTy::Closure(def_id, substs) = def_ty {
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
} else {
bug!("Closure is not defined by a closure expr");
};
- let region_name = renctx.synthesize_region_name();
+ let region_name = self.synthesize_region_name();
let closure_kind_ty = substs.as_closure().kind_ty(def_id, tcx);
let note = match closure_kind_ty.to_opt_closure_kind() {
/// ```
fn give_name_if_anonymous_region_appears_in_arguments(
&self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
fr: RegionVid,
- renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
- let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs();
- let argument_index = self.get_argument_index_for_region(mbcx.infcx.tcx, fr)?;
-
- let arg_ty =
- self.universal_regions.unnormalized_input_tys[implicit_inputs + argument_index];
- if let Some(region_name) = self.give_name_if_we_can_match_hir_ty_from_argument(
- mbcx,
- fr,
- arg_ty,
- argument_index,
- renctx,
- ) {
+ let implicit_inputs = self.regioncx.universal_regions().defining_ty.implicit_inputs();
+ let argument_index = self.regioncx.get_argument_index_for_region(self.infcx.tcx, fr)?;
+
+ let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
+ [implicit_inputs + argument_index];
+ if let Some(region_name) =
+ self.give_name_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
+ {
return Some(region_name);
}
- self.give_name_if_we_cannot_match_hir_ty(mbcx, fr, arg_ty, renctx)
+ self.give_name_if_we_cannot_match_hir_ty(fr, arg_ty)
}
fn give_name_if_we_can_match_hir_ty_from_argument(
&self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
needle_fr: RegionVid,
argument_ty: Ty<'tcx>,
argument_index: usize,
- renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
- let mir_hir_id = mbcx.infcx.tcx.hir().as_local_hir_id(mbcx.mir_def_id)?;
- let fn_decl = mbcx.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
+ let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id)?;
+ let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
match argument_hir_ty.kind {
// This indicates a variable with no type annotation, like
// (`give_name_if_anonymous_region_appears_in_arguments`).
hir::TyKind::Infer => None,
- _ => self.give_name_if_we_can_match_hir_ty(
- mbcx.infcx.tcx,
- needle_fr,
- argument_ty,
- argument_hir_ty,
- renctx,
- ),
+ _ => self.give_name_if_we_can_match_hir_ty(needle_fr, argument_ty, argument_hir_ty),
}
}
/// ```
fn give_name_if_we_cannot_match_hir_ty(
&self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
needle_fr: RegionVid,
argument_ty: Ty<'tcx>,
- renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
- let counter = renctx.counter;
+ let counter = *self.next_region_name.try_borrow().unwrap();
let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(needle_fr, counter);
- let type_name = mbcx.infcx.extract_type_name(&argument_ty, Some(highlight)).0;
+ let type_name = self.infcx.extract_type_name(&argument_ty, Some(highlight)).0;
debug!(
"give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
);
let assigned_region_name = if type_name.find(&format!("'{}", counter)).is_some() {
// Only add a label if we can confirm that a region was labelled.
- let argument_index = self.get_argument_index_for_region(mbcx.infcx.tcx, needle_fr)?;
- let (_, span) = self.get_argument_name_and_span_for_region(
- &mbcx.body,
- &mbcx.local_names,
+ let argument_index =
+ self.regioncx.get_argument_index_for_region(self.infcx.tcx, needle_fr)?;
+ let (_, span) = self.regioncx.get_argument_name_and_span_for_region(
+ &self.body,
+ &self.local_names,
argument_index,
);
// This counter value will already have been used, so this function will increment
// it so the next value will be used next and return the region name that would
// have been used.
- name: renctx.synthesize_region_name(),
+ name: self.synthesize_region_name(),
source: RegionNameSource::CannotMatchHirTy(span, type_name),
})
} else {
/// to highlighting that closest type instead.
fn give_name_if_we_can_match_hir_ty(
&self,
- tcx: TyCtxt<'tcx>,
needle_fr: RegionVid,
argument_ty: Ty<'tcx>,
argument_hir_ty: &hir::Ty<'_>,
- renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> =
&mut vec![(argument_ty, argument_hir_ty)];
hir::TyKind::Rptr(_lifetime, referent_hir_ty),
) => {
if region.to_region_vid() == needle_fr {
- let region_name = renctx.synthesize_region_name();
+ let region_name = self.synthesize_region_name();
// Just grab the first character, the `&`.
- let source_map = tcx.sess.source_map();
+ let source_map = self.infcx.tcx.sess.source_map();
let ampersand_span = source_map.start_point(hir_ty.span);
return Some(RegionName {
substs,
needle_fr,
last_segment,
- renctx,
search_stack,
) {
return Some(name);
substs: SubstsRef<'tcx>,
needle_fr: RegionVid,
last_segment: &'hir hir::PathSegment<'hir>,
- renctx: &mut RegionErrorNamingCtx,
search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
) -> Option<RegionName> {
// Did the user give explicit arguments? (e.g., `Foo<..>`)
| hir::LifetimeName::Error
| hir::LifetimeName::Static
| hir::LifetimeName::Underscore => {
- let region_name = renctx.synthesize_region_name();
+ let region_name = self.synthesize_region_name();
let ampersand_span = lifetime.span;
Some(RegionName {
name: region_name,
/// | let x = Some(&22);
/// - fully elaborated type of `x` is `Option<&'1 u32>`
/// ```
- fn give_name_if_anonymous_region_appears_in_upvars(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- fr: RegionVid,
- renctx: &mut RegionErrorNamingCtx,
- ) -> Option<RegionName> {
- let upvar_index = self.get_upvar_index_for_region(mbcx.infcx.tcx, fr)?;
- let (upvar_name, upvar_span) =
- self.get_upvar_name_and_span_for_region(mbcx.infcx.tcx, &mbcx.upvars, upvar_index);
- let region_name = renctx.synthesize_region_name();
+ fn give_name_if_anonymous_region_appears_in_upvars(&self, fr: RegionVid) -> Option<RegionName> {
+ let upvar_index = self.regioncx.get_upvar_index_for_region(self.infcx.tcx, fr)?;
+ let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
+ self.infcx.tcx,
+ &self.upvars,
+ upvar_index,
+ );
+ let region_name = self.synthesize_region_name();
Some(RegionName {
name: region_name,
/// must be a closure since, in a free fn, such an argument would
/// have to either also appear in an argument (if using elision)
/// or be early bound (named, not in argument).
- fn give_name_if_anonymous_region_appears_in_output(
- &self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
- fr: RegionVid,
- renctx: &mut RegionErrorNamingCtx,
- ) -> Option<RegionName> {
- let tcx = mbcx.infcx.tcx;
+ fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
+ let tcx = self.infcx.tcx;
- let return_ty = self.universal_regions.unnormalized_output_ty;
+ let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
if !tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) {
return None;
}
let mut highlight = RegionHighlightMode::default();
- highlight.highlighting_region_vid(fr, renctx.counter);
- let type_name = mbcx.infcx.extract_type_name(&return_ty, Some(highlight)).0;
+ highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
+ let type_name = self.infcx.extract_type_name(&return_ty, Some(highlight)).0;
- let mir_hir_id = tcx.hir().as_local_hir_id(mbcx.mir_def_id).expect("non-local mir");
+ let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id).expect("non-local mir");
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
hir::Node::Expr(hir::Expr {
kind: hir::ImplItemKind::Method(method_sig, _),
..
}) => (method_sig.decl.output.span(), ""),
- _ => (mbcx.body.span, ""),
+ _ => (self.body.span, ""),
};
Some(RegionName {
// This counter value will already have been used, so this function will increment it
// so the next value will be used next and return the region name that would have been
// used.
- name: renctx.synthesize_region_name(),
+ name: self.synthesize_region_name(),
source: RegionNameSource::AnonRegionFromOutput(
return_span,
mir_description.to_string(),
fn give_name_if_anonymous_region_appears_in_yield_ty(
&self,
- mbcx: &MirBorrowckCtxt<'_, 'tcx>,
fr: RegionVid,
- renctx: &mut RegionErrorNamingCtx,
) -> Option<RegionName> {
// Note: generators from `async fn` yield `()`, so we don't have to
// worry about them here.
- let yield_ty = self.universal_regions.yield_ty?;
+ let yield_ty = self.regioncx.universal_regions().yield_ty?;
debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty,);
- let tcx = mbcx.infcx.tcx;
+ let tcx = self.infcx.tcx;
if !tcx.any_free_region_meets(&yield_ty, |r| r.to_region_vid() == fr) {
return None;
}
let mut highlight = RegionHighlightMode::default();
- highlight.highlighting_region_vid(fr, renctx.counter);
- let type_name = mbcx.infcx.extract_type_name(&yield_ty, Some(highlight)).0;
+ highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
+ let type_name = self.infcx.extract_type_name(&yield_ty, Some(highlight)).0;
- let mir_hir_id = tcx.hir().as_local_hir_id(mbcx.mir_def_id).expect("non-local mir");
+ let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id).expect("non-local mir");
let yield_span = match tcx.hir().get(mir_hir_id) {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
}) => (tcx.sess.source_map().end_point(*span)),
- _ => mbcx.body.span,
+ _ => self.body.span,
};
debug!(
);
Some(RegionName {
- name: renctx.synthesize_region_name(),
+ name: self.synthesize_region_name(),
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
})
}
fr: RegionVid,
) -> Option<(Option<Symbol>, Span)> {
debug!("get_var_name_and_span_for_region(fr={:?})", fr);
- assert!(self.universal_regions.is_universal_region(fr));
+ assert!(self.universal_regions().is_universal_region(fr));
debug!("get_var_name_and_span_for_region: attempting upvar");
self.get_upvar_index_for_region(tcx, fr)
/// Search the upvars (if any) to find one that references fr. Return its index.
crate fn get_upvar_index_for_region(&self, tcx: TyCtxt<'tcx>, fr: RegionVid) -> Option<usize> {
let upvar_index =
- self.universal_regions.defining_ty.upvar_tys(tcx).position(|upvar_ty| {
+ self.universal_regions().defining_ty.upvar_tys(tcx).position(|upvar_ty| {
debug!("get_upvar_index_for_region: upvar_ty={:?}", upvar_ty);
tcx.any_free_region_meets(&upvar_ty, |r| {
let r = r.to_region_vid();
})
})?;
- let upvar_ty = self.universal_regions.defining_ty.upvar_tys(tcx).nth(upvar_index);
+ let upvar_ty = self.universal_regions().defining_ty.upvar_tys(tcx).nth(upvar_index);
debug!(
"get_upvar_index_for_region: found {:?} in upvar {} which has type {:?}",
tcx: TyCtxt<'tcx>,
fr: RegionVid,
) -> Option<usize> {
- let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs();
+ let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs();
let argument_index =
- self.universal_regions.unnormalized_input_tys.iter().skip(implicit_inputs).position(
+ self.universal_regions().unnormalized_input_tys.iter().skip(implicit_inputs).position(
|arg_ty| {
debug!("get_argument_index_for_region: arg_ty = {:?}", arg_ty);
tcx.any_free_region_meets(arg_ty, |r| r.to_region_vid() == fr)
debug!(
"get_argument_index_for_region: found {:?} in argument {} which has type {:?}",
- fr, argument_index, self.universal_regions.unnormalized_input_tys[argument_index],
+ fr,
+ argument_index,
+ self.universal_regions().unnormalized_input_tys[argument_index],
);
Some(argument_index)
local_names: &IndexVec<Local, Option<Symbol>>,
argument_index: usize,
) -> (Option<Symbol>, Span) {
- let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs();
+ let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs();
let argument_local = Local::new(implicit_inputs + argument_index + 1);
debug!("get_argument_name_and_span_for_region: argument_local={:?}", argument_local);
//! This query borrow-checks the MIR to (further) ensure it is not broken.
-use rustc::infer::{opaque_types, InferCtxt};
+use rustc::infer::InferCtxt;
use rustc::lint::builtin::MUTABLE_BORROW_RESERVATION_CONFLICT;
use rustc::lint::builtin::UNUSED_MUT;
use rustc::mir::{
use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
use rustc::mir::{Terminator, TerminatorKind};
use rustc::ty::query::Providers;
-use rustc::ty::{self, TyCtxt};
+use rustc::ty::{self, RegionVid, TyCtxt};
+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_index::vec::IndexVec;
use smallvec::SmallVec;
+use std::cell::RefCell;
use std::collections::BTreeMap;
use std::mem;
use std::rc::Rc;
use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use crate::transform::MirSource;
-use self::diagnostics::{
- AccessKind, OutlivesSuggestionBuilder, RegionErrorKind, RegionErrorNamingCtx, RegionErrors,
-};
+use self::diagnostics::{AccessKind, RegionName};
use self::flows::Flows;
use self::location::LocationTable;
use self::prefixes::PrefixSet;
move_error_reported: BTreeMap::new(),
uninitialized_error_reported: Default::default(),
errors_buffer,
- nonlexical_regioncx: regioncx,
+ regioncx,
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
borrow_set,
dominators,
upvars,
local_names,
+ region_names: RefCell::default(),
+ next_region_name: RefCell::new(1),
};
// Compute and report region errors, if any.
/// If the function we're checking is a closure, then we'll need to report back the list of
/// mutable upvars that have been used. This field keeps track of them.
used_mut_upvars: SmallVec<[Field; 8]>,
- /// Non-lexical region inference context, if NLL is enabled. This
- /// contains the results from region inference and lets us e.g.
+ /// Region inference context. This contains the results from region inference and lets us e.g.
/// find out which CFG points are contained in each borrow region.
- nonlexical_regioncx: Rc<RegionInferenceContext<'tcx>>,
+ regioncx: Rc<RegionInferenceContext<'tcx>>,
/// The set of borrows extracted from the MIR
borrow_set: Rc<BorrowSet<'tcx>>,
/// Names of local (user) variables (extracted from `var_debug_info`).
local_names: IndexVec<Local, Option<Name>>,
+
+ /// Record the region names generated for each region in the given
+ /// MIR def so that we can reuse them later in help/error messages.
+ region_names: RefCell<FxHashMap<RegionVid, RegionName>>,
+
+ /// The counter for generating new region names.
+ next_region_name: RefCell<usize>,
}
// Check that:
debug!(
"visit_terminator_drop \
- loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",
+ loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",
loc, term, drop_place, drop_place_ty, span
);
// initial reservation.
}
}
-
- /// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
- fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) {
- // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are
- // buffered in the `MirBorrowckCtxt`.
-
- // FIXME(mark-i-m): Would be great to get rid of the naming context.
- let mut region_naming = RegionErrorNamingCtx::new();
- let mut outlives_suggestion = OutlivesSuggestionBuilder::default();
-
- for nll_error in nll_errors.into_iter() {
- match nll_error {
- RegionErrorKind::TypeTestDoesNotLiveLongEnough { span, generic } => {
- // FIXME. We should handle this case better. It
- // indicates that we have e.g., some region variable
- // whose value is like `'a+'b` where `'a` and `'b` are
- // distinct unrelated univesal regions that are not
- // known to outlive one another. It'd be nice to have
- // some examples where this arises to decide how best
- // to report it; we could probably handle it by
- // iterating over the universal regions and reporting
- // an error that multiple bounds are required.
- self.infcx
- .tcx
- .sess
- .struct_span_err(span, &format!("`{}` does not live long enough", generic))
- .buffer(&mut self.errors_buffer);
- }
-
- RegionErrorKind::TypeTestGenericBoundError {
- span,
- generic,
- lower_bound_region,
- } => {
- let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
- self.infcx
- .construct_generic_bound_failure(
- region_scope_tree,
- span,
- None,
- generic,
- lower_bound_region,
- )
- .buffer(&mut self.errors_buffer);
- }
-
- RegionErrorKind::UnexpectedHiddenRegion {
- opaque_type_def_id,
- hidden_ty,
- member_region,
- } => {
- let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
- opaque_types::unexpected_hidden_region_diagnostic(
- self.infcx.tcx,
- Some(region_scope_tree),
- opaque_type_def_id,
- hidden_ty,
- member_region,
- )
- .buffer(&mut self.errors_buffer);
- }
-
- RegionErrorKind::BoundUniversalRegionError {
- longer_fr,
- fr_origin,
- error_region,
- } => {
- // Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
- let (_, span) = self.nonlexical_regioncx.find_outlives_blame_span(
- &self.body,
- longer_fr,
- fr_origin,
- error_region,
- );
-
- // FIXME: improve this error message
- self.infcx
- .tcx
- .sess
- .struct_span_err(span, "higher-ranked subtype error")
- .buffer(&mut self.errors_buffer);
- }
-
- RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {
- if is_reported {
- let db = self.nonlexical_regioncx.report_error(
- self,
- longer_fr,
- fr_origin,
- shorter_fr,
- &mut outlives_suggestion,
- &mut region_naming,
- );
-
- db.buffer(&mut self.errors_buffer);
- } else {
- // We only report the first error, so as not to overwhelm the user. See
- // `RegRegionErrorKind` docs.
- //
- // FIXME: currently we do nothing with these, but perhaps we can do better?
- // FIXME: try collecting these constraints on the outlives suggestion
- // builder. Does it make the suggestions any better?
- debug!(
- "Unreported region error: can't prove that {:?}: {:?}",
- longer_fr, shorter_fr
- );
- }
- }
- }
- }
-
- // Emit one outlives suggestions for each MIR def we borrowck
- outlives_suggestion.add_suggestion(self, &mut region_naming);
- }
}
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let upvar = &self.upvars[field.index()];
debug!(
"upvar.mutability={:?} local_mutation_is_allowed={:?} \
- place={:?}",
+ place={:?}",
upvar, is_local_mutation_allowed, place
);
match (upvar.mutability, is_local_mutation_allowed) {
+use std::collections::VecDeque;
use std::rc::Rc;
use rustc::infer::canonical::QueryOutlivesConstraint;
/// variables are identified by their index (`RegionVid`). The
/// definition contains information about where the region came
/// from as well as its final inferred value.
- pub(in crate::borrow_check) definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
+ definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
/// The liveness constraints added to each region. For most
/// regions, these start out empty and steadily grow, though for
/// each universally quantified region R they start out containing
/// the entire CFG and `end(R)`.
- pub(in crate::borrow_check) liveness_constraints: LivenessValues<RegionVid>,
+ liveness_constraints: LivenessValues<RegionVid>,
/// The outlives constraints computed by the type-check.
- pub(in crate::borrow_check) constraints: Rc<OutlivesConstraintSet>,
+ constraints: Rc<OutlivesConstraintSet>,
/// The constraint-set, but in graph form, making it easy to traverse
/// the constraints adjacent to a particular region. Used to construct
/// the SCC (see `constraint_sccs`) and for error reporting.
- pub(in crate::borrow_check) constraint_graph: Rc<NormalConstraintGraph>,
+ constraint_graph: Rc<NormalConstraintGraph>,
/// The SCC computed from `constraints` and the constraint
/// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
/// compute the values of each region.
- pub(in crate::borrow_check) constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
+ constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B`
/// exists if `B: A`. Computed lazilly.
- pub(in crate::borrow_check) rev_constraint_graph: Option<Rc<VecGraph<ConstraintSccIndex>>>,
+ rev_constraint_graph: Option<Rc<VecGraph<ConstraintSccIndex>>>,
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
- pub(in crate::borrow_check) member_constraints:
- Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
+ member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
/// Records the member constraints that we applied to each scc.
/// This is useful for error reporting. Once constraint
/// propagation is done, this vector is sorted according to
/// `member_region_scc`.
- pub(in crate::borrow_check) member_constraints_applied: Vec<AppliedMemberConstraint>,
+ member_constraints_applied: Vec<AppliedMemberConstraint>,
/// Map closure bounds to a `Span` that should be used for error reporting.
- pub(in crate::borrow_check) closure_bounds_mapping:
+ closure_bounds_mapping:
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
/// Contains the minimum universe of any variable within the same
/// SCC. We will ensure that no SCC contains values that are not
/// visible from this index.
- pub(in crate::borrow_check) scc_universes: IndexVec<ConstraintSccIndex, ty::UniverseIndex>,
+ scc_universes: IndexVec<ConstraintSccIndex, ty::UniverseIndex>,
/// Contains a "representative" from each SCC. This will be the
/// minimal RegionVid belonging to that universe. It is used as a
/// of its SCC and be sure that -- if they have the same repr --
/// they *must* be equal (though not having the same repr does not
/// mean they are unequal).
- pub(in crate::borrow_check) scc_representatives: IndexVec<ConstraintSccIndex, ty::RegionVid>,
+ scc_representatives: IndexVec<ConstraintSccIndex, ty::RegionVid>,
/// The final inferred values of the region variables; we compute
/// one value per SCC. To get the value for any given *region*,
/// you first find which scc it is a part of.
- pub(in crate::borrow_check) scc_values: RegionValues<ConstraintSccIndex>,
+ scc_values: RegionValues<ConstraintSccIndex>,
/// Type constraints that we check after solving.
- pub(in crate::borrow_check) type_tests: Vec<TypeTest<'tcx>>,
+ type_tests: Vec<TypeTest<'tcx>>,
/// Information about the universally quantified regions in scope
/// on this function.
- pub(in crate::borrow_check) universal_regions: Rc<UniversalRegions<'tcx>>,
+ universal_regions: Rc<UniversalRegions<'tcx>>,
/// Information about how the universally quantified regions in
/// scope on this function relate to one another.
- pub(in crate::borrow_check) universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
+ universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
}
/// Each time that `apply_member_constraint` is successful, it appends
Error,
}
+#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+enum Trace {
+ StartRegion,
+ FromOutlivesConstraint(OutlivesConstraint),
+ NotVisited,
+}
+
impl<'tcx> RegionInferenceContext<'tcx> {
/// Creates a new region inference context with a total of
/// `num_region_variables` valid inference variables; the first N
}
// Type-test failed. Report the error.
-
- // Try to convert the lower-bound region into something named we can print for the user.
- let lower_bound_region = self.to_error_region(type_test.lower_bound);
+ let erased_generic_kind = infcx.tcx.erase_regions(&type_test.generic_kind);
// Skip duplicate-ish errors.
- let type_test_span = type_test.locations.span(body);
- let erased_generic_kind = tcx.erase_regions(&type_test.generic_kind);
- if !deduplicate_errors.insert((
+ if deduplicate_errors.insert((
erased_generic_kind,
- lower_bound_region,
+ type_test.lower_bound,
type_test.locations,
)) {
- continue;
- } else {
debug!(
"check_type_test: reporting error for erased_generic_kind={:?}, \
lower_bound_region={:?}, \
type_test.locations={:?}",
- erased_generic_kind, lower_bound_region, type_test.locations,
+ erased_generic_kind, type_test.lower_bound, type_test.locations,
);
- }
- if let Some(lower_bound_region) = lower_bound_region {
- errors_buffer.push(RegionErrorKind::TypeTestGenericBoundError {
- span: type_test_span,
- generic: type_test.generic_kind,
- lower_bound_region,
- });
- } else {
- errors_buffer.push(RegionErrorKind::TypeTestDoesNotLiveLongEnough {
- span: type_test_span,
- generic: type_test.generic_kind,
- });
+ errors_buffer.push(RegionErrorKind::TypeTestError { type_test: type_test.clone() });
}
}
}
for (longer_fr, shorter_fr) in subset_errors.into_iter() {
debug!(
"check_polonius_subset_errors: subset_error longer_fr={:?},\
- shorter_fr={:?}",
+ shorter_fr={:?}",
longer_fr, shorter_fr
);
debug!("check_bound_universal_region: error_element = {:?}", error_element);
// Find the region that introduced this `error_element`.
- let error_region = match error_element {
- RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
- RegionElement::RootUniversalRegion(r) => r,
- RegionElement::PlaceholderRegion(error_placeholder) => self
- .definitions
- .iter_enumerated()
- .filter_map(|(r, definition)| match definition.origin {
- NLLRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r),
- _ => None,
- })
- .next()
- .unwrap(),
- };
-
errors_buffer.push(RegionErrorKind::BoundUniversalRegionError {
longer_fr,
- error_region,
+ error_element,
fr_origin: NLLRegionVariableOrigin::Placeholder(placeholder),
});
}
});
}
}
+
+ /// We have a constraint `fr1: fr2` that is not satisfied, where
+ /// `fr2` represents some universal region. Here, `r` is some
+ /// region where we know that `fr1: r` and this function has the
+ /// job of determining whether `r` is "to blame" for the fact that
+ /// `fr1: fr2` is required.
+ ///
+ /// This is true under two conditions:
+ ///
+ /// - `r == fr2`
+ /// - `fr2` is `'static` and `r` is some placeholder in a universe
+ /// that cannot be named by `fr1`; in that case, we will require
+ /// that `fr1: 'static` because it is the only way to `fr1: r` to
+ /// be satisfied. (See `add_incompatible_universe`.)
+ crate fn provides_universal_region(
+ &self,
+ r: RegionVid,
+ fr1: RegionVid,
+ fr2: RegionVid,
+ ) -> bool {
+ debug!("provides_universal_region(r={:?}, fr1={:?}, fr2={:?})", r, fr1, fr2);
+ let result = {
+ r == fr2 || {
+ fr2 == self.universal_regions.fr_static && self.cannot_name_placeholder(fr1, r)
+ }
+ };
+ debug!("provides_universal_region: result = {:?}", result);
+ result
+ }
+
+ /// If `r2` represents a placeholder region, then this returns
+ /// `true` if `r1` cannot name that placeholder in its
+ /// value; otherwise, returns `false`.
+ crate fn cannot_name_placeholder(&self, r1: RegionVid, r2: RegionVid) -> bool {
+ debug!("cannot_name_value_of(r1={:?}, r2={:?})", r1, r2);
+
+ match self.definitions[r2].origin {
+ NLLRegionVariableOrigin::Placeholder(placeholder) => {
+ let universe1 = self.definitions[r1].universe;
+ debug!(
+ "cannot_name_value_of: universe1={:?} placeholder={:?}",
+ universe1, placeholder
+ );
+ universe1.cannot_name(placeholder.universe)
+ }
+
+ NLLRegionVariableOrigin::FreeRegion | NLLRegionVariableOrigin::Existential { .. } => {
+ false
+ }
+ }
+ }
+
+ crate fn retrieve_closure_constraint_info(
+ &self,
+ body: &Body<'tcx>,
+ constraint: &OutlivesConstraint,
+ ) -> (ConstraintCategory, bool, Span) {
+ let loc = match constraint.locations {
+ Locations::All(span) => return (constraint.category, false, span),
+ Locations::Single(loc) => loc,
+ };
+
+ let opt_span_category =
+ self.closure_bounds_mapping[&loc].get(&(constraint.sup, constraint.sub));
+ opt_span_category.map(|&(category, span)| (category, true, span)).unwrap_or((
+ constraint.category,
+ false,
+ body.source_info(loc).span,
+ ))
+ }
+
+ /// Finds a good span to blame for the fact that `fr1` outlives `fr2`.
+ crate fn find_outlives_blame_span(
+ &self,
+ body: &Body<'tcx>,
+ fr1: RegionVid,
+ fr1_origin: NLLRegionVariableOrigin,
+ fr2: RegionVid,
+ ) -> (ConstraintCategory, Span) {
+ let (category, _, span) = self.best_blame_constraint(body, fr1, fr1_origin, |r| {
+ self.provides_universal_region(r, fr1, fr2)
+ });
+ (category, span)
+ }
+
+ /// Walks the graph of constraints (where `'a: 'b` is considered
+ /// an edge `'a -> 'b`) to find all paths from `from_region` to
+ /// `to_region`. The paths are accumulated into the vector
+ /// `results`. The paths are stored as a series of
+ /// `ConstraintIndex` values -- in other words, a list of *edges*.
+ ///
+ /// Returns: a series of constraints as well as the region `R`
+ /// that passed the target test.
+ crate fn find_constraint_paths_between_regions(
+ &self,
+ from_region: RegionVid,
+ target_test: impl Fn(RegionVid) -> bool,
+ ) -> Option<(Vec<OutlivesConstraint>, RegionVid)> {
+ let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions);
+ context[from_region] = Trace::StartRegion;
+
+ // Use a deque so that we do a breadth-first search. We will
+ // stop at the first match, which ought to be the shortest
+ // path (fewest constraints).
+ let mut deque = VecDeque::new();
+ deque.push_back(from_region);
+
+ while let Some(r) = deque.pop_front() {
+ debug!(
+ "find_constraint_paths_between_regions: from_region={:?} r={:?} value={}",
+ from_region,
+ r,
+ self.region_value_str(r),
+ );
+
+ // Check if we reached the region we were looking for. If so,
+ // we can reconstruct the path that led to it and return it.
+ if target_test(r) {
+ let mut result = vec![];
+ let mut p = r;
+ loop {
+ match context[p] {
+ Trace::NotVisited => {
+ bug!("found unvisited region {:?} on path to {:?}", p, r)
+ }
+
+ Trace::FromOutlivesConstraint(c) => {
+ result.push(c);
+ p = c.sup;
+ }
+
+ Trace::StartRegion => {
+ result.reverse();
+ return Some((result, r));
+ }
+ }
+ }
+ }
+
+ // Otherwise, walk over the outgoing constraints and
+ // enqueue any regions we find, keeping track of how we
+ // reached them.
+
+ // A constraint like `'r: 'x` can come from our constraint
+ // graph.
+ let fr_static = self.universal_regions.fr_static;
+ let outgoing_edges_from_graph =
+ self.constraint_graph.outgoing_edges(r, &self.constraints, fr_static);
+
+ // Always inline this closure because it can be hot.
+ let mut handle_constraint = #[inline(always)]
+ |constraint: OutlivesConstraint| {
+ debug_assert_eq!(constraint.sup, r);
+ let sub_region = constraint.sub;
+ if let Trace::NotVisited = context[sub_region] {
+ context[sub_region] = Trace::FromOutlivesConstraint(constraint);
+ deque.push_back(sub_region);
+ }
+ };
+
+ // This loop can be hot.
+ for constraint in outgoing_edges_from_graph {
+ handle_constraint(constraint);
+ }
+
+ // Member constraints can also give rise to `'r: 'x` edges that
+ // were not part of the graph initially, so watch out for those.
+ // (But they are extremely rare; this loop is very cold.)
+ for constraint in self.applied_member_constraints(r) {
+ let p_c = &self.member_constraints[constraint.member_constraint_index];
+ let constraint = OutlivesConstraint {
+ sup: r,
+ sub: constraint.min_choice,
+ locations: Locations::All(p_c.definition_span),
+ category: ConstraintCategory::OpaqueType,
+ };
+ handle_constraint(constraint);
+ }
+ }
+
+ None
+ }
+
+ /// Finds some region R such that `fr1: R` and `R` is live at `elem`.
+ crate fn find_sub_region_live_at(&self, fr1: RegionVid, elem: Location) -> RegionVid {
+ debug!("find_sub_region_live_at(fr1={:?}, elem={:?})", fr1, elem);
+ self.find_constraint_paths_between_regions(fr1, |r| {
+ // First look for some `r` such that `fr1: r` and `r` is live at `elem`
+ debug!(
+ "find_sub_region_live_at: liveness_constraints for {:?} are {:?}",
+ r,
+ self.liveness_constraints.region_value_str(r),
+ );
+ self.liveness_constraints.contains(r, elem)
+ })
+ .or_else(|| {
+ // If we fail to find that, we may find some `r` such that
+ // `fr1: r` and `r` is a placeholder from some universe
+ // `fr1` cannot name. This would force `fr1` to be
+ // `'static`.
+ self.find_constraint_paths_between_regions(fr1, |r| {
+ self.cannot_name_placeholder(fr1, r)
+ })
+ })
+ .or_else(|| {
+ // If we fail to find THAT, it may be that `fr1` is a
+ // placeholder that cannot "fit" into its SCC. In that
+ // case, there should be some `r` where `fr1: r`, both
+ // `fr1` and `r` are in the same SCC, and `fr1` is a
+ // placeholder that `r` cannot name. We can blame that
+ // edge.
+ self.find_constraint_paths_between_regions(fr1, |r| {
+ self.constraint_sccs.scc(fr1) == self.constraint_sccs.scc(r)
+ && self.cannot_name_placeholder(r, fr1)
+ })
+ })
+ .map(|(_path, r)| r)
+ .unwrap()
+ }
+
+ /// Get the region outlived by `longer_fr` and live at `element`.
+ crate fn region_from_element(&self, longer_fr: RegionVid, element: RegionElement) -> RegionVid {
+ match element {
+ RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
+ RegionElement::RootUniversalRegion(r) => r,
+ RegionElement::PlaceholderRegion(error_placeholder) => self
+ .definitions
+ .iter_enumerated()
+ .filter_map(|(r, definition)| match definition.origin {
+ NLLRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r),
+ _ => None,
+ })
+ .next()
+ .unwrap(),
+ }
+ }
+
+ /// Get the region definition of `r`.
+ crate fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx> {
+ &self.definitions[r]
+ }
+
+ /// Check if the SCC of `r` contains `upper`.
+ crate fn upper_bound_in_region_scc(&self, r: RegionVid, upper: RegionVid) -> bool {
+ let r_scc = self.constraint_sccs.scc(r);
+ self.scc_values.contains(r_scc, upper)
+ }
+
+ crate fn universal_regions(&self) -> &UniversalRegions<'tcx> {
+ self.universal_regions.as_ref()
+ }
+
+ /// Tries to find the best constraint to blame for the fact that
+ /// `R: from_region`, where `R` is some region that meets
+ /// `target_test`. This works by following the constraint graph,
+ /// creating a constraint path that forces `R` to outlive
+ /// `from_region`, and then finding the best choices within that
+ /// path to blame.
+ crate fn best_blame_constraint(
+ &self,
+ body: &Body<'tcx>,
+ from_region: RegionVid,
+ from_region_origin: NLLRegionVariableOrigin,
+ target_test: impl Fn(RegionVid) -> bool,
+ ) -> (ConstraintCategory, bool, Span) {
+ debug!(
+ "best_blame_constraint(from_region={:?}, from_region_origin={:?})",
+ from_region, from_region_origin
+ );
+
+ // Find all paths
+ let (path, target_region) =
+ self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
+ debug!(
+ "best_blame_constraint: path={:#?}",
+ path.iter()
+ .map(|&c| format!(
+ "{:?} ({:?}: {:?})",
+ c,
+ self.constraint_sccs.scc(c.sup),
+ self.constraint_sccs.scc(c.sub),
+ ))
+ .collect::<Vec<_>>()
+ );
+
+ // Classify each of the constraints along the path.
+ let mut categorized_path: Vec<(ConstraintCategory, bool, Span)> = path
+ .iter()
+ .map(|constraint| {
+ if constraint.category == ConstraintCategory::ClosureBounds {
+ self.retrieve_closure_constraint_info(body, &constraint)
+ } else {
+ (constraint.category, false, constraint.locations.span(body))
+ }
+ })
+ .collect();
+ debug!("best_blame_constraint: categorized_path={:#?}", categorized_path);
+
+ // To find the best span to cite, we first try to look for the
+ // final constraint that is interesting and where the `sup` is
+ // not unified with the ultimate target region. The reason
+ // for this is that we have a chain of constraints that lead
+ // from the source to the target region, something like:
+ //
+ // '0: '1 ('0 is the source)
+ // '1: '2
+ // '2: '3
+ // '3: '4
+ // '4: '5
+ // '5: '6 ('6 is the target)
+ //
+ // Some of those regions are unified with `'6` (in the same
+ // SCC). We want to screen those out. After that point, the
+ // "closest" constraint we have to the end is going to be the
+ // most likely to be the point where the value escapes -- but
+ // we still want to screen for an "interesting" point to
+ // highlight (e.g., a call site or something).
+ let target_scc = self.constraint_sccs.scc(target_region);
+ let mut range = 0..path.len();
+
+ // As noted above, when reporting an error, there is typically a chain of constraints
+ // leading from some "source" region which must outlive some "target" region.
+ // In most cases, we prefer to "blame" the constraints closer to the target --
+ // but there is one exception. When constraints arise from higher-ranked subtyping,
+ // we generally prefer to blame the source value,
+ // as the "target" in this case tends to be some type annotation that the user gave.
+ // Therefore, if we find that the region origin is some instantiation
+ // of a higher-ranked region, we start our search from the "source" point
+ // rather than the "target", and we also tweak a few other things.
+ //
+ // An example might be this bit of Rust code:
+ //
+ // ```rust
+ // let x: fn(&'static ()) = |_| {};
+ // let y: for<'a> fn(&'a ()) = x;
+ // ```
+ //
+ // In MIR, this will be converted into a combination of assignments and type ascriptions.
+ // In particular, the 'static is imposed through a type ascription:
+ //
+ // ```rust
+ // x = ...;
+ // AscribeUserType(x, fn(&'static ())
+ // y = x;
+ // ```
+ //
+ // We wind up ultimately with constraints like
+ //
+ // ```rust
+ // !a: 'temp1 // from the `y = x` statement
+ // 'temp1: 'temp2
+ // 'temp2: 'static // from the AscribeUserType
+ // ```
+ //
+ // and here we prefer to blame the source (the y = x statement).
+ let blame_source = match from_region_origin {
+ NLLRegionVariableOrigin::FreeRegion
+ | NLLRegionVariableOrigin::Existential { from_forall: false } => true,
+ NLLRegionVariableOrigin::Placeholder(_)
+ | NLLRegionVariableOrigin::Existential { from_forall: true } => false,
+ };
+
+ let find_region = |i: &usize| {
+ let constraint = path[*i];
+
+ let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup);
+
+ if blame_source {
+ match categorized_path[*i].0 {
+ ConstraintCategory::OpaqueType
+ | ConstraintCategory::Boring
+ | ConstraintCategory::BoringNoLocation
+ | ConstraintCategory::Internal => false,
+ ConstraintCategory::TypeAnnotation
+ | ConstraintCategory::Return
+ | ConstraintCategory::Yield => true,
+ _ => constraint_sup_scc != target_scc,
+ }
+ } else {
+ match categorized_path[*i].0 {
+ ConstraintCategory::OpaqueType
+ | ConstraintCategory::Boring
+ | ConstraintCategory::BoringNoLocation
+ | ConstraintCategory::Internal => false,
+ _ => true,
+ }
+ }
+ };
+
+ let best_choice =
+ if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
+
+ debug!(
+ "best_blame_constraint: best_choice={:?} blame_source={}",
+ best_choice, blame_source
+ );
+
+ if let Some(i) = best_choice {
+ if let Some(next) = categorized_path.get(i + 1) {
+ if categorized_path[i].0 == ConstraintCategory::Return
+ && next.0 == ConstraintCategory::OpaqueType
+ {
+ // The return expression is being influenced by the return type being
+ // impl Trait, point at the return type and not the return expr.
+ return *next;
+ }
+ }
+ return categorized_path[i];
+ }
+
+ // If that search fails, that is.. unusual. Maybe everything
+ // is in the same SCC or something. In that case, find what
+ // appears to be the most interesting point to report to the
+ // user via an even more ad-hoc guess.
+ categorized_path.sort_by(|p0, p1| p0.0.cmp(&p1.0));
+ debug!("`: sorted_path={:#?}", categorized_path);
+
+ *categorized_path.first().unwrap()
+ }
}
impl<'tcx> RegionDefinition<'tcx> {
/// An individual element in a region value -- the value of a
/// particular region variable consists of a set of these elements.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
crate enum RegionElement {
/// A point in the control-flow graph.
Location(Location),
TyCtxt, UserType, UserTypeAnnotationIndex,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
Ok((layout.size, layout.align.abi))
}
- Some(GlobalAlloc::Memory(alloc)) =>
- // Need to duplicate the logic here, because the global allocations have
- // different associated types than the interpreter-local ones.
- {
+ Some(GlobalAlloc::Memory(alloc)) => {
+ // Need to duplicate the logic here, because the global allocations have
+ // different associated types than the interpreter-local ones.
Ok((alloc.size, alloc.align))
}
Some(GlobalAlloc::Function(_)) => bug!("We already checked function pointers above"),
let variant_index = variants_start
.checked_add(variant_index_relative)
.expect("oveflow computing absolute variant idx");
- assert!(
- (variant_index as usize)
- < rval
- .layout
- .ty
- .ty_adt_def()
- .expect("tagged layout for non adt")
- .variants
- .len()
- );
+ let variants_len = rval
+ .layout
+ .ty
+ .ty_adt_def()
+ .expect("tagged layout for non adt")
+ .variants
+ .len();
+ assert!((variant_index as usize) < variants_len);
(u128::from(variant_index), VariantIdx::from_u32(variant_index))
} else {
(u128::from(dataful_variant.as_u32()), dataful_variant)
// happens at run-time so that's okay.
let align = match self.size_and_align_of(base.meta, field_layout)? {
Some((_, align)) => align,
- None if offset == Size::ZERO =>
- // An extern type at offset 0, we fall back to its static alignment.
- // FIXME: Once we have made decisions for how to handle size and alignment
- // of `extern type`, this should be adapted. It is just a temporary hack
- // to get some code to work that probably ought to work.
- {
+ None if offset == Size::ZERO => {
+ // An extern type at offset 0, we fall back to its static alignment.
+ // FIXME: Once we have made decisions for how to handle size and alignment
+ // of `extern type`, this should be adapted. It is just a temporary hack
+ // to get some code to work that probably ought to work.
field_layout.align.abi
}
None => bug!("Cannot compute offset for extern type field at non-0 offset"),
ClosureVar(name) => write!(out, ".<closure-var({})>", name),
TupleElem(idx) => write!(out, ".{}", idx),
ArrayElem(idx) => write!(out, "[{}]", idx),
- Deref =>
- // This does not match Rust syntax, but it is more readable for long paths -- and
+ // `.<deref>` does not match Rust syntax, but it is more readable for long paths -- and
// some of the other items here also are not Rust syntax. Actually we can't
// even use the usual syntax because we are just showing the projections,
// not the root.
- {
- write!(out, ".<deref>")
- }
+ Deref => write!(out, ".<deref>"),
Tag => write!(out, ".<enum-tag>"),
DynDowncast => write!(out, ".<dyn-downcast>"),
}
ty::Adt(def, ..) if def.is_enum() => {
// we might be projecting *to* a variant, or to a field *in*a variant.
match layout.variants {
- layout::Variants::Single { index } =>
- // Inside a variant
- {
+ layout::Variants::Single { index } => {
+ // Inside a variant
PathElem::Field(def.variants[index].fields[field].ident.name)
}
_ => bug!(),
#![feature(nll)]
#![feature(in_band_lifetimes)]
#![feature(inner_deref)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0);
debug!(" => recursion depth={}", recursion_depth);
- let recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
+ let adjusted_recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
// HACK: drop_in_place creates tight monomorphization loops. Give
// it more margin.
recursion_depth / 4
// Code that needs to instantiate the same function recursively
// more than the recursion limit is assumed to be causing an
// infinite expansion.
- if recursion_depth > *tcx.sess.recursion_limit.get() {
+ if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
let error = format!("reached the recursion limit while instantiating `{}`", instance);
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
// Nothing to do, just keep recursing.
}
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
if self.mode == MonoItemCollectionMode::Eager {
create_mono_items_for_default_impls(self.tcx, item, self.output);
}
output: &mut Vec<MonoItem<'tcx>>,
) {
match item.kind {
- hir::ItemKind::Impl(_, _, _, ref generics, .., ref impl_item_refs) => {
+ hir::ItemKind::Impl { ref generics, ref items, .. } => {
for param in generics.params {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {}
let param_env = ty::ParamEnv::reveal_all();
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
let overridden_methods: FxHashSet<_> =
- impl_item_refs.iter().map(|iiref| iiref.ident.modern()).collect();
+ items.iter().map(|iiref| iiref.ident.modern()).collect();
for method in tcx.provided_trait_methods(trait_ref.def_id) {
if overridden_methods.contains(&method.ident.modern()) {
continue;
use super::{ConstKind, Item};
-use rustc_error_codes::*;
-
/// An operation that is not *always* allowed in a const context.
pub trait NonConstOp: std::fmt::Debug {
/// Whether this operation can be evaluated by miri.
use rustc::traits::{self, TraitEngine};
use rustc::ty::cast::CastTy;
use rustc::ty::{self, TyCtxt};
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir::{def_id::DefId, HirId};
use rustc_index::bit_set::BitSet;
use crate::const_eval::{is_const_fn, is_min_const_fn};
use crate::util;
-use rustc_error_codes::*;
-
pub struct UnsafetyChecker<'a, 'tcx> {
body: &'a Body<'tcx>,
const_context: bool,
}
}
-type Const<'tcx> = OpTy<'tcx>;
-
/// Finds optimization opportunities on the MIR.
struct ConstPropagator<'mir, 'tcx> {
ecx: InterpCx<'mir, 'tcx, ConstPropMachine>,
}
}
- fn get_const(&self, local: Local) -> Option<Const<'tcx>> {
+ fn get_const(&self, local: Local) -> Option<OpTy<'tcx>> {
if local == RETURN_PLACE {
// Try to read the return place as an immediate so that if it is representable as a
// scalar, we can handle it as such, but otherwise, just return the value as is.
r
}
- fn eval_constant(
- &mut self,
- c: &Constant<'tcx>,
- source_info: SourceInfo,
- ) -> Option<Const<'tcx>> {
+ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
self.ecx.tcx.span = c.span;
// FIXME we need to revisit this for #67176
}
}
- fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
+ fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
trace!("eval_place(place={:?})", place);
self.use_ecx(source_info, |this| this.ecx.eval_place_to_op(place, None))
}
- fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
+ fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
match *op {
Operand::Constant(ref c) => self.eval_constant(c, source_info),
Operand::Move(ref place) | Operand::Copy(ref place) => {
self.check_binary_op(*op, left, right, source_info, place_layout, overflow_check)?;
}
- // Work around: avoid ICE in miri. FIXME(wesleywiser)
- // The Miri engine ICEs when taking a reference to an uninitialized unsized
- // local. There's nothing it can do here: taking a reference needs an allocation
- // which needs to know the size. Normally that's okay as during execution
- // (e.g. for CTFE) it can never happen. But here in const_prop
- // unknown data is uninitialized, so if e.g. a function argument is unsized
- // and has a reference taken, we get an ICE.
+ // Do not try creating references (#67862)
Rvalue::Ref(_, _, place_ref) => {
- trace!("checking Ref({:?})", place_ref);
+ trace!("skipping Ref({:?})", place_ref);
- if let Some(local) = place_ref.as_local() {
- let alive = if let LocalValue::Live(_) = self.ecx.frame().locals[local].value {
- true
- } else {
- false
- };
-
- if !alive {
- trace!("skipping Ref({:?}) to uninitialized local", place);
- return None;
- }
- }
+ return None;
}
_ => {}
fn replace_with_const(
&mut self,
rval: &mut Rvalue<'tcx>,
- value: Const<'tcx>,
+ value: OpTy<'tcx>,
source_info: SourceInfo,
) {
trace!("attepting to replace {:?} with {:?}", rval, value);
) -> McfResult {
let span = terminator.source_info.span;
match &terminator.kind {
- TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::Resume => Ok(()),
+ TerminatorKind::FalseEdges { .. }
+ | TerminatorKind::FalseUnwind { .. }
+ | TerminatorKind::Goto { .. }
+ | TerminatorKind::Return
+ | TerminatorKind::Resume => Ok(()),
TerminatorKind::Drop { location, .. } => check_place(tcx, location, span, def_id, body),
TerminatorKind::DropAndReplace { location, value, .. } => {
check_operand(tcx, value, span, def_id, body)
}
- TerminatorKind::FalseEdges { .. } | TerminatorKind::SwitchInt { .. }
- if !feature_allowed(tcx, def_id, sym::const_if_match) =>
- {
+ TerminatorKind::SwitchInt { .. } if !feature_allowed(tcx, def_id, sym::const_if_match) => {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
- TerminatorKind::FalseEdges { .. } => Ok(()),
TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => {
check_operand(tcx, discr, span, def_id, body)
}
TerminatorKind::Assert { cond, expected: _, msg: _, target: _, cleanup: _ } => {
check_operand(tcx, cond, span, def_id, body)
}
-
- TerminatorKind::FalseUnwind { .. } if feature_allowed(tcx, def_id, sym::const_loop) => {
- Ok(())
- }
-
- TerminatorKind::FalseUnwind { .. } => {
- Err((span, "loops are not allowed in const fn".into()))
- }
}
}
use rustc::ty::{self, Ty, TyCtxt};
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId};
use rustc_span::{MultiSpan, Span};
rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
-rustc_error_codes = { path = "../librustc_error_codes" }
} else if cx.body_owner_kind.is_fn_or_closure() {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
- let fn_sig = cx.tables().liberated_fn_sigs()[id].clone();
+ let fn_sig = cx.tables().liberated_fn_sigs()[id];
let fn_def_id = tcx.hir().local_def_id(id);
let ty = tcx.type_of(fn_def_id);
let def_id = cx.tcx.hir().local_def_id(count.hir_id);
let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
let span = cx.tcx.def_span(def_id);
- let count =
- match cx.tcx.const_eval_resolve(cx.param_env, def_id, substs, None, Some(span)) {
- Ok(cv) => cv.eval_usize(cx.tcx, cx.param_env),
- Err(ErrorHandled::Reported) => 0,
- Err(ErrorHandled::TooGeneric) => {
- let span = cx.tcx.def_span(def_id);
- cx.tcx
- .sess
- .span_err(span, "array lengths can't depend on generic parameters");
- 0
- }
- };
+ let count = match cx.tcx.const_eval_resolve(
+ ty::ParamEnv::reveal_all(),
+ def_id,
+ substs,
+ None,
+ Some(span),
+ ) {
+ Ok(cv) => cv.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()),
+ Err(ErrorHandled::Reported) => 0,
+ Err(ErrorHandled::TooGeneric) => {
+ let span = cx.tcx.def_span(def_id);
+ cx.tcx.sess.span_err(span, "array lengths can't depend on generic parameters");
+ 0
+ }
+ };
ExprKind::Repeat { value: v.to_ref(), count }
}
use rustc::session::parse::feature_err;
use rustc::session::Session;
use rustc::ty::{self, Ty, TyCtxt};
-use rustc_error_codes::*;
use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::*;
use std::cmp::Ordering;
use std::fmt;
-use rustc_error_codes::*;
-
#[derive(Clone, Debug)]
crate enum PatternError {
AssocConstInPattern(Span),
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(bool_to_option)]
#![recursion_limit = "256"]
rustc_feature = { path = "../librustc_feature" }
rustc_lexer = { path = "../librustc_lexer" }
rustc_errors = { path = "../librustc_errors" }
-rustc_error_codes = { path = "../librustc_error_codes" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }
use crate::{parse_in, validate_attr};
use rustc_data_structures::fx::FxHashMap;
-use rustc_error_codes::*;
use rustc_errors::{error_code, struct_span_err, Applicability, Handler};
use rustc_feature::{Feature, Features, State as FeatureState};
use rustc_feature::{
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
use syntax::ast;
use syntax::print::pprust;
use super::{BlockMode, Parser, PathStyle, SemiColonMode, SeqSep, TokenExpectType, TokenType};
use rustc_data_structures::fx::FxHashSet;
-use rustc_error_codes::*;
use rustc_errors::{pluralize, struct_span_err};
use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult};
use rustc_span::source_map::Spanned;
use crate::maybe_whole;
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult, StashKey};
use rustc_span::source_map::{self, respan, Span, Spanned};
use rustc_span::symbol::{kw, sym, Symbol};
let constness = constness.map(|c| c.node);
let trait_ref = TraitRef { path, constness, ref_id: ty_first.id };
- ItemKind::Impl(
+ ItemKind::Impl {
unsafety,
polarity,
defaultness,
generics,
- Some(trait_ref),
- ty_second,
- impl_items,
- )
+ of_trait: Some(trait_ref),
+ self_ty: ty_second,
+ items: impl_items,
+ }
}
None => {
// Reject `impl const Type {}` here
}
// impl Type
- ItemKind::Impl(
+ ItemKind::Impl {
unsafety,
polarity,
defaultness,
generics,
- None,
- ty_first,
- impl_items,
- )
+ of_trait: None,
+ self_ty: ty_first,
+ items: impl_items,
+ }
}
};
use std::path::PathBuf;
use std::{cmp, mem, slice};
-use rustc_error_codes::*;
-
bitflags::bitflags! {
struct Restrictions: u8 {
const STMT_EXPR = 1 << 0;
}
pub(super) fn error_inclusive_range_with_no_end(&self, span: Span) {
- use rustc_error_codes::E0586;
struct_span_err!(self.sess.span_diagnostic, span, E0586, "inclusive range with no end")
.span_suggestion_short(
span,
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
-use rustc_error_codes::*;
use rustc_errors::{pluralize, struct_span_err, Applicability, PResult};
use rustc_span::source_map::Span;
use rustc_span::symbol::{kw, sym};
rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
-rustc_error_codes = { path = "../librustc_error_codes" }
use rustc::session::parse::feature_err;
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
}
}
}
- hir::ItemKind::Impl(.., ref opt_trait, _, impl_item_refs) => {
- for impl_item_ref in impl_item_refs {
+ hir::ItemKind::Impl { ref of_trait, items, .. } => {
+ for impl_item_ref in items {
let impl_item = self.krate.impl_item(impl_item_ref.id);
- if opt_trait.is_some()
+ if of_trait.is_some()
|| has_allow_dead_code_or_lang_attr(
self.tcx,
impl_item.hir_id,
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Trait(..)
- | hir::ItemKind::Impl(..) => {
+ | hir::ItemKind::Impl { .. } => {
// FIXME(66095): Because item.span is annotated with things
// like expansion data, and ident.span isn't, we use the
// def_span method if it's part of a macro invocation
use syntax::attr;
use syntax::entry::EntryPointType;
-use rustc_error_codes::*;
-
struct EntryContext<'a, 'tcx> {
session: &'a Session,
use rustc_span::{sym, Span};
use rustc_target::spec::abi::Abi::RustIntrinsic;
-use rustc_error_codes::*;
-
fn check_mod_intrinsics(tcx: TyCtxt<'_>, module_def_id: DefId) {
tcx.hir().visit_item_likes_in_module(module_def_id, &mut ItemVisitor { tcx }.as_deep_visitor());
}
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(in_band_lifetimes)]
#![feature(nll)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![recursion_limit = "256"]
#[macro_use]
use rustc_span::{sym, Span};
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
-use rustc_error_codes::*;
-
fn new_lib_features() -> LibFeatures {
LibFeatures { stable: Default::default(), unstable: Default::default() }
}
use Context::*;
-use rustc::session::Session;
-
use rustc::hir::map::Map;
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Destination, Movability, Node};
+use rustc_session::Session;
use rustc_span::Span;
-use rustc_error_codes::*;
-
#[derive(Clone, Copy, Debug, PartialEq)]
enum Context {
Normal,
hir::ItemKind::Fn(ref sig, ..) if sig.header.is_const() => {
return true;
}
- hir::ItemKind::Impl(..) | hir::ItemKind::Fn(..) => {
+ hir::ItemKind::Impl { .. } | hir::ItemKind::Fn(..) => {
let generics = tcx.generics_of(tcx.hir().local_def_id(item.hir_id));
generics.requires_monomorphization(tcx)
}
// does too.
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap();
match self.tcx.hir().expect_item(impl_hir_id).kind {
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
let generics = self.tcx.generics_of(impl_did);
generics.requires_monomorphization(self.tcx)
}
| hir::ItemKind::Static(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::ForeignMod(..)
- | hir::ItemKind::Impl(..)
+ | hir::ItemKind::Impl { .. }
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..)
| hir::ItemKind::Struct(..)
}
// We need only trait impls here, not inherent impls, and only non-exported ones
- if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.kind {
+ if let hir::ItemKind::Impl { of_trait: Some(ref trait_ref), ref items, .. } = item.kind {
if !self.access_levels.is_reachable(item.hir_id) {
- self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
+ self.worklist.extend(items.iter().map(|ii_ref| ii_ref.id.hir_id));
let trait_def_id = match trait_ref.path.res {
Res::Def(DefKind::Trait, def_id) => def_id,
use std::mem::replace;
use std::num::NonZeroU32;
-use rustc_error_codes::*;
-
#[derive(PartialEq)]
enum AnnotationKind {
// Annotation is required if not inherited from unstable parents
// deprecated_since and its reason.
if let Some(parent_stab) = self.parent_stab {
if parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() {
- stab.rustc_depr = parent_stab.rustc_depr.clone()
+ stab.rustc_depr = parent_stab.rustc_depr
}
}
// they don't have their own stability. They still can be annotated as unstable
// and propagate this unstability to children, but this annotation is completely
// optional. They inherit stability from their parents when unannotated.
- hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {
+ hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {
self.in_trait_impl = false;
kind = AnnotationKind::Container;
}
- hir::ItemKind::Impl(.., Some(_), _, _) => {
+ hir::ItemKind::Impl { of_trait: Some(_), .. } => {
self.in_trait_impl = true;
}
hir::ItemKind::Struct(ref sd, _) => {
// they don't have their own stability. They still can be annotated as unstable
// and propagate this unstability to children, but this annotation is completely
// optional. They inherit stability from their parents when unannotated.
- hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
+ hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {}
_ => self.check_missing_stability(i.hir_id, i.span, i.kind.descriptive_variant()),
}
// For implementations of traits, check the stability of each item
// individually as it's possible to have a stable trait with unstable
// items.
- hir::ItemKind::Impl(.., Some(ref t), _, impl_item_refs) => {
+ hir::ItemKind::Impl { of_trait: Some(ref t), items, .. } => {
if let Res::Def(DefKind::Trait, trait_did) = t.path.res {
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let trait_item_def_id = self
.tcx
rustc_metadata = { path = "../librustc_metadata" }
syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
-rustc_error_codes = { path = "../librustc_error_codes" }
use crate::Registry;
use rustc::middle::cstore::MetadataLoader;
use rustc::session::Session;
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_metadata::locator;
use rustc_span::symbol::sym;
syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
rustc_data_structures = { path = "../librustc_data_structures" }
-rustc_error_codes = { path = "../librustc_error_codes" }
log = "0.4"
use std::marker::PhantomData;
use std::{cmp, fmt, mem};
-use rustc_error_codes::*;
-
////////////////////////////////////////////////////////////////////////////////
/// Generic infrastructure used to implement specific visitors below.
////////////////////////////////////////////////////////////////////////////////
Node::ImplItem(impl_item) => {
match tcx.hir().get(tcx.hir().get_parent_item(hir_id)) {
Node::Item(item) => match &item.kind {
- hir::ItemKind::Impl(.., None, _, _) => &impl_item.vis,
- hir::ItemKind::Impl(.., Some(trait_ref), _, _) => {
+ hir::ItemKind::Impl { of_trait: None, .. } => &impl_item.vis,
+ hir::ItemKind::Impl { of_trait: Some(trait_ref), .. } => {
return def_id_visibility(tcx, trait_ref.path.res.def_id());
}
kind => bug!("unexpected item kind: {:?}", kind),
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let inherited_item_level = match item.kind {
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
Option::<AccessLevel>::of_impl(item.hir_id, self.tcx, &self.access_levels)
}
// Foreign modules inherit level from parents.
}
}
}
- hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => {
- for impl_item_ref in impl_item_refs {
- if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() {
+ hir::ItemKind::Impl { ref of_trait, items, .. } => {
+ for impl_item_ref in items {
+ if of_trait.is_some() || impl_item_ref.vis.node.is_pub() {
self.update(impl_item_ref.id.hir_id, item_level);
}
}
}
}
// Visit everything except for private impl items.
- hir::ItemKind::Impl(.., impl_item_refs) => {
+ hir::ItemKind::Impl { items, .. } => {
if item_level.is_some() {
self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref();
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
let impl_item_level = self.get(impl_item_ref.id.hir_id);
if impl_item_level.is_some() {
self.reach(impl_item_ref.id.hir_id, impl_item_level)
// (i.e., we could just return here to not check them at
// all, or some worse estimation of whether an impl is
// publicly visible).
- hir::ItemKind::Impl(.., ref g, ref trait_ref, ref self_, impl_item_refs) => {
+ hir::ItemKind::Impl { generics: ref g, ref of_trait, ref self_ty, items, .. } => {
// `impl [... for] Private` is never visible.
let self_contains_private;
// `impl [... for] Public<...>`, but not `impl [... for]
at_outer_type: true,
outer_type_is_public_path: false,
};
- visitor.visit_ty(&self_);
+ visitor.visit_ty(&self_ty);
self_contains_private = visitor.contains_private;
self_is_public_path = visitor.outer_type_is_public_path;
}
// Miscellaneous info about the impl:
// `true` iff this is `impl Private for ...`.
- let not_private_trait = trait_ref.as_ref().map_or(
+ let not_private_trait = of_trait.as_ref().map_or(
true, // no trait counts as public trait
|tr| {
let did = tr.path.res.def_id();
// directly because we might have `impl<T: Foo<Private>> ...`,
// and we shouldn't warn about the generics if all the methods
// are private (because `T` won't be visible externally).
- let trait_or_some_public_method = trait_ref.is_some()
- || impl_item_refs.iter().any(|impl_item_ref| {
+ let trait_or_some_public_method = of_trait.is_some()
+ || items.iter().any(|impl_item_ref| {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => {
if !self_contains_private && not_private_trait && trait_or_some_public_method {
intravisit::walk_generics(self, g);
- match *trait_ref {
+ match of_trait {
None => {
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
// This is where we choose whether to walk down
// further into the impl to check its items. We
// should only walk into public items so that we
}
}
}
- Some(ref tr) => {
+ Some(tr) => {
// Any private types in a trait impl fall into three
// categories.
// 1. mentioned in the trait definition
intravisit::walk_path(self, &tr.path);
// Those in 3. are warned with this call.
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
if let hir::ImplItemKind::TyAlias(ref ty) = impl_item.kind {
self.visit_ty(ty);
}
}
}
- } else if trait_ref.is_none() && self_is_public_path {
+ } else if of_trait.is_none() && self_is_public_path {
// `impl Public<Private> { ... }`. Any public static
// methods will be visible as `Public::foo`.
let mut found_pub_static = false;
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
if self.item_is_public(&impl_item_ref.id.hir_id, &impl_item_ref.vis) {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item_ref.kind {
// Subitems of inherent impls have their own publicity.
// A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity.
- hir::ItemKind::Impl(.., ref trait_ref, _, impl_item_refs) => {
+ hir::ItemKind::Impl { ref of_trait, items, .. } => {
let impl_vis = ty::Visibility::of_impl(item.hir_id, tcx, &Default::default());
self.check(item.hir_id, impl_vis).generics().predicates();
- for impl_item_ref in impl_item_refs {
+ for impl_item_ref in items {
let impl_item = tcx.hir().impl_item(impl_item_ref.id);
- let impl_item_vis = if trait_ref.is_none() {
+ let impl_item_vis = if of_trait.is_none() {
min(
ty::Visibility::from_hir(&impl_item.vis, item.hir_id, tcx),
impl_vis,
rustc_feature = { path = "../librustc_feature" }
rustc_hir = { path = "../librustc_hir" }
rustc_metadata = { path = "../librustc_metadata" }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
use rustc::middle::cstore::CrateStore;
use rustc::ty;
use rustc_data_structures::sync::Lrc;
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability};
use rustc_expand::base::SyntaxExtension;
use rustc_expand::expand::AstFragment;
}
// These items do not add names to modules.
- ItemKind::Impl(..) | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {}
+ ItemKind::Impl { .. } | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {}
ItemKind::MacroDef(..) | ItemKind::Mac(_) => unreachable!(),
}
// Pick the def data. This need not be unique, but the more
// information we encapsulate into, the better
let def_data = match &i.kind {
- ItemKind::Impl(..) => DefPathData::Impl,
+ ItemKind::Impl { .. } => DefPathData::Impl,
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
return visit::walk_item(self, i);
}
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_feature::BUILTIN_ATTRIBUTES;
use rustc_hir::def::Namespace::{self, *};
-use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
+use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::SourceMap;
use crate::imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
use crate::path_names_to_string;
-use crate::VisResolutionError;
+use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
use crate::{BindingError, CrateLint, HasGenericParams, LegacyScope, Module, ModuleOrUniformRoot};
+use crate::{NameBinding, NameBindingKind, PrivacyError, VisResolutionError};
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet, Segment};
-use rustc_error_codes::*;
-
type Res = def::Res<ast::NodeId>;
/// A vector of spans and replacements, a message and applicability.
}
false
}
+
+ fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
+ let res = b.res();
+ if b.span.is_dummy() {
+ let add_built_in = match b.res() {
+ // These already contain the "built-in" prefix or look bad with it.
+ Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod => false,
+ _ => true,
+ };
+ let (built_in, from) = if from_prelude {
+ ("", " from prelude")
+ } else if b.is_extern_crate()
+ && !b.is_import()
+ && self.session.opts.externs.get(&ident.as_str()).is_some()
+ {
+ ("", " passed with `--extern`")
+ } else if add_built_in {
+ (" built-in", "")
+ } else {
+ ("", "")
+ };
+
+ let article = if built_in.is_empty() { res.article() } else { "a" };
+ format!(
+ "{a}{built_in} {thing}{from}",
+ a = article,
+ thing = res.descr(),
+ built_in = built_in,
+ from = from
+ )
+ } else {
+ let introduced = if b.is_import() { "imported" } else { "defined" };
+ format!("the {thing} {introduced} here", thing = res.descr(), introduced = introduced)
+ }
+ }
+
+ crate fn report_ambiguity_error(&self, ambiguity_error: &AmbiguityError<'_>) {
+ let AmbiguityError { kind, ident, b1, b2, misc1, misc2 } = *ambiguity_error;
+ let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
+ // We have to print the span-less alternative first, otherwise formatting looks bad.
+ (b2, b1, misc2, misc1, true)
+ } else {
+ (b1, b2, misc1, misc2, false)
+ };
+
+ let mut err = struct_span_err!(
+ self.session,
+ ident.span,
+ E0659,
+ "`{ident}` is ambiguous ({why})",
+ ident = ident,
+ why = kind.descr()
+ );
+ err.span_label(ident.span, "ambiguous name");
+
+ let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
+ let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
+ let note_msg = format!(
+ "`{ident}` could{also} refer to {what}",
+ ident = ident,
+ also = also,
+ what = what
+ );
+
+ let thing = b.res().descr();
+ let mut help_msgs = Vec::new();
+ if b.is_glob_import()
+ && (kind == AmbiguityKind::GlobVsGlob
+ || kind == AmbiguityKind::GlobVsExpanded
+ || kind == AmbiguityKind::GlobVsOuter && swapped != also.is_empty())
+ {
+ help_msgs.push(format!(
+ "consider adding an explicit import of \
+ `{ident}` to disambiguate",
+ ident = ident
+ ))
+ }
+ if b.is_extern_crate() && ident.span.rust_2018() {
+ help_msgs.push(format!(
+ "use `::{ident}` to refer to this {thing} unambiguously",
+ ident = ident,
+ thing = thing,
+ ))
+ }
+ if misc == AmbiguityErrorMisc::SuggestCrate {
+ help_msgs.push(format!(
+ "use `crate::{ident}` to refer to this {thing} unambiguously",
+ ident = ident,
+ thing = thing,
+ ))
+ } else if misc == AmbiguityErrorMisc::SuggestSelf {
+ help_msgs.push(format!(
+ "use `self::{ident}` to refer to this {thing} unambiguously",
+ ident = ident,
+ thing = thing,
+ ))
+ }
+
+ err.span_note(b.span, ¬e_msg);
+ for (i, help_msg) in help_msgs.iter().enumerate() {
+ let or = if i == 0 { "" } else { "or " };
+ err.help(&format!("{}{}", or, help_msg));
+ }
+ };
+
+ could_refer_to(b1, misc1, "");
+ could_refer_to(b2, misc2, " also");
+ err.emit();
+ }
+
+ crate fn report_privacy_error(&self, privacy_error: &PrivacyError<'_>) {
+ let PrivacyError { ident, binding, .. } = *privacy_error;
+ let session = &self.session;
+ let mk_struct_span_error = |is_constructor| {
+ let mut descr = binding.res().descr().to_string();
+ if is_constructor {
+ descr += " constructor";
+ }
+ if binding.is_import() {
+ descr += " import";
+ }
+
+ let mut err =
+ struct_span_err!(session, ident.span, E0603, "{} `{}` is private", descr, ident);
+
+ err.span_label(ident.span, &format!("this {} is private", descr));
+ err.span_note(
+ session.source_map().def_span(binding.span),
+ &format!("the {} `{}` is defined here", descr, ident),
+ );
+
+ err
+ };
+
+ let mut err = if let NameBindingKind::Res(
+ Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id),
+ _,
+ ) = binding.kind
+ {
+ let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
+ if let Some(fields) = self.field_names.get(&def_id) {
+ let mut err = mk_struct_span_error(true);
+ let first_field = fields.first().expect("empty field list in the map");
+ err.span_label(
+ fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)),
+ "a constructor is private if any of the fields is private",
+ );
+ err
+ } else {
+ mk_struct_span_error(false)
+ }
+ } else {
+ mk_struct_span_error(false)
+ };
+
+ err.emit();
+ }
}
impl<'a, 'b> ImportResolver<'a, 'b> {
use syntax::unwrap_or;
use syntax::util::lev_distance::find_best_match_for_name;
-use rustc_error_codes::*;
-
use log::*;
use std::cell::Cell;
// Remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`
!(self.last_import_segment && binding.is_extern_crate())
{
- self.privacy_errors.push(PrivacyError(path_span, ident, binding));
+ self.privacy_errors.push(PrivacyError {
+ ident,
+ binding,
+ dedup_span: path_span,
+ });
}
Ok(binding)
use std::collections::BTreeSet;
use std::mem::replace;
-use rustc_error_codes::*;
-
mod diagnostics;
type Res = def::Res<NodeId>;
self.resolve_adt(item, generics);
}
- ItemKind::Impl(.., ref generics, ref opt_trait_ref, ref self_type, ref impl_items) => {
- self.resolve_implementation(
- generics,
- opt_trait_ref,
- &self_type,
- item.id,
- impl_items,
- )
+ ItemKind::Impl {
+ ref generics,
+ ref of_trait,
+ ref self_ty,
+ items: ref impl_items,
+ ..
+ } => {
+ self.resolve_implementation(generics, of_trait, &self_ty, item.id, impl_items);
}
ItemKind::Trait(.., ref generics, ref bounds, ref trait_items) => {
use rustc::session::config::nightly_options;
use rustc_data_structures::fx::FxHashSet;
-use rustc_error_codes::*;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, DefKind};
//!
//! Module structure of the crate is built here.
//! Paths in macros, imports, expressions, types, patterns are resolved here.
-//! Label names are resolved here as well.
+//! Label and lifetime names are resolved here as well.
//!
//! Type-relative name resolution (methods, fields, associated items) happens in `librustc_typeck`.
-//! Lifetime names are resolved in `librustc/middle/resolve_lifetime.rs`.
-
-// ignore-tidy-filelength
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_expand::base::SyntaxExtension;
use rustc_hir::def::Namespace::*;
-use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
+use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::PrimTy::{self, Bool, Char, Float, Int, Str, Uint};
use rustc_hir::{GlobMap, TraitMap};
use late::{HasGenericParams, PathSource, Rib, RibKind::*};
use macros::{LegacyBinding, LegacyScope};
-use rustc_error_codes::*;
-
type Res = def::Res<NodeId>;
mod build_reduced_graph;
}
}
-struct PrivacyError<'a>(Span, Ident, &'a NameBinding<'a>);
+struct PrivacyError<'a> {
+ ident: Ident,
+ binding: &'a NameBinding<'a>,
+ dedup_span: Span,
+}
struct UseError<'a> {
err: DiagnosticBuilder<'a>,
}
}
- fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
- let res = b.res();
- if b.span.is_dummy() {
- let add_built_in = match b.res() {
- // These already contain the "built-in" prefix or look bad with it.
- Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod => false,
- _ => true,
- };
- let (built_in, from) = if from_prelude {
- ("", " from prelude")
- } else if b.is_extern_crate()
- && !b.is_import()
- && self.session.opts.externs.get(&ident.as_str()).is_some()
- {
- ("", " passed with `--extern`")
- } else if add_built_in {
- (" built-in", "")
- } else {
- ("", "")
- };
-
- let article = if built_in.is_empty() { res.article() } else { "a" };
- format!(
- "{a}{built_in} {thing}{from}",
- a = article,
- thing = res.descr(),
- built_in = built_in,
- from = from
- )
- } else {
- let introduced = if b.is_import() { "imported" } else { "defined" };
- format!("the {thing} {introduced} here", thing = res.descr(), introduced = introduced)
- }
- }
-
- fn report_ambiguity_error(&self, ambiguity_error: &AmbiguityError<'_>) {
- let AmbiguityError { kind, ident, b1, b2, misc1, misc2 } = *ambiguity_error;
- let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
- // We have to print the span-less alternative first, otherwise formatting looks bad.
- (b2, b1, misc2, misc1, true)
- } else {
- (b1, b2, misc1, misc2, false)
- };
-
- let mut err = struct_span_err!(
- self.session,
- ident.span,
- E0659,
- "`{ident}` is ambiguous ({why})",
- ident = ident,
- why = kind.descr()
- );
- err.span_label(ident.span, "ambiguous name");
-
- let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
- let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
- let note_msg = format!(
- "`{ident}` could{also} refer to {what}",
- ident = ident,
- also = also,
- what = what
- );
-
- let thing = b.res().descr();
- let mut help_msgs = Vec::new();
- if b.is_glob_import()
- && (kind == AmbiguityKind::GlobVsGlob
- || kind == AmbiguityKind::GlobVsExpanded
- || kind == AmbiguityKind::GlobVsOuter && swapped != also.is_empty())
- {
- help_msgs.push(format!(
- "consider adding an explicit import of \
- `{ident}` to disambiguate",
- ident = ident
- ))
- }
- if b.is_extern_crate() && ident.span.rust_2018() {
- help_msgs.push(format!(
- "use `::{ident}` to refer to this {thing} unambiguously",
- ident = ident,
- thing = thing,
- ))
- }
- if misc == AmbiguityErrorMisc::SuggestCrate {
- help_msgs.push(format!(
- "use `crate::{ident}` to refer to this {thing} unambiguously",
- ident = ident,
- thing = thing,
- ))
- } else if misc == AmbiguityErrorMisc::SuggestSelf {
- help_msgs.push(format!(
- "use `self::{ident}` to refer to this {thing} unambiguously",
- ident = ident,
- thing = thing,
- ))
- }
-
- err.span_note(b.span, ¬e_msg);
- for (i, help_msg) in help_msgs.iter().enumerate() {
- let or = if i == 0 { "" } else { "or " };
- err.help(&format!("{}{}", or, help_msg));
- }
- };
-
- could_refer_to(b1, misc1, "");
- could_refer_to(b2, misc2, " also");
- err.emit();
- }
-
fn report_errors(&mut self, krate: &Crate) {
self.report_with_use_injections(krate);
}
let mut reported_spans = FxHashSet::default();
- for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors {
- if reported_spans.insert(dedup_span) {
- let session = &self.session;
- let mk_struct_span_error = |is_constructor| {
- struct_span_err!(
- session,
- ident.span,
- E0603,
- "{}{} `{}` is private",
- binding.res().descr(),
- if is_constructor { " constructor" } else { "" },
- ident.name,
- )
- };
-
- let mut err = if let NameBindingKind::Res(
- Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id),
- _,
- ) = binding.kind
- {
- let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
- if let Some(fields) = self.field_names.get(&def_id) {
- let mut err = mk_struct_span_error(true);
- let first_field = fields.first().expect("empty field list in the map");
- err.span_label(
- fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)),
- "a constructor is private if any of the fields is private",
- );
- err
- } else {
- mk_struct_span_error(false)
- }
- } else {
- mk_struct_span_error(false)
- };
-
- err.emit();
+ for error in &self.privacy_errors {
+ if reported_spans.insert(error.dedup_span) {
+ self.report_privacy_error(error);
}
}
}
use log::debug;
-use rustc_error_codes::*;
-
// This counts the no of times a lifetime is used
#[derive(Clone, Copy, Debug)]
pub enum LifetimeUseSet<'tcx> {
| hir::ItemKind::Union(_, ref generics)
| hir::ItemKind::Trait(_, _, ref generics, ..)
| hir::ItemKind::TraitAlias(ref generics, ..)
- | hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
+ | hir::ItemKind::Impl { ref generics, .. } => {
// Impls permit `'_` to be used and it is equivalent to "some fresh lifetime name".
// This is not true for other kinds of items.x
let track_lifetime_uses = match item.kind {
- hir::ItemKind::Impl(..) => true,
+ hir::ItemKind::Impl { .. } => true,
_ => false,
};
// These kinds of items have only early-bound lifetime parameters.
}
match parent.kind {
hir::ItemKind::Trait(_, _, ref generics, ..)
- | hir::ItemKind::Impl(_, _, _, ref generics, ..) => {
+ | hir::ItemKind::Impl { ref generics, .. } => {
index += generics.params.len() as u32;
}
_ => {}
}
Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(_, body), .. }) => {
- if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) =
+ if let hir::ItemKind::Impl { ref self_ty, ref items, .. } =
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
{
impl_self = Some(self_ty);
assoc_item_kind =
- impl_items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
+ items.iter().find(|ii| ii.id.hir_id == parent).map(|ii| ii.kind);
}
Some(body)
}
self.process_struct(item, def, ty_params)
}
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
- Impl(.., ref ty_params, ref trait_ref, ref typ, ref impl_items) => {
- self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
+ Impl { ref generics, ref of_trait, ref self_ty, ref items, .. } => {
+ self.process_impl(item, generics, of_trait, &self_ty, items)
}
Trait(_, _, ref generics, ref trait_refs, ref methods) => {
self.process_trait(item, generics, trait_refs, methods)
attributes: lower_attributes(item.attrs.clone(), self),
}))
}
- ast::ItemKind::Impl(.., ref trait_ref, ref typ, ref impls) => {
- if let ast::TyKind::Path(None, ref path) = typ.kind {
+ ast::ItemKind::Impl { ref of_trait, ref self_ty, ref items, .. } => {
+ if let ast::TyKind::Path(None, ref path) = self_ty.kind {
// Common case impl for a struct or something basic.
if generated_code(path.span) {
return None;
let impl_id = self.next_impl_id();
let span = self.span_from_span(sub_span);
- let type_data = self.lookup_def_id(typ.id);
+ let type_data = self.lookup_def_id(self_ty.id);
type_data.map(|type_data| {
Data::RelationData(
Relation {
kind: RelationKind::Impl { id: impl_id },
span: span.clone(),
from: id_from_def_id(type_data),
- to: trait_ref
+ to: of_trait
.as_ref()
.and_then(|t| self.lookup_def_id(t.ref_id))
.map(id_from_def_id)
},
Impl {
id: impl_id,
- kind: match *trait_ref {
+ kind: match *of_trait {
Some(_) => ImplKind::Direct,
None => ImplKind::Inherent,
},
span: span,
value: String::new(),
parent: None,
- children: impls
+ children: items
.iter()
.map(|i| id_from_node_id(i.id, self))
.collect(),
{
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
Some(Node::Item(item)) => match item.kind {
- hir::ItemKind::Impl(.., ref ty, _) => {
+ hir::ItemKind::Impl { ref self_ty, .. } => {
let mut qualname = String::from("<");
- qualname.push_str(&self.tcx.hir().hir_to_pretty_string(ty.hir_id));
+ qualname.push_str(&self.tcx.hir().hir_to_pretty_string(self_ty.hir_id));
let trait_id = self.tcx.trait_id_of_impl(impl_id);
let mut decl_id = None;
Ok(sig)
}
- ast::ItemKind::Impl(
+ ast::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
- ref opt_trait,
- ref ty,
- _,
- ) => {
+ ref of_trait,
+ ref self_ty,
+ items: _,
+ } => {
let mut text = String::new();
if let ast::Defaultness::Default = defaultness {
text.push_str("default ");
text.push(' ');
- let trait_sig = if let Some(ref t) = *opt_trait {
+ let trait_sig = if let Some(ref t) = *of_trait {
if polarity == ast::ImplPolarity::Negative {
text.push('!');
}
text_sig(String::new())
};
- let ty_sig = ty.make(offset + text.len(), id, scx)?;
+ let ty_sig = self_ty.make(offset + text.len(), id, scx)?;
text.push_str(&ty_sig.text);
text.push_str(" {}");
[dependencies]
log = "0.4"
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" }
rustc_target = { path = "../librustc_target" }
self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
parse_switch_with_opt_path, [UNTRACKED],
"run the self profiler and output the raw event data"),
+ // keep this in sync with the event filter names in librustc_data_structures/profiling.rs
self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
- "specifies which kinds of events get recorded by the self profiler"),
+ "specifies which kinds of events get recorded by the self profiler;
+ for example: `-Z self-profile-events=default,query-keys`
+ all options: none, all, default, generic-activity, query-provider, query-cache-hit
+ query-blocked, incr-cache-load, query-keys"),
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
"emits a section containing stack size metadata"),
plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{Lock, Lrc, Once};
-use rustc_error_codes::E0658;
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
use rustc_errors::{error_code, Applicability, DiagnosticBuilder};
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
lo.line != hi.line
}
- pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
- debug!("span_to_lines(sp={:?})", sp);
-
+ pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError> {
let lo = self.lookup_char_pos(sp.lo());
debug!("span_to_lines: lo={:?}", lo);
let hi = self.lookup_char_pos(sp.hi());
debug!("span_to_lines: hi={:?}", hi);
-
if lo.file.start_pos != hi.file.start_pos {
return Err(SpanLinesError::DistinctSources(DistinctSources {
begin: (lo.file.name.clone(), lo.file.start_pos),
end: (hi.file.name.clone(), hi.file.start_pos),
}));
}
+ Ok((lo, hi))
+ }
+
+ pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
+ debug!("span_to_lines(sp={:?})", sp);
+ let (lo, hi) = self.is_valid_span(sp)?;
assert!(hi.line >= lo.line);
let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
#![feature(box_syntax)]
#![feature(bool_to_option)]
#![feature(nll)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#[macro_use]
extern crate log;
&mut self,
value: &Canonical<'tcx, InEnvironment<'tcx, Goal<'tcx>>>,
) -> (Canonical<'tcx, InEnvironment<'tcx, Goal<'tcx>>>, UniverseMap) {
- (value.clone(), UniverseMap)
+ (*value, UniverseMap)
}
fn invert_goal(
},
Node::Item(item) => match item.kind {
- ItemKind::Impl(.., Some(..), _, _) => NodeKind::TraitImpl,
- ItemKind::Impl(.., None, _, _) => NodeKind::InherentImpl,
+ ItemKind::Impl { of_trait: Some(_), .. } => NodeKind::TraitImpl,
+ ItemKind::Impl { of_trait: None, .. } => NodeKind::InherentImpl,
ItemKind::Fn(..) => NodeKind::Fn,
_ => NodeKind::Other,
},
#![feature(bool_to_option)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![recursion_limit = "256"]
#[macro_use]
let parent_def_id = tcx.hir().local_def_id(parent_id);
let parent_item = tcx.hir().expect_item(parent_id);
match parent_item.kind {
- hir::ItemKind::Impl(.., ref impl_item_refs) => {
- if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) {
+ hir::ItemKind::Impl { ref items, .. } => {
+ if let Some(impl_item_ref) = items.iter().find(|i| i.id.hir_id == id) {
let assoc_item =
associated_item_from_impl_item_ref(tcx, parent_def_id, impl_item_ref);
debug_assert_eq!(assoc_item.def_id, def_id);
.map(|trait_item_ref| trait_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id)),
),
- hir::ItemKind::Impl(.., ref impl_item_refs) => tcx.arena.alloc_from_iter(
- impl_item_refs
+ hir::ItemKind::Impl { ref items, .. } => tcx.arena.alloc_from_iter(
+ items
.iter()
.map(|impl_item_ref| impl_item_ref.id)
.map(|id| tcx.hir().local_def_id(id.hir_id)),
syntax = { path = "../libsyntax" }
rustc_span = { path = "../librustc_span" }
rustc_index = { path = "../librustc_index" }
-rustc_error_codes = { path = "../librustc_error_codes" }
use std::slice;
use rustc::mir::interpret::LitToConstInput;
-use rustc_error_codes::*;
#[derive(Debug)]
pub struct PathSeg(pub DefId, pub usize);
// those that do.
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, trait_ref),
- &trait_ref.print_only_trait_path().to_string(),
+ || trait_ref.print_only_trait_path().to_string(),
binding.item_name,
path_span,
- match binding.kind {
+ || match binding.kind {
ConvertedBindingKind::Equality(ty) => Some(ty.to_string()),
_ => None,
},
predicates.iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()),
)
},
- ¶m_name.as_str(),
+ || param_name.to_string(),
assoc_name,
span,
- None,
+ || None,
)
}
fn one_bound_for_assoc_type<I>(
&self,
all_candidates: impl Fn() -> I,
- ty_param_name: &str,
+ ty_param_name: impl Fn() -> String,
assoc_name: ast::Ident,
span: Span,
- is_equality: Option<String>,
+ is_equality: impl Fn() -> Option<String>,
) -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
where
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
None => {
self.complain_about_assoc_type_not_found(
all_candidates,
- ty_param_name,
+ &ty_param_name(),
assoc_name,
span,
);
if let Some(bound2) = matching_candidates.next() {
debug!("one_bound_for_assoc_type: bound2 = {:?}", bound2);
+ let is_equality = is_equality();
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(matching_candidates);
let mut err = if is_equality.is_some() {
// More specific Error Index entry.
E0222,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
- ty_param_name
+ ty_param_name()
)
} else {
struct_span_err!(
E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
- ty_param_name
+ ty_param_name()
)
};
err.span_label(span, format!("ambiguous associated type `{}`", assoc_name));
"use fully qualified syntax to disambiguate",
format!(
"<{} as {}>::{}",
- ty_param_name,
+ ty_param_name(),
bound.print_only_trait_path(),
assoc_name,
),
} else {
err.note(&format!(
"associated type `{}` could derive from `{}`",
- ty_param_name,
+ ty_param_name(),
bound.print_only_trait_path(),
));
}
err.help(&format!(
"consider introducing a new type parameter `T` and adding `where` constraints:\
\n where\n T: {},\n{}",
- ty_param_name,
+ ty_param_name(),
where_bounds.join(",\n"),
));
}
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
- "Self",
+ || "Self".to_string(),
assoc_ident,
span,
- None,
+ || None,
)?
}
(&ty::Param(_), Res::SelfTy(Some(param_did), None))
use rustc_span::Span;
use syntax::ast::Ident;
-use rustc_error_codes::*;
-
use std::iter;
#[derive(Copy, Clone, Debug)]
use rustc::ty::subst::SubstsRef;
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::{infer, traits};
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_span::Span;
use syntax::ast;
-use rustc_error_codes::*;
-
/// Reifies a cast check to be checked once we have full type information for
/// a function context.
pub struct CastCheck<'tcx> {
}
ty::Infer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
ty::FnPtr(sig) => {
- let expected_sig = ExpectedSig { cause_span: None, sig: sig.skip_binder().clone() };
+ let expected_sig = ExpectedSig { cause_span: None, sig: *sig.skip_binder() };
(Some(expected_sig), Some(ty::ClosureKind::Fn))
}
_ => (None, None),
//! sort of a minor point so I've opted to leave it for later -- after all,
//! we may want to adjust precisely when coercions occur.
+use crate::astconv::AstConv;
use crate::check::{FnCtxt, Needs};
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc::infer::{Coercion, InferOk, InferResult};
use rustc::session::parse::feature_err;
+use rustc::traits::object_safety_violations;
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
use rustc::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast,
use rustc::ty::relate::RelateResult;
use rustc::ty::subst::SubstsRef;
use rustc::ty::{self, Ty, TypeAndMut};
-use rustc_error_codes::*;
use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
-use rustc_span;
use rustc_span::symbol::sym;
+use rustc_span::{self, Span};
use rustc_target::spec::abi::Abi;
use smallvec::{smallvec, SmallVec};
use std::ops::Deref;
};
let mut err;
+ let mut unsized_return = false;
match cause.code {
ObligationCauseCode::ReturnNoExpression => {
err = struct_span_err!(
parent_id,
expression.map(|expr| (expr, blk_id)),
);
+ if !fcx.tcx.features().unsized_locals {
+ unsized_return = self.is_return_ty_unsized(fcx, blk_id);
+ }
}
ObligationCauseCode::ReturnValue(id) => {
err = self.report_return_mismatched_types(
id,
None,
);
+ if !fcx.tcx.features().unsized_locals {
+ let id = fcx.tcx.hir().get_parent_node(id);
+ unsized_return = self.is_return_ty_unsized(fcx, id);
+ }
}
_ => {
err = fcx.report_mismatched_types(cause, expected, found, coercion_error);
.filter(|e| fcx.is_assign_to_bool(e, self.expected_ty()))
.is_some();
- err.emit_unless(assign_to_bool);
+ err.emit_unless(assign_to_bool || unsized_return);
self.final_ty = Some(fcx.tcx.types.err);
}
let mut err = fcx.report_mismatched_types(cause, expected, found, ty_err);
let mut pointing_at_return_type = false;
- let mut return_sp = None;
+ let mut fn_output = None;
// Verify that this is a tail expression of a function, otherwise the
// label pointing out the cause for the type coercion will be wrong
);
}
if !pointing_at_return_type {
- return_sp = Some(fn_decl.output.span()); // `impl Trait` return type
+ fn_output = Some(&fn_decl.output); // `impl Trait` return type
}
}
- if let (Some(sp), Some(return_sp)) = (fcx.ret_coercion_span.borrow().as_ref(), return_sp) {
- err.span_label(return_sp, "expected because this return type...");
- err.span_label( *sp, format!(
- "...is found to be `{}` here",
- fcx.resolve_vars_with_obligations(expected),
- ));
+ if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.borrow().as_ref(), fn_output) {
+ self.add_impl_trait_explanation(&mut err, fcx, expected, *sp, fn_output);
}
err
}
+ fn add_impl_trait_explanation<'a>(
+ &self,
+ err: &mut DiagnosticBuilder<'a>,
+ fcx: &FnCtxt<'a, 'tcx>,
+ expected: Ty<'tcx>,
+ sp: Span,
+ fn_output: &hir::FunctionRetTy<'_>,
+ ) {
+ let return_sp = fn_output.span();
+ err.span_label(return_sp, "expected because this return type...");
+ err.span_label(
+ sp,
+ format!("...is found to be `{}` here", fcx.resolve_vars_with_obligations(expected)),
+ );
+ let impl_trait_msg = "for information on `impl Trait`, see \
+ <https://doc.rust-lang.org/book/ch10-02-traits.html\
+ #returning-types-that-implement-traits>";
+ let trait_obj_msg = "for information on trait objects, see \
+ <https://doc.rust-lang.org/book/ch17-02-trait-objects.html\
+ #using-trait-objects-that-allow-for-values-of-different-types>";
+ err.note("to return `impl Trait`, all returned values must be of the same type");
+ err.note(impl_trait_msg);
+ let snippet = fcx
+ .tcx
+ .sess
+ .source_map()
+ .span_to_snippet(return_sp)
+ .unwrap_or_else(|_| "dyn Trait".to_string());
+ let mut snippet_iter = snippet.split_whitespace();
+ let has_impl = snippet_iter.next().map_or(false, |s| s == "impl");
+ // Only suggest `Box<dyn Trait>` if `Trait` in `impl Trait` is object safe.
+ let mut is_object_safe = false;
+ if let hir::FunctionRetTy::Return(ty) = fn_output {
+ // Get the return type.
+ if let hir::TyKind::Def(..) = ty.kind {
+ let ty = AstConv::ast_ty_to_ty(fcx, ty);
+ // Get the `impl Trait`'s `DefId`.
+ if let ty::Opaque(def_id, _) = ty.kind {
+ let hir_id = fcx.tcx.hir().as_local_hir_id(def_id).unwrap();
+ // Get the `impl Trait`'s `Item` so that we can get its trait bounds and
+ // get the `Trait`'s `DefId`.
+ if let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) =
+ fcx.tcx.hir().expect_item(hir_id).kind
+ {
+ // Are of this `impl Trait`'s traits object safe?
+ is_object_safe = bounds.iter().all(|bound| {
+ bound.trait_def_id().map_or(false, |def_id| {
+ object_safety_violations(fcx.tcx, def_id).is_empty()
+ })
+ })
+ }
+ }
+ }
+ };
+ if has_impl {
+ if is_object_safe {
+ err.help(&format!(
+ "you can instead return a boxed trait object using `Box<dyn {}>`",
+ &snippet[5..]
+ ));
+ } else {
+ err.help(&format!(
+ "if the trait `{}` were object safe, you could return a boxed trait object",
+ &snippet[5..]
+ ));
+ }
+ err.note(trait_obj_msg);
+ }
+ err.help("alternatively, create a new `enum` with a variant for each returned type");
+ }
+
+ fn is_return_ty_unsized(&self, fcx: &FnCtxt<'a, 'tcx>, blk_id: hir::HirId) -> bool {
+ if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id) {
+ if let hir::FunctionRetTy::Return(ty) = fn_decl.output {
+ let ty = AstConv::ast_ty_to_ty(fcx, ty);
+ if let ty::Dynamic(..) = ty.kind {
+ return true;
+ }
+ }
+ }
+ false
+ }
+
pub fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> {
if let Some(final_ty) = self.final_ty {
final_ty
use super::{potentially_plural_count, FnCtxt, Inherited};
-use rustc_error_codes::*;
-
/// Checks that a method from an impl conforms to the signature of
/// the same method as declared in the trait.
///
use rustc_span::Span;
-use rustc_error_codes::*;
-
/// This function confirms that the `Drop` implementation identified by
/// `drop_impl_did` is not any more specialized than the type it is
/// attached to (Issue #8142).
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;
-use rustc_error_codes::*;
-
use std::fmt::Display;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
use rustc::traits::{ObligationCause, ObligationCauseCode};
use rustc::ty::subst::Subst;
use rustc::ty::{self, Ty, TyCtxt};
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_span::symbol::Symbol;
use syntax::ast;
use syntax::util::lev_distance::{find_best_match_for_name, lev_distance};
-use rustc_error_codes::*;
-
use smallvec::{smallvec, SmallVec};
use self::CandidateKind::*;
use syntax::ast;
use syntax::util::lev_distance;
-use rustc_error_codes::*;
-
use std::cmp::Ordering;
use super::probe::Mode;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LOCAL_CRATE};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_hir::{ExprKind, GenericArg, HirIdMap, ItemKind, Node, PatKind, QPath};
+use rustc_hir::{ExprKind, GenericArg, HirIdMap, Item, ItemKind, Node, PatKind, QPath};
use rustc_index::vec::Idx;
use rustc_span::hygiene::DesugaringKind;
use rustc_span::source_map::{original_sp, DUMMY_SP};
use syntax::attr;
use syntax::util::parser::ExprPrecedence;
-use rustc_error_codes::*;
-
use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp;
use std::collections::hash_map::Entry;
check_enum(tcx, it.span, &enum_definition.variants, it.hir_id);
}
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
- hir::ItemKind::Impl(.., ref impl_item_refs) => {
+ hir::ItemKind::Impl { ref items, .. } => {
debug!("ItemKind::Impl {} with id {}", it.ident, it.hir_id);
let impl_def_id = tcx.hir().local_def_id(it.hir_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
- check_impl_items_against_trait(
- tcx,
- it.span,
- impl_def_id,
- impl_trait_ref,
- impl_item_refs,
- );
+ check_impl_items_against_trait(tcx, it.span, impl_def_id, impl_trait_ref, items);
let trait_def_id = impl_trait_ref.def_id;
check_on_unimplemented(tcx, trait_def_id, it);
}
"type has conflicting packed and align representation hints"
)
.emit();
- } else if check_packed_inner(tcx, def_id, &mut Vec::new()) {
- struct_span_err!(
- tcx.sess,
- sp,
- E0588,
- "packed type cannot transitively contain a `[repr(align)]` type"
- )
- .emit();
+ } else {
+ if let Some(def_spans) = check_packed_inner(tcx, def_id, &mut vec![]) {
+ let mut err = struct_span_err!(
+ tcx.sess,
+ sp,
+ E0588,
+ "packed type cannot transitively contain a `#[repr(align)]` type"
+ );
+
+ let hir = tcx.hir();
+ if let Some(hir_id) = hir.as_local_hir_id(def_spans[0].0) {
+ if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
+ err.span_note(
+ tcx.def_span(def_spans[0].0),
+ &format!("`{}` has a `#[repr(align)]` attribute", ident),
+ );
+ }
+ }
+
+ if def_spans.len() > 2 {
+ let mut first = true;
+ for (adt_def, span) in def_spans.iter().skip(1).rev() {
+ if let Some(hir_id) = hir.as_local_hir_id(*adt_def) {
+ if let Node::Item(Item { ident, .. }) = hir.get(hir_id) {
+ err.span_note(
+ *span,
+ &if first {
+ format!(
+ "`{}` contains a field of type `{}`",
+ tcx.type_of(def_id),
+ ident
+ )
+ } else {
+ format!("...which contains a field of type `{}`", ident)
+ },
+ );
+ first = false;
+ }
+ }
+ }
+ }
+
+ err.emit();
+ }
}
}
}
-fn check_packed_inner(tcx: TyCtxt<'_>, def_id: DefId, stack: &mut Vec<DefId>) -> bool {
- let t = tcx.type_of(def_id);
- if stack.contains(&def_id) {
- debug!("check_packed_inner: {:?} is recursive", t);
- return false;
- }
- if let ty::Adt(def, substs) = t.kind {
+fn check_packed_inner(
+ tcx: TyCtxt<'_>,
+ def_id: DefId,
+ stack: &mut Vec<DefId>,
+) -> Option<Vec<(DefId, Span)>> {
+ if let ty::Adt(def, substs) = tcx.type_of(def_id).kind {
if def.is_struct() || def.is_union() {
- if tcx.adt_def(def.did).repr.align.is_some() {
- return true;
+ if def.repr.align.is_some() {
+ return Some(vec![(def.did, DUMMY_SP)]);
}
- // push struct def_id before checking fields
+
stack.push(def_id);
for field in &def.non_enum_variant().fields {
- let f = field.ty(tcx, substs);
- if let ty::Adt(def, _) = f.kind {
- if check_packed_inner(tcx, def.did, stack) {
- return true;
+ if let ty::Adt(def, _) = field.ty(tcx, substs).kind {
+ if !stack.contains(&def.did) {
+ if let Some(mut defs) = check_packed_inner(tcx, def.did, stack) {
+ defs.push((def.did, field.ident.span));
+ return Some(defs);
+ }
}
}
}
- // only need to pop if not early out
stack.pop();
}
}
- false
+
+ None
}
/// Emit an error when encountering more or less than one variant in a transparent enum.
use rustc_span::Span;
use syntax::ast::Ident;
-use rustc_error_codes::*;
-
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Checks a `a <op>= b`
pub fn check_binop_assign(
use syntax::ast;
use syntax::util::lev_distance::find_best_match_for_name;
-use rustc_error_codes::*;
-
use std::cmp;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use rustc_hir as hir;
use rustc_hir::itemlikevisit::ParItemLikeVisitor;
-use rustc_error_codes::*;
-
/// Helper type of a temporary returned by `.for_item(...)`.
/// This is necessary because we can't write the following bound:
///
//
// won't be allowed unless there's an *explicit* implementation of `Send`
// for `T`
- hir::ItemKind::Impl(_, _, defaultness, _, ref trait_ref, ref self_ty, _) => {
+ hir::ItemKind::Impl { defaultness, ref of_trait, ref self_ty, .. } => {
let is_auto = tcx
.impl_trait_ref(tcx.hir().local_def_id(item.hir_id))
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
}
match polarity {
ty::ImplPolarity::Positive => {
- check_impl(tcx, item, self_ty, trait_ref);
+ check_impl(tcx, item, self_ty, of_trait);
}
ty::ImplPolarity::Negative => {
// FIXME(#27579): what amount of WF checking do we need for neg impls?
- if trait_ref.is_some() && !is_auto {
+ if of_trait.is_some() && !is_auto {
struct_span_err!(
tcx.sess,
item.span,
use rustc::ty::adjustment::CoerceUnsizedInfo;
use rustc::ty::TypeFoldable;
use rustc::ty::{self, Ty, TyCtxt};
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).expect("foreign Drop impl on non-ADT");
let sp = match tcx.hir().expect_item(impl_hir_id).kind {
- ItemKind::Impl(.., ty, _) => ty.span,
+ ItemKind::Impl { self_ty, .. } => self_ty.span,
_ => bug!("expected Drop impl item"),
};
Ok(()) => {}
Err(CopyImplementationError::InfrigingFields(fields)) => {
let item = tcx.hir().expect_item(impl_hir_id);
- let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.kind {
+ let span = if let ItemKind::Impl { of_trait: Some(ref tr), .. } = item.kind {
tr.path.span
} else {
span
}
Err(CopyImplementationError::NotAnAdt) => {
let item = tcx.hir().expect_item(impl_hir_id);
- let span = if let ItemKind::Impl(.., ref ty, _) = item.kind { ty.span } else { span };
+ let span =
+ if let ItemKind::Impl { self_ty, .. } = item.kind { self_ty.span } else { span };
struct_span_err!(
tcx.sess,
return err_info;
} else if diff_fields.len() > 1 {
let item = tcx.hir().expect_item(impl_hir_id);
- let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.kind {
+ let span = if let ItemKind::Impl { of_trait: Some(ref t), .. } = item.kind {
t.path.span
} else {
tcx.hir().span(impl_hir_id)
use rustc_span::Span;
use syntax::ast;
-use rustc_error_codes::*;
-
/// On-demand query: yields a map containing all types mapped to their inherent impls.
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> &CrateInherentImpls {
assert_eq!(crate_num, LOCAL_CRATE);
impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
fn visit_item(&mut self, item: &hir::Item<'_>) {
let ty = match item.kind {
- hir::ItemKind::Impl(.., None, ref ty, _) => ty,
+ hir::ItemKind::Impl { of_trait: None, ref self_ty, .. } => self_ty,
_ => return,
};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_error_codes::*;
-
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) {
assert_eq!(crate_num, LOCAL_CRATE);
let krate = tcx.hir().krate();
use rustc::traits;
use rustc::ty::query::Providers;
use rustc::ty::{self, TyCtxt, TypeFoldable};
-use rustc_error_codes::*;
use rustc_errors::struct_span_err;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::HirId;
use rustc_hir as hir;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
-use rustc_error_codes::*;
-
pub fn check(tcx: TyCtxt<'_>) {
let mut orphan = OrphanChecker { tcx };
tcx.hir().krate().visit_all_item_likes(&mut orphan);
fn visit_item(&mut self, item: &hir::Item<'_>) {
let def_id = self.tcx.hir().local_def_id(item.hir_id);
// "Trait" impl
- if let hir::ItemKind::Impl(.., generics, Some(tr), impl_ty, _) = &item.kind {
+ if let hir::ItemKind::Impl { generics, of_trait: Some(ref tr), self_ty, .. } = &item.kind {
debug!(
"coherence2::orphan check: trait impl {}",
self.tcx.hir().node_to_string(item.hir_id)
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
if *is_target_ty {
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
- err.span_label(impl_ty.span, &msg);
+ err.span_label(self_ty.span, &msg);
} else {
// Point at `C<B>` in `impl<A, B> for C<B> in D<A>`
err.span_label(tr.path.span, &msg);
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::Unsafety;
-use rustc_error_codes::*;
-
pub fn check(tcx: TyCtxt<'_>) {
let mut unsafety = UnsafetyChecker { tcx };
tcx.hir().krate().visit_all_item_likes(&mut unsafety);
impl ItemLikeVisitor<'v> for UnsafetyChecker<'tcx> {
fn visit_item(&mut self, item: &'v hir::Item<'v>) {
- if let hir::ItemKind::Impl(unsafety, polarity, _, ref generics, ..) = item.kind {
+ if let hir::ItemKind::Impl { unsafety, polarity, ref generics, .. } = item.kind {
self.check_unsafety_coherence(item, Some(generics), unsafety, polarity);
}
}
use syntax::ast::{Ident, MetaItemKind};
use syntax::attr::{list_contains_name, mark_used, InlineAttr, OptimizeAttr};
-use rustc_error_codes::*;
-
struct OnlySelfBounds(bool);
///////////////////////////////////////////////////////////////////////////
| hir::ItemKind::Enum(_, generics)
| hir::ItemKind::TraitAlias(generics, _)
| hir::ItemKind::Trait(_, _, generics, ..)
- | hir::ItemKind::Impl(_, _, _, generics, ..)
+ | hir::ItemKind::Impl { generics, .. }
| hir::ItemKind::Struct(_, generics) => (generics, true),
hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. })
| hir::ItemKind::TyAlias(_, generics) => (generics, false),
Node::Item(item) => {
match item.kind {
ItemKind::Fn(.., ref generics, _)
- | ItemKind::Impl(_, _, _, ref generics, ..)
+ | ItemKind::Impl { ref generics, .. }
| ItemKind::TyAlias(_, ref generics)
| ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. })
| ItemKind::Enum(_, ref generics)
tcx.predicates_of(def_id);
convert_enum_variant_types(tcx, def_id, &enum_definition.variants);
}
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.impl_trait_ref(def_id);
Node::Item(item) => {
match item.kind {
- ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) => {
- generics
- }
+ ItemKind::Fn(.., ref generics, _) | ItemKind::Impl { ref generics, .. } => generics,
ItemKind::TyAlias(_, ref generics)
| ItemKind::Enum(_, ref generics)
icx.to_ty(ty)
}
}
- ItemKind::TyAlias(ref ty, _) | ItemKind::Impl(.., ref ty, _) => icx.to_ty(ty),
+ ItemKind::TyAlias(ref self_ty, _) | ItemKind::Impl { ref self_ty, .. } => {
+ icx.to_ty(self_ty)
+ }
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
match tcx.hir().expect_item(hir_id).kind {
- hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
- opt_trait_ref.as_ref().map(|ast_trait_ref| {
- let selfty = tcx.type_of(def_id);
- AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
- })
- }
+ hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| {
+ let selfty = tcx.type_of(def_id);
+ AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
+ }),
_ => bug!(),
}
}
let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
let item = tcx.hir().expect_item(hir_id);
match &item.kind {
- hir::ItemKind::Impl(_, hir::ImplPolarity::Negative, ..) => {
+ hir::ItemKind::Impl { polarity: hir::ImplPolarity::Negative, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be negative");
}
ty::ImplPolarity::Negative
}
- hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, None, _, _) => {
+ hir::ItemKind::Impl { polarity: hir::ImplPolarity::Positive, of_trait: None, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be inherent");
}
ty::ImplPolarity::Positive
}
- hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, Some(_tr), _, _) => {
+ hir::ItemKind::Impl {
+ polarity: hir::ImplPolarity::Positive, of_trait: Some(_), ..
+ } => {
if is_rustc_reservation {
ty::ImplPolarity::Reservation
} else {
Node::Item(item) => {
match item.kind {
- ItemKind::Impl(_, _, defaultness, ref generics, ..) => {
+ ItemKind::Impl { defaultness, ref generics, .. } => {
if defaultness.is_default() {
is_default_impl_trait = tcx.impl_trait_ref(def_id);
}
// before uses of `U`. This avoids false ambiguity errors
// in trait checking. See `setup_constraining_predicates`
// for details.
- if let Node::Item(&Item { kind: ItemKind::Impl(..), .. }) = node {
+ if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
let self_ty = tcx.type_of(def_id);
let trait_ref = tcx.impl_trait_ref(def_id);
cgp::setup_constraining_predicates(
use rustc_span::Span;
-use rustc_error_codes::*;
-
/// Checks that all the type/lifetime parameters on an impl also
/// appear in the trait ref or self type (or are constrained by a
/// where-clause). These rules are needed to ensure that, given a
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
- if let hir::ItemKind::Impl(.., ref impl_item_refs) = item.kind {
+ if let hir::ItemKind::Impl { ref items, .. } = item.kind {
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
- enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_item_refs);
- enforce_impl_items_are_distinct(self.tcx, impl_item_refs);
+ enforce_impl_params_are_constrained(self.tcx, impl_def_id, items);
+ enforce_impl_items_are_distinct(self.tcx, items);
}
}
#![feature(exhaustive_patterns)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(try_blocks)]
#![feature(never_type)]
#![recursion_limit = "256"]
use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
-use rustc_error_codes::*;
-
use std::iter;
use astconv::{AstConv, Bounds};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_span::symbol::sym;
-use rustc_error_codes::*;
-
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
tcx.hir().krate().visit_all_item_likes(&mut OutlivesTest { tcx });
}
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use rustc_span::Span;
-use rustc_error_codes::*;
-
pub trait StructuredDiagnostic<'tcx> {
fn session(&self) -> &Session;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_span::symbol::sym;
-use rustc_error_codes::*;
-
pub fn test_variance(tcx: TyCtxt<'_>) {
tcx.hir().krate().visit_all_item_likes(&mut VarianceTest { tcx });
}
// constraint, and add it to our list. Since we make sure to never re-add
// deleted items, this process will always finish.
while !vid_map.is_empty() {
- let target = vid_map.keys().next().expect("Keys somehow empty").clone();
+ let target = *vid_map.keys().next().expect("Keys somehow empty");
let deps = vid_map.remove(&target).expect("Entry somehow missing");
for smaller in deps.smaller.iter() {
clean::Typedef {
type_: cx.tcx.type_of(did).clean(cx),
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
+ item_type: build_type_alias_type(cx, did),
+ }
+}
+
+fn build_type_alias_type(cx: &DocContext<'_>, did: DefId) -> Option<clean::Type> {
+ let type_ = cx.tcx.type_of(did).clean(cx);
+ type_.def_id().and_then(|did| build_ty(cx, did))
+}
+
+pub fn build_ty(cx: &DocContext, did: DefId) -> Option<clean::Type> {
+ match cx.tcx.def_kind(did)? {
+ DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Const | DefKind::Static => {
+ Some(cx.tcx.type_of(did).clean(cx))
+ }
+ DefKind::TyAlias => build_type_alias_type(cx, did),
+ _ => None,
}
}
let for_ = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item(hir_id).kind {
- hir::ItemKind::Impl(.., ref t, _) => t.clean(cx),
+ hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
_ => panic!("did given to build_impl was not an impl"),
}
} else {
let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item(hir_id).kind {
- hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => (
- item_ids.iter().map(|ii| tcx.hir().impl_item(ii.id).clean(cx)).collect::<Vec<_>>(),
- gen.clean(cx),
+ hir::ItemKind::Impl { ref generics, ref items, .. } => (
+ items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
+ generics.clean(cx),
),
_ => panic!("did given to build_impl was not an impl"),
}
MethodItem((sig, &self.generics, body, Some(self.defaultness)).clean(cx))
}
hir::ImplItemKind::TyAlias(ref ty) => {
- TypedefItem(Typedef { type_: ty.clean(cx), generics: Generics::default() }, true)
+ let type_ = ty.clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
+ TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
}
hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(
OpaqueTy { bounds: bounds.clean(cx), generics: Generics::default() },
AssocTypeItem(bounds, ty.clean(cx))
} else {
+ let type_ = cx.tcx.type_of(self.def_id).clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(
Typedef {
- type_: cx.tcx.type_of(self.def_id).clean(cx),
+ type_,
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
+ item_type,
},
true,
)
impl Clean<Item> for doctree::Typedef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
+ let type_ = self.ty.clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
Item {
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
visibility: self.vis.clean(cx),
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
- inner: TypedefItem(
- Typedef { type_: self.ty.clean(cx), generics: self.gen.clean(cx) },
- false,
- ),
+ inner: TypedefItem(Typedef { type_, generics: self.gen.clean(cx), item_type }, false),
}
}
}
build_deref_target_impls(cx, &items, &mut ret);
}
- let provided = trait_
+ let provided: FxHashSet<String> = trait_
.def_id()
.map(|did| {
cx.tcx
})
.unwrap_or_default();
- ret.push(Item {
+ let for_ = self.for_.clean(cx);
+ let type_alias = for_.def_id().and_then(|did| match cx.tcx.def_kind(did) {
+ Some(DefKind::TyAlias) => Some(cx.tcx.type_of(did).clean(cx)),
+ _ => None,
+ });
+ let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| Item {
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
inner: ImplItem(Impl {
unsafety: self.unsafety,
generics: self.generics.clean(cx),
- provided_trait_methods: provided,
+ provided_trait_methods: provided.clone(),
trait_,
- for_: self.for_.clean(cx),
+ for_,
items,
polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)),
synthetic: false,
blanket_impl: None,
}),
- });
+ };
+ if let Some(type_alias) = type_alias {
+ ret.push(make_item(trait_.clone(), type_alias, items.clone()));
+ }
+ ret.push(make_item(trait_, for_, items));
ret
}
}
pub struct Typedef {
pub type_: Type,
pub generics: Generics,
+ // Type of target item.
+ pub item_type: Option<Type>,
+}
+
+impl GetDefId for Typedef {
+ fn def_id(&self) -> Option<DefId> {
+ self.type_.def_id()
+ }
}
#[derive(Clone, Debug)]
let fm = sess
.source_map()
.new_source_file(FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned());
- let highlight_result = {
+ let highlight_result = rustc_driver::catch_fatal_errors(|| {
let lexer = lexer::StringReader::new(&sess, fm, None);
let mut classifier = Classifier::new(lexer, sess.source_map());
} else {
Ok(String::from_utf8_lossy(&highlighted_source).into_owned())
}
- };
+ })
+ .unwrap_or(Err(()));
match highlight_result {
Ok(highlighted_source) => {
}
_ => {}
}
- self.buf.push_back(event);
+ match event {
+ Event::Start(Tag::Link(_, _, _)) | Event::End(Tag::Link(..)) => {}
+ event => self.buf.push_back(event),
+ }
}
let id = self.id_map.derive(id);
let start_tags = format!(
"<h{level} id=\"{id}\" class=\"section-header\">\
- <a href=\"#{id}\">",
+ <a href=\"#{id}\">",
id = id,
level = level
);
deref_mut: bool,
) {
let deref_type = impl_.inner_impl().trait_.as_ref().unwrap();
- let target = impl_
+ let (target, real_target) = impl_
.inner_impl()
.items
.iter()
.filter_map(|item| match item.inner {
- clean::TypedefItem(ref t, true) => Some(&t.type_),
+ clean::TypedefItem(ref t, true) => Some(match *t {
+ clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
+ _ => (&t.type_, &t.type_),
+ }),
_ => None,
})
.next()
.expect("Expected associated type binding");
let what =
- AssocItemRender::DerefFor { trait_: deref_type, type_: target, deref_mut_: deref_mut };
+ AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut };
if let Some(did) = target.def_id() {
- render_assoc_items(w, cx, container_item, did, what)
+ render_assoc_items(w, cx, container_item, did, what);
} else {
if let Some(prim) = target.primitive_type() {
if let Some(&did) = cx.cache.primitive_locations.get(&prim) {
.filter(|i| i.inner_impl().trait_.is_some())
.find(|i| i.inner_impl().trait_.def_id() == c.deref_trait_did)
{
- if let Some(target) = impl_
+ if let Some((target, real_target)) = impl_
.inner_impl()
.items
.iter()
.filter_map(|item| match item.inner {
- clean::TypedefItem(ref t, true) => Some(&t.type_),
+ clean::TypedefItem(ref t, true) => Some(match *t {
+ clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
+ _ => (&t.type_, &t.type_),
+ }),
_ => None,
})
.next()
"{:#}",
impl_.inner_impl().trait_.as_ref().unwrap().print()
)),
- Escape(&format!("{:#}", target.print()))
+ Escape(&format!("{:#}", real_target.print()))
));
out.push_str("</a>");
let mut ret = impls
| clean::StructFieldItem(..)
| clean::VariantItem(..) => (
(
- Some(*self.parent_stack.last().unwrap()),
+ Some(*self.parent_stack.last().expect("parent_stack is empty")),
Some(&self.stack[..self.stack.len() - 1]),
),
false,
if self.parent_stack.is_empty() {
((None, None), false)
} else {
- let last = self.parent_stack.last().unwrap();
+ let last = self.parent_stack.last().expect("parent_stack is empty 2");
let did = *last;
let path = match self.paths.get(&did) {
// The current stack not necessarily has correlation
self.impls.entry(did).or_insert(vec![]).push(impl_item.clone());
}
} else {
- let trait_did = impl_item.trait_did().unwrap();
+ let trait_did = impl_item.trait_did().expect("no trait did");
self.orphan_trait_impls.push((trait_did, dids, impl_item));
}
None
});
if pushed {
- self.stack.pop().unwrap();
+ self.stack.pop().expect("stack already empty");
}
if parent_pushed {
- self.parent_stack.pop().unwrap();
+ self.parent_stack.pop().expect("parent stack already empty");
}
self.stripped_mod = orig_stripped_mod;
self.parent_is_trait_impl = orig_parent_is_trait_impl;
for item in search_index {
item.parent_idx = item.parent.map(|nodeid| {
if nodeid_to_pathid.contains_key(&nodeid) {
- *nodeid_to_pathid.get(&nodeid).unwrap()
+ *nodeid_to_pathid.get(&nodeid).expect("no pathid")
} else {
let pathid = lastpathid;
nodeid_to_pathid.insert(nodeid, pathid);
items: crate_items,
paths: crate_paths,
})
- .unwrap()
+ .expect("failed serde conversion")
)
}
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_driver;
-extern crate rustc_error_codes;
extern crate rustc_errors;
extern crate rustc_expand;
extern crate rustc_feature;
dox[code_block.code].to_owned(),
);
- let validation_status = {
+ let validation_status = rustc_driver::catch_fatal_errors(|| {
let mut has_syntax_errors = false;
let mut only_whitespace = true;
// even if there is a syntax error, we need to run the lexer over the whole file
} else {
None
}
- };
+ })
+ .unwrap_or(Some(CodeBlockInvalid::SyntaxError));
if let Some(code_block_invalid) = validation_status {
let mut diag = if let Some(sp) =
let crate_types = if options.proc_macro_crate {
vec![config::CrateType::ProcMacro]
} else {
- vec![config::CrateType::Dylib]
+ vec![config::CrateType::Rlib]
};
let sessopts = config::Options {
intravisit::walk_crate(this, krate);
});
});
+ compiler.session().abort_if_errors();
let ret: Result<_, ErrorReported> = Ok(collector.tests);
ret
})
- })
- .expect("compiler aborted in rustdoc!");
+ });
+ let tests = match tests {
+ Ok(tests) => tests,
+ Err(ErrorReported) => return 1,
+ };
test_args.insert(0, "rustdoctest".to_string());
}
fn visit_item(&mut self, item: &'hir hir::Item) {
- let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.kind {
- self.map.hir_to_pretty_string(ty.hir_id)
+ let name = if let hir::ItemKind::Impl { ref self_ty, .. } = item.kind {
+ self.map.hir_to_pretty_string(self_ty.hir_id)
} else {
item.ident.to_string()
};
om.trait_aliases.push(t);
}
- hir::ItemKind::Impl(
+ hir::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
- ref trait_,
- for_,
- ref item_ids,
- ) => {
+ ref of_trait,
+ self_ty,
+ ref items,
+ } => {
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
// them up regardless of where they're located.
- if !self.inlining && trait_.is_none() {
+ if !self.inlining && of_trait.is_none() {
let items =
- item_ids.iter().map(|ii| self.cx.tcx.hir().impl_item(ii.id)).collect();
+ items.iter().map(|item| self.cx.tcx.hir().impl_item(item.id)).collect();
let i = Impl {
unsafety,
polarity,
defaultness,
generics,
- trait_,
- for_,
+ trait_: of_trait,
+ for_: self_ty,
items,
attrs: &item.attrs,
id: item.hir_id,
#![feature(shrink_to)]
#![feature(slice_concat_ext)]
#![feature(slice_internals)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(specialization)]
#![feature(staged_api)]
#![feature(std_internals)]
///
/// | Platform | System call |
/// |:---------:|:--------------------------------------------------------------------:|
-/// | Cloud ABI | [clock_time_get (Monotonic Clock)] |
+/// | CloudABI | [clock_time_get (Monotonic Clock)] |
/// | SGX | [`insecure_time` usercall]. More information on [timekeeping in SGX] |
/// | UNIX | [clock_gettime (Monotonic Clock)] |
/// | Darwin | [mach_absolute_time] |
/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#clock_time_get
/// [clock_gettime (Monotonic Clock)]: https://linux.die.net/man/3/clock_gettime
/// [mach_absolute_time]: https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/services/services.html
-/// [clock_time_get (Monotonic Clock)]: https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt
+/// [clock_time_get (Monotonic Clock)]: https://nuxi.nl/cloudabi/#clock_time_get
///
/// **Disclaimer:** These system calls might change over time.
///
///
/// | Platform | System call |
/// |:---------:|:--------------------------------------------------------------------:|
-/// | Cloud ABI | [clock_time_get (Realtime Clock)] |
+/// | CloudABI | [clock_time_get (Realtime Clock)] |
/// | SGX | [`insecure_time` usercall]. More information on [timekeeping in SGX] |
/// | UNIX | [clock_gettime (Realtime Clock)] |
/// | DARWIN | [gettimeofday] |
/// | WASI | [__wasi_clock_time_get (Realtime Clock)] |
/// | Windows | [GetSystemTimeAsFileTime] |
///
-/// [clock_time_get (Realtime Clock)]: https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt
+/// [clock_time_get (Realtime Clock)]: https://nuxi.nl/cloudabi/#clock_time_get
/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time
/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode
/// [gettimeofday]: http://man7.org/linux/man-pages/man2/gettimeofday.2.html
rustc_lexer = { path = "../librustc_lexer" }
rustc_macros = { path = "../librustc_macros" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
-rustc_error_codes = { path = "../librustc_error_codes" }
rustc_session = { path = "../librustc_session" }
/// An implementation.
///
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
- Impl(
- Unsafety,
- ImplPolarity,
- Defaultness,
- Generics,
- Option<TraitRef>, // (optional) trait this impl implements
- P<Ty>, // self
- Vec<AssocItem>,
- ),
+ Impl {
+ unsafety: Unsafety,
+ polarity: ImplPolarity,
+ defaultness: Defaultness,
+ generics: Generics,
+
+ /// The trait being implemented, if any.
+ of_trait: Option<TraitRef>,
+
+ self_ty: P<Ty>,
+ items: Vec<AssocItem>,
+ },
/// A macro invocation.
///
/// E.g., `foo!(..)`.
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
- ItemKind::Mac(..) | ItemKind::MacroDef(..) | ItemKind::Impl(..) => "item",
+ ItemKind::Mac(..) | ItemKind::MacroDef(..) | ItemKind::Impl { .. } => "item",
}
}
}
use rustc_span::{symbol::sym, symbol::Symbol, Span};
use std::num::NonZeroU32;
-use rustc_error_codes::*;
-
pub fn is_builtin_attr(attr: &Attribute) -> bool {
attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
}
#![feature(label_break_value)]
#![feature(nll)]
#![feature(try_trait)]
-#![feature(slice_patterns)]
+#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(unicode_internals)]
#![recursion_limit = "256"]
vis.visit_variant_data(variant_data);
vis.visit_generics(generics);
}
- ItemKind::Impl(_unsafety, _polarity, _defaultness, generics, trait_ref, ty, items) => {
+ ItemKind::Impl {
+ unsafety: _,
+ polarity: _,
+ defaultness: _,
+ generics,
+ of_trait,
+ self_ty,
+ items,
+ } => {
vis.visit_generics(generics);
- visit_opt(trait_ref, |trait_ref| vis.visit_trait_ref(trait_ref));
- vis.visit_ty(ty);
+ 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(_is_auto, _unsafety, generics, bounds, items) => {
self.head(visibility_qualified(&item.vis, "union"));
self.print_struct(struct_def, generics, item.ident, item.span, true);
}
- ast::ItemKind::Impl(
+ ast::ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref generics,
- ref opt_trait,
- ref ty,
- ref impl_items,
- ) => {
+ ref of_trait,
+ ref self_ty,
+ ref items,
+ } => {
self.head("");
self.print_visibility(&item.vis);
self.print_defaultness(defaultness);
self.s.word("!");
}
- if let Some(ref t) = *opt_trait {
+ if let Some(ref t) = *of_trait {
self.print_trait_ref(t);
self.s.space();
self.word_space("for");
}
- self.print_type(ty);
+ self.print_type(self_ty);
self.print_where_clause(&generics.where_clause);
self.s.space();
self.bopen();
self.print_inner_attributes(&item.attrs);
- for impl_item in impl_items {
+ for impl_item in items {
self.print_assoc_item(impl_item);
}
self.bclose(item.span);
visitor.visit_generics(generics);
visitor.visit_enum_def(enum_definition, generics, item.id, item.span)
}
- ItemKind::Impl(_, _, _, ref generics, ref opt_trait_reference, ref typ, ref impl_items) => {
+ ItemKind::Impl {
+ unsafety: _,
+ polarity: _,
+ defaultness: _,
+ ref generics,
+ ref of_trait,
+ ref self_ty,
+ ref items,
+ } => {
visitor.visit_generics(generics);
- walk_list!(visitor, visit_trait_ref, opt_trait_reference);
- visitor.visit_ty(typ);
- walk_list!(visitor, visit_impl_item, impl_items);
+ walk_list!(visitor, visit_trait_ref, of_trait);
+ visitor.visit_ty(self_ty);
+ walk_list!(visitor, visit_impl_item, items);
}
ItemKind::Struct(ref struct_definition, ref generics)
| ItemKind::Union(ref struct_definition, ref generics) => {
// If we're being run in SpawnedSecondary mode, run the test here. run_test
// will then exit the process.
if let Ok(name) = env::var(SECONDARY_TEST_INVOKER_VAR) {
+ env::remove_var(SECONDARY_TEST_INVOKER_VAR);
let test = tests
.iter()
.filter(|test| test.desc.name.as_slice() == name)
.map(make_owned_test)
.next()
- .expect("couldn't find a test with the provided name");
+ .expect(&format!("couldn't find a test with the provided name '{}'", name));
let TestDescAndFn { desc, testfn } = test;
let testfn = match testfn {
StaticTestFn(f) => f,
}
StaticBenchFn(benchfn) => {
// Benchmarks aren't expected to panic, so we run them all in-process.
- crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
- (benchfn.clone())(harness)
- });
+ crate::bench::benchmark(desc, monitor_ch, opts.nocapture, benchfn);
}
DynTestFn(f) => {
match strategy {
-Subproject commit 9330ec5a4c1df5fc1fa62f993ed6a04da68cb040
+Subproject commit cd87134ab77e6bacb2128137065b328b9c35e0e5
#![feature(start)]
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<drop_in_place_intrinsic::StructWithDtor[0]> @@ drop_in_place_intrinsic-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<drop_in_place_intrinsic::StructWithDtor[0]> @@ drop_in_place_intrinsic-cgu.0[Internal]
struct StructWithDtor(u32);
impl Drop for StructWithDtor {
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]; 2]> @@ drop_in_place_intrinsic-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]; 2]> @@ drop_in_place_intrinsic-cgu.0[Internal]
let x = [StructWithDtor(0), StructWithDtor(1)];
drop_slice_in_place(&x);
// not have drop-glue for the unsized [StructWithDtor]. This has to be
// generated though when the drop_in_place() intrinsic is used.
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]]> @@ drop_in_place_intrinsic-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]]> @@ drop_in_place_intrinsic-cgu.0[Internal]
::std::ptr::drop_in_place(x as *const _ as *mut [StructWithDtor]);
}
}
struct NonGenericNoDrop(i32);
struct NonGenericWithDrop(i32);
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue-cgu.0[Internal]
impl Drop for NonGenericWithDrop {
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
//~ MONO_ITEM fn generic_drop_glue::start[0]
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<i8, char>
let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
// This is supposed to generate drop-glue because it contains a field that
// needs to be dropped.
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue-cgu.0[Internal]
let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<i32, i64>
let _ = match EnumWithDrop::A::<i32, i64>(0) {
EnumWithDrop::A(x) => x,
EnumWithDrop::B(x) => x as i32
};
- //~MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue-cgu.0[Internal]
+ //~MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<f64, f32>
let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
EnumWithDrop::A(x) => x,
fn start(_: isize, _: *const *const u8) -> isize {
let s1 = Struct { _a: 0u32 };
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<instantiation_through_vtable::Struct[0]<u32>> @@ instantiation_through_vtable-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u32>> @@ instantiation_through_vtable-cgu.0[Internal]
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::foo[0]<u32>
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u32>
let _ = &s1 as &Trait;
let s1 = Struct { _a: 0u64 };
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<instantiation_through_vtable::Struct[0]<u64>> @@ instantiation_through_vtable-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u64>> @@ instantiation_through_vtable-cgu.0[Internal]
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::foo[0]<u64>
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64>
let _ = &s1 as &Trait;
#![deny(dead_code)]
#![feature(start)]
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<non_generic_drop_glue::StructWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::StructWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
struct StructWithDrop {
x: i32
}
x: i32
}
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<non_generic_drop_glue::EnumWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::EnumWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
enum EnumWithDrop {
A(i32)
}
#![deny(dead_code)]
#![feature(start)]
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::Root[0]> @@ transitive_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Root[0]> @@ transitive_drop_glue-cgu.0[Internal]
struct Root(Intermediate);
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::Intermediate[0]> @@ transitive_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Intermediate[0]> @@ transitive_drop_glue-cgu.0[Internal]
struct Intermediate(Leaf);
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::Leaf[0]> @@ transitive_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Leaf[0]> @@ transitive_drop_glue-cgu.0[Internal]
struct Leaf;
impl Drop for Leaf {
fn start(_: isize, _: *const *const u8) -> isize {
let _ = Root(Intermediate(Leaf));
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::RootGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::LeafGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<u32>
let _ = RootGen(IntermediateGen(LeafGen(0u32)));
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::RootGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<transitive_drop_glue::LeafGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<i16>
let _ = RootGen(IntermediateGen(LeafGen(0i16)));
#![deny(dead_code)]
#![feature(start)]
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<tuple_drop_glue::Dropped[0]> @@ tuple_drop_glue-cgu.0[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<tuple_drop_glue::Dropped[0]> @@ tuple_drop_glue-cgu.0[Internal]
struct Dropped;
impl Drop for Dropped {
//~ MONO_ITEM fn tuple_drop_glue::start[0]
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<(u32, tuple_drop_glue::Dropped[0])> @@ tuple_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(u32, tuple_drop_glue::Dropped[0])> @@ tuple_drop_glue-cgu.0[Internal]
let x = (0u32, Dropped);
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<(i16, (tuple_drop_glue::Dropped[0], bool))> @@ tuple_drop_glue-cgu.0[Internal]
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<(tuple_drop_glue::Dropped[0], bool)> @@ tuple_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(i16, (tuple_drop_glue::Dropped[0], bool))> @@ tuple_drop_glue-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(tuple_drop_glue::Dropped[0], bool)> @@ tuple_drop_glue-cgu.0[Internal]
let x = (0i16, (Dropped, true));
0
fn start(_: isize, _: *const *const u8) -> isize {
// simple case
let bool_sized = &true;
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<bool> @@ unsizing-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<bool> @@ unsizing-cgu.0[Internal]
//~ MONO_ITEM fn unsizing::{{impl}}[0]::foo[0]
let _bool_unsized = bool_sized as &Trait;
let char_sized = &'a';
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<char> @@ unsizing-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<char> @@ unsizing-cgu.0[Internal]
//~ MONO_ITEM fn unsizing::{{impl}}[1]::foo[0]
let _char_unsized = char_sized as &Trait;
_b: 2,
_c: 3.0f64
};
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<f64> @@ unsizing-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<f64> @@ unsizing-cgu.0[Internal]
//~ MONO_ITEM fn unsizing::{{impl}}[2]::foo[0]
let _struct_unsized = struct_sized as &Struct<Trait>;
// custom coercion
let wrapper_sized = Wrapper(&0u32);
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<u32> @@ unsizing-cgu.0[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<u32> @@ unsizing-cgu.0[Internal]
//~ MONO_ITEM fn unsizing::{{impl}}[3]::foo[0]
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
// aux-build:cgu_extern_drop_glue.rs
extern crate cgu_extern_drop_glue;
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<cgu_extern_drop_glue::Struct[0]> @@ extern_drop_glue[Internal] extern_drop_glue-mod1[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<cgu_extern_drop_glue::Struct[0]> @@ extern_drop_glue[Internal] extern_drop_glue-mod1[Internal]
struct LocalStruct(cgu_extern_drop_glue::Struct);
//~ MONO_ITEM fn extern_drop_glue::user[0] @@ extern_drop_glue[External]
pub fn user()
{
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<extern_drop_glue::LocalStruct[0]> @@ extern_drop_glue[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<extern_drop_glue::LocalStruct[0]> @@ extern_drop_glue[Internal]
let _ = LocalStruct(cgu_extern_drop_glue::Struct(0));
}
//~ MONO_ITEM fn extern_drop_glue::mod1[0]::user[0] @@ extern_drop_glue-mod1[External]
pub fn user()
{
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<extern_drop_glue::mod1[0]::LocalStruct[0]> @@ extern_drop_glue-mod1[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<extern_drop_glue::mod1[0]::LocalStruct[0]> @@ extern_drop_glue-mod1[Internal]
let _ = LocalStruct(cgu_extern_drop_glue::Struct(0));
}
}
#![allow(dead_code)]
#![crate_type="rlib"]
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<local_drop_glue::Struct[0]> @@ local_drop_glue[Internal] local_drop_glue-mod1[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<local_drop_glue::Struct[0]> @@ local_drop_glue[Internal] local_drop_glue-mod1[Internal]
struct Struct {
_a: u32
}
fn drop(&mut self) {}
}
-//~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<local_drop_glue::Outer[0]> @@ local_drop_glue[Internal]
+//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<local_drop_glue::Outer[0]> @@ local_drop_glue[Internal]
struct Outer {
_a: Struct
}
{
use super::Struct;
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<local_drop_glue::mod1[0]::Struct2[0]> @@ local_drop_glue-mod1[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<local_drop_glue::mod1[0]::Struct2[0]> @@ local_drop_glue-mod1[Internal]
struct Struct2 {
_a: Struct,
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<(u32, local_drop_glue::Struct[0])> @@ local_drop_glue-mod1[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(u32, local_drop_glue::Struct[0])> @@ local_drop_glue-mod1[Internal]
_b: (u32, Struct),
}
//~ MONO_ITEM fn vtable_through_const::start[0]
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
- //~ MONO_ITEM fn core::ptr[0]::real_drop_in_place[0]<u32> @@ vtable_through_const[Internal]
+ //~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<u32> @@ vtable_through_const[Internal]
// Since Trait1::do_something() is instantiated via its default implementation,
// it is considered a generic and is instantiated here only because it is
// regular function exit. We used to have problems with quadratic growths of drop calls in such
// functions.
// FIXME(eddyb) the `void @` forces a match on the instruction, instead of the
-// comment, that's `; call core::ptr::real_drop_in_place::<drop::SomeUniqueName>`
+// comment, that's `; call core::intrinsics::drop_in_place::<drop::SomeUniqueName>`
// for the `v0` mangling, should switch to matching on that once `legacy` is gone.
// CHECK-NOT: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
fn main() {
- *(&(4, 5).1);
+ *(&(4, 5).1); // This does not currently propagate (#67862)
}
// END RUST SOURCE
// ...
// _4 = const main::promoted[0];
// _2 = &((*_4).1: i32);
-// _1 = const 5i32;
+// _1 = (*_2);
// ...
// }
// END rustc.main.ConstProp.after.mir
// }
// }
// END rustc.main-{{closure}}.EraseRegions.after.mir
-// START rustc.ptr-real_drop_in_place.Test.SimplifyCfg-make_shim.after.mir
-// fn std::ptr::real_drop_in_place(_1: &mut Test) -> () {
+// START rustc.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
+// fn std::intrinsics::drop_in_place(_1: *mut Test) -> () {
// ...
// bb0: {
// Retag([raw] _1);
// return;
// }
// }
-// END rustc.ptr-real_drop_in_place.Test.SimplifyCfg-make_shim.after.mir
+// END rustc.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
// END RUST SOURCE
-// START rustc.ptr-real_drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir
+// START rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir
// let mut _2: usize;
// let mut _3: usize;
// let mut _4: usize;
// _3 = Len((*_1));
// switchInt(move _2) -> [0usize: bb8, otherwise: bb14];
// }
-// END rustc.ptr-real_drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir
+// END rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir
#![feature(box_syntax)]
-#![feature(slice_patterns)]
fn move_out_from_end() {
let a = [box 1, box 2];
// }
// END rustc.E-V-{{constant}}.mir_map.0.mir
-// START rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
+// START rustc.ptr-drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
// bb0: {
// goto -> bb7;
// }
// _2 = &mut (*_1);
// _3 = const <std::vec::Vec<i32> as std::ops::Drop>::drop(move _2) -> [return: bb6, unwind: bb5];
// }
-// END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
+// END rustc.ptr-drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
// START rustc.Test-X-{{constructor}}.mir_map.0.mir
// fn Test::X(_1: usize) -> Test {
--- /dev/null
+-include ../../run-make-fulldeps/tools.mk
+
+# Different optimization levels imply different values for `-Zshare-generics`,
+# so try out a whole bunch of combinations to make sure everything is compatible
+all:
+ # First up, try some defaults
+ $(RUSTC) --crate-type rlib foo.rs
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=3
+
+ # Next try mixing up some things explicitly
+ $(RUSTC) --crate-type rlib foo.rs -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=no
+ $(RUSTC) --crate-type rlib foo.rs -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes
+ $(RUSTC) --crate-type rlib foo.rs -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=no
+ $(RUSTC) --crate-type rlib foo.rs -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes
+
+ # Now combine a whole bunch of options together
+ $(RUSTC) --crate-type rlib foo.rs
+ $(RUSTC) --crate-type dylib bar.rs
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=1
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=1 -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=1 -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=2
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=2 -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=2 -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=3
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=3 -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=3 -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=s
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=s -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=s -Z share-generics=yes
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=z
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=z -Z share-generics=no
+ $(RUSTC) --crate-type dylib bar.rs -C opt-level=z -Z share-generics=yes
--- /dev/null
+extern crate foo;
+
+pub fn bar() {
+ foo::foo();
+}
--- /dev/null
+pub fn foo() {
+ bar::<usize>();
+}
+
+pub fn bar<T>() {
+ baz();
+}
+
+fn baz() {}
+++ /dev/null
-# needs-sanitizer-support
-
--include ../tools.mk
-
-LOG := $(TMPDIR)/log.txt
-
-# NOTE the address sanitizer only supports x86_64 linux and macOS
-
-ifeq ($(TARGET),x86_64-apple-darwin)
-EXTRA_RUSTFLAG=-C rpath
-else
-ifeq ($(TARGET),x86_64-unknown-linux-gnu)
-
-# Apparently there are very specific Linux kernels, notably the one that's
-# currently on Travis CI, which contain a buggy commit that triggers failures in
-# the ASan implementation, detailed at google/sanitizers#837. As noted in
-# google/sanitizers#856 the "fix" is to avoid using PIE binaries, so we pass a
-# different relocation model to avoid generating a PIE binary. Once Travis is no
-# longer running kernel 4.4.0-93 we can remove this and pass an empty set of
-# flags again.
-EXTRA_RUSTFLAG=-C relocation-model=dynamic-no-pic
-endif
-endif
-
-all:
- $(RUSTC) -g -Z sanitizer=address -Z print-link-args $(EXTRA_RUSTFLAG) overflow.rs | $(CGREP) rustc_rt.asan
- # Verify that stack buffer overflow is detected:
- $(TMPDIR)/overflow 2>&1 | $(CGREP) stack-buffer-overflow
- # Verify that variable name is included in address sanitizer report:
- $(TMPDIR)/overflow 2>&1 | $(CGREP) "'xs'"
+++ /dev/null
-fn main() {
- let xs = [0, 1, 2, 3];
- let _y = unsafe { *xs.as_ptr().offset(4) };
-}
+++ /dev/null
--include ../tools.mk
-
-all:
- $(RUSTC) -Z sanitizer=leak --target i686-unknown-linux-gnu hello.rs 2>&1 | \
- $(CGREP) 'LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target'
+++ /dev/null
-#![feature(no_core)]
-#![no_core]
-#![no_main]
+++ /dev/null
--include ../tools.mk
-
-# needs-sanitizer-support
-
-all:
- $(RUSTC) -O -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan
- $(TMPDIR)/leak 2>&1 | $(CGREP) 'detected memory leaks'
+++ /dev/null
-#![feature(test)]
-
-use std::hint::black_box;
-use std::mem;
-
-fn main() {
- for _ in 0..10 {
- let xs = vec![1, 2, 3];
- // Prevent compiler from removing the memory allocation.
- let xs = black_box(xs);
- mem::forget(xs);
- }
-}
+++ /dev/null
--include ../tools.mk
-
-# needs-sanitizer-support
-# only-linux
-# only-x86_64
-
-all:
- $(RUSTC) -g -Z sanitizer=memory -Z print-link-args uninit.rs | $(CGREP) rustc_rt.msan
- $(TMPDIR)/uninit 2>&1 | $(CGREP) use-of-uninitialized-value
- $(RUSTC) -g -Z sanitizer=memory -Z print-link-args maybeuninit.rs | $(CGREP) rustc_rt.msan
- $(TMPDIR)/maybeuninit 2>&1 | $(CGREP) use-of-uninitialized-value
+++ /dev/null
-use std::mem::MaybeUninit;
-
-fn main() {
- // This is technically not sound -- but we're literally trying to test
- // that the sanitizer catches this, so I guess "intentionally unsound"?
- let xs: [u8; 4] = unsafe { MaybeUninit::uninit().assume_init() };
- let y = xs[0] + xs[1];
-}
+++ /dev/null
-fn main() {
- // This is technically not sound -- but we're literally trying to test
- // that the sanitizer catches this, so I guess "intentionally unsound"?
- #[allow(deprecated)]
- let xs: [u8; 4] = unsafe { std::mem::uninitialized() };
- let y = xs[0] + xs[1];
-}
--- /dev/null
+# This test makes sure all generic instances get re-exported from Rust dylibs for use by
+# `-Zshare-generics`. There are two rlibs (`instance_provider_a` and `instance_provider_b`)
+# which both provide an instance of `Cell<i32>::set`. There is `instance_user_dylib` which is
+# supposed to re-export both these instances, and then there are `instance_user_a_rlib` and
+# `instance_user_b_rlib` which each rely on a specific instance to be available.
+#
+# In the end everything is linked together into `linked_leaf`. If `instance_user_dylib` does
+# not export both then we'll get an `undefined reference` error for one of the instances.
+#
+# This is regression test for https://github.com/rust-lang/rust/issues/67276.
+
+-include ../../run-make-fulldeps/tools.mk
+
+COMMON_ARGS=-Cprefer-dynamic -Zshare-generics=yes -Ccodegen-units=1 -Zsymbol-mangling-version=v0
+
+all:
+ $(RUSTC) instance_provider_a.rs $(COMMON_ARGS) --crate-type=rlib
+ $(RUSTC) instance_provider_b.rs $(COMMON_ARGS) --crate-type=rlib
+ $(RUSTC) instance_user_dylib.rs $(COMMON_ARGS) --crate-type=dylib
+ $(RUSTC) instance_user_a_rlib.rs $(COMMON_ARGS) --crate-type=rlib
+ $(RUSTC) instance_user_b_rlib.rs $(COMMON_ARGS) --crate-type=rlib
+ $(RUSTC) linked_leaf.rs $(COMMON_ARGS) --crate-type=bin
--- /dev/null
+use std::cell::Cell;
+
+pub fn foo() {
+ let a: Cell<i32> = Cell::new(1);
+ a.set(123);
+}
--- /dev/null
+use std::cell::Cell;
+
+pub fn foo() {
+ let b: Cell<i32> = Cell::new(1);
+ b.set(123);
+}
--- /dev/null
+extern crate instance_provider_a as upstream;
+use std::cell::Cell;
+
+pub fn foo() {
+ upstream::foo();
+
+ let b: Cell<i32> = Cell::new(1);
+ b.set(123);
+}
--- /dev/null
+extern crate instance_provider_b as upstream;
+use std::cell::Cell;
+
+pub fn foo() {
+ upstream::foo();
+
+ let b: Cell<i32> = Cell::new(1);
+ b.set(123);
+}
--- /dev/null
+extern crate instance_provider_a;
+extern crate instance_provider_b;
+
+pub fn foo() {
+ instance_provider_a::foo();
+ instance_provider_b::foo();
+}
--- /dev/null
+extern crate instance_user_dylib;
+extern crate instance_user_a_rlib;
+extern crate instance_user_b_rlib;
+
+use std::cell::Cell;
+
+fn main() {
+
+ instance_user_a_rlib::foo();
+ instance_user_b_rlib::foo();
+ instance_user_dylib::foo();
+
+ let a: Cell<i32> = Cell::new(1);
+ a.set(123);
+}
///
pub fn indent_after_fenced() {}
//~^^^ WARNING could not parse code block as Rust code
+
+/// ```
+/// "invalid
+/// ```
+pub fn invalid() {}
+//~^^^^ WARNING could not parse code block as Rust code
|
= note: error from rustc: unknown start of token: \
+warning: could not parse code block as Rust code
+ --> $DIR/invalid-syntax.rs:97:5
+ |
+LL | /// ```
+ | _____^
+LL | | /// "invalid
+LL | | /// ```
+ | |_______^
+ |
+ = note: error from rustc: unterminated double quote string
+help: mark blocks that do not contain Rust code as text
+ |
+LL | /// ```text
+ | ^^^^^^^
+
--- /dev/null
+// compile-flags:--test
+
+/// ```
+/// assert!(true)
+/// ```
+pub fn f() {}
+
+pub fn f() {}
--- /dev/null
+error[E0428]: the name `f` is defined multiple times
+ --> $DIR/test-compile-fail1.rs:8:1
+ |
+6 | pub fn f() {}
+ | ---------- previous definition of the value `f` here
+7 |
+8 | pub fn f() {}
+ | ^^^^^^^^^^ `f` redefined here
+ |
+ = note: `f` must be defined only once in the value namespace of this module
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0428`.
--- /dev/null
+// compile-flags:--test
+
+fail
--- /dev/null
+error: expected one of `!` or `::`, found `<eof>`
+ --> $DIR/test-compile-fail2.rs:3:1
+ |
+3 | fail
+ | ^^^^ expected one of `!` or `::`
+
+error: aborting due to previous error
+
--- /dev/null
+// compile-flags:--test
+
+"fail
--- /dev/null
+error: unterminated double quote string
+ --> $DIR/test-compile-fail3.rs:3:1
+ |
+3 | "fail
+ | ^^^^^^
+
+error: aborting due to previous error
+
--- /dev/null
+// compile-flags:--test
+// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
+// build-pass
+
+#![no_std]
+
+extern crate alloc;
+
+/// ```
+/// assert!(true)
+/// ```
+pub fn f() {}
--- /dev/null
+
+running 1 test
+test $DIR/test-no_std.rs - f (line 9) ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
+
/// <script>alert("not valid Rust");</script>
/// ```
pub fn escape() {}
+
+// @has bad_codeblock_syntax/fn.unterminated.html
+// @has - '//*[@class="docblock"]/pre/code' '"unterminated'
+/// ```
+/// "unterminated
+/// ```
+pub fn unterminated() {}
--- /dev/null
+#![crate_name = "foo"]
+
+// @has 'foo/struct.Bar.html'
+// @has '-' '//*[@id="deref-methods"]' 'Methods from Deref<Target = FooC>'
+// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_a"]' 'pub fn foo_a(&self)'
+// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)'
+// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)'
+// @has '-' '//*[@class="sidebar-title"]' 'Methods from Deref<Target=FooC>'
+// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a'
+// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b'
+// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c'
+
+pub struct FooA;
+pub type FooB = FooA;
+pub type FooC = FooB;
+
+impl FooA {
+ pub fn foo_a(&self) {}
+}
+
+impl FooB {
+ pub fn foo_b(&self) {}
+}
+
+impl FooC {
+ pub fn foo_c(&self) {}
+}
+
+pub struct Bar;
+impl std::ops::Deref for Bar {
+ type Target = FooC;
+ fn deref(&self) -> &Self::Target { unimplemented!() }
+}
--- /dev/null
+#![crate_name = "foo"]
+
+// @has foo/fn.foo.html
+// !@has - '//a[@href="http://a.a"]'
+// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere'
+// @has - '//a[@href="#another-one-urg"]' 'Another one urg'
+
+/// fooo
+///
+/// # Implementing [stuff](http://a.a "title") somewhere
+///
+/// hello
+///
+/// # Another [one][two] urg
+///
+/// [two]: http://a.a
+pub fn foo() {}
--- /dev/null
+fn main() {
+ match "foo".to_string() {
+ ['f', 'o', ..] => {}
+ //~^ ERROR expected an array or slice, found `std::string::String`
+ _ => { }
+ };
+
+ // Note that this one works with default binding modes.
+ match &[0, 1, 2] {
+ [..] => {}
+ };
+
+ match &[0, 1, 2] {
+ &[..] => {} // ok
+ };
+
+ match [0, 1, 2] {
+ [0] => {}, //~ ERROR pattern requires
+
+ [0, 1, x @ ..] => {
+ let a: [_; 1] = x;
+ }
+ [0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires
+ };
+
+ match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope
+ [] => {}
+ };
+}
+
+fn another_fn_to_avoid_suppression() {
+ match Default::default()
+ {
+ [] => {} //~ ERROR type annotations needed
+ };
+}
--- /dev/null
+error[E0425]: cannot find value `does_not_exist` in this scope
+ --> $DIR/slice-pat-type-mismatches.rs:26:11
+ |
+LL | match does_not_exist {
+ | ^^^^^^^^^^^^^^ not found in this scope
+
+error[E0529]: expected an array or slice, found `std::string::String`
+ --> $DIR/slice-pat-type-mismatches.rs:3:9
+ |
+LL | ['f', 'o', ..] => {}
+ | ^^^^^^^^^^^^^^ pattern cannot match with input type `std::string::String`
+
+error[E0527]: pattern requires 1 element but array has 3
+ --> $DIR/slice-pat-type-mismatches.rs:18:9
+ |
+LL | [0] => {},
+ | ^^^ expected 3 elements
+
+error[E0528]: pattern requires at least 4 elements but array has 3
+ --> $DIR/slice-pat-type-mismatches.rs:23:9
+ |
+LL | [0, 1, 2, 3, x @ ..] => {}
+ | ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements
+
+error[E0282]: type annotations needed
+ --> $DIR/slice-pat-type-mismatches.rs:34:9
+ |
+LL | [] => {}
+ | ^^ cannot infer type
+ |
+ = note: type must be known at this point
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529.
+For more information about an error, try `rustc --explain E0282`.
--- /dev/null
+fn main() {
+ let a: &[u8] = &[];
+ match a {
+ [1, tail @ .., tail @ ..] => {},
+ //~^ ERROR identifier `tail` is bound more than once in the same pattern
+ //~| ERROR `..` can only be used once per slice pattern
+ _ => ()
+ }
+}
+
+const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
--- /dev/null
+error[E0416]: identifier `tail` is bound more than once in the same pattern
+ --> $DIR/subslice-only-once-semantic-restriction.rs:4:24
+ |
+LL | [1, tail @ .., tail @ ..] => {},
+ | ^^^^ used in a pattern more than once
+
+error: `..` can only be used once per slice pattern
+ --> $DIR/subslice-only-once-semantic-restriction.rs:4:31
+ |
+LL | [1, tail @ .., tail @ ..] => {},
+ | -- ^^ can only be used once per slice pattern
+ | |
+ | previously used here
+
+error[E0308]: mismatched types
+ --> $DIR/subslice-only-once-semantic-restriction.rs:11:30
+ |
+LL | const RECOVERY_WITNESS: () = 0;
+ | ^ expected `()`, found integer
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0308, E0416.
+For more information about an error, try `rustc --explain E0308`.
// run-pass
-#![feature(slice_patterns, const_fn, const_if_match)]
+#![feature(const_fn, const_if_match)]
#[derive(PartialEq, Debug, Clone)]
struct N(u8);
// run-pass
-#![feature(slice_patterns)]
-
#[derive(PartialEq, Debug, Clone)]
struct N(u8);
// run-pass
-#![feature(slice_patterns)]
-
#![allow(unreachable_patterns)]
use std::convert::identity;
// run-pass
-#![feature(slice_patterns)]
-
fn a() {
let x = [1, 2, 3];
match x {
// run-pass
-#![feature(slice_patterns)]
-
use std::fmt::Debug;
fn foldl<T, U, F>(values: &[T],
// run-pass
-#![allow(unused_variables)]
-#![feature(slice_patterns)]
+#![allow(unused_variables)]
pub fn main() {
let x = &[1, 2, 3, 4, 5];
// run-pass
-#![feature(slice_patterns)]
-
fn a() {
let x = [1];
match x {
// run-pass
-#![feature(slice_patterns)]
-
struct Foo {
string: &'static str
}
// edition:2018
// compile-flags: --crate-type lib
-use std::{
- cell::RefCell,
- fmt::Debug,
- rc::Rc,
-};
+use std::{cell::RefCell, fmt::Debug, rc::Rc};
-fn non_sync() -> impl Debug { RefCell::new(()) }
+fn non_sync() -> impl Debug {
+ RefCell::new(())
+}
-fn non_send() -> impl Debug { Rc::new(()) }
+fn non_send() -> impl Debug {
+ Rc::new(())
+}
fn take_ref<T>(_: &T) {}
//~^ ERROR future cannot be sent between threads safely
assert_send(non_sync_with_method_call());
//~^ ERROR future cannot be sent between threads safely
- //~^^ ERROR future cannot be sent between threads safely
}
LL | }
| - `f` is later dropped here
-error: future cannot be sent between threads safely
- --> $DIR/async-fn-nonsend.rs:54:5
- |
-LL | fn assert_send(_: impl Send) {}
- | ----------- ---- required by this bound in `assert_send`
-...
-LL | assert_send(non_sync_with_method_call());
- | ^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
- |
- = help: within `std::fmt::ArgumentV1<'_>`, the trait `std::marker::Sync` is not implemented for `*mut (dyn std::ops::Fn() + 'static)`
-note: future is not `Send` as this value is used across an await
- --> $DIR/async-fn-nonsend.rs:43:9
- |
-LL | let f: &mut std::fmt::Formatter = panic!();
- | - has type `&mut std::fmt::Formatter<'_>`
-LL | if non_sync().fmt(f).unwrap() == () {
-LL | fut().await;
- | ^^^^^^^^^^^ await occurs here, with `f` maybe used later
-LL | }
-LL | }
- | - `f` is later dropped here
-
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
error: future cannot be sent between threads safely
--> $DIR/issue-64130-4-async-move.rs:15:17
|
-LL | pub fn foo() -> impl Future + Send {
- | ^^^^^^^^^^^^^^^^^^ future returned by `foo` is not `Send`
+LL | pub fn foo() -> impl Future + Send {
+ | ^^^^^^^^^^^^^^^^^^ future returned by `foo` is not `Send`
+...
+LL | / async move {
+LL | | match client.status() {
+LL | | 200 => {
+LL | | let _x = get().await;
+... |
+LL | | }
+LL | | }
+ | |_____- this returned value is of type `impl std::future::Future`
|
= help: the trait `std::marker::Sync` is not implemented for `(dyn std::any::Any + std::marker::Send + 'static)`
note: future is not `Send` as this value is used across an await
// run-pass
+
#![feature(never_type, never_type_fallback)]
#![feature(exhaustive_patterns)]
-#![feature(slice_patterns)]
+
#![allow(unreachable_patterns)]
#![allow(unreachable_code)]
#![allow(unused_variables)]
// run-pass
-// #47096
-#![feature(slice_patterns)]
+// Regression test for #47096.
fn foo(s: &[i32]) -> &[i32] {
let &[ref xs @ ..] = s;
// run-pass
-#![feature(slice_patterns)]
fn main() {
let buf = &[0u8; 4];
// run-pass
-#![feature(slice_patterns)]
fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
match (l1, l2) {
// run-pass
-#![feature(slice_patterns)]
fn main() {
let x = [(), ()];
// Check that closure captures for slice patterns are inferred correctly
-#![feature(slice_patterns)]
#![allow(unused_variables)]
// run-pass
// Check that closure captures for slice patterns are inferred correctly
-#![feature(slice_patterns)]
-
fn arr_by_ref(mut x: [String; 3]) {
let f = || {
let [ref y, ref z @ ..] = x;
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-closures-slice-patterns.rs:9:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:7:13
|
LL | let f = || {
| -- immutable borrow occurs here
| - immutable borrow later used here
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-closures-slice-patterns.rs:18:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:16:13
|
LL | let mut f = || {
| -- mutable borrow occurs here
| - mutable borrow later used here
error[E0382]: borrow of moved value: `x`
- --> $DIR/borrowck-closures-slice-patterns.rs:27:5
+ --> $DIR/borrowck-closures-slice-patterns.rs:25:5
|
LL | fn arr_by_move(x: [String; 3]) {
| - move occurs because `x` has type `[std::string::String; 3]`, which does not implement the `Copy` trait
| ^^ value borrowed here after move
error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-closures-slice-patterns.rs:35:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:33:13
|
LL | let f = || {
| -- immutable borrow occurs here
| - immutable borrow later used here
error[E0501]: cannot borrow `x` as immutable because previous closure requires unique access
- --> $DIR/borrowck-closures-slice-patterns.rs:44:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:42:13
|
LL | let mut f = || {
| -- closure construction occurs here
| - first borrow later used here
error[E0382]: borrow of moved value: `x`
- --> $DIR/borrowck-closures-slice-patterns.rs:53:5
+ --> $DIR/borrowck-closures-slice-patterns.rs:51:5
|
LL | fn arr_box_by_move(x: Box<[String; 3]>) {
| - move occurs because `x` has type `std::boxed::Box<[std::string::String; 3]>`, which does not implement the `Copy` trait
| ^^ value borrowed here after move
error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-closures-slice-patterns.rs:61:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:59:13
|
LL | let f = || {
| -- immutable borrow occurs here
| - immutable borrow later used here
error[E0501]: cannot borrow `x` as immutable because previous closure requires unique access
- --> $DIR/borrowck-closures-slice-patterns.rs:70:13
+ --> $DIR/borrowck-closures-slice-patterns.rs:68:13
|
LL | let mut f = || {
| -- closure construction occurs here
// ignore-tidy-linelength
-#![feature(slice_patterns)]
-
pub struct Foo {
x: u32
}
error[E0499]: cannot borrow `x` as mutable more than once at a time
- --> $DIR/borrowck-describe-lvalue.rs:258:13
+ --> $DIR/borrowck-describe-lvalue.rs:256:13
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
| ------ first borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
- --> $DIR/borrowck-describe-lvalue.rs:268:20
+ --> $DIR/borrowck-describe-lvalue.rs:266:20
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
| ------ first borrow later used here
error: captured variable cannot escape `FnMut` closure body
- --> $DIR/borrowck-describe-lvalue.rs:266:16
+ --> $DIR/borrowck-describe-lvalue.rs:264:16
|
LL | || {
| - inferred to be a `FnMut` closure
= note: ...therefore, they cannot allow references to captured variables to escape
error[E0503]: cannot use `f.x` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:41:9
+ --> $DIR/borrowck-describe-lvalue.rs:39:9
|
LL | let x = f.x();
| - borrow of `f` occurs here
| - borrow later used here
error[E0503]: cannot use `g.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:48:9
+ --> $DIR/borrowck-describe-lvalue.rs:46:9
|
LL | let x = g.x();
| - borrow of `g` occurs here
| - borrow later used here
error[E0503]: cannot use `h.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:55:9
+ --> $DIR/borrowck-describe-lvalue.rs:53:9
|
LL | let x = &mut h.0;
| -------- borrow of `h.0` occurs here
| - borrow later used here
error[E0503]: cannot use `e.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:63:20
+ --> $DIR/borrowck-describe-lvalue.rs:61:20
|
LL | let x = e.x();
| - borrow of `e` occurs here
| - borrow later used here
error[E0503]: cannot use `u.a` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:71:9
+ --> $DIR/borrowck-describe-lvalue.rs:69:9
|
LL | let x = &mut u.a;
| -------- borrow of `u.a` occurs here
| - borrow later used here
error[E0503]: cannot use `f.x` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:78:9
+ --> $DIR/borrowck-describe-lvalue.rs:76:9
|
LL | let x = f.x();
| - borrow of `*f` occurs here
| - borrow later used here
error[E0503]: cannot use `g.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:85:9
+ --> $DIR/borrowck-describe-lvalue.rs:83:9
|
LL | let x = g.x();
| - borrow of `*g` occurs here
| - borrow later used here
error[E0503]: cannot use `h.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:92:9
+ --> $DIR/borrowck-describe-lvalue.rs:90:9
|
LL | let x = &mut h.0;
| -------- borrow of `h.0` occurs here
| - borrow later used here
error[E0503]: cannot use `e.0` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:100:20
+ --> $DIR/borrowck-describe-lvalue.rs:98:20
|
LL | let x = e.x();
| - borrow of `*e` occurs here
| - borrow later used here
error[E0503]: cannot use `u.a` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:109:9
+ --> $DIR/borrowck-describe-lvalue.rs:107:9
|
LL | let x = &mut u.a;
| -------- borrow of `u.a` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:117:15
+ --> $DIR/borrowck-describe-lvalue.rs:115:15
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:122:18
+ --> $DIR/borrowck-describe-lvalue.rs:120:18
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:127:25
+ --> $DIR/borrowck-describe-lvalue.rs:125:25
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:132:28
+ --> $DIR/borrowck-describe-lvalue.rs:130:28
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:143:15
+ --> $DIR/borrowck-describe-lvalue.rs:141:15
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:148:18
+ --> $DIR/borrowck-describe-lvalue.rs:146:18
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:153:15
+ --> $DIR/borrowck-describe-lvalue.rs:151:15
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[..]` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:158:18
+ --> $DIR/borrowck-describe-lvalue.rs:156:18
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `e` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:171:13
+ --> $DIR/borrowck-describe-lvalue.rs:169:13
|
LL | let x = &mut e;
| ------ borrow of `e` occurs here
| - borrow later used here
error[E0502]: cannot borrow `e.0` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:171:18
+ --> $DIR/borrowck-describe-lvalue.rs:169:18
|
LL | let x = &mut e;
| ------ mutable borrow occurs here
| - mutable borrow later used here
error[E0502]: cannot borrow `e.x` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:175:23
+ --> $DIR/borrowck-describe-lvalue.rs:173:23
|
LL | let x = &mut e;
| ------ mutable borrow occurs here
| - mutable borrow later used here
error[E0502]: cannot borrow `s.y.0` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:188:22
+ --> $DIR/borrowck-describe-lvalue.rs:186:22
|
LL | let x = &mut s;
| ------ mutable borrow occurs here
| - mutable borrow later used here
error[E0502]: cannot borrow `s.x.y` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:194:28
+ --> $DIR/borrowck-describe-lvalue.rs:192:28
|
LL | let x = &mut s;
| ------ mutable borrow occurs here
| - mutable borrow later used here
error[E0503]: cannot use `*v` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:236:9
+ --> $DIR/borrowck-describe-lvalue.rs:234:9
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0503]: cannot use `v[_].y` because it was mutably borrowed
- --> $DIR/borrowck-describe-lvalue.rs:236:9
+ --> $DIR/borrowck-describe-lvalue.rs:234:9
|
LL | let x = &mut v;
| ------ borrow of `v` occurs here
| - borrow later used here
error[E0502]: cannot borrow `v[..].x` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:247:24
+ --> $DIR/borrowck-describe-lvalue.rs:245:24
|
LL | let x = &mut v;
| ------ mutable borrow occurs here
| - mutable borrow later used here
error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:210:29
+ --> $DIR/borrowck-describe-lvalue.rs:208:29
|
LL | let x = &mut block;
| ---------- mutable borrow occurs here
| - mutable borrow later used here
error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-describe-lvalue.rs:225:33
+ --> $DIR/borrowck-describe-lvalue.rs:223:33
|
LL | let x = &mut block;
| ---------- mutable borrow occurs here
| - mutable borrow later used here
error[E0382]: use of moved value: `x`
- --> $DIR/borrowck-describe-lvalue.rs:278:22
+ --> $DIR/borrowck-describe-lvalue.rs:276:22
|
LL | drop(x);
| - value moved here
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: use of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-match.rs:15:14
+ --> $DIR/borrowck-move-out-from-array-match.rs:13:14
|
LL | [_, _, _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-match.rs:25:14
+ --> $DIR/borrowck-move-out-from-array-match.rs:23:14
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array-match.rs:35:15
+ --> $DIR/borrowck-move-out-from-array-match.rs:33:15
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-match.rs:46:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:44:11
|
LL | [_x, _, _] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-match.rs:57:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:55:11
|
LL | [.., _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-match.rs:68:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:66:11
|
LL | [(_x, _), _, _] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-match.rs:79:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:77:11
|
LL | [.., (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array-match.rs:91:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:89:11
|
LL | [_y @ .., _, _] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array-match.rs:101:15
+ --> $DIR/borrowck-move-out-from-array-match.rs:99:15
|
LL | [_, _, _y @ ..] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-match.rs:112:11
+ --> $DIR/borrowck-move-out-from-array-match.rs:110:11
|
LL | [x @ .., _] => {}
| ------ value moved here
// Once the bug is fixed, the test, which is derived from a
// passing test for `let` statements, should become check-pass.
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:19:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:17:11
|
LL | [_, _, _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:30:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:28:11
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:43:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:41:11
|
LL | [_x, _, _] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:54:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:52:11
|
LL | [.., _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:65:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:63:11
|
LL | [(_x, _), _, _] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:76:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:74:11
|
LL | [.., (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:87:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:85:11
|
LL | [_, _y @ ..] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:98:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:96:11
|
LL | [_y @ .., _] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:111:11
+ --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:109:11
|
LL | [x @ .., _, _] => {}
| ------ value moved here
// check-pass
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:15:14
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:13:14
|
LL | [_, _, _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:25:14
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:23:14
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:35:15
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:33:15
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:46:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:44:11
|
LL | [_x, _, _] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:57:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:55:11
|
LL | [.., _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:68:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:66:11
|
LL | [(_x, _), _, _] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:79:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:77:11
|
LL | [.., (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:91:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:89:11
|
LL | [_y @ .., _, _] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:101:15
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:99:15
|
LL | [_, _, _y @ ..] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:112:11
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:110:11
|
LL | [x @ .., _] => {}
| ------ value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:125:5
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:123:5
|
LL | [_, _, _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:133:5
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:131:5
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:141:5
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:139:5
|
LL | [_, _, _x @ ..] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-match.rs:149:5
+ --> $DIR/borrowck-move-out-from-array-use-match.rs:147:5
|
LL | [_, _, _x @ ..] => {}
| ------- value moved here
// Once the bug is fixed, the test, which is derived from a
// passing test for `let` statements, should become check-pass.
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:19:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:17:11
|
LL | [_, _, _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:30:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:28:11
|
LL | [_, _, (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:43:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:41:11
|
LL | [_x, _, _] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:54:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:52:11
|
LL | [.., _x] => {}
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:65:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:63:11
|
LL | [(_x, _), _, _] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:76:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:74:11
|
LL | [.., (_x, _)] => {}
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:87:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:85:11
|
LL | [_, _y @ ..] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:98:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:96:11
|
LL | [_y @ .., _] => {}
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:111:11
+ --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:109:11
|
LL | [x @ .., _, _] => {}
| ------ value moved here
// check-pass
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use.rs:12:14
+ --> $DIR/borrowck-move-out-from-array-use.rs:10:14
|
LL | let [_, _, _x] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use.rs:18:14
+ --> $DIR/borrowck-move-out-from-array-use.rs:16:14
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array-use.rs:24:15
+ --> $DIR/borrowck-move-out-from-array-use.rs:22:15
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:32:10
+ --> $DIR/borrowck-move-out-from-array-use.rs:30:10
|
LL | let [_x, _, _] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:38:16
+ --> $DIR/borrowck-move-out-from-array-use.rs:36:16
|
LL | let [.., _x] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:44:10
+ --> $DIR/borrowck-move-out-from-array-use.rs:42:10
|
LL | let [(_x, _), _, _] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:50:16
+ --> $DIR/borrowck-move-out-from-array-use.rs:48:16
|
LL | let [.., (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use.rs:56:11
+ --> $DIR/borrowck-move-out-from-array-use.rs:54:11
|
LL | let [_y @ .., _, _] = a;
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array-use.rs:62:15
+ --> $DIR/borrowck-move-out-from-array-use.rs:60:15
|
LL | let [_, _, _y @ ..] = a;
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:70:13
+ --> $DIR/borrowck-move-out-from-array-use.rs:68:13
|
LL | let [x @ .., _] = a;
| ------ value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:78:5
+ --> $DIR/borrowck-move-out-from-array-use.rs:76:5
|
LL | let [_, _, _x] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:84:5
+ --> $DIR/borrowck-move-out-from-array-use.rs:82:5
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:90:5
+ --> $DIR/borrowck-move-out-from-array-use.rs:88:5
|
LL | let [_, _, _x @ ..] = a;
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array-use.rs:96:5
+ --> $DIR/borrowck-move-out-from-array-use.rs:94:5
|
LL | let [_, _, _x @ ..] = a;
| ------- value moved here
-#![feature(slice_patterns)]
-
fn array() -> [(String, String); 3] {
Default::default()
}
error[E0382]: use of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array.rs:12:14
+ --> $DIR/borrowck-move-out-from-array.rs:10:14
|
LL | let [_, _, _x] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..]`
- --> $DIR/borrowck-move-out-from-array.rs:18:14
+ --> $DIR/borrowck-move-out-from-array.rs:16:14
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array.rs:24:15
+ --> $DIR/borrowck-move-out-from-array.rs:22:15
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array.rs:32:10
+ --> $DIR/borrowck-move-out-from-array.rs:30:10
|
LL | let [_x, _, _] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array.rs:38:16
+ --> $DIR/borrowck-move-out-from-array.rs:36:16
|
LL | let [.., _x] = a;
| -- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array.rs:44:10
+ --> $DIR/borrowck-move-out-from-array.rs:42:10
|
LL | let [(_x, _), _, _] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array.rs:50:16
+ --> $DIR/borrowck-move-out-from-array.rs:48:16
|
LL | let [.., (_x, _)] = a;
| -- value moved here
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array.rs:56:11
+ --> $DIR/borrowck-move-out-from-array.rs:54:11
|
LL | let [_y @ .., _, _] = a;
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a[..].0`
- --> $DIR/borrowck-move-out-from-array.rs:62:15
+ --> $DIR/borrowck-move-out-from-array.rs:60:15
|
LL | let [_, _, _y @ ..] = a;
| ------- value moved here
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `a`
- --> $DIR/borrowck-move-out-from-array.rs:70:13
+ --> $DIR/borrowck-move-out-from-array.rs:68:13
|
LL | let [x @ .., _] = a;
| ------ value moved here
// Test that we do not permit moves from &[] matched by a vec pattern.
-#![feature(slice_patterns)]
-
#[derive(Clone, Debug)]
struct Foo {
string: String
error[E0508]: cannot move out of type `[Foo]`, a non-copy slice
- --> $DIR/borrowck-move-out-of-vec-tail.rs:19:19
+ --> $DIR/borrowck-move-out-of-vec-tail.rs:17:19
|
LL | match tail {
| ^^^^ cannot move out of here
// check-pass
-#![feature(slice_patterns)]
-
fn nop(_s: &[& i32]) {}
fn nop_subslice(_s: &[i32]) {}
-#![feature(slice_patterns)]
-
fn nop(_s: &[& i32]) {}
fn nop_subslice(_s: &[i32]) {}
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:8:13
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:6:13
|
LL | let [ref first, ref second, ..] = *s;
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:14:14
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:12:14
|
LL | let [.., ref fourth, ref third, _, ref first] = *s;
| --------- immutable borrow occurs here
| ----- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:21:16
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:19:16
|
LL | let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s;
| ------------- immutable borrow occurs here
| --------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:23:19
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:21:19
|
LL | let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s;
| ------------- immutable borrow occurs here
| --------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:28:14
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:26:14
|
LL | let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s;
| --------------- immutable borrow occurs here
| ----------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:34:13
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:32:13
|
LL | let [ref first, ref second, ..] = *s;
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:41:10
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:39:10
|
LL | let [.., ref second, ref first] = *s;
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-array.rs:48:10
+ --> $DIR/borrowck-slice-pattern-element-loan-array.rs:46:10
|
LL | let [_, ref s1 @ ..] = *s;
| ----------- immutable borrow occurs here
// run-pass
-//compile-flags: -Z borrowck=mir
-
-#![feature(slice_patterns)]
fn mut_head_tail<'a, A>(v: &'a mut [A]) -> Option<(&'a mut A, &'a mut [A])> {
match *v {
// check-pass
-#![feature(slice_patterns)]
-
fn nop(_s: &[& i32]) {}
fn nop_subslice(_s: &[i32]) {}
-#![feature(slice_patterns)]
-
fn nop(_s: &[& i32]) {}
fn nop_subslice(_s: &[i32]) {}
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:8:20
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:6:20
|
LL | if let [ref first, ref second, ..] = *s {
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:16:21
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:14:21
|
LL | if let [.., ref fourth, ref third, _, ref first] = *s {
| --------- immutable borrow occurs here
| ----- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:24:20
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:22:20
|
LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
| ------------- immutable borrow occurs here
| --------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:27:23
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:25:23
|
LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
| ------------- immutable borrow occurs here
| --------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:30:26
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:28:26
|
LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
| ------------- immutable borrow occurs here
| --------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:35:21
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:33:21
|
LL | if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
| --------------- immutable borrow occurs here
| ----------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:38:21
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:36:21
|
LL | if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
| --------------- immutable borrow occurs here
| ----------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:41:21
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:39:21
|
LL | if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
| --------------- immutable borrow occurs here
| ----------- immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:49:20
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:47:20
|
LL | if let [ref first, ref second, ..] = *s {
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:58:17
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:56:17
|
LL | if let [.., ref second, ref first] = *s {
| ---------- immutable borrow occurs here
| ------ immutable borrow later used here
error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:67:17
+ --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:65:17
|
LL | if let [_, _, _, ref s1 @ ..] = *s {
| ----------- immutable borrow occurs here
-#![feature(slice_patterns)]
-
fn a<'a>() -> &'a [isize] {
let vec = vec![1, 2, 3, 4];
let vec: &[isize] = &vec;
error[E0515]: cannot return value referencing local variable `vec`
- --> $DIR/borrowck-vec-pattern-element-loan.rs:10:5
+ --> $DIR/borrowck-vec-pattern-element-loan.rs:8:5
|
LL | let vec: &[isize] = &vec;
| ---- `vec` is borrowed here
| ^^^^ returns a value referencing data owned by the current function
error[E0515]: cannot return value referencing local variable `vec`
- --> $DIR/borrowck-vec-pattern-element-loan.rs:20:5
+ --> $DIR/borrowck-vec-pattern-element-loan.rs:18:5
|
LL | let vec: &[isize] = &vec;
| ---- `vec` is borrowed here
| ^^^^ returns a value referencing data owned by the current function
error[E0515]: cannot return value referencing local variable `vec`
- --> $DIR/borrowck-vec-pattern-element-loan.rs:30:5
+ --> $DIR/borrowck-vec-pattern-element-loan.rs:28:5
|
LL | let vec: &[isize] = &vec;
| ---- `vec` is borrowed here
-#![feature(slice_patterns)]
-
fn a() {
let mut v = vec![1, 2, 3];
let vb: &mut [isize] = &mut v;
error[E0499]: cannot borrow `v` as mutable more than once at a time
- --> $DIR/borrowck-vec-pattern-loan-from-mut.rs:8:13
+ --> $DIR/borrowck-vec-pattern-loan-from-mut.rs:6:13
|
LL | let vb: &mut [isize] = &mut v;
| ------ first mutable borrow occurs here
-// http://rust-lang.org/COPYRIGHT.
-
-#![feature(slice_patterns)]
-
fn main() {
let mut a = [1, 2, 3, 4];
let t = match a {
error[E0506]: cannot assign to `a[_]` because it is borrowed
- --> $DIR/borrowck-vec-pattern-move-tail.rs:12:5
+ --> $DIR/borrowck-vec-pattern-move-tail.rs:8:5
|
LL | [1, 2, ref tail @ ..] => tail,
| ------------- borrow of `a[_]` occurs here
#![feature(box_patterns)]
#![feature(box_syntax)]
-#![feature(slice_patterns)]
fn a() {
let mut vec = [box 1, box 2, box 3];
error[E0506]: cannot assign to `vec[_]` because it is borrowed
- --> $DIR/borrowck-vec-pattern-nesting.rs:10:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:9:13
|
LL | [box ref _a, _, _] => {
| ------ borrow of `vec[_]` occurs here
| -- borrow later used here
error[E0506]: cannot assign to `vec[_]` because it is borrowed
- --> $DIR/borrowck-vec-pattern-nesting.rs:24:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:23:13
|
LL | &mut [ref _b @ ..] => {
| ----------- borrow of `vec[_]` occurs here
| -- borrow later used here
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:35:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:34:11
|
LL | match vec {
| ^^^ cannot move out of here
|
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:47:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:46:13
|
LL | let a = vec[0];
| ^^^^^^
| help: consider borrowing here: `&vec[0]`
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:56:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:55:11
|
LL | match vec {
| ^^^ cannot move out of here
|
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:66:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:65:13
|
LL | let a = vec[0];
| ^^^^^^
| help: consider borrowing here: `&vec[0]`
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:75:11
+ --> $DIR/borrowck-vec-pattern-nesting.rs:74:11
|
LL | match vec {
| ^^^ cannot move out of here
= note: move occurs because these variables have types that don't implement the `Copy` trait
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
- --> $DIR/borrowck-vec-pattern-nesting.rs:86:13
+ --> $DIR/borrowck-vec-pattern-nesting.rs:85:13
|
LL | let a = vec[0];
| ^^^^^^
-#![feature(slice_patterns)]
-
fn a<'a>() -> &'a isize {
let vec = vec![1, 2, 3, 4];
let vec: &[isize] = &vec;
error[E0515]: cannot return value referencing local variable `vec`
- --> $DIR/borrowck-vec-pattern-tail-element-loan.rs:10:5
+ --> $DIR/borrowck-vec-pattern-tail-element-loan.rs:8:5
|
LL | let vec: &[isize] = &vec;
| ---- `vec` is borrowed here
--> $DIR/variadic-ffi-4.rs:24:11
|
LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) {
- | - let's call the lifetime of this reference `'1`
+ | - let's call the lifetime of this reference `'3`
LL | ap0 = &mut ap1;
| ------^^^^^^^^
| | |
| | borrowed value does not live long enough
- | assignment requires that `ap1` is borrowed for `'1`
+ | assignment requires that `ap1` is borrowed for `'3`
...
LL | }
| - `ap1` dropped here while still borrowed
--> $DIR/coerce-expect-unsized-ascribed.rs:13:13
|
LL | let _ = box { |x| (x as u8) }: Box<dyn Fn(i32) -> _>;
- | ^^^^^^^^^^^^^^^^^^^^^ expected trait `std::ops::Fn`, found closure
+ | ^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::ops::Fn`, found closure
|
= note: expected struct `std::boxed::Box<dyn std::ops::Fn(i32) -> u8>`
found struct `std::boxed::Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:13:19: 13:32]>`
--> $DIR/coerce-expect-unsized-ascribed.rs:14:13
|
LL | let _ = box if true { false } else { true }: Box<dyn Debug>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::fmt::Debug`, found `bool`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::fmt::Debug`, found `bool`
|
= note: expected struct `std::boxed::Box<dyn std::fmt::Debug>`
found struct `std::boxed::Box<bool>`
--> $DIR/coerce-expect-unsized-ascribed.rs:15:13
|
LL | let _ = box match true { true => 'a', false => 'b' }: Box<dyn Debug>;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::fmt::Debug`, found `char`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::fmt::Debug`, found `char`
|
= note: expected struct `std::boxed::Box<dyn std::fmt::Debug>`
found struct `std::boxed::Box<char>`
--> $DIR/coerce-expect-unsized-ascribed.rs:21:13
|
LL | let _ = &{ |x| (x as u8) }: &dyn Fn(i32) -> _;
- | ^^^^^^^^^^^^^^^^^^ expected trait `std::ops::Fn`, found closure
+ | ^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::ops::Fn`, found closure
|
= note: expected reference `&dyn std::ops::Fn(i32) -> u8`
found reference `&[closure@$DIR/coerce-expect-unsized-ascribed.rs:21:16: 21:29]`
--> $DIR/coerce-expect-unsized-ascribed.rs:22:13
|
LL | let _ = &if true { false } else { true }: &dyn Debug;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::fmt::Debug`, found `bool`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::fmt::Debug`, found `bool`
|
= note: expected reference `&dyn std::fmt::Debug`
found reference `&bool`
--> $DIR/coerce-expect-unsized-ascribed.rs:23:13
|
LL | let _ = &match true { true => 'a', false => 'b' }: &dyn Debug;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::fmt::Debug`, found `char`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::fmt::Debug`, found `char`
|
= note: expected reference `&dyn std::fmt::Debug`
found reference `&char`
--> $DIR/coerce-expect-unsized-ascribed.rs:26:13
|
LL | let _ = Box::new(|x| (x as u8)): Box<dyn Fn(i32) -> _>;
- | ^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::ops::Fn`, found closure
+ | ^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn std::ops::Fn`, found closure
|
= note: expected struct `std::boxed::Box<dyn std::ops::Fn(i32) -> _>`
found struct `std::boxed::Box<[closure@$DIR/coerce-expect-unsized-ascribed.rs:26:22: 26:35]>`
|
LL | pub fn no_vec_partial_eq_array<A, B>() -> impl PartialEq<[B; 33]>
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[B; 33]`
+...
+LL | Vec::<A>::new()
+ | --------------- this returned value is of type `std::vec::Vec<A>`
|
= note: required because of the requirements on the impl of `std::cmp::PartialEq<[B; 33]>` for `std::vec::Vec<A>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_vec_partial_eq_ref_array<'a, A, B>() -> impl PartialEq<&'a [B; 33]>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[B; 33]`
+...
+LL | Vec::<A>::new()
+ | --------------- this returned value is of type `std::vec::Vec<A>`
|
= note: required because of the requirements on the impl of `std::cmp::PartialEq<&'a [B; 33]>` for `std::vec::Vec<A>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_vecdeque_partial_eq_array<A, B>() -> impl PartialEq<[B; 33]>
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[B; 33]`
+...
+LL | VecDeque::<A>::new()
+ | -------------------- this returned value is of type `std::collections::VecDeque<A>`
|
= note: required because of the requirements on the impl of `std::cmp::PartialEq<[B; 33]>` for `std::collections::VecDeque<A>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_vecdeque_partial_eq_ref_array<'a, A, B>() -> impl PartialEq<&'a [B; 33]>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[B; 33]`
+...
+LL | VecDeque::<A>::new()
+ | -------------------- this returned value is of type `std::collections::VecDeque<A>`
|
= note: required because of the requirements on the impl of `std::cmp::PartialEq<&'a [B; 33]>` for `std::collections::VecDeque<A>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_vecdeque_partial_eq_ref_mut_array<'a, A, B>() -> impl PartialEq<&'a mut [B; 33]>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[B; 33]`
+...
+LL | VecDeque::<A>::new()
+ | -------------------- this returned value is of type `std::collections::VecDeque<A>`
|
= note: required because of the requirements on the impl of `std::cmp::PartialEq<&'a mut [B; 33]>` for `std::collections::VecDeque<A>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_iterator() -> impl Iterator<Item = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_double_ended_iterator() -> impl DoubleEndedIterator {
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::iter::DoubleEndedIterator` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_exact_size_iterator() -> impl ExactSizeIterator {
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::iter::ExactSizeIterator` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_fused_iterator() -> impl FusedIterator {
| ^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::iter::FusedIterator` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_trusted_len() -> impl TrustedLen {
| ^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::iter::TrustedLen` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_clone() -> impl Clone {
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
|
LL | pub fn no_debug() -> impl Debug {
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
+LL |
+LL | IntoIter::new([0i32; 33])
+ | ------------------------- this returned value is of type `std::array::IntoIter<i32, 33usize>`
|
= note: required because of the requirements on the impl of `std::fmt::Debug` for `std::array::IntoIter<i32, 33usize>`
= note: the return type of a function must have a statically known size
--- /dev/null
+// check-pass
+
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+fn takes_closure_of_array_3<F>(f: F) where F: Fn([i32; 3]) {
+ f([1, 2, 3]);
+}
+
+fn takes_closure_of_array_3_apit(f: impl Fn([i32; 3])) {
+ f([1, 2, 3]);
+}
+
+fn returns_closure_of_array_3() -> impl Fn([i32; 3]) {
+ |_| {}
+}
+
+fn main() {}
--- /dev/null
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+ --> $DIR/integer-literal-generic-arg-in-where-clause.rs:3:12
+ |
+LL | #![feature(const_generics)]
+ | ^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(incomplete_features)]` on by default
+
// build-pass
+// ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors)
#![warn(const_err)]
warning: index out of bounds: the len is 3 but the index is 4
- --> $DIR/array-literal-index-oob.rs:6:8
+ --> $DIR/array-literal-index-oob.rs:7:8
|
LL | &{ [1, 2, 3][4] };
| ^^^^^^^^^^^^
|
note: lint level defined here
- --> $DIR/array-literal-index-oob.rs:3:9
+ --> $DIR/array-literal-index-oob.rs:4:9
|
LL | #![warn(const_err)]
| ^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
- --> $DIR/array-literal-index-oob.rs:6:8
+ --> $DIR/array-literal-index-oob.rs:7:8
|
LL | &{ [1, 2, 3][4] };
| ---^^^^^^^^^^^^--
| indexing out of bounds: the len is 3 but the index is 4
warning: erroneous constant used
- --> $DIR/array-literal-index-oob.rs:6:5
+ --> $DIR/array-literal-index-oob.rs:7:5
|
LL | &{ [1, 2, 3][4] };
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
--- /dev/null
+// check-pass
+
+trait TraitA {
+ const VALUE: usize;
+}
+
+struct A;
+impl TraitA for A {
+ const VALUE: usize = 1;
+}
+
+trait TraitB {
+ type MyA: TraitA;
+ const VALUE: usize = Self::MyA::VALUE;
+}
+
+struct B;
+impl TraitB for B {
+ type MyA = A;
+}
+
+fn main() {
+ let _ = [0; A::VALUE];
+ let _ = [0; B::VALUE]; // Indirectly refers to `A::VALUE`
+}
// build-pass
+// ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors)
// compile-flags: -O
#![warn(const_err)]
warning: this expression will panic at runtime
- --> $DIR/promoted_errors.rs:8:14
+ --> $DIR/promoted_errors.rs:9:14
|
LL | let _x = 0u32 - 1;
| ^^^^^^^^ attempt to subtract with overflow
|
note: lint level defined here
- --> $DIR/promoted_errors.rs:4:9
+ --> $DIR/promoted_errors.rs:5:9
|
LL | #![warn(const_err)]
| ^^^^^^^^^
warning: attempt to divide by zero
- --> $DIR/promoted_errors.rs:10:20
+ --> $DIR/promoted_errors.rs:11:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
- --> $DIR/promoted_errors.rs:10:20
+ --> $DIR/promoted_errors.rs:11:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^ dividing by zero
warning: erroneous constant used
- --> $DIR/promoted_errors.rs:10:20
+ --> $DIR/promoted_errors.rs:11:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^ referenced constant has errors
warning: attempt to divide by zero
- --> $DIR/promoted_errors.rs:14:14
+ --> $DIR/promoted_errors.rs:15:14
|
LL | let _x = 1 / (1 - 1);
| ^^^^^^^^^^^
warning: attempt to divide by zero
- --> $DIR/promoted_errors.rs:16:20
+ --> $DIR/promoted_errors.rs:17:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
- --> $DIR/promoted_errors.rs:16:20
+ --> $DIR/promoted_errors.rs:17:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^ dividing by zero
warning: erroneous constant used
- --> $DIR/promoted_errors.rs:16:20
+ --> $DIR/promoted_errors.rs:17:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^ referenced constant has errors
warning: attempt to divide by zero
- --> $DIR/promoted_errors.rs:20:14
+ --> $DIR/promoted_errors.rs:21:14
|
LL | let _x = 1 / (false as u32);
| ^^^^^^^^^^^^^^^^^^
// build-pass
+// ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors)
// compile-flags: -C overflow-checks=on -O
#![warn(const_err)]
warning: attempt to subtract with overflow
- --> $DIR/promoted_errors2.rs:7:20
+ --> $DIR/promoted_errors2.rs:8:20
|
LL | println!("{}", 0u32 - 1);
| ^^^^^^^^
|
note: lint level defined here
- --> $DIR/promoted_errors2.rs:4:9
+ --> $DIR/promoted_errors2.rs:5:9
|
LL | #![warn(const_err)]
| ^^^^^^^^^
warning: attempt to subtract with overflow
- --> $DIR/promoted_errors2.rs:9:14
+ --> $DIR/promoted_errors2.rs:10:14
|
LL | let _x = 0u32 - 1;
| ^^^^^^^^
warning: attempt to divide by zero
- --> $DIR/promoted_errors2.rs:11:20
+ --> $DIR/promoted_errors2.rs:12:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
- --> $DIR/promoted_errors2.rs:11:20
+ --> $DIR/promoted_errors2.rs:12:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^ dividing by zero
warning: erroneous constant used
- --> $DIR/promoted_errors2.rs:11:20
+ --> $DIR/promoted_errors2.rs:12:20
|
LL | println!("{}", 1 / (1 - 1));
| ^^^^^^^^^^^ referenced constant has errors
warning: attempt to divide by zero
- --> $DIR/promoted_errors2.rs:15:14
+ --> $DIR/promoted_errors2.rs:16:14
|
LL | let _x = 1 / (1 - 1);
| ^^^^^^^^^^^
warning: attempt to divide by zero
- --> $DIR/promoted_errors2.rs:17:20
+ --> $DIR/promoted_errors2.rs:18:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^
warning: reaching this expression at runtime will panic or abort
- --> $DIR/promoted_errors2.rs:17:20
+ --> $DIR/promoted_errors2.rs:18:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^ dividing by zero
warning: erroneous constant used
- --> $DIR/promoted_errors2.rs:17:20
+ --> $DIR/promoted_errors2.rs:18:20
|
LL | println!("{}", 1 / (false as u32));
| ^^^^^^^^^^^^^^^^^^ referenced constant has errors
warning: attempt to divide by zero
- --> $DIR/promoted_errors2.rs:21:14
+ --> $DIR/promoted_errors2.rs:22:14
|
LL | let _x = 1 / (false as u32);
| ^^^^^^^^^^^^^^^^^^
// check-pass
-#![feature(slice_patterns)]
fn main() {
match &[0, 1] as &[i32] {
--- /dev/null
+// compile-flags: -Z mir-opt-level=2
+// run-pass
+
+struct Baz<T: ?Sized> {
+ a: T
+}
+
+fn main() {
+ let d : Baz<[i32; 4]> = Baz { a: [1,2,3,4] };
+ assert_eq!([1, 2, 3, 4], d.a);
+}
--- /dev/null
+// compile-flags: -Z mir-opt-level=3
+// run-pass
+
+struct X {
+ x: isize
+}
+
+fn f1(a: &mut X, b: &mut isize, c: isize) -> isize {
+ let r = a.x + *b + c;
+ a.x = 0;
+ *b = 10;
+ return r;
+}
+
+fn f2<F>(a: isize, f: F) -> isize where F: FnOnce(isize) { f(1); return a; }
+
+pub fn main() {
+ let mut a = X {x: 1};
+ let mut b = 2;
+ let c = 3;
+ assert_eq!(f1(&mut a, &mut b, c), 6);
+ assert_eq!(a.x, 0);
+ assert_eq!(f2(a.x, |_| a.x = 50), 0);
+}
--- /dev/null
+// compile-flags: -Z mir-opt-level=2
+// run-pass
+
+use std::cell::Cell;
+
+#[derive(Debug)]
+struct B<'a> {
+ a: [Cell<Option<&'a B<'a>>>; 2]
+}
+
+impl<'a> B<'a> {
+ fn new() -> B<'a> {
+ B { a: [Cell::new(None), Cell::new(None)] }
+ }
+}
+
+fn f() {
+ let b2 = B::new();
+ b2.a[0].set(Some(&b2));
+}
+
+fn main() {
+ f();
+}
--- /dev/null
+// compile-flags: -Z mir-opt-level=2
+// run-pass
+
+fn e220() -> (i64, i64) {
+ #[inline(never)]
+ fn get_displacement() -> [i64; 2] {
+ [139776, 963904]
+ }
+
+ let res = get_displacement();
+ match (&res[0], &res[1]) {
+ (arg0, arg1) => (*arg0, *arg1),
+ }
+}
+
+fn main() {
+ assert_eq!(e220(), (139776, 963904));
+}
error[E0080]: could not evaluate static initializer
--> $SRC_DIR/libcore/ptr/mod.rs:LL:COL
|
-LL | / unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
+LL | / pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
LL | | // Code here does not matter - this is replaced by the
LL | | // real drop glue by the compiler.
-LL | | real_drop_in_place(to_drop)
+LL | | drop_in_place(to_drop)
LL | | }
| |_^ calling non-const function `<std::vec::Vec<i32> as std::ops::Drop>::drop`
|
::: $DIR/drop.rs:23:1
|
LL | };
- | - inside call to `std::ptr::real_drop_in_place::<std::vec::Vec<i32>> - shim(Some(std::vec::Vec<i32>))` at $DIR/drop.rs:23:1
+ | - inside call to `std::intrinsics::drop_in_place::<std::vec::Vec<i32>> - shim(Some(std::vec::Vec<i32>))` at $DIR/drop.rs:23:1
error: aborting due to previous error
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:346:17
+thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
//~^ ERROR mismatched types
//~| expected trait object `dyn T`
//~| found reference `&_`
- //~| expected trait `T`, found reference
let &&&x = &(&1isize as &dyn T);
//~^ ERROR mismatched types
//~| expected trait object `dyn T`
//~| found reference `&_`
- //~| expected trait `T`, found reference
let box box x = box 1isize as Box<dyn T>;
//~^ ERROR mismatched types
//~| expected trait object `dyn T`
LL | let &&x = &1isize as &dyn T;
| ^^
| |
- | expected trait `T`, found reference
+ | expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x`
|
= note: expected trait object `dyn T`
found reference `&_`
error[E0308]: mismatched types
- --> $DIR/destructure-trait-ref.rs:37:11
+ --> $DIR/destructure-trait-ref.rs:36:11
|
LL | let &&&x = &(&1isize as &dyn T);
| ^^
| |
- | expected trait `T`, found reference
+ | expected trait object `dyn T`, found reference
| help: you can probably remove the explicit borrow: `x`
|
= note: expected trait object `dyn T`
found reference `&_`
error[E0308]: mismatched types
- --> $DIR/destructure-trait-ref.rs:42:13
+ --> $DIR/destructure-trait-ref.rs:40:13
|
LL | let box box x = box 1isize as Box<dyn T>;
| ^^^^^ ------------------------ this expression has type `std::boxed::Box<dyn T>`
| |
- | expected trait `T`, found struct `std::boxed::Box`
+ | expected trait object `dyn T`, found struct `std::boxed::Box`
|
= note: expected trait object `dyn T`
found struct `std::boxed::Box<_>`
// edition:2018
// ignore-wasm32-bare compiled with panic=abort by default
-#![feature(slice_patterns)]
#![allow(unused)]
use std::{
// run-pass
-#![allow(unused_assignments)]
-#![allow(unused_variables)]
-
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait, untagged_unions)]
-#![feature(slice_patterns)]
+
+#![allow(unused_assignments)]
+#![allow(unused_variables)]
use std::cell::{Cell, RefCell};
use std::mem::ManuallyDrop;
let z: Box<dyn ToBar> = Box::new(Bar1 {f: 36});
f5.2 = Bar1 {f: 36};
//~^ ERROR mismatched types
- //~| expected trait `ToBar`, found struct `Bar1`
+ //~| expected trait object `dyn ToBar`, found struct `Bar1`
//~| expected trait object `dyn ToBar`
//~| found struct `Bar1`
//~| ERROR the size for values of type
--> $DIR/dst-bad-assign-3.rs:33:12
|
LL | f5.2 = Bar1 {f: 36};
- | ^^^^^^^^^^^^ expected trait `ToBar`, found struct `Bar1`
+ | ^^^^^^^^^^^^ expected trait object `dyn ToBar`, found struct `Bar1`
|
= note: expected trait object `dyn ToBar`
found struct `Bar1`
let z: Box<dyn ToBar> = Box::new(Bar1 {f: 36});
f5.ptr = Bar1 {f: 36};
//~^ ERROR mismatched types
- //~| expected trait `ToBar`, found struct `Bar1`
+ //~| expected trait object `dyn ToBar`, found struct `Bar1`
//~| expected trait object `dyn ToBar`
//~| found struct `Bar1`
//~| ERROR the size for values of type
--> $DIR/dst-bad-assign.rs:35:14
|
LL | f5.ptr = Bar1 {f: 36};
- | ^^^^^^^^^^^^ expected trait `ToBar`, found struct `Bar1`
+ | ^^^^^^^^^^^^ expected trait object `dyn ToBar`, found struct `Bar1`
|
= note: expected trait object `dyn ToBar`
found struct `Bar1`
-#![feature(slice_patterns)]
-
fn main() {
let r = &[1, 2];
match r {
error[E0528]: pattern requires at least 3 elements but array has 2
- --> $DIR/E0528.rs:6:10
+ --> $DIR/E0528.rs:4:10
|
LL | &[a, b, c, rest @ ..] => {
| ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 2 elements
--> $DIR/E0603.rs:6:17
|
LL | SomeModule::PRIVATE;
- | ^^^^^^^
+ | ^^^^^^^ this constant is private
+ |
+note: the constant `PRIVATE` is defined here
+ --> $DIR/E0603.rs:2:5
+ |
+LL | const PRIVATE: u32 = 0x_a_bad_1dea_u32;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
--- /dev/null
+// run-rustfix
+#![allow(dead_code)]
+struct Struct;
+trait Trait {}
+impl Trait for Struct {}
+impl Trait for u32 {}
+
+fn foo() -> impl Trait { Struct }
+//~^ ERROR E0746
+
+fn bar() -> impl Trait { //~ ERROR E0746
+ if true {
+ return 0;
+ }
+ 42
+}
+
+fn main() {}
--- /dev/null
+// run-rustfix
+#![allow(dead_code)]
+struct Struct;
+trait Trait {}
+impl Trait for Struct {}
+impl Trait for u32 {}
+
+fn foo() -> dyn Trait { Struct }
+//~^ ERROR E0746
+
+fn bar() -> dyn Trait { //~ ERROR E0746
+ if true {
+ return 0;
+ }
+ 42
+}
+
+fn main() {}
--- /dev/null
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/E0746.rs:8:13
+ |
+LL | fn foo() -> dyn Trait { Struct }
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+help: return `impl Trait` instead, as all return paths are of type `Struct`, which implements `Trait`
+ |
+LL | fn foo() -> impl Trait { Struct }
+ | ^^^^^^^^^^
+
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/E0746.rs:11:13
+ |
+LL | fn bar() -> dyn Trait {
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+help: return `impl Trait` instead, as all return paths are of type `{integer}`, which implements `Trait`
+ |
+LL | fn bar() -> impl Trait {
+ | ^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0746`.
--> $DIR/error-festival.rs:22:10
|
LL | foo::FOO;
- | ^^^
+ | ^^^ this constant is private
+ |
+note: the constant `FOO` is defined here
+ --> $DIR/error-festival.rs:7:5
+ |
+LL | const FOO: u32 = 0;
+ | ^^^^^^^^^^^^^^^^^^^
error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
--> $DIR/error-festival.rs:12:5
--> $DIR/export-import.rs:1:8
|
LL | use m::unexported;
- | ^^^^^^^^^^
+ | ^^^^^^^^^^ this function is private
+ |
+note: the function `unexported` is defined here
+ --> $DIR/export-import.rs:7:5
+ |
+LL | fn unexported() { }
+ | ^^^^^^^^^^^^^^^
error: aborting due to previous error
--> $DIR/export-tag-variant.rs:7:26
|
LL | fn main() { let z = foo::Y::Y1; }
- | ^
+ | ^ this enum is private
+ |
+note: the enum `Y` is defined here
+ --> $DIR/export-tag-variant.rs:4:5
+ |
+LL | enum Y { Y1 }
+ | ^^^^^^
error: aborting due to previous error
--> $DIR/export.rs:10:18
|
LL | fn main() { foo::z(10); }
- | ^
+ | ^ this function is private
+ |
+note: the function `z` is defined here
+ --> $DIR/export.rs:5:5
+ |
+LL | fn z(y: isize) { log(debug, y); }
+ | ^^^^^^^^^^^^^^
error: aborting due to 5 previous errors
}
// Check that private crates can be used from outside their modules, albeit with warnings
-use foo::core::cell; //~ ERROR crate `core` is private
+use foo::core::cell; //~ ERROR crate import `core` is private
fn f() {
- foo::core::cell::Cell::new(0); //~ ERROR crate `core` is private
+ foo::core::cell::Cell::new(0); //~ ERROR crate import `core` is private
use foo::*;
mod core {} // Check that private crates are not glob imported
-error[E0603]: crate `core` is private
+error[E0603]: crate import `core` is private
--> $DIR/extern-crate-visibility.rs:6:10
|
LL | use foo::core::cell;
- | ^^^^
+ | ^^^^ this crate import is private
+ |
+note: the crate import `core` is defined here
+ --> $DIR/extern-crate-visibility.rs:2:5
+ |
+LL | extern crate core;
+ | ^^^^^^^^^^^^^^^^^^
-error[E0603]: crate `core` is private
+error[E0603]: crate import `core` is private
--> $DIR/extern-crate-visibility.rs:9:10
|
LL | foo::core::cell::Cell::new(0);
- | ^^^^
+ | ^^^^ this crate import is private
+ |
+note: the crate import `core` is defined here
+ --> $DIR/extern-crate-visibility.rs:2:5
+ |
+LL | extern crate core;
+ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
+++ /dev/null
-// Test that slice pattern syntax with `..` is gated by `slice_patterns` feature gate
-
-fn main() {
- let x = [1, 2, 3, 4, 5];
- match x {
- [1, 2, ..] => {} //~ ERROR subslice patterns are unstable
- [1, .., 5] => {} //~ ERROR subslice patterns are unstable
- [.., 4, 5] => {} //~ ERROR subslice patterns are unstable
- }
-
- let x = [ 1, 2, 3, 4, 5 ];
- match x {
- [ xs @ .., 4, 5 ] => {} //~ ERROR subslice patterns are unstable
- [ 1, xs @ .., 5 ] => {} //~ ERROR subslice patterns are unstable
- [ 1, 2, xs @ .. ] => {} //~ ERROR subslice patterns are unstable
- }
-}
+++ /dev/null
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:6:16
- |
-LL | [1, 2, ..] => {}
- | ^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:7:13
- |
-LL | [1, .., 5] => {}
- | ^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:8:10
- |
-LL | [.., 4, 5] => {}
- | ^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:13:11
- |
-LL | [ xs @ .., 4, 5 ] => {}
- | ^^^^^^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:14:14
- |
-LL | [ 1, xs @ .., 5 ] => {}
- | ^^^^^^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/feature-gate-slice-patterns.rs:15:17
- |
-LL | [ 1, 2, xs @ .. ] => {}
- | ^^^^^^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error: aborting due to 6 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= note: required because of the requirements on the impl of `std::marker::Copy` for `Fooy<T>`
- = note: the requirement `Fooy<T>: std::marker::Copy` appears on the associated impl typebut not on the corresponding associated trait type
+ = note: the requirement `Fooy<T>: std::marker::Copy` appears on the associated impl type but not on the corresponding associated trait type
error: aborting due to 3 previous errors
--> $DIR/privacy.rs:16:14
|
LL | foo::f()
- | ^
+ | ^ this function is private
+ |
+note: the function `f` is defined here
+ --> $DIR/privacy.rs:4:5
+ |
+LL | fn f() {}
+ | ^^^^^^
error: aborting due to previous error
#![allow(non_shorthand_field_patterns)]
#![allow(dead_code)]
#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-#![feature(slice_patterns)]
struct Foo(isize, isize, isize, isize);
struct Bar{a: isize, b: isize, c: isize, d: isize}
--- /dev/null
+#![allow(bare_trait_objects)]
+struct Struct;
+trait Trait {}
+impl Trait for Struct {}
+impl Trait for u32 {}
+
+fn fuz() -> (usize, Trait) { (42, Struct) }
+//~^ ERROR E0277
+//~| ERROR E0308
+fn bar() -> (usize, dyn Trait) { (42, Struct) }
+//~^ ERROR E0277
+//~| ERROR E0308
+fn bap() -> Trait { Struct }
+//~^ ERROR E0746
+fn ban() -> dyn Trait { Struct }
+//~^ ERROR E0746
+fn bak() -> dyn Trait { unimplemented!() } //~ ERROR E0277
+// Suggest using `Box<dyn Trait>`
+fn bal() -> dyn Trait { //~ ERROR E0746
+ if true {
+ return Struct;
+ }
+ 42
+}
+
+// Suggest using `impl Trait`
+fn bat() -> dyn Trait { //~ ERROR E0746
+ if true {
+ return 0;
+ }
+ 42
+}
+
+fn main() {}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:35
+ |
+LL | fn fuz() -> (usize, Trait) { (42, Struct) }
+ | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
+ |
+ = note: expected trait object `(dyn Trait + 'static)`
+ found struct `Struct`
+
+error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:7:13
+ |
+LL | fn fuz() -> (usize, Trait) { (42, Struct) }
+ | ^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
+ | |
+ | doesn't have a size known at compile-time
+ |
+ = help: within `(usize, (dyn Trait + 'static))`, the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
+ = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+ = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
+ = note: the return type of a function must have a statically known size
+
+error[E0308]: mismatched types
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:39
+ |
+LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
+ | ^^^^^^ expected trait object `dyn Trait`, found struct `Struct`
+ |
+ = note: expected trait object `(dyn Trait + 'static)`
+ found struct `Struct`
+
+error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:10:13
+ |
+LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
+ | ^^^^^^^^^^^^^^^^^^ ------------ this returned value is of type `(usize, (dyn Trait + 'static))`
+ | |
+ | doesn't have a size known at compile-time
+ |
+ = help: within `(usize, (dyn Trait + 'static))`, the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
+ = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+ = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
+ = note: the return type of a function must have a statically known size
+
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:13:13
+ |
+LL | fn bap() -> Trait { Struct }
+ | ^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+help: return `impl Trait` instead, as all return paths are of type `Struct`, which implements `Trait`
+ |
+LL | fn bap() -> impl Trait { Struct }
+ | ^^^^^^^^^^
+
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
+ |
+LL | fn ban() -> dyn Trait { Struct }
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+help: return `impl Trait` instead, as all return paths are of type `Struct`, which implements `Trait`
+ |
+LL | fn ban() -> impl Trait { Struct }
+ | ^^^^^^^^^^
+
+error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
+ |
+LL | fn bak() -> dyn Trait { unimplemented!() }
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
+ = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+ = note: the return type of a function must have a statically known size
+
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
+ |
+LL | fn bal() -> dyn Trait {
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = note: if all the returned values were of the same type you could use `impl Trait` as the return type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = note: you can create a new `enum` with a variant for each returned type
+help: return a boxed trait object instead
+ |
+LL | fn bal() -> Box<dyn Trait> {
+LL | if true {
+LL | return Box::new(Struct);
+LL | }
+LL | Box::new(42)
+ |
+
+error[E0746]: return type cannot have an unboxed trait object
+ --> $DIR/dyn-trait-return-should-be-impl-trait.rs:27:13
+ |
+LL | fn bat() -> dyn Trait {
+ | ^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+help: return `impl Trait` instead, as all return paths are of type `{integer}`, which implements `Trait`
+ |
+LL | fn bat() -> impl Trait {
+ | ^^^^^^^^^^
+
+error: aborting due to 9 previous errors
+
+Some errors have detailed explanations: E0277, E0308, E0746.
+For more information about an error, try `rustc --explain E0277`.
LL | }
LL | 0_u32
| ^^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: if the trait `Foo` were object safe, you could return a boxed trait object
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0277]: cannot add `impl Foo` to `u32`
--> $DIR/equality.rs:24:11
--- /dev/null
+#![allow(bare_trait_objects)]
+trait NotObjectSafe {
+ fn foo() -> Self;
+}
+
+struct A;
+struct B;
+
+impl NotObjectSafe for A {
+ fn foo() -> Self {
+ A
+ }
+}
+
+impl NotObjectSafe for B {
+ fn foo() -> Self {
+ B
+ }
+}
+
+fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be made into an object
+ if true {
+ return A;
+ }
+ B
+}
+
+fn cat() -> Box<dyn NotObjectSafe> { //~ ERROR the trait `NotObjectSafe` cannot be made into an
+ if true {
+ return Box::new(A);
+ }
+ Box::new(B)
+}
+
+fn main() {}
--- /dev/null
+error[E0038]: the trait `NotObjectSafe` cannot be made into an object
+ --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:1
+ |
+LL | fn foo() -> Self;
+ | --- associated function `foo` has no `self` parameter
+...
+LL | fn car() -> dyn NotObjectSafe {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+
+error[E0038]: the trait `NotObjectSafe` cannot be made into an object
+ --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:1
+ |
+LL | fn foo() -> Self;
+ | --- associated function `foo` has no `self` parameter
+...
+LL | fn cat() -> Box<dyn NotObjectSafe> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0038`.
--- /dev/null
+trait NotObjectSafe {
+ fn foo() -> Self;
+}
+
+trait ObjectSafe {
+ fn bar(&self);
+}
+
+struct A;
+struct B;
+
+impl NotObjectSafe for A {
+ fn foo() -> Self {
+ A
+ }
+}
+
+impl NotObjectSafe for B {
+ fn foo() -> Self {
+ B
+ }
+}
+
+impl ObjectSafe for A {
+ fn bar(&self) {}
+}
+
+impl ObjectSafe for B {
+ fn bar(&self) {}
+}
+
+fn can() -> impl NotObjectSafe {
+ if true {
+ return A;
+ }
+ B //~ ERROR mismatched types
+}
+
+fn cat() -> impl ObjectSafe {
+ if true {
+ return A;
+ }
+ B //~ ERROR mismatched types
+}
+
+fn main() {}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:36:5
+ |
+LL | fn can() -> impl NotObjectSafe {
+ | ------------------ expected because this return type...
+LL | if true {
+LL | return A;
+ | - ...is found to be `A` here
+LL | }
+LL | B
+ | ^ expected struct `A`, found struct `B`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: if the trait `NotObjectSafe` were object safe, you could return a boxed trait object
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
+
+error[E0308]: mismatched types
+ --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:43:5
+ |
+LL | fn cat() -> impl ObjectSafe {
+ | --------------- expected because this return type...
+LL | if true {
+LL | return A;
+ | - ...is found to be `A` here
+LL | }
+LL | B
+ | ^ expected struct `A`, found struct `B`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn ObjectSafe>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
LL | use foo;
| ^^^ no `foo` in the root
-error[E0603]: unresolved item `foo` is private
+error[E0603]: unresolved item import `foo` is private
--> $DIR/import.rs:15:10
|
LL | zed::foo();
- | ^^^
+ | ^^^ this unresolved item import is private
+ |
+note: the unresolved item import `foo` is defined here
+ --> $DIR/import.rs:10:9
+ |
+LL | use foo;
+ | ^^^
error: aborting due to 3 previous errors
use ParseOptions;
}
-pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private
+pub use parser::ParseOptions; //~ ERROR struct import `ParseOptions` is private
fn main() {}
-error[E0603]: struct `ParseOptions` is private
+error[E0603]: struct import `ParseOptions` is private
--> $DIR/issue-55884-2.rs:12:17
|
LL | pub use parser::ParseOptions;
- | ^^^^^^^^^^^^
+ | ^^^^^^^^^^^^ this struct import is private
+ |
+note: the struct import `ParseOptions` is defined here
+ --> $DIR/issue-55884-2.rs:9:9
+ |
+LL | use ParseOptions;
+ | ^^^^^^^^^^^^
error: aborting due to previous error
LL | pub use super::foo;
| ^^^^^^^^^^
-error[E0603]: module `foo` is private
+error[E0603]: module import `foo` is private
--> $DIR/reexports.rs:33:15
|
LL | use b::a::foo::S;
- | ^^^
+ | ^^^ this module import is private
+ |
+note: the module import `foo` is defined here
+ --> $DIR/reexports.rs:21:17
+ |
+LL | pub use super::foo; // This is OK since the value `foo` is visible enough.
+ | ^^^^^^^^^^
-error[E0603]: module `foo` is private
+error[E0603]: module import `foo` is private
--> $DIR/reexports.rs:34:15
|
LL | use b::b::foo::S as T;
- | ^^^
+ | ^^^ this module import is private
+ |
+note: the module import `foo` is defined here
+ --> $DIR/reexports.rs:26:17
+ |
+LL | pub use super::*; // This is also OK since the value `foo` is visible enough.
+ | ^^^^^^^^
warning: glob import doesn't reexport anything because no candidate is public enough
--> $DIR/reexports.rs:9:17
--> $DIR/unresolved-imports-used.rs:9:10
|
LL | use qux::quz;
- | ^^^
+ | ^^^ this function is private
+ |
+note: the function `quz` is defined here
+ --> $DIR/unresolved-imports-used.rs:5:4
+ |
+LL | fn quz() {}
+ | ^^^^^^^^
error: unused import: `qux::quy`
--> $DIR/unresolved-imports-used.rs:16:5
--> $DIR/issue-10545.rs:6:14
|
LL | fn foo(_: a::S) {
- | ^
+ | ^ this struct is private
+ |
+note: the struct `S` is defined here
+ --> $DIR/issue-10545.rs:2:5
+ |
+LL | struct S;
+ | ^^^^^^^^^
error: aborting due to previous error
--> $DIR/issue-11593.rs:7:24
|
LL | impl private_trait_xc::Foo for Bar {}
- | ^^^
+ | ^^^ this trait is private
+ |
+note: the trait `Foo` is defined here
+ --> $DIR/auxiliary/private-trait-xc.rs:1:1
+ |
+LL | trait Foo {}
+ | ^^^^^^^^^
error: aborting due to previous error
--> $DIR/issue-11680.rs:6:21
|
LL | let _b = other::Foo::Bar(1);
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Foo` is defined here
+ --> $DIR/auxiliary/issue-11680.rs:1:1
+ |
+LL | enum Foo {
+ | ^^^^^^^^
error[E0603]: enum `Foo` is private
--> $DIR/issue-11680.rs:9:27
|
LL | let _b = other::test::Foo::Bar(1);
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Foo` is defined here
+ --> $DIR/auxiliary/issue-11680.rs:6:5
+ |
+LL | enum Foo {
+ | ^^^^^^^^
error: aborting due to 2 previous errors
-#![feature(slice_patterns)]
#![deny(unreachable_patterns)]
fn main() {
error: unreachable pattern
- --> $DIR/issue-12369.rs:10:9
+ --> $DIR/issue-12369.rs:9:9
|
LL | &[10,a, ref rest @ ..] => 10
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
- --> $DIR/issue-12369.rs:2:9
+ --> $DIR/issue-12369.rs:1:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
-#![feature(slice_patterns)]
-
fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) {
match (l1, l2) {
//~^ ERROR: cannot move out of type `[T]`, a non-copy slice
error[E0508]: cannot move out of type `[T]`, a non-copy slice
- --> $DIR/issue-12567.rs:4:11
+ --> $DIR/issue-12567.rs:2:11
|
LL | match (l1, l2) {
| ^^^^^^^^ cannot move out of here
= note: move occurs because these variables have types that don't implement the `Copy` trait
error[E0508]: cannot move out of type `[T]`, a non-copy slice
- --> $DIR/issue-12567.rs:4:11
+ --> $DIR/issue-12567.rs:2:11
|
LL | match (l1, l2) {
| ^^^^^^^^ cannot move out of here
--> $DIR/issue-13407.rs:6:8
|
LL | A::C = 1;
- | ^
+ | ^ this unit struct is private
+ |
+note: the unit struct `C` is defined here
+ --> $DIR/issue-13407.rs:2:5
+ |
+LL | struct C;
+ | ^^^^^^^^^
error[E0308]: mismatched types
--> $DIR/issue-13407.rs:6:12
--> $DIR/issue-13641.rs:9:8
|
LL | a::Foo::new();
- | ^^^
+ | ^^^ this struct is private
+ |
+note: the struct `Foo` is defined here
+ --> $DIR/issue-13641.rs:2:5
+ |
+LL | struct Foo;
+ | ^^^^^^^^^^^
error[E0603]: enum `Bar` is private
--> $DIR/issue-13641.rs:11:8
|
LL | a::Bar::new();
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Bar` is defined here
+ --> $DIR/issue-13641.rs:4:5
+ |
+LL | enum Bar {}
+ | ^^^^^^^^
error: aborting due to 2 previous errors
// run-pass
-#![feature(slice_patterns)]
fn main() {
let mut x: &[_] = &[1, 2, 3, 4];
// run-pass
-#![feature(slice_patterns)]
fn main() {
assert_eq!(count_members(&[1, 2, 3, 4]), 4);
--> $DIR/issue-16725.rs:6:19
|
LL | unsafe { foo::bar(); }
- | ^^^
+ | ^^^ this function is private
+ |
+note: the function `bar` is defined here
+ --> $DIR/auxiliary/issue-16725.rs:2:5
+ |
+LL | fn bar();
+ | ^^^^^^^^^
error: aborting due to previous error
--> $DIR/issue-17718-const-privacy.rs:5:8
|
LL | use a::B;
- | ^
+ | ^ this constant is private
+ |
+note: the constant `B` is defined here
+ --> $DIR/issue-17718-const-privacy.rs:13:5
+ |
+LL | const B: usize = 3;
+ | ^^^^^^^^^^^^^^^^^^^
error[E0603]: constant `BAR` is private
--> $DIR/issue-17718-const-privacy.rs:8:5
|
LL | BAR,
- | ^^^
+ | ^^^ this constant is private
+ |
+note: the constant `BAR` is defined here
+ --> $DIR/auxiliary/issue-17718-const-privacy.rs:4:1
+ |
+LL | const BAR: usize = 3;
+ | ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
// run-pass
-#![feature(slice_patterns)]
fn main() {
assert_eq!(match [0u8; 1024] {
// run-pass
-// Test that we do not ICE when pattern matching an array against a slice.
-#![feature(slice_patterns)]
+// Test that we do not ICE when pattern matching an array against a slice.
fn main() {
match "foo".as_bytes() {
+++ /dev/null
-//~ ERROR cycle detected when computing layout of
-//~| NOTE ...which requires computing layout of
-//~| NOTE ...which again requires computing layout of
-
-// build-fail
-
-trait Mirror { type It: ?Sized; }
-impl<T: ?Sized> Mirror for T { type It = Self; }
-struct S(Option<<S as Mirror>::It>);
-
-fn main() { //~ NOTE cycle used when processing `main`
- let _s = S(None);
-}
+++ /dev/null
-error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
- |
- = note: ...which requires computing layout of `S`...
- = note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
-note: cycle used when processing `main`
- --> $DIR/issue-26548.rs:11:1
- |
-LL | fn main() {
- | ^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0391`.
-#![feature(slice_patterns)]
-
pub struct History<'a> { pub _s: &'a str }
impl<'a> History<'a> {
error[E0515]: cannot return value referencing function parameter
- --> $DIR/issue-26619.rs:7:76
+ --> $DIR/issue-26619.rs:5:76
|
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
| -------- ^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
--> $DIR/issue-28388-2.rs:7:8
|
LL | use m::n::{};
- | ^
+ | ^ this module is private
+ |
+note: the module `n` is defined here
+ --> $DIR/issue-28388-2.rs:4:5
+ |
+LL | mod n {}
+ | ^^^^^
error: aborting due to previous error
--> $DIR/issue-29161.rs:13:8
|
LL | a::A::default();
- | ^
+ | ^ this struct is private
+ |
+note: the struct `A` is defined here
+ --> $DIR/issue-29161.rs:2:5
+ |
+LL | struct A;
+ | ^^^^^^^^^
error: aborting due to 2 previous errors
// check-pass
-#![feature(slice_patterns)]
fn check(list: &[u8]) {
match list {
+++ /dev/null
-// check-pass
-
-struct S<T> {
- t : T,
- s : Box<S<fn(u : T)>>
-}
-
-fn f(x : S<u32>) {}
-
-fn main () {}
+// FIXME: missing sysroot spans (#53081)
+// ignore-i586-unknown-linux-gnu
+// ignore-i586-unknown-linux-musl
+// ignore-i686-unknown-linux-musl
+
fn main() {
let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() };
//~^ ERROR failed to resolve: could not find `imp` in `sys` [E0433]
error[E0433]: failed to resolve: could not find `imp` in `sys`
- --> $DIR/issue-38857.rs:2:23
+ --> $DIR/issue-38857.rs:7:23
|
LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() };
| ^^^ could not find `imp` in `sys`
error[E0603]: module `sys` is private
- --> $DIR/issue-38857.rs:2:18
+ --> $DIR/issue-38857.rs:7:18
|
LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() };
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `sys` is defined here
+ --> $SRC_DIR/libstd/lib.rs:LL:COL
+ |
+LL | mod sys;
+ | ^^^^^^^^
error: aborting due to 2 previous errors
--> $DIR/issue-3993.rs:1:10
|
LL | use zoo::fly;
- | ^^^
+ | ^^^ this function is private
+ |
+note: the function `fly` is defined here
+ --> $DIR/issue-3993.rs:4:5
+ |
+LL | fn fly() {}
+ | ^^^^^^^^
error: aborting due to previous error
|
LL | ) -> Either<impl Trait<<u32 as Add<u32>>::Output>, impl Trait<<u32 as Add<u32>>::Output>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<u32>` is not implemented for `impl Trait<<u32 as std::ops::Add>::Output>`
+...
+LL | add_generic(value, 1u32)
+ | ------------------------ this returned value is of type `Either<impl Trait<<u32 as std::ops::Add>::Output>, impl Trait<<u32 as std::ops::Add>::Output>>`
|
= note: the return type of a function must have a statically known size
|
LL | ) -> Either<impl Trait<<u32 as Add<u32>>::Output>, impl Trait<<u32 as Add<u32>>::Output>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<u32>` is not implemented for `impl Trait<<u32 as std::ops::Add>::Output>`
+...
+LL | add_generic(value, 1u32)
+ | ------------------------ this returned value is of type `Either<impl Trait<<u32 as std::ops::Add>::Output>, impl Trait<<u32 as std::ops::Add>::Output>>`
|
= note: the return type of a function must have a statically known size
|
LL | -> Struct {
| ^^^^^^ doesn't have a size known at compile-time
+LL |
+LL | Struct { r: r }
+ | --------------- this returned value is of type `Struct`
|
= help: within `Struct`, the trait `std::marker::Sized` is not implemented for `(dyn A + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
// run-pass
-#![feature(slice_patterns)]
use std::ops::Add;
|
LL | fn foo() -> impl Future<Item=(), Error=Box<dyn Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Future` is not implemented for `std::result::Result<(), _>`
+LL |
+LL | Ok(())
+ | ------ this returned value is of type `std::result::Result<(), _>`
|
= note: the return type of a function must have a statically known size
--- /dev/null
+#![deny(non_snake_case)]
+#![allow(unused_variables)]
+#![allow(dead_code)]
+
+enum Foo {
+ Bad {
+ lowerCamelCaseName: bool,
+ //~^ ERROR structure field `lowerCamelCaseName` should have a snake case name
+ },
+ Good {
+ snake_case_name: bool,
+ },
+}
+
+fn main() {
+ let b = Foo::Bad { lowerCamelCaseName: true };
+
+ match b {
+ Foo::Bad { lowerCamelCaseName } => {}
+ Foo::Good { snake_case_name: lowerCamelCaseBinding } => { }
+ //~^ ERROR variable `lowerCamelCaseBinding` should have a snake case name
+ }
+
+ if let Foo::Good { snake_case_name: anotherLowerCamelCaseBinding } = b { }
+ //~^ ERROR variable `anotherLowerCamelCaseBinding` should have a snake case name
+
+ if let Foo::Bad { lowerCamelCaseName: yetAnotherLowerCamelCaseBinding } = b { }
+ //~^ ERROR variable `yetAnotherLowerCamelCaseBinding` should have a snake case name
+}
--- /dev/null
+error: structure field `lowerCamelCaseName` should have a snake case name
+ --> $DIR/issue-66362-no-snake-case-warning-for-field-puns.rs:7:9
+ |
+LL | lowerCamelCaseName: bool,
+ | ^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `lower_camel_case_name`
+ |
+note: lint level defined here
+ --> $DIR/issue-66362-no-snake-case-warning-for-field-puns.rs:1:9
+ |
+LL | #![deny(non_snake_case)]
+ | ^^^^^^^^^^^^^^
+
+error: variable `lowerCamelCaseBinding` should have a snake case name
+ --> $DIR/issue-66362-no-snake-case-warning-for-field-puns.rs:20:38
+ |
+LL | Foo::Good { snake_case_name: lowerCamelCaseBinding } => { }
+ | ^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `lower_camel_case_binding`
+
+error: variable `anotherLowerCamelCaseBinding` should have a snake case name
+ --> $DIR/issue-66362-no-snake-case-warning-for-field-puns.rs:24:41
+ |
+LL | if let Foo::Good { snake_case_name: anotherLowerCamelCaseBinding } = b { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `another_lower_camel_case_binding`
+
+error: variable `yetAnotherLowerCamelCaseBinding` should have a snake case name
+ --> $DIR/issue-66362-no-snake-case-warning-for-field-puns.rs:27:43
+ |
+LL | if let Foo::Bad { lowerCamelCaseName: yetAnotherLowerCamelCaseBinding } = b { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `yet_another_lower_camel_case_binding`
+
+error: aborting due to 4 previous errors
+
--> $DIR/macro-local-data-key-priv.rs:8:10
|
LL | bar::baz.with(|_| ());
- | ^^^
+ | ^^^ this constant is private
+ |
+note: the constant `baz` is defined here
+ --> $DIR/macro-local-data-key-priv.rs:4:5
+ |
+LL | thread_local!(static baz: f64 = 0.0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
--- /dev/null
+// check-pass
+// Regression test for issue #61651
+// Verifies that we don't try to constrain inference
+// variables due to the presence of multiple applicable
+// marker trait impls
+
+#![feature(marker_trait_attr)]
+
+#[marker] // Remove this line and it works?!?
+trait Foo<T> {}
+impl Foo<u16> for u8 {}
+impl Foo<[u8; 1]> for u8 {}
+fn foo<T: Foo<U>, U>(_: T) -> U { unimplemented!() }
+
+fn main() {
+ let _: u16 = foo(0_u8);
+}
+++ /dev/null
-#![feature(slice_patterns)]
-
-fn main() {
- match "foo".to_string() {
- ['f', 'o', ..] => {}
- //~^ ERROR expected an array or slice, found `std::string::String`
- _ => { }
- };
-
- // Note that this one works with default binding modes.
- match &[0, 1, 2] {
- [..] => {}
- };
-
- match &[0, 1, 2] {
- &[..] => {} // ok
- };
-
- match [0, 1, 2] {
- [0] => {}, //~ ERROR pattern requires
-
- [0, 1, x @ ..] => {
- let a: [_; 1] = x;
- }
- [0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires
- };
-
- match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope
- [] => {}
- };
-}
-
-fn another_fn_to_avoid_suppression() {
- match Default::default()
- {
- [] => {} //~ ERROR type annotations needed
- };
-}
+++ /dev/null
-error[E0425]: cannot find value `does_not_exist` in this scope
- --> $DIR/match-vec-mismatch.rs:28:11
- |
-LL | match does_not_exist {
- | ^^^^^^^^^^^^^^ not found in this scope
-
-error[E0529]: expected an array or slice, found `std::string::String`
- --> $DIR/match-vec-mismatch.rs:5:9
- |
-LL | ['f', 'o', ..] => {}
- | ^^^^^^^^^^^^^^ pattern cannot match with input type `std::string::String`
-
-error[E0527]: pattern requires 1 element but array has 3
- --> $DIR/match-vec-mismatch.rs:20:9
- |
-LL | [0] => {},
- | ^^^ expected 3 elements
-
-error[E0528]: pattern requires at least 4 elements but array has 3
- --> $DIR/match-vec-mismatch.rs:25:9
- |
-LL | [0, 1, 2, 3, x @ ..] => {}
- | ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements
-
-error[E0282]: type annotations needed
- --> $DIR/match-vec-mismatch.rs:36:9
- |
-LL | [] => {}
- | ^^ cannot infer type
- |
- = note: type must be known at this point
-
-error: aborting due to 5 previous errors
-
-Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529.
-For more information about an error, try `rustc --explain E0282`.
// Ensure that we cannot move out of a reference to a fixed-size array
-#![feature(slice_patterns)]
-
struct D { _x: u8 }
impl Drop for D { fn drop(&mut self) { } }
error[E0508]: cannot move out of type `[D; 4]`, a non-copy array
- --> $DIR/move-out-of-array-ref.rs:10:24
+ --> $DIR/move-out-of-array-ref.rs:8:24
|
LL | let [_, e, _, _] = *a;
| - ^^
| move occurs because `e` has type `D`, which does not implement the `Copy` trait
error[E0508]: cannot move out of type `[D; 4]`, a non-copy array
- --> $DIR/move-out-of-array-ref.rs:15:27
+ --> $DIR/move-out-of-array-ref.rs:13:27
|
LL | let [_, s @ .. , _] = *a;
| ------ ^^
| move occurs because `s` has type `[D; 2]`, which does not implement the `Copy` trait
error[E0508]: cannot move out of type `[D; 4]`, a non-copy array
- --> $DIR/move-out-of-array-ref.rs:20:24
+ --> $DIR/move-out-of-array-ref.rs:18:24
|
LL | let [_, e, _, _] = *a;
| - ^^
| move occurs because `e` has type `D`, which does not implement the `Copy` trait
error[E0508]: cannot move out of type `[D; 4]`, a non-copy array
- --> $DIR/move-out-of-array-ref.rs:25:27
+ --> $DIR/move-out-of-array-ref.rs:23:27
|
LL | let [_, s @ .. , _] = *a;
| ------ ^^
|
LL | fn should_ret_unit() -> impl T {
| ^^^^^^ the trait `T` is not implemented for `()`
+LL |
+LL | panic!()
+ | -------- this returned value is of type `()`
|
= note: the return type of a function must have a statically known size
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
#![feature(or_patterns)]
-#![feature(slice_patterns)]
+
#![allow(incomplete_features)]
#![deny(unreachable_patterns)]
#![feature(or_patterns)]
-#![feature(slice_patterns)]
+
#![allow(incomplete_features)]
#![deny(unreachable_patterns)]
#![feature(or_patterns)]
-#![feature(slice_patterns)]
+
#![allow(incomplete_features)]
#![deny(unreachable_patterns)]
--> $DIR/pub-item-macro.rs:17:23
|
LL | let y: u32 = foo::x;
- | ^
+ | ^ this static is private
+ |
+note: the static `x` is defined here
+ --> $DIR/pub-item-macro.rs:4:5
+ |
+LL | static x: u32 = 0;
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | pub_x!();
+ | --------- in this macro invocation
error: aborting due to 2 previous errors
+++ /dev/null
-fn main() {
- let a: &[u8] = &[];
- match a {
- [1, tail @ .., tail @ ..] => {},
- //~^ ERROR identifier `tail` is bound more than once in the same pattern
- //~| ERROR subslice patterns are unstable
- //~| ERROR subslice patterns are unstable
- //~| ERROR `..` can only be used once per slice pattern
- _ => ()
- }
-}
-
-const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
+++ /dev/null
-error[E0416]: identifier `tail` is bound more than once in the same pattern
- --> $DIR/match-vec-invalid.rs:4:24
- |
-LL | [1, tail @ .., tail @ ..] => {},
- | ^^^^ used in a pattern more than once
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/match-vec-invalid.rs:4:13
- |
-LL | [1, tail @ .., tail @ ..] => {},
- | ^^^^^^^^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error[E0658]: subslice patterns are unstable
- --> $DIR/match-vec-invalid.rs:4:24
- |
-LL | [1, tail @ .., tail @ ..] => {},
- | ^^^^^^^^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
-error: `..` can only be used once per slice pattern
- --> $DIR/match-vec-invalid.rs:4:31
- |
-LL | [1, tail @ .., tail @ ..] => {},
- | -- ^^ can only be used once per slice pattern
- | |
- | previously used here
-
-error[E0308]: mismatched types
- --> $DIR/match-vec-invalid.rs:13:30
- |
-LL | const RECOVERY_WITNESS: () = 0;
- | ^ expected `()`, found integer
-
-error: aborting due to 5 previous errors
-
-Some errors have detailed explanations: E0308, E0416, E0658.
-For more information about an error, try `rustc --explain E0308`.
let Test(&desc[..]) = x;
//~^ ERROR: expected one of `)`, `,`, `@`, or `|`, found `[`
- //~^^ ERROR subslice patterns are unstable
}
const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
| expected one of `)`, `,`, `@`, or `|`
| help: missing `,`
-error[E0658]: subslice patterns are unstable
- --> $DIR/pat-lt-bracket-6.rs:5:20
- |
-LL | let Test(&desc[..]) = x;
- | ^^
- |
- = note: for more information, see https://github.com/rust-lang/rust/issues/62254
- = help: add `#![feature(slice_patterns)]` to the crate attributes to enable
-
error[E0308]: mismatched types
- --> $DIR/pat-lt-bracket-6.rs:10:30
+ --> $DIR/pat-lt-bracket-6.rs:9:30
|
LL | const RECOVERY_WITNESS: () = 0;
| ^ expected `()`, found integer
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0308, E0658.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0308`.
// Test that moving on both sides of an `@` pattern is not allowed.
#![feature(bindings_after_at)]
-#![feature(slice_patterns)]
fn main() {
struct U; // Not copy!
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:12:9
+ --> $DIR/borrowck-move-and-move.rs:11:9
|
LL | let a @ b = U;
| ^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:16:9
+ --> $DIR/borrowck-move-and-move.rs:15:9
|
LL | let a @ (b, c) = (U, U);
| ^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:20:9
+ --> $DIR/borrowck-move-and-move.rs:19:9
|
LL | let a @ (b, c) = (u(), u());
| ^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:25:9
+ --> $DIR/borrowck-move-and-move.rs:24:9
|
LL | a @ Ok(b) | a @ Err(b) => {}
| ^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:25:21
+ --> $DIR/borrowck-move-and-move.rs:24:21
|
LL | a @ Ok(b) | a @ Err(b) => {}
| ^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:37:9
+ --> $DIR/borrowck-move-and-move.rs:36:9
|
LL | xs @ [a, .., b] => {}
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:43:9
+ --> $DIR/borrowck-move-and-move.rs:42:9
|
LL | xs @ [_, ys @ .., _] => {}
| ^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-move-and-move.rs:32:12
+ --> $DIR/borrowck-move-and-move.rs:31:12
|
LL | fn fun(a @ b: U) {}
| ^^^^^ binds an already bound by-move value by moving it
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:12:13
+ --> $DIR/borrowck-move-and-move.rs:11:13
|
LL | let a @ b = U;
| ----^ - move occurs because value has type `main::U`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:16:17
+ --> $DIR/borrowck-move-and-move.rs:15:17
|
LL | let a @ (b, c) = (U, U);
| --------^- ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:20:17
+ --> $DIR/borrowck-move-and-move.rs:19:17
|
LL | let a @ (b, c) = (u(), u());
| --------^- ---------- move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:25:16
+ --> $DIR/borrowck-move-and-move.rs:24:16
|
LL | match Ok(U) {
| ----- move occurs because value has type `std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:25:29
+ --> $DIR/borrowck-move-and-move.rs:24:29
|
LL | match Ok(U) {
| ----- move occurs because value has type `std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:37:22
+ --> $DIR/borrowck-move-and-move.rs:36:22
|
LL | match [u(), u(), u(), u()] {
| -------------------- move occurs because value has type `[main::U; 4]`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:43:18
+ --> $DIR/borrowck-move-and-move.rs:42:18
|
LL | match [u(), u(), u(), u()] {
| -------------------- move occurs because value has type `[main::U; 4]`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-move-and-move.rs:32:16
+ --> $DIR/borrowck-move-and-move.rs:31:16
|
LL | fn fun(a @ b: U) {}
| ----^
#![feature(bindings_after_at)]
#![feature(box_patterns)]
-#![feature(slice_patterns)]
#[derive(Copy, Clone)]
struct C;
#![feature(bindings_after_at)]
#![feature(box_patterns)]
-#![feature(slice_patterns)]
#[derive(Copy, Clone)]
struct C;
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-at-and-box.rs:17:9
+ --> $DIR/borrowck-pat-at-and-box.rs:16:9
|
LL | let a @ box &b = Box::new(&C);
| ^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-at-and-box.rs:21:9
+ --> $DIR/borrowck-pat-at-and-box.rs:20:9
|
LL | let a @ box b = Box::new(C);
| ^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-at-and-box.rs:33:25
+ --> $DIR/borrowck-pat-at-and-box.rs:32:25
|
LL | match Box::new(C) { a @ box b => {} }
| ^^^^^^^^^ binds an already bound by-move value by moving it
error[E0009]: cannot bind by-move and by-ref in the same pattern
- --> $DIR/borrowck-pat-at-and-box.rs:37:21
+ --> $DIR/borrowck-pat-at-and-box.rs:36:21
|
LL | let ref a @ box b = Box::new(NC);
| ------------^
| by-ref pattern here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:39:9
+ --> $DIR/borrowck-pat-at-and-box.rs:38:9
|
LL | let ref a @ box ref mut b = Box::new(nc());
| -----^^^^^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:41:9
+ --> $DIR/borrowck-pat-at-and-box.rs:40:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:43:9
+ --> $DIR/borrowck-pat-at-and-box.rs:42:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:46:9
+ --> $DIR/borrowck-pat-at-and-box.rs:45:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:52:9
+ --> $DIR/borrowck-pat-at-and-box.rs:51:9
|
LL | let ref mut a @ box ref b = Box::new(NC);
| ---------^^^^^^^-----
| mutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:66:9
+ --> $DIR/borrowck-pat-at-and-box.rs:65:9
|
LL | ref mut a @ box ref b => {
| ---------^^^^^^^-----
| mutable borrow occurs here
error[E0009]: cannot bind by-move and by-ref in the same pattern
- --> $DIR/borrowck-pat-at-and-box.rs:75:38
+ --> $DIR/borrowck-pat-at-and-box.rs:74:38
|
LL | box [Ok(a), ref xs @ .., Err(b)] => {}
| ----------- ^ by-move pattern here
| by-ref pattern here
error[E0009]: cannot bind by-move and by-ref in the same pattern
- --> $DIR/borrowck-pat-at-and-box.rs:81:46
+ --> $DIR/borrowck-pat-at-and-box.rs:80:46
|
LL | [Ok(box ref a), ref xs @ .., Err(box b), Err(box ref mut c)] => {}
| ----- ----------- ^ --------- by-ref pattern here
| by-ref pattern here
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-at-and-box.rs:25:11
+ --> $DIR/borrowck-pat-at-and-box.rs:24:11
|
LL | fn f1(a @ box &b: Box<&C>) {}
| ^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-at-and-box.rs:29:11
+ --> $DIR/borrowck-pat-at-and-box.rs:28:11
|
LL | fn f2(a @ box b: Box<C>) {}
| ^^^^^^^^^ binds an already bound by-move value by moving it
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:58:11
+ --> $DIR/borrowck-pat-at-and-box.rs:57:11
|
LL | fn f5(ref mut a @ box ref b: Box<NC>) {
| ---------^^^^^^^-----
| mutable borrow occurs here
error[E0382]: use of moved value
- --> $DIR/borrowck-pat-at-and-box.rs:17:18
+ --> $DIR/borrowck-pat-at-and-box.rs:16:18
|
LL | let a @ box &b = Box::new(&C);
| ---------^ ------------ move occurs because value has type `std::boxed::Box<&C>`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-pat-at-and-box.rs:21:17
+ --> $DIR/borrowck-pat-at-and-box.rs:20:17
|
LL | let a @ box b = Box::new(C);
| --------^ ----------- move occurs because value has type `std::boxed::Box<C>`, which does not implement the `Copy` trait
| value moved here
error[E0382]: use of moved value
- --> $DIR/borrowck-pat-at-and-box.rs:33:33
+ --> $DIR/borrowck-pat-at-and-box.rs:32:33
|
LL | match Box::new(C) { a @ box b => {} }
| ----------- --------^
| move occurs because value has type `std::boxed::Box<C>`, which does not implement the `Copy` trait
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:46:21
+ --> $DIR/borrowck-pat-at-and-box.rs:45:21
|
LL | let ref a @ box ref mut b = Box::new(NC);
| ------------^^^^^^^^^
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:52:25
+ --> $DIR/borrowck-pat-at-and-box.rs:51:25
|
LL | let ref mut a @ box ref b = Box::new(NC);
| ----------------^^^^^
| -- mutable borrow later used here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:66:25
+ --> $DIR/borrowck-pat-at-and-box.rs:65:25
|
LL | ref mut a @ box ref b => {
| ----------------^^^^^
| -- mutable borrow later used here
error[E0382]: use of moved value
- --> $DIR/borrowck-pat-at-and-box.rs:25:20
+ --> $DIR/borrowck-pat-at-and-box.rs:24:20
|
LL | fn f1(a @ box &b: Box<&C>) {}
| ---------^
| move occurs because value has type `std::boxed::Box<&C>`, which does not implement the `Copy` trait
error[E0382]: use of moved value
- --> $DIR/borrowck-pat-at-and-box.rs:29:19
+ --> $DIR/borrowck-pat-at-and-box.rs:28:19
|
LL | fn f2(a @ box b: Box<C>) {}
| --------^
| move occurs because value has type `std::boxed::Box<C>`, which does not implement the `Copy` trait
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:58:27
+ --> $DIR/borrowck-pat-at-and-box.rs:57:27
|
LL | fn f5(ref mut a @ box ref b: Box<NC>) {
| ----------------^^^^^
// Test `Copy` bindings in the rhs of `@` patterns.
-#![feature(slice_patterns)]
#![feature(bindings_after_at)]
#[derive(Copy, Clone)]
// of an `@` pattern according to NLL borrowck.
#![feature(bindings_after_at)]
-#![feature(slice_patterns)]
fn main() {
struct U; // Not copy!
#![feature(bindings_after_at)]
-#![feature(slice_patterns)]
enum Option<T> {
None,
error: cannot borrow `z` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:10:9
|
LL | ref mut z @ &mut Some(ref a) => {
| ---------^^^^^^^^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:32:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:9
|
LL | let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
| ---------^^^^-----------------^
| first mutable borrow occurs here
error: cannot borrow `b` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:32:22
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:22
|
LL | let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
| -----^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:36:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:35:9
|
LL | let ref a @ ref mut b = U;
| -----^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:38:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:37:9
|
LL | let ref mut a @ ref b = U;
| ---------^^^-----
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:40:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:39:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:42:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:9
|
LL | let ref mut a @ (ref b, ref c) = (U, U);
| ---------^^^^-----^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:45:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:44:9
|
LL | let ref mut a @ ref b = u();
| ---------^^^-----
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:49:9
|
LL | let ref a @ ref mut b = u();
| -----^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:56:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:55:9
|
LL | let ref mut a @ ref b = U;
| ---------^^^-----
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:60:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:59:9
|
LL | let ref a @ ref mut b = U;
| -----^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:66:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:65:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
| ---------^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:66:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:65:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
| ---------^^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:74:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:74:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----^^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:86:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:85:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| -----^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:86:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:85:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| -----^^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:93:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:92:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ---------^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:93:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:92:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ---------^^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:100:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:99:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| -----^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:100:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:99:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| -----^^^^^^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:107:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ---------^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:33
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:107:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ---------^^^^^^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:116:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:115:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:121:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:120:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:128:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:127:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:133:9
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:132:9
|
LL | let ref mut a @ (ref b, ref c) = (U, U);
| ---------^^^^-----^^-----^
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:25:11
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:24:11
|
LL | fn f1(ref a @ ref mut b: U) {}
| -----^^^---------
| immutable borrow occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:27:11
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:26:11
|
LL | fn f2(ref mut a @ ref b: U) {}
| ---------^^^-----
| mutable borrow occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:29:11
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:28:11
|
LL | fn f3(ref a @ [ref b, ref mut mid @ .., ref c]: [U; 4]) {}
| -----^^^^^^^^^^^----------------^^^^^^^^
| immutable borrow occurs here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:10:31
|
LL | ref mut z @ &mut Some(ref a) => {
| ----------------------^^^^^-
| ---------- mutable borrow later used here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:45:21
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:44:21
|
LL | let ref mut a @ ref b = u();
| ------------^^^^^
| -------- mutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:17
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:49:17
|
LL | let ref a @ ref mut b = u();
| --------^^^^^^^^^
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:20
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:74:20
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----------^^^^^^^^^-
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:45
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:74:45
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| ------------^^^^^^^^^-
| - immutable borrow later used here
error[E0594]: cannot assign to `*b`, as it is immutable for the pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:86:61
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:85:61
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| ^^^^^^ cannot assign
= note: variables bound in patterns are immutable until the end of the pattern guard
error[E0594]: cannot assign to `*a`, as it is immutable for the pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:93:61
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:92:61
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ^^^^^^^^^^^ cannot assign
= note: variables bound in patterns are immutable until the end of the pattern guard
error[E0507]: cannot move out of `b` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:100:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:99:66
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| ^ move occurs because `b` has type `&mut main::U`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0507]: cannot move out of `b` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:100:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:99:66
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| ^ move occurs because `b` has type `&mut main::U`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0507]: cannot move out of `a` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:107:66
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ^ move occurs because `a` has type `&mut std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0507]: cannot move out of `a` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:107:66
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ^ move occurs because `a` has type `&mut std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:121:18
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:120:18
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| ---------^^^^^^^^^------------
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:121:29
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:120:29
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| --------------------^^^^^^^^^-
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:128:18
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:127:18
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| ---------^^^^^^^^^------------
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:128:29
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:127:29
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| --------------------^^^^^^^^^-
// Test that `ref mut x @ ref mut y` and varieties of that are not allowed.
#![feature(bindings_after_at)]
-#![feature(slice_patterns)]
fn main() {
struct U;
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:25:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:24:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:29:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:28:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:32:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:31:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:35:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:34:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:39:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:38:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:43:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:42:9
|
LL | let ref mut a @ (
| ^--------
| |_____^
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:53:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:52:9
|
LL | let ref mut a @ (
| ^--------
| |_________^
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:63:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:62:9
|
LL | let a @ (ref mut b, ref mut c) = (U, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:67:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66:9
|
LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:71:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:70:9
|
LL | let a @ &mut ref mut b = &mut U;
| ^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:74:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:73:9
|
LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:79:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:79:37
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:85:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:84:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:85:37
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:84:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:92:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:91:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:92:37
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:91:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:104:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:103:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:104:37
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:103:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:11:11
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:10:11
|
LL | fn f1(ref mut a @ ref mut b: U) {}
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:13:11
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:12:11
|
LL | fn f2(ref mut a @ ref mut b: U) {}
| ---------^^^---------
| first mutable borrow occurs here
error: cannot borrow `a` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:16:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:15:9
|
LL | ref mut a @ [
| ^--------
| |_________^
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:25:21
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:24:21
|
LL | let ref mut a @ ref mut b = U;
| ------------^^^^^^^^^
| - first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:35:21
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:34:21
|
LL | let ref mut a @ ref mut b = U;
| ------------^^^^^^^^^
| ------ first borrow later used here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:63:25
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:62:25
|
LL | let a @ (ref mut b, ref mut c) = (U, U);
| ----------------^^^^^^^^^- ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:67:21
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66:21
|
LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
| ------------^-- -------- move occurs because value has type `&mut (main::U, [main::U; 2])`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:71:18
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:70:18
|
LL | let a @ &mut ref mut b = &mut U;
| ---------^^^^^^^^^ ------ move occurs because value has type `&mut main::U`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:74:30
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:73:30
|
LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
| ---------------------^^^^^^^^^- ----------- move occurs because value has type `&mut (main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:92:24
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:91:24
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------------^^^^^^^^^-
| ----------- first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:92:53
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:91:53
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ----------------^^^^^^^^^-
| ----------- first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:104:24
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:103:24
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------------^^^^^^^^^-
| - first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:104:53
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:103:53
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ----------------^^^^^^^^^-
+++ /dev/null
-// check-pass
-
-// This used to cause a stack overflow in the compiler.
-
-#![feature(slice_patterns)]
-
-fn main() {
- const LARGE_SIZE: usize = 1024 * 1024;
- let [..] = [0u8; LARGE_SIZE];
- match [0u8; LARGE_SIZE] {
- [..] => {}
- }
-}
+++ /dev/null
-// check-pass
-#![feature(slice_patterns)]
-#![deny(unreachable_patterns)]
-
-const C0: &'static [u8] = b"\x00";
-
-fn main() {
- let x: &[u8] = &[0];
- match x {
- &[] => {}
- &[1..=255] => {}
- C0 => {}
- &[_, _, ..] => {}
- }
-}
--- /dev/null
+// check-pass
+
+// This used to cause a stack overflow during exhaustiveness checking in the compiler.
+
+fn main() {
+ const LARGE_SIZE: usize = 1024 * 1024;
+ let [..] = [0u8; LARGE_SIZE];
+ match [0u8; LARGE_SIZE] {
+ [..] => {}
+ }
+}
--- /dev/null
+// check-pass
+
+#![deny(unreachable_patterns)]
+
+const C0: &'static [u8] = b"\x00";
+
+fn main() {
+ let x: &[u8] = &[0];
+ match x {
+ &[] => {}
+ &[1..=255] => {}
+ C0 => {}
+ &[_, _, ..] => {}
+ }
+}
-#![feature(slice_patterns)]
#![deny(unreachable_patterns)]
fn main() {
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:9:9
+ --> $DIR/match-byte-array-patterns.rs:8:9
|
LL | &[0x41, 0x41, 0x41, 0x41] => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
- --> $DIR/match-byte-array-patterns.rs:2:9
+ --> $DIR/match-byte-array-patterns.rs:1:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:15:9
+ --> $DIR/match-byte-array-patterns.rs:14:9
|
LL | b"AAAA" => {},
| ^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:21:9
+ --> $DIR/match-byte-array-patterns.rs:20:9
|
LL | b"AAAA" => {},
| ^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:27:9
+ --> $DIR/match-byte-array-patterns.rs:26:9
|
LL | b"AAAA" => {},
| ^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:35:9
+ --> $DIR/match-byte-array-patterns.rs:34:9
|
LL | &[0x41, 0x41, 0x41, 0x41] => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:41:9
+ --> $DIR/match-byte-array-patterns.rs:40:9
|
LL | b"AAAA" => {},
| ^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:47:9
+ --> $DIR/match-byte-array-patterns.rs:46:9
|
LL | b"AAAA" => {},
| ^^^^^^^
error: unreachable pattern
- --> $DIR/match-byte-array-patterns.rs:53:9
+ --> $DIR/match-byte-array-patterns.rs:52:9
|
LL | b"AAAA" => {},
| ^^^^^^^
-#![feature(slice_patterns)]
-
fn check(list: &[Option<()>]) {
match list {
//~^ ERROR `&[_, Some(_), .., None, _]` not covered
error[E0004]: non-exhaustive patterns: `&[_, Some(_), .., None, _]` not covered
- --> $DIR/match-slice-patterns.rs:4:11
+ --> $DIR/match-slice-patterns.rs:2:11
|
LL | match list {
| ^^^^ pattern `&[_, Some(_), .., None, _]` not covered
-#![feature(slice_patterns)]
#![deny(unreachable_patterns)]
fn main() {
error: unreachable pattern
- --> $DIR/match-vec-unreachable.rs:9:9
+ --> $DIR/match-vec-unreachable.rs:8:9
|
LL | [(1, 2), (2, 3), b] => (),
| ^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
- --> $DIR/match-vec-unreachable.rs:2:9
+ --> $DIR/match-vec-unreachable.rs:1:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/match-vec-unreachable.rs:19:9
+ --> $DIR/match-vec-unreachable.rs:18:9
|
LL | [_, _, _, _, _] => { }
| ^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/match-vec-unreachable.rs:27:9
+ --> $DIR/match-vec-unreachable.rs:26:9
|
LL | ['a', 'b', 'c'] => {}
| ^^^^^^^^^^^^^^^
-#![feature(slice_patterns)]
-
enum T { A(U), B }
enum U { C, D }
error[E0004]: non-exhaustive patterns: `(Some(&[]), Err(_))` not covered
- --> $DIR/non-exhaustive-match-nested.rs:7:11
+ --> $DIR/non-exhaustive-match-nested.rs:5:11
|
LL | match (l1, l2) {
| ^^^^^^^^ pattern `(Some(&[]), Err(_))` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `A(C)` not covered
- --> $DIR/non-exhaustive-match-nested.rs:17:11
+ --> $DIR/non-exhaustive-match-nested.rs:15:11
|
LL | enum T { A(U), B }
| ------------------
-#![feature(slice_patterns)]
#![allow(illegal_floating_point_literal_pattern)]
enum T { A, B }
error[E0004]: non-exhaustive patterns: `A` not covered
- --> $DIR/non-exhaustive-match.rs:8:11
+ --> $DIR/non-exhaustive-match.rs:7:11
|
LL | enum T { A, B }
| ---------------
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `false` not covered
- --> $DIR/non-exhaustive-match.rs:9:11
+ --> $DIR/non-exhaustive-match.rs:8:11
|
LL | match true {
| ^^^^ pattern `false` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `Some(_)` not covered
- --> $DIR/non-exhaustive-match.rs:12:11
+ --> $DIR/non-exhaustive-match.rs:11:11
|
LL | match Some(10) {
| ^^^^^^^^ pattern `Some(_)` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `(_, _, std::i32::MIN..=3i32)` and `(_, _, 5i32..=std::i32::MAX)` not covered
- --> $DIR/non-exhaustive-match.rs:15:11
+ --> $DIR/non-exhaustive-match.rs:14:11
|
LL | match (2, 3, 4) {
| ^^^^^^^^^ patterns `(_, _, std::i32::MIN..=3i32)` and `(_, _, 5i32..=std::i32::MAX)` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `(A, A)` not covered
- --> $DIR/non-exhaustive-match.rs:19:11
+ --> $DIR/non-exhaustive-match.rs:18:11
|
LL | match (T::A, T::A) {
| ^^^^^^^^^^^^ pattern `(A, A)` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `B` not covered
- --> $DIR/non-exhaustive-match.rs:23:11
+ --> $DIR/non-exhaustive-match.rs:22:11
|
LL | enum T { A, B }
| ---------------
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `[]` not covered
- --> $DIR/non-exhaustive-match.rs:34:11
+ --> $DIR/non-exhaustive-match.rs:33:11
|
LL | match *vec {
| ^^^^ pattern `[]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `[_, _, _, _, ..]` not covered
- --> $DIR/non-exhaustive-match.rs:47:11
+ --> $DIR/non-exhaustive-match.rs:46:11
|
LL | match *vec {
| ^^^^ pattern `[_, _, _, _, ..]` not covered
-#![feature(slice_patterns)]
-
struct Foo {
first: bool,
second: Option<[usize; 4]>
error[E0004]: non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:9:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:7:11
|
LL | / struct Foo {
LL | | first: bool,
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `Red` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:25:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:23:11
|
LL | / enum Color {
LL | | Red,
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `East`, `South` and `West` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:37:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:35:11
|
LL | / enum Direction {
LL | | North, East, South, West
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `Second`, `Third`, `Fourth` and 8 more not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:48:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:46:11
|
LL | / enum ExcessiveEnum {
LL | | First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:56:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:54:11
|
LL | / enum Color {
LL | | Red,
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `[Second(true), Second(false)]` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:72:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:70:11
|
LL | match *x {
| ^^ pattern `[Second(true), Second(false)]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `((), false)` not covered
- --> $DIR/non-exhaustive-pattern-witness.rs:85:11
+ --> $DIR/non-exhaustive-pattern-witness.rs:83:11
|
LL | match ((), false) {
| ^^^^^^^^^^^ pattern `((), false)` not covered
-#![feature(slice_patterns)]
-
fn main() {
let s: &[bool] = &[true; 0];
let s1: &[bool; 1] = &[false; 1];
error[E0004]: non-exhaustive patterns: `&[false, _]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:10:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:8:11
|
LL | match s2 {
| ^^ pattern `&[false, _]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:14:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:12:11
|
LL | match s3 {
| ^^ pattern `&[false, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:18:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:16:11
|
LL | match s10 {
| ^^^ pattern `&[false, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, true]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:27:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:25:11
|
LL | match s2 {
| ^^ pattern `&[false, true]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, .., true]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:32:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:30:11
|
LL | match s3 {
| ^^ pattern `&[false, .., true]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, .., true]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:37:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:35:11
|
LL | match s {
| ^ pattern `&[false, .., true]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:44:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:42:11
|
LL | match s {
| ^ pattern `&[_, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[_, _, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:48:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:46:11
|
LL | match s {
| ^ pattern `&[_, _, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:53:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:51:11
|
LL | match s {
| ^ pattern `&[false, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false, _, ..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:58:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:56:11
|
LL | match s {
| ^ pattern `&[false, _, ..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[_, .., false]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:64:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:62:11
|
LL | match s {
| ^ pattern `&[_, .., false]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[_, _, .., true]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:71:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:69:11
|
LL | match s {
| ^ pattern `&[_, _, .., true]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[true, _, .., _]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:78:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:76:11
|
LL | match s {
| ^ pattern `&[true, _, .., _]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[..]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:87:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:85:11
|
LL | match s {
| ^ pattern `&[..]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[true]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:91:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:89:11
|
LL | match s {
| ^ pattern `&[true]` not covered
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
error[E0004]: non-exhaustive patterns: `&[false]` not covered
- --> $DIR/slice-patterns-exhaustiveness.rs:99:11
+ --> $DIR/slice-patterns-exhaustiveness.rs:97:11
|
LL | match s1 {
| ^^ pattern `&[false]` not covered
// check-pass
-#![feature(slice_patterns)]
fn main() {
let s: &[bool] = &[true; 0];
-#![feature(slice_patterns)]
#![deny(unreachable_patterns)]
fn main() {
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:9:9
+ --> $DIR/slice-patterns-reachability.rs:8:9
|
LL | [true, ..] => {}
| ^^^^^^^^^^
|
note: lint level defined here
- --> $DIR/slice-patterns-reachability.rs:2:9
+ --> $DIR/slice-patterns-reachability.rs:1:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:10:9
+ --> $DIR/slice-patterns-reachability.rs:9:9
|
LL | [true] => {}
| ^^^^^^
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:15:9
+ --> $DIR/slice-patterns-reachability.rs:14:9
|
LL | [.., true] => {}
| ^^^^^^^^^^
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:16:9
+ --> $DIR/slice-patterns-reachability.rs:15:9
|
LL | [true] => {}
| ^^^^^^
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:21:9
+ --> $DIR/slice-patterns-reachability.rs:20:9
|
LL | [false, .., true] => {}
| ^^^^^^^^^^^^^^^^^
error: unreachable pattern
- --> $DIR/slice-patterns-reachability.rs:22:9
+ --> $DIR/slice-patterns-reachability.rs:21:9
|
LL | [false, true] => {}
| ^^^^^^^^^^^^^
LL | }
LL | 1u32
| ^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0308]: mismatched types
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:13:16
LL | } else {
LL | return 1u32;
| ^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0308]: mismatched types
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:22:9
LL | } else {
LL | 1u32
| ^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0308]: `if` and `else` have incompatible types
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:31:9
| ---- ...is found to be `i32` here
LL | _ => 1u32,
| ^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0308]: mismatched types
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:45:5
LL | | _ => 2u32,
LL | | }
| |_____^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error[E0308]: mismatched types
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:59:13
...
LL | 1u32
| ^^^^ expected `i32`, found `u32`
+ |
+ = note: to return `impl Trait`, all returned values must be of the same type
+ = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
+ = help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>`
+ = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
+ = help: alternatively, create a new `enum` with a variant for each returned type
error: aborting due to 7 previous errors
--> $DIR/decl-macro.rs:8:8
|
LL | m::mac!();
- | ^^^
+ | ^^^ this macro is private
+ |
+note: the macro `mac` is defined here
+ --> $DIR/decl-macro.rs:4:5
+ |
+LL | macro mac() {}
+ | ^^^^^^^^^^^
error: aborting due to previous error
--> $DIR/privacy-in-paths.rs:24:16
|
LL | ::foo::bar::baz::f();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `bar` is defined here
+ --> $DIR/privacy-in-paths.rs:3:5
+ |
+LL | mod bar {
+ | ^^^^^^^
error[E0603]: module `bar` is private
--> $DIR/privacy-in-paths.rs:25:16
|
LL | ::foo::bar::S::f();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `bar` is defined here
+ --> $DIR/privacy-in-paths.rs:3:5
+ |
+LL | mod bar {
+ | ^^^^^^^
error[E0603]: trait `T` is private
--> $DIR/privacy-in-paths.rs:26:23
|
LL | <() as ::foo::T>::Assoc::f();
- | ^
+ | ^ this trait is private
+ |
+note: the trait `T` is defined here
+ --> $DIR/privacy-in-paths.rs:8:5
+ |
+LL | trait T {
+ | ^^^^^^^
error: aborting due to 3 previous errors
--> $DIR/privacy-ns2.rs:63:15
|
LL | use foo3::Bar;
- | ^^^
+ | ^^^ this trait is private
+ |
+note: the trait `Bar` is defined here
+ --> $DIR/privacy-ns2.rs:55:5
+ |
+LL | trait Bar {
+ | ^^^^^^^^^
error[E0603]: trait `Bar` is private
--> $DIR/privacy-ns2.rs:67:15
|
LL | use foo3::Bar;
- | ^^^
+ | ^^^ this trait is private
+ |
+note: the trait `Bar` is defined here
+ --> $DIR/privacy-ns2.rs:55:5
+ |
+LL | trait Bar {
+ | ^^^^^^^^^
error[E0603]: trait `Bar` is private
--> $DIR/privacy-ns2.rs:74:16
|
LL | use foo3::{Bar,Baz};
- | ^^^
+ | ^^^ this trait is private
+ |
+note: the trait `Bar` is defined here
+ --> $DIR/privacy-ns2.rs:55:5
+ |
+LL | trait Bar {
+ | ^^^^^^^^^
error[E0107]: wrong number of const arguments: expected 0, found 1
--> $DIR/privacy-ns2.rs:41:18
--> $DIR/privacy-ufcs.rs:12:20
|
LL | <i32 as ::foo::Bar>::baz();
- | ^^^
+ | ^^^ this trait is private
+ |
+note: the trait `Bar` is defined here
+ --> $DIR/privacy-ufcs.rs:4:5
+ |
+LL | trait Bar {
+ | ^^^^^^^^^
error: aborting due to previous error
--> $DIR/privacy1.rs:132:18
|
LL | use bar::baz::{foo, bar};
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:132:18
|
LL | use bar::baz::{foo, bar};
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:141:18
|
LL | use bar::baz;
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `i` is private
--> $DIR/privacy1.rs:165:20
|
LL | use self::foo::i::A;
- | ^
+ | ^ this module is private
+ |
+note: the module `i` is defined here
+ --> $DIR/privacy1.rs:170:9
+ |
+LL | mod i {
+ | ^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:104:16
|
LL | ::bar::baz::A::foo();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:105:16
|
LL | ::bar::baz::A::bar();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:107:16
|
LL | ::bar::baz::A.foo2();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:108:16
|
LL | ::bar::baz::A.bar2();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: trait `B` is private
--> $DIR/privacy1.rs:112:16
|
LL | ::bar::B::foo();
- | ^
+ | ^ this trait is private
+ |
+note: the trait `B` is defined here
+ --> $DIR/privacy1.rs:40:5
+ |
+LL | trait B {
+ | ^^^^^^^
error[E0603]: function `epriv` is private
--> $DIR/privacy1.rs:118:20
|
LL | ::bar::epriv();
- | ^^^^^
+ | ^^^^^ this function is private
+ |
+note: the function `epriv` is defined here
+ --> $DIR/privacy1.rs:65:9
+ |
+LL | fn epriv();
+ | ^^^^^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:127:16
|
LL | ::bar::baz::foo();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:128:16
|
LL | ::bar::baz::bar();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `baz` is defined here
+ --> $DIR/privacy1.rs:50:5
+ |
+LL | mod baz {
+ | ^^^^^^^
error[E0603]: trait `B` is private
--> $DIR/privacy1.rs:157:17
|
LL | impl ::bar::B for f32 { fn foo() -> f32 { 1.0 } }
- | ^
+ | ^ this trait is private
+ |
+note: the trait `B` is defined here
+ --> $DIR/privacy1.rs:40:5
+ |
+LL | trait B {
+ | ^^^^^^^
error[E0624]: method `bar` is private
--> $DIR/privacy1.rs:77:9
LL | use bar::foo;
| ^^^^^^^^ no `foo` in `bar`
-error[E0603]: function `foo` is private
+error[E0603]: function import `foo` is private
--> $DIR/privacy2.rs:23:20
|
LL | use bar::glob::foo;
- | ^^^
+ | ^^^ this function import is private
+ |
+note: the function import `foo` is defined here
+ --> $DIR/privacy2.rs:10:13
+ |
+LL | use foo;
+ | ^^^
error: requires `sized` lang_item
--> $DIR/privacy4.rs:21:14
|
LL | use bar::glob::gpriv;
- | ^^^^
+ | ^^^^ this module is private
+ |
+note: the module `glob` is defined here
+ --> $DIR/privacy4.rs:13:5
+ |
+LL | mod glob {
+ | ^^^^^^^^
error: aborting due to previous error
| -- a constructor is private if any of the fields is private
...
LL | let a = a::A(());
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:52:16
| ----- a constructor is private if any of the fields is private
...
LL | let b = a::B(2);
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:53:16
| ---------------- a constructor is private if any of the fields is private
...
LL | let c = a::C(2, 3);
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:56:12
| -- a constructor is private if any of the fields is private
...
LL | let a::A(()) = a;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:57:12
| -- a constructor is private if any of the fields is private
...
LL | let a::A(_) = a;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:58:18
| -- a constructor is private if any of the fields is private
...
LL | match a { a::A(()) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:59:18
| -- a constructor is private if any of the fields is private
...
LL | match a { a::A(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:61:12
| ----- a constructor is private if any of the fields is private
...
LL | let a::B(_) = b;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:62:12
| ----- a constructor is private if any of the fields is private
...
LL | let a::B(_b) = b;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:63:18
| ----- a constructor is private if any of the fields is private
...
LL | match b { a::B(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:64:18
| ----- a constructor is private if any of the fields is private
...
LL | match b { a::B(_b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:65:18
| ----- a constructor is private if any of the fields is private
...
LL | match b { a::B(1) => {} a::B(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:65:32
| ----- a constructor is private if any of the fields is private
...
LL | match b { a::B(1) => {} a::B(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:68:12
| ---------------- a constructor is private if any of the fields is private
...
LL | let a::C(_, _) = c;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:69:12
| ---------------- a constructor is private if any of the fields is private
...
LL | let a::C(_a, _) = c;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:70:12
| ---------------- a constructor is private if any of the fields is private
...
LL | let a::C(_, _b) = c;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:71:12
| ---------------- a constructor is private if any of the fields is private
...
LL | let a::C(_a, _b) = c;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:72:18
| ---------------- a constructor is private if any of the fields is private
...
LL | match c { a::C(_, _) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:73:18
| ---------------- a constructor is private if any of the fields is private
...
LL | match c { a::C(_a, _) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:74:18
| ---------------- a constructor is private if any of the fields is private
...
LL | match c { a::C(_, _b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:75:18
| ---------------- a constructor is private if any of the fields is private
...
LL | match c { a::C(_a, _b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:83:17
| -- a constructor is private if any of the fields is private
...
LL | let a2 = a::A;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/privacy5.rs:6:5
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:84:17
| ----- a constructor is private if any of the fields is private
...
LL | let b2 = a::B;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/privacy5.rs:7:5
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:85:17
| ---------------- a constructor is private if any of the fields is private
...
LL | let c2 = a::C;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/privacy5.rs:8:5
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:90:20
|
LL | let a = other::A(());
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:91:20
|
LL | let b = other::B(2);
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:92:20
|
LL | let c = other::C(2, 3);
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:95:16
|
LL | let other::A(()) = a;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:96:16
|
LL | let other::A(_) = a;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:97:22
|
LL | match a { other::A(()) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:98:22
|
LL | match a { other::A(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:100:16
|
LL | let other::B(_) = b;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:101:16
|
LL | let other::B(_b) = b;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:102:22
|
LL | match b { other::B(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:103:22
|
LL | match b { other::B(_b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:104:22
|
LL | match b { other::B(1) => {}
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:105:16
|
LL | other::B(_) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:107:16
|
LL | let other::C(_, _) = c;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:108:16
|
LL | let other::C(_a, _) = c;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:109:16
|
LL | let other::C(_, _b) = c;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:110:16
|
LL | let other::C(_a, _b) = c;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:111:22
|
LL | match c { other::C(_, _) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:112:22
|
LL | match c { other::C(_a, _) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:113:22
|
LL | match c { other::C(_, _b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:114:22
|
LL | match c { other::C(_a, _b) => {} }
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `A` is private
--> $DIR/privacy5.rs:122:21
|
LL | let a2 = other::A;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:1:14
|
LL | pub struct A(());
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `A` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:1:1
+ |
+LL | pub struct A(());
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `B` is private
--> $DIR/privacy5.rs:123:21
|
LL | let b2 = other::B;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:2:14
|
LL | pub struct B(isize);
| ----- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `B` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:2:1
+ |
+LL | pub struct B(isize);
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `C` is private
--> $DIR/privacy5.rs:124:21
|
LL | let c2 = other::C;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy_tuple_struct.rs:3:14
|
LL | pub struct C(pub isize, isize);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `C` is defined here
+ --> $DIR/auxiliary/privacy_tuple_struct.rs:3:1
+ |
+LL | pub struct C(pub isize, isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 48 previous errors
--> $DIR/private-item-simple.rs:6:8
|
LL | a::f();
- | ^
+ | ^ this function is private
+ |
+note: the function `f` is defined here
+ --> $DIR/private-item-simple.rs:2:5
+ |
+LL | fn f() {}
+ | ^^^^^^
error: aborting due to previous error
--> $DIR/test.rs:38:25
|
LL | use pub_restricted::Crate;
- | ^^^^^
+ | ^^^^^ this struct is private
+ |
+note: the struct `Crate` is defined here
+ --> $DIR/auxiliary/pub_restricted.rs:3:1
+ |
+LL | pub(crate) struct Crate;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: function `f` is private
--> $DIR/test.rs:30:19
|
LL | use foo::bar::f;
- | ^
+ | ^ this function is private
+ |
+note: the function `f` is defined here
+ --> $DIR/test.rs:8:9
+ |
+LL | pub(super) fn f() {}
+ | ^^^^^^^^^^^^^^^^^
error[E0616]: field `x` of struct `foo::bar::S` is private
--> $DIR/test.rs:31:5
mod m {
use test_macros::Empty;
}
-use m::Empty; //~ ERROR derive macro `Empty` is private
+use m::Empty; //~ ERROR derive macro import `Empty` is private
// To resolve `empty_helper` we need to resolve `Empty`.
// During initial resolution `use m::Empty` introduces no entries, so we proceed to `macro_use`,
LL | #[empty_helper]
| ^^^^^^^^^^^^
-error[E0603]: derive macro `Empty` is private
+error[E0603]: derive macro import `Empty` is private
--> $DIR/disappearing-resolution.rs:11:8
|
LL | use m::Empty;
- | ^^^^^
+ | ^^^^^ this derive macro import is private
+ |
+note: the derive macro import `Empty` is defined here
+ --> $DIR/disappearing-resolution.rs:9:9
+ |
+LL | use test_macros::Empty;
+ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
--> $DIR/unreachable-variant.rs:6:21
|
LL | let _x = other::super_sekrit::sooper_sekrit::baz;
- | ^^^^^^^^^^^^
+ | ^^^^^^^^^^^^ this module is private
+ |
+note: the module `super_sekrit` is defined here
+ --> $DIR/auxiliary/unreachable_variant.rs:1:1
+ |
+LL | mod super_sekrit {
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
--- /dev/null
+//~ ERROR cycle detected when computing layout of
+//~| NOTE ...which requires computing layout of
+//~| NOTE ...which again requires computing layout of
+
+// build-fail
+
+trait Mirror { type It: ?Sized; }
+impl<T: ?Sized> Mirror for T { type It = Self; }
+struct S(Option<<S as Mirror>::It>);
+
+fn main() { //~ NOTE cycle used when processing `main`
+ let _s = S(None);
+}
--- /dev/null
+error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
+ |
+ = note: ...which requires computing layout of `S`...
+ = note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
+note: cycle used when processing `main`
+ --> $DIR/issue-26548-recursion-via-normalize.rs:11:1
+ |
+LL | fn main() {
+ | ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
--- /dev/null
+// Dropck shouldn't hit a recursion limit from checking `S<u32>` since it has
+// no free regions or type parameters.
+// Codegen however, has to error for the infinitely many `drop_in_place`
+// functions it has been asked to create.
+// build-fail
+
+struct S<T> {
+ t: T,
+ s: Box<S<fn(u: T)>>,
+}
+
+fn f(x: S<u32>) {}
+
+fn main() {
+ // Force instantiation.
+ f as fn(_);
+}
--- /dev/null
+error: reached the recursion limit while instantiating `std::intrinsics::drop_in_place::<S<fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(u32))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>> - shim(Some(S<fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(u32))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>))`
+
+error: aborting due to previous error
+
}
#[repr(packed)]
-struct SC(SA); //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+struct SC(SA); //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
#[repr(packed)]
-struct SD(SB); //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+struct SD(SB); //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
#[repr(packed)]
-struct SE(UA); //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+struct SE(UA); //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
#[repr(packed)]
-struct SF(UB); //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+struct SF(UB); //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
#[repr(packed)]
-union UC { //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+union UC { //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
a: UA
}
#[repr(packed)]
-union UD { //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+union UD { //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
n: UB
}
#[repr(packed)]
-union UE { //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+union UE { //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
a: SA
}
#[repr(packed)]
-union UF { //~ ERROR: packed type cannot transitively contain a `[repr(align)]` type
+union UF { //~ ERROR: packed type cannot transitively contain a `#[repr(align)]` type
n: SB
}
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:19:1
|
LL | struct SC(SA);
| ^^^^^^^^^^^^^^
+ |
+note: `SA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:5:1
+ |
+LL | struct SA(i32);
+ | ^^^^^^^^^^^^^^^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:22:1
|
LL | struct SD(SB);
| ^^^^^^^^^^^^^^
+ |
+note: `SA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:5:1
+ |
+LL | struct SA(i32);
+ | ^^^^^^^^^^^^^^^
+note: `SD` contains a field of type `SB`
+ --> $DIR/repr-packed-contains-align.rs:22:11
+ |
+LL | struct SD(SB);
+ | ^^
+note: ...which contains a field of type `SA`
+ --> $DIR/repr-packed-contains-align.rs:7:11
+ |
+LL | struct SB(SA);
+ | ^^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:25:1
|
LL | struct SE(UA);
| ^^^^^^^^^^^^^^
+ |
+note: `UA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:10:1
+ |
+LL | / union UA {
+LL | | i: i32
+LL | | }
+ | |_^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:28:1
|
LL | struct SF(UB);
| ^^^^^^^^^^^^^^
+ |
+note: `UA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:10:1
+ |
+LL | / union UA {
+LL | | i: i32
+LL | | }
+ | |_^
+note: `SF` contains a field of type `UB`
+ --> $DIR/repr-packed-contains-align.rs:28:11
+ |
+LL | struct SF(UB);
+ | ^^
+note: ...which contains a field of type `UA`
+ --> $DIR/repr-packed-contains-align.rs:15:5
+ |
+LL | a: UA
+ | ^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:31:1
|
LL | / union UC {
LL | | a: UA
+LL | | }
+ | |_^
+ |
+note: `UA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:10:1
+ |
+LL | / union UA {
+LL | | i: i32
LL | | }
| |_^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:36:1
|
LL | / union UD {
LL | | n: UB
LL | | }
| |_^
+ |
+note: `UA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:10:1
+ |
+LL | / union UA {
+LL | | i: i32
+LL | | }
+ | |_^
+note: `UD` contains a field of type `UB`
+ --> $DIR/repr-packed-contains-align.rs:37:5
+ |
+LL | n: UB
+ | ^
+note: ...which contains a field of type `UA`
+ --> $DIR/repr-packed-contains-align.rs:15:5
+ |
+LL | a: UA
+ | ^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:41:1
|
LL | / union UE {
LL | | a: SA
LL | | }
| |_^
+ |
+note: `SA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:5:1
+ |
+LL | struct SA(i32);
+ | ^^^^^^^^^^^^^^^
-error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
+error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
--> $DIR/repr-packed-contains-align.rs:46:1
|
LL | / union UF {
LL | | n: SB
LL | | }
| |_^
+ |
+note: `SA` has a `#[repr(align)]` attribute
+ --> $DIR/repr-packed-contains-align.rs:5:1
+ |
+LL | struct SA(i32);
+ | ^^^^^^^^^^^^^^^
+note: `UF` contains a field of type `SB`
+ --> $DIR/repr-packed-contains-align.rs:47:5
+ |
+LL | n: SB
+ | ^
+note: ...which contains a field of type `SA`
+ --> $DIR/repr-packed-contains-align.rs:7:11
+ |
+LL | struct SB(SA);
+ | ^^
error: aborting due to 8 previous errors
--> $DIR/privacy-enum-ctor.rs:57:22
|
LL | let _: Z = m::n::Z;
- | ^
+ | ^ this enum is private
+ |
+note: the enum `Z` is defined here
+ --> $DIR/privacy-enum-ctor.rs:11:9
+ |
+LL | pub(in m) enum Z {
+ | ^^^^^^^^^^^^^^^^
error[E0603]: enum `Z` is private
--> $DIR/privacy-enum-ctor.rs:61:22
|
LL | let _: Z = m::n::Z::Fn;
- | ^
+ | ^ this enum is private
+ |
+note: the enum `Z` is defined here
+ --> $DIR/privacy-enum-ctor.rs:11:9
+ |
+LL | pub(in m) enum Z {
+ | ^^^^^^^^^^^^^^^^
error[E0603]: enum `Z` is private
--> $DIR/privacy-enum-ctor.rs:64:22
|
LL | let _: Z = m::n::Z::Struct;
- | ^
+ | ^ this enum is private
+ |
+note: the enum `Z` is defined here
+ --> $DIR/privacy-enum-ctor.rs:11:9
+ |
+LL | pub(in m) enum Z {
+ | ^^^^^^^^^^^^^^^^
error[E0603]: enum `Z` is private
--> $DIR/privacy-enum-ctor.rs:68:22
|
LL | let _: Z = m::n::Z::Unit {};
- | ^
+ | ^ this enum is private
+ |
+note: the enum `Z` is defined here
+ --> $DIR/privacy-enum-ctor.rs:11:9
+ |
+LL | pub(in m) enum Z {
+ | ^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> $DIR/privacy-enum-ctor.rs:27:20
| --------------- a constructor is private if any of the fields is private
...
LL | n::Z;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `Z` is defined here
+ --> $DIR/privacy-struct-ctor.rs:12:9
+ |
+LL | pub(in m) struct Z(pub(in m::n) u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `S` is private
--> $DIR/privacy-struct-ctor.rs:29:8
| -- a constructor is private if any of the fields is private
...
LL | m::S;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `S` is defined here
+ --> $DIR/privacy-struct-ctor.rs:6:5
+ |
+LL | pub struct S(u8);
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `S` is private
--> $DIR/privacy-struct-ctor.rs:31:19
| -- a constructor is private if any of the fields is private
...
LL | let _: S = m::S(2);
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `S` is defined here
+ --> $DIR/privacy-struct-ctor.rs:6:5
+ |
+LL | pub struct S(u8);
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `Z` is private
--> $DIR/privacy-struct-ctor.rs:35:11
| --------------- a constructor is private if any of the fields is private
...
LL | m::n::Z;
- | ^
+ | ^ this tuple struct constructor is private
+ |
+note: the tuple struct constructor `Z` is defined here
+ --> $DIR/privacy-struct-ctor.rs:12:9
+ |
+LL | pub(in m) struct Z(pub(in m::n) u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `S` is private
--> $DIR/privacy-struct-ctor.rs:41:16
|
LL | xcrate::m::S;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy-struct-ctor.rs:2:18
|
LL | pub struct S(u8);
| -- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `S` is defined here
+ --> $DIR/auxiliary/privacy-struct-ctor.rs:2:5
+ |
+LL | pub struct S(u8);
+ | ^^^^^^^^^^^^^^^^^
error[E0603]: tuple struct constructor `Z` is private
--> $DIR/privacy-struct-ctor.rs:45:19
|
LL | xcrate::m::n::Z;
- | ^
+ | ^ this tuple struct constructor is private
|
::: $DIR/auxiliary/privacy-struct-ctor.rs:5:28
|
LL | pub(in m) struct Z(pub(in m::n) u8);
| --------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `Z` is defined here
+ --> $DIR/auxiliary/privacy-struct-ctor.rs:5:9
+ |
+LL | pub(in m) struct Z(pub(in m::n) u8);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 10 previous errors
-#![feature(slice_patterns)]
-
pub fn main() {
let sl: &[u8] = b"foo";
error[E0004]: non-exhaustive patterns: `&[]` not covered
- --> $DIR/slice.rs:6:11
+ --> $DIR/slice.rs:4:11
|
LL | match sl {
| ^^ pattern `&[]` not covered
--> $DIR/struct.rs:23:32
|
LL | let ts_explicit = structs::TupleStruct(640, 480);
- | ^^^^^^^^^^^
+ | ^^^^^^^^^^^ this tuple struct constructor is private
|
::: $DIR/auxiliary/structs.rs:11:24
|
LL | pub struct TupleStruct(pub u16, pub u16);
| ---------------- a constructor is private if any of the fields is private
+ |
+note: the tuple struct constructor `TupleStruct` is defined here
+ --> $DIR/auxiliary/structs.rs:11:1
+ |
+LL | pub struct TupleStruct(pub u16, pub u16);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: unit struct `UnitStruct` is private
--> $DIR/struct.rs:32:32
|
LL | let us_explicit = structs::UnitStruct;
- | ^^^^^^^^^^
+ | ^^^^^^^^^^ this unit struct is private
+ |
+note: the unit struct `UnitStruct` is defined here
+ --> $DIR/auxiliary/structs.rs:8:1
+ |
+LL | pub struct UnitStruct;
+ | ^^^^^^^^^^^^^^^^^^^^^^
error[E0639]: cannot create non-exhaustive struct using struct expression
--> $DIR/struct.rs:7:14
--> $DIR/variant.rs:11:48
|
LL | let variant_tuple = NonExhaustiveVariants::Tuple(640);
- | ^^^^^
+ | ^^^^^ this tuple variant is private
+ |
+note: the tuple variant `Tuple` is defined here
+ --> $DIR/auxiliary/variants.rs:5:23
+ |
+LL | #[non_exhaustive] Tuple(u32),
+ | ^^^^^^^^^^
error[E0603]: unit variant `Unit` is private
--> $DIR/variant.rs:14:47
|
LL | let variant_unit = NonExhaustiveVariants::Unit;
- | ^^^^
+ | ^^^^ this unit variant is private
+ |
+note: the unit variant `Unit` is defined here
+ --> $DIR/auxiliary/variants.rs:4:23
+ |
+LL | #[non_exhaustive] Unit,
+ | ^^^^
error[E0603]: unit variant `Unit` is private
--> $DIR/variant.rs:18:32
|
LL | NonExhaustiveVariants::Unit => "",
- | ^^^^
+ | ^^^^ this unit variant is private
+ |
+note: the unit variant `Unit` is defined here
+ --> $DIR/auxiliary/variants.rs:4:23
+ |
+LL | #[non_exhaustive] Unit,
+ | ^^^^
error[E0603]: tuple variant `Tuple` is private
--> $DIR/variant.rs:20:32
|
LL | NonExhaustiveVariants::Tuple(fe_tpl) => "",
- | ^^^^^
+ | ^^^^^ this tuple variant is private
+ |
+note: the tuple variant `Tuple` is defined here
+ --> $DIR/auxiliary/variants.rs:5:23
+ |
+LL | #[non_exhaustive] Tuple(u32),
+ | ^^^^^^^^^^
error[E0603]: tuple variant `Tuple` is private
--> $DIR/variant.rs:26:35
|
LL | if let NonExhaustiveVariants::Tuple(fe_tpl) = variant_struct {
- | ^^^^^
+ | ^^^^^ this tuple variant is private
+ |
+note: the tuple variant `Tuple` is defined here
+ --> $DIR/auxiliary/variants.rs:5:23
+ |
+LL | #[non_exhaustive] Tuple(u32),
+ | ^^^^^^^^^^
error[E0639]: cannot create non-exhaustive variant using struct expression
--> $DIR/variant.rs:8:26
// run-pass
-#![feature(slice_patterns)]
fn slice_pat() {
let sl: &[u8] = b"foo";
--- /dev/null
+// needs-sanitizer-support
+// only-x86_64
+//
+// compile-flags: -Z sanitizer=address -O
+//
+// run-fail
+// error-pattern: AddressSanitizer: stack-buffer-overflow
+// error-pattern: 'xs' <== Memory access at offset
+
+#![feature(test)]
+
+use std::hint::black_box;
+use std::mem;
+
+fn main() {
+ let xs = [0, 1, 2, 3];
+ // Avoid optimizing everything out.
+ let xs = black_box(xs.as_ptr());
+ let code = unsafe { *xs.offset(4) };
+ std::process::exit(code);
+}
--- /dev/null
+// needs-sanitizer-support
+// only-x86_64
+//
+// compile-flags: -Z sanitizer=leak -O
+//
+// run-fail
+// error-pattern: LeakSanitizer: detected memory leaks
+
+#![feature(test)]
+
+use std::hint::black_box;
+use std::mem;
+
+fn main() {
+ for _ in 0..10 {
+ let xs = vec![1, 2, 3];
+ // Prevent compiler from removing the memory allocation.
+ let xs = black_box(xs);
+ mem::forget(xs);
+ }
+}
--- /dev/null
+// needs-sanitizer-support
+// only-linux
+// only-x86_64
+//
+// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
+//
+// run-fail
+// error-pattern: MemorySanitizer: use-of-uninitialized-value
+// error-pattern: Uninitialized value was created by an allocation
+// error-pattern: in the stack frame of function 'random'
+//
+// This test case intentionally limits the usage of the std,
+// since it will be linked with an uninstrumented version of it.
+
+#![feature(core_intrinsics)]
+#![feature(start)]
+#![feature(test)]
+
+use std::hint::black_box;
+use std::mem::MaybeUninit;
+
+#[inline(never)]
+#[no_mangle]
+fn random() -> [isize; 32] {
+ let r = unsafe { MaybeUninit::uninit().assume_init() };
+ // Avoid optimizing everything out.
+ black_box(r)
+}
+
+#[inline(never)]
+#[no_mangle]
+fn xor(a: &[isize]) -> isize {
+ let mut s = 0;
+ for i in 0..a.len() {
+ s = s ^ a[i];
+ }
+ s
+}
+
+#[start]
+fn main(_: isize, _: *const *const u8) -> isize {
+ let r = random();
+ xor(&r)
+}
--- /dev/null
+// ignore-tidy-linelength
+// compile-flags: -Z sanitizer=leak --target i686-unknown-linux-gnu
+// error-pattern: error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target
+
+#![feature(no_core)]
+#![no_core]
+#![no_main]
--- /dev/null
+error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target
+
+error: aborting due to previous error
+
}
mod bar {
- use foo::bar::f as g; //~ ERROR module `bar` is private
+ use foo::bar::f as g; //~ ERROR module import `bar` is private
use foo as f;
pub use foo::*;
}
-use bar::f::f; //~ ERROR module `f` is private
+use bar::f::f; //~ ERROR module import `f` is private
fn main() {}
-error[E0603]: module `bar` is private
+error[E0603]: module import `bar` is private
--> $DIR/shadowed-use-visibility.rs:9:14
|
LL | use foo::bar::f as g;
- | ^^^
+ | ^^^ this module import is private
+ |
+note: the module import `bar` is defined here
+ --> $DIR/shadowed-use-visibility.rs:4:9
+ |
+LL | use foo as bar;
+ | ^^^^^^^^^^
-error[E0603]: module `f` is private
+error[E0603]: module import `f` is private
--> $DIR/shadowed-use-visibility.rs:15:10
|
LL | use bar::f::f;
- | ^
+ | ^ this module import is private
+ |
+note: the module import `f` is defined here
+ --> $DIR/shadowed-use-visibility.rs:11:9
+ |
+LL | use foo as f;
+ | ^^^^^^^^
error: aborting due to 2 previous errors
+// FIXME: missing sysroot spans (#53081)
+// ignore-i586-unknown-linux-gnu
+// ignore-i586-unknown-linux-musl
+// ignore-i686-unknown-linux-musl
+
fn main() {
let _ = std::thread::thread_info::current_thread();
//~^ERROR module `thread_info` is private
error[E0603]: module `thread_info` is private
- --> $DIR/stability-in-private-module.rs:2:26
+ --> $DIR/stability-in-private-module.rs:7:26
|
LL | let _ = std::thread::thread_info::current_thread();
- | ^^^^^^^^^^^
+ | ^^^^^^^^^^^ this module is private
+ |
+note: the module `thread_info` is defined here
+ --> $SRC_DIR/libstd/thread/mod.rs:LL:COL
+ |
+LL | use crate::sys_common::thread_info;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
--> $DIR/static-priv-by-default2.rs:15:30
|
LL | use child::childs_child::private;
- | ^^^^^^^
+ | ^^^^^^^ this static is private
+ |
+note: the static `private` is defined here
+ --> $DIR/static-priv-by-default2.rs:7:9
+ |
+LL | static private: isize = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0603]: static `private` is private
--> $DIR/static-priv-by-default2.rs:23:33
|
LL | use static_priv_by_default::private;
- | ^^^^^^^
+ | ^^^^^^^ this static is private
+ |
+note: the static `private` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:3:1
+ |
+LL | static private: isize = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
--> $DIR/struct-variant-privacy-xc.rs:4:33
|
LL | fn f(b: struct_variant_privacy::Bar) {
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Bar` is defined here
+ --> $DIR/auxiliary/struct_variant_privacy.rs:1:1
+ |
+LL | enum Bar {
+ | ^^^^^^^^
error[E0603]: enum `Bar` is private
--> $DIR/struct-variant-privacy-xc.rs:6:33
|
LL | struct_variant_privacy::Bar::Baz { a: _a } => {}
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Bar` is defined here
+ --> $DIR/auxiliary/struct_variant_privacy.rs:1:1
+ |
+LL | enum Bar {
+ | ^^^^^^^^
error: aborting due to 2 previous errors
--> $DIR/struct-variant-privacy.rs:7:14
|
LL | fn f(b: foo::Bar) {
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Bar` is defined here
+ --> $DIR/struct-variant-privacy.rs:2:5
+ |
+LL | enum Bar {
+ | ^^^^^^^^
error[E0603]: enum `Bar` is private
--> $DIR/struct-variant-privacy.rs:9:14
|
LL | foo::Bar::Baz { a: _a } => {}
- | ^^^
+ | ^^^ this enum is private
+ |
+note: the enum `Bar` is defined here
+ --> $DIR/struct-variant-privacy.rs:2:5
+ |
+LL | enum Bar {
+ | ^^^^^^^^
error: aborting due to 2 previous errors
#![cfg(test)]
use std::io::Write;
+use std::env;
#[test]
fn it_works() {
fn it_exits() {
std::process::exit(123);
}
+
+#[test]
+fn no_residual_environment() {
+ for (key, _) in env::vars() {
+ // Look for keys like __RUST_TEST_INVOKE.
+ if key.contains("TEST_INVOKE") {
+ panic!("shouldn't have '{}' in environment", key);
+ }
+ }
+}
-running 4 tests
+running 5 tests
test it_exits ... FAILED
test it_fails ... FAILED
test it_panics ... ok
test it_works ... ok
+test no_residual_environment ... ok
failures:
testing321
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `2`,
- right: `5`', $DIR/test-panic-abort.rs:31:5
+ right: `5`', $DIR/test-panic-abort.rs:32:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
it_exits
it_fails
-test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
+test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
is_sync_send!((1..));
is_sync_send!(repeat(1));
is_sync_send!(empty::<usize>());
+ is_sync_send!(empty::<*mut i32>());
is_sync_send!(once(1));
// for option.rs
// run-pass
// pretty-expanded FIXME #23616
-#![feature(slice_patterns)]
-
fn f<T,>(_: T,) {}
struct Foo<T,>(T);
...
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
| - help: consider restricting this bound: `U: std::fmt::Debug`
+LL | 5u32
+ | ---- this returned value is of type `u32`
|
= help: the trait `std::fmt::Debug` is not implemented for `U`
= note: the return type of a function must have a statically known size
...
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
| - help: consider restricting this bound: `V: std::fmt::Debug`
+LL | 5u32
+ | ---- this returned value is of type `u32`
|
= help: the trait `std::fmt::Debug` is not implemented for `V`
= note: the return type of a function must have a statically known size
LL | fn ice(x: Box<dyn Iterator<Item=()>>) {
| - possibly return type missing here?
LL | *x
- | ^^ expected `()`, found trait `std::iter::Iterator`
+ | ^^ expected `()`, found trait object `dyn std::iter::Iterator`
|
= note: expected unit type `()`
found trait object `(dyn std::iter::Iterator<Item = ()> + 'static)`
#![feature(box_syntax)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
-#![feature(slice_patterns)]
+
#![deny(unreachable_patterns)]
mod foo {
--> $DIR/use-from-trait-xc.rs:14:24
|
LL | use use_from_trait_xc::Foo::new;
- | ^^^
+ | ^^^ this struct is private
+ |
+note: the struct `Foo` is defined here
+ --> $DIR/auxiliary/use-from-trait-xc.rs:9:1
+ |
+LL | struct Foo;
+ | ^^^^^^^^^^^
error[E0603]: struct `Foo` is private
--> $DIR/use-from-trait-xc.rs:17:24
|
LL | use use_from_trait_xc::Foo::C;
- | ^^^
+ | ^^^ this struct is private
+ |
+note: the struct `Foo` is defined here
+ --> $DIR/auxiliary/use-from-trait-xc.rs:9:1
+ |
+LL | struct Foo;
+ | ^^^^^^^^^^^
error: aborting due to 9 previous errors
--> $DIR/use-mod-3.rs:1:10
|
LL | use foo::bar::{
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `bar` is defined here
+ --> $DIR/use-mod-3.rs:9:5
+ |
+LL | mod bar { pub type Bar = isize; }
+ | ^^^^^^^
error[E0603]: module `bar` is private
--> $DIR/use-mod-3.rs:4:10
|
LL | use foo::bar::{
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `bar` is defined here
+ --> $DIR/use-mod-3.rs:9:5
+ |
+LL | mod bar { pub type Bar = isize; }
+ | ^^^^^^^
error: aborting due to 2 previous errors
--> $DIR/xcrate-private-by-default.rs:23:29
|
LL | static_priv_by_default::j;
- | ^
+ | ^ this static is private
+ |
+note: the static `j` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:47:1
+ |
+LL | static j: isize = 0;
+ | ^^^^^^^^^^^^^^^^^^^^
error[E0603]: function `k` is private
--> $DIR/xcrate-private-by-default.rs:25:29
|
LL | static_priv_by_default::k;
- | ^
+ | ^ this function is private
+ |
+note: the function `k` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:48:1
+ |
+LL | fn k() {}
+ | ^^^^^^
error[E0603]: unit struct `l` is private
--> $DIR/xcrate-private-by-default.rs:27:29
|
LL | static_priv_by_default::l;
- | ^
+ | ^ this unit struct is private
+ |
+note: the unit struct `l` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:49:1
+ |
+LL | struct l;
+ | ^^^^^^^^^
error[E0603]: enum `m` is private
--> $DIR/xcrate-private-by-default.rs:29:35
|
LL | foo::<static_priv_by_default::m>();
- | ^
+ | ^ this enum is private
+ |
+note: the enum `m` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:50:1
+ |
+LL | enum m {}
+ | ^^^^^^
error[E0603]: type alias `n` is private
--> $DIR/xcrate-private-by-default.rs:31:35
|
LL | foo::<static_priv_by_default::n>();
- | ^
+ | ^ this type alias is private
+ |
+note: the type alias `n` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:51:1
+ |
+LL | type n = isize;
+ | ^^^^^^^^^^^^^^^
error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:35:29
|
LL | static_priv_by_default::foo::a;
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `foo` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:12:1
+ |
+LL | mod foo {
+ | ^^^^^^^
error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:37:29
|
LL | static_priv_by_default::foo::b;
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `foo` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:12:1
+ |
+LL | mod foo {
+ | ^^^^^^^
error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:39:29
|
LL | static_priv_by_default::foo::c;
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `foo` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:12:1
+ |
+LL | mod foo {
+ | ^^^^^^^
error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:41:35
|
LL | foo::<static_priv_by_default::foo::d>();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `foo` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:12:1
+ |
+LL | mod foo {
+ | ^^^^^^^
error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:43:35
|
LL | foo::<static_priv_by_default::foo::e>();
- | ^^^
+ | ^^^ this module is private
+ |
+note: the module `foo` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:12:1
+ |
+LL | mod foo {
+ | ^^^^^^^
error: aborting due to 10 previous errors
-Subproject commit 920cdb59e1edf2c4cb2f266fa521f12c1b97a499
+Subproject commit fd0428f622feee209e6014b802f5717d48d9e978