diff --git a/Cargo.lock b/Cargo.lock index b54566e7176b0..8cbf6cf6869ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -434,9 +434,9 @@ dependencies = [ [[package]] name = "chalk-derive" -version = "0.11.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9bd01eab87277d973183a1d2e56bace1c11f8242c52c20636fb7dddf343ac9" +checksum = "d463e01905d607e181de72e8608721d3269f29176c9a14ce037011316ae7131d" dependencies = [ "proc-macro2 1.0.3", "quote 1.0.2", @@ -446,20 +446,21 @@ dependencies = [ [[package]] name = "chalk-engine" -version = "0.11.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c7a637c3d17ed555aef16e16952a5d1e127bd55178cc30be22afeb92da90c7d" +checksum = "efaf428f5398d36284f79690cf988762b7c091249f50a6c11db613a46c057000" dependencies = [ "chalk-derive", "chalk-ir", "rustc-hash", + "tracing", ] [[package]] name = "chalk-ir" -version = "0.11.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595e5735ded16c3f3dc348f7b15bbb2521a0080b1863cac38ad5271589944670" +checksum = "fd3fdc1e9f68498ffe80f4a23b0b95f1ca6fb21d5a4c9b0c085fab3ca712bdbe" dependencies = [ "chalk-derive", "lazy_static", @@ -467,9 +468,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.11.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d9d938139db425867a30cc0cfec0269406d8238d0571d829041eaa7a8455d11" +checksum = "5b9fd4102807b7ebe8fb034fa0f488c5656e1966d3261b558b81a08d519cdb29" dependencies = [ "chalk-derive", "chalk-engine", @@ -478,6 +479,7 @@ dependencies = [ "itertools 0.9.0", "petgraph", "rustc-hash", + "tracing", ] [[package]] @@ -5332,6 +5334,37 @@ dependencies = [ "syn 0.15.35", ] +[[package]] +name = "tracing" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41f40ed0e162c911ac6fcb53ecdc8134c46905fdbbae8c50add462a538b495f" +dependencies = [ + "cfg-if", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +dependencies = [ + "proc-macro2 1.0.3", + "quote 1.0.2", + "syn 1.0.11", +] + +[[package]] +name = "tracing-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" +dependencies = [ + "lazy_static", +] + [[package]] name = "try-lock" version = "0.2.2" @@ -5405,15 +5438,15 @@ dependencies = [ [[package]] name = "unicode-script" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b2c5c29e805da6817f5af6a627d65adb045cebf05cccd5a3493d6109454391c" +checksum = "58b33414ea8db4b7ea0343548dbdc31d27aef06beacf7044a87e564d9b0feb7d" [[package]] name = "unicode-security" -version = "0.0.3" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5f9011bbed9c13372bc8df618b55a38138445199caf3b61d432c6859c36dee0" +checksum = "5d87c28edc5b263377e448d6cdcb935c06b95413d8013ba6fae470558ccab18f" dependencies = [ "unicode-normalization", "unicode-script", diff --git a/config.toml.example b/config.toml.example index bc6760334170b..c0be7dded17bc 100644 --- a/config.toml.example +++ b/config.toml.example @@ -118,18 +118,24 @@ # nightlies are already produced for. The current platform must be able to run # binaries of this build triple and the nightly will be used to bootstrap the # first compiler. -#build = "x86_64-unknown-linux-gnu" # defaults to your host platform +# +# Defaults to host platform +#build = "x86_64-unknown-linux-gnu" # In addition to the build triple, other triples to produce full compiler # toolchains for. Each of these triples will be bootstrapped from the build # triple and then will continue to bootstrap themselves. This platform must # currently be able to run all of the triples provided here. -#host = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple +# +# Defaults to just the build triple +#host = ["x86_64-unknown-linux-gnu"] # In addition to all host triples, other triples to produce the standard library # for. Each host triple will be used to produce a copy of the standard library # for each target triple. -#target = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple +# +# Defaults to just the build triple +#target = ["x86_64-unknown-linux-gnu"] # Use this directory to store build artifacts. # You can use "$ROOT" to indicate the root of the git repository. @@ -174,7 +180,7 @@ # Python interpreter to use for various tasks throughout the build, notably # rustdoc tests, the lldb python interpreter, and some dist bits and pieces. # -# Defaults to the Python interpreter used to execute x.py. +# Defaults to the Python interpreter used to execute x.py #python = "python" # Force Cargo to check that Cargo.lock describes the precise dependency @@ -313,11 +319,15 @@ # Whether or not debug assertions are enabled for the compiler and standard # library. -#debug-assertions = debug +# +# Defaults to rust.debug value +#debug-assertions = false # Whether or not debug assertions are enabled for the standard library. # Overrides the `debug-assertions` option, if defined. -#debug-assertions-std = debug-assertions +# +# Defaults to rust.debug-assertions value +#debug-assertions-std = false # Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. # `0` - no debug info @@ -326,16 +336,24 @@ # Can be overridden for specific subsets of Rust code (rustc, std or tools). # Debuginfo for tests run with compiletest is not controlled by this option # and needs to be enabled separately with `debuginfo-level-tests`. -#debuginfo-level = if debug { 2 } else { 0 } +# +# Defaults to 2 if debug is true +#debuginfo-level = 0 # Debuginfo level for the compiler. -#debuginfo-level-rustc = debuginfo-level +# +# Defaults to rust.debuginfo-level value +#debuginfo-level-rustc = 0 # Debuginfo level for the standard library. -#debuginfo-level-std = debuginfo-level +# +# Defaults to rust.debuginfo-level value +#debuginfo-level-std = 0 # Debuginfo level for the tools. -#debuginfo-level-tools = debuginfo-level +# +# Defaults to rust.debuginfo-level value +#debuginfo-level-tools = 0 # Debuginfo level for the test suites run with compiletest. # FIXME(#61117): Some tests fail when this option is enabled. diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 82a755c7892b1..1949d70e5deea 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -184,6 +184,7 @@ def default_build_triple(): ostype = require(["uname", "-s"], exit=required) cputype = require(['uname', '-m'], exit=required) + # If we do not have `uname`, assume Windows. if ostype is None or cputype is None: return 'x86_64-pc-windows-msvc' @@ -236,6 +237,11 @@ def default_build_triple(): if ostype.endswith('WOW64'): cputype = 'x86_64' ostype = 'pc-windows-gnu' + elif sys.platform == 'win32': + # Some Windows platforms might have a `uname` command that returns a + # non-standard string (e.g. gnuwin32 tools returns `windows32`). In + # these cases, fall back to using sys.platform. + return 'x86_64-pc-windows-msvc' else: err = "unknown OS type: {}".format(ostype) sys.exit(err) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 8f0a245a5658a..0735ba8869add 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -23,7 +23,7 @@ use crate::install; use crate::native; use crate::run; use crate::test; -use crate::tool; +use crate::tool::{self, SourceType}; use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir}; use crate::{Build, DocTests, GitRepo, Mode}; @@ -759,6 +759,7 @@ impl<'a> Builder<'a> { &self, compiler: Compiler, mode: Mode, + source_type: SourceType, target: Interned, cmd: &str, ) -> Cargo { @@ -1125,7 +1126,7 @@ impl<'a> Builder<'a> { cargo.env("RUSTC_VERBOSE", self.verbosity.to_string()); - if !mode.is_tool() { + if source_type == SourceType::InTree { // When extending this list, add the new lints to the RUSTFLAGS of the // build_bootstrap function of src/bootstrap/bootstrap.py as well as // some code doesn't go through this `rustc` wrapper. diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 7a8bfb2d5d877..0d38d2eebe793 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -44,7 +44,13 @@ impl Step for Std { let target = self.target; let compiler = builder.compiler(0, builder.config.build); - let mut cargo = builder.cargo(compiler, Mode::Std, target, cargo_subcommand(builder.kind)); + let mut cargo = builder.cargo( + compiler, + Mode::Std, + SourceType::InTree, + target, + cargo_subcommand(builder.kind), + ); std_cargo(builder, target, compiler.stage, &mut cargo); builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target)); @@ -92,8 +98,13 @@ impl Step for Rustc { builder.ensure(Std { target }); - let mut cargo = - builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind)); + let mut cargo = builder.cargo( + compiler, + Mode::Rustc, + SourceType::InTree, + target, + cargo_subcommand(builder.kind), + ); rustc_cargo(builder, &mut cargo, target); builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target)); @@ -113,7 +124,7 @@ impl Step for Rustc { } macro_rules! tool_check_step { - ($name:ident, $path:expr) => { + ($name:ident, $path:expr, $source_type:expr) => { #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct $name { pub target: Interned, @@ -145,7 +156,7 @@ macro_rules! tool_check_step { target, cargo_subcommand(builder.kind), $path, - SourceType::InTree, + $source_type, &[], ); @@ -184,8 +195,12 @@ macro_rules! tool_check_step { }; } -tool_check_step!(Rustdoc, "src/tools/rustdoc"); -tool_check_step!(Clippy, "src/tools/clippy"); +tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree); +// Clippy is a hybrid. It is an external tool, but uses a git subtree instead +// of a submodule. Since the SourceType only drives the deny-warnings +// behavior, treat it as in-tree so that any new warnings in clippy will be +// rejected. +tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree); /// Cargo's output path for the standard library in a given stage, compiled /// by a particular compiler for the specified target. diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index afcf0dcac7e55..b07ff21755e0c 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -20,14 +20,14 @@ use filetime::FileTime; use serde::Deserialize; use crate::builder::Cargo; +use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; +use crate::cache::{Interned, INTERNER}; use crate::dist; use crate::native; +use crate::tool::SourceType; use crate::util::{exe, is_dylib, symlink_dir}; use crate::{Compiler, DependencyType, GitRepo, Mode}; -use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; -use crate::cache::{Interned, INTERNER}; - #[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)] pub struct Std { pub target: Interned, @@ -87,7 +87,7 @@ impl Step for Std { target_deps.extend(copy_third_party_objects(builder, &compiler, target)); target_deps.extend(copy_self_contained_objects(builder, &compiler, target)); - let mut cargo = builder.cargo(compiler, Mode::Std, target, "build"); + let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build"); std_cargo(builder, target, compiler.stage, &mut cargo); builder.info(&format!( @@ -131,26 +131,13 @@ fn copy_third_party_objects( compiler: &Compiler, target: Interned, ) -> Vec<(PathBuf, DependencyType)> { - let libdir = builder.sysroot_libdir(*compiler, target); let mut target_deps = vec![]; - // Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx. - // - // This target needs to be linked to Fortanix's port of llvm's libunwind. - // libunwind requires support for rwlock and printing to stderr, - // which is provided by std for this target. + // FIXME: remove this in 2021 if target == "x86_64-fortanix-unknown-sgx" { - let src_path_env = "X86_FORTANIX_SGX_LIBS"; - let src = - env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env)); - copy_and_stamp( - builder, - &*libdir, - Path::new(&src), - "libunwind.a", - &mut target_deps, - DependencyType::Target, - ); + if env::var_os("X86_FORTANIX_SGX_LIBS").is_some() { + builder.info("Warning: X86_FORTANIX_SGX_LIBS environment variable is ignored, libunwind is now compiled as part of rustbuild"); + } } if builder.config.sanitizers && compiler.stage != 0 { @@ -513,7 +500,7 @@ impl Step for Rustc { target: builder.config.build, }); - let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build"); + let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build"); rustc_cargo(builder, &mut cargo, target); builder.info(&format!( diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 6d7fb7acfcb04..8b76158f9e564 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -435,7 +435,8 @@ impl Step for Std { t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css"))); let run_cargo_rustdoc_for = |package: &str| { - let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc"); + let mut cargo = + builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc"); compile::std_cargo(builder, target, compiler.stage, &mut cargo); // Keep a whitelist so we do not build internal stdlib crates, these will be @@ -534,7 +535,7 @@ impl Step for Rustc { t!(symlink_dir_force(&builder.config, &out, &out_dir)); // Build cargo command. - let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc"); + let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc"); cargo.env( "RUSTDOCFLAGS", "--document-private-items \ diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index e7aeb08643c29..5728b9d24de99 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -301,16 +301,21 @@ pub enum Mode { /// Build codegen libraries, placing output in the "stageN-codegen" directory Codegen, - /// Build some tools, placing output in the "stageN-tools" directory. The - /// "other" here is for miscellaneous sets of tools that are built using the - /// bootstrap compiler in its entirety (target libraries and all). - /// Typically these tools compile with stable Rust. + /// Build a tool, placing output in the "stage0-bootstrap-tools" + /// directory. This is for miscellaneous sets of tools that are built + /// using the bootstrap stage0 compiler in its entirety (target libraries + /// and all). Typically these tools compile with stable Rust. ToolBootstrap, - /// Compile a tool which uses all libraries we compile (up to rustc). - /// Doesn't use the stage0 compiler libraries like "other", and includes - /// tools like rustdoc, cargo, rls, etc. + /// Build a tool which uses the locally built std, placing output in the + /// "stageN-tools" directory. Its usage is quite rare, mainly used by + /// compiletest which needs libtest. ToolStd, + + /// Build a tool which uses the locally built rustc and the target std, + /// placing the output in the "stageN-tools" directory. This is used for + /// anything that needs a fully functional rustc, such as rustdoc, clippy, + /// cargo, rls, rustfmt, miri, etc. ToolRustc, } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index bb35203c82604..12ab6b1636cc1 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -367,7 +367,8 @@ impl Step for Miri { extra_features: Vec::new(), }); if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) { - let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install"); + let mut cargo = + builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install"); cargo.arg("xargo"); // Configure `cargo install` path. cargo adds a `bin/`. cargo.env("CARGO_INSTALL_ROOT", &builder.out); @@ -1696,7 +1697,8 @@ impl Step for Crate { // we're working with automatically. let compiler = builder.compiler_for(compiler.stage, compiler.host, target); - let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand()); + let mut cargo = + builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand()); match mode { Mode::Std => { compile::std_cargo(builder, target, compiler.stage, &mut cargo); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index c92082a942316..0055dee609204 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -16,7 +16,7 @@ use crate::util::{add_dylib_path, exe, CiEnv}; use crate::Compiler; use crate::Mode; -#[derive(Debug, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum SourceType { InTree, Submodule, @@ -226,14 +226,10 @@ pub fn prepare_tool_cargo( source_type: SourceType, extra_features: &[String], ) -> CargoCommand { - let mut cargo = builder.cargo(compiler, mode, target, command); + let mut cargo = builder.cargo(compiler, mode, source_type, target, command); let dir = builder.src.join(path); cargo.arg("--manifest-path").arg(dir.join("Cargo.toml")); - if source_type == SourceType::Submodule { - cargo.env("RUSTC_EXTERNAL_TOOL", "1"); - } - let mut features = extra_features.to_vec(); if builder.build.config.cargo_native_static { if path.ends_with("cargo") @@ -596,6 +592,7 @@ macro_rules! tool_extended { $path:expr, $tool_name:expr, stable = $stable:expr, + $(in_tree = $in_tree:expr,)* $extra_deps:block;)+) => { $( #[derive(Debug, Clone, Hash, PartialEq, Eq)] @@ -647,7 +644,11 @@ macro_rules! tool_extended { path: $path, extra_features: $sel.extra_features, is_optional_tool: true, - source_type: SourceType::Submodule, + source_type: if false $(|| $in_tree)* { + SourceType::InTree + } else { + SourceType::Submodule + }, }) } } @@ -659,8 +660,8 @@ macro_rules! tool_extended { // to make `./x.py build ` work. tool_extended!((self, builder), Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {}; - CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, {}; - Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, {}; + CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {}; + Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {}; Miri, miri, "src/tools/miri", "miri", stable=false, {}; CargoMiri, miri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, {}; Rls, rls, "src/tools/rls", "rls", stable=true, { diff --git a/src/ci/docker/dist-various-2/Dockerfile b/src/ci/docker/dist-various-2/Dockerfile index 43f5581f996ea..1f1c246002352 100644 --- a/src/ci/docker/dist-various-2/Dockerfile +++ b/src/ci/docker/dist-various-2/Dockerfile @@ -71,9 +71,7 @@ RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc COPY dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/ COPY dist-various-2/x86_64-fortanix-unknown-sgx-clang-wrap.sh /usr/bin/x86_64-fortanix-unknown-sgx-clang-11 RUN ln -s /usr/bin/x86_64-fortanix-unknown-sgx-clang-11 /usr/bin/x86_64-fortanix-unknown-sgx-clang++-11 -# We pass the commit id of the port of LLVM's libunwind to the build script. -# Any update to the commit id here, should cause the container image to be re-built from this point on. -RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "800f95131fe6acd20b96b6f4723ca3c820f3d379" +RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh COPY dist-various-2/build-wasi-toolchain.sh /tmp/ RUN /tmp/build-wasi-toolchain.sh @@ -105,8 +103,6 @@ ENV TARGETS=$TARGETS,nvptx64-nvidia-cuda ENV TARGETS=$TARGETS,armv7-unknown-linux-gnueabi ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi -ENV X86_FORTANIX_SGX_LIBS="/x86_64-fortanix-unknown-sgx/lib/" - # As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211 # we need asm in the search path for gcc-7 (for gnux32) but not in the search path of the # cross compilers. diff --git a/src/ci/docker/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh b/src/ci/docker/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh index 4294b1ef93dd8..78bf4527feff1 100755 --- a/src/ci/docker/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh +++ b/src/ci/docker/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh @@ -3,14 +3,7 @@ set -eu source shared.sh -if [ -z "$1" ]; then - echo "Usage: ${0} " - exit -1 -fi - target="x86_64-fortanix-unknown-sgx" -url="https://github.com/fortanix/llvm-project/archive/${1}.tar.gz" -repo_name="llvm-project" install_prereq() { curl https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - @@ -24,39 +17,4 @@ install_prereq() { clang-11 } -build_unwind() { - set -x - dir_name="${target}_temp" - rm -rf ${dir_name} - mkdir -p ${dir_name} - pushd ${dir_name} - - # Clone Fortanix's fork of llvm-project which has a port of libunwind - fetch_github_commit_archive "$repo_name" "$url" - cd "${repo_name}/libunwind" - - # Build libunwind - mkdir -p build - cd build - target_CC="CC_${target//-/_}" - target_CXX="CXX_${target//-/_}" - target_CFLAGS="CFLAGS_${target//-/_}" - target_CXXFLAGS="CXXFLAGS_${target//-/_}" - cmake -DCMAKE_BUILD_TYPE="RELEASE" -DRUST_SGX=1 -G "Unix Makefiles" \ - -DCMAKE_C_COMPILER="${!target_CC}" -DCMAKE_CXX_COMPILER="${!target_CXX}" \ - -DCMAKE_C_FLAGS="${!target_CFLAGS}" -DCMAKE_CXX_FLAGS="${!target_CXXFLAGS}" \ - -DCMAKE_C_COMPILER_TARGET=$target -DCMAKE_CXX_COMPILER_TARGET=$target \ - -DLLVM_ENABLE_WARNINGS=1 -DLIBUNWIND_ENABLE_WERROR=1 -DLIBUNWIND_ENABLE_PEDANTIC=0 \ - -DLLVM_PATH=../../llvm/ ../ - make unwind_static - install -D "lib/libunwind.a" "/${target}/lib/libunwind.a" - - popd - rm -rf ${dir_name} - - { set +x; } 2>/dev/null -} - -set -x hide_output install_prereq -build_unwind diff --git a/src/doc/book b/src/doc/book index 30cd9dfe71c44..4e7c00bece154 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 30cd9dfe71c446de63826bb4472627af45acc9db +Subproject commit 4e7c00bece1544d409312ec93467beb62b5bd0cb diff --git a/src/doc/embedded-book b/src/doc/embedded-book index 5555a97f04ad7..616962ad0dd80 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit 5555a97f04ad7974ac6fb8fb47c267c4274adf4a +Subproject commit 616962ad0dd80f34d8b802da038d0aed9dd691bb diff --git a/src/doc/reference b/src/doc/reference index 5d40ba5c2515c..04d5d5d7ba624 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 5d40ba5c2515caffa7790cda621239dc21ef5a72 +Subproject commit 04d5d5d7ba624b6f5016298451f3a63d557f3260 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 7aa82129aa23e..6f94ccb48da6f 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 7aa82129aa23e7e181efbeb8da03a2a897ef6afc +Subproject commit 6f94ccb48da6fa4ed0031290f21411cf789f7d5e diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index a941bc9348f2c..c4c985dd134ba 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -474,7 +474,7 @@ Here is the list of currently supported register classes: | AArch64 | `reg` | `x[0-28]`, `x30` | `r` | | AArch64 | `vreg` | `v[0-31]` | `w` | | AArch64 | `vreg_low16` | `v[0-15]` | `x` | -| ARM | `reg` | `r[0-r10]`, `r12`, `r14` | `r` | +| ARM | `reg` | `r[0-5]` `r7`\*, `r[8-10]`, `r11`\*, `r12`, `r14` | `r` | | ARM (Thumb) | `reg_thumb` | `r[0-r7]` | `l` | | ARM (ARM) | `reg_thumb` | `r[0-r10]`, `r12`, `r14` | `l` | | ARM | `sreg` | `s[0-31]` | `t` | @@ -497,6 +497,8 @@ Here is the list of currently supported register classes: > Note #2: On x86-64 the high byte registers (e.g. `ah`) are only available when used as an explicit register. Specifying the `reg_byte` register class for an operand will always allocate a low byte register. > > Note #3: NVPTX doesn't have a fixed register set, so named registers are not supported. +> +> Note #4: On ARM the frame pointer is either `r7` or `r11` depending on the platform. Additional register classes may be added in the future based on demand (e.g. MMX, x87, etc). @@ -591,7 +593,9 @@ Some registers cannot be used for input or output operands: | Architecture | Unsupported register | Reason | | ------------ | -------------------- | ------ | | All | `sp` | The stack pointer must be restored to its original value at the end of an asm code block. | -| All | `bp` (x86), `r11` (ARM), `x29` (AArch64), `x8` (RISC-V), `fr` (Hexagon) | The frame pointer cannot be used as an input or output. | +| All | `bp` (x86), `x29` (AArch64), `x8` (RISC-V), `fr` (Hexagon) | The frame pointer cannot be used as an input or output. | +| ARM | `r7` or `r11` | On ARM the frame pointer can be either `r7` or `r11` depending on the target. The frame pointer cannot be used as an input or output. | +| ARM | `r6` | `r6` is used internally by LLVM as a base pointer and therefore cannot be used as an input or output. | | x86 | `k0` | This is a constant zero register which can't be modified. | | x86 | `ip` | This is the program counter, not a real register. | | x86 | `mm[0-7]` | MMX registers are not currently supported (but may be in the future). | diff --git a/src/liballoc/benches/lib.rs b/src/liballoc/benches/lib.rs index f31717d9fd517..608eafc88d2a6 100644 --- a/src/liballoc/benches/lib.rs +++ b/src/liballoc/benches/lib.rs @@ -1,3 +1,6 @@ +// Disabling on android for the time being +// See https://github.com/rust-lang/rust/issues/73535#event-3477699747 +#![cfg(not(target_os = "android"))] #![feature(btree_drain_filter)] #![feature(map_first_last)] #![feature(repr_simd)] diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index d10cbf1afab30..f1b560b9b9685 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -92,11 +92,13 @@ //! pub struct Foo; //! //! #[no_mangle] +//! #[allow(improper_ctypes_definitions)] //! pub extern "C" fn foo_new() -> Box { //! Box::new(Foo) //! } //! //! #[no_mangle] +//! #[allow(improper_ctypes_definitions)] //! pub extern "C" fn foo_delete(_: Option>) {} //! ``` //! diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 350249f5db519..bb9091a66594b 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -488,7 +488,7 @@ struct MergeIter> { } impl BTreeMap { - /// Makes a new empty BTreeMap with a reasonable choice for B. + /// Makes a new empty BTreeMap. /// /// Does not allocate anything on its own. /// @@ -1396,6 +1396,14 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> { fn last(mut self) -> Option<(&'a K, &'a V)> { self.next_back() } + + fn min(mut self) -> Option<(&'a K, &'a V)> { + self.next() + } + + fn max(mut self) -> Option<(&'a K, &'a V)> { + self.next_back() + } } #[stable(feature = "fused", since = "1.26.0")] @@ -1458,6 +1466,14 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> { fn last(mut self) -> Option<(&'a K, &'a mut V)> { self.next_back() } + + fn min(mut self) -> Option<(&'a K, &'a mut V)> { + self.next() + } + + fn max(mut self) -> Option<(&'a K, &'a mut V)> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1595,6 +1611,14 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> { fn last(mut self) -> Option<&'a K> { self.next_back() } + + fn min(mut self) -> Option<&'a K> { + self.next() + } + + fn max(mut self) -> Option<&'a K> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1768,6 +1792,14 @@ impl<'a, K, V> Iterator for Range<'a, K, V> { fn last(mut self) -> Option<(&'a K, &'a V)> { self.next_back() } + + fn min(mut self) -> Option<(&'a K, &'a V)> { + self.next() + } + + fn max(mut self) -> Option<(&'a K, &'a V)> { + self.next_back() + } } #[stable(feature = "map_values_mut", since = "1.10.0")] @@ -1853,6 +1885,14 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> { fn last(mut self) -> Option<(&'a K, &'a mut V)> { self.next_back() } + + fn min(mut self) -> Option<(&'a K, &'a mut V)> { + self.next() + } + + fn max(mut self) -> Option<(&'a K, &'a mut V)> { + self.next_back() + } } impl<'a, K, V> RangeMut<'a, K, V> { diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index 525ef38c32fa2..d8959966fe5ad 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -1291,12 +1291,22 @@ impl<'a, T> Iterator for Iter<'a, T> { fn next(&mut self) -> Option<&'a T> { self.iter.next() } + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } + fn last(mut self) -> Option<&'a T> { self.next_back() } + + fn min(mut self) -> Option<&'a T> { + self.next() + } + + fn max(mut self) -> Option<&'a T> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> DoubleEndedIterator for Iter<'a, T> { @@ -1321,6 +1331,7 @@ impl Iterator for IntoIter { fn next(&mut self) -> Option { self.iter.next().map(|(k, _)| k) } + fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } @@ -1359,6 +1370,14 @@ impl<'a, T> Iterator for Range<'a, T> { fn last(mut self) -> Option<&'a T> { self.next_back() } + + fn min(mut self) -> Option<&'a T> { + self.next() + } + + fn max(mut self) -> Option<&'a T> { + self.next_back() + } } #[stable(feature = "btree_range", since = "1.17.0")] @@ -1429,6 +1448,10 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> { }; (self_len.saturating_sub(other_len), Some(self_len)) } + + fn min(mut self) -> Option<&'a T> { + self.next() + } } #[stable(feature = "fused", since = "1.26.0")] @@ -1460,6 +1483,10 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> { // the number of elements to less than half the range of usize. (0, Some(a_len + b_len)) } + + fn min(mut self) -> Option<&'a T> { + self.next() + } } #[stable(feature = "fused", since = "1.26.0")] @@ -1516,6 +1543,10 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> { IntersectionInner::Answer(Some(_)) => (1, Some(1)), } } + + fn min(mut self) -> Option<&'a T> { + self.next() + } } #[stable(feature = "fused", since = "1.26.0")] @@ -1541,6 +1572,10 @@ impl<'a, T: Ord> Iterator for Union<'a, T> { // No checked_add - see SymmetricDifference::size_hint. (max(a_len, b_len), Some(a_len + b_len)) } + + fn min(mut self) -> Option<&'a T> { + self.next() + } } #[stable(feature = "fused", since = "1.26.0")] diff --git a/src/liballoc/collections/vec_deque/tests.rs b/src/liballoc/collections/vec_deque/tests.rs index fc2ec7908e823..960af4bfda053 100644 --- a/src/liballoc/collections/vec_deque/tests.rs +++ b/src/liballoc/collections/vec_deque/tests.rs @@ -1,7 +1,5 @@ use super::*; -use test; - #[bench] #[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks fn bench_push_back_100(b: &mut test::Bencher) { diff --git a/src/liballoc/raw_vec/tests.rs b/src/liballoc/raw_vec/tests.rs index 6418c4a9823f2..5408faa079c15 100644 --- a/src/liballoc/raw_vec/tests.rs +++ b/src/liballoc/raw_vec/tests.rs @@ -12,7 +12,6 @@ fn allocator_param() { // // Instead, this just checks that the `RawVec` methods do at // least go through the Allocator API when it reserves - // storage. // A dumb allocator that consumes a fixed amount of fuel diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs index 731a1b5f875b7..682d829d219f3 100644 --- a/src/liballoc/tests/btree/map.rs +++ b/src/liballoc/tests/btree/map.rs @@ -309,6 +309,41 @@ fn test_iter_mixed() { test(size, map.into_iter()); } +#[test] +fn test_iter_min_max() { + let mut a = BTreeMap::new(); + assert_eq!(a.iter().min(), None); + assert_eq!(a.iter().max(), None); + assert_eq!(a.iter_mut().min(), None); + assert_eq!(a.iter_mut().max(), None); + assert_eq!(a.range(..).min(), None); + assert_eq!(a.range(..).max(), None); + assert_eq!(a.range_mut(..).min(), None); + assert_eq!(a.range_mut(..).max(), None); + assert_eq!(a.keys().min(), None); + assert_eq!(a.keys().max(), None); + assert_eq!(a.values().min(), None); + assert_eq!(a.values().max(), None); + assert_eq!(a.values_mut().min(), None); + assert_eq!(a.values_mut().max(), None); + a.insert(1, 42); + a.insert(2, 24); + assert_eq!(a.iter().min(), Some((&1, &42))); + assert_eq!(a.iter().max(), Some((&2, &24))); + assert_eq!(a.iter_mut().min(), Some((&1, &mut 42))); + assert_eq!(a.iter_mut().max(), Some((&2, &mut 24))); + assert_eq!(a.range(..).min(), Some((&1, &42))); + assert_eq!(a.range(..).max(), Some((&2, &24))); + assert_eq!(a.range_mut(..).min(), Some((&1, &mut 42))); + assert_eq!(a.range_mut(..).max(), Some((&2, &mut 24))); + assert_eq!(a.keys().min(), Some(&1)); + assert_eq!(a.keys().max(), Some(&2)); + assert_eq!(a.values().min(), Some(&24)); + assert_eq!(a.values().max(), Some(&42)); + assert_eq!(a.values_mut().min(), Some(&mut 24)); + assert_eq!(a.values_mut().max(), Some(&mut 42)); +} + fn range_keys(map: &BTreeMap, range: impl RangeBounds) -> Vec { map.range(range) .map(|(&k, &v)| { diff --git a/src/liballoc/tests/btree/set.rs b/src/liballoc/tests/btree/set.rs index 75251ca0d51e9..b6c34b7c6c346 100644 --- a/src/liballoc/tests/btree/set.rs +++ b/src/liballoc/tests/btree/set.rs @@ -33,6 +33,37 @@ fn test_hash() { assert_eq!(hash(&x), hash(&y)); } +#[test] +fn test_iter_min_max() { + let mut a = BTreeSet::new(); + assert_eq!(a.iter().min(), None); + assert_eq!(a.iter().max(), None); + assert_eq!(a.range(..).min(), None); + assert_eq!(a.range(..).max(), None); + assert_eq!(a.difference(&BTreeSet::new()).min(), None); + assert_eq!(a.difference(&BTreeSet::new()).max(), None); + assert_eq!(a.intersection(&a).min(), None); + assert_eq!(a.intersection(&a).max(), None); + assert_eq!(a.symmetric_difference(&BTreeSet::new()).min(), None); + assert_eq!(a.symmetric_difference(&BTreeSet::new()).max(), None); + assert_eq!(a.union(&a).min(), None); + assert_eq!(a.union(&a).max(), None); + a.insert(1); + a.insert(2); + assert_eq!(a.iter().min(), Some(&1)); + assert_eq!(a.iter().max(), Some(&2)); + assert_eq!(a.range(..).min(), Some(&1)); + assert_eq!(a.range(..).max(), Some(&2)); + assert_eq!(a.difference(&BTreeSet::new()).min(), Some(&1)); + assert_eq!(a.difference(&BTreeSet::new()).max(), Some(&2)); + assert_eq!(a.intersection(&a).min(), Some(&1)); + assert_eq!(a.intersection(&a).max(), Some(&2)); + assert_eq!(a.symmetric_difference(&BTreeSet::new()).min(), Some(&1)); + assert_eq!(a.symmetric_difference(&BTreeSet::new()).max(), Some(&2)); + assert_eq!(a.union(&a).min(), Some(&1)); + assert_eq!(a.union(&a).max(), Some(&2)); +} + fn check(a: &[i32], b: &[i32], expected: &[i32], f: F) where F: FnOnce(&BTreeSet, &BTreeSet, &mut dyn FnMut(&i32) -> bool) -> bool, diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index fc8a992e1701b..c2cf64393adf8 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -62,7 +62,7 @@ use core::array::LengthAtMost32; use core::cmp::{self, Ordering}; use core::fmt; -use core::hash::{self, Hash}; +use core::hash::{Hash, Hasher}; use core::intrinsics::{arith_offset, assume}; use core::iter::{FromIterator, FusedIterator, TrustedLen}; use core::marker::PhantomData; @@ -1801,6 +1801,21 @@ impl SpecFromElem for T { } } +impl SpecFromElem for i8 { + #[inline] + fn from_elem(elem: i8, n: usize) -> Vec { + if elem == 0 { + return Vec { buf: RawVec::with_capacity_zeroed(n), len: n }; + } + unsafe { + let mut v = Vec::with_capacity(n); + ptr::write_bytes(v.as_mut_ptr(), elem as u8, n); + v.set_len(n); + v + } + } +} + impl SpecFromElem for u8 { #[inline] fn from_elem(elem: u8, n: usize) -> Vec { @@ -1845,7 +1860,6 @@ macro_rules! impl_is_zero { }; } -impl_is_zero!(i8, |x| x == 0); impl_is_zero!(i16, |x| x == 0); impl_is_zero!(i32, |x| x == 0); impl_is_zero!(i64, |x| x == 0); @@ -1943,7 +1957,7 @@ impl Clone for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for Vec { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { Hash::hash(&**self, state) } } diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs index 5ff52a9a11b5a..46ba0a279b7ff 100644 --- a/src/libcore/convert/num.rs +++ b/src/libcore/convert/num.rs @@ -445,3 +445,42 @@ nzint_impl_from! { NonZeroU16, NonZeroI128, #[stable(feature = "nz_int_conv", si nzint_impl_from! { NonZeroU32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } nzint_impl_from! { NonZeroU32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } + +macro_rules! nzint_impl_try_from_int { + ($Int: ty, $NonZeroInt: ty, #[$attr:meta], $doc: expr) => { + #[$attr] + #[doc = $doc] + impl TryFrom<$Int> for $NonZeroInt { + type Error = TryFromIntError; + + #[inline] + fn try_from(value: $Int) -> Result { + Self::new(value).ok_or(TryFromIntError(())) + } + } + }; + ($Int: ty, $NonZeroInt: ty, #[$attr:meta]) => { + nzint_impl_try_from_int!($Int, + $NonZeroInt, + #[$attr], + concat!("Attempts to convert `", + stringify!($Int), + "` to `", + stringify!($NonZeroInt), + "`.")); + } +} + +// Int -> Non-zero Int +nzint_impl_try_from_int! { u8, NonZeroU8, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { u16, NonZeroU16, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { u32, NonZeroU32, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { u64, NonZeroU64, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { u128, NonZeroU128, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { usize, NonZeroUsize, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { i8, NonZeroI8, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { i16, NonZeroI16, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { i32, NonZeroI32, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { i64, NonZeroI64, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { i128, NonZeroI128, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } +nzint_impl_try_from_int! { isize, NonZeroIsize, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 2298958b88101..5d09018759191 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1917,6 +1917,15 @@ extern "rust-intrinsic" { #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")] pub fn discriminant_value(v: &T) -> ::Discriminant; + /// Returns the number of variants of the type `T` cast to a `usize`; + /// if `T` has no variants, returns 0. Uninhabited variants will be counted. + /// + /// The to-be-stabilized version of this intrinsic is + /// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html) + #[rustc_const_unstable(feature = "variant_count", issue = "73662")] + #[cfg(not(bootstrap))] + pub fn variant_count() -> usize; + /// Rust's "try catch" construct which invokes the function pointer `try_fn` /// with the data pointer `data`. /// @@ -1960,6 +1969,12 @@ extern "rust-intrinsic" { pub fn ptr_guaranteed_ne(ptr: *const T, other: *const T) -> bool; } +#[rustc_const_unstable(feature = "variant_count", issue = "73662")] +#[cfg(bootstrap)] +pub const fn variant_count() -> usize { + 0 +} + // Some functions are defined here because they accidentally got made // available in this module on stable. See . // (`transmute` also falls into this category, but it cannot be wrapped due to the diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 4eb2fdbd07868..2b26e5303a89c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -124,6 +124,7 @@ #![feature(unsized_locals)] #![feature(untagged_unions)] #![feature(unwind_attributes)] +#![feature(variant_count)] #![feature(doc_alias)] #![feature(mmx_target_feature)] #![feature(tbm_target_feature)] diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index 066bb8b3dc787..46e6ea7cd1866 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -358,12 +358,13 @@ pub fn size_of_val(val: &T) -> usize { /// - an (unstable) [extern type], then this function is always safe to /// call, but may panic or otherwise return the wrong value, as the /// extern type's layout is not known. This is the same behavior as -/// [`size_of_val`] on a reference to an extern type tail. +/// [`size_of_val`] on a reference to a type with an extern type tail. /// - otherwise, it is conservatively not allowed to call this function. /// /// [slice]: ../../std/primitive.slice.html /// [trait object]: ../../book/ch17-02-trait-objects.html /// [extern type]: ../../unstable-book/language-features/extern-types.html +/// [`size_of_val`]: ../../core/mem/fn.size_of_val.html /// /// # Examples /// @@ -492,12 +493,13 @@ pub fn align_of_val(val: &T) -> usize { /// - an (unstable) [extern type], then this function is always safe to /// call, but may panic or otherwise return the wrong value, as the /// extern type's layout is not known. This is the same behavior as -/// [`align_of_val`] on a reference to an extern type tail. +/// [`align_of_val`] on a reference to a type with an extern type tail. /// - otherwise, it is conservatively not allowed to call this function. /// /// [slice]: ../../std/primitive.slice.html /// [trait object]: ../../book/ch17-02-trait-objects.html /// [extern type]: ../../unstable-book/language-features/extern-types.html +/// [`align_of_val`]: ../../core/mem/fn.align_of_val.html /// /// # Examples /// @@ -999,3 +1001,33 @@ impl fmt::Debug for Discriminant { pub const fn discriminant(v: &T) -> Discriminant { Discriminant(intrinsics::discriminant_value(v)) } + +/// Returns the number of variants in the enum type `T`. +/// +/// If `T` is not an enum, calling this function will not result in undefined behavior, but the +/// return value is unspecified. Equally, if `T` is an enum with more variants than `usize::MAX` +/// the return value is unspecified. Uninhabited variants will be counted. +/// +/// # Examples +/// +/// ``` +/// # #![feature(never_type)] +/// # #![feature(variant_count)] +/// +/// use std::mem; +/// +/// enum Void {} +/// enum Foo { A(&'static str), B(i32), C(i32) } +/// +/// assert_eq!(mem::variant_count::(), 0); +/// assert_eq!(mem::variant_count::(), 3); +/// +/// assert_eq!(mem::variant_count::>(), 2); +/// assert_eq!(mem::variant_count::>(), 2); +/// ``` +#[inline(always)] +#[unstable(feature = "variant_count", issue = "73662")] +#[rustc_const_unstable(feature = "variant_count", issue = "73662")] +pub const fn variant_count() -> usize { + intrinsics::variant_count::() +} diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index 04c7789fa4ff4..2cdfee87a3546 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -224,6 +224,7 @@ pub trait FnMut: FnOnce { #[must_use = "closures are lazy and do nothing unless called"] pub trait FnOnce { /// The returned type after the call operator is used. + #[cfg_attr(not(bootstrap), lang = "fn_once_output")] #[stable(feature = "fn_once_output", since = "1.12.0")] type Output; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 5f0a12678ff43..7aca6af3de6f3 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -142,11 +142,6 @@ use crate::{ ops::{self, Deref, DerefMut}, }; -// Note that this is not a lang item per se, but it has a hidden dependency on -// `Iterator`, which is one. The compiler assumes that the `next` method of -// `Iterator` is an enumeration with one type parameter and two variants, -// which basically means it must be `Option`. - /// The `Option` type. See [the module level documentation](index.html) for more. #[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] #[rustc_diagnostic_item = "option_type"] diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs index 395b3879cfd0c..64a506a6377f2 100644 --- a/src/libcore/ptr/const_ptr.rs +++ b/src/libcore/ptr/const_ptr.rs @@ -316,7 +316,6 @@ impl *const T { /// differently have not been explored. This method should not be used to introduce such /// differences, and it should also not be stabilized before we have a better understanding /// of this issue. - /// ``` #[unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[inline] @@ -349,7 +348,6 @@ impl *const T { /// differently have not been explored. This method should not be used to introduce such /// differences, and it should also not be stabilized before we have a better understanding /// of this issue. - /// ``` #[unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[inline] diff --git a/src/libcore/ptr/mut_ptr.rs b/src/libcore/ptr/mut_ptr.rs index b86ef5b13b353..6b5cd9fdb854d 100644 --- a/src/libcore/ptr/mut_ptr.rs +++ b/src/libcore/ptr/mut_ptr.rs @@ -294,7 +294,6 @@ impl *mut T { /// differently have not been explored. This method should not be used to introduce such /// differences, and it should also not be stabilized before we have a better understanding /// of this issue. - /// ``` #[unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[inline] @@ -327,7 +326,6 @@ impl *mut T { /// differently have not been explored. This method should not be used to introduce such /// differences, and it should also not be stabilized before we have a better understanding /// of this issue. - /// ``` #[unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[inline] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index c69aafe687cf8..57bacdd99eff4 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2817,6 +2817,7 @@ pub trait SliceIndex: private_slice_index::Sealed { /// performing any bounds checking. /// Calling this method with an out-of-bounds index is *[undefined behavior]* /// even if the resulting reference is not used. + /// /// [undefined behavior]: ../../reference/behavior-considered-undefined.html #[unstable(feature = "slice_index_methods", issue = "none")] unsafe fn get_unchecked(self, slice: &T) -> &Self::Output; @@ -2825,6 +2826,7 @@ pub trait SliceIndex: private_slice_index::Sealed { /// performing any bounds checking. /// Calling this method with an out-of-bounds index is *[undefined behavior]* /// even if the resulting reference is not used. + /// /// [undefined behavior]: ../../reference/behavior-considered-undefined.html #[unstable(feature = "slice_index_methods", issue = "none")] unsafe fn get_unchecked_mut(self, slice: &mut T) -> &mut Self::Output; diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs index 0227a66b8633a..48aec6d718d3d 100644 --- a/src/libcore/tests/nonzero.rs +++ b/src/libcore/tests/nonzero.rs @@ -1,3 +1,4 @@ +use core::convert::TryFrom; use core::num::{IntErrorKind, NonZeroI32, NonZeroI8, NonZeroU32, NonZeroU8}; use core::option::Option::{self, None, Some}; use std::mem::size_of; @@ -176,3 +177,21 @@ fn test_nonzero_bitor_assign() { target |= 0; assert_eq!(target.get(), 0b1011_1111); } + +#[test] +fn test_nonzero_from_int_on_success() { + assert_eq!(NonZeroU8::try_from(5), Ok(NonZeroU8::new(5).unwrap())); + assert_eq!(NonZeroU32::try_from(5), Ok(NonZeroU32::new(5).unwrap())); + + assert_eq!(NonZeroI8::try_from(-5), Ok(NonZeroI8::new(-5).unwrap())); + assert_eq!(NonZeroI32::try_from(-5), Ok(NonZeroI32::new(-5).unwrap())); +} + +#[test] +fn test_nonzero_from_int_on_err() { + assert!(NonZeroU8::try_from(0).is_err()); + assert!(NonZeroU32::try_from(0).is_err()); + + assert!(NonZeroI8::try_from(0).is_err()); + assert!(NonZeroI32::try_from(0).is_err()); +} diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs index fd3e11858cef6..27056d5f934fd 100644 --- a/src/libpanic_abort/lib.rs +++ b/src/libpanic_abort/lib.rs @@ -21,6 +21,7 @@ use core::any::Any; #[rustc_std_internal_symbol] +#[cfg_attr(not(bootstrap), allow(improper_ctypes_definitions))] pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Send + 'static) { unreachable!() } diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index f791fe82a27e7..f361354da2ac2 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -81,6 +81,7 @@ extern "C" { mod dwarf; #[rustc_std_internal_symbol] +#[cfg_attr(not(bootstrap), allow(improper_ctypes_definitions))] pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) { Box::into_raw(imp::cleanup(payload)) } diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index e98d709539d79..99fbb1ee3ea83 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -335,6 +335,8 @@ pub enum GenericParamKind { }, Const { ty: P, + /// Span of the `const` keyword. + kw_span: Span, }, } diff --git a/src/librustc_ast/attr/mod.rs b/src/librustc_ast/attr/mod.rs index b812f2dadf6d4..6c128f0176f66 100644 --- a/src/librustc_ast/attr/mod.rs +++ b/src/librustc_ast/attr/mod.rs @@ -475,7 +475,7 @@ impl MetaItem { let span = span.with_hi(segments.last().unwrap().ident.span.hi()); Path { span, segments } } - Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt { + Some(TokenTree::Token(Token { kind: token::Interpolated(nt, _), .. })) => match *nt { token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span), token::Nonterminal::NtPath(ref path) => path.clone(), _ => return None, diff --git a/src/librustc_ast/mut_visit.rs b/src/librustc_ast/mut_visit.rs index 2ffef9d48c181..3fd2815daa14f 100644 --- a/src/librustc_ast/mut_visit.rs +++ b/src/librustc_ast/mut_visit.rs @@ -656,7 +656,7 @@ pub fn noop_visit_token(t: &mut Token, vis: &mut T) { *span = ident.span; return; // Avoid visiting the span for the second time. } - token::Interpolated(nt) => { + token::Interpolated(nt, _) => { let mut nt = Lrc::make_mut(nt); vis.visit_interpolated(&mut nt); } @@ -762,7 +762,7 @@ pub fn noop_flat_map_generic_param( GenericParamKind::Type { default } => { visit_opt(default, |default| vis.visit_ty(default)); } - GenericParamKind::Const { ty } => { + GenericParamKind::Const { ty, kw_span: _ } => { vis.visit_ty(ty); } } diff --git a/src/librustc_ast/token.rs b/src/librustc_ast/token.rs index a5b9c2a95bbea..89be3e6e212cc 100644 --- a/src/librustc_ast/token.rs +++ b/src/librustc_ast/token.rs @@ -182,6 +182,15 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool { .contains(&name) } +/// A hack used to pass AST fragments to attribute and derive macros +/// as a single nonterminal token instead of a token stream. +/// FIXME: It needs to be removed, but there are some compatibility issues (see #73345). +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +pub enum FlattenGroup { + Yes, + No, +} + #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum TokenKind { /* Expression-operator symbols. */ @@ -236,7 +245,7 @@ pub enum TokenKind { /// treat regular and interpolated lifetime identifiers in the same way. Lifetime(Symbol), - Interpolated(Lrc), + Interpolated(Lrc, FlattenGroup), // Can be expanded into several tokens. /// A doc comment. @@ -343,7 +352,7 @@ impl Token { /// if they keep spans or perform edition checks. pub fn uninterpolated_span(&self) -> Span { match &self.kind { - Interpolated(nt) => nt.span(), + Interpolated(nt, _) => nt.span(), _ => self.span, } } @@ -382,7 +391,7 @@ impl Token { ModSep | // global path Lifetime(..) | // labeled loop Pound => true, // expression attributes - Interpolated(ref nt) => match **nt { + Interpolated(ref nt, _) => match **nt { NtLiteral(..) | NtExpr(..) | NtBlock(..) | @@ -408,7 +417,7 @@ impl Token { Lifetime(..) | // lifetime bound in trait object Lt | BinOp(Shl) | // associated path ModSep => true, // global path - Interpolated(ref nt) => match **nt { + Interpolated(ref nt, _) => match **nt { NtTy(..) | NtPath(..) => true, _ => false, }, @@ -420,7 +429,7 @@ impl Token { pub fn can_begin_const_arg(&self) -> bool { match self.kind { OpenDelim(Brace) => true, - Interpolated(ref nt) => match **nt { + Interpolated(ref nt, _) => match **nt { NtExpr(..) | NtBlock(..) | NtLiteral(..) => true, _ => false, }, @@ -455,7 +464,7 @@ impl Token { match self.uninterpolate().kind { Literal(..) | BinOp(Minus) => true, Ident(name, false) if name.is_bool_lit() => true, - Interpolated(ref nt) => match &**nt { + Interpolated(ref nt, _) => match &**nt { NtLiteral(_) => true, NtExpr(e) => match &e.kind { ast::ExprKind::Lit(_) => true, @@ -476,7 +485,7 @@ impl Token { // otherwise returns the original token. pub fn uninterpolate(&self) -> Cow<'_, Token> { match &self.kind { - Interpolated(nt) => match **nt { + Interpolated(nt, _) => match **nt { NtIdent(ident, is_raw) => { Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span)) } @@ -523,7 +532,7 @@ impl Token { /// Returns `true` if the token is an interpolated path. fn is_path(&self) -> bool { - if let Interpolated(ref nt) = self.kind { + if let Interpolated(ref nt, _) = self.kind { if let NtPath(..) = **nt { return true; } @@ -535,7 +544,7 @@ impl Token { /// That is, is this a pre-parsed expression dropped into the token stream /// (which happens while parsing the result of macro expansion)? pub fn is_whole_expr(&self) -> bool { - if let Interpolated(ref nt) = self.kind { + if let Interpolated(ref nt, _) = self.kind { if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt { return true; } @@ -546,7 +555,7 @@ impl Token { // Is the token an interpolated block (`$b:block`)? pub fn is_whole_block(&self) -> bool { - if let Interpolated(ref nt) = self.kind { + if let Interpolated(ref nt, _) = self.kind { if let NtBlock(..) = **nt { return true; } @@ -724,7 +733,7 @@ impl Token { b == d && (a == c || a == kw::DollarCrate || c == kw::DollarCrate) } - (&Interpolated(_), &Interpolated(_)) => false, + (&Interpolated(..), &Interpolated(..)) => false, _ => panic!("forgot to add a token?"), } diff --git a/src/librustc_ast/util/literal.rs b/src/librustc_ast/util/literal.rs index 4428d09902b92..ea59f867c59d2 100644 --- a/src/librustc_ast/util/literal.rs +++ b/src/librustc_ast/util/literal.rs @@ -205,7 +205,7 @@ impl Lit { token::Lit::new(token::Bool, name, None) } token::Literal(lit) => lit, - token::Interpolated(ref nt) => { + token::Interpolated(ref nt, _) => { if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt { if let ast::ExprKind::Lit(lit) = &expr.kind { return Ok(lit.clone()); diff --git a/src/librustc_ast/util/parser.rs b/src/librustc_ast/util/parser.rs index d8b44a22f2c92..e5bcc571d4176 100644 --- a/src/librustc_ast/util/parser.rs +++ b/src/librustc_ast/util/parser.rs @@ -5,7 +5,7 @@ use rustc_span::symbol::kw; /// Associative operator with precedence. /// /// This is the enum which specifies operator precedence and fixity to the parser. -#[derive(PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum AssocOp { /// `+` Add, diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs index b7894eb145b0a..d2c4478ccfeb6 100644 --- a/src/librustc_ast_lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -1001,6 +1001,7 @@ impl<'hir> LoweringContext<'_, 'hir> { asm::InlineAsmReg::parse( sess.asm_arch?, |feature| sess.target_features.contains(&Symbol::intern(feature)), + &sess.target.target, s, ) .map_err(|e| { diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 39b14ac458832..863f525bdc8f3 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -1027,7 +1027,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_token(&mut self, token: Token) -> TokenStream { match token.kind { - token::Interpolated(nt) => { + token::Interpolated(nt, _) => { let tts = (self.nt_to_tokenstream)(&nt, &self.sess.parse_sess, token.span); self.lower_token_stream(tts) } @@ -2230,7 +2230,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { (hir::ParamName::Plain(param.ident), kind) } - GenericParamKind::Const { ref ty } => { + GenericParamKind::Const { ref ty, kw_span: _ } => { let ty = self .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { this.lower_ty(&ty, ImplTraitContext::disallowed()) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 8eb125e444053..975881d9a0ac0 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -1135,9 +1135,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { generics.params.iter().map(|param| { let ident = Some(param.ident.to_string()); let (kind, ident) = match ¶m.kind { - GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, ident), - GenericParamKind::Type { .. } => (ParamKindOrd::Type, ident), - GenericParamKind::Const { ref ty } => { + GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident), + GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident), + GenericParamKind::Const { ref ty, kw_span: _ } => { let ty = pprust::ty_to_string(ty); (ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty))) } diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index b1abc08aa67b0..86faa1f086ce2 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -266,7 +266,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option) token::Shebang(s) => format!("/* shebang: {}*/", s), token::Unknown(s) => s.to_string(), - token::Interpolated(ref nt) => nonterminal_to_string(nt), + token::Interpolated(ref nt, _) => nonterminal_to_string(nt), } } @@ -2578,7 +2578,7 @@ impl<'a> State<'a> { s.print_type(default) } } - ast::GenericParamKind::Const { ref ty } => { + ast::GenericParamKind::Const { ref ty, kw_span: _ } => { s.word_space("const"); s.print_ident(param.ident); s.s.space(); diff --git a/src/librustc_ast_pretty/pprust/tests.rs b/src/librustc_ast_pretty/pprust/tests.rs index f51439f89ffbe..f92e40ed6ffab 100644 --- a/src/librustc_ast_pretty/pprust/tests.rs +++ b/src/librustc_ast_pretty/pprust/tests.rs @@ -2,7 +2,6 @@ use super::*; use rustc_ast::ast; use rustc_ast::with_default_globals; -use rustc_span; use rustc_span::source_map::respan; use rustc_span::symbol::Ident; diff --git a/src/librustc_builtin_macros/deriving/mod.rs b/src/librustc_builtin_macros/deriving/mod.rs index 9660cade38241..dc21be3b296aa 100644 --- a/src/librustc_builtin_macros/deriving/mod.rs +++ b/src/librustc_builtin_macros/deriving/mod.rs @@ -123,7 +123,7 @@ fn inject_impl_of_structural_trait( *default = None; ast::GenericArg::Type(cx.ty_ident(span, param.ident)) } - ast::GenericParamKind::Const { ty: _ } => { + ast::GenericParamKind::Const { ty: _, kw_span: _ } => { ast::GenericArg::Const(cx.const_ident(span, param.ident)) } }) diff --git a/src/librustc_builtin_macros/env.rs b/src/librustc_builtin_macros/env.rs index d769ebb1f5520..6c3a1ce0958ec 100644 --- a/src/librustc_builtin_macros/env.rs +++ b/src/librustc_builtin_macros/env.rs @@ -22,8 +22,10 @@ pub fn expand_option_env<'cx>( }; let sp = cx.with_def_site_ctxt(sp); - let e = match env::var(&var.as_str()) { - Err(..) => { + let value = env::var(&var.as_str()).ok().as_deref().map(Symbol::intern); + cx.parse_sess.env_depinfo.borrow_mut().insert((Symbol::intern(&var), value)); + let e = match value { + None => { let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp)); cx.expr_path(cx.path_all( sp, @@ -37,10 +39,10 @@ pub fn expand_option_env<'cx>( ))], )) } - Ok(s) => cx.expr_call_global( + Some(value) => cx.expr_call_global( sp, cx.std_path(&[sym::option, sym::Option, sym::Some]), - vec![cx.expr_str(sp, Symbol::intern(&s))], + vec![cx.expr_str(sp, value)], ), }; MacEager::expr(e) @@ -78,12 +80,14 @@ pub fn expand_env<'cx>( } let sp = cx.with_def_site_ctxt(sp); - let e = match env::var(&*var.as_str()) { - Err(_) => { + let value = env::var(&*var.as_str()).ok().as_deref().map(Symbol::intern); + cx.parse_sess.env_depinfo.borrow_mut().insert((var, value)); + let e = match value { + None => { cx.span_err(sp, &msg.as_str()); return DummyResult::any(sp); } - Ok(s) => cx.expr_str(sp, Symbol::intern(&s)), + Some(value) => cx.expr_str(sp, value), }; MacEager::expr(e) } diff --git a/src/librustc_builtin_macros/lib.rs b/src/librustc_builtin_macros/lib.rs index a0f82d65618f4..f56d8a372a73e 100644 --- a/src/librustc_builtin_macros/lib.rs +++ b/src/librustc_builtin_macros/lib.rs @@ -5,6 +5,7 @@ #![feature(bool_to_option)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] +#![feature(inner_deref)] #![feature(nll)] #![feature(or_patterns)] #![feature(proc_macro_internals)] diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 8a957a729fb68..dab85b8fb864d 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -29,13 +29,12 @@ use rustc_hir::def::CtorKind; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::ich::NodeIdHashingMode; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::truncate; use rustc_middle::mir::{self, Field, GeneratorLayout}; use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout}; -use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; +use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::Instance; -use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; +use rustc_middle::ty::{self, AdtKind, GeneratorSubsts, ParamEnv, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::{self, DebugInfo}; use rustc_span::symbol::{Interner, Symbol}; @@ -392,6 +391,7 @@ fn vec_slice_metadata( align: pointer_align, flags: DIFlags::FlagZero, discriminant: None, + source_info: None, }, MemberDescription { name: "length".to_owned(), @@ -401,6 +401,7 @@ fn vec_slice_metadata( align: usize_align, flags: DIFlags::FlagZero, discriminant: None, + source_info: None, }, ]; @@ -508,6 +509,7 @@ fn trait_pointer_metadata( align: data_ptr_field.align.abi, flags: DIFlags::FlagArtificial, discriminant: None, + source_info: None, }, MemberDescription { name: "vtable".to_owned(), @@ -517,6 +519,7 @@ fn trait_pointer_metadata( align: vtable_field.align.abi, flags: DIFlags::FlagArtificial, discriminant: None, + source_info: None, }, ]; @@ -859,7 +862,7 @@ fn foreign_type_metadata( debug!("foreign_type_metadata: {:?}", t); let name = compute_debuginfo_type_name(cx.tcx, t, false); - create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA) + create_struct_stub(cx, t, &name, unique_type_id, NO_SCOPE_METADATA, DIFlags::FlagZero) } fn pointer_type_metadata( @@ -1026,6 +1029,12 @@ impl MetadataCreationResult<'ll> { } } +#[derive(Debug)] +struct SourceInfo<'ll> { + file: &'ll DIFile, + line: u32, +} + /// Description of a type member, which can either be a regular field (as in /// structs or tuples) or an enum variant. #[derive(Debug)] @@ -1037,6 +1046,7 @@ struct MemberDescription<'ll> { align: Align, flags: DIFlags, discriminant: Option, + source_info: Option>, } impl<'ll> MemberDescription<'ll> { @@ -1045,14 +1055,18 @@ impl<'ll> MemberDescription<'ll> { cx: &CodegenCx<'ll, '_>, composite_type_metadata: &'ll DIScope, ) -> &'ll DIType { + let (file, line) = self + .source_info + .map(|info| (info.file, info.line)) + .unwrap_or_else(|| (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)); unsafe { llvm::LLVMRustDIBuilderCreateVariantMemberType( DIB(cx), composite_type_metadata, self.name.as_ptr().cast(), self.name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file, + line, self.size.bits(), self.align.bits() as u32, self.offset.bits(), @@ -1124,6 +1138,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> { align: field.align.abi, flags: DIFlags::FlagZero, discriminant: None, + source_info: None, } }) .collect() @@ -1145,8 +1160,14 @@ fn prepare_struct_metadata( let containing_scope = get_namespace_for_item(cx, struct_def_id); - let struct_metadata_stub = - create_struct_stub(cx, struct_type, &struct_name, unique_type_id, Some(containing_scope)); + let struct_metadata_stub = create_struct_stub( + cx, + struct_type, + &struct_name, + unique_type_id, + Some(containing_scope), + DIFlags::FlagZero, + ); create_and_register_recursive_type_forward_declaration( cx, @@ -1185,6 +1206,7 @@ impl<'tcx> TupleMemberDescriptionFactory<'tcx> { align, flags: DIFlags::FlagZero, discriminant: None, + source_info: None, } }) .collect() @@ -1201,8 +1223,14 @@ fn prepare_tuple_metadata( ) -> RecursiveTypeDescription<'ll, 'tcx> { let tuple_name = compute_debuginfo_type_name(cx.tcx, tuple_type, false); - let struct_stub = - create_struct_stub(cx, tuple_type, &tuple_name[..], unique_type_id, containing_scope); + let struct_stub = create_struct_stub( + cx, + tuple_type, + &tuple_name[..], + unique_type_id, + containing_scope, + DIFlags::FlagZero, + ); create_and_register_recursive_type_forward_declaration( cx, @@ -1244,6 +1272,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> { align: field.align.abi, flags: DIFlags::FlagZero, discriminant: None, + source_info: None, } }) .collect() @@ -1351,11 +1380,11 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { let variant_info_for = |index: VariantIdx| match self.enum_type.kind { ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index]), - ty::Generator(_, substs, _) => { + ty::Generator(def_id, _, _) => { let (generator_layout, generator_saved_local_names) = generator_variant_info_data.as_ref().unwrap(); VariantInfo::Generator { - substs, + def_id, generator_layout: *generator_layout, generator_saved_local_names, variant_index: index, @@ -1371,6 +1400,10 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { } else { type_metadata(cx, self.enum_type, self.span) }; + let flags = match self.enum_type.kind { + ty::Generator(..) => DIFlags::FlagArtificial, + _ => DIFlags::FlagZero, + }; match self.layout.variants { Variants::Single { index } => { @@ -1404,8 +1437,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags: DIFlags::FlagZero, + flags, discriminant: None, + source_info: variant_info.source_info(cx), }] } Variants::Multiple { @@ -1457,11 +1491,12 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags: DIFlags::FlagZero, + flags, discriminant: Some( self.layout.ty.discriminant_for_variant(cx.tcx, i).unwrap().val as u64, ), + source_info: variant_info.source_info(cx), } }) .collect() @@ -1527,7 +1562,8 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { self.layout.fields.offset(tag_field), self.layout.field(cx, tag_field).size, ); - variant_info_for(*niche_variants.start()).map_struct_name(|variant_name| { + let variant_info = variant_info_for(*niche_variants.start()); + variant_info.map_struct_name(|variant_name| { name.push_str(variant_name); }); @@ -1538,8 +1574,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: variant.size, align: variant.align.abi, - flags: DIFlags::FlagZero, + flags, discriminant: None, + source_info: variant_info.source_info(cx), }] } else { variants @@ -1587,8 +1624,9 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { offset: Size::ZERO, size: self.layout.size, align: self.layout.align.abi, - flags: DIFlags::FlagZero, + flags, discriminant: niche_value, + source_info: variant_info.source_info(cx), } }) .collect() @@ -1613,24 +1651,27 @@ impl VariantMemberDescriptionFactory<'ll, 'tcx> { .iter() .enumerate() .map(|(i, &(ref name, ty))| { + // Discriminant is always the first field of our variant + // when using the enum fallback. + let is_artificial_discr = use_enum_fallback(cx) && i == 0; let (size, align) = cx.size_and_align_of(ty); MemberDescription { name: name.to_string(), - type_metadata: if use_enum_fallback(cx) { - match self.tag_type_metadata { - // Discriminant is always the first field of our variant - // when using the enum fallback. - Some(metadata) if i == 0 => metadata, - _ => type_metadata(cx, ty, self.span), - } + type_metadata: if is_artificial_discr { + self.tag_type_metadata.unwrap_or_else(|| type_metadata(cx, ty, self.span)) } else { type_metadata(cx, ty, self.span) }, offset: self.offsets[i], size, align, - flags: DIFlags::FlagZero, + flags: if is_artificial_discr { + DIFlags::FlagArtificial + } else { + DIFlags::FlagZero + }, discriminant: None, + source_info: None, } }) .collect() @@ -1651,7 +1692,7 @@ enum EnumTagInfo<'ll> { enum VariantInfo<'a, 'tcx> { Adt(&'tcx ty::VariantDef), Generator { - substs: SubstsRef<'tcx>, + def_id: DefId, generator_layout: &'tcx GeneratorLayout<'tcx>, generator_saved_local_names: &'a IndexVec>, variant_index: VariantIdx, @@ -1662,8 +1703,8 @@ impl<'tcx> VariantInfo<'_, 'tcx> { fn map_struct_name(&self, f: impl FnOnce(&str) -> R) -> R { match self { VariantInfo::Adt(variant) => f(&variant.ident.as_str()), - VariantInfo::Generator { substs, variant_index, .. } => { - f(&substs.as_generator().variant_name(*variant_index)) + VariantInfo::Generator { variant_index, .. } => { + f(&GeneratorSubsts::variant_name(*variant_index)) } } } @@ -1699,6 +1740,32 @@ impl<'tcx> VariantInfo<'_, 'tcx> { }; field_name.map(|name| name.to_string()).unwrap_or_else(|| format!("__{}", i)) } + + fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option> { + match self { + VariantInfo::Generator { def_id, variant_index, .. } => { + let span = + cx.tcx.generator_layout(*def_id).variant_source_info[*variant_index].span; + if !span.is_dummy() { + let loc = cx.lookup_debug_loc(span.lo()); + return Some(SourceInfo { + file: file_metadata(cx, &loc.file, def_id.krate), + line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + }); + } + } + _ => {} + } + None + } + + #[allow(dead_code)] + fn is_artificial(&self) -> bool { + match self { + VariantInfo::Generator { .. } => true, + VariantInfo::Adt(..) => false, + } + } } /// Returns a tuple of (1) `type_metadata_stub` of the variant, (2) a @@ -1718,7 +1785,15 @@ fn describe_enum_variant( .type_map .borrow_mut() .get_unique_type_id_of_enum_variant(cx, layout.ty, &variant_name); - create_struct_stub(cx, layout.ty, &variant_name, unique_type_id, Some(containing_scope)) + create_struct_stub( + cx, + layout.ty, + &variant_name, + unique_type_id, + Some(containing_scope), + // FIXME(tmandry): This doesn't seem to have any effect. + if variant.is_artificial() { DIFlags::FlagArtificial } else { DIFlags::FlagZero }, + ) }); // Build an array of (field name, field type) pairs to be captured in the factory closure. @@ -1778,7 +1853,13 @@ fn prepare_enum_metadata( span: Span, outer_field_tys: Vec>, ) -> RecursiveTypeDescription<'ll, 'tcx> { - let enum_name = compute_debuginfo_type_name(cx.tcx, enum_type, false); + let tcx = cx.tcx; + let enum_name = compute_debuginfo_type_name(tcx, enum_type, false); + // FIXME(tmandry): This doesn't seem to have any effect. + let enum_flags = match enum_type.kind { + ty::Generator(..) => DIFlags::FlagArtificial, + _ => DIFlags::FlagZero, + }; let containing_scope = get_namespace_for_item(cx, enum_def_id); // FIXME: This should emit actual file metadata for the enum, but we @@ -1792,7 +1873,7 @@ fn prepare_enum_metadata( let discriminant_type_metadata = |discr: Primitive| { let enumerators_metadata: Vec<_> = match enum_type.kind { ty::Adt(def, _) => def - .discriminants(cx.tcx) + .discriminants(tcx) .zip(&def.variants) .map(|((_, discr), v)| { let name = v.ident.as_str(); @@ -1815,15 +1896,16 @@ fn prepare_enum_metadata( .collect(), ty::Generator(_, substs, _) => substs .as_generator() - .variant_range(enum_def_id, cx.tcx) + .variant_range(enum_def_id, tcx) .map(|variant_index| { - let name = substs.as_generator().variant_name(variant_index); + debug_assert_eq!(tcx.types.u32, substs.as_generator().discr_ty(tcx)); + let name = GeneratorSubsts::variant_name(variant_index); unsafe { Some(llvm::LLVMRustDIBuilderCreateEnumerator( DIB(cx), name.as_ptr().cast(), name.len(), - // Generators use u32 as discriminant type. + // Generators use u32 as discriminant type, verified above. variant_index.as_u32().into(), true, // IsUnsigned )) @@ -1841,12 +1923,12 @@ fn prepare_enum_metadata( None => { let (discriminant_size, discriminant_align) = (discr.size(cx), discr.align(cx)); let discriminant_base_type_metadata = - type_metadata(cx, discr.to_ty(cx.tcx), rustc_span::DUMMY_SP); + type_metadata(cx, discr.to_ty(tcx), rustc_span::DUMMY_SP); let item_name; let discriminant_name = match enum_type.kind { ty::Adt(..) => { - item_name = cx.tcx.item_name(enum_def_id).as_str(); + item_name = tcx.item_name(enum_def_id).as_str(); &*item_name } ty::Generator(..) => enum_name.as_str(), @@ -1912,7 +1994,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - DIFlags::FlagZero, + enum_flags, None, 0, // RuntimeLang unique_type_id_str.as_ptr().cast(), @@ -2033,7 +2115,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - DIFlags::FlagZero, + enum_flags, discriminator_metadata, empty_array, variant_part_unique_type_id_str.as_ptr().cast(), @@ -2059,7 +2141,7 @@ fn prepare_enum_metadata( UNKNOWN_LINE_NUMBER, layout.size.bits(), layout.align.abi.bits() as u32, - DIFlags::FlagZero, + enum_flags, None, type_array, 0, @@ -2110,6 +2192,7 @@ fn composite_type_metadata( composite_type_name, composite_type_unique_id, containing_scope, + DIFlags::FlagZero, ); // ... and immediately create and add the member descriptions. set_members_of_composite_type(cx, composite_type, composite_type_metadata, member_descriptions); @@ -2211,6 +2294,7 @@ fn create_struct_stub( struct_type_name: &str, unique_type_id: UniqueTypeId, containing_scope: Option<&'ll DIScope>, + flags: DIFlags, ) -> &'ll DICompositeType { let (struct_size, struct_align) = cx.size_and_align_of(struct_type); @@ -2232,7 +2316,7 @@ fn create_struct_stub( UNKNOWN_LINE_NUMBER, struct_size.bits(), struct_align.bits() as u32, - DIFlags::FlagZero, + flags, None, empty_array, 0, @@ -2297,9 +2381,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global } let tcx = cx.tcx; - let attrs = tcx.codegen_fn_attrs(def_id); - let no_mangle = attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE); // We may want to remove the namespace scope if we're in an extern block (see // https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952). let var_scope = get_namespace_for_item(cx, def_id); @@ -2316,14 +2398,11 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global let variable_type = Instance::mono(cx.tcx, def_id).monomorphic_ty(cx.tcx); let type_metadata = type_metadata(cx, variable_type, span); let var_name = tcx.item_name(def_id).as_str(); - let linkage_name = if no_mangle { - None - } else { - Some(mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name.as_str()) - }; + let linkage_name: &str = + &mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name.as_str(); // When empty, linkage_name field is omitted, // which is what we want for no_mangle statics - let linkage_name = linkage_name.as_deref().unwrap_or(""); + let linkage_name = if var_name == linkage_name { "" } else { linkage_name }; let global_align = cx.align_of(variable_type); diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 8c580847ef8fd..b5434298805f3 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -267,9 +267,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let substs = instance.substs.truncate_to(self.tcx(), generics); let template_parameters = get_template_parameters(self, &generics, substs, &mut name); - // Get the linkage_name, which is just the symbol name - let linkage_name = mangled_name_of_instance(self, instance); - let linkage_name = linkage_name.name.as_str(); + let linkage_name: &str = &mangled_name_of_instance(self, instance).name.as_str(); + // Omit the linkage_name if it is the same as subprogram name. + let linkage_name = if &name == linkage_name { "" } else { linkage_name }; // FIXME(eddyb) does this need to be separate from `loc.line` for some reason? let scope_line = loc.line; diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 0a1cc31044a22..130c0cf1877c6 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -206,7 +206,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { } } "size_of" | "pref_align_of" | "min_align_of" | "needs_drop" | "type_id" - | "type_name" => { + | "type_name" | "variant_count" => { let value = self .tcx .const_eval_instance(ty::ParamEnv::reveal_all(), instance, None) diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index 67a2251e8593e..80278bb9f53d8 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -156,6 +156,10 @@ const ARM_WHITELIST: &[(&str, Option)] = &[ ("vfp2", Some(sym::arm_target_feature)), ("vfp3", Some(sym::arm_target_feature)), ("vfp4", Some(sym::arm_target_feature)), + // This is needed for inline assembly, but shouldn't be stabilized as-is + // since it should be enabled per-function using #[instruction_set], not + // #[target_feature]. + ("thumb-mode", Some(sym::arm_target_feature)), ]; const AARCH64_WHITELIST: &[(&str, Option)] = &[ diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 77009aca6d32e..5a0da6be5980e 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -70,10 +70,10 @@ fn uncached_llvm_type<'a, 'tcx>( write!(&mut name, "::{}", def.variants[index].ident).unwrap(); } } - if let (&ty::Generator(_, substs, _), &Variants::Single { index }) + if let (&ty::Generator(_, _, _), &Variants::Single { index }) = (&layout.ty.kind, &layout.variants) { - write!(&mut name, "::{}", substs.as_generator().variant_name(index)).unwrap(); + write!(&mut name, "::{}", ty::GeneratorSubsts::variant_name(index)).unwrap(); } Some(name) } diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 6c995be913c9e..a34029410784a 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -140,7 +140,12 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( // The third parameter is for env vars, used on windows to set up the // path for MSVC to find its DLLs, and gcc to find its bundled // toolchain -fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> Command { +fn get_linker( + sess: &Session, + linker: &Path, + flavor: LinkerFlavor, + self_contained: bool, +) -> Command { let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe"); // If our linker looks like a batch script on Windows then to execute this @@ -199,7 +204,7 @@ fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> Command { // The compiler's sysroot often has some bundled tools, so add it to the // PATH for the child. - let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(); + let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained); let mut msvc_changed_path = false; if sess.target.target.options.is_like_msvc { if let Some(ref tool) = msvc_tool { @@ -551,19 +556,25 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( "Linker does not support -static-pie command line option. Retrying with -static instead." ); // Mirror `add_(pre,post)_link_objects` to replace CRT objects. - let fallback = crt_objects_fallback(sess, crate_type); + let self_contained = crt_objects_fallback(sess, crate_type); let opts = &sess.target.target.options; - let pre_objects = - if fallback { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects }; - let post_objects = - if fallback { &opts.post_link_objects_fallback } else { &opts.post_link_objects }; + let pre_objects = if self_contained { + &opts.pre_link_objects_fallback + } else { + &opts.pre_link_objects + }; + let post_objects = if self_contained { + &opts.post_link_objects_fallback + } else { + &opts.post_link_objects + }; let get_objects = |objects: &CrtObjects, kind| { objects .get(&kind) .iter() .copied() .flatten() - .map(|obj| get_object_file_path(sess, obj).into_os_string()) + .map(|obj| get_object_file_path(sess, obj, self_contained).into_os_string()) .collect::>() }; let pre_objects_static_pie = get_objects(pre_objects, LinkOutputKind::StaticPicExe); @@ -1066,9 +1077,11 @@ fn get_crt_libs_path(sess: &Session) -> Option { } } -fn get_object_file_path(sess: &Session, name: &str) -> PathBuf { +fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> PathBuf { // prefer system {,dll}crt2.o libs, see get_crt_libs_path comment for more details - if sess.target.target.llvm_target.contains("windows-gnu") { + if sess.opts.debugging_opts.link_self_contained.is_none() + && sess.target.target.llvm_target.contains("windows-gnu") + { if let Some(compiler_libs_path) = get_crt_libs_path(sess) { let file_path = compiler_libs_path.join(name); if file_path.exists() { @@ -1081,9 +1094,12 @@ fn get_object_file_path(sess: &Session, name: &str) -> PathBuf { if file_path.exists() { return file_path; } - let file_path = fs.get_selfcontained_lib_path().join(name); - if file_path.exists() { - return file_path; + // Special directory with objects used only in self-contained linkage mode + if self_contained { + let file_path = fs.get_self_contained_lib_path().join(name); + if file_path.exists() { + return file_path; + } } for search_path in fs.search_paths() { let file_path = search_path.dir.join(name); @@ -1268,6 +1284,10 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind { /// Whether we link to our own CRT objects instead of relying on gcc to pull them. /// We only provide such support for a very limited number of targets. fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool { + if let Some(self_contained) = sess.opts.debugging_opts.link_self_contained { + return self_contained; + } + match sess.target.target.options.crt_objects_fallback { // FIXME: Find a better heuristic for "native musl toolchain is available", // based on host and linker path, for example. @@ -1287,12 +1307,13 @@ fn add_pre_link_objects( cmd: &mut dyn Linker, sess: &Session, link_output_kind: LinkOutputKind, - fallback: bool, + self_contained: bool, ) { let opts = &sess.target.target.options; - let objects = if fallback { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects }; + let objects = + if self_contained { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects }; for obj in objects.get(&link_output_kind).iter().copied().flatten() { - cmd.add_object(&get_object_file_path(sess, obj)); + cmd.add_object(&get_object_file_path(sess, obj, self_contained)); } } @@ -1301,12 +1322,13 @@ fn add_post_link_objects( cmd: &mut dyn Linker, sess: &Session, link_output_kind: LinkOutputKind, - fallback: bool, + self_contained: bool, ) { let opts = &sess.target.target.options; - let objects = if fallback { &opts.post_link_objects_fallback } else { &opts.post_link_objects }; + let objects = + if self_contained { &opts.post_link_objects_fallback } else { &opts.post_link_objects }; for obj in objects.get(&link_output_kind).iter().copied().flatten() { - cmd.add_object(&get_object_file_path(sess, obj)); + cmd.add_object(&get_object_file_path(sess, obj, self_contained)); } } @@ -1468,9 +1490,12 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<' } /// Add sysroot and other globally set directories to the directory search list. -fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session) { +fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) { // Prefer system mingw-w64 libs, see get_crt_libs_path comment for more details. - if cfg!(windows) && sess.target.target.llvm_target.contains("windows-gnu") { + if sess.opts.debugging_opts.link_self_contained.is_none() + && cfg!(windows) + && sess.target.target.llvm_target.contains("windows-gnu") + { if let Some(compiler_libs_path) = get_crt_libs_path(sess) { cmd.include_path(&compiler_libs_path); } @@ -1481,8 +1506,11 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session) { let lib_path = sess.target_filesearch(PathKind::All).get_lib_path(); cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path)); - let lib_path = sess.target_filesearch(PathKind::All).get_selfcontained_lib_path(); - cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path)); + // Special directory with libraries used only in self-contained linkage mode + if self_contained { + let lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path(); + cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path)); + } } /// Add options making relocation sections in the produced ELF files read-only @@ -1545,13 +1573,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( codegen_results: &CodegenResults, target_cpu: &str, ) -> Command { - let base_cmd = get_linker(sess, path, flavor); + let crt_objects_fallback = crt_objects_fallback(sess, crate_type); + let base_cmd = get_linker(sess, path, flavor, crt_objects_fallback); // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction // to the linker args construction. assert!(base_cmd.get_args().is_empty() || sess.target.target.target_vendor == "uwp"); let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor, target_cpu); let link_output_kind = link_output_kind(sess, crate_type); - let crt_objects_fallback = crt_objects_fallback(sess, crate_type); // NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT add_pre_link_args(cmd, sess, flavor); @@ -1597,7 +1625,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER // FIXME: Order-dependent, at least relatively to other args adding searh directories. - add_library_search_dirs(cmd, sess); + add_library_search_dirs(cmd, sess, crt_objects_fallback); // OBJECT-FILES-YES add_local_crate_regular_objects(cmd, codegen_results); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 5125ce779ed8e..480f9a5032087 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -380,7 +380,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // checked operation, just a comparison with the minimum // value, so we have to check for the assert message. if !bx.check_overflow() { - if let AssertKind::OverflowNeg = *msg { + if let AssertKind::OverflowNeg(_) = *msg { const_cond = Some(expected); } } diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 39afb3d82ff5a..53d831749ceb7 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -358,7 +358,6 @@ cfg_if! { use parking_lot::Mutex as InnerLock; use parking_lot::RwLock as InnerRwLock; - use std; use std::thread; pub use rayon::{join, scope}; diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 6a5e23adafa53..162585360fbda 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -446,6 +446,7 @@ E0762: include_str!("./error_codes/E0762.md"), E0763: include_str!("./error_codes/E0763.md"), E0764: include_str!("./error_codes/E0764.md"), E0765: include_str!("./error_codes/E0765.md"), +E0766: include_str!("./error_codes/E0766.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/src/librustc_error_codes/error_codes/E0701.md b/src/librustc_error_codes/error_codes/E0701.md index 87f416ada1803..4965e64310591 100644 --- a/src/librustc_error_codes/error_codes/E0701.md +++ b/src/librustc_error_codes/error_codes/E0701.md @@ -1,7 +1,7 @@ This error indicates that a `#[non_exhaustive]` attribute was incorrectly placed on something other than a struct or enum. -Examples of erroneous code: +Erroneous code example: ```compile_fail,E0701 #[non_exhaustive] diff --git a/src/librustc_error_codes/error_codes/E0766.md b/src/librustc_error_codes/error_codes/E0766.md new file mode 100644 index 0000000000000..4e775df2cac4d --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0766.md @@ -0,0 +1,13 @@ +A double quote byte string (`b"`) was not terminated. + +Erroneous code example: + +```compile_fail,E0766 +let s = b"; // error! +``` + +To fix this error, add the missing double quote at the end of the string: + +``` +let s = b""; // ok! +``` diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index b22da86c09187..1362a1155bcdd 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -31,6 +31,9 @@ use std::path::Path; use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream}; use termcolor::{Buffer, Color, WriteColor}; +/// Default column width, used in tests and when terminal dimensions cannot be determined. +const DEFAULT_COLUMN_WIDTH: usize = 140; + /// Describes the way the content of the `rendered` field of the json output is generated #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum HumanReadableErrorType { @@ -74,7 +77,8 @@ struct Margin { pub computed_left: usize, /// The end of the line to be displayed. pub computed_right: usize, - /// The current width of the terminal. 140 by default and in tests. + /// The current width of the terminal. Uses value of `DEFAULT_COLUMN_WIDTH` constant by default + /// and in tests. pub column_width: usize, /// The end column of a span label, including the span. Doesn't account for labels not in the /// same line as the span. @@ -1414,11 +1418,11 @@ impl EmitterWriter { let column_width = if let Some(width) = self.terminal_width { width.saturating_sub(code_offset) } else if self.ui_testing { - 140 + DEFAULT_COLUMN_WIDTH } else { termize::dimensions() .map(|(w, _)| w.saturating_sub(code_offset)) - .unwrap_or(usize::MAX) + .unwrap_or(DEFAULT_COLUMN_WIDTH) }; let margin = Margin::new( diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs index a57ae798ffceb..d4c756c9ec7f8 100644 --- a/src/librustc_expand/base.rs +++ b/src/librustc_expand/base.rs @@ -4,7 +4,7 @@ use crate::module::DirectoryOwnership; use rustc_ast::ast::{self, Attribute, NodeId, PatKind}; use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::ptr::P; -use rustc_ast::token; +use rustc_ast::token::{self, FlattenGroup}; use rustc_ast::tokenstream::{self, TokenStream, TokenTree}; use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_attr::{self as attr, Deprecation, HasAttrs, Stability}; @@ -142,7 +142,7 @@ impl Annotatable { | Annotatable::StructField(..) | Annotatable::Variant(..) => panic!("unexpected annotatable"), }; - TokenTree::token(token::Interpolated(Lrc::new(nt)), DUMMY_SP).into() + TokenTree::token(token::Interpolated(Lrc::new(nt), FlattenGroup::Yes), DUMMY_SP).into() } pub fn expect_item(self) -> P { @@ -374,7 +374,7 @@ where impl MutVisitor for AvoidInterpolatedIdents { fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) { if let tokenstream::TokenTree::Token(token) = tt { - if let token::Interpolated(nt) = &token.kind { + if let token::Interpolated(nt, _) = &token.kind { if let token::NtIdent(ident, is_raw) = **nt { *tt = tokenstream::TokenTree::token( token::Ident(ident.name, is_raw), diff --git a/src/librustc_expand/mbe/macro_parser.rs b/src/librustc_expand/mbe/macro_parser.rs index 968f7c8e273a3..c90a438c25ece 100644 --- a/src/librustc_expand/mbe/macro_parser.rs +++ b/src/librustc_expand/mbe/macro_parser.rs @@ -785,12 +785,12 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool { sym::literal => token.can_begin_literal_maybe_minus(), sym::vis => match token.kind { // The follow-set of :vis + "priv" keyword + interpolated - token::Comma | token::Ident(..) | token::Interpolated(_) => true, + token::Comma | token::Ident(..) | token::Interpolated(..) => true, _ => token.can_begin_type(), }, sym::block => match token.kind { token::OpenDelim(token::Brace) => true, - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { token::NtItem(_) | token::NtPat(_) | token::NtTy(_) @@ -804,7 +804,7 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool { }, sym::path | sym::meta => match token.kind { token::ModSep | token::Ident(..) => true, - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { token::NtPath(_) | token::NtMeta(_) => true, _ => may_be_ident(&nt), }, @@ -823,12 +823,12 @@ fn may_begin_with(token: &Token, name: Symbol) -> bool { token::ModSep | // path token::Lt | // path (UFCS constant) token::BinOp(token::Shl) => true, // path (double UFCS) - token::Interpolated(ref nt) => may_be_ident(nt), + token::Interpolated(ref nt, _) => may_be_ident(nt), _ => false, }, sym::lifetime => match token.kind { token::Lifetime(_) => true, - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { token::NtLifetime(_) | token::NtTT(_) => true, _ => false, }, diff --git a/src/librustc_expand/mbe/transcribe.rs b/src/librustc_expand/mbe/transcribe.rs index e2d3d5c4d644e..486f0a6420d6e 100644 --- a/src/librustc_expand/mbe/transcribe.rs +++ b/src/librustc_expand/mbe/transcribe.rs @@ -4,7 +4,7 @@ use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch}; use rustc_ast::ast::MacCall; use rustc_ast::mut_visit::{self, MutVisitor}; -use rustc_ast::token::{self, NtTT, Token}; +use rustc_ast::token::{self, FlattenGroup, NtTT, Token}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -240,7 +240,10 @@ pub(super) fn transcribe<'a>( result.push(tt.clone().into()); } else { marker.visit_span(&mut sp); - let token = TokenTree::token(token::Interpolated(nt.clone()), sp); + let token = TokenTree::token( + token::Interpolated(nt.clone(), FlattenGroup::No), + sp, + ); result.push(token.into()); } } else { diff --git a/src/librustc_expand/proc_macro.rs b/src/librustc_expand/proc_macro.rs index df7bf9438c3d0..1e26c832a2621 100644 --- a/src/librustc_expand/proc_macro.rs +++ b/src/librustc_expand/proc_macro.rs @@ -2,7 +2,7 @@ use crate::base::{self, *}; use crate::proc_macro_server; use rustc_ast::ast::{self, ItemKind, MetaItemKind, NestedMetaItem}; -use rustc_ast::token; +use rustc_ast::token::{self, FlattenGroup}; use rustc_ast::tokenstream::{self, TokenStream}; use rustc_data_structures::sync::Lrc; use rustc_errors::{Applicability, ErrorReported}; @@ -102,7 +102,7 @@ impl MultiItemModifier for ProcMacroDerive { } } - let token = token::Interpolated(Lrc::new(token::NtItem(item))); + let token = token::Interpolated(Lrc::new(token::NtItem(item)), FlattenGroup::Yes); let input = tokenstream::TokenTree::token(token, DUMMY_SP).into(); let server = proc_macro_server::Rustc::new(ecx); diff --git a/src/librustc_expand/proc_macro_server.rs b/src/librustc_expand/proc_macro_server.rs index ea55674045c0f..c88b5a37f718a 100644 --- a/src/librustc_expand/proc_macro_server.rs +++ b/src/librustc_expand/proc_macro_server.rs @@ -1,7 +1,7 @@ use crate::base::ExtCtxt; use rustc_ast::ast; -use rustc_ast::token; +use rustc_ast::token::{self, FlattenGroup}; use rustc_ast::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint}; use rustc_ast::util::comments; use rustc_ast_pretty::pprust; @@ -60,7 +60,12 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec)> let Token { kind, span } = match tree { tokenstream::TokenTree::Delimited(span, delim, tts) => { let delimiter = Delimiter::from_internal(delim); - return TokenTree::Group(Group { delimiter, stream: tts, span }); + return TokenTree::Group(Group { + delimiter, + stream: tts, + span, + flatten: FlattenGroup::No, + }); } tokenstream::TokenTree::Token(token) => token, }; @@ -167,6 +172,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec)> delimiter: Delimiter::Bracket, stream, span: DelimSpan::from_single(span), + flatten: FlattenGroup::No, })); if style == ast::AttrStyle::Inner { stack.push(tt!(Punct::new('!', false))); @@ -174,12 +180,13 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec)> tt!(Punct::new('#', false)) } - Interpolated(nt) => { + Interpolated(nt, flatten) => { let stream = nt_to_tokenstream(&nt, sess, span); TokenTree::Group(Group { delimiter: Delimiter::None, stream, span: DelimSpan::from_single(span), + flatten, }) } @@ -195,7 +202,7 @@ impl ToInternal for TokenTree { let (ch, joint, span) = match self { TokenTree::Punct(Punct { ch, joint, span }) => (ch, joint, span), - TokenTree::Group(Group { delimiter, stream, span }) => { + TokenTree::Group(Group { delimiter, stream, span, .. }) => { return tokenstream::TokenTree::Delimited(span, delimiter.to_internal(), stream) .into(); } @@ -283,6 +290,10 @@ pub struct Group { delimiter: Delimiter, stream: TokenStream, span: DelimSpan, + /// A hack used to pass AST fragments to attribute and derive macros + /// as a single nonterminal token instead of a token stream. + /// FIXME: It needs to be removed, but there are some compatibility issues (see #73345). + flatten: FlattenGroup, } #[derive(Copy, Clone, PartialEq, Eq, Hash)] @@ -437,14 +448,12 @@ impl server::TokenStreamIter for Rustc<'_> { let next = iter.cursor.next_with_joint()?; Some(TokenTree::from_internal((next, self.sess, &mut iter.stack))) })?; - // HACK: The condition "dummy span + group with empty delimiter" represents an AST - // fragment approximately converted into a token stream. This may happen, for - // example, with inputs to proc macro attributes, including derives. Such "groups" - // need to flattened during iteration over stream's token trees. - // Eventually this needs to be removed in favor of keeping original token trees - // and not doing the roundtrip through AST. + // A hack used to pass AST fragments to attribute and derive macros + // as a single nonterminal token instead of a token stream. + // Such token needs to be "unwrapped" and not represented as a delimited group. + // FIXME: It needs to be removed, but there are some compatibility issues (see #73345). if let TokenTree::Group(ref group) = tree { - if group.delimiter == Delimiter::None && group.span.entire().is_dummy() { + if matches!(group.flatten, FlattenGroup::Yes) { iter.cursor.append(group.stream.clone()); continue; } @@ -456,7 +465,12 @@ impl server::TokenStreamIter for Rustc<'_> { impl server::Group for Rustc<'_> { fn new(&mut self, delimiter: Delimiter, stream: Self::TokenStream) -> Self::Group { - Group { delimiter, stream, span: DelimSpan::from_single(server::Span::call_site(self)) } + Group { + delimiter, + stream, + span: DelimSpan::from_single(server::Span::call_site(self)), + flatten: FlattenGroup::No, + } } fn delimiter(&mut self, group: &Self::Group) -> Delimiter { group.delimiter diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 7d1cb7738c35e..f3dfec7ca7215 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -1511,13 +1511,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool { // Check whether a span corresponding to a range expression is a // range literal, rather than an explicit struct or `new()` call. fn is_lit(sm: &SourceMap, span: &Span) -> bool { - let end_point = sm.end_point(*span); - - if let Ok(end_string) = sm.span_to_snippet(end_point) { - !(end_string.ends_with('}') || end_string.ends_with(')')) - } else { - false - } + sm.span_to_snippet(*span).map(|range_src| range_src.contains("..")).unwrap_or(false) }; match expr.kind { diff --git a/src/librustc_hir/lang_items.rs b/src/librustc_hir/lang_items.rs index 091ded6d74d0f..cd6f034f7a5da 100644 --- a/src/librustc_hir/lang_items.rs +++ b/src/librustc_hir/lang_items.rs @@ -25,7 +25,7 @@ use lazy_static::lazy_static; // So you probably just want to nip down to the end. macro_rules! language_item_table { ( - $( $variant:ident, $name:expr, $method:ident, $target:path; )* + $( $variant:ident, $name:expr, $method:ident, $target:expr; )* ) => { enum_from_u32! { @@ -207,6 +207,8 @@ language_item_table! { FnMutTraitLangItem, "fn_mut", fn_mut_trait, Target::Trait; FnOnceTraitLangItem, "fn_once", fn_once_trait, Target::Trait; + FnOnceOutputLangItem, "fn_once_output", fn_once_output, Target::AssocTy; + FutureTraitLangItem, "future_trait", future_trait, Target::Trait; GeneratorStateLangItem, "generator_state", gen_state, Target::Enum; GeneratorTraitLangItem, "generator", gen_trait, Target::Trait; diff --git a/src/librustc_index/bit_set.rs b/src/librustc_index/bit_set.rs index 46c38840516e2..cb8b30830c5de 100644 --- a/src/librustc_index/bit_set.rs +++ b/src/librustc_index/bit_set.rs @@ -700,7 +700,7 @@ impl GrowableBitSet { /// /// All operations that involve a row and/or column index will panic if the /// index exceeds the relevant bound. -#[derive(Clone, Debug, Eq, PartialEq, RustcDecodable, RustcEncodable)] +#[derive(Clone, Eq, PartialEq, RustcDecodable, RustcEncodable)] pub struct BitMatrix { num_rows: usize, num_columns: usize, @@ -876,6 +876,22 @@ impl BitMatrix { } } +impl fmt::Debug for BitMatrix { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + /// Forces its contents to print in regular mode instead of alternate mode. + struct OneLinePrinter(T); + impl fmt::Debug for OneLinePrinter { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "{:?}", self.0) + } + } + + write!(fmt, "BitMatrix({}x{}) ", self.num_rows, self.num_columns)?; + let items = self.rows().flat_map(|r| self.iter(r).map(move |c| (r, c))); + fmt.debug_set().entries(items.map(OneLinePrinter)).finish() + } +} + /// A fixed-column-size, variable-row-size 2D bit matrix with a moderately /// sparse representation. /// diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index e9a4119f4a333..ed5e715ce7084 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -549,6 +549,22 @@ fn escape_dep_filename(filename: &FileName) -> String { filename.to_string().replace(" ", "\\ ") } +// Makefile comments only need escaping newlines and `\`. +// The result can be unescaped by anything that can unescape `escape_default` and friends. +fn escape_dep_env(symbol: Symbol) -> String { + let s = symbol.as_str(); + let mut escaped = String::with_capacity(s.len()); + for c in s.chars() { + match c { + '\n' => escaped.push_str(r"\n"), + '\r' => escaped.push_str(r"\r"), + '\\' => escaped.push_str(r"\\"), + _ => escaped.push(c), + } + } + escaped +} + fn write_out_deps( sess: &Session, boxed_resolver: &Steal>>, @@ -604,6 +620,25 @@ fn write_out_deps( for path in files { writeln!(file, "{}:", path)?; } + + // Emit special comments with information about accessed environment variables. + let env_depinfo = sess.parse_sess.env_depinfo.borrow(); + if !env_depinfo.is_empty() { + let mut envs: Vec<_> = env_depinfo + .iter() + .map(|(k, v)| (escape_dep_env(*k), v.map(escape_dep_env))) + .collect(); + envs.sort_unstable(); + writeln!(file)?; + for (k, v) in envs { + write!(file, "# env-dep:{}", k)?; + if let Some(v) = v { + write!(file, "={}", v)?; + } + writeln!(file)?; + } + } + Ok(()) })(); diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index 200e7acf80235..77b3d26463dfe 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -179,21 +179,18 @@ pub enum Base { /// but shebang isn't a part of rust syntax. pub fn strip_shebang(input: &str) -> Option { // Shebang must start with `#!` literally, without any preceding whitespace. - if input.starts_with("#!") { - let input_tail = &input[2..]; - // Shebang must have something non-whitespace after `#!` on the first line. - let first_line_tail = input_tail.lines().next()?; - if first_line_tail.contains(|c| !is_whitespace(c)) { - // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe - // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level), - // then it may be valid Rust code, so consider it Rust code. - let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| - !matches!(tok, TokenKind::Whitespace | TokenKind::LineComment | TokenKind::BlockComment { .. }) - ); - if next_non_whitespace_token != Some(TokenKind::OpenBracket) { - // No other choice than to consider this a shebang. - return Some(2 + first_line_tail.len()); - } + // For simplicity we consider any line starting with `#!` a shebang, + // regardless of restrictions put on shebangs by specific platforms. + if let Some(input_tail) = input.strip_prefix("#!") { + // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe + // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level), + // then it may be valid Rust code, so consider it Rust code. + let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| + !matches!(tok, TokenKind::Whitespace | TokenKind::LineComment | TokenKind::BlockComment { .. }) + ); + if next_non_whitespace_token != Some(TokenKind::OpenBracket) { + // No other choice than to consider this a shebang. + return Some(2 + input_tail.lines().next().unwrap_or_default().len()); } } None diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index ada6f2a9381dc..58c15257326ae 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" [dependencies] log = "0.4" -unicode-security = "0.0.3" +unicode-security = "0.0.5" rustc_middle = { path = "../librustc_middle" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_attr = { path = "../librustc_attr" } diff --git a/src/librustc_lint/array_into_iter.rs b/src/librustc_lint/array_into_iter.rs index 5b282c4203400..82ac60be17c82 100644 --- a/src/librustc_lint/array_into_iter.rs +++ b/src/librustc_lint/array_into_iter.rs @@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter { // Check if the method call actually calls the libcore // `IntoIterator::into_iter`. - let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); match cx.tcx.trait_of_item(def_id) { Some(trait_id) if cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_id) => {} _ => return, @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter { // `Box` is the only thing that values can be moved out of via // method call. `Box::new([1]).into_iter()` should trigger this // lint. - let mut recv_ty = cx.tables.expr_ty(receiver_arg); + let mut recv_ty = cx.tables().expr_ty(receiver_arg); let mut num_box_derefs = 0; while recv_ty.is_box() { num_box_derefs += 1; @@ -60,13 +60,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter { // Make sure that there is an autoref coercion at the expected // position. The first `num_box_derefs` adjustments are the derefs // of the box. - match cx.tables.expr_adjustments(receiver_arg).get(num_box_derefs) { + match cx.tables().expr_adjustments(receiver_arg).get(num_box_derefs) { Some(Adjustment { kind: Adjust::Borrow(_), .. }) => {} _ => return, } // Emit lint diagnostic. - let target = match cx.tables.expr_ty_adjusted(receiver_arg).kind { + let target = match cx.tables().expr_ty_adjusted(receiver_arg).kind { ty::Ref(_, ty::TyS { kind: ty::Array(..), .. }, _) => "[T; N]", ty::Ref(_, ty::TyS { kind: ty::Slice(..), .. }, _) => "[T]", diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index e746396e4c684..d8f3caa2c4434 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -144,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { } fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) { - let ty = cx.tables.node_type(e.hir_id); + let ty = cx.tables().node_type(e.hir_id); self.check_heap_type(cx, e.span, ty); } } @@ -161,11 +161,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>) { if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind { let variant = cx - .tables + .tables() .pat_ty(pat) .ty_adt_def() .expect("struct pattern type is not an ADT") - .variant_of_res(cx.tables.qpath_res(qpath, pat.hir_id)); + .variant_of_res(cx.tables().qpath_res(qpath, pat.hir_id)); for fieldpat in field_pats { if fieldpat.is_shorthand { continue; @@ -178,7 +178,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { } if let PatKind::Binding(binding_annot, _, ident, None) = fieldpat.pat.kind { if cx.tcx.find_field_index(ident, &variant) - == Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables)) + == Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables())) { cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| { let mut err = lint @@ -901,7 +901,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { expr: &hir::Expr<'_>, ) -> Option<(Ty<'tcx>, Ty<'tcx>)> { let def = if let hir::ExprKind::Path(ref qpath) = expr.kind { - cx.tables.qpath_res(qpath, expr.hir_id) + cx.tables().qpath_res(qpath, expr.hir_id) } else { return None; }; @@ -909,7 +909,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { if !def_id_is_transmute(cx, did) { return None; } - let sig = cx.tables.node_type(expr.hir_id).fn_sig(cx.tcx); + let sig = cx.tables().node_type(expr.hir_id).fn_sig(cx.tcx); let from = sig.inputs().skip_binder()[0]; let to = *sig.output().skip_binder(); return Some((from, to)); @@ -1891,7 +1891,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue { if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind { // Find calls to `mem::{uninitialized,zeroed}` methods. if let hir::ExprKind::Path(ref qpath) = path_expr.kind { - let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?; + let def_id = cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id()?; if cx.tcx.is_diagnostic_item(sym::mem_zeroed, def_id) { return Some(InitKind::Zeroed); @@ -1905,14 +1905,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue { } } else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind { // Find problematic calls to `MaybeUninit::assume_init`. - let def_id = cx.tables.type_dependent_def_id(expr.hir_id)?; + let def_id = cx.tables().type_dependent_def_id(expr.hir_id)?; if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) { // This is a call to *some* method named `assume_init`. // See if the `self` parameter is one of the dangerous constructors. if let hir::ExprKind::Call(ref path_expr, _) = args[0].kind { if let hir::ExprKind::Path(ref qpath) = path_expr.kind { let def_id = - cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?; + cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id()?; if cx.tcx.is_diagnostic_item(sym::maybe_uninit_zeroed, def_id) { return Some(InitKind::Zeroed); @@ -2025,7 +2025,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue { // This conjures an instance of a type out of nothing, // using zeroed or uninitialized memory. // We are extremely conservative with what we warn about. - let conjured_ty = cx.tables.expr_ty(expr); + let conjured_ty = cx.tables().expr_ty(expr); if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) { cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| { let mut err = lint.build(&format!( diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index e5d3227d5afd4..0b4ae131af0fc 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -37,6 +37,7 @@ use rustc_session::Session; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; use rustc_target::abi::LayoutOf; +use std::cell::Cell; use std::slice; /// Information about the registered lints. @@ -423,9 +424,17 @@ pub struct LateContext<'a, 'tcx> { /// Type context we're checking in. pub tcx: TyCtxt<'tcx>, - /// Side-tables for the body we are in. - // FIXME: Make this lazy to avoid running the TypeckTables query? - pub tables: &'a ty::TypeckTables<'tcx>, + /// Current body, or `None` if outside a body. + pub enclosing_body: Option, + + /// Type-checking side-tables for the current body. Access using the + /// `tables` method, which handles querying the tables on demand. + // FIXME(eddyb) move all the code accessing internal fields like this, + // to this module, to avoid exposing it to lint logic. + pub(super) cached_typeck_tables: Cell>>, + + // HACK(eddyb) replace this with having `Option` around `&TypeckTables`. + pub(super) empty_typeck_tables: &'a ty::TypeckTables<'tcx>, /// Parameter environment for the item we are in. pub param_env: ty::ParamEnv<'tcx>, @@ -667,6 +676,22 @@ impl LintContext for EarlyContext<'_> { } impl<'a, 'tcx> LateContext<'a, 'tcx> { + /// Gets the type-checking side-tables for the current body, + /// or empty `TypeckTables` if outside a body. + // FIXME(eddyb) return `Option<&'tcx ty::TypeckTables<'tcx>>`, + // where `None` indicates we're outside a body. + pub fn tables(&self) -> &'a ty::TypeckTables<'tcx> { + if let Some(body) = self.enclosing_body { + self.cached_typeck_tables.get().unwrap_or_else(|| { + let tables = self.tcx.body_tables(body); + self.cached_typeck_tables.set(Some(tables)); + tables + }) + } else { + self.empty_typeck_tables + } + } + pub fn current_lint_root(&self) -> hir::HirId { self.last_node_with_lint_attrs } diff --git a/src/librustc_lint/late.rs b/src/librustc_lint/late.rs index c8f827b1f5ced..ef62d44c4026b 100644 --- a/src/librustc_lint/late.rs +++ b/src/librustc_lint/late.rs @@ -30,6 +30,7 @@ use rustc_span::Span; use log::debug; use std::any::Any; +use std::cell::Cell; use std::slice; /// Extract the `LintStore` from the query context. @@ -104,12 +105,25 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx> hir_visit::NestedVisitorMap::All(self.context.tcx.hir()) } - fn visit_nested_body(&mut self, body: hir::BodyId) { - let old_tables = self.context.tables; - self.context.tables = self.context.tcx.body_tables(body); - let body = self.context.tcx.hir().body(body); + fn visit_nested_body(&mut self, body_id: hir::BodyId) { + let old_enclosing_body = self.context.enclosing_body.replace(body_id); + let old_cached_typeck_tables = self.context.cached_typeck_tables.get(); + + // HACK(eddyb) avoid trashing `cached_typeck_tables` when we're + // nested in `visit_fn`, which may have already resulted in them + // being queried. + if old_enclosing_body != Some(body_id) { + self.context.cached_typeck_tables.set(None); + } + + let body = self.context.tcx.hir().body(body_id); self.visit_body(body); - self.context.tables = old_tables; + self.context.enclosing_body = old_enclosing_body; + + // See HACK comment above. + if old_enclosing_body != Some(body_id) { + self.context.cached_typeck_tables.set(old_cached_typeck_tables); + } } fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { @@ -181,13 +195,14 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx> ) { // Wrap in tables here, not just in visit_nested_body, // in order for `check_fn` to be able to use them. - let old_tables = self.context.tables; - self.context.tables = self.context.tcx.body_tables(body_id); + let old_enclosing_body = self.context.enclosing_body.replace(body_id); + let old_cached_typeck_tables = self.context.cached_typeck_tables.take(); let body = self.context.tcx.hir().body(body_id); lint_callback!(self, check_fn, fk, decl, body, span, id); hir_visit::walk_fn(self, fk, decl, body_id, span, id); lint_callback!(self, check_fn_post, fk, decl, body, span, id); - self.context.tables = old_tables; + self.context.enclosing_body = old_enclosing_body; + self.context.cached_typeck_tables.set(old_cached_typeck_tables); } fn visit_variant_data( @@ -361,7 +376,9 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( let context = LateContext { tcx, - tables: &ty::TypeckTables::empty(None), + enclosing_body: None, + cached_typeck_tables: Cell::new(None), + empty_typeck_tables: &ty::TypeckTables::empty(None), param_env: ty::ParamEnv::empty(), access_levels, lint_store: unerased_lint_store(tcx), @@ -408,7 +425,9 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tc let context = LateContext { tcx, - tables: &ty::TypeckTables::empty(None), + enclosing_body: None, + cached_typeck_tables: Cell::new(None), + empty_typeck_tables: &ty::TypeckTables::empty(None), param_env: ty::ParamEnv::empty(), access_levels, lint_store: unerased_lint_store(tcx), diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index ca2ca3145abc8..b39abe7b411bb 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -167,7 +167,8 @@ macro_rules! late_lint_mod_passes { $args, [ HardwiredLints: HardwiredLints, - ImproperCTypes: ImproperCTypes, + ImproperCTypesDeclarations: ImproperCTypesDeclarations, + ImproperCTypesDefinitions: ImproperCTypesDefinitions, VariantSizeDifferences: VariantSizeDifferences, BoxPointers: BoxPointers, PathStatements: PathStatements, diff --git a/src/librustc_lint/non_ascii_idents.rs b/src/librustc_lint/non_ascii_idents.rs index 064b0255397ce..30dbd069c29bd 100644 --- a/src/librustc_lint/non_ascii_idents.rs +++ b/src/librustc_lint/non_ascii_idents.rs @@ -1,9 +1,7 @@ use crate::{EarlyContext, EarlyLintPass, LintContext}; use rustc_ast::ast; use rustc_data_structures::fx::FxHashMap; -use rustc_span::symbol::{Ident, SymbolStr}; -use std::hash::{Hash, Hasher}; -use std::ops::Deref; +use rustc_span::symbol::SymbolStr; declare_lint! { pub NON_ASCII_IDENTS, @@ -19,158 +17,256 @@ declare_lint! { crate_level_only } -// FIXME: Change this to warn. declare_lint! { pub CONFUSABLE_IDENTS, - Allow, + Warn, "detects visually confusable pairs between identifiers", crate_level_only } -declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS, UNCOMMON_CODEPOINTS, CONFUSABLE_IDENTS]); - -enum CowBoxSymStr { - Interned(SymbolStr), - Owned(Box), -} - -impl Deref for CowBoxSymStr { - type Target = str; - - fn deref(&self) -> &str { - match self { - CowBoxSymStr::Interned(interned) => interned, - CowBoxSymStr::Owned(ref owned) => owned, - } - } -} - -impl Hash for CowBoxSymStr { - #[inline] - fn hash(&self, state: &mut H) { - Hash::hash(&**self, state) - } -} - -impl PartialEq for CowBoxSymStr { - #[inline] - fn eq(&self, other: &CowBoxSymStr) -> bool { - PartialEq::eq(&**self, &**other) - } -} - -impl Eq for CowBoxSymStr {} - -fn calc_skeleton(symbol_str: SymbolStr, buffer: &'_ mut String) -> CowBoxSymStr { - use std::mem::swap; - use unicode_security::confusable_detection::skeleton; - buffer.clear(); - buffer.extend(skeleton(&symbol_str)); - if symbol_str == *buffer { - CowBoxSymStr::Interned(symbol_str) - } else { - let mut owned = String::new(); - swap(buffer, &mut owned); - CowBoxSymStr::Owned(owned.into_boxed_str()) - } -} - -fn is_in_ascii_confusable_closure(c: char) -> bool { - // FIXME: move this table to `unicode_security` crate. - // data here corresponds to Unicode 13. - const ASCII_CONFUSABLE_CLOSURE: &[(u64, u64)] = &[(0x00, 0x7f), (0xba, 0xba), (0x2080, 0x2080)]; - let c = c as u64; - for &(range_start, range_end) in ASCII_CONFUSABLE_CLOSURE { - if c >= range_start && c <= range_end { - return true; - } - } - false +declare_lint! { + pub MIXED_SCRIPT_CONFUSABLES, + Warn, + "detects Unicode scripts whose mixed script confusables codepoints are solely used", + crate_level_only } -fn is_in_ascii_confusable_closure_relevant_list(c: char) -> bool { - // FIXME: move this table to `unicode_security` crate. - // data here corresponds to Unicode 13. - const ASCII_CONFUSABLE_CLOSURE_RELEVANT_LIST: &[u64] = &[ - 0x22, 0x25, 0x27, 0x2f, 0x30, 0x31, 0x49, 0x4f, 0x60, 0x6c, 0x6d, 0x6e, 0x72, 0x7c, 0xba, - 0x2080, - ]; - let c = c as u64; - for &item in ASCII_CONFUSABLE_CLOSURE_RELEVANT_LIST { - if c == item { - return true; - } - } - false -} +declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS, UNCOMMON_CODEPOINTS, CONFUSABLE_IDENTS, MIXED_SCRIPT_CONFUSABLES]); impl EarlyLintPass for NonAsciiIdents { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) { use rustc_session::lint::Level; - if cx.builder.lint_level(CONFUSABLE_IDENTS).0 == Level::Allow { + use rustc_span::Span; + use std::collections::BTreeMap; + use unicode_security::GeneralSecurityProfile; + use utils::CowBoxSymStr; + + let check_non_ascii_idents = cx.builder.lint_level(NON_ASCII_IDENTS).0 != Level::Allow; + let check_uncommon_codepoints = + cx.builder.lint_level(UNCOMMON_CODEPOINTS).0 != Level::Allow; + let check_confusable_idents = cx.builder.lint_level(CONFUSABLE_IDENTS).0 != Level::Allow; + let check_mixed_script_confusables = + cx.builder.lint_level(MIXED_SCRIPT_CONFUSABLES).0 != Level::Allow; + + if !check_non_ascii_idents + && !check_uncommon_codepoints + && !check_confusable_idents + && !check_mixed_script_confusables + { return; } + + let mut has_non_ascii_idents = false; let symbols = cx.sess.parse_sess.symbol_gallery.symbols.lock(); - let mut symbol_strs_and_spans = Vec::with_capacity(symbols.len()); - let mut in_fast_path = true; - for (symbol, sp) in symbols.iter() { - // fast path + for (symbol, &sp) in symbols.iter() { let symbol_str = symbol.as_str(); - if !symbol_str.chars().all(is_in_ascii_confusable_closure) { - // fallback to slow path. - symbol_strs_and_spans.clear(); - in_fast_path = false; - break; + if symbol_str.is_ascii() { + continue; } - if symbol_str.chars().any(is_in_ascii_confusable_closure_relevant_list) { - symbol_strs_and_spans.push((symbol_str, *sp)); + has_non_ascii_idents = true; + cx.struct_span_lint(NON_ASCII_IDENTS, sp, |lint| { + lint.build("identifier contains non-ASCII characters").emit() + }); + if check_uncommon_codepoints + && !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed) + { + cx.struct_span_lint(UNCOMMON_CODEPOINTS, sp, |lint| { + lint.build("identifier contains uncommon Unicode codepoints").emit() + }) } } - if !in_fast_path { - // slow path - for (symbol, sp) in symbols.iter() { + + if has_non_ascii_idents && check_confusable_idents { + let mut skeleton_map: FxHashMap = + FxHashMap::with_capacity_and_hasher(symbols.len(), Default::default()); + let mut str_buf = String::new(); + for (symbol, &sp) in symbols.iter() { + fn calc_skeleton(symbol_str: &SymbolStr, buffer: &mut String) -> CowBoxSymStr { + use std::mem::replace; + use unicode_security::confusable_detection::skeleton; + buffer.clear(); + buffer.extend(skeleton(symbol_str)); + if *symbol_str == *buffer { + CowBoxSymStr::Interned(symbol_str.clone()) + } else { + let owned = replace(buffer, String::new()); + CowBoxSymStr::Owned(owned.into_boxed_str()) + } + } let symbol_str = symbol.as_str(); - symbol_strs_and_spans.push((symbol_str, *sp)); + let is_ascii = symbol_str.is_ascii(); + let skeleton = calc_skeleton(&symbol_str, &mut str_buf); + skeleton_map + .entry(skeleton) + .and_modify(|(existing_symbolstr, existing_span, existing_is_ascii)| { + if !*existing_is_ascii || !is_ascii { + cx.struct_span_lint(CONFUSABLE_IDENTS, sp, |lint| { + lint.build(&format!( + "identifier pair considered confusable between `{}` and `{}`", + existing_symbolstr, symbol_str + )) + .span_label( + *existing_span, + "this is where the previous identifier occurred", + ) + .emit(); + }); + } + if *existing_is_ascii && !is_ascii { + *existing_symbolstr = symbol_str.clone(); + *existing_span = sp; + *existing_is_ascii = is_ascii; + } + }) + .or_insert((symbol_str, sp, is_ascii)); } } - drop(symbols); - symbol_strs_and_spans.sort_by_key(|x| x.0.clone()); - let mut skeleton_map = - FxHashMap::with_capacity_and_hasher(symbol_strs_and_spans.len(), Default::default()); - let mut str_buf = String::new(); - for (symbol_str, sp) in symbol_strs_and_spans { - let skeleton = calc_skeleton(symbol_str.clone(), &mut str_buf); - skeleton_map - .entry(skeleton) - .and_modify(|(existing_symbolstr, existing_span)| { - cx.struct_span_lint(CONFUSABLE_IDENTS, sp, |lint| { - lint.build(&format!( - "identifier pair considered confusable between `{}` and `{}`", - existing_symbolstr, symbol_str - )) - .span_label( - *existing_span, - "this is where the previous identifier occurred", - ) - .emit(); + + if has_non_ascii_idents && check_mixed_script_confusables { + use unicode_security::is_potential_mixed_script_confusable_char; + use unicode_security::mixed_script::AugmentedScriptSet; + + #[derive(Clone)] + enum ScriptSetUsage { + Suspicious(Vec, Span), + Verified, + } + + let mut script_states: FxHashMap = + FxHashMap::default(); + let latin_augmented_script_set = AugmentedScriptSet::for_char('A'); + script_states.insert(latin_augmented_script_set, ScriptSetUsage::Verified); + + let mut has_suspicous = false; + for (symbol, &sp) in symbols.iter() { + let symbol_str = symbol.as_str(); + for ch in symbol_str.chars() { + if ch.is_ascii() { + // all ascii characters are covered by exception. + continue; + } + if !GeneralSecurityProfile::identifier_allowed(ch) { + // this character is covered by `uncommon_codepoints` lint. + continue; + } + let augmented_script_set = AugmentedScriptSet::for_char(ch); + script_states + .entry(augmented_script_set) + .and_modify(|existing_state| { + if let ScriptSetUsage::Suspicious(ch_list, _) = existing_state { + if is_potential_mixed_script_confusable_char(ch) { + ch_list.push(ch); + } else { + *existing_state = ScriptSetUsage::Verified; + } + } + }) + .or_insert_with(|| { + if !is_potential_mixed_script_confusable_char(ch) { + ScriptSetUsage::Verified + } else { + has_suspicous = true; + ScriptSetUsage::Suspicious(vec![ch], sp) + } + }); + } + } + + if has_suspicous { + let verified_augmented_script_sets = script_states + .iter() + .flat_map(|(k, v)| match v { + ScriptSetUsage::Verified => Some(*k), + _ => None, + }) + .collect::>(); + + // we're sorting the output here. + let mut lint_reports: BTreeMap<(Span, Vec), AugmentedScriptSet> = + BTreeMap::new(); + + 'outerloop: for (augment_script_set, usage) in script_states { + let (mut ch_list, sp) = match usage { + ScriptSetUsage::Verified => continue, + ScriptSetUsage::Suspicious(ch_list, sp) => (ch_list, sp), + }; + + if augment_script_set.is_all() { + continue; + } + + for existing in verified_augmented_script_sets.iter() { + if existing.is_all() { + continue; + } + let mut intersect = *existing; + intersect.intersect_with(augment_script_set); + if !intersect.is_empty() && !intersect.is_all() { + continue 'outerloop; + } + } + + ch_list.sort(); + ch_list.dedup(); + lint_reports.insert((sp, ch_list), augment_script_set); + } + + for ((sp, ch_list), script_set) in lint_reports { + cx.struct_span_lint(MIXED_SCRIPT_CONFUSABLES, sp, |lint| { + let message = format!( + "The usage of Script Group `{}` in this crate consists solely of mixed script confusables", + script_set); + let mut note = "The usage includes ".to_string(); + for (idx, ch) in ch_list.into_iter().enumerate() { + if idx != 0 { + note += ", "; + } + let char_info = format!("'{}' (U+{:04X})", ch, ch as u32); + note += &char_info; + } + note += "."; + lint.build(&message).note(¬e).note("Please recheck to make sure their usages are indeed what you want.").emit() }); - }) - .or_insert((symbol_str, sp)); + } + } } } - fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { - use unicode_security::GeneralSecurityProfile; - let name_str = ident.name.as_str(); - if name_str.is_ascii() { - return; +} + +mod utils { + use rustc_span::symbol::SymbolStr; + use std::hash::{Hash, Hasher}; + use std::ops::Deref; + + pub(super) enum CowBoxSymStr { + Interned(SymbolStr), + Owned(Box), + } + + impl Deref for CowBoxSymStr { + type Target = str; + + fn deref(&self) -> &str { + match self { + CowBoxSymStr::Interned(interned) => interned, + CowBoxSymStr::Owned(ref owned) => owned, + } + } + } + + impl Hash for CowBoxSymStr { + #[inline] + fn hash(&self, state: &mut H) { + Hash::hash(&**self, state) } - cx.struct_span_lint(NON_ASCII_IDENTS, ident.span, |lint| { - lint.build("identifier contains non-ASCII characters").emit() - }); - if !name_str.chars().all(GeneralSecurityProfile::identifier_allowed) { - cx.struct_span_lint(UNCOMMON_CODEPOINTS, ident.span, |lint| { - lint.build("identifier contains uncommon Unicode codepoints").emit() - }) + } + + impl PartialEq for CowBoxSymStr { + #[inline] + fn eq(&self, other: &CowBoxSymStr) -> bool { + PartialEq::eq(&**self, &**other) } } + + impl Eq for CowBoxSymStr {} } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index a19c9a3557996..814ca627e2cf8 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -14,7 +14,7 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{Integer, LayoutOf, TagEncoding, VariantIdx, Variants}; use rustc_target::spec::abi::Abi; @@ -167,7 +167,8 @@ fn report_bin_hex_error( the type `{}` and will become `{}{}`", repr_str, val, t, actually, t )); - if let Some(sugg_ty) = get_type_suggestion(&cx.tables.node_type(expr.hir_id), val, negative) + if let Some(sugg_ty) = + get_type_suggestion(&cx.tables().node_type(expr.hir_id), val, negative) { if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') { let (sans_suffix, _) = repr_str.split_at(pos); @@ -301,7 +302,7 @@ fn lint_uint_literal<'a, 'tcx>( if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) { match par_e.kind { hir::ExprKind::Cast(..) => { - if let ty::Char = cx.tables.expr_ty(par_e).kind { + if let ty::Char = cx.tables().expr_ty(par_e).kind { cx.struct_span_lint(OVERFLOWING_LITERALS, par_e.span, |lint| { lint.build("only `u8` can be cast into `char`") .span_suggestion( @@ -352,7 +353,7 @@ fn lint_literal<'a, 'tcx>( e: &'tcx hir::Expr<'tcx>, lit: &hir::Lit, ) { - match cx.tables.node_type(e.hir_id).kind { + match cx.tables().node_type(e.hir_id).kind { ty::Int(t) => { match lit.node { ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => { @@ -448,7 +449,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { // Normalize the binop so that the literal is always on the RHS in // the comparison let norm_binop = if swap { rev_binop(binop) } else { binop }; - match cx.tables.node_type(expr.hir_id).kind { + match cx.tables().node_type(expr.hir_id).kind { ty::Int(int_ty) => { let (min, max) = int_ty_range(int_ty); let lit_val: i128 = match lit.kind { @@ -498,10 +499,24 @@ declare_lint! { "proper use of libc types in foreign modules" } -declare_lint_pass!(ImproperCTypes => [IMPROPER_CTYPES]); +declare_lint_pass!(ImproperCTypesDeclarations => [IMPROPER_CTYPES]); + +declare_lint! { + IMPROPER_CTYPES_DEFINITIONS, + Warn, + "proper use of libc types in foreign item definitions" +} + +declare_lint_pass!(ImproperCTypesDefinitions => [IMPROPER_CTYPES_DEFINITIONS]); + +enum ImproperCTypesMode { + Declarations, + Definitions, +} struct ImproperCTypesVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, + mode: ImproperCTypesMode, } enum FfiResult<'tcx> { @@ -804,6 +819,15 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { help: Some("consider using a struct instead".into()), }, + ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) + if { + matches!(self.mode, ImproperCTypesMode::Definitions) + && ty.is_sized(self.cx.tcx.at(DUMMY_SP), self.cx.param_env) + } => + { + FfiSafe + } + ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { self.check_type_for_ffi(cache, ty) } @@ -811,20 +835,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { ty::Array(inner_ty, _) => self.check_type_for_ffi(cache, inner_ty), ty::FnPtr(sig) => { - match sig.abi() { - Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic | Abi::RustCall => { - return FfiUnsafe { - ty, - reason: "this function pointer has Rust-specific calling convention" + if self.is_internal_abi(sig.abi()) { + return FfiUnsafe { + ty, + reason: "this function pointer has Rust-specific calling convention".into(), + help: Some( + "consider using an `extern fn(...) -> ...` \ + function pointer instead" .into(), - help: Some( - "consider using an `extern fn(...) -> ...` \ - function pointer instead" - .into(), - ), - }; - } - _ => {} + ), + }; } let sig = cx.erase_late_bound_regions(&sig); @@ -857,7 +877,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { FfiUnsafe { ty, reason: "opaque types have no C equivalent".into(), help: None } } + // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe, + // so they are currently ignored for the purposes of this lint. + ty::Param(..) | ty::Projection(..) + if matches!(self.mode, ImproperCTypesMode::Definitions) => + { + FfiSafe + } + ty::Param(..) + | ty::Projection(..) | ty::Infer(..) | ty::Bound(..) | ty::Error(_) @@ -865,7 +894,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { | ty::Generator(..) | ty::GeneratorWitness(..) | ty::Placeholder(..) - | ty::Projection(..) | ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty), } } @@ -877,9 +905,20 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { note: &str, help: Option<&str>, ) { - self.cx.struct_span_lint(IMPROPER_CTYPES, sp, |lint| { - let mut diag = - lint.build(&format!("`extern` block uses type `{}`, which is not FFI-safe", ty)); + let lint = match self.mode { + ImproperCTypesMode::Declarations => IMPROPER_CTYPES, + ImproperCTypesMode::Definitions => IMPROPER_CTYPES_DEFINITIONS, + }; + + self.cx.struct_span_lint(lint, sp, |lint| { + let item_description = match self.mode { + ImproperCTypesMode::Declarations => "block", + ImproperCTypesMode::Definitions => "fn", + }; + let mut diag = lint.build(&format!( + "`extern` {} uses type `{}`, which is not FFI-safe", + item_description, ty + )); diag.span_label(sp, "not FFI-safe"); if let Some(help) = help { diag.help(help); @@ -947,7 +986,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { // it is only OK to use this function because extern fns cannot have // any generic types right now: - let ty = self.cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty); + let ty = self.cx.tcx.normalize_erasing_regions(self.cx.param_env, ty); // C doesn't really support passing arrays by value - the only way to pass an array by value // is through a struct. So, first test that the top level isn't an array, and then @@ -997,15 +1036,22 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { let ty = self.cx.tcx.type_of(def_id); self.check_type_for_ffi_and_report_errors(span, ty, true, false); } + + fn is_internal_abi(&self, abi: Abi) -> bool { + if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi { + true + } else { + false + } + } } -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDeclarations { fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem<'_>) { - let mut vis = ImproperCTypesVisitor { cx }; + let mut vis = ImproperCTypesVisitor { cx, mode: ImproperCTypesMode::Declarations }; let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); - if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi { - // Don't worry about types in internal ABIs. - } else { + + if !vis.is_internal_abi(abi) { match it.kind { hir::ForeignItemKind::Fn(ref decl, _, _) => { vis.check_foreign_fn(it.hir_id, decl); @@ -1019,6 +1065,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { } } +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDefinitions { + fn check_fn( + &mut self, + cx: &LateContext<'a, 'tcx>, + kind: hir::intravisit::FnKind<'tcx>, + decl: &'tcx hir::FnDecl<'_>, + _: &'tcx hir::Body<'_>, + _: Span, + hir_id: hir::HirId, + ) { + use hir::intravisit::FnKind; + + let abi = match kind { + FnKind::ItemFn(_, _, header, ..) => header.abi, + FnKind::Method(_, sig, ..) => sig.header.abi, + _ => return, + }; + + let mut vis = ImproperCTypesVisitor { cx, mode: ImproperCTypesMode::Definitions }; + if !vis.is_internal_abi(abi) { + vis.check_foreign_fn(hir_id, decl); + } + } +} + declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 8196b37391b21..506ac77894a41 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { return; } - let ty = cx.tables.expr_ty(&expr); + let ty = cx.tables().expr_ty(&expr); let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1); let mut fn_warned = false; @@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { hir::ExprKind::Call(ref callee, _) => { match callee.kind { hir::ExprKind::Path(ref qpath) => { - match cx.tables.qpath_res(qpath, callee.hir_id) { + match cx.tables().qpath_res(qpath, callee.hir_id) { Res::Def(DefKind::Fn | DefKind::AssocFn, def_id) => Some(def_id), // `Res::Local` if it was a closure, for which we // do not currently support must-use linting @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { _ => None, } } - hir::ExprKind::MethodCall(..) => cx.tables.type_dependent_def_id(expr.hir_id), + hir::ExprKind::MethodCall(..) => cx.tables().type_dependent_def_id(expr.hir_id), _ => None, }; if let Some(def_id) = maybe_def_id { @@ -950,7 +950,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation { _ => return, } - for adj in cx.tables.expr_adjustments(e) { + for adj in cx.tables().expr_adjustments(e) { if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind { cx.struct_span_lint(UNUSED_ALLOCATION, e.span, |lint| { let msg = match m { diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index ada48bc147e47..d25f8bd1b8c58 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -293,11 +293,9 @@ fn main() { } } - // LLVM requires symbols from this library, but apparently they're not printed - // during llvm-config? + // Libstdc++ depends on pthread which Rust doesn't link on MinGW + // since nothing else requires it. if target.contains("windows-gnu") { - println!("cargo:rustc-link-lib=static-nobundle=gcc_s"); println!("cargo:rustc-link-lib=static-nobundle=pthread"); - println!("cargo:rustc-link-lib=dylib=uuid"); } } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 79e1a6cc5dcdb..f54ed9b92029e 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -15,6 +15,7 @@ pub struct RustString { /// Appending to a Rust string -- used by RawRustStringOstream. #[no_mangle] +#[cfg_attr(not(bootstrap), allow(improper_ctypes_definitions))] pub unsafe extern "C" fn LLVMRustStringWriteImpl( sr: &RustString, ptr: *const c_char, diff --git a/src/librustc_middle/Cargo.toml b/src/librustc_middle/Cargo.toml index 21d0b102a4a66..02d82c6793386 100644 --- a/src/librustc_middle/Cargo.toml +++ b/src/librustc_middle/Cargo.toml @@ -30,7 +30,7 @@ rustc_serialize = { path = "../librustc_serialize" } rustc_ast = { path = "../librustc_ast" } rustc_span = { path = "../librustc_span" } byteorder = { version = "1.3" } -chalk-ir = "0.11.0" +chalk-ir = "0.14.0" smallvec = { version = "1.0", features = ["union", "may_dangle"] } measureme = "0.7.1" rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index d89c35d313ca3..b3e410f362d68 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2,6 +2,8 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html +// ignore-tidy-filelength + use crate::mir::interpret::{GlobalAlloc, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; @@ -1246,10 +1248,10 @@ pub enum TerminatorKind<'tcx> { #[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)] pub enum AssertKind { BoundsCheck { len: O, index: O }, - Overflow(BinOp), - OverflowNeg, - DivisionByZero, - RemainderByZero, + Overflow(BinOp, O, O), + OverflowNeg(O), + DivisionByZero(O), + RemainderByZero(O), ResumedAfterReturn(GeneratorKind), ResumedAfterPanic(GeneratorKind), } @@ -1522,17 +1524,17 @@ impl AssertKind { pub fn description(&self) -> &'static str { use AssertKind::*; match self { - Overflow(BinOp::Add) => "attempt to add with overflow", - Overflow(BinOp::Sub) => "attempt to subtract with overflow", - Overflow(BinOp::Mul) => "attempt to multiply with overflow", - Overflow(BinOp::Div) => "attempt to divide with overflow", - Overflow(BinOp::Rem) => "attempt to calculate the remainder with overflow", - OverflowNeg => "attempt to negate with overflow", - Overflow(BinOp::Shr) => "attempt to shift right with overflow", - Overflow(BinOp::Shl) => "attempt to shift left with overflow", - Overflow(op) => bug!("{:?} cannot overflow", op), - DivisionByZero => "attempt to divide by zero", - RemainderByZero => "attempt to calculate the remainder with a divisor of zero", + Overflow(BinOp::Add, _, _) => "attempt to add with overflow", + Overflow(BinOp::Sub, _, _) => "attempt to subtract with overflow", + Overflow(BinOp::Mul, _, _) => "attempt to multiply with overflow", + Overflow(BinOp::Div, _, _) => "attempt to divide with overflow", + Overflow(BinOp::Rem, _, _) => "attempt to calculate the remainder with overflow", + OverflowNeg(_) => "attempt to negate with overflow", + Overflow(BinOp::Shr, _, _) => "attempt to shift right with overflow", + Overflow(BinOp::Shl, _, _) => "attempt to shift left with overflow", + Overflow(op, _, _) => bug!("{:?} cannot overflow", op), + DivisionByZero(_) => "attempt to divide by zero", + RemainderByZero(_) => "attempt to calculate the remainder with a divisor of zero", ResumedAfterReturn(GeneratorKind::Gen) => "generator resumed after completion", ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion", ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking", @@ -1546,12 +1548,54 @@ impl AssertKind { where O: Debug, { + use AssertKind::*; match self { - AssertKind::BoundsCheck { ref len, ref index } => write!( + BoundsCheck { ref len, ref index } => write!( f, "\"index out of bounds: the len is {{}} but the index is {{}}\", {:?}, {:?}", len, index ), + + OverflowNeg(op) => { + write!(f, "\"attempt to negate {{}} which would overflow\", {:?}", op) + } + DivisionByZero(op) => write!(f, "\"attempt to divide {{}} by zero\", {:?}", op), + RemainderByZero(op) => write!( + f, + "\"attempt to calculate the remainder of {{}} with a divisor of zero\", {:?}", + op + ), + Overflow(BinOp::Add, l, r) => write!( + f, + "\"attempt to compute `{{}} + {{}}` which would overflow\", {:?}, {:?}", + l, r + ), + Overflow(BinOp::Sub, l, r) => write!( + f, + "\"attempt to compute `{{}} - {{}}` which would overflow\", {:?}, {:?}", + l, r + ), + Overflow(BinOp::Mul, l, r) => write!( + f, + "\"attempt to compute `{{}} * {{}}` which would overflow\", {:?}, {:?}", + l, r + ), + Overflow(BinOp::Div, l, r) => write!( + f, + "\"attempt to compute `{{}} / {{}}` which would overflow\", {:?}, {:?}", + l, r + ), + Overflow(BinOp::Rem, l, r) => write!( + f, + "\"attempt to compute the remainder of `{{}} % {{}}` which would overflow\", {:?}, {:?}", + l, r + ), + Overflow(BinOp::Shr, _, r) => { + write!(f, "\"attempt to shift right by {{}} which would overflow\", {:?}", r) + } + Overflow(BinOp::Shl, _, r) => { + write!(f, "\"attempt to shift left by {{}} which would overflow\", {:?}", r) + } _ => write!(f, "\"{}\"", self.description()), } } @@ -1564,6 +1608,34 @@ impl fmt::Debug for AssertKind { BoundsCheck { ref len, ref index } => { write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index) } + OverflowNeg(op) => write!(f, "attempt to negate {:#?} which would overflow", op), + DivisionByZero(op) => write!(f, "attempt to divide {:#?} by zero", op), + RemainderByZero(op) => { + write!(f, "attempt to calculate the remainder of {:#?} with a divisor of zero", op) + } + Overflow(BinOp::Add, l, r) => { + write!(f, "attempt to compute `{:#?} + {:#?}` which would overflow", l, r) + } + Overflow(BinOp::Sub, l, r) => { + write!(f, "attempt to compute `{:#?} - {:#?}` which would overflow", l, r) + } + Overflow(BinOp::Mul, l, r) => { + write!(f, "attempt to compute `{:#?} * {:#?}` which would overflow", l, r) + } + Overflow(BinOp::Div, l, r) => { + write!(f, "attempt to compute `{:#?} / {:#?}` which would overflow", l, r) + } + Overflow(BinOp::Rem, l, r) => write!( + f, + "attempt to compute the remainder of `{:#?} % {:#?}` which would overflow", + l, r + ), + Overflow(BinOp::Shr, _, r) => { + write!(f, "attempt to shift right by {:#?} which would overflow", r) + } + Overflow(BinOp::Shl, _, r) => { + write!(f, "attempt to shift left by {:#?} which would overflow", r) + } _ => write!(f, "{}", self.description()), } } diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 1aae97cc2a894..9ad79230a4f6d 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -10,6 +10,8 @@ use rustc_index::vec::IndexVec; use rustc_span::{Span, Symbol}; use rustc_target::abi::VariantIdx; use smallvec::SmallVec; +use std::cell::Cell; +use std::fmt::{self, Debug}; use super::{Field, SourceInfo}; @@ -58,7 +60,7 @@ rustc_index::newtype_index! { } /// The layout of generator state. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)] pub struct GeneratorLayout<'tcx> { /// The type of every local stored inside the generator. pub field_tys: IndexVec>, @@ -67,12 +69,72 @@ pub struct GeneratorLayout<'tcx> { /// be stored in multiple variants. pub variant_fields: IndexVec>, + /// The source that led to each variant being created (usually, a yield or + /// await). + pub variant_source_info: IndexVec, + /// Which saved locals are storage-live at the same time. Locals that do not /// have conflicts with each other are allowed to overlap in the computed /// layout. pub storage_conflicts: BitMatrix, } +impl Debug for GeneratorLayout<'_> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + /// Prints an iterator of (key, value) tuples as a map. + struct MapPrinter<'a, K, V>(Cell + 'a>>>); + impl<'a, K, V> MapPrinter<'a, K, V> { + fn new(iter: impl Iterator + 'a) -> Self { + Self(Cell::new(Some(Box::new(iter)))) + } + } + impl<'a, K: Debug, V: Debug> Debug for MapPrinter<'a, K, V> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_map().entries(self.0.take().unwrap()).finish() + } + } + + /// Prints the generator variant name. + struct GenVariantPrinter(VariantIdx); + impl From for GenVariantPrinter { + fn from(idx: VariantIdx) -> Self { + GenVariantPrinter(idx) + } + } + impl Debug for GenVariantPrinter { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + let variant_name = ty::GeneratorSubsts::variant_name(self.0); + if fmt.alternate() { + write!(fmt, "{:9}({:?})", variant_name, self.0) + } else { + write!(fmt, "{}", variant_name) + } + } + } + + /// Forces its contents to print in regular mode instead of alternate mode. + struct OneLinePrinter(T); + impl Debug for OneLinePrinter { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "{:?}", self.0) + } + } + + fmt.debug_struct("GeneratorLayout") + .field("field_tys", &MapPrinter::new(self.field_tys.iter_enumerated())) + .field( + "variant_fields", + &MapPrinter::new( + self.variant_fields + .iter_enumerated() + .map(|(k, v)| (GenVariantPrinter(k), OneLinePrinter(v))), + ), + ) + .field("storage_conflicts", &self.storage_conflicts) + .finish() + } +} + #[derive(Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct BorrowCheckResult<'tcx> { /// All the opaque types that are restricted to concrete types diff --git a/src/librustc_middle/mir/type_foldable.rs b/src/librustc_middle/mir/type_foldable.rs index 89f8f10449e2d..6bb6abe028910 100644 --- a/src/librustc_middle/mir/type_foldable.rs +++ b/src/librustc_middle/mir/type_foldable.rs @@ -58,15 +58,14 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { Assert { ref cond, expected, ref msg, target, cleanup } => { use AssertKind::*; let msg = match msg { - BoundsCheck { ref len, ref index } => { + BoundsCheck { len, index } => { BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) } } - Overflow(_) - | OverflowNeg - | DivisionByZero - | RemainderByZero - | ResumedAfterReturn(_) - | ResumedAfterPanic(_) => msg.clone(), + Overflow(op, l, r) => Overflow(*op, l.fold_with(folder), r.fold_with(folder)), + OverflowNeg(op) => OverflowNeg(op.fold_with(folder)), + DivisionByZero(op) => DivisionByZero(op.fold_with(folder)), + RemainderByZero(op) => RemainderByZero(op.fold_with(folder)), + ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg.clone(), }; Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup } } @@ -117,12 +116,11 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { BoundsCheck { ref len, ref index } => { len.visit_with(visitor) || index.visit_with(visitor) } - Overflow(_) - | OverflowNeg - | DivisionByZero - | RemainderByZero - | ResumedAfterReturn(_) - | ResumedAfterPanic(_) => false, + Overflow(_, l, r) => l.visit_with(visitor) || r.visit_with(visitor), + OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) => { + op.visit_with(visitor) + } + ResumedAfterReturn(_) | ResumedAfterPanic(_) => false, } } else { false diff --git a/src/librustc_middle/mir/visit.rs b/src/librustc_middle/mir/visit.rs index 2efc5f1dabedc..c6ace5bbf6685 100644 --- a/src/librustc_middle/mir/visit.rs +++ b/src/librustc_middle/mir/visit.rs @@ -571,7 +571,13 @@ macro_rules! make_mir_visitor { self.visit_operand(len, location); self.visit_operand(index, location); } - Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero | + Overflow(_, l, r) => { + self.visit_operand(l, location); + self.visit_operand(r, location); + } + OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) => { + self.visit_operand(op, location); + } ResumedAfterReturn(_) | ResumedAfterPanic(_) => { // Nothing to visit } diff --git a/src/librustc_middle/traits/chalk.rs b/src/librustc_middle/traits/chalk.rs index a49a0045812b0..405af8cb2406c 100644 --- a/src/librustc_middle/traits/chalk.rs +++ b/src/librustc_middle/traits/chalk.rs @@ -10,6 +10,7 @@ use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; use rustc_hir::def_id::DefId; +use rustc_target::spec::abi::Abi; use smallvec::SmallVec; @@ -77,6 +78,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { type DefId = DefId; type InternedAdtId = &'tcx AdtDef; type Identifier = (); + type FnAbi = Abi; fn debug_program_clause_implication( pci: &chalk_ir::ProgramClauseImplication, diff --git a/src/librustc_middle/ty/consts.rs b/src/librustc_middle/ty/consts.rs new file mode 100644 index 0000000000000..ced0429deab93 --- /dev/null +++ b/src/librustc_middle/ty/consts.rs @@ -0,0 +1,111 @@ +use crate::mir::interpret::truncate; +use rustc_target::abi::Size; + +#[derive(Copy, Clone)] +/// A type for representing any integer. Only used for printing. +// FIXME: Use this for the integer-tree representation needed for type level ints and +// const generics? +pub struct ConstInt { + /// Number of bytes of the integer. Only 1, 2, 4, 8, 16 are legal values. + size: u8, + /// Whether the value is of a signed integer type. + signed: bool, + /// Whether the value is a `usize` or `isize` type. + is_ptr_sized_integral: bool, + /// Raw memory of the integer. All bytes beyond the `size` are unused and must be zero. + raw: u128, +} + +impl ConstInt { + pub fn new(raw: u128, size: Size, signed: bool, is_ptr_sized_integral: bool) -> Self { + assert!(raw <= truncate(u128::MAX, size)); + Self { raw, size: size.bytes() as u8, signed, is_ptr_sized_integral } + } +} + +impl std::fmt::Debug for ConstInt { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { size, signed, raw, is_ptr_sized_integral } = *self; + if signed { + let bit_size = size * 8; + let min = 1u128 << (bit_size - 1); + let max = min - 1; + if raw == min { + match (size, is_ptr_sized_integral) { + (_, true) => write!(fmt, "isize::MIN"), + (1, _) => write!(fmt, "i8::MIN"), + (2, _) => write!(fmt, "i16::MIN"), + (4, _) => write!(fmt, "i32::MIN"), + (8, _) => write!(fmt, "i64::MIN"), + (16, _) => write!(fmt, "i128::MIN"), + _ => bug!("ConstInt 0x{:x} with size = {} and signed = {}", raw, size, signed), + } + } else if raw == max { + match (size, is_ptr_sized_integral) { + (_, true) => write!(fmt, "isize::MAX"), + (1, _) => write!(fmt, "i8::MAX"), + (2, _) => write!(fmt, "i16::MAX"), + (4, _) => write!(fmt, "i32::MAX"), + (8, _) => write!(fmt, "i64::MAX"), + (16, _) => write!(fmt, "i128::MAX"), + _ => bug!("ConstInt 0x{:x} with size = {} and signed = {}", raw, size, signed), + } + } else { + match size { + 1 => write!(fmt, "{}", raw as i8)?, + 2 => write!(fmt, "{}", raw as i16)?, + 4 => write!(fmt, "{}", raw as i32)?, + 8 => write!(fmt, "{}", raw as i64)?, + 16 => write!(fmt, "{}", raw as i128)?, + _ => bug!("ConstInt 0x{:x} with size = {} and signed = {}", raw, size, signed), + } + if fmt.alternate() { + match (size, is_ptr_sized_integral) { + (_, true) => write!(fmt, "_isize")?, + (1, _) => write!(fmt, "_i8")?, + (2, _) => write!(fmt, "_i16")?, + (4, _) => write!(fmt, "_i32")?, + (8, _) => write!(fmt, "_i64")?, + (16, _) => write!(fmt, "_i128")?, + _ => bug!(), + } + } + Ok(()) + } + } else { + let max = truncate(u128::MAX, Size::from_bytes(size)); + if raw == max { + match (size, is_ptr_sized_integral) { + (_, true) => write!(fmt, "usize::MAX"), + (1, _) => write!(fmt, "u8::MAX"), + (2, _) => write!(fmt, "u16::MAX"), + (4, _) => write!(fmt, "u32::MAX"), + (8, _) => write!(fmt, "u64::MAX"), + (16, _) => write!(fmt, "u128::MAX"), + _ => bug!("ConstInt 0x{:x} with size = {} and signed = {}", raw, size, signed), + } + } else { + match size { + 1 => write!(fmt, "{}", raw as u8)?, + 2 => write!(fmt, "{}", raw as u16)?, + 4 => write!(fmt, "{}", raw as u32)?, + 8 => write!(fmt, "{}", raw as u64)?, + 16 => write!(fmt, "{}", raw as u128)?, + _ => bug!("ConstInt 0x{:x} with size = {} and signed = {}", raw, size, signed), + } + if fmt.alternate() { + match (size, is_ptr_sized_integral) { + (_, true) => write!(fmt, "_usize")?, + (1, _) => write!(fmt, "_u8")?, + (2, _) => write!(fmt, "_u16")?, + (4, _) => write!(fmt, "_u32")?, + (8, _) => write!(fmt, "_u64")?, + (16, _) => write!(fmt, "_u128")?, + _ => bug!(), + } + } + Ok(()) + } + } + } +} diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 6b7940ed7abcc..03aab2c0f9f2c 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -84,6 +84,8 @@ pub use self::trait_def::TraitDef; pub use self::query::queries; +pub use self::consts::ConstInt; + pub mod adjustment; pub mod binding; pub mod cast; @@ -108,6 +110,7 @@ pub mod trait_def; pub mod util; pub mod walk; +mod consts; mod context; mod diagnostics; mod instance; diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 1a08639a533d5..061214249713d 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -1,10 +1,8 @@ use crate::middle::cstore::{ExternCrate, ExternCrateSource}; -use crate::mir::interpret::{ - sign_extend, truncate, AllocId, ConstValue, GlobalAlloc, Pointer, Scalar, -}; +use crate::mir::interpret::{AllocId, ConstValue, GlobalAlloc, Pointer, Scalar}; use crate::ty::layout::IntegerExt; use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; -use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable}; +use crate::ty::{self, ConstInt, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; use rustc_ast::ast; @@ -981,35 +979,14 @@ pub trait PrettyPrinter<'tcx>: } // Int (Scalar::Raw { data, .. }, ty::Uint(ui)) => { - let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size(); - let max = truncate(u128::MAX, bit_size); - - let ui_str = ui.name_str(); - if data == max { - p!(write("{}::MAX", ui_str)) - } else { - if print_ty { p!(write("{}{}", data, ui_str)) } else { p!(write("{}", data)) } - }; + let size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size(); + let int = ConstInt::new(data, size, false, ty.is_ptr_sized_integral()); + if print_ty { p!(write("{:#?}", int)) } else { p!(write("{:?}", int)) } } (Scalar::Raw { data, .. }, ty::Int(i)) => { let size = Integer::from_attr(&self.tcx(), SignedInt(*i)).size(); - let bit_size = size.bits() as u128; - let min = 1u128 << (bit_size - 1); - let max = min - 1; - - let i_str = i.name_str(); - match data { - d if d == min => p!(write("{}::MIN", i_str)), - d if d == max => p!(write("{}::MAX", i_str)), - _ => { - let data = sign_extend(data, size) as i128; - if print_ty { - p!(write("{}{}", data, i_str)) - } else { - p!(write("{}", data)) - } - } - } + let int = ConstInt::new(data, size, true, ty.is_ptr_sized_integral()); + if print_ty { p!(write("{:#?}", int)) } else { p!(write("{:?}", int)) } } // Char (Scalar::Raw { data, .. }, ty::Char) if char::from_u32(data as u32).is_some() => { diff --git a/src/librustc_middle/ty/relate.rs b/src/librustc_middle/ty/relate.rs index 14cddd11c438d..e9a8b9095bf72 100644 --- a/src/librustc_middle/ty/relate.rs +++ b/src/librustc_middle/ty/relate.rs @@ -617,12 +617,22 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List> { a: &Self, b: &Self, ) -> RelateResult<'tcx, Self> { - if a.len() != b.len() { + let tcx = relation.tcx(); + + // FIXME: this is wasteful, but want to do a perf run to see how slow it is. + // We need to perform this deduplication as we sometimes generate duplicate projections + // in `a`. + let mut a_v: Vec<_> = a.into_iter().collect(); + let mut b_v: Vec<_> = b.into_iter().collect(); + a_v.sort_by(|a, b| a.stable_cmp(tcx, b)); + a_v.dedup(); + b_v.sort_by(|a, b| a.stable_cmp(tcx, b)); + b_v.dedup(); + if a_v.len() != b_v.len() { return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))); } - let tcx = relation.tcx(); - let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| { + let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| { use crate::ty::ExistentialPredicate::*; match (ep_a, ep_b) { (Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)), diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 1d680c3563675..8f86d2ef522d3 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -522,8 +522,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { /// Calls `f` with a reference to the name of the enumerator for the given /// variant `v`. - #[inline] - pub fn variant_name(self, v: VariantIdx) -> Cow<'static, str> { + pub fn variant_name(v: VariantIdx) -> Cow<'static, str> { match v.as_usize() { Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME), Self::RETURNED => Cow::from(Self::RETURNED_NAME), diff --git a/src/librustc_middle/ty/subst.rs b/src/librustc_middle/ty/subst.rs index fd31adae499fe..e9fd67a748c85 100644 --- a/src/librustc_middle/ty/subst.rs +++ b/src/librustc_middle/ty/subst.rs @@ -336,8 +336,10 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { /// /// For example given: /// + /// ```no_run /// trait X { fn f(); } /// impl X for U { fn f() {} } + /// ``` /// /// * If `self` is `[Self, S, T]`: the identity substs of `f` in the trait. /// * If `source_ancestor` is the def_id of the trait. diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 8d7944004c75e..60a1fe0b19870 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -156,6 +156,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { format!("variable moved due to use{}", move_spans.describe()), ); } + if let UseSpans::PatUse(span) = move_spans { + err.span_suggestion_verbose( + span.shrink_to_lo(), + &format!( + "borrow this field in the pattern to avoid moving {}", + self.describe_place(moved_place.as_ref()) + .map(|n| format!("`{}`", n)) + .unwrap_or_else(|| "the value".to_string()) + ), + "ref ".to_string(), + Applicability::MachineApplicable, + ); + } + if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() { let sess = self.infcx.tcx.sess; if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) { @@ -198,11 +212,28 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { _ => true, }; - if needs_note { - let mpi = self.move_data.moves[move_out_indices[0]].path; - let place = &self.move_data.move_paths[mpi].place; + let mpi = self.move_data.moves[move_out_indices[0]].path; + let place = &self.move_data.move_paths[mpi].place; + let ty = place.ty(self.body, self.infcx.tcx).ty; + + if is_loop_move { + if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind { + // We have a `&mut` ref, we need to reborrow on each iteration (#62112). + err.span_suggestion_verbose( + span.shrink_to_lo(), + &format!( + "consider creating a fresh reborrow of {} here", + self.describe_place(moved_place) + .map(|n| format!("`{}`", n)) + .unwrap_or_else(|| "the mutable reference".to_string()), + ), + "&mut *".to_string(), + Applicability::MachineApplicable, + ); + } + } - let ty = place.ty(self.body, self.infcx.tcx).ty; + if needs_note { let opt_name = self.describe_place_with_options(place.as_ref(), IncludingDowncast(true)); let note_msg = match opt_name { diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 5253acbba7f1c..849fd63998db4 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -509,7 +509,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // Used in a closure. (LaterUseKind::ClosureCapture, var_span) } - UseSpans::OtherUse(span) => { + UseSpans::PatUse(span) | UseSpans::OtherUse(span) => { let block = &self.body.basic_blocks()[location.block]; let kind = if let Some(&Statement { diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index ca8e54ea28649..388076a9d60af 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -542,20 +542,26 @@ pub(super) enum UseSpans { // The span of the first use of the captured variable inside the closure. var_span: Span, }, - // This access has a single span associated to it: common case. + /// This access is caused by a `match` or `if let` pattern. + PatUse(Span), + /// This access has a single span associated to it: common case. OtherUse(Span), } impl UseSpans { pub(super) fn args_or_use(self) -> Span { match self { - UseSpans::ClosureUse { args_span: span, .. } | UseSpans::OtherUse(span) => span, + UseSpans::ClosureUse { args_span: span, .. } + | UseSpans::PatUse(span) + | UseSpans::OtherUse(span) => span, } } pub(super) fn var_or_use(self) -> Span { match self { - UseSpans::ClosureUse { var_span: span, .. } | UseSpans::OtherUse(span) => span, + UseSpans::ClosureUse { var_span: span, .. } + | UseSpans::PatUse(span) + | UseSpans::OtherUse(span) => span, } } @@ -624,7 +630,7 @@ impl UseSpans { { match self { closure @ UseSpans::ClosureUse { .. } => closure, - UseSpans::OtherUse(_) => if_other(), + UseSpans::PatUse(_) | UseSpans::OtherUse(_) => if_other(), } } } @@ -741,7 +747,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - OtherUse(stmt.source_info.span) + if moved_place.projection.iter().any(|p| matches!(p, ProjectionElem::Downcast(..))) { + PatUse(stmt.source_info.span) + } else { + OtherUse(stmt.source_info.span) + } } /// Finds the span of arguments of a closure (within `maybe_closure_span`) diff --git a/src/librustc_mir/const_eval/error.rs b/src/librustc_mir/const_eval/error.rs index 5deae94fe0c8e..8a72be33b8429 100644 --- a/src/librustc_mir/const_eval/error.rs +++ b/src/librustc_mir/const_eval/error.rs @@ -2,6 +2,7 @@ use std::error::Error; use std::fmt; use rustc_middle::mir::AssertKind; +use rustc_middle::ty::ConstInt; use rustc_span::{Span, Symbol}; use super::InterpCx; @@ -13,7 +14,7 @@ pub enum ConstEvalErrKind { NeedsRfc(String), ConstAccessesStatic, ModifiedGlobal, - AssertFailure(AssertKind), + AssertFailure(AssertKind), Panic { msg: Symbol, line: u32, col: u32, file: Symbol }, } diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs index dc13126df0e4c..8be0ab9019fe2 100644 --- a/src/librustc_mir/const_eval/machine.rs +++ b/src/librustc_mir/const_eval/machine.rs @@ -248,25 +248,19 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, _unwind: Option, ) -> InterpResult<'tcx> { use rustc_middle::mir::AssertKind::*; - // Convert `AssertKind` to `AssertKind`. + // Convert `AssertKind` to `AssertKind`. + let eval_to_int = + |op| ecx.read_immediate(ecx.eval_operand(op, None)?).map(|x| x.to_const_int()); let err = match msg { BoundsCheck { ref len, ref index } => { - let len = ecx - .read_immediate(ecx.eval_operand(len, None)?) - .expect("can't eval len") - .to_scalar()? - .to_machine_usize(&*ecx)?; - let index = ecx - .read_immediate(ecx.eval_operand(index, None)?) - .expect("can't eval index") - .to_scalar()? - .to_machine_usize(&*ecx)?; + let len = eval_to_int(len)?; + let index = eval_to_int(index)?; BoundsCheck { len, index } } - Overflow(op) => Overflow(*op), - OverflowNeg => OverflowNeg, - DivisionByZero => DivisionByZero, - RemainderByZero => RemainderByZero, + Overflow(op, l, r) => Overflow(*op, eval_to_int(l)?, eval_to_int(r)?), + OverflowNeg(op) => OverflowNeg(eval_to_int(op)?), + DivisionByZero(op) => DivisionByZero(eval_to_int(op)?), + RemainderByZero(op) => RemainderByZero(eval_to_int(op)?), ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind), ResumedAfterPanic(generator_kind) => ResumedAfterPanic(*generator_kind), }; diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 6ac1e6be03674..88ba28dab82e1 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -69,6 +69,13 @@ crate fn eval_nullary_intrinsic<'tcx>( ConstValue::from_machine_usize(n, &tcx) } sym::type_id => ConstValue::from_u64(tcx.type_id_hash(tp_ty)), + sym::variant_count => { + if let ty::Adt(ref adt, _) = tp_ty.kind { + ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx) + } else { + ConstValue::from_machine_usize(0u64, &tcx) + } + } other => bug!("`{}` is not a zero arg intrinsic", other), }) } @@ -109,10 +116,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | sym::needs_drop | sym::size_of | sym::type_id - | sym::type_name => { + | sym::type_name + | sym::variant_count => { let gid = GlobalId { instance, promoted: None }; let ty = match intrinsic_name { - sym::min_align_of | sym::pref_align_of | sym::size_of => self.tcx.types.usize, + sym::min_align_of | sym::pref_align_of | sym::size_of | sym::variant_count => { + self.tcx.types.usize + } sym::needs_drop => self.tcx.types.bool, sym::type_id => self.tcx.types.u64, sym::type_name => self.tcx.mk_static_str(), diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 38948ee53846a..dd746f5cfb409 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -9,7 +9,7 @@ use rustc_hir::def::Namespace; use rustc_macros::HashStable; use rustc_middle::ty::layout::{PrimitiveExt, TyAndLayout}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer}; -use rustc_middle::ty::Ty; +use rustc_middle::ty::{ConstInt, Ty}; use rustc_middle::{mir, ty}; use rustc_target::abi::{Abi, HasDataLayout, LayoutOf, Size, TagEncoding}; use rustc_target::abi::{VariantIdx, Variants}; @@ -207,6 +207,19 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { pub fn from_int(i: impl Into, layout: TyAndLayout<'tcx>) -> Self { Self::from_scalar(Scalar::from_int(i, layout.size), layout) } + + #[inline] + pub fn to_const_int(self) -> ConstInt { + assert!(self.layout.ty.is_integral()); + ConstInt::new( + self.to_scalar() + .expect("to_const_int doesn't work on scalar pairs") + .assert_bits(self.layout.size), + self.layout.size, + self.layout.ty.is_signed(), + self.layout.ty.is_ptr_sized_integral(), + ) + } } impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index eb614170baae5..e1c5a4f5b1885 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -19,7 +19,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; -use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, ConstInt, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_session::lint; use rustc_span::{def_id::DefId, Span}; use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout}; @@ -350,14 +350,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn get_const(&self, place: Place<'tcx>) -> Option> { - let op = self.ecx.eval_place_to_op(place, None).ok(); + let op = match self.ecx.eval_place_to_op(place, None) { + Ok(op) => op, + Err(e) => { + trace!("get_const failed: {}", e); + return None; + } + }; // Try to read the local 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. - match op.map(|ret| self.ecx.try_read_immediate(ret)) { - Some(Ok(Ok(imm))) => Some(imm.into()), + Some(match self.ecx.try_read_immediate(op) { + Ok(Ok(imm)) => imm.into(), _ => op, - } + }) } /// Remove `local` from the pool of `Locals`. Allows writing to them, @@ -449,7 +455,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { lint: &'static lint::Lint, source_info: SourceInfo, message: &'static str, - panic: AssertKind, + panic: AssertKind, ) -> Option<()> { let lint_root = self.lint_root(source_info)?; self.tcx.struct_span_lint_hir(lint, lint_root, source_info.span, |lint| { @@ -466,10 +472,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { arg: &Operand<'tcx>, source_info: SourceInfo, ) -> Option<()> { - if self.use_ecx(|this| { + if let (val, true) = self.use_ecx(|this| { let val = this.ecx.read_immediate(this.ecx.eval_operand(arg, None)?)?; let (_res, overflow, _ty) = this.ecx.overflowing_unary_op(op, val)?; - Ok(overflow) + Ok((val, overflow)) })? { // `AssertKind` only has an `OverflowNeg` variant, so make sure that is // appropriate to use. @@ -478,7 +484,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", - AssertKind::OverflowNeg, + AssertKind::OverflowNeg(val.to_const_int()), )?; } @@ -494,29 +500,44 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) -> Option<()> { let r = self.use_ecx(|this| this.ecx.read_immediate(this.ecx.eval_operand(right, None)?))?; + let l = self.use_ecx(|this| this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)); // Check for exceeding shifts *even if* we cannot evaluate the LHS. if op == BinOp::Shr || op == BinOp::Shl { // We need the type of the LHS. We cannot use `place_layout` as that is the type // of the result, which for checked binops is not the same! let left_ty = left.ty(&self.local_decls, self.tcx); - let left_size_bits = self.ecx.layout_of(left_ty).ok()?.size.bits(); + let left_size = self.ecx.layout_of(left_ty).ok()?.size; let right_size = r.layout.size; let r_bits = r.to_scalar().ok(); // This is basically `force_bits`. let r_bits = r_bits.and_then(|r| r.to_bits_or_ptr(right_size, &self.tcx).ok()); - if r_bits.map_or(false, |b| b >= left_size_bits as u128) { + if r_bits.map_or(false, |b| b >= left_size.bits() as u128) { self.report_assert_as_lint( lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", - AssertKind::Overflow(op), + AssertKind::Overflow( + op, + match l { + Some(l) => l.to_const_int(), + // Invent a dummy value, the diagnostic ignores it anyway + None => ConstInt::new( + 1, + left_size, + left_ty.is_signed(), + left_ty.is_ptr_sized_integral(), + ), + }, + r.to_const_int(), + ), )?; } } + let l = l?; + // The remaining operators are handled through `overflowing_binary_op`. if self.use_ecx(|this| { - let l = this.ecx.read_immediate(this.ecx.eval_operand(left, None)?)?; let (_res, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?; Ok(overflow) })? { @@ -524,7 +545,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", - AssertKind::Overflow(op), + AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()), )?; } @@ -857,8 +878,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) { let can_const_prop = self.can_const_prop[place.local]; if let Some(()) = self.const_prop(rval, place_layout, source_info, place) { - // This will return None for variables that are from other blocks, - // so it should be okay to propagate from here on down. + // This will return None if the above `const_prop` invocation only "wrote" a + // type whose creation requires no write. E.g. a generator whose initial state + // consists solely of uninitialized memory (so it doesn't capture any locals). if let Some(value) = self.get_const(place) { if self.should_const_prop(value) { trace!("replacing {:?} with {:?}", rval, value); @@ -949,31 +971,26 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { } Operand::Constant(_) => {} } + let mut eval_to_int = |op| { + let op = self + .eval_operand(op, source_info) + .expect("if we got here, it must be const"); + self.ecx.read_immediate(op).unwrap().to_const_int() + }; let msg = match msg { - AssertKind::DivisionByZero => AssertKind::DivisionByZero, - AssertKind::RemainderByZero => AssertKind::RemainderByZero, + AssertKind::DivisionByZero(op) => { + AssertKind::DivisionByZero(eval_to_int(op)) + } + AssertKind::RemainderByZero(op) => { + AssertKind::RemainderByZero(eval_to_int(op)) + } AssertKind::BoundsCheck { ref len, ref index } => { - let len = - self.eval_operand(len, source_info).expect("len must be const"); - let len = self - .ecx - .read_scalar(len) - .unwrap() - .to_machine_usize(&self.tcx) - .unwrap(); - let index = self - .eval_operand(index, source_info) - .expect("index must be const"); - let index = self - .ecx - .read_scalar(index) - .unwrap() - .to_machine_usize(&self.tcx) - .unwrap(); + let len = eval_to_int(len); + let index = eval_to_int(index); AssertKind::BoundsCheck { len, index } } // Overflow is are already covered by checks on the binary operators. - AssertKind::Overflow(_) | AssertKind::OverflowNeg => return, + AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return, // Need proper const propagator for these. _ => return, }; diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 59be8dc224dee..523d3c9af3f68 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -422,6 +422,9 @@ struct LivenessInfo { /// The set of saved locals live at each suspension point. live_locals_at_suspension_points: Vec>, + /// Parallel vec to the above with SourceInfo for each yield terminator. + source_info_at_suspension_points: Vec, + /// For every saved local, the set of other saved locals that are /// storage-live at the same time as this local. We cannot overlap locals in /// the layout which have conflicting storage. @@ -473,6 +476,7 @@ fn locals_live_across_suspend_points( let mut storage_liveness_map = IndexVec::from_elem(None, body.basic_blocks()); let mut live_locals_at_suspension_points = Vec::new(); + let mut source_info_at_suspension_points = Vec::new(); let mut live_locals_at_any_suspension_point = BitSet::new_empty(body.local_decls.len()); for (block, data) in body.basic_blocks().iter_enumerated() { @@ -518,6 +522,7 @@ fn locals_live_across_suspend_points( live_locals_at_any_suspension_point.union(&live_locals); live_locals_at_suspension_points.push(live_locals); + source_info_at_suspension_points.push(data.terminator().source_info); } } @@ -541,6 +546,7 @@ fn locals_live_across_suspend_points( LivenessInfo { saved_locals, live_locals_at_suspension_points, + source_info_at_suspension_points, storage_conflicts, storage_liveness: storage_liveness_map, } @@ -754,6 +760,7 @@ fn compute_layout<'tcx>( let LivenessInfo { saved_locals, live_locals_at_suspension_points, + source_info_at_suspension_points, storage_conflicts, storage_liveness, } = liveness; @@ -768,7 +775,18 @@ fn compute_layout<'tcx>( } // Leave empty variants for the UNRESUMED, RETURNED, and POISONED states. + // In debuginfo, these will correspond to the beginning (UNRESUMED) or end + // (RETURNED, POISONED) of the function. const RESERVED_VARIANTS: usize = 3; + let body_span = body.source_scopes[OUTERMOST_SOURCE_SCOPE].span; + let mut variant_source_info: IndexVec = [ + SourceInfo::outermost(body_span.shrink_to_lo()), + SourceInfo::outermost(body_span.shrink_to_hi()), + SourceInfo::outermost(body_span.shrink_to_hi()), + ] + .iter() + .copied() + .collect(); // Build the generator variant field list. // Create a map from local indices to generator struct indices. @@ -787,11 +805,13 @@ fn compute_layout<'tcx>( remap.entry(locals[saved_local]).or_insert((tys[saved_local], variant_index, idx)); } variant_fields.push(fields); + variant_source_info.push(source_info_at_suspension_points[suspension_point_idx]); } debug!("generator variant_fields = {:?}", variant_fields); debug!("generator storage_conflicts = {:#?}", storage_conflicts); - let layout = GeneratorLayout { field_tys: tys, variant_fields, storage_conflicts }; + let layout = + GeneratorLayout { field_tys: tys, variant_fields, variant_source_info, storage_conflicts }; (remap, layout, storage_liveness) } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 02614044063fc..db45481e4fd25 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -131,7 +131,7 @@ fn dump_matched_mir_node<'tcx, F>( } writeln!(file, " {} {}", disambiguator, pass_name)?; if let Some(ref layout) = body.generator_layout { - writeln!(file, "// generator_layout = {:?}", layout)?; + writeln!(file, "/* generator_layout = {:#?} */", layout)?; } writeln!(file)?; extra_data(PassWhere::BeforeCFG, &mut file)?; diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index 9531ff0a9071f..e2217fdfac036 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -87,7 +87,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, Operand::Move(is_min), false, - AssertKind::OverflowNeg, + AssertKind::OverflowNeg(arg.to_copy()), expr_span, ); } @@ -288,7 +288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, result_value, - Rvalue::CheckedBinaryOp(op, lhs, rhs), + Rvalue::CheckedBinaryOp(op, lhs.to_copy(), rhs.to_copy()), ); let val_fld = Field::new(0); let of_fld = Field::new(1); @@ -297,7 +297,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let val = tcx.mk_place_field(result_value, val_fld, ty); let of = tcx.mk_place_field(result_value, of_fld, bool_ty); - let err = AssertKind::Overflow(op); + let err = AssertKind::Overflow(op, lhs, rhs); block = self.assert(block, Operand::Move(of), false, err, span); @@ -308,11 +308,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // and 2. there are two possible failure cases, divide-by-zero and overflow. let zero_err = if op == BinOp::Div { - AssertKind::DivisionByZero + AssertKind::DivisionByZero(lhs.to_copy()) } else { - AssertKind::RemainderByZero + AssertKind::RemainderByZero(lhs.to_copy()) }; - let overflow_err = AssertKind::Overflow(op); + let overflow_err = AssertKind::Overflow(op, lhs.to_copy(), rhs.to_copy()); // Check for / 0 let is_zero = self.temp(bool_ty, span); diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 8e74c3847bc90..5050f03bea9b2 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -367,12 +367,15 @@ impl<'a> StringReader<'a> { } rustc_lexer::LiteralKind::ByteStr { terminated } => { if !terminated { - self.fatal_span_( - start + BytePos(1), - suffix_start, - "unterminated double quote byte string", - ) - .raise() + self.sess + .span_diagnostic + .struct_span_fatal_with_code( + self.mk_sp(start + BytePos(1), suffix_start), + "unterminated double quote byte string", + error_code!(E0766), + ) + .emit(); + FatalError.raise(); } (token::ByteStr, Mode::ByteStr, 2, 1) // b" " } diff --git a/src/librustc_parse/parser/attr.rs b/src/librustc_parse/parser/attr.rs index 803f14a2a228a..b8cb146145b98 100644 --- a/src/librustc_parse/parser/attr.rs +++ b/src/librustc_parse/parser/attr.rs @@ -155,7 +155,7 @@ impl<'a> Parser<'a> { /// The delimiters or `=` are still put into the resulting token stream. pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> { let item = match self.token.kind { - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()), _ => None, }, @@ -254,7 +254,7 @@ impl<'a> Parser<'a> { /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> { let nt_meta = match self.token.kind { - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { token::NtMeta(ref e) => Some(e.clone()), _ => None, }, diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 49a5c8801766c..2745b18a8cd51 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -26,7 +26,7 @@ use std::mem; /// `token::Interpolated` tokens. macro_rules! maybe_whole_expr { ($p:expr) => { - if let token::Interpolated(nt) = &$p.token.kind { + if let token::Interpolated(nt, _) = &$p.token.kind { match &**nt { token::NtExpr(e) | token::NtLiteral(e) => { let e = e.clone(); diff --git a/src/librustc_parse/parser/generics.rs b/src/librustc_parse/parser/generics.rs index 04b64d93c70dd..47794746126da 100644 --- a/src/librustc_parse/parser/generics.rs +++ b/src/librustc_parse/parser/generics.rs @@ -47,21 +47,21 @@ impl<'a> Parser<'a> { } fn parse_const_param(&mut self, preceding_attrs: Vec) -> PResult<'a, GenericParam> { - let lo = self.token.span; + let const_span = self.token.span; self.expect_keyword(kw::Const)?; let ident = self.parse_ident()?; self.expect(&token::Colon)?; let ty = self.parse_ty()?; - self.sess.gated_spans.gate(sym::const_generics, lo.to(self.prev_token.span)); + self.sess.gated_spans.gate(sym::const_generics, const_span.to(self.prev_token.span)); Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs.into(), bounds: Vec::new(), - kind: GenericParamKind::Const { ty }, + kind: GenericParamKind::Const { ty, kw_span: const_span }, is_placeholder: false, }) } diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 6f13d7994d17d..10df16964da08 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1780,7 +1780,7 @@ impl<'a> Parser<'a> { fn is_named_param(&self) -> bool { let offset = match self.token.kind { - token::Interpolated(ref nt) => match **nt { + token::Interpolated(ref nt, _) => match **nt { token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon), _ => 0, }, diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 7811d5fb741b2..04074479a21a4 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -54,7 +54,7 @@ enum BlockMode { #[macro_export] macro_rules! maybe_whole { ($p:expr, $constructor:ident, |$x:ident| $e:expr) => { - if let token::Interpolated(nt) = &$p.token.kind { + if let token::Interpolated(nt, _) = &$p.token.kind { if let token::$constructor(x) = &**nt { let $x = x.clone(); $p.bump(); @@ -69,7 +69,7 @@ macro_rules! maybe_whole { macro_rules! maybe_recover_from_interpolated_ty_qpath { ($self: expr, $allow_qpath_recovery: expr) => { if $allow_qpath_recovery && $self.look_ahead(1, |t| t == &token::ModSep) { - if let token::Interpolated(nt) = &$self.token.kind { + if let token::Interpolated(nt, _) = &$self.token.kind { if let token::NtTy(ty) = &**nt { let ty = ty.clone(); $self.bump(); @@ -922,7 +922,7 @@ impl<'a> Parser<'a> { if self.eat(&token::Eq) { let eq_span = self.prev_token.span; let mut is_interpolated_expr = false; - if let token::Interpolated(nt) = &self.token.kind { + if let token::Interpolated(nt, _) = &self.token.kind { if let token::NtExpr(..) = **nt { is_interpolated_expr = true; } diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs index 6603d0afc0248..742183d369735 100644 --- a/src/librustc_parse/parser/pat.rs +++ b/src/librustc_parse/parser/pat.rs @@ -515,7 +515,7 @@ impl<'a> Parser<'a> { self.recover_additional_muts(); // Make sure we don't allow e.g. `let mut $p;` where `$p:pat`. - if let token::Interpolated(ref nt) = self.token.kind { + if let token::Interpolated(ref nt, _) = self.token.kind { if let token::NtPat(_) = **nt { self.expected_ident_found().emit(); } diff --git a/src/librustc_passes/check_attr.rs b/src/librustc_passes/check_attr.rs index 80681c143750f..408f2e8c19a5d 100644 --- a/src/librustc_passes/check_attr.rs +++ b/src/librustc_passes/check_attr.rs @@ -21,7 +21,10 @@ use rustc_session::parse::feature_err; use rustc_span::symbol::sym; use rustc_span::Span; -fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target { +pub(crate) fn target_from_impl_item<'tcx>( + tcx: TyCtxt<'tcx>, + impl_item: &hir::ImplItem<'_>, +) -> Target { match impl_item.kind { hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Fn(..) => { diff --git a/src/librustc_passes/lang_items.rs b/src/librustc_passes/lang_items.rs index 779fb8039d157..f4167c8644e6e 100644 --- a/src/librustc_passes/lang_items.rs +++ b/src/librustc_passes/lang_items.rs @@ -7,17 +7,19 @@ //! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`. //! * Functions called by the compiler itself. +use crate::check_attr::target_from_impl_item; use crate::weak_lang_items; use rustc_middle::middle::cstore::ExternCrate; use rustc_middle::ty::TyCtxt; +use rustc_ast::ast::Attribute; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::lang_items::{extract, ITEM_REFS}; -use rustc_hir::{LangItem, LanguageItems, Target}; +use rustc_hir::{HirId, LangItem, LanguageItems, Target}; use rustc_middle::ty::query::Providers; @@ -28,12 +30,37 @@ struct LanguageItemCollector<'tcx> { impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { fn visit_item(&mut self, item: &hir::Item<'_>) { - if let Some((value, span)) = extract(&item.attrs) { - let actual_target = Target::from_item(item); + self.check_for_lang(Target::from_item(item), item.hir_id, item.attrs) + } + + fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { + self.check_for_lang( + Target::from_trait_item(trait_item), + trait_item.hir_id, + trait_item.attrs, + ) + } + + fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { + self.check_for_lang( + target_from_impl_item(self.tcx, impl_item), + impl_item.hir_id, + impl_item.attrs, + ) + } +} + +impl LanguageItemCollector<'tcx> { + fn new(tcx: TyCtxt<'tcx>) -> LanguageItemCollector<'tcx> { + LanguageItemCollector { tcx, items: LanguageItems::new() } + } + + fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId, attrs: &[Attribute]) { + if let Some((value, span)) = extract(&attrs) { match ITEM_REFS.get(&*value.as_str()).cloned() { // Known lang item with attribute on correct target. Some((item_index, expected_target)) if actual_target == expected_target => { - let def_id = self.tcx.hir().local_def_id(item.hir_id); + let def_id = self.tcx.hir().local_def_id(hir_id); self.collect_item(item_index, def_id.to_def_id()); } // Known lang item with attribute on incorrect target. @@ -71,20 +98,6 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { - // At present, lang items are always items, not trait items. - } - - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { - // At present, lang items are always items, not impl items. - } -} - -impl LanguageItemCollector<'tcx> { - fn new(tcx: TyCtxt<'tcx>) -> LanguageItemCollector<'tcx> { - LanguageItemCollector { tcx, items: LanguageItems::new() } - } - fn collect_item(&mut self, item_index: usize, item_def_id: DefId) { // Check for duplicates. if let Some(original_def_id) = self.items.items[item_index] { diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index ef43f597eab47..72faa68d0b243 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -1325,7 +1325,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> { } fn visit_token(&mut self, t: Token) { - if let token::Interpolated(nt) = t.kind { + if let token::Interpolated(nt, _) = t.kind { if let token::NtExpr(ref expr) = *nt { if let ast::ExprKind::MacCall(..) = expr.kind { self.visit_invoc(expr.id); diff --git a/src/librustc_resolve/def_collector.rs b/src/librustc_resolve/def_collector.rs index f1063f42c91ec..dc8d1a8d3fdf9 100644 --- a/src/librustc_resolve/def_collector.rs +++ b/src/librustc_resolve/def_collector.rs @@ -256,7 +256,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { } fn visit_token(&mut self, t: Token) { - if let token::Interpolated(nt) = t.kind { + if let token::Interpolated(nt, _) = t.kind { if let token::NtExpr(ref expr) = *nt { if let ExprKind::MacCall(..) = expr.kind { self.visit_macro_invoc(expr.id); diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index afe96ca700781..2854683b61bab 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -643,18 +643,18 @@ impl<'a> Resolver<'a> { let not_local_module = crate_name.name != kw::Crate; let mut worklist = vec![(start_module, Vec::::new(), true, not_local_module)]; + let mut worklist_via_import = vec![]; - while let Some((in_module, path_segments, accessible, in_module_is_extern)) = worklist.pop() + while let Some((in_module, path_segments, accessible, in_module_is_extern)) = + match worklist.pop() { + None => worklist_via_import.pop(), + Some(x) => Some(x), + } { // We have to visit module children in deterministic order to avoid // instabilities in reported imports (#43552). in_module.for_each_child(self, |this, ident, ns, name_binding| { - // avoid imports entirely - if name_binding.is_import() && !name_binding.is_extern_crate() { - return; - } - - // avoid non-importable candidates as well + // avoid non-importable candidates if !name_binding.is_importable() { return; } @@ -667,6 +667,17 @@ impl<'a> Resolver<'a> { return; } + let via_import = name_binding.is_import() && !name_binding.is_extern_crate(); + + // There is an assumption elsewhere that paths of variants are in the enum's + // declaration and not imported. With this assumption, the variant component is + // chopped and the rest of the path is assumed to be the enum's own path. For + // errors where a variant is used as the type instead of the enum, this causes + // funny looking invalid suggestions, i.e `foo` instead of `foo::MyEnum`. + if via_import && name_binding.is_possibly_imported_variant() { + return; + } + // collect results based on the filter function // avoid suggesting anything from the same module in which we are resolving if ident.name == lookup_ident.name @@ -724,7 +735,8 @@ impl<'a> Resolver<'a> { let is_extern = in_module_is_extern || name_binding.is_extern_crate(); // add the module to the lookup if seen_modules.insert(module.def_id().unwrap()) { - worklist.push((module, path_segments, child_accessible, is_extern)); + if via_import { &mut worklist_via_import } else { &mut worklist } + .push((module, path_segments, child_accessible, is_extern)); } } } diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 6f769c3c59cae..b8fb813ea155f 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -536,8 +536,8 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { for param in &generics.params { match param.kind { - GenericParamKind::Lifetime { .. } => self.visit_generic_param(param), - GenericParamKind::Type { ref default, .. } => { + GenericParamKind::Lifetime => self.visit_generic_param(param), + GenericParamKind::Type { ref default } => { for bound in ¶m.bounds { self.visit_param_bound(bound); } @@ -551,7 +551,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // Allow all following defaults to refer to this type parameter. default_ban_rib.bindings.remove(&Ident::with_dummy_span(param.ident.name)); } - GenericParamKind::Const { ref ty } => { + GenericParamKind::Const { ref ty, kw_span: _ } => { for bound in ¶m.bounds { self.visit_param_bound(bound); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ce068b8ac69a4..9ddcf9e1de7d1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -703,6 +703,13 @@ impl<'a> NameBinding<'a> { } } + fn is_possibly_imported_variant(&self) -> bool { + match self.kind { + NameBindingKind::Import { binding, .. } => binding.is_possibly_imported_variant(), + _ => self.is_variant(), + } + } + // We sometimes need to treat variants as `pub` for backwards compatibility. fn pseudo_vis(&self) -> ty::Visibility { if self.is_variant() && self.res().def_id().is_local() { diff --git a/src/librustc_session/filesearch.rs b/src/librustc_session/filesearch.rs index 5586b82b0edc0..27396c524f4e6 100644 --- a/src/librustc_session/filesearch.rs +++ b/src/librustc_session/filesearch.rs @@ -41,7 +41,7 @@ impl<'a> FileSearch<'a> { make_target_lib_path(self.sysroot, self.triple) } - pub fn get_selfcontained_lib_path(&self) -> PathBuf { + pub fn get_self_contained_lib_path(&self) -> PathBuf { self.get_lib_path().join("self-contained") } @@ -92,13 +92,13 @@ impl<'a> FileSearch<'a> { } // Returns a list of directories where target-specific tool binaries are located. - pub fn get_tools_search_paths(&self) -> Vec { + pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec { let mut p = PathBuf::from(self.sysroot); p.push(find_libdir(self.sysroot).as_ref()); p.push(RUST_LIB_DIR); p.push(&self.triple); p.push("bin"); - vec![p.clone(), p.join("self-contained")] + if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p.clone()] } } } diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 973891eb84eda..9337f241d7022 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -889,6 +889,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "keep hygiene data after analysis (default: no)"), link_native_libraries: bool = (true, parse_bool, [UNTRACKED], "link native libraries in the linker invocation (default: yes)"), + link_self_contained: Option = (None, parse_opt_bool, [TRACKED], + "control whether to link Rust provided C objects/libraries or rely + on C toolchain installed in the system"), link_only: bool = (false, parse_bool, [TRACKED], "link the `.rlink` file generated by `-Z no-link` (default: no)"), llvm_time_trace: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/librustc_session/parse.rs b/src/librustc_session/parse.rs index ddbc95fb1b0b8..b428315b3cdf3 100644 --- a/src/librustc_session/parse.rs +++ b/src/librustc_session/parse.rs @@ -13,6 +13,7 @@ use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::{MultiSpan, Span, Symbol}; +use std::collections::BTreeMap; use std::path::PathBuf; use std::str; @@ -63,7 +64,7 @@ impl GatedSpans { #[derive(Default)] pub struct SymbolGallery { /// All symbols occurred and their first occurrance span. - pub symbols: Lock>, + pub symbols: Lock>, } impl SymbolGallery { @@ -135,6 +136,8 @@ pub struct ParseSess { pub symbol_gallery: SymbolGallery, /// The parser has reached `Eof` due to an unclosed brace. Used to silence unnecessary errors. pub reached_eof: Lock, + /// Environment variables accessed during the build and their values when they exist. + pub env_depinfo: Lock)>>, } impl ParseSess { @@ -160,6 +163,7 @@ impl ParseSess { gated_spans: GatedSpans::default(), symbol_gallery: SymbolGallery::default(), reached_eof: Lock::new(false), + env_depinfo: Default::default(), } } diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index fa1368b104c7e..857734037afe7 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -832,6 +832,7 @@ symbols! { v1, val, var, + variant_count, vec, Vec, version, diff --git a/src/librustc_target/asm/arm.rs b/src/librustc_target/asm/arm.rs index 1798b2a094975..85a136b94aa79 100644 --- a/src/librustc_target/asm/arm.rs +++ b/src/librustc_target/asm/arm.rs @@ -1,4 +1,5 @@ use super::{InlineAsmArch, InlineAsmType}; +use crate::spec::Target; use rustc_macros::HashStable_Generic; use std::fmt; @@ -58,6 +59,37 @@ impl ArmInlineAsmRegClass { } } +// This uses the same logic as useR7AsFramePointer in LLVM +fn frame_pointer_is_r7(mut has_feature: impl FnMut(&str) -> bool, target: &Target) -> bool { + target.options.is_like_osx || (!target.options.is_like_windows && has_feature("thumb-mode")) +} + +fn frame_pointer_r11( + _arch: InlineAsmArch, + has_feature: impl FnMut(&str) -> bool, + target: &Target, + _allocating: bool, +) -> Result<(), &'static str> { + if !frame_pointer_is_r7(has_feature, target) { + Err("the frame pointer (r11) cannot be used as an operand for inline asm") + } else { + Ok(()) + } +} + +fn frame_pointer_r7( + _arch: InlineAsmArch, + has_feature: impl FnMut(&str) -> bool, + target: &Target, + _allocating: bool, +) -> Result<(), &'static str> { + if frame_pointer_is_r7(has_feature, target) { + Err("the frame pointer (r7) cannot be used as an operand for inline asm") + } else { + Ok(()) + } +} + def_regs! { Arm ArmInlineAsmReg ArmInlineAsmRegClass { r0: reg, reg_thumb = ["r0", "a1"], @@ -66,11 +98,11 @@ def_regs! { r3: reg, reg_thumb = ["r3", "a4"], r4: reg, reg_thumb = ["r4", "v1"], r5: reg, reg_thumb = ["r5", "v2"], - r6: reg, reg_thumb = ["r6", "v3"], - r7: reg, reg_thumb = ["r7", "v4"], + r7: reg, reg_thumb = ["r7", "v4"] % frame_pointer_r7, r8: reg = ["r8", "v5"], r9: reg = ["r9", "v6", "rfp"], r10: reg = ["r10", "sl"], + r11: reg = ["r11", "fp"] % frame_pointer_r11, r12: reg = ["r12", "ip"], r14: reg = ["r14", "lr"], s0: sreg, sreg_low16 = ["s0"], @@ -153,8 +185,8 @@ def_regs! { q13: qreg = ["q13"], q14: qreg = ["q14"], q15: qreg = ["q15"], - #error = ["r11", "fp"] => - "the frame pointer cannot be used as an operand for inline asm", + #error = ["r6", "v3"] => + "r6 is used internally by LLVM and cannot be used as an operand for inline asm", #error = ["r13", "sp"] => "the stack pointer cannot be used as an operand for inline asm", #error = ["r15", "pc"] => diff --git a/src/librustc_target/asm/mod.rs b/src/librustc_target/asm/mod.rs index 834d7c6d381a3..ccec17817d37d 100644 --- a/src/librustc_target/asm/mod.rs +++ b/src/librustc_target/asm/mod.rs @@ -1,4 +1,5 @@ use crate::abi::Size; +use crate::spec::Target; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_macros::HashStable_Generic; use rustc_span::Symbol; @@ -83,12 +84,13 @@ macro_rules! def_regs { pub fn parse( _arch: super::InlineAsmArch, mut _has_feature: impl FnMut(&str) -> bool, + _target: &crate::spec::Target, name: &str, ) -> Result { match name { $( $($alias)|* | $reg_name => { - $($filter(_arch, &mut _has_feature, false)?;)? + $($filter(_arch, &mut _has_feature, _target, false)?;)? Ok(Self::$reg) } )* @@ -103,6 +105,7 @@ macro_rules! def_regs { pub(super) fn fill_reg_map( _arch: super::InlineAsmArch, mut _has_feature: impl FnMut(&str) -> bool, + _target: &crate::spec::Target, _map: &mut rustc_data_structures::fx::FxHashMap< super::InlineAsmRegClass, rustc_data_structures::fx::FxHashSet, @@ -111,7 +114,7 @@ macro_rules! def_regs { #[allow(unused_imports)] use super::{InlineAsmReg, InlineAsmRegClass}; $( - if $($filter(_arch, &mut _has_feature, true).is_ok() &&)? true { + if $($filter(_arch, &mut _has_feature, _target, true).is_ok() &&)? true { if let Some(set) = _map.get_mut(&InlineAsmRegClass::$arch($arch_regclass::$class)) { set.insert(InlineAsmReg::$arch($arch_reg::$reg)); } @@ -234,6 +237,7 @@ impl InlineAsmReg { pub fn parse( arch: InlineAsmArch, has_feature: impl FnMut(&str) -> bool, + target: &Target, name: Symbol, ) -> Result { // FIXME: use direct symbol comparison for register names @@ -241,20 +245,22 @@ impl InlineAsmReg { let name = name.as_str(); Ok(match arch { InlineAsmArch::X86 | InlineAsmArch::X86_64 => { - Self::X86(X86InlineAsmReg::parse(arch, has_feature, &name)?) + Self::X86(X86InlineAsmReg::parse(arch, has_feature, target, &name)?) + } + InlineAsmArch::Arm => { + Self::Arm(ArmInlineAsmReg::parse(arch, has_feature, target, &name)?) } - InlineAsmArch::Arm => Self::Arm(ArmInlineAsmReg::parse(arch, has_feature, &name)?), InlineAsmArch::AArch64 => { - Self::AArch64(AArch64InlineAsmReg::parse(arch, has_feature, &name)?) + Self::AArch64(AArch64InlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => { - Self::RiscV(RiscVInlineAsmReg::parse(arch, has_feature, &name)?) + Self::RiscV(RiscVInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::Nvptx64 => { - Self::Nvptx(NvptxInlineAsmReg::parse(arch, has_feature, &name)?) + Self::Nvptx(NvptxInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::Hexagon => { - Self::Hexagon(HexagonInlineAsmReg::parse(arch, has_feature, &name)?) + Self::Hexagon(HexagonInlineAsmReg::parse(arch, has_feature, target, &name)?) } }) } @@ -536,36 +542,37 @@ impl fmt::Display for InlineAsmType { pub fn allocatable_registers( arch: InlineAsmArch, has_feature: impl FnMut(&str) -> bool, + target: &crate::spec::Target, ) -> FxHashMap> { match arch { InlineAsmArch::X86 | InlineAsmArch::X86_64 => { let mut map = x86::regclass_map(); - x86::fill_reg_map(arch, has_feature, &mut map); + x86::fill_reg_map(arch, has_feature, target, &mut map); map } InlineAsmArch::Arm => { let mut map = arm::regclass_map(); - arm::fill_reg_map(arch, has_feature, &mut map); + arm::fill_reg_map(arch, has_feature, target, &mut map); map } InlineAsmArch::AArch64 => { let mut map = aarch64::regclass_map(); - aarch64::fill_reg_map(arch, has_feature, &mut map); + aarch64::fill_reg_map(arch, has_feature, target, &mut map); map } InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => { let mut map = riscv::regclass_map(); - riscv::fill_reg_map(arch, has_feature, &mut map); + riscv::fill_reg_map(arch, has_feature, target, &mut map); map } InlineAsmArch::Nvptx64 => { let mut map = nvptx::regclass_map(); - nvptx::fill_reg_map(arch, has_feature, &mut map); + nvptx::fill_reg_map(arch, has_feature, target, &mut map); map } InlineAsmArch::Hexagon => { let mut map = hexagon::regclass_map(); - hexagon::fill_reg_map(arch, has_feature, &mut map); + hexagon::fill_reg_map(arch, has_feature, target, &mut map); map } } diff --git a/src/librustc_target/asm/riscv.rs b/src/librustc_target/asm/riscv.rs index 3ff542247ff02..ced7483b00571 100644 --- a/src/librustc_target/asm/riscv.rs +++ b/src/librustc_target/asm/riscv.rs @@ -1,4 +1,5 @@ use super::{InlineAsmArch, InlineAsmType}; +use crate::spec::Target; use rustc_macros::HashStable_Generic; use std::fmt; @@ -50,6 +51,7 @@ impl RiscVInlineAsmRegClass { fn not_e( _arch: InlineAsmArch, mut has_feature: impl FnMut(&str) -> bool, + _target: &Target, _allocating: bool, ) -> Result<(), &'static str> { if has_feature("e") { diff --git a/src/librustc_target/asm/x86.rs b/src/librustc_target/asm/x86.rs index ed51b526414d1..0f62c19e1a3cd 100644 --- a/src/librustc_target/asm/x86.rs +++ b/src/librustc_target/asm/x86.rs @@ -1,4 +1,5 @@ use super::{InlineAsmArch, InlineAsmType}; +use crate::spec::Target; use rustc_macros::HashStable_Generic; use std::fmt; @@ -131,6 +132,7 @@ impl X86InlineAsmRegClass { fn x86_64_only( arch: InlineAsmArch, _has_feature: impl FnMut(&str) -> bool, + _target: &Target, _allocating: bool, ) -> Result<(), &'static str> { match arch { @@ -143,6 +145,7 @@ fn x86_64_only( fn high_byte( arch: InlineAsmArch, _has_feature: impl FnMut(&str) -> bool, + _target: &Target, allocating: bool, ) -> Result<(), &'static str> { match arch { diff --git a/src/librustc_target/spec/apple_sdk_base.rs b/src/librustc_target/spec/apple_sdk_base.rs index b07c2aef1caca..0d0a0da9d1c4c 100644 --- a/src/librustc_target/spec/apple_sdk_base.rs +++ b/src/librustc_target/spec/apple_sdk_base.rs @@ -141,7 +141,6 @@ pub fn opts(arch: Arch, os: AppleOS) -> Result { let pre_link_args = build_pre_link_args(arch, os)?; Ok(TargetOptions { cpu: target_cpu(arch), - dynamic_linking: false, executables: true, pre_link_args, link_env_remove: link_env_remove(arch), diff --git a/src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs b/src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs index 81974769cafb8..d01545619c8fa 100644 --- a/src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs +++ b/src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs @@ -48,8 +48,10 @@ pub fn target() -> Result { "ENCLAVE_SIZE", "CFGDATA_BASE", "DEBUG", - "EH_FRM_HDR_BASE", - "EH_FRM_HDR_SIZE", + "EH_FRM_HDR_OFFSET", + "EH_FRM_HDR_LEN", + "EH_FRM_OFFSET", + "EH_FRM_LEN", "TEXT_BASE", "TEXT_SIZE", ]; diff --git a/src/librustc_trait_selection/traits/chalk_fulfill.rs b/src/librustc_trait_selection/traits/chalk_fulfill.rs index cbbff82d35f73..2ade489275262 100644 --- a/src/librustc_trait_selection/traits/chalk_fulfill.rs +++ b/src/librustc_trait_selection/traits/chalk_fulfill.rs @@ -7,17 +7,17 @@ use crate::traits::{ ChalkEnvironmentAndGoal, ChalkEnvironmentClause, FulfillmentError, FulfillmentErrorCode, ObligationCause, PredicateObligation, SelectionError, TraitEngine, }; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::FxIndexSet; use rustc_hir::def_id::DefId; use rustc_middle::ty::{self, Ty, TyCtxt}; pub struct FulfillmentContext<'tcx> { - obligations: FxHashSet>, + obligations: FxIndexSet>, } impl FulfillmentContext<'tcx> { crate fn new() -> Self { - FulfillmentContext { obligations: FxHashSet::default() } + FulfillmentContext { obligations: FxIndexSet::default() } } } @@ -79,7 +79,7 @@ fn environment<'tcx>( }; // FIXME(eddyb) isn't the unordered nature of this a hazard? - let mut inputs = FxHashSet::default(); + let mut inputs = FxIndexSet::default(); match node_kind { // In a trait impl, we assume that the header trait ref and all its @@ -140,7 +140,8 @@ fn in_environment( None if obligation.param_env.caller_bounds.is_empty() => ty::List::empty(), // FIXME(chalk): this is hit in ui/where-clauses/where-clause-constraints-are-local-for-trait-impl // and ui/generics/generic-static-methods - _ => bug!("non-empty `ParamEnv` with no def-id"), + //_ => bug!("non-empty `ParamEnv` with no def-id"), + _ => ty::List::empty(), }; ChalkEnvironmentAndGoal { environment, goal: obligation.predicate } @@ -195,7 +196,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { infcx: &InferCtxt<'_, 'tcx>, ) -> Result<(), Vec>> { let mut errors = Vec::new(); - let mut next_round = FxHashSet::default(); + let mut next_round = FxIndexSet::default(); let mut making_progress; loop { @@ -203,7 +204,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { // We iterate over all obligations, and record if we are able // to unambiguously prove at least one obligation. - for obligation in self.obligations.drain() { + for obligation in self.obligations.drain(..) { let goal_in_environment = in_environment(infcx, &obligation); let mut orig_values = OriginalQueryValues::default(); let canonical_goal = diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index bc696214cbc66..f71b3fcf129da 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -23,13 +23,13 @@ use crate::traits::error_reporting::InferCtxtExt; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorReported; use rustc_hir::def_id::DefId; -use rustc_hir::lang_items::{FnOnceTraitLangItem, GeneratorTraitLangItem}; +use rustc_hir::lang_items::{FnOnceOutputLangItem, FnOnceTraitLangItem, GeneratorTraitLangItem}; use rustc_infer::infer::resolve::OpportunisticRegionResolver; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, WithConstness}; -use rustc_span::symbol::{sym, Ident}; +use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; pub use rustc_middle::traits::Reveal; @@ -1399,8 +1399,8 @@ fn confirm_callable_candidate<'cx, 'tcx>( debug!("confirm_callable_candidate({:?},{:?})", obligation, fn_sig); - // the `Output` associated type is declared on `FnOnce` let fn_once_def_id = tcx.require_lang_item(FnOnceTraitLangItem, None); + let fn_once_output_def_id = tcx.require_lang_item(FnOnceOutputLangItem, None); let predicate = super::util::closure_trait_ref_and_return_type( tcx, @@ -1410,11 +1410,10 @@ fn confirm_callable_candidate<'cx, 'tcx>( flag, ) .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy::from_ref_and_name( - tcx, - trait_ref, - Ident::with_dummy_span(rustc_hir::FN_OUTPUT_NAME), - ), + projection_ty: ty::ProjectionTy { + substs: trait_ref.substs, + item_def_id: fn_once_output_def_id, + }, ty: ret_type, }); diff --git a/src/librustc_traits/Cargo.toml b/src/librustc_traits/Cargo.toml index 8def98a9603d8..079b9b10fd090 100644 --- a/src/librustc_traits/Cargo.toml +++ b/src/librustc_traits/Cargo.toml @@ -16,8 +16,8 @@ rustc_hir = { path = "../librustc_hir" } rustc_index = { path = "../librustc_index" } rustc_ast = { path = "../librustc_ast" } rustc_span = { path = "../librustc_span" } -chalk-ir = "0.11.0" -chalk-solve = "0.11.0" +chalk-ir = "0.14.0" +chalk-solve = "0.14.0" smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_infer = { path = "../librustc_infer" } rustc_trait_selection = { path = "../librustc_trait_selection" } diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 235497d374098..715e5299a37bd 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -8,7 +8,7 @@ use rustc_middle::traits::ChalkRustInterner as RustInterner; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; -use rustc_middle::ty::{self, AssocItemContainer, AssocKind, Binder, TyCtxt}; +use rustc_middle::ty::{self, AssocItemContainer, AssocKind, TyCtxt}; use rustc_hir::def_id::DefId; @@ -85,14 +85,29 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t .iter() .map(|(wc, _)| wc.subst(self.tcx, &bound_vars)) .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)).collect(); + let associated_ty_ids: Vec<_> = self + .tcx + .associated_items(def_id) + .in_definition_order() + .filter(|i| i.kind == AssocKind::Type) + .map(|i| chalk_ir::AssocTypeId(i.def_id)) + .collect(); let well_known = if self.tcx.lang_items().sized_trait().map(|t| def_id == t).unwrap_or(false) { - Some(chalk_solve::rust_ir::WellKnownTrait::SizedTrait) + Some(chalk_solve::rust_ir::WellKnownTrait::Sized) } else if self.tcx.lang_items().copy_trait().map(|t| def_id == t).unwrap_or(false) { - Some(chalk_solve::rust_ir::WellKnownTrait::CopyTrait) + Some(chalk_solve::rust_ir::WellKnownTrait::Copy) } else if self.tcx.lang_items().clone_trait().map(|t| def_id == t).unwrap_or(false) { - Some(chalk_solve::rust_ir::WellKnownTrait::CloneTrait) + Some(chalk_solve::rust_ir::WellKnownTrait::Clone) + } else if self.tcx.lang_items().drop_trait().map(|t| def_id == t).unwrap_or(false) { + Some(chalk_solve::rust_ir::WellKnownTrait::Drop) + } else if self.tcx.lang_items().fn_trait().map(|t| def_id == t).unwrap_or(false) { + Some(chalk_solve::rust_ir::WellKnownTrait::Fn) + } else if self.tcx.lang_items().fn_once_trait().map(|t| def_id == t).unwrap_or(false) { + Some(chalk_solve::rust_ir::WellKnownTrait::FnOnce) + } else if self.tcx.lang_items().fn_mut_trait().map(|t| def_id == t).unwrap_or(false) { + Some(chalk_solve::rust_ir::WellKnownTrait::FnMut) } else { None }; @@ -110,7 +125,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t non_enumerable: true, coinductive: false, }, - associated_ty_ids: vec![], + associated_ty_ids, well_known, }) } @@ -156,6 +171,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t flags: chalk_solve::rust_ir::AdtFlags { upstream: !adt_def.did.is_local(), fundamental: adt_def.is_fundamental(), + phantom_data: adt_def.is_phantom_data(), }, }); return struct_datum; @@ -176,28 +192,32 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)).collect(); let sig = self.tcx.fn_sig(def_id); - // FIXME(chalk): collect into an intermediate SmallVec here since - // we need `TypeFoldable` for `no_bound_vars` - let argument_types: Binder> = - sig.map_bound(|i| i.inputs().iter().copied().collect()); - let argument_types = argument_types - .no_bound_vars() - .expect("FIXME(chalk): late-bound fn parameters not supported in chalk") + let inputs_and_output = sig.inputs_and_output(); + let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars( + &self.interner, + self.tcx, + &inputs_and_output, + ); + + let argument_types = inputs_and_output[..inputs_and_output.len() - 1] .iter() .map(|t| t.subst(self.tcx, &bound_vars).lower_into(&self.interner)) .collect(); - let return_type = sig - .output() - .no_bound_vars() - .expect("FIXME(chalk): late-bound fn parameters not supported in chalk") + let return_type = inputs_and_output[inputs_and_output.len() - 1] .subst(self.tcx, &bound_vars) .lower_into(&self.interner); - let bound = - chalk_solve::rust_ir::FnDefDatumBound { argument_types, where_clauses, return_type }; + let bound = chalk_solve::rust_ir::FnDefDatumBound { + inputs_and_output: chalk_ir::Binders::new( + iobinders, + chalk_solve::rust_ir::FnDefInputsAndOutputDatum { argument_types, return_type }, + ), + where_clauses, + }; Arc::new(chalk_solve::rust_ir::FnDefDatum { id: fn_def_id, + abi: sig.abi(), binders: chalk_ir::Binders::new(binders, bound), }) } @@ -326,9 +346,16 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t &self, opaque_ty_id: chalk_ir::OpaqueTyId>, ) -> Arc>> { - // FIXME(chalk): actually lower opaque ty + let bound_vars = bound_vars_for_item(self.tcx, opaque_ty_id.0); + let binders = binders_for(&self.interner, bound_vars); + let predicates = self.tcx.predicates_defined_on(opaque_ty_id.0).predicates; + let where_clauses: Vec<_> = predicates + .iter() + .map(|(wc, _)| wc.subst(self.tcx, &bound_vars)) + .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)).collect(); + let value = chalk_solve::rust_ir::OpaqueTyDatumBound { - bounds: chalk_ir::Binders::new(chalk_ir::VariableKinds::new(&self.interner), vec![]), + bounds: chalk_ir::Binders::new(binders, where_clauses), }; Arc::new(chalk_solve::rust_ir::OpaqueTyDatum { opaque_ty_id, @@ -346,7 +373,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t ) -> Option { use chalk_ir::TyData::*; match well_known { - chalk_solve::rust_ir::WellKnownTrait::SizedTrait => match ty { + chalk_solve::rust_ir::WellKnownTrait::Sized => match ty { Apply(apply) => match apply.name { chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() { ty::AdtKind::Struct | ty::AdtKind::Union => None, @@ -364,8 +391,8 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t | InferenceVar(_, _) | BoundVar(_) => None, }, - chalk_solve::rust_ir::WellKnownTrait::CopyTrait - | chalk_solve::rust_ir::WellKnownTrait::CloneTrait => match ty { + chalk_solve::rust_ir::WellKnownTrait::Copy + | chalk_solve::rust_ir::WellKnownTrait::Clone => match ty { Apply(apply) => match apply.name { chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() { ty::AdtKind::Struct | ty::AdtKind::Union => None, @@ -383,7 +410,11 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t | InferenceVar(_, _) | BoundVar(_) => None, }, - chalk_solve::rust_ir::WellKnownTrait::DropTrait => None, + chalk_solve::rust_ir::WellKnownTrait::Drop => None, + chalk_solve::rust_ir::WellKnownTrait::Fn => None, + chalk_solve::rust_ir::WellKnownTrait::FnMut => None, + chalk_solve::rust_ir::WellKnownTrait::FnOnce => None, + chalk_solve::rust_ir::WellKnownTrait::Unsize => None, } } @@ -399,17 +430,17 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t well_known_trait: chalk_solve::rust_ir::WellKnownTrait, ) -> Option>> { use chalk_solve::rust_ir::WellKnownTrait::*; - let t = match well_known_trait { - SizedTrait => { - self.tcx.lang_items().sized_trait().map(|t| chalk_ir::TraitId(t)).unwrap() - } - CopyTrait => self.tcx.lang_items().copy_trait().map(|t| chalk_ir::TraitId(t)).unwrap(), - CloneTrait => { - self.tcx.lang_items().clone_trait().map(|t| chalk_ir::TraitId(t)).unwrap() - } - DropTrait => self.tcx.lang_items().drop_trait().map(|t| chalk_ir::TraitId(t)).unwrap(), + let def_id = match well_known_trait { + Sized => self.tcx.lang_items().sized_trait(), + Copy => self.tcx.lang_items().copy_trait(), + Clone => self.tcx.lang_items().clone_trait(), + Drop => self.tcx.lang_items().drop_trait(), + Fn => self.tcx.lang_items().fn_trait(), + FnMut => self.tcx.lang_items().fn_mut_trait(), + FnOnce => self.tcx.lang_items().fn_once_trait(), + Unsize => self.tcx.lang_items().unsize_trait(), }; - Some(t) + def_id.map(|t| chalk_ir::TraitId(t)) } fn is_object_safe(&self, trait_id: chalk_ir::TraitId>) -> bool { @@ -423,6 +454,87 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t // FIXME(chalk): actually get hidden ty self.tcx.mk_ty(ty::Tuple(self.tcx.intern_substs(&[]))).lower_into(&self.interner) } + + fn closure_kind( + &self, + _closure_id: chalk_ir::ClosureId>, + substs: &chalk_ir::Substitution>, + ) -> chalk_solve::rust_ir::ClosureKind { + let kind = &substs.parameters(&self.interner)[substs.len(&self.interner) - 3]; + match kind.assert_ty_ref(&self.interner).data(&self.interner) { + chalk_ir::TyData::Apply(apply) => match apply.name { + chalk_ir::TypeName::Scalar(scalar) => match scalar { + chalk_ir::Scalar::Int(int_ty) => match int_ty { + chalk_ir::IntTy::I8 => chalk_solve::rust_ir::ClosureKind::Fn, + chalk_ir::IntTy::I16 => chalk_solve::rust_ir::ClosureKind::FnMut, + chalk_ir::IntTy::I32 => chalk_solve::rust_ir::ClosureKind::FnOnce, + _ => bug!("bad closure kind"), + }, + _ => bug!("bad closure kind"), + }, + _ => bug!("bad closure kind"), + }, + _ => bug!("bad closure kind"), + } + } + + fn closure_inputs_and_output( + &self, + _closure_id: chalk_ir::ClosureId>, + substs: &chalk_ir::Substitution>, + ) -> chalk_ir::Binders>> + { + let sig = &substs.parameters(&self.interner)[substs.len(&self.interner) - 2]; + match sig.assert_ty_ref(&self.interner).data(&self.interner) { + chalk_ir::TyData::Function(f) => { + let substitution = f.substitution.parameters(&self.interner); + let return_type = + substitution.last().unwrap().assert_ty_ref(&self.interner).clone(); + // Closure arguments are tupled + let argument_tuple = substitution[0].assert_ty_ref(&self.interner); + let argument_types = match argument_tuple.data(&self.interner) { + chalk_ir::TyData::Apply(apply) => match apply.name { + chalk_ir::TypeName::Tuple(_) => apply + .substitution + .iter(&self.interner) + .map(|arg| arg.assert_ty_ref(&self.interner)) + .cloned() + .collect(), + _ => bug!("Expecting closure FnSig args to be tupled."), + }, + _ => bug!("Expecting closure FnSig args to be tupled."), + }; + + chalk_ir::Binders::new( + chalk_ir::VariableKinds::from( + &self.interner, + (0..f.num_binders).map(|_| chalk_ir::VariableKind::Lifetime), + ), + chalk_solve::rust_ir::FnDefInputsAndOutputDatum { argument_types, return_type }, + ) + } + _ => panic!("Invalid sig."), + } + } + + fn closure_upvars( + &self, + _closure_id: chalk_ir::ClosureId>, + substs: &chalk_ir::Substitution>, + ) -> chalk_ir::Binders>> { + let inputs_and_output = self.closure_inputs_and_output(_closure_id, substs); + let tuple = substs.parameters(&self.interner).last().unwrap().assert_ty_ref(&self.interner); + inputs_and_output.map_ref(|_| tuple.clone()) + } + + fn closure_fn_substitution( + &self, + _closure_id: chalk_ir::ClosureId>, + substs: &chalk_ir::Substitution>, + ) -> chalk_ir::Substitution> { + let substitution = &substs.parameters(&self.interner)[0..substs.len(&self.interner) - 3]; + chalk_ir::Substitution::from(&self.interner, substitution) + } } /// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked diff --git a/src/librustc_traits/chalk/lowering.rs b/src/librustc_traits/chalk/lowering.rs index 5546a8db53395..e09359b8b3fc1 100644 --- a/src/librustc_traits/chalk/lowering.rs +++ b/src/librustc_traits/chalk/lowering.rs @@ -43,6 +43,8 @@ use rustc_span::def_id::DefId; use std::collections::btree_map::{BTreeMap, Entry}; +use chalk_ir::fold::shift::Shift; + /// Essentially an `Into` with a `&RustInterner` parameter crate trait LowerInto<'tcx, T> { /// Lower a rustc construct (e.g., `ty::TraitPredicate`) to a chalk type, consuming `self`. @@ -82,7 +84,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::InEnvironment Some( - chalk_ir::ProgramClauseData::Implies(chalk_ir::ProgramClauseImplication { - consequence: chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty( - ty.lower_into(interner), - )), - conditions: chalk_ir::Goals::new(interner), - priority: chalk_ir::ClausePriority::High, - }) + chalk_ir::ProgramClauseData(chalk_ir::Binders::new( + chalk_ir::VariableKinds::new(interner), + chalk_ir::ProgramClauseImplication { + consequence: chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty( + ty.lower_into(interner).shifted_in(interner), + )), + conditions: chalk_ir::Goals::new(interner), + priority: chalk_ir::ClausePriority::High, + }, + )) .intern(interner), ), }); @@ -416,12 +421,15 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { }) .intern(interner) } - // FIXME(chalk): add region - Dynamic(predicates, _region) => { - TyData::Dyn(chalk_ir::DynTy { bounds: predicates.lower_into(interner) }) - .intern(interner) - } - Closure(_def_id, _) => unimplemented!(), + Dynamic(predicates, region) => TyData::Dyn(chalk_ir::DynTy { + bounds: predicates.lower_into(interner), + lifetime: region.lower_into(interner), + }) + .intern(interner), + Closure(def_id, substs) => apply( + chalk_ir::TypeName::Closure(chalk_ir::ClosureId(def_id)), + substs.lower_into(interner), + ), Generator(_def_id, _substs, _) => unimplemented!(), GeneratorWitness(_) => unimplemented!(), Never => apply(chalk_ir::TypeName::Never, empty()), @@ -624,7 +632,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>( } (0..parameters.len()).for_each(|i| { - parameters.get(&(i as u32)).expect("Skipped bound var index."); + parameters.get(&(i as u32)).expect(&format!("Skipped bound var index `{:?}`.", i)); }); let binders = chalk_ir::VariableKinds::from(interner, parameters.into_iter().map(|(_, v)| v)); diff --git a/src/librustc_traits/chalk/mod.rs b/src/librustc_traits/chalk/mod.rs index 6f657be0908b4..52ec0f2409dce 100644 --- a/src/librustc_traits/chalk/mod.rs +++ b/src/librustc_traits/chalk/mod.rs @@ -133,6 +133,7 @@ crate fn evaluate_goal<'tcx>( }, chalk_ir::TypeName::Array => unimplemented!(), chalk_ir::TypeName::FnDef(_) => unimplemented!(), + chalk_ir::TypeName::Closure(_) => unimplemented!(), chalk_ir::TypeName::Never => unimplemented!(), chalk_ir::TypeName::Tuple(_size) => unimplemented!(), chalk_ir::TypeName::Slice => unimplemented!(), diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index ef6c7c14404a7..1c0b22ca7370b 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -75,7 +75,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: &str) -> hir::Unsafety { | "saturating_sub" | "rotate_left" | "rotate_right" | "ctpop" | "ctlz" | "cttz" | "bswap" | "bitreverse" | "discriminant_value" | "type_id" | "likely" | "unlikely" | "ptr_guaranteed_eq" | "ptr_guaranteed_ne" | "minnumf32" | "minnumf64" | "maxnumf32" - | "maxnumf64" | "type_name" => hir::Unsafety::Normal, + | "maxnumf64" | "type_name" | "variant_count" => hir::Unsafety::Normal, _ => hir::Unsafety::Unsafe, } } @@ -137,7 +137,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let unsafety = intrinsic_operation_unsafety(&name[..]); let (n_tps, inputs, output) = match &name[..] { "breakpoint" => (0, Vec::new(), tcx.mk_unit()), - "size_of" | "pref_align_of" | "min_align_of" => (1, Vec::new(), tcx.types.usize), + "size_of" | "pref_align_of" | "min_align_of" | "variant_count" => { + (1, Vec::new(), tcx.types.usize) + } "size_of_val" | "min_align_of_val" => { (1, vec![tcx.mk_imm_ptr(param(0))], tcx.types.usize) } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 259c4a8664f1b..7bdf137f116c8 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -295,8 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { opt_input_types: Option<&[Ty<'tcx>]>, ) -> Option>> { debug!( - "lookup_in_trait_adjusted(self_ty={:?}, \ - m_name={}, trait_def_id={:?})", + "lookup_in_trait_adjusted(self_ty={:?}, m_name={}, trait_def_id={:?})", self_ty, m_name, trait_def_id ); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index a3e34815d3182..8842ca877268a 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -380,8 +380,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.sess, span, E0699, - "the type of this value must be known \ - to call a method on a raw pointer on it" + "the type of this value must be known to call a method on a raw pointer on \ + it" ) .emit(); } else { diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 56804792b1944..94a5685a992fe 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -8,8 +8,11 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; +use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; -use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{ + self, suggest_constraining_type_param, Ty, TyCtxt, TypeFoldable, TypeVisitor, +}; use rustc_span::symbol::Ident; use rustc_span::Span; use rustc_trait_selection::infer::InferCtxtExt; @@ -249,254 +252,229 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { method.sig.output() } + // error types are considered "builtin" + Err(()) if lhs_ty.references_error() || rhs_ty.references_error() => { + self.tcx.ty_error() + } Err(()) => { - // error types are considered "builtin" - if !lhs_ty.references_error() && !rhs_ty.references_error() { - let source_map = self.tcx.sess.source_map(); - - match is_assign { - IsAssign::Yes => { - let mut err = struct_span_err!( - self.tcx.sess, - expr.span, - E0368, - "binary assignment operation `{}=` cannot be applied to type `{}`", - op.node.as_str(), + let source_map = self.tcx.sess.source_map(); + let (mut err, missing_trait, use_output, involves_fn) = match is_assign { + IsAssign::Yes => { + let mut err = struct_span_err!( + self.tcx.sess, + expr.span, + E0368, + "binary assignment operation `{}=` cannot be applied to type `{}`", + op.node.as_str(), + lhs_ty, + ); + err.span_label( + lhs_expr.span, + format!("cannot use `{}=` on type `{}`", op.node.as_str(), lhs_ty), + ); + let missing_trait = match op.node { + hir::BinOpKind::Add => Some("std::ops::AddAssign"), + hir::BinOpKind::Sub => Some("std::ops::SubAssign"), + hir::BinOpKind::Mul => Some("std::ops::MulAssign"), + hir::BinOpKind::Div => Some("std::ops::DivAssign"), + hir::BinOpKind::Rem => Some("std::ops::RemAssign"), + hir::BinOpKind::BitAnd => Some("std::ops::BitAndAssign"), + hir::BinOpKind::BitXor => Some("std::ops::BitXorAssign"), + hir::BinOpKind::BitOr => Some("std::ops::BitOrAssign"), + hir::BinOpKind::Shl => Some("std::ops::ShlAssign"), + hir::BinOpKind::Shr => Some("std::ops::ShrAssign"), + _ => None, + }; + (err, missing_trait, false, false) + } + IsAssign::No => { + let (message, missing_trait, use_output) = match op.node { + hir::BinOpKind::Add => ( + format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty), + Some("std::ops::Add"), + true, + ), + hir::BinOpKind::Sub => ( + format!("cannot subtract `{}` from `{}`", rhs_ty, lhs_ty), + Some("std::ops::Sub"), + true, + ), + hir::BinOpKind::Mul => ( + format!("cannot multiply `{}` to `{}`", rhs_ty, lhs_ty), + Some("std::ops::Mul"), + true, + ), + hir::BinOpKind::Div => ( + format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty), + Some("std::ops::Div"), + true, + ), + hir::BinOpKind::Rem => ( + format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty), + Some("std::ops::Rem"), + true, + ), + hir::BinOpKind::BitAnd => ( + format!("no implementation for `{} & {}`", lhs_ty, rhs_ty), + Some("std::ops::BitAnd"), + true, + ), + hir::BinOpKind::BitXor => ( + format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty), + Some("std::ops::BitXor"), + true, + ), + hir::BinOpKind::BitOr => ( + format!("no implementation for `{} | {}`", lhs_ty, rhs_ty), + Some("std::ops::BitOr"), + true, + ), + hir::BinOpKind::Shl => ( + format!("no implementation for `{} << {}`", lhs_ty, rhs_ty), + Some("std::ops::Shl"), + true, + ), + hir::BinOpKind::Shr => ( + format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty), + Some("std::ops::Shr"), + true, + ), + hir::BinOpKind::Eq | hir::BinOpKind::Ne => ( + format!( + "binary operation `{}` cannot be applied to type `{}`", + op.node.as_str(), + lhs_ty + ), + Some("std::cmp::PartialEq"), + false, + ), + hir::BinOpKind::Lt + | hir::BinOpKind::Le + | hir::BinOpKind::Gt + | hir::BinOpKind::Ge => ( + format!( + "binary operation `{}` cannot be applied to type `{}`", + op.node.as_str(), + lhs_ty + ), + Some("std::cmp::PartialOrd"), + false, + ), + _ => ( + format!( + "binary operation `{}` cannot be applied to type `{}`", + op.node.as_str(), + lhs_ty + ), + None, + false, + ), + }; + let mut err = + struct_span_err!(self.tcx.sess, op.span, E0369, "{}", message.as_str()); + let mut involves_fn = false; + if !lhs_expr.span.eq(&rhs_expr.span) { + involves_fn |= self.add_type_neq_err_label( + &mut err, + lhs_expr.span, lhs_ty, + rhs_ty, + op, + is_assign, ); - err.span_label( - lhs_expr.span, - format!("cannot use `{}=` on type `{}`", op.node.as_str(), lhs_ty), + involves_fn |= self.add_type_neq_err_label( + &mut err, + rhs_expr.span, + rhs_ty, + lhs_ty, + op, + is_assign, ); - let mut suggested_deref = false; - if let Ref(_, rty, _) = lhs_ty.kind { - if { - self.infcx.type_is_copy_modulo_regions( - self.param_env, - rty, - lhs_expr.span, - ) && self - .lookup_op_method(rty, &[rhs_ty], Op::Binary(op, is_assign)) - .is_ok() - } { - if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) { - let msg = &format!( - "`{}=` can be used on '{}', you can dereference `{}`", - op.node.as_str(), - rty.peel_refs(), - lstring, - ); - err.span_suggestion( - lhs_expr.span, - msg, - format!("*{}", lstring), - rustc_errors::Applicability::MachineApplicable, - ); - suggested_deref = true; - } - } - } - let missing_trait = match op.node { - hir::BinOpKind::Add => Some("std::ops::AddAssign"), - hir::BinOpKind::Sub => Some("std::ops::SubAssign"), - hir::BinOpKind::Mul => Some("std::ops::MulAssign"), - hir::BinOpKind::Div => Some("std::ops::DivAssign"), - hir::BinOpKind::Rem => Some("std::ops::RemAssign"), - hir::BinOpKind::BitAnd => Some("std::ops::BitAndAssign"), - hir::BinOpKind::BitXor => Some("std::ops::BitXorAssign"), - hir::BinOpKind::BitOr => Some("std::ops::BitOrAssign"), - hir::BinOpKind::Shl => Some("std::ops::ShlAssign"), - hir::BinOpKind::Shr => Some("std::ops::ShrAssign"), - _ => None, - }; - if let Some(missing_trait) = missing_trait { - if op.node == hir::BinOpKind::Add - && self.check_str_addition( - lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, true, op, - ) - { - // This has nothing here because it means we did string - // concatenation (e.g., "Hello " += "World!"). This means - // we don't want the note in the else clause to be emitted - } else if let ty::Param(p) = lhs_ty.kind { - suggest_constraining_param( - self.tcx, - self.body_id, - &mut err, - lhs_ty, - rhs_ty, - missing_trait, - p, - false, - ); - } else if !suggested_deref { - suggest_impl_missing(&mut err, lhs_ty, &missing_trait); - } - } - err.emit(); } - IsAssign::No => { - let (message, missing_trait, use_output) = match op.node { - hir::BinOpKind::Add => ( - format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty), - Some("std::ops::Add"), - true, - ), - hir::BinOpKind::Sub => ( - format!("cannot subtract `{}` from `{}`", rhs_ty, lhs_ty), - Some("std::ops::Sub"), - true, - ), - hir::BinOpKind::Mul => ( - format!("cannot multiply `{}` to `{}`", rhs_ty, lhs_ty), - Some("std::ops::Mul"), - true, - ), - hir::BinOpKind::Div => ( - format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty), - Some("std::ops::Div"), - true, - ), - hir::BinOpKind::Rem => ( - format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty), - Some("std::ops::Rem"), - true, - ), - hir::BinOpKind::BitAnd => ( - format!("no implementation for `{} & {}`", lhs_ty, rhs_ty), - Some("std::ops::BitAnd"), - true, - ), - hir::BinOpKind::BitXor => ( - format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty), - Some("std::ops::BitXor"), - true, - ), - hir::BinOpKind::BitOr => ( - format!("no implementation for `{} | {}`", lhs_ty, rhs_ty), - Some("std::ops::BitOr"), - true, - ), - hir::BinOpKind::Shl => ( - format!("no implementation for `{} << {}`", lhs_ty, rhs_ty), - Some("std::ops::Shl"), - true, - ), - hir::BinOpKind::Shr => ( - format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty), - Some("std::ops::Shr"), - true, - ), - hir::BinOpKind::Eq | hir::BinOpKind::Ne => ( - format!( - "binary operation `{}` cannot be applied to type `{}`", - op.node.as_str(), - lhs_ty - ), - Some("std::cmp::PartialEq"), - false, - ), - hir::BinOpKind::Lt - | hir::BinOpKind::Le - | hir::BinOpKind::Gt - | hir::BinOpKind::Ge => ( - format!( - "binary operation `{}` cannot be applied to type `{}`", - op.node.as_str(), - lhs_ty - ), - Some("std::cmp::PartialOrd"), - false, - ), - _ => ( - format!( - "binary operation `{}` cannot be applied to type `{}`", - op.node.as_str(), - lhs_ty - ), - None, - false, - ), - }; - let mut err = struct_span_err!( - self.tcx.sess, - op.span, - E0369, - "{}", - message.as_str() + (err, missing_trait, use_output, involves_fn) + } + }; + let mut suggested_deref = false; + if let Ref(_, rty, _) = lhs_ty.kind { + if { + self.infcx.type_is_copy_modulo_regions(self.param_env, rty, lhs_expr.span) + && self + .lookup_op_method(rty, &[rhs_ty], Op::Binary(op, is_assign)) + .is_ok() + } { + if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) { + let msg = &format!( + "`{}{}` can be used on `{}`, you can dereference `{}`", + op.node.as_str(), + match is_assign { + IsAssign::Yes => "=", + IsAssign::No => "", + }, + rty.peel_refs(), + lstring, ); - - let mut involves_fn = false; - if !lhs_expr.span.eq(&rhs_expr.span) { - involves_fn |= self.add_type_neq_err_label( - &mut err, - lhs_expr.span, - lhs_ty, - rhs_ty, - op, - is_assign, - ); - involves_fn |= self.add_type_neq_err_label( + err.span_suggestion_verbose( + lhs_expr.span.shrink_to_lo(), + msg, + "*".to_string(), + rustc_errors::Applicability::MachineApplicable, + ); + suggested_deref = true; + } + } + } + if let Some(missing_trait) = missing_trait { + let mut visitor = TypeParamVisitor(vec![]); + visitor.visit_ty(lhs_ty); + + if op.node == hir::BinOpKind::Add + && self.check_str_addition( + lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, is_assign, op, + ) + { + // This has nothing here because it means we did string + // concatenation (e.g., "Hello " + "World!"). This means + // we don't want the note in the else clause to be emitted + } else if let [ty] = &visitor.0[..] { + if let ty::Param(p) = ty.kind { + // Check if the method would be found if the type param wasn't + // involved. If so, it means that adding a trait bound to the param is + // enough. Otherwise we do not give the suggestion. + let mut eraser = TypeParamEraser(&self, expr.span); + let needs_bound = self + .lookup_op_method( + eraser.fold_ty(lhs_ty), + &[eraser.fold_ty(rhs_ty)], + Op::Binary(op, is_assign), + ) + .is_ok(); + if needs_bound { + suggest_constraining_param( + self.tcx, + self.body_id, &mut err, - rhs_expr.span, + ty, rhs_ty, - lhs_ty, - op, - is_assign, + missing_trait, + p, + use_output, ); + } else if *ty != lhs_ty { + // When we know that a missing bound is responsible, we don't show + // this note as it is redundant. + err.note(&format!( + "the trait `{}` is not implemented for `{}`", + missing_trait, lhs_ty + )); } - - let mut suggested_deref = false; - if let Ref(_, rty, _) = lhs_ty.kind { - if { - self.infcx.type_is_copy_modulo_regions( - self.param_env, - rty, - lhs_expr.span, - ) && self - .lookup_op_method(rty, &[rhs_ty], Op::Binary(op, is_assign)) - .is_ok() - } { - if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) { - err.help(&format!( - "`{}` can be used on '{}', you can \ - dereference `{2}`: `*{2}`", - op.node.as_str(), - rty.peel_refs(), - lstring - )); - suggested_deref = true; - } - } - } - if let Some(missing_trait) = missing_trait { - if op.node == hir::BinOpKind::Add - && self.check_str_addition( - lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, false, op, - ) - { - // This has nothing here because it means we did string - // concatenation (e.g., "Hello " + "World!"). This means - // we don't want the note in the else clause to be emitted - } else if let ty::Param(p) = lhs_ty.kind { - suggest_constraining_param( - self.tcx, - self.body_id, - &mut err, - lhs_ty, - rhs_ty, - missing_trait, - p, - use_output, - ); - } else if !suggested_deref && !involves_fn { - suggest_impl_missing(&mut err, lhs_ty, &missing_trait); - } - } - err.emit(); + } else { + bug!("type param visitor stored a non type param: {:?}", ty.kind); } + } else if !suggested_deref && !involves_fn { + suggest_impl_missing(&mut err, lhs_ty, &missing_trait); } } + err.emit(); self.tcx.ty_error() } }; @@ -570,7 +548,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>, err: &mut rustc_errors::DiagnosticBuilder<'_>, - is_assign: bool, + is_assign: IsAssign, op: hir::BinOp, ) -> bool { let source_map = self.tcx.sess.source_map(); @@ -593,7 +571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &format!("{:?}", rhs_ty) == "&&str" ) => { - if !is_assign { // Do not supply this message if `&str += &str` + if let IsAssign::No = is_assign { // Do not supply this message if `&str += &str` err.span_label( op.span, "`+` cannot be used to concatenate two `&str` strings", @@ -634,7 +612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { source_map.span_to_snippet(rhs_expr.span), is_assign, ) { - (Ok(l), Ok(r), false) => { + (Ok(l), Ok(r), IsAssign::No) => { let to_string = if l.starts_with('&') { // let a = String::new(); let b = String::new(); // let _ = &a + b; @@ -686,11 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); err.span_label( ex.span, - format!( - "cannot apply unary \ - operator `{}`", - op.as_str() - ), + format!("cannot apply unary operator `{}`", op.as_str()), ); match actual.kind { Uint(_) if op == hir::UnOp::UnNeg => { @@ -928,8 +902,7 @@ fn suggest_impl_missing(err: &mut DiagnosticBuilder<'_>, ty: Ty<'_>, missing_tra if let Adt(def, _) = ty.peel_refs().kind { if def.did.is_local() { err.note(&format!( - "an implementation of `{}` might \ - be missing for `{}`", + "an implementation of `{}` might be missing for `{}`", missing_trait, ty )); } @@ -975,3 +948,32 @@ fn suggest_constraining_param( err.span_label(span, msg); } } + +struct TypeParamVisitor<'tcx>(Vec>); + +impl<'tcx> TypeVisitor<'tcx> for TypeParamVisitor<'tcx> { + fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool { + if let ty::Param(_) = ty.kind { + self.0.push(ty); + } + ty.super_visit_with(self) + } +} + +struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span); + +impl TypeFolder<'tcx> for TypeParamEraser<'_, 'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.0.tcx + } + + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { + match ty.kind { + ty::Param(_) => self.0.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::MiscVariable, + span: self.1, + }), + _ => ty.super_fold_with(self), + } + } +} diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 08e04f719e9ba..78628b198a3c3 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -278,7 +278,7 @@ fn build_type_alias_type(cx: &DocContext<'_>, did: DefId) -> Option type_.def_id().and_then(|did| build_ty(cx, did)) } -pub fn build_ty(cx: &DocContext, did: DefId) -> Option { +pub fn build_ty(cx: &DocContext<'_>, did: DefId) -> Option { match cx.tcx.def_kind(did) { DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Const | DefKind::Static => { Some(cx.tcx.type_of(did).clean(cx)) diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index c4e4802db6c07..832b2420c2389 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -328,7 +328,7 @@ pub fn strip_path(path: &Path) -> Path { Path { global: path.global, res: path.res, segments } } -pub fn qpath_to_string(p: &hir::QPath) -> String { +pub fn qpath_to_string(p: &hir::QPath<'_>) -> String { let segments = match *p { hir::QPath::Resolved(_, ref path) => &path.segments, hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(), @@ -417,7 +417,7 @@ impl ToSource for rustc_span::Span { } } -pub fn name_from_pat(p: &hir::Pat) -> String { +pub fn name_from_pat(p: &hir::Pat<'_>) -> String { use rustc_hir::*; debug!("trying to get a name from pattern: {:?}", p); @@ -481,8 +481,8 @@ pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { _ => { let mut s = n.to_string(); // array lengths are obviously usize - if s.ends_with("usize") { - let n = s.len() - "usize".len(); + if s.ends_with("_usize") { + let n = s.len() - "_usize".len(); s.truncate(n); if s.ends_with(": ") { let n = s.len() - ": ".len(); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 5dbcc5c9ec8b9..35b15cf717cee 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -123,10 +123,6 @@ pub struct Options { /// /// Be aware: This option can come both from the CLI and from crate attributes! pub default_passes: DefaultPassOption, - /// Document items that have lower than `pub` visibility. - pub document_private: bool, - /// Document items that have `doc(hidden)`. - pub document_hidden: bool, /// Any passes manually selected by the user. /// /// Be aware: This option can come both from the CLI and from crate attributes! @@ -177,8 +173,6 @@ impl fmt::Debug for Options { .field("test_args", &self.test_args) .field("persist_doctests", &self.persist_doctests) .field("default_passes", &self.default_passes) - .field("document_private", &self.document_private) - .field("document_hidden", &self.document_hidden) .field("manual_passes", &self.manual_passes) .field("display_warnings", &self.display_warnings) .field("show_coverage", &self.show_coverage) @@ -250,6 +244,10 @@ pub struct RenderOptions { pub generate_search_filter: bool, /// Option (disabled by default) to generate files used by RLS and some other tools. pub generate_redirect_pages: bool, + /// Document items that have lower than `pub` visibility. + pub document_private: bool, + /// Document items that have `doc(hidden)`. + pub document_hidden: bool, } impl Options { @@ -567,8 +565,6 @@ impl Options { should_test, test_args, default_passes, - document_private, - document_hidden, manual_passes, display_warnings, show_coverage, @@ -597,6 +593,8 @@ impl Options { markdown_playground_url, generate_search_filter, generate_redirect_pages, + document_private, + document_hidden, }, output_format, }) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 1690b946bb625..8ab6c74289d17 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -62,6 +62,8 @@ pub struct DocContext<'tcx> { // FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set. pub generated_synthetics: RefCell, DefId)>>, pub auto_traits: Vec, + /// The options given to rustdoc that could be relevant to a pass. + pub render_options: RenderOptions, } impl<'tcx> DocContext<'tcx> { @@ -281,8 +283,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt describe_lints, lint_cap, mut default_passes, - mut document_private, - document_hidden, mut manual_passes, display_warnings, render_options, @@ -448,6 +448,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt .cloned() .filter(|trait_def_id| tcx.trait_is_auto(*trait_def_id)) .collect(), + render_options, }; debug!("crate: {:?}", tcx.hir().krate()); @@ -524,7 +525,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt } if attr.is_word() && name == sym::document_private_items { - document_private = true; + ctxt.render_options.document_private = true; } } @@ -544,9 +545,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt for p in passes { let run = match p.condition { Always => true, - WhenDocumentPrivate => document_private, - WhenNotDocumentPrivate => !document_private, - WhenNotDocumentHidden => !document_hidden, + WhenDocumentPrivate => ctxt.render_options.document_private, + WhenNotDocumentPrivate => !ctxt.render_options.document_private, + WhenNotDocumentHidden => !ctxt.render_options.document_hidden, }; if run { debug!("running pass {}", p.pass.name); @@ -556,7 +557,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt ctxt.sess().abort_if_errors(); - (krate, ctxt.renderinfo.into_inner(), render_options) + (krate, ctxt.renderinfo.into_inner(), ctxt.render_options) }) }) }) diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 5b13832742770..943729a74ab2d 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -262,7 +262,7 @@ pub struct ProcMacro<'hir> { pub whence: Span, } -pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType { +pub fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType { match *vdata { hir::VariantData::Struct(..) => Plain, hir::VariantData::Tuple(..) => Tuple, diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index e60ff37fd279a..a453a8b3dcb2a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -468,7 +468,7 @@ impl clean::Path { pub fn href(did: DefId) -> Option<(String, ItemType, Vec)> { let cache = cache(); - if !did.is_local() && !cache.access_levels.is_public(did) { + if !did.is_local() && !cache.access_levels.is_public(did) && !cache.document_private { return None; } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1681b73d0c257..04c4685213b2e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -469,6 +469,7 @@ pub fn run( static_root_path, generate_search_filter, generate_redirect_pages, + document_private, .. } = options; @@ -546,7 +547,7 @@ pub fn run( scx.ensure_dir(&dst)?; krate = sources::render(&dst, &mut scx, krate)?; let (new_crate, index, cache) = - Cache::from_krate(renderinfo, &extern_html_root_urls, &dst, krate); + Cache::from_krate(renderinfo, document_private, &extern_html_root_urls, &dst, krate); krate = new_crate; let cache = Arc::new(cache); let mut cx = Context { diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 225940773413e..1b5c8a9378e41 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -91,6 +91,10 @@ crate struct Cache { /// The version of the crate being documented, if given from the `--crate-version` flag. pub crate_version: Option, + /// Whether to document private items. + /// This is stored in `Cache` so it doesn't need to be passed through all rustdoc functions. + pub document_private: bool, + // Private fields only used when initially crawling a crate to build a cache stack: Vec, parent_stack: Vec, @@ -126,6 +130,7 @@ crate struct Cache { impl Cache { pub fn from_krate( renderinfo: RenderInfo, + document_private: bool, extern_html_root_urls: &BTreeMap, dst: &Path, mut krate: clean::Crate, @@ -160,6 +165,7 @@ impl Cache { stripped_mod: false, access_levels, crate_version: krate.version.take(), + document_private, orphan_impl_items: Vec::new(), orphan_trait_impls: Vec::new(), traits: krate.external_traits.replace(Default::default()), diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 59bb206678f51..62a23298c1b9f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1408,6 +1408,7 @@ function defocusSearchBar() { addClass(actives[currentTab][0].previousElementSibling, "highlighted"); removeClass(actives[currentTab][0], "highlighted"); + e.preventDefault(); } else if (e.which === 40) { // down if (!actives[currentTab].length) { var results = document.getElementById("results").childNodes; @@ -1421,6 +1422,7 @@ function defocusSearchBar() { addClass(actives[currentTab][0].nextElementSibling, "highlighted"); removeClass(actives[currentTab][0], "highlighted"); } + e.preventDefault(); } else if (e.which === 13) { // return if (actives[currentTab].length) { document.location.href = diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index f5b2f1bb5b178..8da74f375d9ce 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -178,6 +178,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { let result = cx.enter_resolver(|resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id) }); + debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns); let result = match result { Ok((_, Res::Err)) => Err(ErrorKind::ResolutionFailure), _ => result.map_err(|_| ErrorKind::ResolutionFailure), @@ -202,7 +203,13 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { } return Ok((res, Some(path_str.to_owned()))); } - _ => return Ok((res, extra_fragment.clone())), + other => { + debug!( + "failed to resolve {} in namespace {:?} (got {:?})", + path_str, ns, other + ); + return Ok((res, extra_fragment.clone())); + } }; if value != (ns == ValueNS) { @@ -555,12 +562,13 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { } else { (parts[0].to_owned(), None) }; + let resolved_self; + let mut path_str; let (res, fragment) = { let mut kind = None; - let mut path_str = if let Some(prefix) = - ["struct@", "enum@", "type@", "trait@", "union@"] - .iter() - .find(|p| link.starts_with(**p)) + path_str = if let Some(prefix) = ["struct@", "enum@", "type@", "trait@", "union@"] + .iter() + .find(|p| link.starts_with(**p)) { kind = Some(TypeNS); link.trim_start_matches(prefix) @@ -614,7 +622,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { let base_node = if item.is_mod() && item.attrs.inner_docs { None } else { parent_node }; - let resolved_self; // replace `Self` with suitable item's parent name if path_str.starts_with("Self::") { if let Some(ref name) = parent_name { @@ -760,6 +767,32 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { if let Res::PrimTy(_) = res { item.attrs.links.push((ori_link, None, fragment)); } else { + debug!("intra-doc link to {} resolved to {:?}", path_str, res); + if let Some(local) = res.opt_def_id().and_then(|def_id| def_id.as_local()) { + use rustc_hir::def_id::LOCAL_CRATE; + + let hir_id = self.cx.tcx.hir().as_local_hir_id(local); + if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id) + && !self.cx.render_options.document_private + { + let item_name = item.name.as_deref().unwrap_or(""); + let err_msg = format!( + "public documentation for `{}` links to a private item", + item_name + ); + build_diagnostic( + cx, + &item, + path_str, + &dox, + link_range, + &err_msg, + "this item is private", + None, + ); + continue; + } + } let id = register_res(cx, res); item.attrs.links.push((ori_link, Some(id), fragment)); } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 21aa0ded5a4b2..e9504aa3af123 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -166,7 +166,7 @@ pub fn run(options: Options) -> Result<(), String> { } // Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade. -fn scrape_test_config(krate: &::rustc_hir::Crate) -> TestOptions { +fn scrape_test_config(krate: &::rustc_hir::Crate<'_>) -> TestOptions { use rustc_ast_pretty::pprust; let mut opts = @@ -973,7 +973,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> intravisit::NestedVisitorMap::All(self.map) } - fn visit_item(&mut self, item: &'hir hir::Item) { + fn visit_item(&mut self, item: &'hir hir::Item<'_>) { let name = if let hir::ItemKind::Impl { ref self_ty, .. } = item.kind { rustc_hir_pretty::id_to_string(&self.map, self_ty.hir_id) } else { @@ -985,19 +985,19 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> }); } - fn visit_trait_item(&mut self, item: &'hir hir::TraitItem) { + fn visit_trait_item(&mut self, item: &'hir hir::TraitItem<'_>) { self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { intravisit::walk_trait_item(this, item); }); } - fn visit_impl_item(&mut self, item: &'hir hir::ImplItem) { + fn visit_impl_item(&mut self, item: &'hir hir::ImplItem<'_>) { self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { intravisit::walk_impl_item(this, item); }); } - fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem) { + fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) { self.visit_testable(item.ident.to_string(), &item.attrs, item.hir_id, item.span, |this| { intravisit::walk_foreign_item(this, item); }); @@ -1005,8 +1005,8 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> fn visit_variant( &mut self, - v: &'hir hir::Variant, - g: &'hir hir::Generics, + v: &'hir hir::Variant<'_>, + g: &'hir hir::Generics<'_>, item_id: hir::HirId, ) { self.visit_testable(v.ident.to_string(), &v.attrs, v.id, v.span, |this| { @@ -1014,13 +1014,13 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> }); } - fn visit_struct_field(&mut self, f: &'hir hir::StructField) { + fn visit_struct_field(&mut self, f: &'hir hir::StructField<'_>) { self.visit_testable(f.ident.to_string(), &f.attrs, f.hir_id, f.span, |this| { intravisit::walk_struct_field(this, f); }); } - fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef<'_>) { self.visit_testable( macro_def.ident.to_string(), ¯o_def.attrs, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d2a950027cf87..c18f417e4f8e1 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -62,7 +62,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { self.exact_paths.entry(did).or_insert_with(|| def_id_to_path(tcx, did)); } - pub fn visit(mut self, krate: &'tcx hir::Crate) -> Module<'tcx> { + pub fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> { let mut module = self.visit_mod_contents( krate.item.span, krate.item.attrs, @@ -84,10 +84,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_variant_data( &mut self, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'_>, name: Symbol, - sd: &'tcx hir::VariantData, - generics: &'tcx hir::Generics, + sd: &'tcx hir::VariantData<'_>, + generics: &'tcx hir::Generics<'_>, ) -> Struct<'tcx> { debug!("visiting struct"); let struct_type = struct_type_from_def(&*sd); @@ -105,10 +105,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_union_data( &mut self, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'_>, name: Symbol, - sd: &'tcx hir::VariantData, - generics: &'tcx hir::Generics, + sd: &'tcx hir::VariantData<'_>, + generics: &'tcx hir::Generics<'_>, ) -> Union<'tcx> { debug!("visiting union"); let struct_type = struct_type_from_def(&*sd); @@ -126,10 +126,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_enum_def( &mut self, - it: &'tcx hir::Item, + it: &'tcx hir::Item<'_>, name: Symbol, - def: &'tcx hir::EnumDef, - generics: &'tcx hir::Generics, + def: &'tcx hir::EnumDef<'_>, + generics: &'tcx hir::Generics<'_>, ) -> Enum<'tcx> { debug!("visiting enum"); Enum { @@ -156,11 +156,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_fn( &mut self, om: &mut Module<'tcx>, - item: &'tcx hir::Item, + item: &'tcx hir::Item<'_>, name: Symbol, - decl: &'tcx hir::FnDecl, + decl: &'tcx hir::FnDecl<'_>, header: hir::FnHeader, - generics: &'tcx hir::Generics, + generics: &'tcx hir::Generics<'_>, body: hir::BodyId, ) { debug!("visiting fn"); @@ -231,7 +231,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { &mut self, span: Span, attrs: &'tcx [ast::Attribute], - vis: &'tcx hir::Visibility, + vis: &'tcx hir::Visibility<'_>, id: hir::HirId, m: &'tcx hir::Mod<'tcx>, name: Option, @@ -375,7 +375,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { ret } - fn visit_item(&mut self, item: &'tcx hir::Item, renamed: Option, om: &mut Module<'tcx>) { + fn visit_item( + &mut self, + item: &'tcx hir::Item<'_>, + renamed: Option, + om: &mut Module<'tcx>, + ) { debug!("visiting item {:?}", item); let ident = renamed.unwrap_or(item.ident); @@ -587,7 +592,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_foreign_item( &mut self, - item: &'tcx hir::ForeignItem, + item: &'tcx hir::ForeignItem<'_>, renamed: Option, om: &mut Module<'tcx>, ) { @@ -607,7 +612,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } // Convert each `exported_macro` into a doc item. - fn visit_local_macro(&self, def: &'tcx hir::MacroDef, renamed: Option) -> Macro<'tcx> { + fn visit_local_macro( + &self, + def: &'tcx hir::MacroDef<'_>, + renamed: Option, + ) -> Macro<'tcx> { debug!("visit_local_macro: {}", def.ident); let tts = def.ast.body.inner_tokens().trees().collect::>(); // Extract the spans of all matchers. They represent the "interface" of the macro. diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index a4996d9eee810..d972cf6db18cf 100644 --- a/src/libstd/keyword_docs.rs +++ b/src/libstd/keyword_docs.rs @@ -913,10 +913,28 @@ mod match_keyword {} // /// Organize code into [modules]. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// Use `mod` to create new [modules] to encapsulate code, including other +/// modules: +/// +/// ``` +/// mod foo { +/// mod bar { +/// type MyType = (u8, u8); +/// fn baz() {} +/// } +/// } +/// ``` +/// +/// Like [`struct`]s and [`enum`]s, a module and its content are private by +/// default, unaccessible to code outside of the module. +/// +/// To learn more about allowing access, see the documentation for the [`pub`] +/// keyword. /// +/// [`enum`]: keyword.enum.html +/// [`pub`]: keyword.pub.html +/// [`struct`]: keyword.struct.html /// [modules]: ../reference/items/modules.html -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 mod mod_keyword {} #[doc(keyword = "move")] @@ -965,11 +983,61 @@ mod move_keyword {} #[doc(keyword = "mut")] // -/// A mutable binding, reference, or pointer. +/// A mutable variable, reference, or pointer. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// `mut` can be used in several situations. The first is mutable variables, +/// which can be used anywhere you can bind a value to a variable name. Some +/// examples: /// -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// ```rust +/// // A mutable variable in the parameter list of a function. +/// fn foo(mut x: u8, y: u8) -> u8 { +/// x += y; +/// x +/// } +/// +/// // Modifying a mutable variable. +/// # #[allow(unused_assignments)] +/// let mut a = 5; +/// a = 6; +/// +/// assert_eq!(foo(3, 4), 7); +/// assert_eq!(a, 6); +/// ``` +/// +/// The second is mutable references. They can be created from `mut` variables +/// and must be unique: no other variables can have a mutable reference, nor a +/// shared reference. +/// +/// ```rust +/// // Taking a mutable reference. +/// fn push_two(v: &mut Vec) { +/// v.push(2); +/// } +/// +/// // A mutable reference cannot be taken to a non-mutable variable. +/// let mut v = vec![0, 1]; +/// // Passing a mutable reference. +/// push_two(&mut v); +/// +/// assert_eq!(v, vec![0, 1, 2]); +/// ``` +/// +/// ```rust,compile_fail,E0502 +/// let mut v = vec![0, 1]; +/// let mut_ref_v = &mut v; +/// ##[allow(unused)] +/// let ref_v = &v; +/// mut_ref_v.push(2); +/// ``` +/// +/// Mutable raw pointers work much like mutable references, with the added +/// possibility of not pointing to a valid object. The syntax is `*mut Type`. +/// +/// More information on mutable references and pointers can be found in``` +/// [Reference]. +/// +/// [Reference]: ../reference/types/pointer.html#mutable-references-mut mod mut_keyword {} #[doc(keyword = "pub")] @@ -1000,18 +1068,148 @@ mod ref_keyword {} // /// Return a value from a function. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// A `return` marks the end of an execution path in a function: /// -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// ``` +/// fn foo() -> i32 { +/// return 3; +/// } +/// assert_eq!(foo(), 3); +/// ``` +/// +/// `return` is not needed when the returned value is the last expression in the +/// function. In this case the `;` is omitted: +/// +/// ``` +/// fn foo() -> i32 { +/// 3 +/// } +/// assert_eq!(foo(), 3); +/// ``` +/// +/// `return` returns from the function immediately (an "early return"): +/// +/// ```no_run +/// use std::fs::File; +/// use std::io::{Error, ErrorKind, Read, Result}; +/// +/// fn main() -> Result<()> { +/// let mut file = match File::open("foo.txt") { +/// Ok(f) => f, +/// Err(e) => return Err(e), +/// }; +/// +/// let mut contents = String::new(); +/// let size = match file.read_to_string(&mut contents) { +/// Ok(s) => s, +/// Err(e) => return Err(e), +/// }; +/// +/// if contents.contains("impossible!") { +/// return Err(Error::new(ErrorKind::Other, "oh no!")); +/// } +/// +/// if size > 9000 { +/// return Err(Error::new(ErrorKind::Other, "over 9000!")); +/// } +/// +/// assert_eq!(contents, "Hello, world!"); +/// Ok(()) +/// } +/// ``` mod return_keyword {} #[doc(keyword = "self")] // /// The receiver of a method, or the current module. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// `self` is used in two situations: referencing the current module and marking +/// the receiver of a method. /// -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// In paths, `self` can be used to refer to the current module, either in a +/// [`use`] statement or in a path to access an element: +/// +/// ``` +/// # #![allow(unused_imports)] +/// use std::io::{self, Read}; +/// ``` +/// +/// Is functionally the same as: +/// +/// ``` +/// # #![allow(unused_imports)] +/// use std::io; +/// use std::io::Read; +/// ``` +/// +/// Using `self` to access an element in the current module: +/// +/// ``` +/// # #![allow(dead_code)] +/// # fn main() {} +/// fn foo() {} +/// fn bar() { +/// self::foo() +/// } +/// ``` +/// +/// `self` as the current receiver for a method allows to omit the parameter +/// type most of the time. With the exception of this particularity, `self` is +/// used much like any other parameter: +/// +/// ``` +/// struct Foo(i32); +/// +/// impl Foo { +/// // No `self`. +/// fn new() -> Self { +/// Self(0) +/// } +/// +/// // Consuming `self`. +/// fn consume(self) -> Self { +/// Self(self.0 + 1) +/// } +/// +/// // Borrowing `self`. +/// fn borrow(&self) -> &i32 { +/// &self.0 +/// } +/// +/// // Borrowing `self` mutably. +/// fn borrow_mut(&mut self) -> &mut i32 { +/// &mut self.0 +/// } +/// } +/// +/// // This method must be called with a `Type::` prefix. +/// let foo = Foo::new(); +/// assert_eq!(foo.0, 0); +/// +/// // Those two calls produces the same result. +/// let foo = Foo::consume(foo); +/// assert_eq!(foo.0, 1); +/// let foo = foo.consume(); +/// assert_eq!(foo.0, 2); +/// +/// // Borrowing is handled automatically with the second syntax. +/// let borrow_1 = Foo::borrow(&foo); +/// let borrow_2 = foo.borrow(); +/// assert_eq!(borrow_1, borrow_2); +/// +/// // Borrowing mutably is handled automatically too with the second syntax. +/// let mut foo = Foo::new(); +/// *Foo::borrow_mut(&mut foo) += 1; +/// assert_eq!(foo.0, 1); +/// *foo.borrow_mut() += 1; +/// assert_eq!(foo.0, 2); +/// ``` +/// +/// Note that this automatic conversion when calling `foo.method()` is not +/// limited to the examples above. See the [Reference] for more information. +/// +/// [`use`]: keyword.use.html +/// [Reference]: ../reference/items/associated-items.html#methods mod self_keyword {} #[doc(keyword = "Self")] @@ -1019,11 +1217,66 @@ mod self_keyword {} /// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type /// definition. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// Within a type definition: +/// +/// ``` +/// # #![allow(dead_code)] +/// struct Node { +/// elem: i32, +/// // `Self` is a `Node` here. +/// next: Option>, +/// } +/// ``` +/// +/// In an [`impl`] block: +/// +/// ``` +/// struct Foo(i32); +/// +/// impl Foo { +/// fn new() -> Self { +/// Self(0) +/// } +/// } +/// +/// assert_eq!(Foo::new().0, Foo(0).0); +/// ``` +/// +/// Generic parameters are implicit with `Self`: +/// +/// ``` +/// # #![allow(dead_code)] +/// struct Wrap { +/// elem: T, +/// } +/// +/// impl Wrap { +/// fn new(elem: T) -> Self { +/// Self { elem } +/// } +/// } +/// ``` +/// +/// In a [`trait`] definition and related [`impl`] block: +/// +/// ``` +/// trait Example { +/// fn example() -> Self; +/// } +/// +/// struct Foo(i32); +/// +/// impl Example for Foo { +/// fn example() -> Self { +/// Self(42) +/// } +/// } +/// +/// assert_eq!(Foo::example().0, Foo(42).0); +/// ``` /// /// [`impl`]: keyword.impl.html /// [`trait`]: keyword.trait.html -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 mod self_upper_keyword {} #[doc(keyword = "static")] @@ -1147,10 +1400,26 @@ mod struct_keyword {} // /// The parent of the current [module]. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// ```rust +/// # #![allow(dead_code)] +/// # fn main() {} +/// mod a { +/// pub fn foo() {} +/// } +/// mod b { +/// pub fn foo() { +/// super::a::foo(); // call a's foo function +/// } +/// } +/// ``` +/// +/// It is also possible to use `super` multiple times: `super::super::foo`, +/// going up the ancestor chain. +/// +/// See the [Reference] for more information. /// /// [module]: ../reference/items/modules.html -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// [Reference]: ../reference/paths.html#super mod super_keyword {} #[doc(keyword = "trait")] diff --git a/src/libstd/os/illumos/fs.rs b/src/libstd/os/illumos/fs.rs index 2abbf1fa9fa16..b668aa2595d67 100644 --- a/src/libstd/os/illumos/fs.rs +++ b/src/libstd/os/illumos/fs.rs @@ -1,7 +1,5 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] -use libc; - use crate::fs::Metadata; use crate::sys_common::AsInner; diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index d22ac1d538584..97d62d958ca4f 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -170,7 +170,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. - let backtrace_env = if update_panic_count(0) >= 2 { + let backtrace_env = if panic_count::get() >= 2 { RustBacktrace::Print(backtrace_rs::PrintFmt::Full) } else { backtrace::rust_backtrace_env() @@ -221,19 +221,65 @@ fn default_hook(info: &PanicInfo<'_>) { #[cfg(not(test))] #[doc(hidden)] #[unstable(feature = "update_panic_count", issue = "none")] -pub fn update_panic_count(amt: isize) -> usize { +pub mod panic_count { use crate::cell::Cell; - thread_local! { static PANIC_COUNT: Cell = Cell::new(0) } + use crate::sync::atomic::{AtomicUsize, Ordering}; + + // Panic count for the current thread. + thread_local! { static LOCAL_PANIC_COUNT: Cell = Cell::new(0) } + + // Sum of panic counts from all threads. The purpose of this is to have + // a fast path in `is_zero` (which is used by `panicking`). Access to + // this variable can be always be done with relaxed ordering because + // it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero, + // `LOCAL_PANIC_COUNT` will be zero. + static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0); + + pub fn increase() -> usize { + GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); + LOCAL_PANIC_COUNT.with(|c| { + let next = c.get() + 1; + c.set(next); + next + }) + } + + pub fn decrease() -> usize { + GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); + LOCAL_PANIC_COUNT.with(|c| { + let next = c.get() - 1; + c.set(next); + next + }) + } - PANIC_COUNT.with(|c| { - let next = (c.get() as isize + amt) as usize; - c.set(next); - next - }) + pub fn get() -> usize { + LOCAL_PANIC_COUNT.with(|c| c.get()) + } + + #[inline] + pub fn is_zero() -> bool { + if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) == 0 { + // Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads + // (including the current one) will have `LOCAL_PANIC_COUNT` + // equal to zero, so TLS access can be avoided. + true + } else { + is_zero_slow_path() + } + } + + // Slow path is in a separate function to reduce the amount of code + // inlined from `is_zero`. + #[inline(never)] + #[cold] + fn is_zero_slow_path() -> bool { + LOCAL_PANIC_COUNT.with(|c| c.get() == 0) + } } #[cfg(test)] -pub use realstd::rt::update_panic_count; +pub use realstd::rt::panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. pub unsafe fn r#try R>(f: F) -> Result> { @@ -283,7 +329,7 @@ pub unsafe fn r#try R>(f: F) -> Result> #[cold] unsafe fn cleanup(payload: *mut u8) -> Box { let obj = Box::from_raw(__rust_panic_cleanup(payload)); - update_panic_count(-1); + panic_count::decrease(); obj } @@ -312,8 +358,9 @@ pub unsafe fn r#try R>(f: F) -> Result> } /// Determines whether the current thread is unwinding because of panic. +#[inline] pub fn panicking() -> bool { - update_panic_count(0) != 0 + !panic_count::is_zero() } /// The entry point for panicking with a formatted message. @@ -445,7 +492,7 @@ fn rust_panic_with_hook( message: Option<&fmt::Arguments<'_>>, location: &Location<'_>, ) -> ! { - let panics = update_panic_count(1); + let panics = panic_count::increase(); // If this is the third nested call (e.g., panics == 2, this is 0-indexed), // the panic hook probably triggered the last panic, otherwise the @@ -495,7 +542,7 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. pub fn rust_panic_without_hook(payload: Box) -> ! { - update_panic_count(1); + panic_count::increase(); struct RewrapBox(Box); diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 2426b2dead712..fb825ab16ebd7 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -15,7 +15,7 @@ #![doc(hidden)] // Re-export some of our utilities which are expected by other crates. -pub use crate::panicking::{begin_panic, begin_panic_fmt, update_panic_count}; +pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count}; // To reduce the generated code of the new `lang_start`, this function is doing // the real work. diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index fc6ce5770338e..f61bcf06f0815 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -11,7 +11,7 @@ IMAGE_BASE: .long 1 /* type = NT_VERSION */ 0: .asciz "toolchain-version" /* name */ 1: .align 4 -2: .long 0 /* desc - toolchain version number, 32-bit LE */ +2: .long 1 /* desc - toolchain version number, 32-bit LE */ 3: .align 4 .section .rodata @@ -60,10 +60,14 @@ IMAGE_BASE: globvar TEXT_BASE 8 /* The size in bytes of enclacve text section */ globvar TEXT_SIZE 8 - /* The base address (relative to enclave start) of the enclave EH_FRM_HDR section */ - globvar EH_FRM_HDR_BASE 8 - /* The size in bytes of enclacve EH_FRM_HDR section */ - globvar EH_FRM_HDR_SIZE 8 + /* The base address (relative to enclave start) of the enclave .eh_frame_hdr section */ + globvar EH_FRM_HDR_OFFSET 8 + /* The size in bytes of enclave .eh_frame_hdr section */ + globvar EH_FRM_HDR_LEN 8 + /* The base address (relative to enclave start) of the enclave .eh_frame section */ + globvar EH_FRM_OFFSET 8 + /* The size in bytes of enclacve .eh_frame section */ + globvar EH_FRM_LEN 8 .org .Lxsave_clear+512 .Lxsave_header: diff --git a/src/libstd/sys/sgx/abi/mod.rs b/src/libstd/sys/sgx/abi/mod.rs index 87e7a5da2b7a9..5ef26d4cc4dc6 100644 --- a/src/libstd/sys/sgx/abi/mod.rs +++ b/src/libstd/sys/sgx/abi/mod.rs @@ -56,6 +56,7 @@ unsafe extern "C" fn tcs_init(secondary: bool) { // able to specify this #[cfg(not(test))] #[no_mangle] +#[allow(improper_ctypes_definitions)] extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64) -> (u64, u64) { // FIXME: how to support TLS in library mode? let tls = Box::new(tls::Tls::new()); diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index cd24605ec7ab7..ada8eaa1c9745 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -2,9 +2,6 @@ //! Unix-specific networking functionality -#[cfg(unix)] -use libc; - // FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here? #[cfg(not(unix))] #[allow(non_camel_case_types)] diff --git a/src/libstd/sys/vxworks/args.rs b/src/libstd/sys/vxworks/args.rs index efd615f404db6..adff6c489bbc9 100644 --- a/src/libstd/sys/vxworks/args.rs +++ b/src/libstd/sys/vxworks/args.rs @@ -56,7 +56,6 @@ mod imp { use crate::ffi::{CStr, OsString}; use crate::marker::PhantomData; use crate::ptr; - use libc; use crate::sys_common::mutex::Mutex; diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index 9864a855df738..7cc64658ee1a9 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -6,7 +6,6 @@ use crate::path::Path; use crate::sys; use crate::sys::platform::fs::MetadataExt as UnixMetadataExt; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; -use libc; /// Unix-specific extensions to [`File`]. /// diff --git a/src/libstd/sys/vxworks/rand.rs b/src/libstd/sys/vxworks/rand.rs index 87ebd2c9593fc..3a1ff5fd3b9c6 100644 --- a/src/libstd/sys/vxworks/rand.rs +++ b/src/libstd/sys/vxworks/rand.rs @@ -13,7 +13,6 @@ pub fn hashmap_random_keys() -> (u64, u64) { mod imp { use crate::io; use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; - use libc; pub fn fill_bytes(v: &mut [u8]) { static RNG_INIT: AtomicBool = AtomicBool::new(false); diff --git a/src/libstd/sys/vxworks/rwlock.rs b/src/libstd/sys/vxworks/rwlock.rs index fd2e1a6e7bcfb..c90304c2b4a6a 100644 --- a/src/libstd/sys/vxworks/rwlock.rs +++ b/src/libstd/sys/vxworks/rwlock.rs @@ -1,6 +1,5 @@ use crate::cell::UnsafeCell; use crate::sync::atomic::{AtomicUsize, Ordering}; -use libc; pub struct RWLock { inner: UnsafeCell, diff --git a/src/libstd/sys/vxworks/time.rs b/src/libstd/sys/vxworks/time.rs index 8ebbf89213f32..8365c9ee9c995 100644 --- a/src/libstd/sys/vxworks/time.rs +++ b/src/libstd/sys/vxworks/time.rs @@ -1,7 +1,6 @@ use crate::cmp::Ordering; use crate::time::Duration; use ::core::hash::{Hash, Hasher}; -use libc; pub use self::inner::{Instant, SystemTime, UNIX_EPOCH}; use crate::convert::TryInto; @@ -104,7 +103,6 @@ mod inner { use crate::fmt; use crate::sys::cvt; use crate::time::Duration; - use libc; use super::Timespec; diff --git a/src/libstd/sys/wasi/alloc.rs b/src/libstd/sys/wasi/alloc.rs index bc61416278401..57187851a14e3 100644 --- a/src/libstd/sys/wasi/alloc.rs +++ b/src/libstd/sys/wasi/alloc.rs @@ -1,7 +1,6 @@ use crate::alloc::{GlobalAlloc, Layout, System}; use crate::ptr; use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN}; -use libc; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index f6f16f686e557..31d235cf679db 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -9,6 +9,8 @@ fn main() { { // Build the unwinding from libunwind C/C++ source code. llvm_libunwind::compile(); + } else if target.contains("x86_64-fortanix-unknown-sgx") { + llvm_libunwind::compile(); } else if target.contains("linux") { if target.contains("musl") { // linking for musl is handled in lib.rs @@ -55,6 +57,7 @@ mod llvm_libunwind { /// Compile the libunwind C/C++ source code. pub fn compile() { + let target = env::var("TARGET").expect("TARGET was not set"); let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap(); let target_endian_little = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap() != "big"; @@ -75,6 +78,35 @@ mod llvm_libunwind { cfg.flag("/EHsc"); cfg.define("_CRT_SECURE_NO_WARNINGS", None); cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); + } else if target.contains("x86_64-fortanix-unknown-sgx") { + cfg.cpp(false); + + cfg.static_flag(true); + cfg.opt_level(3); + + cfg.flag("-nostdinc++"); + cfg.flag("-fno-exceptions"); + cfg.flag("-fno-rtti"); + cfg.flag("-fstrict-aliasing"); + cfg.flag("-funwind-tables"); + cfg.flag("-fvisibility=hidden"); + cfg.flag("-fno-stack-protector"); + cfg.flag("-ffreestanding"); + cfg.flag("-fexceptions"); + + // easiest way to undefine since no API available in cc::Build to undefine + cfg.flag("-U_FORTIFY_SOURCE"); + cfg.define("_FORTIFY_SOURCE", "0"); + + cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); + + cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); + cfg.define("RUST_SGX", "1"); + cfg.define("__NO_STRING_INLINES", None); + cfg.define("__NO_MATH_INLINES", None); + cfg.define("_LIBUNWIND_IS_BAREMETAL", None); + cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); + cfg.define("NDEBUG", None); } else { cfg.flag("-std=c99"); cfg.flag("-std=c++11"); @@ -103,6 +135,10 @@ mod llvm_libunwind { unwind_sources.push("Unwind_AppleExtras.cpp"); } + if target.contains("x86_64-fortanix-unknown-sgx") { + unwind_sources.push("UnwindRustSgx.c"); + } + let root = Path::new("../llvm-project/libunwind"); cfg.include(root.join("include")); for src in unwind_sources { diff --git a/src/test/codegen/async-fn-debug-msvc.rs b/src/test/codegen/async-fn-debug-msvc.rs new file mode 100644 index 0000000000000..4e145b81ecbf7 --- /dev/null +++ b/src/test/codegen/async-fn-debug-msvc.rs @@ -0,0 +1,48 @@ +// Verify debuginfo for generators: +// - Each variant points to the file and line of its yield point +// - The generator types and variants are marked artificial +// - Captured vars from the source are not marked artificial +// +// ignore-tidy-linelength +// compile-flags: -C debuginfo=2 --edition=2018 +// only-msvc + +async fn foo() {} +async fn async_fn_test() { + foo().await; + let s = String::from("foo"); + foo().await; +} + +// FIXME: No way to reliably check the filename. + +// CHECK-DAG: [[ASYNC_FN:!.*]] = !DINamespace(name: "async_fn_test" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[ASYNC_FN]], {{.*}}flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// For brevity, we only check the struct name and members of the last variant. +// CHECK-SAME: file: [[FILE:![0-9]*]], line: 11, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 12, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 14, +// CHECK-SAME: baseType: [[VARIANT:![0-9]*]] +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[ASYNC_FN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "RUST$ENUM$DISR", scope: [[S1]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) + +fn main() { + let _dummy = async_fn_test(); +} diff --git a/src/test/codegen/async-fn-debug.rs b/src/test/codegen/async-fn-debug.rs new file mode 100644 index 0000000000000..8fa4be1ae86d8 --- /dev/null +++ b/src/test/codegen/async-fn-debug.rs @@ -0,0 +1,51 @@ +// Verify debuginfo for async fn: +// - Each variant points to the file and line of its yield point +// - The generator types and variants are marked artificial +// - Captured vars from the source are not marked artificial +// +// ignore-tidy-linelength +// compile-flags: -C debuginfo=2 --edition=2018 +// ignore-msvc + +async fn foo() {} +async fn async_fn_test() { + foo().await; + let s = String::from("foo"); + foo().await; +} + +// FIXME: No way to reliably check the filename. + +// CHECK-DAG: [[ASYNC_FN:!.*]] = !DINamespace(name: "async_fn_test" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[ASYNC_FN]], {{.*}}flags: DIFlagArtificial +// CHECK: [[VARIANT:!.*]] = !DICompositeType(tag: DW_TAG_variant_part, scope: [[ASYNC_FN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK-SAME: discriminator: [[DISC:![0-9]*]] +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE:![0-9]*]], line: 11, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 12, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 14, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) +// CHECK: [[DISC]] = !DIDerivedType(tag: DW_TAG_member, name: "__state", scope: [[ASYNC_FN]], +// CHECK-SAME: flags: DIFlagArtificial + +fn main() { + let _dummy = async_fn_test(); +} diff --git a/src/test/codegen/debug-linkage-name.rs b/src/test/codegen/debug-linkage-name.rs new file mode 100644 index 0000000000000..0d7dca3aba344 --- /dev/null +++ b/src/test/codegen/debug-linkage-name.rs @@ -0,0 +1,42 @@ +// Verifies that linkage name is omitted when it is +// the same as variable / function name. +// +// compile-flags: -C no-prepopulate-passes +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +pub mod xyz { + // CHECK: !DIGlobalVariable(name: "A", + // CHECK: linkageName: + // CHECK-SAME: line: 12, + pub static A: u32 = 1; + + // CHECK: !DIGlobalVariable(name: "B", + // CHECK-NOT: linkageName: + // CHECK-SAME: line: 18, + #[no_mangle] + pub static B: u32 = 2; + + // CHECK: !DIGlobalVariable(name: "C", + // CHECK-NOT: linkageName: + // CHECK-SAME: line: 24, + #[export_name = "C"] + pub static C: u32 = 2; + + // CHECK: !DISubprogram(name: "e", + // CHECK: linkageName: + // CHECK-SAME: line: 29, + pub extern fn e() {} + + // CHECK: !DISubprogram(name: "f", + // CHECK-NOT: linkageName: + // CHECK-SAME: line: 35, + #[no_mangle] + pub extern fn f() {} + + // CHECK: !DISubprogram(name: "g", + // CHECK-NOT: linkageName: + // CHECK-SAME: line: 41, + #[export_name = "g"] + pub extern fn g() {} +} diff --git a/src/test/codegen/generator-debug-msvc.rs b/src/test/codegen/generator-debug-msvc.rs new file mode 100644 index 0000000000000..82a1568ea9584 --- /dev/null +++ b/src/test/codegen/generator-debug-msvc.rs @@ -0,0 +1,52 @@ +// Verify debuginfo for generators: +// - Each variant points to the file and line of its yield point +// - The generator types and variants are marked artificial +// - Captured vars from the source are not marked artificial +// +// ignore-tidy-linelength +// compile-flags: -C debuginfo=2 +// only-msvc + +#![feature(generators, generator_trait)] +use std::ops::Generator; + +fn generator_test() -> impl Generator { + || { + yield 0; + let s = String::from("foo"); + yield 1; + } +} + +// FIXME: No way to reliably check the filename. + +// CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "generator_test" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "generator-0", scope: [[GEN_FN]], {{.*}}flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// For brevity, we only check the struct name and members of the last variant. +// CHECK-SAME: file: [[FILE:![0-9]*]], line: 14, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 18, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 18, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, scope: [[GEN]], +// CHECK-SAME: file: [[FILE]], line: 17, +// CHECK-SAME: baseType: [[VARIANT:![0-9]*]] +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN_FN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "RUST$ENUM$DISR", scope: [[S1]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) + +fn main() { + let _dummy = generator_test(); +} diff --git a/src/test/codegen/generator-debug.rs b/src/test/codegen/generator-debug.rs new file mode 100644 index 0000000000000..5c7c64148189a --- /dev/null +++ b/src/test/codegen/generator-debug.rs @@ -0,0 +1,55 @@ +// Verify debuginfo for generators: +// - Each variant points to the file and line of its yield point +// - The generator types and variants are marked artificial +// - Captured vars from the source are not marked artificial +// +// ignore-tidy-linelength +// compile-flags: -C debuginfo=2 --edition=2018 +// ignore-msvc + +#![feature(generators, generator_trait)] +use std::ops::Generator; + +fn generator_test() -> impl Generator { + || { + yield 0; + let s = String::from("foo"); + yield 1; + } +} + +// FIXME: No way to reliably check the filename. + +// CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "generator_test" +// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "generator-0", scope: [[GEN_FN]], {{.*}}flags: DIFlagArtificial +// CHECK: [[VARIANT:!.*]] = !DICompositeType(tag: DW_TAG_variant_part, scope: [[GEN_FN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK-SAME: discriminator: [[DISC:![0-9]*]] +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE:![0-9]*]], line: 14, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 18, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 18, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 15, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]], +// CHECK-SAME: file: [[FILE]], line: 17, +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]], +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: [[S1]] +// CHECK-NOT: flags: DIFlagArtificial +// CHECK-SAME: ) +// CHECK: [[DISC]] = !DIDerivedType(tag: DW_TAG_member, name: "__state", scope: [[GEN_FN]], +// CHECK-SAME: flags: DIFlagArtificial + +fn main() { + let _dummy = generator_test(); +} diff --git a/src/test/mir-opt/address-of/rustc.address_of_reborrow.SimplifyCfg-initial.after.mir b/src/test/mir-opt/address-of/rustc.address_of_reborrow.SimplifyCfg-initial.after.mir index aeb38f3f91068..07793b3598f9e 100644 --- a/src/test/mir-opt/address-of/rustc.address_of_reborrow.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/address-of/rustc.address_of_reborrow.SimplifyCfg-initial.after.mir @@ -128,7 +128,7 @@ fn address_of_reborrow() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/address-of.rs:4:9: 4:10 StorageLive(_2); // scope 0 at $DIR/address-of.rs:4:14: 4:21 - _2 = [const 0i32; 10]; // scope 0 at $DIR/address-of.rs:4:14: 4:21 + _2 = [const 0_i32; 10]; // scope 0 at $DIR/address-of.rs:4:14: 4:21 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -139,7 +139,7 @@ fn address_of_reborrow() -> () { FakeRead(ForLet, _1); // scope 0 at $DIR/address-of.rs:4:9: 4:10 StorageLive(_3); // scope 1 at $DIR/address-of.rs:5:9: 5:14 StorageLive(_4); // scope 1 at $DIR/address-of.rs:5:22: 5:29 - _4 = [const 0i32; 10]; // scope 1 at $DIR/address-of.rs:5:22: 5:29 + _4 = [const 0_i32; 10]; // scope 1 at $DIR/address-of.rs:5:22: 5:29 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir index d39b9b8a3b444..2a3a18d6c5b5d 100644 --- a/src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -25,7 +25,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14 - _1 = [const 42u32, const 43u32, const 44u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29 + _1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) @@ -45,7 +45,7 @@ fn main() -> () { // + span: $DIR/array-index-is-temporary.rs:13:26: 13:28 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002c)) } StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14 - _2 = const 1usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18 + _2 = const 1_usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir index 381c1ca6f22ef..093c170cf7a3a 100644 --- a/src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -25,7 +25,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14 - _1 = [const 42u32, const 43u32, const 44u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29 + _1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) @@ -45,7 +45,7 @@ fn main() -> () { // + span: $DIR/array-index-is-temporary.rs:13:26: 13:28 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002c)) } StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14 - _2 = const 1usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18 + _2 = const 1_usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) diff --git a/src/test/mir-opt/byte_slice/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/byte_slice/rustc.main.SimplifyCfg-elaborate-drops.after.mir index 88cb09ac15a9c..54e01dceb5099 100644 --- a/src/test/mir-opt/byte_slice/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/byte_slice/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -21,7 +21,7 @@ fn main() -> () { // + span: $DIR/byte_slice.rs:5:13: 5:19 // + literal: Const { ty: &[u8; 3], val: Value(Scalar(alloc0)) } StorageLive(_2); // scope 1 at $DIR/byte_slice.rs:6:9: 6:10 - _2 = [const 5u8, const 120u8]; // scope 1 at $DIR/byte_slice.rs:6:13: 6:24 + _2 = [const 5_u8, const 120_u8]; // scope 1 at $DIR/byte_slice.rs:6:13: 6:24 // ty::Const // + ty: u8 // + val: Value(Scalar(0x05)) diff --git a/src/test/mir-opt/combine_array_len/32bit/rustc.norm2.InstCombine.diff b/src/test/mir-opt/combine_array_len/32bit/rustc.norm2.InstCombine.diff index e11619cf0cd0e..65db967fe5f81 100644 --- a/src/test/mir-opt/combine_array_len/32bit/rustc.norm2.InstCombine.diff +++ b/src/test/mir-opt/combine_array_len/32bit/rustc.norm2.InstCombine.diff @@ -28,7 +28,7 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/combine_array_len.rs:5:9: 5:10 StorageLive(_3); // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 - _3 = const 0usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 + _3 = const 0_usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) @@ -36,7 +36,7 @@ // + span: $DIR/combine_array_len.rs:5:15: 5:16 // + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) } - _4 = Len(_1); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 -+ _4 = const 2usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 ++ _4 = const 2_usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000002)) @@ -52,7 +52,7 @@ StorageDead(_3); // scope 0 at $DIR/combine_array_len.rs:5:17: 5:18 StorageLive(_6); // scope 1 at $DIR/combine_array_len.rs:6:9: 6:10 StorageLive(_7); // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 - _7 = const 1usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 + _7 = const 1_usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -60,7 +60,7 @@ // + span: $DIR/combine_array_len.rs:6:15: 6:16 // + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) } - _8 = Len(_1); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 -+ _8 = const 2usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 ++ _8 = const 2_usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/combine_array_len/64bit/rustc.norm2.InstCombine.diff b/src/test/mir-opt/combine_array_len/64bit/rustc.norm2.InstCombine.diff index 050cfe359a175..712c4eb230c7e 100644 --- a/src/test/mir-opt/combine_array_len/64bit/rustc.norm2.InstCombine.diff +++ b/src/test/mir-opt/combine_array_len/64bit/rustc.norm2.InstCombine.diff @@ -28,7 +28,7 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/combine_array_len.rs:5:9: 5:10 StorageLive(_3); // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 - _3 = const 0usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 + _3 = const 0_usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) @@ -36,7 +36,7 @@ // + span: $DIR/combine_array_len.rs:5:15: 5:16 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) } - _4 = Len(_1); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 -+ _4 = const 2usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 ++ _4 = const 2_usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000002)) @@ -52,7 +52,7 @@ StorageDead(_3); // scope 0 at $DIR/combine_array_len.rs:5:17: 5:18 StorageLive(_6); // scope 1 at $DIR/combine_array_len.rs:6:9: 6:10 StorageLive(_7); // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 - _7 = const 1usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 + _7 = const 1_usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -60,7 +60,7 @@ // + span: $DIR/combine_array_len.rs:6:15: 6:16 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) } - _8 = Len(_1); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 -+ _8 = const 2usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 ++ _8 = const 2_usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000002)) diff --git a/src/test/mir-opt/const_prop/aggregate/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/aggregate/rustc.main.ConstProp.diff index f4b6c7db444e5..e84e88b93fcd8 100644 --- a/src/test/mir-opt/const_prop/aggregate/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/aggregate/rustc.main.ConstProp.diff @@ -14,7 +14,7 @@ StorageLive(_1); // scope 0 at $DIR/aggregate.rs:5:9: 5:10 StorageLive(_2); // scope 0 at $DIR/aggregate.rs:5:13: 5:24 StorageLive(_3); // scope 0 at $DIR/aggregate.rs:5:13: 5:22 - _3 = (const 0i32, const 1i32, const 2i32); // scope 0 at $DIR/aggregate.rs:5:13: 5:22 + _3 = (const 0_i32, const 1_i32, const 2_i32); // scope 0 at $DIR/aggregate.rs:5:13: 5:22 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -34,8 +34,8 @@ // + span: $DIR/aggregate.rs:5:20: 5:21 // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } - _2 = (_3.1: i32); // scope 0 at $DIR/aggregate.rs:5:13: 5:24 -- _1 = Add(move _2, const 0i32); // scope 0 at $DIR/aggregate.rs:5:13: 5:28 -+ _2 = const 1i32; // scope 0 at $DIR/aggregate.rs:5:13: 5:24 +- _1 = Add(move _2, const 0_i32); // scope 0 at $DIR/aggregate.rs:5:13: 5:28 ++ _2 = const 1_i32; // scope 0 at $DIR/aggregate.rs:5:13: 5:24 // ty::Const // + ty: i32 - // + val: Value(Scalar(0x00000000)) @@ -45,7 +45,7 @@ - // + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) } + // + span: $DIR/aggregate.rs:5:13: 5:24 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } -+ _1 = const 1i32; // scope 0 at $DIR/aggregate.rs:5:13: 5:28 ++ _1 = const 1_i32; // scope 0 at $DIR/aggregate.rs:5:13: 5:28 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/const_prop/array_index/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/array_index/32bit/rustc.main.ConstProp.diff index d02906132e296..48908479935d1 100644 --- a/src/test/mir-opt/const_prop/array_index/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/array_index/32bit/rustc.main.ConstProp.diff @@ -15,7 +15,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/array_index.rs:5:9: 5:10 StorageLive(_2); // scope 0 at $DIR/array_index.rs:5:18: 5:30 - _2 = [const 0u32, const 1u32, const 2u32, const 3u32]; // scope 0 at $DIR/array_index.rs:5:18: 5:30 + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; // scope 0 at $DIR/array_index.rs:5:18: 5:30 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -41,14 +41,14 @@ // + span: $DIR/array_index.rs:5:28: 5:29 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_3); // scope 0 at $DIR/array_index.rs:5:31: 5:32 - _3 = const 2usize; // scope 0 at $DIR/array_index.rs:5:31: 5:32 + _3 = const 2_usize; // scope 0 at $DIR/array_index.rs:5:31: 5:32 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000002)) // mir::Constant // + span: $DIR/array_index.rs:5:31: 5:32 // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) } - _4 = const 4usize; // scope 0 at $DIR/array_index.rs:5:18: 5:33 + _4 = const 4_usize; // scope 0 at $DIR/array_index.rs:5:18: 5:33 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000004)) @@ -75,7 +75,7 @@ bb1: { - _1 = _2[_3]; // scope 0 at $DIR/array_index.rs:5:18: 5:33 -+ _1 = const 2u32; // scope 0 at $DIR/array_index.rs:5:18: 5:33 ++ _1 = const 2_u32; // scope 0 at $DIR/array_index.rs:5:18: 5:33 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/const_prop/array_index/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/array_index/64bit/rustc.main.ConstProp.diff index 4fe3f08955894..fd662698a0fd4 100644 --- a/src/test/mir-opt/const_prop/array_index/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/array_index/64bit/rustc.main.ConstProp.diff @@ -15,7 +15,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/array_index.rs:5:9: 5:10 StorageLive(_2); // scope 0 at $DIR/array_index.rs:5:18: 5:30 - _2 = [const 0u32, const 1u32, const 2u32, const 3u32]; // scope 0 at $DIR/array_index.rs:5:18: 5:30 + _2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; // scope 0 at $DIR/array_index.rs:5:18: 5:30 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -41,14 +41,14 @@ // + span: $DIR/array_index.rs:5:28: 5:29 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_3); // scope 0 at $DIR/array_index.rs:5:31: 5:32 - _3 = const 2usize; // scope 0 at $DIR/array_index.rs:5:31: 5:32 + _3 = const 2_usize; // scope 0 at $DIR/array_index.rs:5:31: 5:32 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000002)) // mir::Constant // + span: $DIR/array_index.rs:5:31: 5:32 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) } - _4 = const 4usize; // scope 0 at $DIR/array_index.rs:5:18: 5:33 + _4 = const 4_usize; // scope 0 at $DIR/array_index.rs:5:18: 5:33 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000004)) @@ -75,7 +75,7 @@ bb1: { - _1 = _2[_3]; // scope 0 at $DIR/array_index.rs:5:18: 5:33 -+ _1 = const 2u32; // scope 0 at $DIR/array_index.rs:5:18: 5:33 ++ _1 = const 2_u32; // scope 0 at $DIR/array_index.rs:5:18: 5:33 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/const_prop/bad_op_div_by_zero/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_div_by_zero/rustc.main.ConstProp.diff index de06e5334e040..ed28678edb30d 100644 --- a/src/test/mir-opt/const_prop/bad_op_div_by_zero/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_div_by_zero/rustc.main.ConstProp.diff @@ -19,7 +19,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/bad_op_div_by_zero.rs:4:9: 4:10 - _1 = const 0i32; // scope 0 at $DIR/bad_op_div_by_zero.rs:4:13: 4:14 + _1 = const 0_i32; // scope 0 at $DIR/bad_op_div_by_zero.rs:4:13: 4:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -29,8 +29,8 @@ StorageLive(_2); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:9: 5:11 StorageLive(_3); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:18: 5:19 - _3 = _1; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:18: 5:19 -- _4 = Eq(_3, const 0i32); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 -+ _3 = const 0i32; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:18: 5:19 +- _4 = Eq(_3, const 0_i32); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 ++ _3 = const 0_i32; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:18: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -45,11 +45,17 @@ + // mir::Constant + // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x01)) } - assert(!move _4, "attempt to divide by zero") -> bb1; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + assert(!move _4, "attempt to divide {} by zero", const 1_i32) -> bb1; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:15 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } } bb1: { -- _5 = Eq(_3, const -1i32); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 +- _5 = Eq(_3, const -1_i32); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + _5 = const false; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 // ty::Const - // + ty: i32 @@ -59,7 +65,7 @@ // mir::Constant // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:19 - // + literal: Const { ty: i32, val: Value(Scalar(0xffffffff)) } -- _6 = Eq(const 1i32, const i32::MIN); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 +- _6 = Eq(const 1_i32, const i32::MIN); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + _6 = const false; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 // ty::Const @@ -82,19 +88,25 @@ // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:19 - // + literal: Const { ty: i32, val: Value(Scalar(0x80000000)) } - _7 = BitAnd(move _5, move _6); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 -- assert(!move _7, "attempt to divide with overflow") -> bb2; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 +- assert(!move _7, "attempt to compute `{} / {}` which would overflow", const 1_i32, _3) -> bb2; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to divide with overflow") -> bb2; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 ++ assert(!const false, "attempt to compute `{} / {}` which would overflow", const 1_i32, _3) -> bb2; // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/bad_op_div_by_zero.rs:5:14: 5:15 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } } bb2: { - _2 = Div(const 1i32, move _3); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 + _2 = Div(const 1_i32, move _3); // scope 1 at $DIR/bad_op_div_by_zero.rs:5:14: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/const_prop/bad_op_mod_by_zero/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_mod_by_zero/rustc.main.ConstProp.diff index 7052c8387041b..8855df95aeab5 100644 --- a/src/test/mir-opt/const_prop/bad_op_mod_by_zero/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_mod_by_zero/rustc.main.ConstProp.diff @@ -19,7 +19,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/bad_op_mod_by_zero.rs:4:9: 4:10 - _1 = const 0i32; // scope 0 at $DIR/bad_op_mod_by_zero.rs:4:13: 4:14 + _1 = const 0_i32; // scope 0 at $DIR/bad_op_mod_by_zero.rs:4:13: 4:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -29,8 +29,8 @@ StorageLive(_2); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:9: 5:11 StorageLive(_3); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:18: 5:19 - _3 = _1; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:18: 5:19 -- _4 = Eq(_3, const 0i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 -+ _3 = const 0i32; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:18: 5:19 +- _4 = Eq(_3, const 0_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 ++ _3 = const 0_i32; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:18: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -45,11 +45,17 @@ + // mir::Constant + // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x01)) } - assert(!move _4, "attempt to calculate the remainder with a divisor of zero") -> bb1; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + assert(!move _4, "attempt to calculate the remainder of {} with a divisor of zero", const 1_i32) -> bb1; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:15 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } } bb1: { -- _5 = Eq(_3, const -1i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 +- _5 = Eq(_3, const -1_i32); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + _5 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 // ty::Const - // + ty: i32 @@ -59,7 +65,7 @@ // mir::Constant // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 - // + literal: Const { ty: i32, val: Value(Scalar(0xffffffff)) } -- _6 = Eq(const 1i32, const i32::MIN); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 +- _6 = Eq(const 1_i32, const i32::MIN); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + _6 = const false; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 // ty::Const @@ -82,19 +88,25 @@ // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 - // + literal: Const { ty: i32, val: Value(Scalar(0x80000000)) } - _7 = BitAnd(move _5, move _6); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 -- assert(!move _7, "attempt to calculate the remainder with overflow") -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 +- assert(!move _7, "attempt to compute the remainder of `{} % {}` which would overflow", const 1_i32, _3) -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to calculate the remainder with overflow") -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 ++ assert(!const false, "attempt to compute the remainder of `{} % {}` which would overflow", const 1_i32, _3) -> bb2; // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/bad_op_mod_by_zero.rs:5:14: 5:15 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } } bb2: { - _2 = Rem(const 1i32, move _3); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 + _2 = Rem(const 1_i32, move _3); // scope 1 at $DIR/bad_op_mod_by_zero.rs:5:14: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff index 7ceec94d81e76..ee4d4c39f172c 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff @@ -39,7 +39,7 @@ StorageDead(_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:35: 5:36 StorageLive(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:13: 7:15 StorageLive(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 - _6 = const 3usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 + _6 = const 3_usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000003)) diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff index 483a6f232ef79..3626814fa9770 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff @@ -39,7 +39,7 @@ StorageDead(_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:35: 5:36 StorageLive(_5); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:13: 7:15 StorageLive(_6); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 - _6 = const 3usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 + _6 = const 3_usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000003)) diff --git a/src/test/mir-opt/const_prop/boxes/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/boxes/rustc.main.ConstProp.diff index 16f937f3e7b5e..f271188ebfdb0 100644 --- a/src/test/mir-opt/const_prop/boxes/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/boxes/rustc.main.ConstProp.diff @@ -17,7 +17,7 @@ StorageLive(_3); // scope 0 at $DIR/boxes.rs:12:14: 12:22 StorageLive(_4); // scope 0 at $DIR/boxes.rs:12:14: 12:22 _4 = Box(i32); // scope 0 at $DIR/boxes.rs:12:14: 12:22 - (*_4) = const 42i32; // scope 0 at $DIR/boxes.rs:12:19: 12:21 + (*_4) = const 42_i32; // scope 0 at $DIR/boxes.rs:12:19: 12:21 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -27,7 +27,7 @@ _3 = move _4; // scope 0 at $DIR/boxes.rs:12:14: 12:22 StorageDead(_4); // scope 0 at $DIR/boxes.rs:12:21: 12:22 _2 = (*_3); // scope 0 at $DIR/boxes.rs:12:13: 12:22 - _1 = Add(move _2, const 0i32); // scope 0 at $DIR/boxes.rs:12:13: 12:26 + _1 = Add(move _2, const 0_i32); // scope 0 at $DIR/boxes.rs:12:13: 12:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/const_prop/cast/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/cast/rustc.main.ConstProp.diff index 58c27c5a20f8c..54af804d19b00 100644 --- a/src/test/mir-opt/const_prop/cast/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/cast/rustc.main.ConstProp.diff @@ -14,8 +14,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/cast.rs:4:9: 4:10 -- _1 = const 42u8 as u32 (Misc); // scope 0 at $DIR/cast.rs:4:13: 4:24 -+ _1 = const 42u32; // scope 0 at $DIR/cast.rs:4:13: 4:24 +- _1 = const 42_u8 as u32 (Misc); // scope 0 at $DIR/cast.rs:4:13: 4:24 ++ _1 = const 42_u32; // scope 0 at $DIR/cast.rs:4:13: 4:24 // ty::Const - // + ty: u8 - // + val: Value(Scalar(0x2a)) @@ -23,7 +23,7 @@ - // + span: $DIR/cast.rs:4:13: 4:17 - // + literal: Const { ty: u8, val: Value(Scalar(0x2a)) } - StorageLive(_2); // scope 1 at $DIR/cast.rs:6:9: 6:10 -- _2 = const 42u32 as u8 (Misc); // scope 1 at $DIR/cast.rs:6:13: 6:24 +- _2 = const 42_u32 as u8 (Misc); // scope 1 at $DIR/cast.rs:6:13: 6:24 - // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) @@ -32,7 +32,7 @@ + // + span: $DIR/cast.rs:4:13: 4:24 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } + StorageLive(_2); // scope 1 at $DIR/cast.rs:6:9: 6:10 -+ _2 = const 42u8; // scope 1 at $DIR/cast.rs:6:13: 6:24 ++ _2 = const 42_u8; // scope 1 at $DIR/cast.rs:6:13: 6:24 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x2a)) diff --git a/src/test/mir-opt/const_prop/checked_add/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/checked_add/rustc.main.ConstProp.diff index f9f7d543d21f5..e3690d7129497 100644 --- a/src/test/mir-opt/const_prop/checked_add/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/checked_add/rustc.main.ConstProp.diff @@ -11,8 +11,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/checked_add.rs:5:9: 5:10 -- _2 = CheckedAdd(const 1u32, const 1u32); // scope 0 at $DIR/checked_add.rs:5:18: 5:23 -+ _2 = (const 2u32, const false); // scope 0 at $DIR/checked_add.rs:5:18: 5:23 +- _2 = CheckedAdd(const 1_u32, const 1_u32); // scope 0 at $DIR/checked_add.rs:5:18: 5:23 ++ _2 = (const 2_u32, const false); // scope 0 at $DIR/checked_add.rs:5:18: 5:23 // ty::Const // + ty: u32 - // + val: Value(Scalar(0x00000001)) @@ -30,21 +30,33 @@ // mir::Constant - // + span: $DIR/checked_add.rs:5:22: 5:23 - // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } -- assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 +- assert(!move (_2.1: bool), "attempt to compute `{} + {}` which would overflow", const 1_u32, const 1_u32) -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 + // + span: $DIR/checked_add.rs:5:18: 5:23 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to add with overflow") -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 -+ // ty::Const ++ assert(!const false, "attempt to compute `{} + {}` which would overflow", const 1_u32, const 1_u32) -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/checked_add.rs:5:18: 5:23 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } ++ // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/checked_add.rs:5:18: 5:19 + // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/checked_add.rs:5:22: 5:23 + // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } } bb1: { - _1 = move (_2.0: u32); // scope 0 at $DIR/checked_add.rs:5:18: 5:23 -+ _1 = const 2u32; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 ++ _1 = const 2_u32; // scope 0 at $DIR/checked_add.rs:5:18: 5:23 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/const_prop/discriminant/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/discriminant/32bit/rustc.main.ConstProp.diff index 1c873f53f378a..26010b43c922a 100644 --- a/src/test/mir-opt/const_prop/discriminant/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/discriminant/32bit/rustc.main.ConstProp.diff @@ -25,17 +25,17 @@ - // + span: $DIR/discriminant.rs:11:39: 11:43 - // + literal: Const { ty: bool, val: Value(Scalar(0x01)) } - _4 = discriminant(_3); // scope 0 at $DIR/discriminant.rs:11:21: 11:31 -- switchInt(move _4) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 +- switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // + span: $DIR/discriminant.rs:11:34: 11:44 + // + literal: Const { ty: std::option::Option, val: Value(Scalar(0x01)) } -+ _4 = const 1isize; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 ++ _4 = const 1_isize; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/discriminant.rs:11:21: 11:31 + // + literal: Const { ty: isize, val: Value(Scalar(0x00000001)) } -+ switchInt(const 1isize) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 ++ switchInt(const 1_isize) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x00000001)) @@ -45,7 +45,7 @@ } bb1: { - _2 = const 10i32; // scope 0 at $DIR/discriminant.rs:11:59: 11:61 + _2 = const 10_i32; // scope 0 at $DIR/discriminant.rs:11:59: 11:61 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000000a)) @@ -60,7 +60,7 @@ } bb3: { - _2 = const 42i32; // scope 0 at $DIR/discriminant.rs:11:47: 11:49 + _2 = const 42_i32; // scope 0 at $DIR/discriminant.rs:11:47: 11:49 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -71,7 +71,7 @@ } bb4: { - _1 = Add(move _2, const 0i32); // scope 0 at $DIR/discriminant.rs:11:13: 11:68 + _1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:11:13: 11:68 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/const_prop/discriminant/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/discriminant/64bit/rustc.main.ConstProp.diff index 75b4b7e5a62ba..b09c9c4766116 100644 --- a/src/test/mir-opt/const_prop/discriminant/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/discriminant/64bit/rustc.main.ConstProp.diff @@ -25,17 +25,17 @@ - // + span: $DIR/discriminant.rs:11:39: 11:43 - // + literal: Const { ty: bool, val: Value(Scalar(0x01)) } - _4 = discriminant(_3); // scope 0 at $DIR/discriminant.rs:11:21: 11:31 -- switchInt(move _4) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 +- switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // + span: $DIR/discriminant.rs:11:34: 11:44 + // + literal: Const { ty: std::option::Option, val: Value(Scalar(0x01)) } -+ _4 = const 1isize; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 ++ _4 = const 1_isize; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x0000000000000001)) + // mir::Constant + // + span: $DIR/discriminant.rs:11:21: 11:31 + // + literal: Const { ty: isize, val: Value(Scalar(0x0000000000000001)) } -+ switchInt(const 1isize) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 ++ switchInt(const 1_isize) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x0000000000000001)) @@ -45,7 +45,7 @@ } bb1: { - _2 = const 10i32; // scope 0 at $DIR/discriminant.rs:11:59: 11:61 + _2 = const 10_i32; // scope 0 at $DIR/discriminant.rs:11:59: 11:61 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000000a)) @@ -60,7 +60,7 @@ } bb3: { - _2 = const 42i32; // scope 0 at $DIR/discriminant.rs:11:47: 11:49 + _2 = const 42_i32; // scope 0 at $DIR/discriminant.rs:11:47: 11:49 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -71,7 +71,7 @@ } bb4: { - _1 = Add(move _2, const 0i32); // scope 0 at $DIR/discriminant.rs:11:13: 11:68 + _1 = Add(move _2, const 0_i32); // scope 0 at $DIR/discriminant.rs:11:13: 11:68 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/const_prop/indirect/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/indirect/rustc.main.ConstProp.diff index 941cde9172a6f..71980185fd5cd 100644 --- a/src/test/mir-opt/const_prop/indirect/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/indirect/rustc.main.ConstProp.diff @@ -13,8 +13,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/indirect.rs:5:9: 5:10 StorageLive(_2); // scope 0 at $DIR/indirect.rs:5:13: 5:25 -- _2 = const 2u32 as u8 (Misc); // scope 0 at $DIR/indirect.rs:5:13: 5:25 -+ _2 = const 2u8; // scope 0 at $DIR/indirect.rs:5:13: 5:25 +- _2 = const 2_u32 as u8 (Misc); // scope 0 at $DIR/indirect.rs:5:13: 5:25 ++ _2 = const 2_u8; // scope 0 at $DIR/indirect.rs:5:13: 5:25 // ty::Const - // + ty: u32 - // + val: Value(Scalar(0x00000002)) @@ -23,10 +23,10 @@ // mir::Constant - // + span: $DIR/indirect.rs:5:14: 5:18 - // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } -- _3 = CheckedAdd(move _2, const 1u8); // scope 0 at $DIR/indirect.rs:5:13: 5:29 +- _3 = CheckedAdd(_2, const 1_u8); // scope 0 at $DIR/indirect.rs:5:13: 5:29 + // + span: $DIR/indirect.rs:5:13: 5:25 + // + literal: Const { ty: u8, val: Value(Scalar(0x02)) } -+ _3 = (const 3u8, const false); // scope 0 at $DIR/indirect.rs:5:13: 5:29 ++ _3 = (const 3_u8, const false); // scope 0 at $DIR/indirect.rs:5:13: 5:29 // ty::Const // + ty: u8 - // + val: Value(Scalar(0x01)) @@ -34,27 +34,33 @@ // mir::Constant - // + span: $DIR/indirect.rs:5:28: 5:29 - // + literal: Const { ty: u8, val: Value(Scalar(0x01)) } -- assert(!move (_3.1: bool), "attempt to add with overflow") -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29 +- assert(!move (_3.1: bool), "attempt to compute `{} + {}` which would overflow", move _2, const 1_u8) -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29 + // + span: $DIR/indirect.rs:5:13: 5:29 + // + literal: Const { ty: u8, val: Value(Scalar(0x03)) } -+ // ty::Const + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/indirect.rs:5:13: 5:29 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to add with overflow") -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29 ++ assert(!const false, "attempt to compute `{} + {}` which would overflow", move _2, const 1_u8) -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/indirect.rs:5:13: 5:29 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } ++ // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x01)) + // mir::Constant + // + span: $DIR/indirect.rs:5:28: 5:29 + // + literal: Const { ty: u8, val: Value(Scalar(0x01)) } } bb1: { - _1 = move (_3.0: u8); // scope 0 at $DIR/indirect.rs:5:13: 5:29 -+ _1 = const 3u8; // scope 0 at $DIR/indirect.rs:5:13: 5:29 ++ _1 = const 3_u8; // scope 0 at $DIR/indirect.rs:5:13: 5:29 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x03)) diff --git a/src/test/mir-opt/const_prop/issue-66971/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/issue-66971/rustc.main.ConstProp.diff index c26494bdc1042..242907b5599d8 100644 --- a/src/test/mir-opt/const_prop/issue-66971/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/issue-66971/rustc.main.ConstProp.diff @@ -19,7 +19,7 @@ + // mir::Constant + // + span: $DIR/issue-66971.rs:16:13: 16:15 + // + literal: Const { ty: (), val: Value(Scalar()) } - _2 = (move _3, const 0u8, const 0u8); // scope 0 at $DIR/issue-66971.rs:16:12: 16:22 + _2 = (move _3, const 0_u8, const 0_u8); // scope 0 at $DIR/issue-66971.rs:16:12: 16:22 // ty::Const // + ty: u8 // + val: Value(Scalar(0x00)) diff --git a/src/test/mir-opt/const_prop/issue-67019/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/issue-67019/rustc.main.ConstProp.diff index e328febb407ae..d5c1105d7caff 100644 --- a/src/test/mir-opt/const_prop/issue-67019/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/issue-67019/rustc.main.ConstProp.diff @@ -11,7 +11,7 @@ StorageLive(_1); // scope 0 at $DIR/issue-67019.rs:11:5: 11:20 StorageLive(_2); // scope 0 at $DIR/issue-67019.rs:11:10: 11:19 StorageLive(_3); // scope 0 at $DIR/issue-67019.rs:11:11: 11:17 - _3 = (const 1u8, const 2u8); // scope 0 at $DIR/issue-67019.rs:11:11: 11:17 + _3 = (const 1_u8, const 2_u8); // scope 0 at $DIR/issue-67019.rs:11:11: 11:17 // ty::Const // + ty: u8 // + val: Value(Scalar(0x01)) diff --git a/src/test/mir-opt/const_prop/mutable_variable/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable/rustc.main.ConstProp.diff index 187c17454350a..3d4309a8aec54 100644 --- a/src/test/mir-opt/const_prop/mutable_variable/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable/rustc.main.ConstProp.diff @@ -14,14 +14,14 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/mutable_variable.rs:5:9: 5:14 - _1 = const 42i32; // scope 0 at $DIR/mutable_variable.rs:5:17: 5:19 + _1 = const 42_i32; // scope 0 at $DIR/mutable_variable.rs:5:17: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) // mir::Constant // + span: $DIR/mutable_variable.rs:5:17: 5:19 // + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) } - _1 = const 99i32; // scope 1 at $DIR/mutable_variable.rs:6:5: 6:11 + _1 = const 99_i32; // scope 1 at $DIR/mutable_variable.rs:6:5: 6:11 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000063)) @@ -30,7 +30,7 @@ // + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) } StorageLive(_2); // scope 1 at $DIR/mutable_variable.rs:7:9: 7:10 - _2 = _1; // scope 1 at $DIR/mutable_variable.rs:7:13: 7:14 -+ _2 = const 99i32; // scope 1 at $DIR/mutable_variable.rs:7:13: 7:14 ++ _2 = const 99_i32; // scope 1 at $DIR/mutable_variable.rs:7:13: 7:14 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000063)) diff --git a/src/test/mir-opt/const_prop/mutable_variable_aggregate/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable_aggregate/rustc.main.ConstProp.diff index cf432b2acc1c5..f581b222c83cb 100644 --- a/src/test/mir-opt/const_prop/mutable_variable_aggregate/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable_aggregate/rustc.main.ConstProp.diff @@ -14,7 +14,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/mutable_variable_aggregate.rs:5:9: 5:14 - _1 = (const 42i32, const 43i32); // scope 0 at $DIR/mutable_variable_aggregate.rs:5:17: 5:25 + _1 = (const 42_i32, const 43_i32); // scope 0 at $DIR/mutable_variable_aggregate.rs:5:17: 5:25 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -29,7 +29,7 @@ - // + span: $DIR/mutable_variable_aggregate.rs:5:22: 5:24 + // + span: $DIR/mutable_variable_aggregate.rs:5:17: 5:25 // + literal: Const { ty: i32, val: Value(Scalar(0x0000002b)) } - (_1.1: i32) = const 99i32; // scope 1 at $DIR/mutable_variable_aggregate.rs:6:5: 6:13 + (_1.1: i32) = const 99_i32; // scope 1 at $DIR/mutable_variable_aggregate.rs:6:5: 6:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000063)) @@ -38,7 +38,7 @@ // + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) } StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:9: 7:10 - _2 = _1; // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14 -+ _2 = (const 42i32, const 99i32); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14 ++ _2 = (const 42_i32, const 99_i32); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/mutable_variable_aggregate_mut_ref/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable_aggregate_mut_ref/rustc.main.ConstProp.diff index 0d703068d41f4..e78bc31b77480 100644 --- a/src/test/mir-opt/const_prop/mutable_variable_aggregate_mut_ref/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable_aggregate_mut_ref/rustc.main.ConstProp.diff @@ -18,7 +18,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/mutable_variable_aggregate_mut_ref.rs:5:9: 5:14 - _1 = (const 42i32, const 43i32); // scope 0 at $DIR/mutable_variable_aggregate_mut_ref.rs:5:17: 5:25 + _1 = (const 42_i32, const 43_i32); // scope 0 at $DIR/mutable_variable_aggregate_mut_ref.rs:5:17: 5:25 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -35,7 +35,7 @@ // + literal: Const { ty: i32, val: Value(Scalar(0x0000002b)) } StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate_mut_ref.rs:6:9: 6:10 _2 = &mut _1; // scope 1 at $DIR/mutable_variable_aggregate_mut_ref.rs:6:13: 6:19 - ((*_2).1: i32) = const 99i32; // scope 2 at $DIR/mutable_variable_aggregate_mut_ref.rs:7:5: 7:13 + ((*_2).1: i32) = const 99_i32; // scope 2 at $DIR/mutable_variable_aggregate_mut_ref.rs:7:5: 7:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000063)) diff --git a/src/test/mir-opt/const_prop/mutable_variable_aggregate_partial_read/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable_aggregate_partial_read/rustc.main.ConstProp.diff index f6bb72baea419..b1a0ab88fccd5 100644 --- a/src/test/mir-opt/const_prop/mutable_variable_aggregate_partial_read/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable_aggregate_partial_read/rustc.main.ConstProp.diff @@ -24,14 +24,14 @@ } bb1: { - (_1.1: i32) = const 99i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:6:5: 6:13 + (_1.1: i32) = const 99_i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:6:5: 6:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000063)) // mir::Constant // + span: $DIR/mutable_variable_aggregate_partial_read.rs:6:11: 6:13 // + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) } - (_1.0: i32) = const 42i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:7:5: 7:13 + (_1.0: i32) = const 42_i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:7:5: 7:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -40,7 +40,7 @@ // + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) } StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:9: 8:10 - _2 = (_1.1: i32); // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:13: 8:16 -+ _2 = const 99i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:13: 8:16 ++ _2 = const 99_i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:13: 8:16 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000063)) diff --git a/src/test/mir-opt/const_prop/mutable_variable_no_prop/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable_no_prop/rustc.main.ConstProp.diff index b7f1242d8d125..3b72af2d0b9c5 100644 --- a/src/test/mir-opt/const_prop/mutable_variable_no_prop/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable_no_prop/rustc.main.ConstProp.diff @@ -19,7 +19,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/mutable_variable_no_prop.rs:7:9: 7:14 - _1 = const 42u32; // scope 0 at $DIR/mutable_variable_no_prop.rs:7:17: 7:19 + _1 = const 42_u32; // scope 0 at $DIR/mutable_variable_no_prop.rs:7:17: 7:19 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/mutable_variable_unprop_assign/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/mutable_variable_unprop_assign/rustc.main.ConstProp.diff index e0b9fbe04c387..b59b180b07d7f 100644 --- a/src/test/mir-opt/const_prop/mutable_variable_unprop_assign/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/mutable_variable_unprop_assign/rustc.main.ConstProp.diff @@ -34,7 +34,7 @@ bb1: { StorageLive(_2); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:9: 6:14 - _2 = (const 1i32, const 2i32); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:29: 6:35 + _2 = (const 1_i32, const 2_i32); // scope 1 at $DIR/mutable_variable_unprop_assign.rs:6:29: 6:35 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.ConstProp.diff index 9bd9bfa9f2796..4bfa50e9851f4 100644 --- a/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.ConstProp.diff @@ -24,8 +24,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10 -- _2 = CheckedAdd(const 2i32, const 2i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ _2 = (const 4i32, const false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 +- _2 = CheckedAdd(const 2_i32, const 2_i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 ++ _2 = (const 4_i32, const false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 // ty::Const // + ty: i32 - // + val: Value(Scalar(0x00000002)) @@ -43,21 +43,33 @@ // mir::Constant - // + span: $DIR/optimizes_into_variable.rs:12:17: 12:18 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } -- assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 +- assert(!move (_2.1: bool), "attempt to compute `{} + {}` which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to add with overflow") -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ // ty::Const ++ assert(!const false, "attempt to compute `{} + {}` which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } ++ // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:14 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:17: 12:18 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } } bb1: { - _1 = move (_2.0: i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ _1 = const 4i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 ++ _1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000004)) @@ -66,7 +78,7 @@ + // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } StorageLive(_3); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10 StorageLive(_4); // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 - _4 = [const 0i32, const 1i32, const 2i32, const 3i32, const 4i32, const 5i32]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 + _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -104,14 +116,14 @@ // + span: $DIR/optimizes_into_variable.rs:13:29: 13:30 // + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } StorageLive(_5); // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 - _5 = const 3usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 + _5 = const 3_usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000003)) // mir::Constant // + span: $DIR/optimizes_into_variable.rs:13:32: 13:33 // + literal: Const { ty: usize, val: Value(Scalar(0x00000003)) } - _6 = const 6usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + _6 = const 6_usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000006)) @@ -138,7 +150,7 @@ bb2: { - _3 = _4[_5]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 -+ _3 = const 3i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 ++ _3 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000003)) @@ -149,7 +161,7 @@ StorageDead(_4); // scope 1 at $DIR/optimizes_into_variable.rs:13:34: 13:35 StorageLive(_8); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10 StorageLive(_9); // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 - _9 = Point { x: const 12u32, y: const 42u32 }; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 + _9 = Point { x: const 12_u32, y: const 42_u32 }; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000000c)) @@ -163,7 +175,7 @@ // + span: $DIR/optimizes_into_variable.rs:14:32: 14:34 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } - _8 = (_9.1: u32); // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 -+ _8 = const 42u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 ++ _8 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.SimplifyLocals.after.mir b/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.SimplifyLocals.after.mir index 8ea9316c7d49b..7b74bf81d96fe 100644 --- a/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.SimplifyLocals.after.mir +++ b/src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.SimplifyLocals.after.mir @@ -17,7 +17,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10 - _1 = const 4i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + _1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000004)) @@ -25,7 +25,7 @@ fn main() -> () { // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } StorageLive(_2); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10 - _2 = const 3i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + _2 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -33,7 +33,7 @@ fn main() -> () { // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34 // + literal: Const { ty: i32, val: Value(Scalar(0x00000003)) } StorageLive(_3); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10 - _3 = const 42u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 + _3 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.ConstProp.diff index 1da763ec9558a..2d40567ce8da1 100644 --- a/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.ConstProp.diff @@ -24,8 +24,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10 -- _2 = CheckedAdd(const 2i32, const 2i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ _2 = (const 4i32, const false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 +- _2 = CheckedAdd(const 2_i32, const 2_i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 ++ _2 = (const 4_i32, const false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 // ty::Const // + ty: i32 - // + val: Value(Scalar(0x00000002)) @@ -43,21 +43,33 @@ // mir::Constant - // + span: $DIR/optimizes_into_variable.rs:12:17: 12:18 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } -- assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 +- assert(!move (_2.1: bool), "attempt to compute `{} + {}` which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to add with overflow") -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ // ty::Const ++ assert(!const false, "attempt to compute `{} + {}` which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } ++ // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:13: 12:14 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/optimizes_into_variable.rs:12:17: 12:18 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000002)) } } bb1: { - _1 = move (_2.0: i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 -+ _1 = const 4i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 ++ _1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000004)) @@ -66,7 +78,7 @@ + // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } StorageLive(_3); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10 StorageLive(_4); // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 - _4 = [const 0i32, const 1i32, const 2i32, const 3i32, const 4i32, const 5i32]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 + _4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:31 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -104,14 +116,14 @@ // + span: $DIR/optimizes_into_variable.rs:13:29: 13:30 // + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } StorageLive(_5); // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 - _5 = const 3usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 + _5 = const 3_usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:32: 13:33 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000003)) // mir::Constant // + span: $DIR/optimizes_into_variable.rs:13:32: 13:33 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000003)) } - _6 = const 6usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + _6 = const 6_usize; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000006)) @@ -138,7 +150,7 @@ bb2: { - _3 = _4[_5]; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 -+ _3 = const 3i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 ++ _3 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000003)) @@ -149,7 +161,7 @@ StorageDead(_4); // scope 1 at $DIR/optimizes_into_variable.rs:13:34: 13:35 StorageLive(_8); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10 StorageLive(_9); // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 - _9 = Point { x: const 12u32, y: const 42u32 }; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 + _9 = Point { x: const 12_u32, y: const 42_u32 }; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:36 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000000c)) @@ -163,7 +175,7 @@ // + span: $DIR/optimizes_into_variable.rs:14:32: 14:34 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } - _8 = (_9.1: u32); // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 -+ _8 = const 42u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 ++ _8 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.SimplifyLocals.after.mir b/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.SimplifyLocals.after.mir index 8ea9316c7d49b..7b74bf81d96fe 100644 --- a/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.SimplifyLocals.after.mir +++ b/src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.SimplifyLocals.after.mir @@ -17,7 +17,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/optimizes_into_variable.rs:12:9: 12:10 - _1 = const 4i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 + _1 = const 4_i32; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000004)) @@ -25,7 +25,7 @@ fn main() -> () { // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18 // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } StorageLive(_2); // scope 1 at $DIR/optimizes_into_variable.rs:13:9: 13:10 - _2 = const 3i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 + _2 = const 3_i32; // scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -33,7 +33,7 @@ fn main() -> () { // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34 // + literal: Const { ty: i32, val: Value(Scalar(0x00000003)) } StorageLive(_3); // scope 2 at $DIR/optimizes_into_variable.rs:14:9: 14:10 - _3 = const 42u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 + _3 = const 42_u32; // scope 2 at $DIR/optimizes_into_variable.rs:14:13: 14:38 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/read_immutable_static/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/read_immutable_static/rustc.main.ConstProp.diff index 103444f796ec6..36edfc42b9a76 100644 --- a/src/test/mir-opt/const_prop/read_immutable_static/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/read_immutable_static/rustc.main.ConstProp.diff @@ -24,7 +24,7 @@ // + span: $DIR/read_immutable_static.rs:7:13: 7:16 // + literal: Const { ty: &u8, val: Value(Scalar(alloc0)) } - _2 = (*_3); // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16 -+ _2 = const 2u8; // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16 ++ _2 = const 2_u8; // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:16 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x02)) @@ -42,14 +42,14 @@ // + literal: Const { ty: &u8, val: Value(Scalar(alloc0)) } - _4 = (*_5); // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22 - _1 = Add(move _2, move _4); // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:22 -+ _4 = const 2u8; // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22 ++ _4 = const 2_u8; // scope 0 at $DIR/read_immutable_static.rs:7:19: 7:22 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x02)) + // mir::Constant + // + span: $DIR/read_immutable_static.rs:7:19: 7:22 + // + literal: Const { ty: u8, val: Value(Scalar(0x02)) } -+ _1 = const 4u8; // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:22 ++ _1 = const 4_u8; // scope 0 at $DIR/read_immutable_static.rs:7:13: 7:22 + // ty::Const + // + ty: u8 + // + val: Value(Scalar(0x04)) diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff index dcd3d4019811e..12e3a04d89bf2 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff @@ -20,7 +20,7 @@ // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ ref_deref[317d]::main[0]), [], Some(promoted[0])) } _2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 - _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 -+ _1 = const 4i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 ++ _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000004)) diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff index ef696f1ab8052..d56f07e0f57f5 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff @@ -12,7 +12,7 @@ StorageLive(_1); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 StorageLive(_2); // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 - StorageLive(_3); // scope 0 at $DIR/ref_deref.rs:5:8: 5:9 -- _3 = const 4i32; // scope 0 at $DIR/ref_deref.rs:5:8: 5:9 +- _3 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:8: 5:9 + _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 // ty::Const - // + ty: i32 diff --git a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff index 7f23f5ea7a69a..0b9c1caa6bdae 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff @@ -12,7 +12,7 @@ StorageLive(_1); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 StorageLive(_2); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 - StorageLive(_3); // scope 0 at $DIR/ref_deref_project.rs:5:8: 5:14 -- _3 = (const 4i32, const 5i32); // scope 0 at $DIR/ref_deref_project.rs:5:8: 5:14 +- _3 = (const 4_i32, const 5_i32); // scope 0 at $DIR/ref_deref_project.rs:5:8: 5:14 + _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 // ty::Const - // + ty: i32 diff --git a/src/test/mir-opt/const_prop/repeat/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/repeat/32bit/rustc.main.ConstProp.diff index b1c9e22913935..3046b2ca9b8a4 100644 --- a/src/test/mir-opt/const_prop/repeat/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/repeat/32bit/rustc.main.ConstProp.diff @@ -17,7 +17,7 @@ StorageLive(_1); // scope 0 at $DIR/repeat.rs:6:9: 6:10 StorageLive(_2); // scope 0 at $DIR/repeat.rs:6:18: 6:28 StorageLive(_3); // scope 0 at $DIR/repeat.rs:6:18: 6:25 - _3 = [const 42u32; 8]; // scope 0 at $DIR/repeat.rs:6:18: 6:25 + _3 = [const 42_u32; 8]; // scope 0 at $DIR/repeat.rs:6:18: 6:25 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) @@ -25,14 +25,14 @@ // + span: $DIR/repeat.rs:6:19: 6:21 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } StorageLive(_4); // scope 0 at $DIR/repeat.rs:6:26: 6:27 - _4 = const 2usize; // scope 0 at $DIR/repeat.rs:6:26: 6:27 + _4 = const 2_usize; // scope 0 at $DIR/repeat.rs:6:26: 6:27 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000002)) // mir::Constant // + span: $DIR/repeat.rs:6:26: 6:27 // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) } - _5 = const 8usize; // scope 0 at $DIR/repeat.rs:6:18: 6:28 + _5 = const 8_usize; // scope 0 at $DIR/repeat.rs:6:18: 6:28 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000008)) @@ -59,8 +59,8 @@ bb1: { - _2 = _3[_4]; // scope 0 at $DIR/repeat.rs:6:18: 6:28 -- _1 = Add(move _2, const 0u32); // scope 0 at $DIR/repeat.rs:6:18: 6:32 -+ _2 = const 42u32; // scope 0 at $DIR/repeat.rs:6:18: 6:28 +- _1 = Add(move _2, const 0_u32); // scope 0 at $DIR/repeat.rs:6:18: 6:32 ++ _2 = const 42_u32; // scope 0 at $DIR/repeat.rs:6:18: 6:28 // ty::Const // + ty: u32 - // + val: Value(Scalar(0x00000000)) @@ -70,7 +70,7 @@ - // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) } + // + span: $DIR/repeat.rs:6:18: 6:28 + // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } -+ _1 = const 42u32; // scope 0 at $DIR/repeat.rs:6:18: 6:32 ++ _1 = const 42_u32; // scope 0 at $DIR/repeat.rs:6:18: 6:32 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/repeat/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/repeat/64bit/rustc.main.ConstProp.diff index 29555b03a8b8e..c06ed33df24c1 100644 --- a/src/test/mir-opt/const_prop/repeat/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/repeat/64bit/rustc.main.ConstProp.diff @@ -17,7 +17,7 @@ StorageLive(_1); // scope 0 at $DIR/repeat.rs:6:9: 6:10 StorageLive(_2); // scope 0 at $DIR/repeat.rs:6:18: 6:28 StorageLive(_3); // scope 0 at $DIR/repeat.rs:6:18: 6:25 - _3 = [const 42u32; 8]; // scope 0 at $DIR/repeat.rs:6:18: 6:25 + _3 = [const 42_u32; 8]; // scope 0 at $DIR/repeat.rs:6:18: 6:25 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000002a)) @@ -25,14 +25,14 @@ // + span: $DIR/repeat.rs:6:19: 6:21 // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } StorageLive(_4); // scope 0 at $DIR/repeat.rs:6:26: 6:27 - _4 = const 2usize; // scope 0 at $DIR/repeat.rs:6:26: 6:27 + _4 = const 2_usize; // scope 0 at $DIR/repeat.rs:6:26: 6:27 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000002)) // mir::Constant // + span: $DIR/repeat.rs:6:26: 6:27 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) } - _5 = const 8usize; // scope 0 at $DIR/repeat.rs:6:18: 6:28 + _5 = const 8_usize; // scope 0 at $DIR/repeat.rs:6:18: 6:28 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000008)) @@ -59,8 +59,8 @@ bb1: { - _2 = _3[_4]; // scope 0 at $DIR/repeat.rs:6:18: 6:28 -- _1 = Add(move _2, const 0u32); // scope 0 at $DIR/repeat.rs:6:18: 6:32 -+ _2 = const 42u32; // scope 0 at $DIR/repeat.rs:6:18: 6:28 +- _1 = Add(move _2, const 0_u32); // scope 0 at $DIR/repeat.rs:6:18: 6:32 ++ _2 = const 42_u32; // scope 0 at $DIR/repeat.rs:6:18: 6:28 // ty::Const // + ty: u32 - // + val: Value(Scalar(0x00000000)) @@ -70,7 +70,7 @@ - // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) } + // + span: $DIR/repeat.rs:6:18: 6:28 + // + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) } -+ _1 = const 42u32; // scope 0 at $DIR/repeat.rs:6:18: 6:32 ++ _1 = const 42_u32; // scope 0 at $DIR/repeat.rs:6:18: 6:32 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x0000002a)) diff --git a/src/test/mir-opt/const_prop/return_place/rustc.add.ConstProp.diff b/src/test/mir-opt/const_prop/return_place/rustc.add.ConstProp.diff index fc7d028277bd9..5e39c8e6d523e 100644 --- a/src/test/mir-opt/const_prop/return_place/rustc.add.ConstProp.diff +++ b/src/test/mir-opt/const_prop/return_place/rustc.add.ConstProp.diff @@ -6,8 +6,8 @@ let mut _1: (u32, bool); // in scope 0 at $DIR/return_place.rs:6:5: 6:10 bb0: { -- _1 = CheckedAdd(const 2u32, const 2u32); // scope 0 at $DIR/return_place.rs:6:5: 6:10 -+ _1 = (const 4u32, const false); // scope 0 at $DIR/return_place.rs:6:5: 6:10 +- _1 = CheckedAdd(const 2_u32, const 2_u32); // scope 0 at $DIR/return_place.rs:6:5: 6:10 ++ _1 = (const 4_u32, const false); // scope 0 at $DIR/return_place.rs:6:5: 6:10 // ty::Const // + ty: u32 - // + val: Value(Scalar(0x00000002)) @@ -25,21 +25,33 @@ // mir::Constant - // + span: $DIR/return_place.rs:6:9: 6:10 - // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } -- assert(!move (_1.1: bool), "attempt to add with overflow") -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10 +- assert(!move (_1.1: bool), "attempt to compute `{} + {}` which would overflow", const 2_u32, const 2_u32) -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10 + // + span: $DIR/return_place.rs:6:5: 6:10 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } -+ assert(!const false, "attempt to add with overflow") -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10 -+ // ty::Const ++ assert(!const false, "attempt to compute `{} + {}` which would overflow", const 2_u32, const 2_u32) -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10 + // ty::Const + // + ty: bool + // + val: Value(Scalar(0x00)) + // mir::Constant + // + span: $DIR/return_place.rs:6:5: 6:10 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } ++ // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/return_place.rs:6:5: 6:6 + // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) + // mir::Constant + // + span: $DIR/return_place.rs:6:9: 6:10 + // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } } bb1: { - _0 = move (_1.0: u32); // scope 0 at $DIR/return_place.rs:6:5: 6:10 -+ _0 = const 4u32; // scope 0 at $DIR/return_place.rs:6:5: 6:10 ++ _0 = const 4_u32; // scope 0 at $DIR/return_place.rs:6:5: 6:10 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000004)) diff --git a/src/test/mir-opt/const_prop/return_place/rustc.add.PreCodegen.before.mir b/src/test/mir-opt/const_prop/return_place/rustc.add.PreCodegen.before.mir index b741c786fb394..23ad8d057ba8d 100644 --- a/src/test/mir-opt/const_prop/return_place/rustc.add.PreCodegen.before.mir +++ b/src/test/mir-opt/const_prop/return_place/rustc.add.PreCodegen.before.mir @@ -4,7 +4,7 @@ fn add() -> u32 { let mut _0: u32; // return place in scope 0 at $DIR/return_place.rs:5:13: 5:16 bb0: { - _0 = const 4u32; // scope 0 at $DIR/return_place.rs:6:5: 6:10 + _0 = const 4_u32; // scope 0 at $DIR/return_place.rs:6:5: 6:10 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000004)) diff --git a/src/test/mir-opt/const_prop/scalar_literal_propagation/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/scalar_literal_propagation/rustc.main.ConstProp.diff index 596ddcb43533b..43e0eb09a2e5f 100644 --- a/src/test/mir-opt/const_prop/scalar_literal_propagation/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/scalar_literal_propagation/rustc.main.ConstProp.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/scalar_literal_propagation.rs:3:9: 3:10 - _1 = const 1u32; // scope 0 at $DIR/scalar_literal_propagation.rs:3:13: 3:14 + _1 = const 1_u32; // scope 0 at $DIR/scalar_literal_propagation.rs:3:13: 3:14 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000001)) @@ -23,14 +23,14 @@ StorageLive(_3); // scope 1 at $DIR/scalar_literal_propagation.rs:4:13: 4:14 - _3 = _1; // scope 1 at $DIR/scalar_literal_propagation.rs:4:13: 4:14 - _2 = const consume(move _3) -> bb1; // scope 1 at $DIR/scalar_literal_propagation.rs:4:5: 4:15 -+ _3 = const 1u32; // scope 1 at $DIR/scalar_literal_propagation.rs:4:13: 4:14 ++ _3 = const 1_u32; // scope 1 at $DIR/scalar_literal_propagation.rs:4:13: 4:14 // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/scalar_literal_propagation.rs:4:13: 4:14 + // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } -+ _2 = const consume(const 1u32) -> bb1; // scope 1 at $DIR/scalar_literal_propagation.rs:4:5: 4:15 ++ _2 = const consume(const 1_u32) -> bb1; // scope 1 at $DIR/scalar_literal_propagation.rs:4:5: 4:15 + // ty::Const // + ty: fn(u32) {consume} // + val: Value(Scalar()) diff --git a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff index 9471dbef410d1..70c4156488223 100644 --- a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff @@ -30,7 +30,7 @@ _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 StorageDead(_3); // scope 0 at $DIR/slice_len.rs:5:18: 5:19 StorageLive(_6); // scope 0 at $DIR/slice_len.rs:5:31: 5:32 - _6 = const 1usize; // scope 0 at $DIR/slice_len.rs:5:31: 5:32 + _6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:5:31: 5:32 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -40,7 +40,7 @@ - _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:5:5: 5:33 - _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:5:5: 5:33 - assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 -+ _7 = const 3usize; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 ++ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000003)) @@ -65,7 +65,7 @@ bb1: { - _1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 -+ _1 = const 2u32; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 ++ _1 = const 2_u32; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff index 3ae88e0d79863..885f28124c4b7 100644 --- a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff @@ -30,7 +30,7 @@ _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 StorageDead(_3); // scope 0 at $DIR/slice_len.rs:5:18: 5:19 StorageLive(_6); // scope 0 at $DIR/slice_len.rs:5:31: 5:32 - _6 = const 1usize; // scope 0 at $DIR/slice_len.rs:5:31: 5:32 + _6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:5:31: 5:32 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -40,7 +40,7 @@ - _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:5:5: 5:33 - _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:5:5: 5:33 - assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 -+ _7 = const 3usize; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 ++ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000003)) @@ -65,7 +65,7 @@ bb1: { - _1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 -+ _1 = const 2u32; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 ++ _1 = const 2_u32; // scope 0 at $DIR/slice_len.rs:5:5: 5:33 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/const_prop/switch_int/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/switch_int/rustc.main.ConstProp.diff index 8072424729ab0..9580b99da9e40 100644 --- a/src/test/mir-opt/const_prop/switch_int/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/switch_int/rustc.main.ConstProp.diff @@ -7,15 +7,15 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 - _1 = const 1i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 + _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/switch_int.rs:7:11: 7:12 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } -- switchInt(_1) -> [1i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 -+ switchInt(const 1i32) -> [1i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(_1) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 ++ switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) @@ -25,7 +25,7 @@ } bb1: { - _0 = const foo(const -1i32) -> bb3; // scope 0 at $DIR/switch_int.rs:9:14: 9:21 + _0 = const foo(const -1_i32) -> bb3; // scope 0 at $DIR/switch_int.rs:9:14: 9:21 // ty::Const // + ty: fn(i32) {foo} // + val: Value(Scalar()) @@ -41,7 +41,7 @@ } bb2: { - _0 = const foo(const 0i32) -> bb3; // scope 0 at $DIR/switch_int.rs:8:14: 8:20 + _0 = const foo(const 0_i32) -> bb3; // scope 0 at $DIR/switch_int.rs:8:14: 8:20 // ty::Const // + ty: fn(i32) {foo} // + val: Value(Scalar()) diff --git a/src/test/mir-opt/const_prop/switch_int/rustc.main.SimplifyBranches-after-const-prop.diff b/src/test/mir-opt/const_prop/switch_int/rustc.main.SimplifyBranches-after-const-prop.diff index 51f3bf20c1aea..54f37e609ec13 100644 --- a/src/test/mir-opt/const_prop/switch_int/rustc.main.SimplifyBranches-after-const-prop.diff +++ b/src/test/mir-opt/const_prop/switch_int/rustc.main.SimplifyBranches-after-const-prop.diff @@ -7,14 +7,14 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 - _1 = const 1i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 + _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/switch_int.rs:7:11: 7:12 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } -- switchInt(const 1i32) -> [1i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 - // ty::Const - // + ty: i32 - // + val: Value(Scalar(0x00000001)) @@ -25,7 +25,7 @@ } bb1: { - _0 = const foo(const -1i32) -> bb3; // scope 0 at $DIR/switch_int.rs:9:14: 9:21 + _0 = const foo(const -1_i32) -> bb3; // scope 0 at $DIR/switch_int.rs:9:14: 9:21 // ty::Const // + ty: fn(i32) {foo} // + val: Value(Scalar()) @@ -41,7 +41,7 @@ } bb2: { - _0 = const foo(const 0i32) -> bb3; // scope 0 at $DIR/switch_int.rs:8:14: 8:20 + _0 = const foo(const 0_i32) -> bb3; // scope 0 at $DIR/switch_int.rs:8:14: 8:20 // ty::Const // + ty: fn(i32) {foo} // + val: Value(Scalar()) diff --git a/src/test/mir-opt/const_prop/tuple_literal_propagation/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/tuple_literal_propagation/rustc.main.ConstProp.diff index 1511b361f587f..941ec64a3cc12 100644 --- a/src/test/mir-opt/const_prop/tuple_literal_propagation/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/tuple_literal_propagation/rustc.main.ConstProp.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/tuple_literal_propagation.rs:3:9: 3:10 - _1 = (const 1u32, const 2u32); // scope 0 at $DIR/tuple_literal_propagation.rs:3:13: 3:19 + _1 = (const 1_u32, const 2_u32); // scope 0 at $DIR/tuple_literal_propagation.rs:3:13: 3:19 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000001)) @@ -30,7 +30,7 @@ StorageLive(_2); // scope 1 at $DIR/tuple_literal_propagation.rs:5:5: 5:15 StorageLive(_3); // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14 - _3 = _1; // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14 -+ _3 = (const 1u32, const 2u32); // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14 ++ _3 = (const 1_u32, const 2_u32); // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14 + // ty::Const + // + ty: u32 + // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/const_prop_miscompile/rustc.bar.ConstProp.diff b/src/test/mir-opt/const_prop_miscompile/rustc.bar.ConstProp.diff index c87f67bf9f587..5fe35b479c126 100644 --- a/src/test/mir-opt/const_prop_miscompile/rustc.bar.ConstProp.diff +++ b/src/test/mir-opt/const_prop_miscompile/rustc.bar.ConstProp.diff @@ -19,8 +19,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/const_prop_miscompile.rs:12:9: 12:14 -- _1 = (const 1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 -+ _1 = const (1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 +- _1 = (const 1_i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 ++ _1 = const (1_i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 // ty::Const - // + ty: i32 + // + ty: (i32,) @@ -33,7 +33,7 @@ StorageLive(_2); // scope 1 at $DIR/const_prop_miscompile.rs:13:5: 15:6 StorageLive(_3); // scope 2 at $DIR/const_prop_miscompile.rs:14:10: 14:22 _3 = &raw mut (_1.0: i32); // scope 2 at $DIR/const_prop_miscompile.rs:14:10: 14:22 - (*_3) = const 5i32; // scope 2 at $DIR/const_prop_miscompile.rs:14:9: 14:26 + (*_3) = const 5_i32; // scope 2 at $DIR/const_prop_miscompile.rs:14:9: 14:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000005)) @@ -52,7 +52,7 @@ StorageLive(_4); // scope 1 at $DIR/const_prop_miscompile.rs:16:9: 16:10 StorageLive(_5); // scope 1 at $DIR/const_prop_miscompile.rs:16:13: 16:20 _5 = (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:16:15: 16:18 - _4 = Eq(move _5, const 5i32); // scope 1 at $DIR/const_prop_miscompile.rs:16:13: 16:25 + _4 = Eq(move _5, const 5_i32); // scope 1 at $DIR/const_prop_miscompile.rs:16:13: 16:25 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000005)) diff --git a/src/test/mir-opt/const_prop_miscompile/rustc.foo.ConstProp.diff b/src/test/mir-opt/const_prop_miscompile/rustc.foo.ConstProp.diff index 8a6850d2fe3ad..98e9825c1c435 100644 --- a/src/test/mir-opt/const_prop_miscompile/rustc.foo.ConstProp.diff +++ b/src/test/mir-opt/const_prop_miscompile/rustc.foo.ConstProp.diff @@ -16,8 +16,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/const_prop_miscompile.rs:5:9: 5:14 -- _1 = (const 1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 -+ _1 = const (1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 +- _1 = (const 1_i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 ++ _1 = const (1_i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 // ty::Const - // + ty: i32 + // + ty: (i32,) @@ -29,7 +29,7 @@ + // + literal: Const { ty: (i32,), val: Value(Scalar(0x00000001)) } StorageLive(_2); // scope 1 at $DIR/const_prop_miscompile.rs:6:6: 6:14 _2 = &mut (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:6:6: 6:14 - (*_2) = const 5i32; // scope 1 at $DIR/const_prop_miscompile.rs:6:5: 6:18 + (*_2) = const 5_i32; // scope 1 at $DIR/const_prop_miscompile.rs:6:5: 6:18 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000005)) @@ -40,7 +40,7 @@ StorageLive(_3); // scope 1 at $DIR/const_prop_miscompile.rs:7:9: 7:10 StorageLive(_4); // scope 1 at $DIR/const_prop_miscompile.rs:7:13: 7:20 _4 = (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:7:15: 7:18 - _3 = Eq(move _4, const 5i32); // scope 1 at $DIR/const_prop_miscompile.rs:7:13: 7:25 + _3 = Eq(move _4, const 5_i32); // scope 1 at $DIR/const_prop_miscompile.rs:7:13: 7:25 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000005)) diff --git a/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff b/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff index 1e0271a560f65..22fbf4e836ba4 100644 --- a/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation_arg/rustc.arg_src.CopyPropagation.diff @@ -12,7 +12,7 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/copy_propagation_arg.rs:28:9: 28:10 _2 = _1; // scope 0 at $DIR/copy_propagation_arg.rs:28:13: 28:14 - _1 = const 123i32; // scope 1 at $DIR/copy_propagation_arg.rs:29:5: 29:12 + _1 = const 123_i32; // scope 1 at $DIR/copy_propagation_arg.rs:29:5: 29:12 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000007b)) diff --git a/src/test/mir-opt/copy_propagation_arg/rustc.bar.CopyPropagation.diff b/src/test/mir-opt/copy_propagation_arg/rustc.bar.CopyPropagation.diff index b875bbea67bdf..6953a80a5f08a 100644 --- a/src/test/mir-opt/copy_propagation_arg/rustc.bar.CopyPropagation.diff +++ b/src/test/mir-opt/copy_propagation_arg/rustc.bar.CopyPropagation.diff @@ -23,7 +23,7 @@ bb1: { StorageDead(_3); // scope 0 at $DIR/copy_propagation_arg.rs:16:12: 16:13 StorageDead(_2); // scope 0 at $DIR/copy_propagation_arg.rs:16:13: 16:14 - _1 = const 5u8; // scope 0 at $DIR/copy_propagation_arg.rs:17:5: 17:10 + _1 = const 5_u8; // scope 0 at $DIR/copy_propagation_arg.rs:17:5: 17:10 // ty::Const // + ty: u8 // + val: Value(Scalar(0x05)) diff --git a/src/test/mir-opt/exponential-or/rustc.match_tuple.SimplifyCfg-initial.after.mir b/src/test/mir-opt/exponential-or/rustc.match_tuple.SimplifyCfg-initial.after.mir index 3c1c02da42ff8..b84ca5df9964e 100644 --- a/src/test/mir-opt/exponential-or/rustc.match_tuple.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/exponential-or/rustc.match_tuple.SimplifyCfg-initial.after.mir @@ -19,11 +19,11 @@ fn match_tuple(_1: (u32, bool, std::option::Option, u32)) -> u32 { bb0: { FakeRead(ForMatchedPlace, _1); // scope 0 at $DIR/exponential-or.rs:7:11: 7:12 - switchInt((_1.0: u32)) -> [1u32: bb2, 4u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:15: 8:16 + switchInt((_1.0: u32)) -> [1_u32: bb2, 4_u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:15: 8:16 } bb1: { - _0 = const 0u32; // scope 0 at $DIR/exponential-or.rs:9:14: 9:15 + _0 = const 0_u32; // scope 0 at $DIR/exponential-or.rs:9:14: 9:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -35,15 +35,15 @@ fn match_tuple(_1: (u32, bool, std::option::Option, u32)) -> u32 { bb2: { _2 = discriminant((_1.2: std::option::Option)); // scope 0 at $DIR/exponential-or.rs:8:37: 8:48 - switchInt(move _2) -> [0isize: bb4, 1isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:37: 8:48 + switchInt(move _2) -> [0_isize: bb4, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:37: 8:48 } bb3: { - switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1i32: bb4, 8i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:42: 8:43 + switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1_i32: bb4, 8_i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:8:42: 8:43 } bb4: { - _5 = Le(const 6u32, (_1.3: u32)); // scope 0 at $DIR/exponential-or.rs:8:62: 8:67 + _5 = Le(const 6_u32, (_1.3: u32)); // scope 0 at $DIR/exponential-or.rs:8:62: 8:67 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000006)) @@ -54,7 +54,7 @@ fn match_tuple(_1: (u32, bool, std::option::Option, u32)) -> u32 { } bb5: { - _6 = Le((_1.3: u32), const 9u32); // scope 0 at $DIR/exponential-or.rs:8:62: 8:67 + _6 = Le((_1.3: u32), const 9_u32); // scope 0 at $DIR/exponential-or.rs:8:62: 8:67 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000009)) @@ -65,7 +65,7 @@ fn match_tuple(_1: (u32, bool, std::option::Option, u32)) -> u32 { } bb6: { - _3 = Le(const 13u32, (_1.3: u32)); // scope 0 at $DIR/exponential-or.rs:8:70: 8:77 + _3 = Le(const 13_u32, (_1.3: u32)); // scope 0 at $DIR/exponential-or.rs:8:70: 8:77 // ty::Const // + ty: u32 // + val: Value(Scalar(0x0000000d)) @@ -76,7 +76,7 @@ fn match_tuple(_1: (u32, bool, std::option::Option, u32)) -> u32 { } bb7: { - _4 = Le((_1.3: u32), const 16u32); // scope 0 at $DIR/exponential-or.rs:8:70: 8:77 + _4 = Le((_1.3: u32), const 16_u32); // scope 0 at $DIR/exponential-or.rs:8:70: 8:77 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000010)) diff --git a/src/test/mir-opt/generator-drop-cleanup/rustc.main-{{closure}}.generator_drop.0.mir b/src/test/mir-opt/generator-drop-cleanup/rustc.main-{{closure}}.generator_drop.0.mir index 3e7083ff62ecd..bd64a31663a69 100644 --- a/src/test/mir-opt/generator-drop-cleanup/rustc.main-{{closure}}.generator_drop.0.mir +++ b/src/test/mir-opt/generator-drop-cleanup/rustc.main-{{closure}}.generator_drop.0.mir @@ -1,5 +1,18 @@ // MIR for `main::{{closure}}#0` 0 generator_drop -// generator_layout = GeneratorLayout { field_tys: [std::string::String], variant_fields: [[], [], [], [_0]], storage_conflicts: BitMatrix { num_rows: 1, num_columns: 1, words: [1], marker: PhantomData } } +/* generator_layout = GeneratorLayout { + field_tys: { + _0: std::string::String, + }, + variant_fields: { + Unresumed(0): [], + Returned (1): [], + Panicked (2): [], + Suspend0 (3): [_0], + }, + storage_conflicts: BitMatrix(1x1) { + (_0, _0), + }, +} */ fn main::{{closure}}#0(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: 13:6 {std::string::String, ()}]) -> () { let mut _0: (); // return place in scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 @@ -21,7 +34,7 @@ fn main::{{closure}}#0(_1: *mut [generator@$DIR/generator-drop-cleanup.rs:10:15: bb0: { _9 = discriminant((*_1)); // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 - switchInt(move _9) -> [0u32: bb7, 3u32: bb11, otherwise: bb12]; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 + switchInt(move _9) -> [0_u32: bb7, 3_u32: bb11, otherwise: bb12]; // scope 0 at $DIR/generator-drop-cleanup.rs:10:15: 13:6 } bb1 (cleanup): { diff --git a/src/test/mir-opt/generator-storage-dead-unwind/rustc.main-{{closure}}.StateTransform.before.mir b/src/test/mir-opt/generator-storage-dead-unwind/rustc.main-{{closure}}.StateTransform.before.mir index 06645860d842d..7dcfda32ca4a2 100644 --- a/src/test/mir-opt/generator-storage-dead-unwind/rustc.main-{{closure}}.StateTransform.before.mir +++ b/src/test/mir-opt/generator-storage-dead-unwind/rustc.main-{{closure}}.StateTransform.before.mir @@ -21,7 +21,7 @@ yields () bb0: { StorageLive(_3); // scope 0 at $DIR/generator-storage-dead-unwind.rs:23:13: 23:14 - _3 = Foo(const 5i32); // scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23 + _3 = Foo(const 5_i32); // scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000005)) @@ -29,7 +29,7 @@ yields () // + span: $DIR/generator-storage-dead-unwind.rs:23:21: 23:22 // + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } StorageLive(_4); // scope 1 at $DIR/generator-storage-dead-unwind.rs:24:13: 24:14 - _4 = Bar(const 6i32); // scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23 + _4 = Bar(const 6_i32); // scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000006)) diff --git a/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir b/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir index c73dea5f8fde6..8776e5919bd8d 100644 --- a/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir +++ b/src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir @@ -1,5 +1,18 @@ // MIR for `main::{{closure}}#0` 0 generator_resume -// generator_layout = GeneratorLayout { field_tys: [HasDrop], variant_fields: [[], [], [], [_0]], storage_conflicts: BitMatrix { num_rows: 1, num_columns: 1, words: [1], marker: PhantomData } } +/* generator_layout = GeneratorLayout { + field_tys: { + _0: HasDrop, + }, + variant_fields: { + Unresumed(0): [], + Returned (1): [], + Panicked (2): [], + Suspend0 (3): [_0], + }, + storage_conflicts: BitMatrix(1x1) { + (_0, _0), + }, +} */ fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}]>, _2: u8) -> std::ops::GeneratorState<(), ()> { debug _x => _10; // in scope 0 at $DIR/generator-tiny.rs:19:17: 19:19 @@ -19,7 +32,7 @@ fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs: bb0: { _11 = discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:19:16: 25:6 {u8, HasDrop, ()}]))); // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6 - switchInt(move _11) -> [0u32: bb1, 3u32: bb5, otherwise: bb6]; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6 + switchInt(move _11) -> [0_u32: bb1, 3_u32: bb5, otherwise: bb6]; // scope 0 at $DIR/generator-tiny.rs:19:16: 25:6 } bb1: { diff --git a/src/test/mir-opt/inline/inline-any-operand/rustc.bar.Inline.after.mir b/src/test/mir-opt/inline/inline-any-operand/rustc.bar.Inline.after.mir index 19748d52ec7e2..c9ff1fe29f5ed 100644 --- a/src/test/mir-opt/inline/inline-any-operand/rustc.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline-any-operand/rustc.bar.Inline.after.mir @@ -25,14 +25,14 @@ fn bar() -> bool { // + literal: Const { ty: fn(i32, i32) -> bool {foo}, val: Value(Scalar()) } StorageLive(_2); // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6 _2 = _1; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:6 - _3 = const 1i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + _3 = const 1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/inline-any-operand.rs:12:7: 12:8 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } - _4 = const -1i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 + _4 = const -1_i32; // scope 1 at $DIR/inline-any-operand.rs:12:5: 12:13 // ty::Const // + ty: i32 // + val: Value(Scalar(0xffffffff)) diff --git a/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff b/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff index 50913de98b506..3b71fbaa5e8a2 100644 --- a/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff +++ b/src/test/mir-opt/inline/inline-into-box-place/32bit/rustc.main.Inline.diff @@ -19,7 +19,7 @@ _2 = Box(std::vec::Vec); // scope 0 at $DIR/inline-into-box-place.rs:8:29: 8:43 - (*_2) = const std::vec::Vec::::new() -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 + _4 = &mut (*_2); // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 -+ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0usize, alloc: std::alloc::Global }; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0_usize, alloc: std::alloc::Global }; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL // ty::Const - // + ty: fn() -> std::vec::Vec {std::vec::Vec::::new} - // + val: Value(Scalar()) @@ -39,7 +39,7 @@ + // + span: $SRC_DIR/liballoc/vec.rs:LL:COL + // + user_ty: UserType(0) + // + literal: Const { ty: alloc::raw_vec::RawVec, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, size: Size { raw: 8 }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) } -+ ((*_4).1: usize) = const 0usize; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).1: usize) = const 0_usize; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff b/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff index 7a1b6460c5bb3..2e7dde39115b7 100644 --- a/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff +++ b/src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff @@ -19,7 +19,7 @@ _2 = Box(std::vec::Vec); // scope 0 at $DIR/inline-into-box-place.rs:8:29: 8:43 - (*_2) = const std::vec::Vec::::new() -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 + _4 = &mut (*_2); // scope 0 at $DIR/inline-into-box-place.rs:8:33: 8:43 -+ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0usize, alloc: std::alloc::Global }; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).0: alloc::raw_vec::RawVec) = const alloc::raw_vec::RawVec:: { ptr: std::ptr::Unique:: { pointer: {0x4 as *const u32}, _marker: std::marker::PhantomData:: }, cap: 0_usize, alloc: std::alloc::Global }; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL // ty::Const - // + ty: fn() -> std::vec::Vec {std::vec::Vec::::new} - // + val: Value(Scalar()) @@ -39,7 +39,7 @@ + // + span: $SRC_DIR/liballoc/vec.rs:LL:COL + // + user_ty: UserType(0) + // + literal: Const { ty: alloc::raw_vec::RawVec, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [65535], len: Size { raw: 16 } }, size: Size { raw: 16 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) } -+ ((*_4).1: usize) = const 0usize; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL ++ ((*_4).1: usize) = const 0_usize; // scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000000)) diff --git a/src/test/mir-opt/inline/inline-specialization/rustc.main.Inline.diff b/src/test/mir-opt/inline/inline-specialization/rustc.main.Inline.diff index a3e0d0a57a7c3..c273c43c4297d 100644 --- a/src/test/mir-opt/inline/inline-specialization/rustc.main.Inline.diff +++ b/src/test/mir-opt/inline/inline-specialization/rustc.main.Inline.diff @@ -13,7 +13,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/inline-specialization.rs:5:9: 5:10 - _1 = const as Foo>::bar() -> bb1; // scope 0 at $DIR/inline-specialization.rs:5:13: 5:38 -+ _1 = const 123u32; // scope 2 at $DIR/inline-specialization.rs:14:31: 14:34 ++ _1 = const 123_u32; // scope 2 at $DIR/inline-specialization.rs:14:31: 14:34 // ty::Const - // + ty: fn() -> u32 { as Foo>::bar} - // + val: Value(Scalar()) diff --git a/src/test/mir-opt/instrument_coverage/rustc.bar.InstrumentCoverage.diff b/src/test/mir-opt/instrument_coverage/rustc.bar.InstrumentCoverage.diff index 1e64379aa0e4b..8a079f0da4b01 100644 --- a/src/test/mir-opt/instrument_coverage/rustc.bar.InstrumentCoverage.diff +++ b/src/test/mir-opt/instrument_coverage/rustc.bar.InstrumentCoverage.diff @@ -7,7 +7,7 @@ bb0: { + StorageLive(_1); // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2 -+ _1 = const std::intrinsics::count_code_region(const 0u32) -> bb2; // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2 ++ _1 = const std::intrinsics::count_code_region(const 0_u32) -> bb2; // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2 + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region} + // + val: Value(Scalar()) diff --git a/src/test/mir-opt/instrument_coverage/rustc.main.InstrumentCoverage.diff b/src/test/mir-opt/instrument_coverage/rustc.main.InstrumentCoverage.diff index 82d21467827eb..3c2ec1dc06b70 100644 --- a/src/test/mir-opt/instrument_coverage/rustc.main.InstrumentCoverage.diff +++ b/src/test/mir-opt/instrument_coverage/rustc.main.InstrumentCoverage.diff @@ -11,7 +11,7 @@ bb0: { - falseUnwind -> [real: bb1, cleanup: bb2]; // scope 0 at $DIR/instrument_coverage.rs:10:5: 14:6 + StorageLive(_4); // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2 -+ _4 = const std::intrinsics::count_code_region(const 0u32) -> bb7; // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2 ++ _4 = const std::intrinsics::count_code_region(const 0_u32) -> bb7; // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2 + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region} + // + val: Value(Scalar()) diff --git a/src/test/mir-opt/issue-41697/32bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir b/src/test/mir-opt/issue-41697/32bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir index d263b2515f17a..403555964ca15 100644 --- a/src/test/mir-opt/issue-41697/32bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir +++ b/src/test/mir-opt/issue-41697/32bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir @@ -5,7 +5,20 @@ let mut _1: (usize, bool); // in scope 0 at $DIR/issue-41697.rs:18:19: 18:22 bb0: { - _1 = CheckedAdd(const 1usize, const 1usize); // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 + _1 = CheckedAdd(const 1_usize, const 1_usize); // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-41697.rs:18:19: 18:20 + // + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) } + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-41697.rs:18:21: 18:22 + // + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) } + assert(!move (_1.1: bool), "attempt to compute `{} + {}` which would overflow", const 1_usize, const 1_usize) -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -18,7 +31,6 @@ // mir::Constant // + span: $DIR/issue-41697.rs:18:21: 18:22 // + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) } - assert(!move (_1.1: bool), "attempt to add with overflow") -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 } bb1 (cleanup): { diff --git a/src/test/mir-opt/issue-41697/64bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir b/src/test/mir-opt/issue-41697/64bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir index 6c00f49fb75b1..df933d3ac251f 100644 --- a/src/test/mir-opt/issue-41697/64bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir +++ b/src/test/mir-opt/issue-41697/64bit/rustc.{{impl}}-{{constant}}.SimplifyCfg-qualify-consts.after.mir @@ -5,7 +5,20 @@ let mut _1: (usize, bool); // in scope 0 at $DIR/issue-41697.rs:18:19: 18:22 bb0: { - _1 = CheckedAdd(const 1usize, const 1usize); // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 + _1 = CheckedAdd(const 1_usize, const 1_usize); // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000001)) + // mir::Constant + // + span: $DIR/issue-41697.rs:18:19: 18:20 + // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) } + // ty::Const + // + ty: usize + // + val: Value(Scalar(0x0000000000000001)) + // mir::Constant + // + span: $DIR/issue-41697.rs:18:21: 18:22 + // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) } + assert(!move (_1.1: bool), "attempt to compute `{} + {}` which would overflow", const 1_usize, const 1_usize) -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -18,7 +31,6 @@ // mir::Constant // + span: $DIR/issue-41697.rs:18:21: 18:22 // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) } - assert(!move (_1.1: bool), "attempt to add with overflow") -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-41697.rs:18:19: 18:22 } bb1 (cleanup): { diff --git a/src/test/mir-opt/issue-41888/rustc.main.ElaborateDrops.after.mir b/src/test/mir-opt/issue-41888/rustc.main.ElaborateDrops.after.mir index ce940273c3ef5..76ad865bcc842 100644 --- a/src/test/mir-opt/issue-41888/rustc.main.ElaborateDrops.after.mir +++ b/src/test/mir-opt/issue-41888/rustc.main.ElaborateDrops.after.mir @@ -96,7 +96,7 @@ fn main() -> () { bb8: { StorageDead(_3); // scope 1 at $DIR/issue-41888.rs:9:19: 9:20 _5 = discriminant(_1); // scope 1 at $DIR/issue-41888.rs:10:16: 10:24 - switchInt(move _5) -> [0isize: bb10, otherwise: bb9]; // scope 1 at $DIR/issue-41888.rs:10:16: 10:24 + switchInt(move _5) -> [0_isize: bb10, otherwise: bb9]; // scope 1 at $DIR/issue-41888.rs:10:16: 10:24 } bb9: { @@ -250,7 +250,7 @@ fn main() -> () { bb20: { _10 = discriminant(_1); // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 - switchInt(move _10) -> [0isize: bb15, otherwise: bb18]; // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 + switchInt(move _10) -> [0_isize: bb15, otherwise: bb18]; // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 } bb21: { @@ -259,7 +259,7 @@ fn main() -> () { bb22 (cleanup): { _11 = discriminant(_1); // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 - switchInt(move _11) -> [0isize: bb17, otherwise: bb19]; // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 + switchInt(move _11) -> [0_isize: bb17, otherwise: bb19]; // scope 0 at $DIR/issue-41888.rs:15:1: 15:2 } bb23 (cleanup): { diff --git a/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir b/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir index 7299a683a9f0b..f65b93a34da65 100644 --- a/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir +++ b/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir @@ -58,7 +58,7 @@ fn main() -> () { } bb7: { - _2 = const 4i32; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 + _2 = const 4_i32; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000004)) diff --git a/src/test/mir-opt/issue-62289/rustc.test.ElaborateDrops.before.mir b/src/test/mir-opt/issue-62289/rustc.test.ElaborateDrops.before.mir index 0b8b03961f2a0..56916d676ed44 100644 --- a/src/test/mir-opt/issue-62289/rustc.test.ElaborateDrops.before.mir +++ b/src/test/mir-opt/issue-62289/rustc.test.ElaborateDrops.before.mir @@ -46,7 +46,7 @@ fn test() -> std::option::Option> { bb2: { StorageDead(_4); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 _5 = discriminant(_3); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 - switchInt(move _5) -> [0isize: bb4, 1isize: bb6, otherwise: bb5]; // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 + switchInt(move _5) -> [0_isize: bb4, 1_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 } bb3 (cleanup): { diff --git a/src/test/mir-opt/issue-72181/32bit/rustc.foo.mir_map.0.mir b/src/test/mir-opt/issue-72181/32bit/rustc.foo.mir_map.0.mir index 776eb61a5264f..9f8810e752cb3 100644 --- a/src/test/mir-opt/issue-72181/32bit/rustc.foo.mir_map.0.mir +++ b/src/test/mir-opt/issue-72181/32bit/rustc.foo.mir_map.0.mir @@ -9,7 +9,7 @@ fn foo(_1: [(Never, u32); 1]) -> u32 { bb0: { StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 - _2 = const 0usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 + _2 = const 0_usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/issue-72181/32bit/rustc.main.mir_map.0.mir b/src/test/mir-opt/issue-72181/32bit/rustc.main.mir_map.0.mir index aa44dcd8eaee3..e3fb5eb193ae9 100644 --- a/src/test/mir-opt/issue-72181/32bit/rustc.main.mir_map.0.mir +++ b/src/test/mir-opt/issue-72181/32bit/rustc.main.mir_map.0.mir @@ -39,7 +39,7 @@ fn main() -> () { StorageDead(_1); // scope 0 at $DIR/issue-72181.rs:24:34: 24:35 StorageLive(_2); // scope 1 at $DIR/issue-72181.rs:26:9: 26:10 StorageLive(_3); // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 - _3 = Foo { a: const 42u64 }; // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 + _3 = Foo { a: const 42_u64 }; // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 // ty::Const // + ty: u64 // + val: Value(Scalar(0x000000000000002a)) @@ -47,7 +47,7 @@ fn main() -> () { // + span: $DIR/issue-72181.rs:26:23: 26:25 // + literal: Const { ty: u64, val: Value(Scalar(0x000000000000002a)) } StorageLive(_4); // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 - _4 = Foo { a: const 10u64 }; // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 + _4 = Foo { a: const 10_u64 }; // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 // ty::Const // + ty: u64 // + val: Value(Scalar(0x000000000000000a)) @@ -60,7 +60,7 @@ fn main() -> () { FakeRead(ForLet, _2); // scope 1 at $DIR/issue-72181.rs:26:9: 26:10 StorageLive(_5); // scope 2 at $DIR/issue-72181.rs:27:13: 27:30 StorageLive(_6); // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 - _6 = const 0usize; // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 + _6 = const 0_usize; // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/issue-72181/64bit/rustc.foo.mir_map.0.mir b/src/test/mir-opt/issue-72181/64bit/rustc.foo.mir_map.0.mir index 639019eaf9ccc..aab8efb415c69 100644 --- a/src/test/mir-opt/issue-72181/64bit/rustc.foo.mir_map.0.mir +++ b/src/test/mir-opt/issue-72181/64bit/rustc.foo.mir_map.0.mir @@ -9,7 +9,7 @@ fn foo(_1: [(Never, u32); 1]) -> u32 { bb0: { StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 - _2 = const 0usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 + _2 = const 0_usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) diff --git a/src/test/mir-opt/issue-72181/64bit/rustc.main.mir_map.0.mir b/src/test/mir-opt/issue-72181/64bit/rustc.main.mir_map.0.mir index 4098e0e295c5d..d9e791b86bc2b 100644 --- a/src/test/mir-opt/issue-72181/64bit/rustc.main.mir_map.0.mir +++ b/src/test/mir-opt/issue-72181/64bit/rustc.main.mir_map.0.mir @@ -39,7 +39,7 @@ fn main() -> () { StorageDead(_1); // scope 0 at $DIR/issue-72181.rs:24:34: 24:35 StorageLive(_2); // scope 1 at $DIR/issue-72181.rs:26:9: 26:10 StorageLive(_3); // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 - _3 = Foo { a: const 42u64 }; // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 + _3 = Foo { a: const 42_u64 }; // scope 1 at $DIR/issue-72181.rs:26:14: 26:27 // ty::Const // + ty: u64 // + val: Value(Scalar(0x000000000000002a)) @@ -47,7 +47,7 @@ fn main() -> () { // + span: $DIR/issue-72181.rs:26:23: 26:25 // + literal: Const { ty: u64, val: Value(Scalar(0x000000000000002a)) } StorageLive(_4); // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 - _4 = Foo { a: const 10u64 }; // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 + _4 = Foo { a: const 10_u64 }; // scope 1 at $DIR/issue-72181.rs:26:29: 26:42 // ty::Const // + ty: u64 // + val: Value(Scalar(0x000000000000000a)) @@ -60,7 +60,7 @@ fn main() -> () { FakeRead(ForLet, _2); // scope 1 at $DIR/issue-72181.rs:26:9: 26:10 StorageLive(_5); // scope 2 at $DIR/issue-72181.rs:27:13: 27:30 StorageLive(_6); // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 - _6 = const 0usize; // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 + _6 = const 0_usize; // scope 4 at $DIR/issue-72181.rs:27:24: 27:25 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) diff --git a/src/test/mir-opt/loop_test/rustc.main.SimplifyCfg-qualify-consts.after.mir b/src/test/mir-opt/loop_test/rustc.main.SimplifyCfg-qualify-consts.after.mir index 7046ebb793466..e699abf421d60 100644 --- a/src/test/mir-opt/loop_test/rustc.main.SimplifyCfg-qualify-consts.after.mir +++ b/src/test/mir-opt/loop_test/rustc.main.SimplifyCfg-qualify-consts.after.mir @@ -67,7 +67,7 @@ fn main() -> () { bb6: { StorageLive(_6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14 - _6 = const 1i32; // scope 0 at $DIR/loop_test.rs:14:17: 14:18 + _6 = const 1_i32; // scope 0 at $DIR/loop_test.rs:14:17: 14:18 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.ElaborateDrops.after.mir b/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.ElaborateDrops.after.mir index 856248e90d495..c6832f21208d4 100644 --- a/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.ElaborateDrops.after.mir +++ b/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.ElaborateDrops.after.mir @@ -54,7 +54,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb5: { - _0 = const 1i32; // scope 1 at $DIR/match-arm-scopes.rs:16:77: 16:78 + _0 = const 1_i32; // scope 1 at $DIR/match-arm-scopes.rs:16:77: 16:78 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -82,7 +82,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb8: { - _0 = const 3i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 + _0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -142,7 +142,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb16: { - _0 = const 3i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 + _0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -181,7 +181,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb20: { - _0 = const 2i32; // scope 2 at $DIR/match-arm-scopes.rs:17:41: 17:42 + _0 = const 2_i32; // scope 2 at $DIR/match-arm-scopes.rs:17:41: 17:42 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.SimplifyCfg-initial.after.mir b/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.SimplifyCfg-initial.after.mir index 1f6b2c982fee0..45f7e91d097c0 100644 --- a/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/match-arm-scopes/rustc.complicated_match.SimplifyCfg-initial.after.mir @@ -67,7 +67,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb8: { - _0 = const 1i32; // scope 1 at $DIR/match-arm-scopes.rs:16:77: 16:78 + _0 = const 1_i32; // scope 1 at $DIR/match-arm-scopes.rs:16:77: 16:78 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -102,7 +102,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb12: { - _0 = const 3i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 + _0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -173,7 +173,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb21: { - _0 = const 3i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 + _0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:16:59: 16:60 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -216,7 +216,7 @@ fn complicated_match(_1: bool, _2: (bool, bool, std::string::String)) -> i32 { } bb25: { - _0 = const 2i32; // scope 2 at $DIR/match-arm-scopes.rs:17:41: 17:42 + _0 = const 2_i32; // scope 2 at $DIR/match-arm-scopes.rs:17:41: 17:42 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir index 3e1dec697b76f..d4a2afe295781 100644 --- a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir @@ -26,7 +26,7 @@ fn full_tested_match() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 - _2 = std::option::Option::::Some(const 42i32); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 + _2 = std::option::Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -35,7 +35,7 @@ fn full_tested_match() -> () { // + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) } FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 - switchInt(move _3) -> [0isize: bb2, 1isize: bb3, otherwise: bb5]; // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 + switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb5]; // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 } bb1 (cleanup): { @@ -43,7 +43,7 @@ fn full_tested_match() -> () { } bb2: { - _1 = (const 3i32, const 3i32); // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 + _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -104,7 +104,7 @@ fn full_tested_match() -> () { _5 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 StorageLive(_8); // scope 2 at $DIR/match_false_edges.rs:16:35: 16:36 _8 = _5; // scope 2 at $DIR/match_false_edges.rs:16:35: 16:36 - _1 = (const 1i32, move _8); // scope 2 at $DIR/match_false_edges.rs:16:31: 16:37 + _1 = (const 1_i32, move _8); // scope 2 at $DIR/match_false_edges.rs:16:31: 16:37 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -128,7 +128,7 @@ fn full_tested_match() -> () { _9 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:17:14: 17:15 StorageLive(_10); // scope 3 at $DIR/match_false_edges.rs:17:24: 17:25 _10 = _9; // scope 3 at $DIR/match_false_edges.rs:17:24: 17:25 - _1 = (const 2i32, move _10); // scope 3 at $DIR/match_false_edges.rs:17:20: 17:26 + _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:17:20: 17:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/match_false_edges/rustc.full_tested_match2.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges/rustc.full_tested_match2.PromoteTemps.before.mir index 4e6dc6e13ff62..f1744a94fdc13 100644 --- a/src/test/mir-opt/match_false_edges/rustc.full_tested_match2.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges/rustc.full_tested_match2.PromoteTemps.before.mir @@ -25,7 +25,7 @@ fn full_tested_match2() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 - _2 = std::option::Option::::Some(const 42i32); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 + _2 = std::option::Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -34,7 +34,7 @@ fn full_tested_match2() -> () { // + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) } FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 - switchInt(move _3) -> [0isize: bb2, 1isize: bb3, otherwise: bb5]; // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 + switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb5]; // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 } bb1 (cleanup): { @@ -54,7 +54,7 @@ fn full_tested_match2() -> () { _9 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:29:14: 29:15 StorageLive(_10); // scope 3 at $DIR/match_false_edges.rs:29:24: 29:25 _10 = _9; // scope 3 at $DIR/match_false_edges.rs:29:24: 29:25 - _1 = (const 2i32, move _10); // scope 3 at $DIR/match_false_edges.rs:29:20: 29:26 + _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:29:20: 29:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) @@ -96,7 +96,7 @@ fn full_tested_match2() -> () { _5 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:27:14: 27:15 StorageLive(_8); // scope 2 at $DIR/match_false_edges.rs:27:35: 27:36 _8 = _5; // scope 2 at $DIR/match_false_edges.rs:27:35: 27:36 - _1 = (const 1i32, move _8); // scope 2 at $DIR/match_false_edges.rs:27:31: 27:37 + _1 = (const 1_i32, move _8); // scope 2 at $DIR/match_false_edges.rs:27:31: 27:37 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -116,7 +116,7 @@ fn full_tested_match2() -> () { } bb10: { - _1 = (const 3i32, const 3i32); // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 + _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) diff --git a/src/test/mir-opt/match_false_edges/rustc.main.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges/rustc.main.PromoteTemps.before.mir index b54058ca73f6f..4ab4c4d341e2f 100644 --- a/src/test/mir-opt/match_false_edges/rustc.main.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges/rustc.main.PromoteTemps.before.mir @@ -36,7 +36,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 - _2 = std::option::Option::::Some(const 1i32); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 + _2 = std::option::Option::::Some(const 1_i32); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -45,7 +45,7 @@ fn main() -> () { // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 _4 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 - switchInt(move _4) -> [1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 + switchInt(move _4) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 } bb1 (cleanup): { @@ -63,7 +63,7 @@ fn main() -> () { bb4: { StorageLive(_14); // scope 0 at $DIR/match_false_edges.rs:39:9: 39:11 _14 = _2; // scope 0 at $DIR/match_false_edges.rs:39:9: 39:11 - _1 = const 4i32; // scope 5 at $DIR/match_false_edges.rs:39:15: 39:16 + _1 = const 4_i32; // scope 5 at $DIR/match_false_edges.rs:39:15: 39:16 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000004)) @@ -102,7 +102,7 @@ fn main() -> () { FakeRead(ForGuardBinding, _7); // scope 0 at $DIR/match_false_edges.rs:36:27: 36:28 StorageLive(_6); // scope 0 at $DIR/match_false_edges.rs:36:14: 36:16 _6 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:36:14: 36:16 - _1 = const 1i32; // scope 2 at $DIR/match_false_edges.rs:36:32: 36:33 + _1 = const 1_i32; // scope 2 at $DIR/match_false_edges.rs:36:32: 36:33 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -123,7 +123,7 @@ fn main() -> () { bb10: { StorageLive(_9); // scope 0 at $DIR/match_false_edges.rs:37:9: 37:11 _9 = _2; // scope 0 at $DIR/match_false_edges.rs:37:9: 37:11 - _1 = const 2i32; // scope 3 at $DIR/match_false_edges.rs:37:15: 37:16 + _1 = const 2_i32; // scope 3 at $DIR/match_false_edges.rs:37:15: 37:16 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) @@ -161,7 +161,7 @@ fn main() -> () { FakeRead(ForGuardBinding, _11); // scope 0 at $DIR/match_false_edges.rs:38:28: 38:29 StorageLive(_10); // scope 0 at $DIR/match_false_edges.rs:38:14: 38:15 _10 = ((_2 as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:38:14: 38:15 - _1 = const 3i32; // scope 4 at $DIR/match_false_edges.rs:38:33: 38:34 + _1 = const 3_i32; // scope 4 at $DIR/match_false_edges.rs:38:33: 38:34 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) diff --git a/src/test/mir-opt/match_test/rustc.main.SimplifyCfg-initial.after.mir b/src/test/mir-opt/match_test/rustc.main.SimplifyCfg-initial.after.mir index 5996496406a9f..ef6c88d8005b3 100644 --- a/src/test/mir-opt/match_test/rustc.main.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/match_test/rustc.main.SimplifyCfg-initial.after.mir @@ -20,7 +20,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/match_test.rs:7:9: 7:10 - _1 = const 3i32; // scope 0 at $DIR/match_test.rs:7:13: 7:14 + _1 = const 3_i32; // scope 0 at $DIR/match_test.rs:7:13: 7:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -39,7 +39,7 @@ fn main() -> () { FakeRead(ForLet, _2); // scope 1 at $DIR/match_test.rs:8:9: 8:10 StorageLive(_3); // scope 2 at $DIR/match_test.rs:12:5: 17:6 FakeRead(ForMatchedPlace, _1); // scope 2 at $DIR/match_test.rs:12:11: 12:12 - _6 = Le(const 0i32, _1); // scope 2 at $DIR/match_test.rs:13:9: 13:14 + _6 = Le(const 0_i32, _1); // scope 2 at $DIR/match_test.rs:13:9: 13:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -50,7 +50,7 @@ fn main() -> () { } bb1: { - _7 = Lt(_1, const 10i32); // scope 2 at $DIR/match_test.rs:13:9: 13:14 + _7 = Lt(_1, const 10_i32); // scope 2 at $DIR/match_test.rs:13:9: 13:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000000a)) @@ -65,7 +65,7 @@ fn main() -> () { } bb3: { - _3 = const 3i32; // scope 2 at $DIR/match_test.rs:16:14: 16:15 + _3 = const 3_i32; // scope 2 at $DIR/match_test.rs:16:14: 16:15 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000003)) @@ -76,7 +76,7 @@ fn main() -> () { } bb4: { - _4 = Le(const 10i32, _1); // scope 2 at $DIR/match_test.rs:14:9: 14:16 + _4 = Le(const 10_i32, _1); // scope 2 at $DIR/match_test.rs:14:9: 14:16 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000000a)) @@ -87,7 +87,7 @@ fn main() -> () { } bb5: { - _5 = Le(_1, const 20i32); // scope 2 at $DIR/match_test.rs:14:9: 14:16 + _5 = Le(_1, const 20_i32); // scope 2 at $DIR/match_test.rs:14:9: 14:16 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000014)) @@ -102,7 +102,7 @@ fn main() -> () { } bb7: { - switchInt(_1) -> [-1i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:15:9: 15:11 + switchInt(_1) -> [-1_i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:15:9: 15:11 } bb8: { @@ -119,7 +119,7 @@ fn main() -> () { bb10: { StorageDead(_9); // scope 2 at $DIR/match_test.rs:13:24: 13:25 FakeRead(ForMatchGuard, _8); // scope 2 at $DIR/match_test.rs:13:18: 13:19 - _3 = const 0i32; // scope 2 at $DIR/match_test.rs:13:23: 13:24 + _3 = const 0_i32; // scope 2 at $DIR/match_test.rs:13:23: 13:24 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -135,7 +135,7 @@ fn main() -> () { } bb12: { - _3 = const 1i32; // scope 2 at $DIR/match_test.rs:14:20: 14:21 + _3 = const 1_i32; // scope 2 at $DIR/match_test.rs:14:20: 14:21 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -146,7 +146,7 @@ fn main() -> () { } bb13: { - _3 = const 2i32; // scope 2 at $DIR/match_test.rs:15:15: 15:16 + _3 = const 2_i32; // scope 2 at $DIR/match_test.rs:15:15: 15:16 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/no-drop-for-inactive-variant/rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/no-drop-for-inactive-variant/rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir index eb6911735a59e..ce987a57d5fc7 100644 --- a/src/test/mir-opt/no-drop-for-inactive-variant/rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/no-drop-for-inactive-variant/rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir @@ -14,7 +14,7 @@ fn unwrap(_1: std::option::Option) -> T { bb0: { _2 = discriminant(_1); // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 - switchInt(move _2) -> [0isize: bb2, 1isize: bb4, otherwise: bb3]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 + switchInt(move _2) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 } bb1 (cleanup): { diff --git a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff index 4511470f3a50f..18fbffb463067 100644 --- a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff +++ b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff @@ -17,8 +17,8 @@ bb0: { - StorageLive(_2); // scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16 -- _2 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 -+ _0 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 +- _2 = [const 0_u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 ++ _0 = [const 0_u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28 // ty::Const // + ty: u8 // + val: Value(Scalar(0x00)) diff --git a/src/test/mir-opt/packed-struct-drop-aligned/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/packed-struct-drop-aligned/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir index 21dab9ab92394..075c7647c671f 100644 --- a/src/test/mir-opt/packed-struct-drop-aligned/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/packed-struct-drop-aligned/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -16,7 +16,7 @@ fn main() -> () { StorageLive(_1); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14 StorageLive(_2); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42 StorageLive(_3); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 - _3 = Droppy(const 0usize); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 + _3 = Droppy(const 0_usize); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) @@ -29,7 +29,7 @@ fn main() -> () { StorageDead(_2); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43 StorageLive(_4); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29 StorageLive(_5); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 - _5 = Droppy(const 0usize); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 + _5 = Droppy(const 0_usize); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/packed-struct-drop-aligned/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/packed-struct-drop-aligned/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir index cf46f74c16df3..99a74b6b24f7f 100644 --- a/src/test/mir-opt/packed-struct-drop-aligned/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/packed-struct-drop-aligned/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -16,7 +16,7 @@ fn main() -> () { StorageLive(_1); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14 StorageLive(_2); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42 StorageLive(_3); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 - _3 = Droppy(const 0usize); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 + _3 = Droppy(const 0_usize); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) @@ -29,7 +29,7 @@ fn main() -> () { StorageDead(_2); // scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43 StorageLive(_4); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29 StorageLive(_5); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 - _5 = Droppy(const 0usize); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 + _5 = Droppy(const 0_usize); // scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) diff --git a/src/test/mir-opt/remove_fake_borrows/rustc.match_guard.CleanupNonCodegenStatements.diff b/src/test/mir-opt/remove_fake_borrows/rustc.match_guard.CleanupNonCodegenStatements.diff index 4e626b1384afc..7fc209778703e 100644 --- a/src/test/mir-opt/remove_fake_borrows/rustc.match_guard.CleanupNonCodegenStatements.diff +++ b/src/test/mir-opt/remove_fake_borrows/rustc.match_guard.CleanupNonCodegenStatements.diff @@ -16,11 +16,11 @@ - FakeRead(ForMatchedPlace, _1); // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 _3 = discriminant(_1); // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 - switchInt(move _3) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 + switchInt(move _3) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 } bb1: { - _0 = const 1i32; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 + _0 = const 1_i32; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -31,7 +31,7 @@ } bb2: { - switchInt((*(*((_1 as Some).0: &&i32)))) -> [0i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:14: 8:15 + switchInt((*(*((_1 as Some).0: &&i32)))) -> [0_i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:14: 8:15 } bb3: { @@ -62,7 +62,7 @@ + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 - _0 = const 0i32; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 + _0 = const 0_i32; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir index c8c5da37abe32..14a7f2d500542 100644 --- a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -56,7 +56,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/retag.rs:30:9: 30:14 - _1 = const 0i32; // scope 0 at $DIR/retag.rs:30:17: 30:18 + _1 = const 0_i32; // scope 0 at $DIR/retag.rs:30:17: 30:18 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -67,7 +67,7 @@ fn main() -> () { StorageLive(_3); // scope 1 at $DIR/retag.rs:32:13: 32:14 StorageLive(_4); // scope 1 at $DIR/retag.rs:32:17: 32:24 StorageLive(_5); // scope 1 at $DIR/retag.rs:32:17: 32:24 - _5 = Test(const 0i32); // scope 1 at $DIR/retag.rs:32:17: 32:24 + _5 = Test(const 0_i32); // scope 1 at $DIR/retag.rs:32:17: 32:24 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -170,7 +170,7 @@ fn main() -> () { StorageLive(_19); // scope 7 at $DIR/retag.rs:47:5: 47:24 StorageLive(_20); // scope 7 at $DIR/retag.rs:47:5: 47:12 StorageLive(_21); // scope 7 at $DIR/retag.rs:47:5: 47:12 - _21 = Test(const 0i32); // scope 7 at $DIR/retag.rs:47:5: 47:12 + _21 = Test(const 0_i32); // scope 7 at $DIR/retag.rs:47:5: 47:12 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/simple-match/32bit/rustc.match_bool.mir_map.0.mir b/src/test/mir-opt/simple-match/32bit/rustc.match_bool.mir_map.0.mir index cc2738b5e50a3..da3191554f0e0 100644 --- a/src/test/mir-opt/simple-match/32bit/rustc.match_bool.mir_map.0.mir +++ b/src/test/mir-opt/simple-match/32bit/rustc.match_bool.mir_map.0.mir @@ -18,7 +18,7 @@ fn match_bool(_1: bool) -> usize { } bb3: { - _0 = const 20usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 + _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x00000014)) @@ -29,7 +29,7 @@ fn match_bool(_1: bool) -> usize { } bb4: { - _0 = const 10usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 + _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000a)) diff --git a/src/test/mir-opt/simple-match/64bit/rustc.match_bool.mir_map.0.mir b/src/test/mir-opt/simple-match/64bit/rustc.match_bool.mir_map.0.mir index 309041abef9be..55b51a899bc50 100644 --- a/src/test/mir-opt/simple-match/64bit/rustc.match_bool.mir_map.0.mir +++ b/src/test/mir-opt/simple-match/64bit/rustc.match_bool.mir_map.0.mir @@ -18,7 +18,7 @@ fn match_bool(_1: bool) -> usize { } bb3: { - _0 = const 20usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 + _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000014)) @@ -29,7 +29,7 @@ fn match_bool(_1: bool) -> usize { } bb4: { - _0 = const 10usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 + _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 // ty::Const // + ty: usize // + val: Value(Scalar(0x000000000000000a)) diff --git a/src/test/mir-opt/simplify-arm-identity/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm-identity/32bit/rustc.main.SimplifyArmIdentity.diff index 94759dca038b1..33a3403cada92 100644 --- a/src/test/mir-opt/simplify-arm-identity/32bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm-identity/32bit/rustc.main.SimplifyArmIdentity.diff @@ -19,7 +19,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/simplify-arm-identity.rs:18:9: 18:10 - ((_1 as Foo).0: u8) = const 0u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 + ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 // ty::Const // + ty: u8 // + val: Value(Scalar(0x00)) @@ -28,7 +28,7 @@ // + literal: Const { ty: u8, val: Value(Scalar(0x00)) } discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 // ty::Const // + ty: isize // + val: Value(Scalar(0x00000000)) @@ -39,7 +39,7 @@ } bb1: { - _2 = const Dst::Foo(0u8); // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 + _2 = const Dst::Foo(0_u8); // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 // ty::Const // + ty: Dst // + val: Value(Scalar(0x00)) diff --git a/src/test/mir-opt/simplify-arm-identity/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm-identity/64bit/rustc.main.SimplifyArmIdentity.diff index ba21f16b685d4..7e4fe1c2dcc4c 100644 --- a/src/test/mir-opt/simplify-arm-identity/64bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm-identity/64bit/rustc.main.SimplifyArmIdentity.diff @@ -19,7 +19,7 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/simplify-arm-identity.rs:18:9: 18:10 - ((_1 as Foo).0: u8) = const 0u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 + ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 // ty::Const // + ty: u8 // + val: Value(Scalar(0x00)) @@ -28,7 +28,7 @@ // + literal: Const { ty: u8, val: Value(Scalar(0x00)) } discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 // ty::Const // + ty: isize // + val: Value(Scalar(0x0000000000000000)) @@ -39,7 +39,7 @@ } bb1: { - _2 = const Dst::Foo(0u8); // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 + _2 = const Dst::Foo(0_u8); // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 // ty::Const // + ty: Dst // + val: Value(Scalar(0x00)) diff --git a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff index 8bb28206964f1..daae94e87f044 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff @@ -13,7 +13,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0isize: bb1, 1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { diff --git a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff index 1226b4feaf41f..15bd5e7c9f0b0 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff @@ -13,7 +13,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0isize: bb1, 1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 } bb1: { diff --git a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff index 5a5d67b36d9a5..37273d1d6517b 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff @@ -18,7 +18,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 } bb1: { diff --git a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff index e82865162615e..f138d637435f8 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff @@ -18,7 +18,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 } bb1: { diff --git a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff index 44f475346e016..b46ca21fb90b3 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff @@ -45,7 +45,7 @@ bb1: { StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - switchInt(move _5) -> [0isize: bb2, 1isize: bb4, otherwise: bb3]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } bb2: { diff --git a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff index c91c55dfb04c4..93412d1a74f8a 100644 --- a/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff @@ -45,7 +45,7 @@ bb1: { StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 - switchInt(move _5) -> [0isize: bb2, 1isize: bb4, otherwise: bb3]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 + switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15 } bb2: { diff --git a/src/test/mir-opt/simplify-locals-fixedpoint/rustc.foo.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-fixedpoint/rustc.foo.SimplifyLocals.diff index f7db14e716526..720296a2c66b0 100644 --- a/src/test/mir-opt/simplify-locals-fixedpoint/rustc.foo.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-fixedpoint/rustc.foo.SimplifyLocals.diff @@ -26,7 +26,7 @@ StorageDead(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 StorageDead(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 _5 = discriminant((_1.0: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 - switchInt(move _5) -> [1isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 + switchInt(move _5) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 } bb1: { @@ -42,7 +42,7 @@ bb2: { _4 = discriminant((_1.1: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 - switchInt(move _4) -> [0isize: bb3, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 + switchInt(move _4) -> [0_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 } bb3: { @@ -51,7 +51,7 @@ StorageLive(_7); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:20 StorageLive(_8); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:13 _8 = _6; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:13 - _7 = Gt(move _8, const 42u8); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:20 + _7 = Gt(move _8, const 42_u8); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:20 // ty::Const // + ty: u8 // + val: Value(Scalar(0x2a)) diff --git a/src/test/mir-opt/simplify-locals-removes-unused-consts/rustc.main.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-consts/rustc.main.SimplifyLocals.diff index 0bd4ba97b3ca0..db06b0392df6c 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-consts/rustc.main.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-consts/rustc.main.SimplifyLocals.diff @@ -98,24 +98,24 @@ - StorageLive(_9); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:34 - StorageLive(_10); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30 - StorageLive(_11); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28 -- _11 = const Temp { x: 40u8 }; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28 +- _11 = const Temp { x: 40_u8 }; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28 + StorageDead(_1); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:14:22: 14:23 + StorageLive(_2); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35 -+ _2 = const use_u8(const 42u8) -> bb2; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35 ++ _2 = const use_u8(const 42_u8) -> bb2; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35 // ty::Const - // + ty: Temp - // + val: Value(Scalar(0x28)) - // mir::Constant - // + span: $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:28 - // + literal: Const { ty: Temp, val: Value(Scalar(0x28)) } -- _10 = const 40u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30 +- _10 = const 40_u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30 - // ty::Const - // + ty: u8 - // + val: Value(Scalar(0x28)) - // mir::Constant - // + span: $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:30 - // + literal: Const { ty: u8, val: Value(Scalar(0x28)) } -- _9 = const 42u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:34 +- _9 = const 42_u8; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:34 - // ty::Const - // + ty: u8 - // + val: Value(Scalar(0x2a)) @@ -123,7 +123,7 @@ - // + span: $DIR/simplify-locals-removes-unused-consts.rs:16:12: 16:34 - // + literal: Const { ty: u8, val: Value(Scalar(0x2a)) } - StorageDead(_10); // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:33: 16:34 -- _8 = const use_u8(const 42u8) -> bb2; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35 +- _8 = const use_u8(const 42_u8) -> bb2; // scope 1 at $DIR/simplify-locals-removes-unused-consts.rs:16:5: 16:35 - // ty::Const // + ty: fn(u8) {use_u8} // + val: Value(Scalar()) diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff index 2f78671763d51..f0b696118e996 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff @@ -15,7 +15,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - switchInt(move _2) -> [0isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 } bb1: { diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff index a97fa98a7b09e..1ac6eb85441f5 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff @@ -15,7 +15,7 @@ bb0: { _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - switchInt(move _2) -> [0isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 } bb1: { diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 97050122ca96e..7f8366309c089 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -46,7 +46,7 @@ _3 = move _4; // scope 6 at $SRC_DIR/libcore/result.rs:LL:COL StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - switchInt(move _5) -> [0isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 } bb1: { diff --git a/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff index 7d3537d094347..aa416049f6613 100644 --- a/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff @@ -26,7 +26,7 @@ bb0: { _3 = discriminant(((*_1).1: std::option::Option>)); // scope 0 at $DIR/simplify_try_if_let.rs:22:13: 22:17 - switchInt(move _3) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try_if_let.rs:22:13: 22:17 + switchInt(move _3) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try_if_let.rs:22:13: 22:17 } bb1: { @@ -62,7 +62,7 @@ bb4: { StorageDead(_6); // scope 1 at $DIR/simplify_try_if_let.rs:26:59: 26:60 _7 = discriminant(_5); // scope 1 at $DIR/simplify_try_if_let.rs:26:24: 26:40 - switchInt(move _7) -> [1isize: bb6, otherwise: bb5]; // scope 1 at $DIR/simplify_try_if_let.rs:26:24: 26:40 + switchInt(move _7) -> [1_isize: bb6, otherwise: bb5]; // scope 1 at $DIR/simplify_try_if_let.rs:26:24: 26:40 } bb5: { diff --git a/src/test/mir-opt/slice-drop-shim/32bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir b/src/test/mir-opt/slice-drop-shim/32bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir index e79dcba13b00b..4a13ddb33b5de 100644 --- a/src/test/mir-opt/slice-drop-shim/32bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir +++ b/src/test/mir-opt/slice-drop-shim/32bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir @@ -31,7 +31,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb3 (cleanup): { _5 = &raw mut (*_1)[_4]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _4 = Add(move _4, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = Add(move _4, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -48,7 +48,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb5: { _7 = &raw mut (*_1)[_4]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _4 = Add(move _4, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = Add(move _4, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -64,7 +64,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { } bb7: { - _4 = const 0usize; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = const 0_usize; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x00000000)) @@ -80,7 +80,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb9 (cleanup): { _11 = _9; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _9 = Offset(move _9, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _9 = Offset(move _9, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -97,7 +97,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb11: { _13 = _9; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _9 = Offset(move _9, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _9 = Offset(move _9, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x00000001)) @@ -126,6 +126,6 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb15: { _2 = SizeOf(std::string::String); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL _3 = Len((*_1)); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - switchInt(move _2) -> [0usize: bb8, otherwise: bb14]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + switchInt(move _2) -> [0_usize: bb8, otherwise: bb14]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL } } diff --git a/src/test/mir-opt/slice-drop-shim/64bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir b/src/test/mir-opt/slice-drop-shim/64bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir index 604a0228f63cf..9968c57c23786 100644 --- a/src/test/mir-opt/slice-drop-shim/64bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir +++ b/src/test/mir-opt/slice-drop-shim/64bit/rustc.ptr-drop_in_place.[std__string__String].AddMovesForPackedDrops.before.mir @@ -31,7 +31,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb3 (cleanup): { _5 = &raw mut (*_1)[_4]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _4 = Add(move _4, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = Add(move _4, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -48,7 +48,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb5: { _7 = &raw mut (*_1)[_4]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _4 = Add(move _4, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = Add(move _4, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -64,7 +64,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { } bb7: { - _4 = const 0usize; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _4 = const 0_usize; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000000)) @@ -80,7 +80,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb9 (cleanup): { _11 = _9; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _9 = Offset(move _9, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _9 = Offset(move _9, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -97,7 +97,7 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb11: { _13 = _9; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - _9 = Offset(move _9, const 1usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + _9 = Offset(move _9, const 1_usize); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL // ty::Const // + ty: usize // + val: Value(Scalar(0x0000000000000001)) @@ -126,6 +126,6 @@ fn std::intrinsics::drop_in_place(_1: *mut [std::string::String]) -> () { bb15: { _2 = SizeOf(std::string::String); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL _3 = Len((*_1)); // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL - switchInt(move _2) -> [0usize: bb8, otherwise: bb14]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL + switchInt(move _2) -> [0_usize: bb8, otherwise: bb14]; // scope 0 at $SRC_DIR/libcore/ptr/mod.rs:LL:COL } } diff --git a/src/test/mir-opt/storage_live_dead_in_statics/rustc.XXX.mir_map.0.mir b/src/test/mir-opt/storage_live_dead_in_statics/rustc.XXX.mir_map.0.mir index 62b7535f2b575..d7f73a22c26fd 100644 --- a/src/test/mir-opt/storage_live_dead_in_statics/rustc.XXX.mir_map.0.mir +++ b/src/test/mir-opt/storage_live_dead_in_statics/rustc.XXX.mir_map.0.mir @@ -59,7 +59,7 @@ static XXX: &Foo = { StorageLive(_5); // scope 0 at $DIR/storage_live_dead_in_statics.rs:7:11: 22:6 StorageLive(_6); // scope 0 at $DIR/storage_live_dead_in_statics.rs:7:12: 22:6 StorageLive(_7); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:9: 8:15 - _7 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:9: 8:15 + _7 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:9: 8:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -73,7 +73,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:8:13: 8:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_8); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:17: 8:23 - _8 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:17: 8:23 + _8 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:17: 8:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -87,7 +87,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:8:21: 8:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_9); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:25: 8:31 - _9 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:25: 8:31 + _9 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:8:25: 8:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -101,7 +101,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:8:29: 8:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_10); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:9: 9:15 - _10 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:9: 9:15 + _10 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:9: 9:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -115,7 +115,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:9:13: 9:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_11); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:17: 9:23 - _11 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:17: 9:23 + _11 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:17: 9:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -129,7 +129,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:9:21: 9:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_12); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:25: 9:31 - _12 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:25: 9:31 + _12 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:9:25: 9:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -143,7 +143,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:9:29: 9:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_13); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:9: 10:15 - _13 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:9: 10:15 + _13 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:9: 10:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -157,7 +157,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:10:13: 10:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_14); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:17: 10:23 - _14 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:17: 10:23 + _14 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:17: 10:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -171,7 +171,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:10:21: 10:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_15); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:25: 10:31 - _15 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:25: 10:31 + _15 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:10:25: 10:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -185,7 +185,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:10:29: 10:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_16); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:9: 11:15 - _16 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:9: 11:15 + _16 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:9: 11:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -199,7 +199,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:11:13: 11:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_17); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:17: 11:23 - _17 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:17: 11:23 + _17 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:17: 11:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -213,7 +213,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:11:21: 11:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_18); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:25: 11:31 - _18 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:25: 11:31 + _18 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:11:25: 11:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -227,7 +227,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:11:29: 11:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_19); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:9: 12:15 - _19 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:9: 12:15 + _19 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:9: 12:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -241,7 +241,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:12:13: 12:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_20); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:17: 12:23 - _20 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:17: 12:23 + _20 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:17: 12:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -255,7 +255,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:12:21: 12:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_21); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:25: 12:31 - _21 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:25: 12:31 + _21 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:12:25: 12:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -269,7 +269,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:12:29: 12:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_22); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:9: 13:15 - _22 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:9: 13:15 + _22 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:9: 13:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -283,7 +283,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:13:13: 13:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_23); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:17: 13:23 - _23 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:17: 13:23 + _23 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:17: 13:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -297,7 +297,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:13:21: 13:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_24); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:25: 13:31 - _24 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:25: 13:31 + _24 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:13:25: 13:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -311,7 +311,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:13:29: 13:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_25); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:9: 14:15 - _25 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:9: 14:15 + _25 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:9: 14:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -325,7 +325,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:14:13: 14:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_26); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:17: 14:23 - _26 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:17: 14:23 + _26 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:17: 14:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -339,7 +339,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:14:21: 14:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_27); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:25: 14:31 - _27 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:25: 14:31 + _27 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:14:25: 14:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -353,7 +353,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:14:29: 14:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_28); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:9: 15:15 - _28 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:9: 15:15 + _28 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:9: 15:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -367,7 +367,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:15:13: 15:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_29); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:17: 15:23 - _29 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:17: 15:23 + _29 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:17: 15:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -381,7 +381,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:15:21: 15:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_30); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:25: 15:31 - _30 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:25: 15:31 + _30 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:15:25: 15:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -395,7 +395,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:15:29: 15:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_31); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:9: 16:15 - _31 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:9: 16:15 + _31 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:9: 16:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -409,7 +409,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:16:13: 16:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:17: 16:23 - _32 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:17: 16:23 + _32 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:17: 16:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -423,7 +423,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:16:21: 16:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_33); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:25: 16:31 - _33 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:25: 16:31 + _33 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:16:25: 16:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -437,7 +437,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:16:29: 16:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_34); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:9: 17:15 - _34 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:9: 17:15 + _34 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:9: 17:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -451,7 +451,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:17:13: 17:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_35); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:17: 17:23 - _35 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:17: 17:23 + _35 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:17: 17:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -465,7 +465,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:17:21: 17:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_36); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:25: 17:31 - _36 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:25: 17:31 + _36 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:17:25: 17:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -479,7 +479,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:17:29: 17:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_37); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:9: 18:15 - _37 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:9: 18:15 + _37 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:9: 18:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -493,7 +493,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:18:13: 18:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_38); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:17: 18:23 - _38 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:17: 18:23 + _38 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:17: 18:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -507,7 +507,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:18:21: 18:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_39); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:25: 18:31 - _39 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:25: 18:31 + _39 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:18:25: 18:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -521,7 +521,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:18:29: 18:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_40); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:9: 19:15 - _40 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:9: 19:15 + _40 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:9: 19:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -535,7 +535,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:19:13: 19:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_41); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:17: 19:23 - _41 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:17: 19:23 + _41 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:17: 19:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -549,7 +549,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:19:21: 19:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_42); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:25: 19:31 - _42 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:25: 19:31 + _42 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:19:25: 19:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -563,7 +563,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:19:29: 19:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_43); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:9: 20:15 - _43 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:9: 20:15 + _43 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:9: 20:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -577,7 +577,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:20:13: 20:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_44); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:17: 20:23 - _44 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:17: 20:23 + _44 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:17: 20:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -591,7 +591,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:20:21: 20:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_45); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:25: 20:31 - _45 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:25: 20:31 + _45 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:20:25: 20:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -605,7 +605,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:20:29: 20:30 // + literal: Const { ty: u32, val: Value(Scalar(0x00000003)) } StorageLive(_46); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:9: 21:15 - _46 = (const 0u32, const 1u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:9: 21:15 + _46 = (const 0_u32, const 1_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:9: 21:15 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -619,7 +619,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:21:13: 21:14 // + literal: Const { ty: u32, val: Value(Scalar(0x00000001)) } StorageLive(_47); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:17: 21:23 - _47 = (const 0u32, const 2u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:17: 21:23 + _47 = (const 0_u32, const 2_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:17: 21:23 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) @@ -633,7 +633,7 @@ static XXX: &Foo = { // + span: $DIR/storage_live_dead_in_statics.rs:21:21: 21:22 // + literal: Const { ty: u32, val: Value(Scalar(0x00000002)) } StorageLive(_48); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:25: 21:31 - _48 = (const 0u32, const 3u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:25: 21:31 + _48 = (const 0_u32, const 3_u32); // scope 0 at $DIR/storage_live_dead_in_statics.rs:21:25: 21:31 // ty::Const // + ty: u32 // + val: Value(Scalar(0x00000000)) diff --git a/src/test/mir-opt/storage_ranges/rustc.main.nll.0.mir b/src/test/mir-opt/storage_ranges/rustc.main.nll.0.mir index 7799f20d974bc..099535c0ad279 100644 --- a/src/test/mir-opt/storage_ranges/rustc.main.nll.0.mir +++ b/src/test/mir-opt/storage_ranges/rustc.main.nll.0.mir @@ -38,7 +38,7 @@ fn main() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/storage_ranges.rs:4:9: 4:10 - _1 = const 0i32; // scope 0 at $DIR/storage_ranges.rs:4:13: 4:14 + _1 = const 0_i32; // scope 0 at $DIR/storage_ranges.rs:4:13: 4:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000000)) @@ -66,7 +66,7 @@ fn main() -> () { StorageDead(_3); // scope 1 at $DIR/storage_ranges.rs:7:5: 7:6 StorageDead(_2); // scope 1 at $DIR/storage_ranges.rs:7:5: 7:6 StorageLive(_6); // scope 1 at $DIR/storage_ranges.rs:8:9: 8:10 - _6 = const 1i32; // scope 1 at $DIR/storage_ranges.rs:8:13: 8:14 + _6 = const 1_i32; // scope 1 at $DIR/storage_ranges.rs:8:13: 8:14 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) diff --git a/src/test/mir-opt/tls-access/rustc.main.SimplifyCfg-final.after.mir b/src/test/mir-opt/tls-access/rustc.main.SimplifyCfg-final.after.mir index e4798c2e32407..5ceca2d091e30 100644 --- a/src/test/mir-opt/tls-access/rustc.main.SimplifyCfg-final.after.mir +++ b/src/test/mir-opt/tls-access/rustc.main.SimplifyCfg-final.after.mir @@ -18,7 +18,7 @@ fn main() -> () { _1 = &(*_2); // scope 1 at $DIR/tls-access.rs:8:17: 8:21 StorageLive(_3); // scope 2 at $DIR/tls-access.rs:9:9: 9:12 _3 = &/*tls*/ mut FOO; // scope 2 at $DIR/tls-access.rs:9:9: 9:12 - (*_3) = const 42u8; // scope 2 at $DIR/tls-access.rs:9:9: 9:17 + (*_3) = const 42_u8; // scope 2 at $DIR/tls-access.rs:9:9: 9:17 // ty::Const // + ty: u8 // + val: Value(Scalar(0x2a)) diff --git a/src/test/mir-opt/uniform_array_move_out/rustc.move_out_by_subslice.mir_map.0.mir b/src/test/mir-opt/uniform_array_move_out/rustc.move_out_by_subslice.mir_map.0.mir index de29cd61019f1..eb40baa2000f8 100644 --- a/src/test/mir-opt/uniform_array_move_out/rustc.move_out_by_subslice.mir_map.0.mir +++ b/src/test/mir-opt/uniform_array_move_out/rustc.move_out_by_subslice.mir_map.0.mir @@ -20,7 +20,7 @@ fn move_out_by_subslice() -> () { StorageLive(_2); // scope 0 at $DIR/uniform_array_move_out.rs:11:14: 11:19 StorageLive(_3); // scope 0 at $DIR/uniform_array_move_out.rs:11:14: 11:19 _3 = Box(i32); // scope 0 at $DIR/uniform_array_move_out.rs:11:14: 11:19 - (*_3) = const 1i32; // scope 0 at $DIR/uniform_array_move_out.rs:11:18: 11:19 + (*_3) = const 1_i32; // scope 0 at $DIR/uniform_array_move_out.rs:11:18: 11:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -48,7 +48,7 @@ fn move_out_by_subslice() -> () { StorageLive(_4); // scope 0 at $DIR/uniform_array_move_out.rs:11:21: 11:26 StorageLive(_5); // scope 0 at $DIR/uniform_array_move_out.rs:11:21: 11:26 _5 = Box(i32); // scope 0 at $DIR/uniform_array_move_out.rs:11:21: 11:26 - (*_5) = const 2i32; // scope 0 at $DIR/uniform_array_move_out.rs:11:25: 11:26 + (*_5) = const 2_i32; // scope 0 at $DIR/uniform_array_move_out.rs:11:25: 11:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/uniform_array_move_out/rustc.move_out_from_end.mir_map.0.mir b/src/test/mir-opt/uniform_array_move_out/rustc.move_out_from_end.mir_map.0.mir index aeab0e892ae8b..7beceb66577fe 100644 --- a/src/test/mir-opt/uniform_array_move_out/rustc.move_out_from_end.mir_map.0.mir +++ b/src/test/mir-opt/uniform_array_move_out/rustc.move_out_from_end.mir_map.0.mir @@ -20,7 +20,7 @@ fn move_out_from_end() -> () { StorageLive(_2); // scope 0 at $DIR/uniform_array_move_out.rs:5:14: 5:19 StorageLive(_3); // scope 0 at $DIR/uniform_array_move_out.rs:5:14: 5:19 _3 = Box(i32); // scope 0 at $DIR/uniform_array_move_out.rs:5:14: 5:19 - (*_3) = const 1i32; // scope 0 at $DIR/uniform_array_move_out.rs:5:18: 5:19 + (*_3) = const 1_i32; // scope 0 at $DIR/uniform_array_move_out.rs:5:18: 5:19 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) @@ -48,7 +48,7 @@ fn move_out_from_end() -> () { StorageLive(_4); // scope 0 at $DIR/uniform_array_move_out.rs:5:21: 5:26 StorageLive(_5); // scope 0 at $DIR/uniform_array_move_out.rs:5:21: 5:26 _5 = Box(i32); // scope 0 at $DIR/uniform_array_move_out.rs:5:21: 5:26 - (*_5) = const 2i32; // scope 0 at $DIR/uniform_array_move_out.rs:5:25: 5:26 + (*_5) = const 2_i32; // scope 0 at $DIR/uniform_array_move_out.rs:5:25: 5:26 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/uninhabited_enum_branching/rustc.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching/rustc.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index df6c90fc7fb37..4f4fb7defc379 100644 --- a/src/test/mir-opt/uninhabited_enum_branching/rustc.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching/rustc.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -33,7 +33,7 @@ fn main() -> () { StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _7 = Test2::D; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 } bb1: { diff --git a/src/test/mir-opt/uninhabited_enum_branching/rustc.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching/rustc.main.UninhabitedEnumBranching.diff index fa1474aa049de..d262c9432ca83 100644 --- a/src/test/mir-opt/uninhabited_enum_branching/rustc.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching/rustc.main.UninhabitedEnumBranching.diff @@ -18,7 +18,7 @@ StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 _2 = Test1::C; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -- switchInt(move _3) -> [0isize: bb2, 1isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 +- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 } @@ -68,7 +68,7 @@ StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _7 = Test2::D; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 } bb5: { diff --git a/src/test/mir-opt/unreachable/rustc.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable/rustc.main.UnreachablePropagation.diff index ccd9612caddd4..e7abf57880047 100644 --- a/src/test/mir-opt/unreachable/rustc.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable/rustc.main.UnreachablePropagation.diff @@ -30,7 +30,7 @@ bb1: { _2 = discriminant(_1); // scope 0 at $DIR/unreachable.rs:9:12: 9:20 -- switchInt(move _2) -> [1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 +- switchInt(move _2) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 + goto -> bb2; // scope 0 at $DIR/unreachable.rs:9:12: 9:20 } @@ -63,7 +63,7 @@ - } - - bb4: { -- _4 = const 42i32; // scope 2 at $DIR/unreachable.rs:15:13: 15:20 +- _4 = const 42_i32; // scope 2 at $DIR/unreachable.rs:15:13: 15:20 - // ty::Const - // + ty: i32 - // + val: Value(Scalar(0x0000002a)) @@ -81,7 +81,7 @@ - } - - bb5: { -- _4 = const 21i32; // scope 2 at $DIR/unreachable.rs:13:13: 13:20 +- _4 = const 21_i32; // scope 2 at $DIR/unreachable.rs:13:13: 13:20 - // ty::Const - // + ty: i32 - // + val: Value(Scalar(0x00000015)) diff --git a/src/test/mir-opt/unreachable_asm/rustc.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_asm/rustc.main.UnreachablePropagation.diff index 449bea06207d9..50694900024a0 100644 --- a/src/test/mir-opt/unreachable_asm/rustc.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_asm/rustc.main.UnreachablePropagation.diff @@ -33,7 +33,7 @@ bb1: { _2 = discriminant(_1); // scope 0 at $DIR/unreachable_asm.rs:11:12: 11:20 - switchInt(move _2) -> [1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable_asm.rs:11:12: 11:20 + switchInt(move _2) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable_asm.rs:11:12: 11:20 } bb2: { @@ -65,7 +65,7 @@ } bb4: { - _4 = const 42i32; // scope 2 at $DIR/unreachable_asm.rs:17:13: 17:20 + _4 = const 42_i32; // scope 2 at $DIR/unreachable_asm.rs:17:13: 17:20 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -83,7 +83,7 @@ } bb5: { - _4 = const 21i32; // scope 2 at $DIR/unreachable_asm.rs:15:13: 15:20 + _4 = const 21_i32; // scope 2 at $DIR/unreachable_asm.rs:15:13: 15:20 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000015)) diff --git a/src/test/mir-opt/unreachable_asm_2/rustc.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_asm_2/rustc.main.UnreachablePropagation.diff index a152e1dbe892f..9be05aefcf69e 100644 --- a/src/test/mir-opt/unreachable_asm_2/rustc.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_asm_2/rustc.main.UnreachablePropagation.diff @@ -36,7 +36,7 @@ bb1: { _2 = discriminant(_1); // scope 0 at $DIR/unreachable_asm_2.rs:11:12: 11:20 - switchInt(move _2) -> [1isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable_asm_2.rs:11:12: 11:20 + switchInt(move _2) -> [1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/unreachable_asm_2.rs:11:12: 11:20 } bb2: { @@ -78,7 +78,7 @@ // + span: $DIR/unreachable_asm_2.rs:20:13: 20:41 // + literal: Const { ty: (), val: Value(Scalar()) } StorageDead(_8); // scope 2 at $DIR/unreachable_asm_2.rs:20:40: 20:41 - _4 = const 42i32; // scope 2 at $DIR/unreachable_asm_2.rs:21:13: 21:20 + _4 = const 42_i32; // scope 2 at $DIR/unreachable_asm_2.rs:21:13: 21:20 // ty::Const // + ty: i32 // + val: Value(Scalar(0x0000002a)) @@ -107,7 +107,7 @@ // + span: $DIR/unreachable_asm_2.rs:16:13: 16:41 // + literal: Const { ty: (), val: Value(Scalar()) } StorageDead(_7); // scope 2 at $DIR/unreachable_asm_2.rs:16:40: 16:41 - _4 = const 21i32; // scope 2 at $DIR/unreachable_asm_2.rs:17:13: 17:20 + _4 = const 21_i32; // scope 2 at $DIR/unreachable_asm_2.rs:17:13: 17:20 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000015)) diff --git a/src/test/mir-opt/unreachable_diverging/rustc.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_diverging/rustc.main.UnreachablePropagation.diff index ff23baf0b4e9f..e7886f683c07e 100644 --- a/src/test/mir-opt/unreachable_diverging/rustc.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_diverging/rustc.main.UnreachablePropagation.diff @@ -38,7 +38,7 @@ bb1: { _3 = discriminant(_2); // scope 1 at $DIR/unreachable_diverging.rs:14:12: 14:22 - switchInt(move _3) -> [1isize: bb3, otherwise: bb2]; // scope 1 at $DIR/unreachable_diverging.rs:14:12: 14:22 + switchInt(move _3) -> [1_isize: bb3, otherwise: bb2]; // scope 1 at $DIR/unreachable_diverging.rs:14:12: 14:22 } bb2: { diff --git a/src/test/mir-opt/unusual-item-types/32bit/rustc.E-V-{{constant}}.mir_map.0.mir b/src/test/mir-opt/unusual-item-types/32bit/rustc.E-V-{{constant}}.mir_map.0.mir index c800ccb1ae51f..7f0266d658992 100644 --- a/src/test/mir-opt/unusual-item-types/32bit/rustc.E-V-{{constant}}.mir_map.0.mir +++ b/src/test/mir-opt/unusual-item-types/32bit/rustc.E-V-{{constant}}.mir_map.0.mir @@ -4,7 +4,7 @@ E::V::{{constant}}#0: isize = { let mut _0: isize; // return place in scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 bb0: { - _0 = const 5isize; // scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 + _0 = const 5_isize; // scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 // ty::Const // + ty: isize // + val: Value(Scalar(0x00000005)) diff --git a/src/test/mir-opt/unusual-item-types/32bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir b/src/test/mir-opt/unusual-item-types/32bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir index f4a5cc0b3279a..4af856c654eed 100644 --- a/src/test/mir-opt/unusual-item-types/32bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir +++ b/src/test/mir-opt/unusual-item-types/32bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir @@ -4,7 +4,7 @@ const ::ASSOCIATED_CONSTANT: i32 = let mut _0: i32; // return place in scope 0 at $DIR/unusual-item-types.rs:10:32: 10:35 bb0: { - _0 = const 2i32; // scope 0 at $DIR/unusual-item-types.rs:10:38: 10:39 + _0 = const 2_i32; // scope 0 at $DIR/unusual-item-types.rs:10:38: 10:39 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/mir-opt/unusual-item-types/64bit/rustc.E-V-{{constant}}.mir_map.0.mir b/src/test/mir-opt/unusual-item-types/64bit/rustc.E-V-{{constant}}.mir_map.0.mir index e635cd2b01bbd..f2c1e9c97ddfe 100644 --- a/src/test/mir-opt/unusual-item-types/64bit/rustc.E-V-{{constant}}.mir_map.0.mir +++ b/src/test/mir-opt/unusual-item-types/64bit/rustc.E-V-{{constant}}.mir_map.0.mir @@ -4,7 +4,7 @@ E::V::{{constant}}#0: isize = { let mut _0: isize; // return place in scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 bb0: { - _0 = const 5isize; // scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 + _0 = const 5_isize; // scope 0 at $DIR/unusual-item-types.rs:22:9: 22:10 // ty::Const // + ty: isize // + val: Value(Scalar(0x0000000000000005)) diff --git a/src/test/mir-opt/unusual-item-types/64bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir b/src/test/mir-opt/unusual-item-types/64bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir index f4a5cc0b3279a..4af856c654eed 100644 --- a/src/test/mir-opt/unusual-item-types/64bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir +++ b/src/test/mir-opt/unusual-item-types/64bit/rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir @@ -4,7 +4,7 @@ const ::ASSOCIATED_CONSTANT: i32 = let mut _0: i32; // return place in scope 0 at $DIR/unusual-item-types.rs:10:32: 10:35 bb0: { - _0 = const 2i32; // scope 0 at $DIR/unusual-item-types.rs:10:38: 10:39 + _0 = const 2_i32; // scope 0 at $DIR/unusual-item-types.rs:10:38: 10:39 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000002)) diff --git a/src/test/run-make/env-dep-info/Makefile b/src/test/run-make/env-dep-info/Makefile new file mode 100644 index 0000000000000..2be0b4b324b08 --- /dev/null +++ b/src/test/run-make/env-dep-info/Makefile @@ -0,0 +1,8 @@ +-include ../../run-make-fulldeps/tools.mk + +all: + EXISTING_ENV=1 EXISTING_OPT_ENV=1 $(RUSTC) --emit dep-info main.rs + $(CGREP) "# env-dep:EXISTING_ENV=1" < $(TMPDIR)/main.d + $(CGREP) "# env-dep:EXISTING_OPT_ENV=1" < $(TMPDIR)/main.d + $(CGREP) "# env-dep:NONEXISTENT_OPT_ENV" < $(TMPDIR)/main.d + $(CGREP) "# env-dep:ESCAPE\nESCAPE\\" < $(TMPDIR)/main.d diff --git a/src/test/run-make/env-dep-info/main.rs b/src/test/run-make/env-dep-info/main.rs new file mode 100644 index 0000000000000..a25246bac792c --- /dev/null +++ b/src/test/run-make/env-dep-info/main.rs @@ -0,0 +1,6 @@ +fn main() { + env!("EXISTING_ENV"); + option_env!("EXISTING_OPT_ENV"); + option_env!("NONEXISTENT_OPT_ENV"); + option_env!("ESCAPE\nESCAPE\\"); +} diff --git a/src/test/rustdoc-ui/intra-links-private.public.stderr b/src/test/rustdoc-ui/intra-links-private.public.stderr new file mode 100644 index 0000000000000..0a8dafdaf9466 --- /dev/null +++ b/src/test/rustdoc-ui/intra-links-private.public.stderr @@ -0,0 +1,10 @@ +warning: `[DontDocMe]` public documentation for `DocMe` links to a private item + --> $DIR/intra-links-private.rs:6:11 + | +LL | /// docs [DontDocMe] + | ^^^^^^^^^ this item is private + | + = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/rustdoc-ui/intra-links-private.rs b/src/test/rustdoc-ui/intra-links-private.rs new file mode 100644 index 0000000000000..b7906aba5b1a9 --- /dev/null +++ b/src/test/rustdoc-ui/intra-links-private.rs @@ -0,0 +1,10 @@ +// check-pass +// revisions: public private +// [private]compile-flags: --document-private-items +#![cfg_attr(private, deny(intra_doc_resolution_failure))] + +/// docs [DontDocMe] +//[public]~^ WARNING `[DontDocMe]` public documentation for `DocMe` links to a private item +// FIXME: for [private] we should also make sure the link was actually generated +pub struct DocMe; +struct DontDocMe; diff --git a/src/test/rustdoc-ui/reference-link-has-one-warning.rs b/src/test/rustdoc-ui/reference-link-has-one-warning.rs new file mode 100644 index 0000000000000..21cb7eb9040bd --- /dev/null +++ b/src/test/rustdoc-ui/reference-link-has-one-warning.rs @@ -0,0 +1,6 @@ +// ignore-test +// check-pass + +/// docs [label][with#anchor#error] +//~^ WARNING has an issue with the link anchor +pub struct S; diff --git a/src/test/rustdoc-ui/reference-link-has-one-warning.stderr b/src/test/rustdoc-ui/reference-link-has-one-warning.stderr new file mode 100644 index 0000000000000..5bbc62b76dd04 --- /dev/null +++ b/src/test/rustdoc-ui/reference-link-has-one-warning.stderr @@ -0,0 +1,10 @@ +warning: `[with#anchor#error]` has an issue with the link anchor. + --> $DIR/reference-link-has-one-warning.rs:3:18 + | +LL | /// docs [label][with#anchor#error] + | ^^^^^^^^^^^^^^^^^ only one `#` is allowed in a link + | + = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs index 905f958826897..85be89719ec39 100644 --- a/src/test/rustdoc/const-generics/add-impl.rs +++ b/src/test/rustdoc/const-generics/add-impl.rs @@ -1,7 +1,6 @@ // ignore-tidy-linelength #![feature(const_generics)] - #![crate_name = "foo"] use std::ops::Add; @@ -11,7 +10,7 @@ pub struct Simd { inner: T, } -// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]/h3/code' 'impl Add> for Simd' +// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]/h3/code' 'impl Add> for Simd' impl Add for Simd { type Output = Self; diff --git a/src/test/ui/abi/abi-sysv64-register-usage.rs b/src/test/ui/abi/abi-sysv64-register-usage.rs index fcdff59ffa984..32864dba4587e 100644 --- a/src/test/ui/abi/abi-sysv64-register-usage.rs +++ b/src/test/ui/abi/abi-sysv64-register-usage.rs @@ -38,6 +38,7 @@ pub struct LargeStruct(i64, i64, i64, i64, i64, i64, i64, i64); #[cfg(target_arch = "x86_64")] #[inline(never)] +#[allow(improper_ctypes_definitions)] pub extern "sysv64" fn large_struct_by_val(mut foo: LargeStruct) -> LargeStruct { foo.0 *= 1; foo.1 *= 2; diff --git a/src/test/ui/align-with-extern-c-fn.rs b/src/test/ui/align-with-extern-c-fn.rs index 09abe4fbf7e09..f77f40998de01 100644 --- a/src/test/ui/align-with-extern-c-fn.rs +++ b/src/test/ui/align-with-extern-c-fn.rs @@ -10,6 +10,7 @@ #[repr(align(16))] pub struct A(i64); +#[allow(improper_ctypes_definitions)] pub extern "C" fn foo(x: A) {} fn main() { diff --git a/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr b/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr index 4fe8572c2d531..0ad05b3adeb88 100644 --- a/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr +++ b/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/match_arr_unknown_len.rs:6:9 | LL | [1, 2] => true, - | ^^^^^^ expected `2usize`, found `N` + | ^^^^^^ expected `2_usize`, found `N` | = note: expected array `[u32; 2]` found array `[u32; N]` diff --git a/src/test/ui/assoc-lang-items.rs b/src/test/ui/assoc-lang-items.rs new file mode 100644 index 0000000000000..23453d201a72f --- /dev/null +++ b/src/test/ui/assoc-lang-items.rs @@ -0,0 +1,21 @@ +#![feature(lang_items)] + +trait Foo { + #[lang = "dummy_lang_item_1"] //~ ERROR definition + fn foo() {} + + #[lang = "dummy_lang_item_2"] //~ ERROR definition + fn bar(); + + #[lang = "dummy_lang_item_3"] //~ ERROR definition + type MyType; +} + +struct Bar; + +impl Bar { + #[lang = "dummy_lang_item_4"] //~ ERROR definition + fn test() {} +} + +fn main() {} diff --git a/src/test/ui/assoc-lang-items.stderr b/src/test/ui/assoc-lang-items.stderr new file mode 100644 index 0000000000000..040792fb1cd5f --- /dev/null +++ b/src/test/ui/assoc-lang-items.stderr @@ -0,0 +1,27 @@ +error[E0522]: definition of an unknown language item: `dummy_lang_item_1` + --> $DIR/assoc-lang-items.rs:4:5 + | +LL | #[lang = "dummy_lang_item_1"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_1` + +error[E0522]: definition of an unknown language item: `dummy_lang_item_2` + --> $DIR/assoc-lang-items.rs:7:5 + | +LL | #[lang = "dummy_lang_item_2"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_2` + +error[E0522]: definition of an unknown language item: `dummy_lang_item_3` + --> $DIR/assoc-lang-items.rs:10:5 + | +LL | #[lang = "dummy_lang_item_3"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_3` + +error[E0522]: definition of an unknown language item: `dummy_lang_item_4` + --> $DIR/assoc-lang-items.rs:17:5 + | +LL | #[lang = "dummy_lang_item_4"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown language item `dummy_lang_item_4` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0522`. diff --git a/src/test/ui/associated-const/defaults-not-assumed-fail.stderr b/src/test/ui/associated-const/defaults-not-assumed-fail.stderr index fe3721a910922..c1b08010cd5b6 100644 --- a/src/test/ui/associated-const/defaults-not-assumed-fail.stderr +++ b/src/test/ui/associated-const/defaults-not-assumed-fail.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | const B: u8 = Self::A + 1; | --------------^^^^^^^^^^^- | | - | attempt to add with overflow + | attempt to compute `u8::MAX + 1_u8` which would overflow | = note: `#[deny(const_err)]` on by default diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr index 510a13ea5b1be..724823e36405e 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^ attempt to negate i32::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,25 +10,25 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -36,7 +36,7 @@ error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | LL | const DIV_REV: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr index 510a13ea5b1be..724823e36405e 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^ attempt to negate i32::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,25 +10,25 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -36,7 +36,7 @@ error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | LL | const DIV_REV: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr index 510a13ea5b1be..724823e36405e 100644 --- a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr +++ b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22 | LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^ attempt to negate i32::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,25 +10,25 @@ error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35 | LL | const NEG_REV: i32 = T::NEG + (-i32::MIN); - | ^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22 | LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36 | LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1); - | ^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22 | LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -36,7 +36,7 @@ error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35 | LL | const DIV_REV: i32 = T::DIV + (1/0); - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22 diff --git a/src/test/ui/binary-op-on-double-ref.fixed b/src/test/ui/binary-op-on-double-ref.fixed new file mode 100644 index 0000000000000..de9dc19af29be --- /dev/null +++ b/src/test/ui/binary-op-on-double-ref.fixed @@ -0,0 +1,9 @@ +// run-rustfix +fn main() { + let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; + let vr = v.iter().filter(|x| { + *x % 2 == 0 + //~^ ERROR cannot mod `&&{integer}` by `{integer}` + }); + println!("{:?}", vr); +} diff --git a/src/test/ui/binary-op-on-double-ref.rs b/src/test/ui/binary-op-on-double-ref.rs index 67e01b9327db1..2616c560cbefb 100644 --- a/src/test/ui/binary-op-on-double-ref.rs +++ b/src/test/ui/binary-op-on-double-ref.rs @@ -1,3 +1,4 @@ +// run-rustfix fn main() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let vr = v.iter().filter(|x| { diff --git a/src/test/ui/binary-op-on-double-ref.stderr b/src/test/ui/binary-op-on-double-ref.stderr index 6c405333ec681..02b0488488c55 100644 --- a/src/test/ui/binary-op-on-double-ref.stderr +++ b/src/test/ui/binary-op-on-double-ref.stderr @@ -1,12 +1,15 @@ error[E0369]: cannot mod `&&{integer}` by `{integer}` - --> $DIR/binary-op-on-double-ref.rs:4:11 + --> $DIR/binary-op-on-double-ref.rs:5:11 | LL | x % 2 == 0 | - ^ - {integer} | | | &&{integer} | - = help: `%` can be used on '{integer}', you can dereference `x`: `*x` +help: `%` can be used on `{integer}`, you can dereference `x` + | +LL | *x % 2 == 0 + | ^ error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index 422d1605aa46b..604143b4e7efd 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -5,6 +5,10 @@ LL | if let Some(thing) = maybe { | ^^^^^ value moved here, in previous iteration of loop | = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `maybe.0` + | +LL | if let Some(ref thing) = maybe { + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/borrowck/move-in-pattern-mut.rs b/src/test/ui/borrowck/move-in-pattern-mut.rs new file mode 100644 index 0000000000000..175eb3b7a04d1 --- /dev/null +++ b/src/test/ui/borrowck/move-in-pattern-mut.rs @@ -0,0 +1,23 @@ +// Issue #63988 +#[derive(Debug)] +struct S; +fn foo(_: Option) {} + +enum E { + V { + s: S, + } +} +fn bar(_: E) {} + +fn main() { + let s = Some(S); + if let Some(mut x) = s { + x = S; + } + foo(s); //~ ERROR use of moved value: `s` + let mut e = E::V { s: S }; + let E::V { s: mut x } = e; + x = S; + bar(e); //~ ERROR use of moved value: `e` +} diff --git a/src/test/ui/borrowck/move-in-pattern-mut.stderr b/src/test/ui/borrowck/move-in-pattern-mut.stderr new file mode 100644 index 0000000000000..391638444c3bd --- /dev/null +++ b/src/test/ui/borrowck/move-in-pattern-mut.stderr @@ -0,0 +1,33 @@ +error[E0382]: use of moved value: `s` + --> $DIR/move-in-pattern-mut.rs:18:9 + | +LL | if let Some(mut x) = s { + | ----- value moved here +... +LL | foo(s); + | ^ value used here after partial move + | + = note: move occurs because value has type `S`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `s.0` + | +LL | if let Some(ref mut x) = s { + | ^^^ + +error[E0382]: use of moved value: `e` + --> $DIR/move-in-pattern-mut.rs:22:9 + | +LL | let E::V { s: mut x } = e; + | ----- value moved here +LL | x = S; +LL | bar(e); + | ^ value used here after partial move + | + = note: move occurs because value has type `S`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `e.s` + | +LL | let E::V { s: ref mut x } = e; + | ^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/move-in-pattern.fixed b/src/test/ui/borrowck/move-in-pattern.fixed new file mode 100644 index 0000000000000..f55fdcc5f90e8 --- /dev/null +++ b/src/test/ui/borrowck/move-in-pattern.fixed @@ -0,0 +1,24 @@ +// run-rustfix +// Issue #63988 +#[derive(Debug)] +struct S; +fn foo(_: Option) {} + +enum E { + V { + s: S, + } +} +fn bar(_: E) {} + +fn main() { + let s = Some(S); + if let Some(ref x) = s { + let _ = x; + } + foo(s); //~ ERROR use of moved value: `s` + let e = E::V { s: S }; + let E::V { s: ref x } = e; + let _ = x; + bar(e); //~ ERROR use of moved value: `e` +} diff --git a/src/test/ui/borrowck/move-in-pattern.rs b/src/test/ui/borrowck/move-in-pattern.rs new file mode 100644 index 0000000000000..7ad04b9490c25 --- /dev/null +++ b/src/test/ui/borrowck/move-in-pattern.rs @@ -0,0 +1,24 @@ +// run-rustfix +// Issue #63988 +#[derive(Debug)] +struct S; +fn foo(_: Option) {} + +enum E { + V { + s: S, + } +} +fn bar(_: E) {} + +fn main() { + let s = Some(S); + if let Some(x) = s { + let _ = x; + } + foo(s); //~ ERROR use of moved value: `s` + let e = E::V { s: S }; + let E::V { s: x } = e; + let _ = x; + bar(e); //~ ERROR use of moved value: `e` +} diff --git a/src/test/ui/borrowck/move-in-pattern.stderr b/src/test/ui/borrowck/move-in-pattern.stderr new file mode 100644 index 0000000000000..c5cb24455eb61 --- /dev/null +++ b/src/test/ui/borrowck/move-in-pattern.stderr @@ -0,0 +1,33 @@ +error[E0382]: use of moved value: `s` + --> $DIR/move-in-pattern.rs:19:9 + | +LL | if let Some(x) = s { + | - value moved here +... +LL | foo(s); + | ^ value used here after partial move + | + = note: move occurs because value has type `S`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `s.0` + | +LL | if let Some(ref x) = s { + | ^^^ + +error[E0382]: use of moved value: `e` + --> $DIR/move-in-pattern.rs:23:9 + | +LL | let E::V { s: x } = e; + | - value moved here +LL | let _ = x; +LL | bar(e); + | ^ value used here after partial move + | + = note: move occurs because value has type `S`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `e.s` + | +LL | let E::V { s: ref x } = e; + | ^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/mut-borrow-in-loop-2.fixed b/src/test/ui/borrowck/mut-borrow-in-loop-2.fixed new file mode 100644 index 0000000000000..ceeba30a90f29 --- /dev/null +++ b/src/test/ui/borrowck/mut-borrow-in-loop-2.fixed @@ -0,0 +1,35 @@ +// run-rustfix +#![allow(dead_code)] + +struct Events(R); + +struct Other; + +pub trait Trait { + fn handle(value: T) -> Self; +} + +// Blanket impl. (If you comment this out, compiler figures out that it +// is passing an `&mut` to a method that must be expecting an `&mut`, +// and injects an auto-reborrow.) +impl Trait for T where T: From { + fn handle(_: U) -> Self { unimplemented!() } +} + +impl<'a, R> Trait<&'a mut Events> for Other { + fn handle(_: &'a mut Events) -> Self { unimplemented!() } +} + +fn this_compiles<'a, R>(value: &'a mut Events) { + for _ in 0..3 { + Other::handle(&mut *value); + } +} + +fn this_does_not<'a, R>(value: &'a mut Events) { + for _ in 0..3 { + Other::handle(&mut *value); //~ ERROR use of moved value: `value` + } +} + +fn main() {} diff --git a/src/test/ui/borrowck/mut-borrow-in-loop-2.rs b/src/test/ui/borrowck/mut-borrow-in-loop-2.rs new file mode 100644 index 0000000000000..d13fb7e567939 --- /dev/null +++ b/src/test/ui/borrowck/mut-borrow-in-loop-2.rs @@ -0,0 +1,35 @@ +// run-rustfix +#![allow(dead_code)] + +struct Events(R); + +struct Other; + +pub trait Trait { + fn handle(value: T) -> Self; +} + +// Blanket impl. (If you comment this out, compiler figures out that it +// is passing an `&mut` to a method that must be expecting an `&mut`, +// and injects an auto-reborrow.) +impl Trait for T where T: From { + fn handle(_: U) -> Self { unimplemented!() } +} + +impl<'a, R> Trait<&'a mut Events> for Other { + fn handle(_: &'a mut Events) -> Self { unimplemented!() } +} + +fn this_compiles<'a, R>(value: &'a mut Events) { + for _ in 0..3 { + Other::handle(&mut *value); + } +} + +fn this_does_not<'a, R>(value: &'a mut Events) { + for _ in 0..3 { + Other::handle(value); //~ ERROR use of moved value: `value` + } +} + +fn main() {} diff --git a/src/test/ui/borrowck/mut-borrow-in-loop-2.stderr b/src/test/ui/borrowck/mut-borrow-in-loop-2.stderr new file mode 100644 index 0000000000000..fa1b741394acb --- /dev/null +++ b/src/test/ui/borrowck/mut-borrow-in-loop-2.stderr @@ -0,0 +1,17 @@ +error[E0382]: use of moved value: `value` + --> $DIR/mut-borrow-in-loop-2.rs:31:23 + | +LL | fn this_does_not<'a, R>(value: &'a mut Events) { + | ----- move occurs because `value` has type `&mut Events`, which does not implement the `Copy` trait +LL | for _ in 0..3 { +LL | Other::handle(value); + | ^^^^^ value moved here, in previous iteration of loop + | +help: consider creating a fresh reborrow of `value` here + | +LL | Other::handle(&mut *value); + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/chalkify/closure.rs b/src/test/ui/chalkify/closure.rs new file mode 100644 index 0000000000000..81114d491d78e --- /dev/null +++ b/src/test/ui/chalkify/closure.rs @@ -0,0 +1,39 @@ +// check-fail +// compile-flags: -Z chalk + +fn main() -> () { + let t = || {}; + t(); + + let mut a = 0; + let mut b = move || { + a = 1; + }; + b(); + + let mut c = b; + + c(); + b(); + + let mut a = 0; + let mut b = || { + a = 1; + }; + b(); + + let mut c = b; + + c(); + b(); //~ ERROR + + // FIXME(chalk): this doesn't quite work + /* + let b = |c| { + c + }; + + let a = &32; + b(a); + */ +} diff --git a/src/test/ui/chalkify/closure.stderr b/src/test/ui/chalkify/closure.stderr new file mode 100644 index 0000000000000..d5a48a7dc6f95 --- /dev/null +++ b/src/test/ui/chalkify/closure.stderr @@ -0,0 +1,18 @@ +error[E0382]: borrow of moved value: `b` + --> $DIR/closure.rs:28:5 + | +LL | let mut c = b; + | - value moved here +... +LL | b(); + | ^ value borrowed here after move + | +note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `a` out of its environment + --> $DIR/closure.rs:21:9 + | +LL | a = 1; + | ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/chalkify/impl_wf.rs b/src/test/ui/chalkify/impl_wf.rs index fdc94f69bf21a..465eb10241ea2 100644 --- a/src/test/ui/chalkify/impl_wf.rs +++ b/src/test/ui/chalkify/impl_wf.rs @@ -23,15 +23,10 @@ impl Bar for Option { type Item = Option; } -// FIXME(chalk): the ordering of these two errors differs between CI and local -// We need to figure out why its non-deterministic -/* impl Bar for f32 { -//^ ERROR the trait bound `f32: Foo` is not satisfied type Item = f32; - //^ ERROR the trait bound `f32: Foo` is not satisfied + //~^ ERROR the trait bound `f32: Foo` is not satisfied } -*/ trait Baz where U: Foo { } diff --git a/src/test/ui/chalkify/impl_wf.stderr b/src/test/ui/chalkify/impl_wf.stderr index 5293bbaecd389..e5d7615e43e31 100644 --- a/src/test/ui/chalkify/impl_wf.stderr +++ b/src/test/ui/chalkify/impl_wf.stderr @@ -11,7 +11,18 @@ LL | impl Foo for str { } = note: to learn more, visit error[E0277]: the trait bound `f32: Foo` is not satisfied - --> $DIR/impl_wf.rs:40:6 + --> $DIR/impl_wf.rs:27:17 + | +LL | trait Bar { + | --- required by a bound in this +LL | type Item: Foo; + | --- required by this bound in `Bar` +... +LL | type Item = f32; + | ^^^ the trait `Foo` is not implemented for `f32` + +error[E0277]: the trait bound `f32: Foo` is not satisfied + --> $DIR/impl_wf.rs:35:6 | LL | trait Baz where U: Foo { } | --- required by this bound in `Baz` @@ -19,6 +30,6 @@ LL | trait Baz where U: Foo { } LL | impl Baz for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/chalkify/inherent_impl.rs b/src/test/ui/chalkify/inherent_impl.rs index 9dd9eb320ddd3..a2730219fbe2a 100644 --- a/src/test/ui/chalkify/inherent_impl.rs +++ b/src/test/ui/chalkify/inherent_impl.rs @@ -1,7 +1,5 @@ // run-pass // compile-flags: -Z chalk -// FIXME(chalk): remove when uncommented -#![allow(dead_code, unused_variables)] trait Foo { } @@ -11,8 +9,6 @@ struct S { x: T, } -// FIXME(chalk): need late-bound regions on FnDefs -/* fn only_foo(_x: &T) { } impl S { @@ -21,7 +17,6 @@ impl S { only_foo(&self.x) } } -*/ trait Bar { } impl Bar for u32 { } @@ -31,16 +26,10 @@ fn only_bar() { } impl S { // Test that the environment of `dummy_bar` adds up with the environment // of the inherent impl. - // FIXME(chalk): need late-bound regions on FnDefs - /* fn dummy_bar(&self) { only_foo(&self.x); only_bar::(); } - */ - fn dummy_bar() { - only_bar::(); - } } fn main() { @@ -48,10 +37,6 @@ fn main() { x: 5, }; - // FIXME(chalk): need late-bound regions on FnDefs - /* - s.dummy_foo(); s.dummy_bar::(); - */ - S::::dummy_bar::(); + s.dummy_foo(); } diff --git a/src/test/ui/chalkify/recursive_where_clause_on_type.rs b/src/test/ui/chalkify/recursive_where_clause_on_type.rs index 6ee13f5e7a104..87324a5f79bdd 100644 --- a/src/test/ui/chalkify/recursive_where_clause_on_type.rs +++ b/src/test/ui/chalkify/recursive_where_clause_on_type.rs @@ -1,5 +1,5 @@ // FIXME(chalk): should fail, see comments -// check-pass +// check-fail // compile-flags: -Z chalk #![feature(trivial_bounds)] @@ -10,7 +10,6 @@ trait Bar { trait Foo: Bar { } struct S where S: Foo; -//~^ WARN Trait bound S: Foo does not depend on any type or lifetime parameters impl Foo for S { } @@ -26,10 +25,6 @@ fn foo() { fn main() { // For some reason, the error is duplicated... - // FIXME(chalk): this order of this duplicate error seems non-determistic - // and causes test to fail - /* - foo::() // ERROR the type `S` is not well-formed (chalk) - //^ ERROR the type `S` is not well-formed (chalk) - */ + foo::() //~ ERROR the type `S` is not well-formed (chalk) + //~^ ERROR the type `S` is not well-formed (chalk) } diff --git a/src/test/ui/chalkify/recursive_where_clause_on_type.stderr b/src/test/ui/chalkify/recursive_where_clause_on_type.stderr index a5b7ef7fdb2e3..fddd58959278e 100644 --- a/src/test/ui/chalkify/recursive_where_clause_on_type.stderr +++ b/src/test/ui/chalkify/recursive_where_clause_on_type.stderr @@ -1,10 +1,14 @@ -warning: Trait bound S: Foo does not depend on any type or lifetime parameters - --> $DIR/recursive_where_clause_on_type.rs:12:19 +error: the type `S` is not well-formed (chalk) + --> $DIR/recursive_where_clause_on_type.rs:28:11 | -LL | struct S where S: Foo; - | ^^^ +LL | foo::() + | ^ + +error: the type `S` is not well-formed (chalk) + --> $DIR/recursive_where_clause_on_type.rs:28:5 | - = note: `#[warn(trivial_bounds)]` on by default +LL | foo::() + | ^^^^^^^^ -warning: 1 warning emitted +error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr b/src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr index b39a160b52987..ceda31550ff44 100644 --- a/src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr +++ b/src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr @@ -13,9 +13,9 @@ LL | pub fn no_iterator() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::iter::Iterator` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::iter::Iterator` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -33,9 +33,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::iter::DoubleEndedIterator` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::iter::DoubleEndedIterator` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -53,9 +53,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::iter::ExactSizeIterator` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::iter::ExactSizeIterator` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -73,9 +73,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::iter::FusedIterator` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::iter::FusedIterator` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -93,9 +93,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::iter::TrustedLen` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::iter::TrustedLen` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -113,9 +113,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::clone::Clone` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::clone::Clone` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error[E0277]: arrays only have std trait implementations for lengths 0..=32 @@ -133,9 +133,9 @@ 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` + | ------------------------- this returned value is of type `std::array::IntoIter` | - = note: required because of the requirements on the impl of `std::fmt::Debug` for `std::array::IntoIter` + = note: required because of the requirements on the impl of `std::fmt::Debug` for `std::array::IntoIter` = note: the return type of a function must have a statically known size error: aborting due to 14 previous errors diff --git a/src/test/ui/const-generics/different_byref.stderr b/src/test/ui/const-generics/different_byref.stderr index 7eb826b8a36b1..a3f331ee81155 100644 --- a/src/test/ui/const-generics/different_byref.stderr +++ b/src/test/ui/const-generics/different_byref.stderr @@ -11,10 +11,10 @@ error[E0308]: mismatched types --> $DIR/different_byref.rs:8:9 | LL | x = Const::<{ [4] }> {}; - | ^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `4usize` + | ^^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize` | - = note: expected type `[3usize]` - found type `[4usize]` + = note: expected type `[3_usize]` + found type `[4_usize]` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/const-generics/types-mismatch-const-args.stderr b/src/test/ui/const-generics/types-mismatch-const-args.stderr index 53328c2e89bf4..49530c9d240b5 100644 --- a/src/test/ui/const-generics/types-mismatch-const-args.stderr +++ b/src/test/ui/const-generics/types-mismatch-const-args.stderr @@ -11,10 +11,10 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:13:41 | LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2u32`, found `4u32` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2_u32`, found `4_u32` | - = note: expected type `2u32` - found type `4u32` + = note: expected type `2_u32` + found type `4_u32` error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:15:41 diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr index b78ac38d7e7e2..0cb7751819774 100644 --- a/src/test/ui/consts/const-err-early.stderr +++ b/src/test/ui/consts/const-err-early.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | pub const A: i8 = -std::i8::MIN; | ------------------^^^^^^^^^^^^^- | | - | attempt to negate with overflow + | attempt to negate i8::MIN which would overflow | note: the lint level is defined here --> $DIR/const-err-early.rs:1:9 @@ -18,7 +18,7 @@ error: any use of this value will cause an error LL | pub const B: u8 = 200u8 + 200u8; | ------------------^^^^^^^^^^^^^- | | - | attempt to add with overflow + | attempt to compute `200_u8 + 200_u8` which would overflow error: any use of this value will cause an error --> $DIR/const-err-early.rs:5:19 @@ -26,7 +26,7 @@ error: any use of this value will cause an error LL | pub const C: u8 = 200u8 * 4; | ------------------^^^^^^^^^- | | - | attempt to multiply with overflow + | attempt to compute `200_u8 * 4_u8` which would overflow error: any use of this value will cause an error --> $DIR/const-err-early.rs:6:19 @@ -34,7 +34,7 @@ error: any use of this value will cause an error LL | pub const D: u8 = 42u8 - (42u8 + 1); | ------------------^^^^^^^^^^^^^^^^^- | | - | attempt to subtract with overflow + | attempt to compute `42_u8 - 43_u8` which would overflow error: any use of this value will cause an error --> $DIR/const-err-early.rs:7:19 diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr index 65427b8a1b289..4ac4a8754d396 100644 --- a/src/test/ui/consts/const-err-multi.stderr +++ b/src/test/ui/consts/const-err-multi.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | pub const A: i8 = -std::i8::MIN; | ------------------^^^^^^^^^^^^^- | | - | attempt to negate with overflow + | attempt to negate i8::MIN which would overflow | note: the lint level is defined here --> $DIR/const-err-multi.rs:1:9 diff --git a/src/test/ui/consts/const-err2.noopt.stderr b/src/test/ui/consts/const-err2.noopt.stderr index 5aeeec4bd1435..687ffc4c4bf95 100644 --- a/src/test/ui/consts/const-err2.noopt.stderr +++ b/src/test/ui/consts/const-err2.noopt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:19:13 | LL | let a = -std::i8::MIN; - | ^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^ attempt to negate i8::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,31 +10,31 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; - | ^^^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^^^ attempt to negate i128::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:23:13 | LL | let b = 200u8 + 200u8 + 200u8; - | ^^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^^ attempt to compute `200_u8 + 200_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:25:18 | LL | let b_i128 = std::i128::MIN - std::i128::MAX; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i128::MIN - i128::MAX` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:27:13 | LL | let c = 200u8 * 4; - | ^^^^^^^^^ attempt to multiply with overflow + | ^^^^^^^^^ attempt to compute `200_u8 * 4_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:29:13 | LL | let d = 42u8 - (42u8 + 1); - | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^ attempt to compute `42_u8 - 43_u8` which would overflow error: this operation will panic at runtime --> $DIR/const-err2.rs:31:14 diff --git a/src/test/ui/consts/const-err2.opt.stderr b/src/test/ui/consts/const-err2.opt.stderr index 5aeeec4bd1435..687ffc4c4bf95 100644 --- a/src/test/ui/consts/const-err2.opt.stderr +++ b/src/test/ui/consts/const-err2.opt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:19:13 | LL | let a = -std::i8::MIN; - | ^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^ attempt to negate i8::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,31 +10,31 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; - | ^^^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^^^ attempt to negate i128::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:23:13 | LL | let b = 200u8 + 200u8 + 200u8; - | ^^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^^ attempt to compute `200_u8 + 200_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:25:18 | LL | let b_i128 = std::i128::MIN - std::i128::MAX; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i128::MIN - i128::MAX` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:27:13 | LL | let c = 200u8 * 4; - | ^^^^^^^^^ attempt to multiply with overflow + | ^^^^^^^^^ attempt to compute `200_u8 * 4_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:29:13 | LL | let d = 42u8 - (42u8 + 1); - | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^ attempt to compute `42_u8 - 43_u8` which would overflow error: this operation will panic at runtime --> $DIR/const-err2.rs:31:14 diff --git a/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr index 5aeeec4bd1435..687ffc4c4bf95 100644 --- a/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:19:13 | LL | let a = -std::i8::MIN; - | ^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^ attempt to negate i8::MIN which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,31 +10,31 @@ error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; - | ^^^^^^^^^^^^^^^ attempt to negate with overflow + | ^^^^^^^^^^^^^^^ attempt to negate i128::MIN which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:23:13 | LL | let b = 200u8 + 200u8 + 200u8; - | ^^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^^ attempt to compute `200_u8 + 200_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:25:18 | LL | let b_i128 = std::i128::MIN - std::i128::MAX; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i128::MIN - i128::MAX` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:27:13 | LL | let c = 200u8 * 4; - | ^^^^^^^^^ attempt to multiply with overflow + | ^^^^^^^^^ attempt to compute `200_u8 * 4_u8` which would overflow error: this arithmetic operation will overflow --> $DIR/const-err2.rs:29:13 | LL | let d = 42u8 - (42u8 + 1); - | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^^^^^^^^^ attempt to compute `42_u8 - 43_u8` which would overflow error: this operation will panic at runtime --> $DIR/const-err2.rs:31:14 diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.stderr b/src/test/ui/consts/const-eval/conditional_array_execution.stderr index df8efc44c4966..62f339809e431 100644 --- a/src/test/ui/consts/const-eval/conditional_array_execution.stderr +++ b/src/test/ui/consts/const-eval/conditional_array_execution.stderr @@ -4,7 +4,7 @@ warning: any use of this value will cause an error LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize]; | ------------------^^^^^--------------------------- | | - | attempt to subtract with overflow + | attempt to compute `5_u32 - 6_u32` which would overflow | note: the lint level is defined here --> $DIR/conditional_array_execution.rs:3:9 diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr index 2c5b4607aa4d3..dd79cbd7e5ff7 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-3.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/const-eval-overflow-3.rs:20:11 | LL | = [0; (i8::MAX + 1) as usize]; - | ^^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^^ attempt to compute `i8::MAX + 1_i8` which would overflow error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr index fe7db23dc2e99..30c52a82ea364 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow-4.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/const-eval-overflow-4.rs:13:13 | LL | : [u32; (i8::MAX as i8 + 1i8) as usize] - | ^^^^^^^^^^^^^^^^^^^^^ attempt to add with overflow + | ^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i8::MAX + 1_i8` which would overflow error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr index 6f823005572b5..2ad557a71139e 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | / const VALS_I8: (i8,) = LL | | ( LL | | i8::MIN - 1, - | | ^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^ attempt to compute `i8::MIN - 1_i8` which would overflow LL | | ); | |_______- | @@ -20,7 +20,7 @@ error: any use of this value will cause an error LL | / const VALS_I16: (i16,) = LL | | ( LL | | i16::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `i16::MIN - 1_i16` which would overflow LL | | ); | |_______- @@ -30,7 +30,7 @@ error: any use of this value will cause an error LL | / const VALS_I32: (i32,) = LL | | ( LL | | i32::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `i32::MIN - 1_i32` which would overflow LL | | ); | |_______- @@ -40,7 +40,7 @@ error: any use of this value will cause an error LL | / const VALS_I64: (i64,) = LL | | ( LL | | i64::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `i64::MIN - 1_i64` which would overflow LL | | ); | |_______- @@ -50,7 +50,7 @@ error: any use of this value will cause an error LL | / const VALS_U8: (u8,) = LL | | ( LL | | u8::MIN - 1, - | | ^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^ attempt to compute `0_u8 - 1_u8` which would overflow LL | | ); | |_______- @@ -59,7 +59,7 @@ error: any use of this value will cause an error | LL | / const VALS_U16: (u16,) = ( LL | | u16::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `0_u16 - 1_u16` which would overflow LL | | ); | |_______- @@ -68,7 +68,7 @@ error: any use of this value will cause an error | LL | / const VALS_U32: (u32,) = ( LL | | u32::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow LL | | ); | |_______- @@ -78,7 +78,7 @@ error: any use of this value will cause an error LL | / const VALS_U64: (u64,) = LL | | ( LL | | u64::MIN - 1, - | | ^^^^^^^^^^^^ attempt to subtract with overflow + | | ^^^^^^^^^^^^ attempt to compute `0_u64 - 1_u64` which would overflow LL | | ); | |_______- diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr index f9a4e5aa96801..fce616b296c29 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | / const VALS_I8: (i8,) = LL | | ( LL | | i8::MAX + 1, - | | ^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^ attempt to compute `i8::MAX + 1_i8` which would overflow LL | | ); | |_______- | @@ -20,7 +20,7 @@ error: any use of this value will cause an error LL | / const VALS_I16: (i16,) = LL | | ( LL | | i16::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `i16::MAX + 1_i16` which would overflow LL | | ); | |_______- @@ -30,7 +30,7 @@ error: any use of this value will cause an error LL | / const VALS_I32: (i32,) = LL | | ( LL | | i32::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow LL | | ); | |_______- @@ -40,7 +40,7 @@ error: any use of this value will cause an error LL | / const VALS_I64: (i64,) = LL | | ( LL | | i64::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `i64::MAX + 1_i64` which would overflow LL | | ); | |_______- @@ -50,7 +50,7 @@ error: any use of this value will cause an error LL | / const VALS_U8: (u8,) = LL | | ( LL | | u8::MAX + 1, - | | ^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8` which would overflow LL | | ); | |_______- @@ -59,7 +59,7 @@ error: any use of this value will cause an error | LL | / const VALS_U16: (u16,) = ( LL | | u16::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `u16::MAX + 1_u16` which would overflow LL | | ); | |_______- @@ -68,7 +68,7 @@ error: any use of this value will cause an error | LL | / const VALS_U32: (u32,) = ( LL | | u32::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `u32::MAX + 1_u32` which would overflow LL | | ); | |_______- @@ -78,7 +78,7 @@ error: any use of this value will cause an error LL | / const VALS_U64: (u64,) = LL | | ( LL | | u64::MAX + 1, - | | ^^^^^^^^^^^^ attempt to add with overflow + | | ^^^^^^^^^^^^ attempt to compute `u64::MAX + 1_u64` which would overflow LL | | ); | |_______- diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr index 6b90617802629..76201524d32bc 100644 --- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr +++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | / const VALS_I8: (i8,) = LL | | ( LL | | i8::MIN * 2, - | | ^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^ attempt to compute `i8::MIN * 2_i8` which would overflow LL | | ); | |_______- | @@ -20,7 +20,7 @@ error: any use of this value will cause an error LL | / const VALS_I16: (i16,) = LL | | ( LL | | i16::MIN * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `i16::MIN * 2_i16` which would overflow LL | | ); | |_______- @@ -30,7 +30,7 @@ error: any use of this value will cause an error LL | / const VALS_I32: (i32,) = LL | | ( LL | | i32::MIN * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `i32::MIN * 2_i32` which would overflow LL | | ); | |_______- @@ -40,7 +40,7 @@ error: any use of this value will cause an error LL | / const VALS_I64: (i64,) = LL | | ( LL | | i64::MIN * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `i64::MIN * 2_i64` which would overflow LL | | ); | |_______- @@ -50,7 +50,7 @@ error: any use of this value will cause an error LL | / const VALS_U8: (u8,) = LL | | ( LL | | u8::MAX * 2, - | | ^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^ attempt to compute `u8::MAX * 2_u8` which would overflow LL | | ); | |_______- @@ -59,7 +59,7 @@ error: any use of this value will cause an error | LL | / const VALS_U16: (u16,) = ( LL | | u16::MAX * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `u16::MAX * 2_u16` which would overflow LL | | ); | |_______- @@ -68,7 +68,7 @@ error: any use of this value will cause an error | LL | / const VALS_U32: (u32,) = ( LL | | u32::MAX * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `u32::MAX * 2_u32` which would overflow LL | | ); | |_______- @@ -78,7 +78,7 @@ error: any use of this value will cause an error LL | / const VALS_U64: (u64,) = LL | | ( LL | | u64::MAX * 2, - | | ^^^^^^^^^^^^ attempt to multiply with overflow + | | ^^^^^^^^^^^^ attempt to compute `u64::MAX * 2_u64` which would overflow LL | | ); | |_______- diff --git a/src/test/ui/consts/const-eval/issue-43197.stderr b/src/test/ui/consts/const-eval/issue-43197.stderr index 8aaae9fe6a7d1..b3e1f496ae3e3 100644 --- a/src/test/ui/consts/const-eval/issue-43197.stderr +++ b/src/test/ui/consts/const-eval/issue-43197.stderr @@ -4,7 +4,7 @@ warning: any use of this value will cause an error LL | const X: u32 = 0 - 1; | ---------------^^^^^- | | - | attempt to subtract with overflow + | attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/issue-43197.rs:3:9 @@ -18,7 +18,7 @@ warning: any use of this value will cause an error LL | const Y: u32 = foo(0 - 1); | -------------------^^^^^-- | | - | attempt to subtract with overflow + | attempt to compute `0_u32 - 1_u32` which would overflow error[E0080]: evaluation of constant expression failed --> $DIR/issue-43197.rs:14:23 diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr index 2e5167a99a2c6..4be84f8d1843c 100644 --- a/src/test/ui/consts/const-eval/issue-50814.stderr +++ b/src/test/ui/consts/const-eval/issue-50814.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | const MAX: u8 = A::MAX + B::MAX; | ----------------^^^^^^^^^^^^^^^- | | - | attempt to add with overflow + | attempt to compute `u8::MAX + u8::MAX` which would overflow | = note: `#[deny(const_err)]` on by default diff --git a/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr index a545503ce8955..52313205dc80b 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr @@ -2,7 +2,7 @@ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:12:20 | LL | println!("{}", 0u32 - 1); - | ^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 @@ -14,13 +14,13 @@ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:14:14 | LL | let _x = 0u32 - 1; - | ^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:41 @@ -50,13 +50,13 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:20:14 | LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:22:20 | LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:22:20 @@ -74,7 +74,7 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:26:14 | LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: 10 warnings emitted diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr index 4887826178244..b411bb2e7fe20 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr @@ -2,7 +2,7 @@ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:14:14 | LL | let _x = 0u32 - 1; - | ^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 @@ -14,7 +14,7 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:41 @@ -44,13 +44,13 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:20:14 | LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:22:20 | LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:22:20 @@ -68,7 +68,7 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:26:14 | LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: 9 warnings emitted diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr index a545503ce8955..52313205dc80b 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr @@ -2,7 +2,7 @@ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:12:20 | LL | println!("{}", 0u32 - 1); - | ^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 @@ -14,13 +14,13 @@ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:14:14 | LL | let _x = 0u32 - 1; - | ^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^ attempt to compute `0_u32 - 1_u32` which would overflow warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero | note: the lint level is defined here --> $DIR/promoted_errors.rs:9:41 @@ -50,13 +50,13 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:20:14 | LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^ attempt to divide 1_i32 by zero warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:22:20 | LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:22:20 @@ -74,7 +74,7 @@ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:26:14 | LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^^^^^^^^^ attempt to divide 1_u32 by zero warning: 10 warnings emitted diff --git a/src/test/ui/consts/const-eval/pub_const_err.stderr b/src/test/ui/consts/const-eval/pub_const_err.stderr index 1f1dd203a6401..ecdba2f1c506d 100644 --- a/src/test/ui/consts/const-eval/pub_const_err.stderr +++ b/src/test/ui/consts/const-eval/pub_const_err.stderr @@ -4,7 +4,7 @@ warning: any use of this value will cause an error LL | pub const Z: u32 = 0 - 1; | -------------------^^^^^- | | - | attempt to subtract with overflow + | attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/pub_const_err.rs:2:9 diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.stderr b/src/test/ui/consts/const-eval/pub_const_err_bin.stderr index 3ae0a11026f38..b2b65767dc059 100644 --- a/src/test/ui/consts/const-eval/pub_const_err_bin.stderr +++ b/src/test/ui/consts/const-eval/pub_const_err_bin.stderr @@ -4,7 +4,7 @@ warning: any use of this value will cause an error LL | pub const Z: u32 = 0 - 1; | -------------------^^^^^- | | - | attempt to subtract with overflow + | attempt to compute `0_u32 - 1_u32` which would overflow | note: the lint level is defined here --> $DIR/pub_const_err_bin.rs:2:9 diff --git a/src/test/ui/consts/const-eval/shift_overflow.stderr b/src/test/ui/consts/const-eval/shift_overflow.stderr index f4840e9ac96bd..478769ca9ffe1 100644 --- a/src/test/ui/consts/const-eval/shift_overflow.stderr +++ b/src/test/ui/consts/const-eval/shift_overflow.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/shift_overflow.rs:3:9 | LL | X = 1 << ((u32::MAX as u64) + 1), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left by 4294967296_u64 which would overflow error: aborting due to previous error diff --git a/src/test/ui/consts/const-len-underflow-separate-spans.stderr b/src/test/ui/consts/const-len-underflow-separate-spans.stderr index 150d3eb525d5e..eff50587ca341 100644 --- a/src/test/ui/consts/const-len-underflow-separate-spans.stderr +++ b/src/test/ui/consts/const-len-underflow-separate-spans.stderr @@ -4,7 +4,7 @@ error: any use of this value will cause an error LL | const LEN: usize = ONE - TWO; | -------------------^^^^^^^^^- | | - | attempt to subtract with overflow + | attempt to compute `1_usize - 2_usize` which would overflow | = note: `#[deny(const_err)]` on by default diff --git a/src/test/ui/consts/const-len-underflow-subspans.rs b/src/test/ui/consts/const-len-underflow-subspans.rs index 37f6ef1bd9d7e..8ef8ef9625c81 100644 --- a/src/test/ui/consts/const-len-underflow-subspans.rs +++ b/src/test/ui/consts/const-len-underflow-subspans.rs @@ -7,5 +7,5 @@ const TWO: usize = 2; fn main() { let a: [i8; ONE - TWO] = unimplemented!(); //~^ ERROR evaluation of constant value failed - //~| attempt to subtract with overflow + //~| attempt to compute `1_usize - 2_usize` which would overflow } diff --git a/src/test/ui/consts/const-len-underflow-subspans.stderr b/src/test/ui/consts/const-len-underflow-subspans.stderr index 63bce1e2c831f..e52e64b25b6de 100644 --- a/src/test/ui/consts/const-len-underflow-subspans.stderr +++ b/src/test/ui/consts/const-len-underflow-subspans.stderr @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed --> $DIR/const-len-underflow-subspans.rs:8:17 | LL | let a: [i8; ONE - TWO] = unimplemented!(); - | ^^^^^^^^^ attempt to subtract with overflow + | ^^^^^^^^^ attempt to compute `1_usize - 2_usize` which would overflow error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-check.eval1.stderr b/src/test/ui/consts/const-match-check.eval1.stderr index 12ba9cacabf7c..eb6b0774e152c 100644 --- a/src/test/ui/consts/const-match-check.eval1.stderr +++ b/src/test/ui/consts/const-match-check.eval1.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:25:15 | LL | A = { let 0 = 0; 0 }, - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html diff --git a/src/test/ui/consts/const-match-check.eval2.stderr b/src/test/ui/consts/const-match-check.eval2.stderr index 2eed7abdc6570..756426d84a479 100644 --- a/src/test/ui/consts/const-match-check.eval2.stderr +++ b/src/test/ui/consts/const-match-check.eval2.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:31:24 | LL | let x: [i32; { let 0 = 0; 0 }] = []; - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html diff --git a/src/test/ui/consts/const-match-check.matchck.stderr b/src/test/ui/consts/const-match-check.matchck.stderr index 1fa0cb17fe66e..84600bb1b8aad 100644 --- a/src/test/ui/consts/const-match-check.matchck.stderr +++ b/src/test/ui/consts/const-match-check.matchck.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:4:22 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html @@ -12,11 +12,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched LL | const X: i32 = { if let 0 = 0 { /* */ } 0 }; | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:8:23 | LL | static Y: i32 = { let 0 = 0; 0 }; - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html @@ -26,11 +26,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched LL | static Y: i32 = { if let 0 = 0 { /* */ } 0 }; | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:13:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html @@ -40,11 +40,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched LL | const X: i32 = { if let 0 = 0 { /* */ } 0 }; | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered --> $DIR/const-match-check.rs:19:26 | LL | const X: i32 = { let 0 = 0; 0 }; - | ^ patterns `i32::MIN..=-1i32` and `1i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html diff --git a/src/test/ui/consts/const-pattern-irrefutable.rs b/src/test/ui/consts/const-pattern-irrefutable.rs index 65f09eb80098c..2105c12a1680a 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.rs +++ b/src/test/ui/consts/const-pattern-irrefutable.rs @@ -9,8 +9,8 @@ use foo::d; const a: u8 = 2; fn main() { - let a = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX - let c = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX - let d = 4; //~ ERROR refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX + let a = 4; //~ ERROR refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX + let c = 4; //~ ERROR refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX + let d = 4; //~ ERROR refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX fn f() {} // Check that the `NOTE`s still work with an item here (cf. issue #35115). } diff --git a/src/test/ui/consts/const-pattern-irrefutable.stderr b/src/test/ui/consts/const-pattern-irrefutable.stderr index bb2fdec72ba0d..3e3bc1979a2e0 100644 --- a/src/test/ui/consts/const-pattern-irrefutable.stderr +++ b/src/test/ui/consts/const-pattern-irrefutable.stderr @@ -1,4 +1,4 @@ -error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered +error[E0005]: refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered --> $DIR/const-pattern-irrefutable.rs:12:9 | LL | const a: u8 = 2; @@ -12,7 +12,7 @@ LL | let a = 4; | = note: the matched value is of type `u8` -error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered +error[E0005]: refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered --> $DIR/const-pattern-irrefutable.rs:13:9 | LL | pub const b: u8 = 2; @@ -26,7 +26,7 @@ LL | let c = 4; | = note: the matched value is of type `u8` -error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=u8::MAX` not covered +error[E0005]: refutable pattern in local binding: `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered --> $DIR/const-pattern-irrefutable.rs:14:9 | LL | pub const d: u8 = 2; diff --git a/src/test/ui/consts/const-variant-count.rs b/src/test/ui/consts/const-variant-count.rs new file mode 100644 index 0000000000000..455419d2c7f1d --- /dev/null +++ b/src/test/ui/consts/const-variant-count.rs @@ -0,0 +1,47 @@ +// run-pass +#![allow(dead_code)] +#![feature(variant_count)] +#![feature(never_type)] + +use std::mem::variant_count; + +enum Void {} + +enum Foo { + A, + B, + C, +} + +enum Bar { + A, + B, + C, + D(usize), + E { field_1: usize, field_2: Foo }, +} + +struct Baz { + a: u32, + b: *const u8, +} + +const TEST_VOID: usize = variant_count::(); +const TEST_FOO: usize = variant_count::(); +const TEST_BAR: usize = variant_count::(); + +const NO_ICE_STRUCT: usize = variant_count::(); +const NO_ICE_BOOL: usize = variant_count::(); +const NO_ICE_PRIM: usize = variant_count::<*const u8>(); + +fn main() { + assert_eq!(TEST_VOID, 0); + assert_eq!(TEST_FOO, 3); + assert_eq!(TEST_BAR, 5); + assert_eq!(variant_count::(), 0); + assert_eq!(variant_count::(), 3); + assert_eq!(variant_count::(), 5); + assert_eq!(variant_count::>(), 2); + assert_eq!(variant_count::>(), 2); + assert_eq!(variant_count::>(), 2); +} diff --git a/src/test/ui/consts/offset_from_ub.stderr b/src/test/ui/consts/offset_from_ub.stderr index 92ecea5fdacdd..cde2fe3262692 100644 --- a/src/test/ui/consts/offset_from_ub.stderr +++ b/src/test/ui/consts/offset_from_ub.stderr @@ -45,7 +45,7 @@ error: any use of this value will cause an error LL | intrinsics::ptr_offset_from(self, origin) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | exact_div: 1isize cannot be divided by 2isize without remainder + | exact_div: 1_isize cannot be divided by 2_isize without remainder | inside `std::ptr::const_ptr::::offset_from` at $SRC_DIR/libcore/ptr/const_ptr.rs:LL:COL | inside `NOT_MULTIPLE_OF_SIZE` at $DIR/offset_from_ub.rs:31:14 | diff --git a/src/test/ui/error-codes/E0080.rs b/src/test/ui/error-codes/E0080.rs index ac0e7737f43fc..b31cf2ec447e7 100644 --- a/src/test/ui/error-codes/E0080.rs +++ b/src/test/ui/error-codes/E0080.rs @@ -1,6 +1,6 @@ enum Enum { X = (1 << 500), //~ ERROR E0080 - //~| shift left with overflow + //~| attempt to shift left by 500_i32 which would overflow Y = (1 / 0) //~ ERROR E0080 } diff --git a/src/test/ui/error-codes/E0080.stderr b/src/test/ui/error-codes/E0080.stderr index 3113fd2189b4c..3acd15ff6bc9e 100644 --- a/src/test/ui/error-codes/E0080.stderr +++ b/src/test/ui/error-codes/E0080.stderr @@ -2,13 +2,13 @@ error[E0080]: evaluation of constant value failed --> $DIR/E0080.rs:2:9 | LL | X = (1 << 500), - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 500_i32 which would overflow error[E0080]: evaluation of constant value failed --> $DIR/E0080.rs:4:9 | LL | Y = (1 / 0) - | ^^^^^^^ attempt to divide by zero + | ^^^^^^^ attempt to divide 1_isize by zero error: aborting due to 2 previous errors diff --git a/src/test/ui/eval-enum.rs b/src/test/ui/eval-enum.rs index cf49b96143817..4ef06c78069f2 100644 --- a/src/test/ui/eval-enum.rs +++ b/src/test/ui/eval-enum.rs @@ -1,9 +1,9 @@ enum Test { DivZero = 1/0, - //~^ attempt to divide by zero + //~^ attempt to divide 1_isize by zero //~| ERROR evaluation of constant value failed RemZero = 1%0, - //~^ attempt to calculate the remainder with a divisor of zero + //~^ attempt to calculate the remainder of 1_isize with a divisor of zero //~| ERROR evaluation of constant value failed } diff --git a/src/test/ui/eval-enum.stderr b/src/test/ui/eval-enum.stderr index 195eaddb71b37..dd89a2d7c3bfc 100644 --- a/src/test/ui/eval-enum.stderr +++ b/src/test/ui/eval-enum.stderr @@ -2,13 +2,13 @@ error[E0080]: evaluation of constant value failed --> $DIR/eval-enum.rs:2:15 | LL | DivZero = 1/0, - | ^^^ attempt to divide by zero + | ^^^ attempt to divide 1_isize by zero error[E0080]: evaluation of constant value failed --> $DIR/eval-enum.rs:5:15 | LL | RemZero = 1%0, - | ^^^ attempt to calculate the remainder with a divisor of zero + | ^^^ attempt to calculate the remainder of 1_isize with a divisor of zero error: aborting due to 2 previous errors diff --git a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr index e32005e21a8e1..20b689aa5e0af 100644 --- a/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr +++ b/src/test/ui/for/for-loop-refutable-pattern-error-message.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in `for` loop binding: `&i32::MIN..=0i32` and `&2i32..=i32::MAX` not covered +error[E0005]: refutable pattern in `for` loop binding: `&i32::MIN..=0_i32` and `&2_i32..=i32::MAX` not covered --> $DIR/for-loop-refutable-pattern-error-message.rs:2:9 | LL | for &1 in [1].iter() {} - | ^^ patterns `&i32::MIN..=0i32` and `&2i32..=i32::MAX` not covered + | ^^ patterns `&i32::MIN..=0_i32` and `&2_i32..=i32::MAX` not covered | = note: the matched value is of type `&i32` diff --git a/src/test/ui/glob-resolve1.rs b/src/test/ui/glob-resolve1.rs index 63c435cc20641..32660fdb41876 100644 --- a/src/test/ui/glob-resolve1.rs +++ b/src/test/ui/glob-resolve1.rs @@ -29,3 +29,7 @@ fn main() { foo::(); //~ ERROR: cannot find type `C` in this scope foo::(); //~ ERROR: cannot find type `D` in this scope } + +mod other { + pub fn import() {} +} diff --git a/src/test/ui/glob-resolve1.stderr b/src/test/ui/glob-resolve1.stderr index 995da6cc1f975..3c818f3ae48ea 100644 --- a/src/test/ui/glob-resolve1.stderr +++ b/src/test/ui/glob-resolve1.stderr @@ -42,6 +42,11 @@ error[E0425]: cannot find function `import` in this scope | LL | import(); | ^^^^^^ not found in this scope + | +help: consider importing this function + | +LL | use other::import; + | error[E0412]: cannot find type `A` in this scope --> $DIR/glob-resolve1.rs:28:11 diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr index 028bfb89312fc..5744232235dd1 100644 --- a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr @@ -79,20 +79,20 @@ LL | m!(0, ..core::u8::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `254u8..=u8::MAX` not covered +error[E0004]: non-exhaustive patterns: `254_u8..=u8::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:42:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `254u8..=u8::MAX` not covered + | ^ pattern `254_u8..=u8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `0u8` not covered +error[E0004]: non-exhaustive patterns: `0_u8` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:43:12 | LL | m!(0, ALMOST_MIN..); - | ^ pattern `0u8` not covered + | ^ pattern `0_u8` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` @@ -106,20 +106,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `43u8` not covered +error[E0004]: non-exhaustive patterns: `43_u8` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:45:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43u8` not covered + | ^ pattern `43_u8` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `43u8` not covered +error[E0004]: non-exhaustive patterns: `43_u8` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:46:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43u8` not covered + | ^ pattern `43_u8` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` @@ -133,20 +133,20 @@ LL | m!(0, ..core::u16::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` -error[E0004]: non-exhaustive patterns: `65534u16..=u16::MAX` not covered +error[E0004]: non-exhaustive patterns: `65534_u16..=u16::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:55:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `65534u16..=u16::MAX` not covered + | ^ pattern `65534_u16..=u16::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` -error[E0004]: non-exhaustive patterns: `0u16` not covered +error[E0004]: non-exhaustive patterns: `0_u16` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:56:12 | LL | m!(0, ALMOST_MIN..); - | ^ pattern `0u16` not covered + | ^ pattern `0_u16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` @@ -160,20 +160,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` -error[E0004]: non-exhaustive patterns: `43u16` not covered +error[E0004]: non-exhaustive patterns: `43_u16` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:58:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43u16` not covered + | ^ pattern `43_u16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` -error[E0004]: non-exhaustive patterns: `43u16` not covered +error[E0004]: non-exhaustive patterns: `43_u16` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:59:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43u16` not covered + | ^ pattern `43_u16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u16` @@ -187,20 +187,20 @@ LL | m!(0, ..core::u32::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` -error[E0004]: non-exhaustive patterns: `4294967294u32..=u32::MAX` not covered +error[E0004]: non-exhaustive patterns: `4294967294_u32..=u32::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:68:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `4294967294u32..=u32::MAX` not covered + | ^ pattern `4294967294_u32..=u32::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` -error[E0004]: non-exhaustive patterns: `0u32` not covered +error[E0004]: non-exhaustive patterns: `0_u32` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:69:12 | LL | m!(0, ALMOST_MIN..); - | ^ pattern `0u32` not covered + | ^ pattern `0_u32` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` @@ -214,20 +214,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` -error[E0004]: non-exhaustive patterns: `43u32` not covered +error[E0004]: non-exhaustive patterns: `43_u32` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:71:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43u32` not covered + | ^ pattern `43_u32` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` -error[E0004]: non-exhaustive patterns: `43u32` not covered +error[E0004]: non-exhaustive patterns: `43_u32` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:72:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43u32` not covered + | ^ pattern `43_u32` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u32` @@ -241,20 +241,20 @@ LL | m!(0, ..core::u64::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` -error[E0004]: non-exhaustive patterns: `18446744073709551614u64..=u64::MAX` not covered +error[E0004]: non-exhaustive patterns: `18446744073709551614_u64..=u64::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:81:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `18446744073709551614u64..=u64::MAX` not covered + | ^ pattern `18446744073709551614_u64..=u64::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` -error[E0004]: non-exhaustive patterns: `0u64` not covered +error[E0004]: non-exhaustive patterns: `0_u64` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:82:12 | LL | m!(0, ALMOST_MIN..); - | ^ pattern `0u64` not covered + | ^ pattern `0_u64` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` @@ -268,20 +268,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` -error[E0004]: non-exhaustive patterns: `43u64` not covered +error[E0004]: non-exhaustive patterns: `43_u64` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:84:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43u64` not covered + | ^ pattern `43_u64` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` -error[E0004]: non-exhaustive patterns: `43u64` not covered +error[E0004]: non-exhaustive patterns: `43_u64` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:85:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43u64` not covered + | ^ pattern `43_u64` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u64` @@ -295,20 +295,20 @@ LL | m!(0, ..core::u128::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454u128..=u128::MAX` not covered +error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454_u128..=u128::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:94:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `340282366920938463463374607431768211454u128..=u128::MAX` not covered + | ^ pattern `340282366920938463463374607431768211454_u128..=u128::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `0u128` not covered +error[E0004]: non-exhaustive patterns: `0_u128` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:95:12 | LL | m!(0, ALMOST_MIN..); - | ^ pattern `0u128` not covered + | ^ pattern `0_u128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` @@ -322,20 +322,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `43u128` not covered +error[E0004]: non-exhaustive patterns: `43_u128` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:97:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43u128` not covered + | ^ pattern `43_u128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `43u128` not covered +error[E0004]: non-exhaustive patterns: `43_u128` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:98:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43u128` not covered + | ^ pattern `43_u128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` @@ -349,11 +349,11 @@ LL | m!(0, ..core::i8::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` -error[E0004]: non-exhaustive patterns: `126i8..=i8::MAX` not covered +error[E0004]: non-exhaustive patterns: `126_i8..=i8::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:110:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `126i8..=i8::MAX` not covered + | ^ pattern `126_i8..=i8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` @@ -376,20 +376,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` -error[E0004]: non-exhaustive patterns: `43i8` not covered +error[E0004]: non-exhaustive patterns: `43_i8` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:113:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43i8` not covered + | ^ pattern `43_i8` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` -error[E0004]: non-exhaustive patterns: `43i8` not covered +error[E0004]: non-exhaustive patterns: `43_i8` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:114:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43i8` not covered + | ^ pattern `43_i8` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` @@ -403,11 +403,11 @@ LL | m!(0, ..core::i16::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` -error[E0004]: non-exhaustive patterns: `32766i16..=i16::MAX` not covered +error[E0004]: non-exhaustive patterns: `32766_i16..=i16::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:123:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `32766i16..=i16::MAX` not covered + | ^ pattern `32766_i16..=i16::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` @@ -430,20 +430,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` -error[E0004]: non-exhaustive patterns: `43i16` not covered +error[E0004]: non-exhaustive patterns: `43_i16` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:126:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43i16` not covered + | ^ pattern `43_i16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` -error[E0004]: non-exhaustive patterns: `43i16` not covered +error[E0004]: non-exhaustive patterns: `43_i16` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:127:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43i16` not covered + | ^ pattern `43_i16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` @@ -457,11 +457,11 @@ LL | m!(0, ..core::i32::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` -error[E0004]: non-exhaustive patterns: `2147483646i32..=i32::MAX` not covered +error[E0004]: non-exhaustive patterns: `2147483646_i32..=i32::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:136:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `2147483646i32..=i32::MAX` not covered + | ^ pattern `2147483646_i32..=i32::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` @@ -484,20 +484,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` -error[E0004]: non-exhaustive patterns: `43i32` not covered +error[E0004]: non-exhaustive patterns: `43_i32` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:139:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43i32` not covered + | ^ pattern `43_i32` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` -error[E0004]: non-exhaustive patterns: `43i32` not covered +error[E0004]: non-exhaustive patterns: `43_i32` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:140:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43i32` not covered + | ^ pattern `43_i32` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` @@ -511,11 +511,11 @@ LL | m!(0, ..core::i64::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i64` -error[E0004]: non-exhaustive patterns: `9223372036854775806i64..=i64::MAX` not covered +error[E0004]: non-exhaustive patterns: `9223372036854775806_i64..=i64::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:149:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `9223372036854775806i64..=i64::MAX` not covered + | ^ pattern `9223372036854775806_i64..=i64::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i64` @@ -538,20 +538,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i64` -error[E0004]: non-exhaustive patterns: `43i64` not covered +error[E0004]: non-exhaustive patterns: `43_i64` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:152:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43i64` not covered + | ^ pattern `43_i64` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i64` -error[E0004]: non-exhaustive patterns: `43i64` not covered +error[E0004]: non-exhaustive patterns: `43_i64` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:153:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43i64` not covered + | ^ pattern `43_i64` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i64` @@ -565,11 +565,11 @@ LL | m!(0, ..core::i128::MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i128` -error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726i128..=i128::MAX` not covered +error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726_i128..=i128::MAX` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:162:12 | LL | m!(0, ..ALMOST_MAX); - | ^ pattern `170141183460469231731687303715884105726i128..=i128::MAX` not covered + | ^ pattern `170141183460469231731687303715884105726_i128..=i128::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i128` @@ -592,20 +592,20 @@ LL | m!(0, ..=ALMOST_MAX); = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i128` -error[E0004]: non-exhaustive patterns: `43i128` not covered +error[E0004]: non-exhaustive patterns: `43_i128` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:165:12 | LL | m!(0, ..=VAL | VAL_2..); - | ^ pattern `43i128` not covered + | ^ pattern `43_i128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i128` -error[E0004]: non-exhaustive patterns: `43i128` not covered +error[E0004]: non-exhaustive patterns: `43_i128` not covered --> $DIR/half-open-range-pats-exhaustive-fail.rs:166:12 | LL | m!(0, ..VAL_1 | VAL_2..); - | ^ pattern `43i128` not covered + | ^ pattern `43_i128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i128` diff --git a/src/test/ui/impl-trait/issue-69840.rs b/src/test/ui/impl-trait/issue-69840.rs new file mode 100644 index 0000000000000..b270f88b6886e --- /dev/null +++ b/src/test/ui/impl-trait/issue-69840.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(impl_trait_in_bindings)] +#![allow(incomplete_features)] + +struct A<'a>(&'a ()); + +trait Trait {} + +impl Trait for () {} + +pub fn foo<'a>() { + let _x: impl Trait> = (); +} + +fn main() {} diff --git a/src/test/ui/issues/issue-16441.rs b/src/test/ui/issues/issue-16441.rs index bae3813f9da95..bafa204e06b25 100644 --- a/src/test/ui/issues/issue-16441.rs +++ b/src/test/ui/issues/issue-16441.rs @@ -5,6 +5,7 @@ struct Empty; // This used to cause an ICE +#[allow(improper_ctypes_definitions)] extern "C" fn ice(_a: Empty) {} fn main() { diff --git a/src/test/ui/issues/issue-26997.rs b/src/test/ui/issues/issue-26997.rs index f6d349a38f523..fcabd1d84557c 100644 --- a/src/test/ui/issues/issue-26997.rs +++ b/src/test/ui/issues/issue-26997.rs @@ -6,6 +6,7 @@ pub struct Foo { } impl Foo { + #[allow(improper_ctypes_definitions)] pub extern fn foo_new() -> Foo { Foo { x: 21, y: 33 } } diff --git a/src/test/ui/issues/issue-28600.rs b/src/test/ui/issues/issue-28600.rs index 3bbe4ae29bdd6..297519b9a79e2 100644 --- a/src/test/ui/issues/issue-28600.rs +++ b/src/test/ui/issues/issue-28600.rs @@ -6,6 +6,7 @@ struct Test; impl Test { #[allow(dead_code)] #[allow(unused_variables)] + #[allow(improper_ctypes_definitions)] pub extern fn test(val: &str) { } diff --git a/src/test/ui/issues/issue-35668.stderr b/src/test/ui/issues/issue-35668.stderr index 98e8e6366b99b..600cacc23aef5 100644 --- a/src/test/ui/issues/issue-35668.stderr +++ b/src/test/ui/issues/issue-35668.stderr @@ -5,6 +5,11 @@ LL | a.iter().map(|a| a*a) | -^- &T | | | &T + | +help: consider restricting type parameter `T` + | +LL | fn func<'a, T: std::ops::Mul>(a: &'a [T]) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-38763.rs b/src/test/ui/issues/issue-38763.rs index 6e6de09225f57..a966cf217e165 100644 --- a/src/test/ui/issues/issue-38763.rs +++ b/src/test/ui/issues/issue-38763.rs @@ -5,6 +5,7 @@ pub struct Foo(i128); #[no_mangle] +#[allow(improper_ctypes_definitions)] pub extern "C" fn foo(x: Foo) -> Foo { x } fn main() { diff --git a/src/test/ui/issues/issue-51907.rs b/src/test/ui/issues/issue-51907.rs index 3691fe1911774..52d26d0954af8 100644 --- a/src/test/ui/issues/issue-51907.rs +++ b/src/test/ui/issues/issue-51907.rs @@ -6,7 +6,9 @@ trait Foo { struct Bar; impl Foo for Bar { + #[allow(improper_ctypes_definitions)] extern fn borrow(&self) {} + #[allow(improper_ctypes_definitions)] extern fn take(self: Box) {} } diff --git a/src/test/ui/issues/issue-5239-1.stderr b/src/test/ui/issues/issue-5239-1.stderr index f4f0f17d00199..078a7ef2173bd 100644 --- a/src/test/ui/issues/issue-5239-1.stderr +++ b/src/test/ui/issues/issue-5239-1.stderr @@ -6,10 +6,10 @@ LL | let x = |ref x: isize| { x += 1; }; | | | cannot use `+=` on type `&isize` | -help: `+=` can be used on 'isize', you can dereference `x` +help: `+=` can be used on `isize`, you can dereference `x` | LL | let x = |ref x: isize| { *x += 1; }; - | ^^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-59326.rs b/src/test/ui/issues/issue-59326.rs new file mode 100644 index 0000000000000..c0e8837749eb4 --- /dev/null +++ b/src/test/ui/issues/issue-59326.rs @@ -0,0 +1,26 @@ +// check-pass +trait Service { + type S; +} + +trait Framing { + type F; +} + +impl Framing for () { + type F = (); +} + +trait HttpService: Service {} + +type BoxService = Box>; + +fn build_server BoxService>(_: F) {} + +fn make_server() -> Box> { + unimplemented!() +} + +fn main() { + build_server(|| make_server()) +} diff --git a/src/test/ui/issues/issue-8460-const.noopt.stderr b/src/test/ui/issues/issue-8460-const.noopt.stderr index 3556ec08247b5..eb8d66790ccea 100644 --- a/src/test/ui/issues/issue-8460-const.noopt.stderr +++ b/src/test/ui/issues/issue-8460-const.noopt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:14:36 | LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize` which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,37 +10,37 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 | LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:18:36 | LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:20:36 | LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:22:36 | LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:24:36 | LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:26:36 | LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^ attempt to divide 1_isize by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -48,103 +48,103 @@ error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 | LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ attempt to divide by zero + | ^^^^^^^ attempt to divide 1_i8 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:30:36 | LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i16 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:32:36 | LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:34:36 | LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i64 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:36:36 | LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^ attempt to divide 1_i128 by zero error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:38:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:40:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:42:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:44:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:46:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:48:36 | LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^ attempt to compute the remainder of `i128::MIN % -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:50:36 | LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^^ attempt to calculate the remainder of 1_isize with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:52:36 | LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^ attempt to calculate the remainder of 1_i8 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:54:36 | LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i16 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:56:36 | LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i32 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:58:36 | LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i64 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:60:36 | LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^ attempt to calculate the remainder of 1_i128 with a divisor of zero error: aborting due to 24 previous errors diff --git a/src/test/ui/issues/issue-8460-const.opt.stderr b/src/test/ui/issues/issue-8460-const.opt.stderr index 3556ec08247b5..eb8d66790ccea 100644 --- a/src/test/ui/issues/issue-8460-const.opt.stderr +++ b/src/test/ui/issues/issue-8460-const.opt.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:14:36 | LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize` which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,37 +10,37 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 | LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:18:36 | LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:20:36 | LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:22:36 | LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:24:36 | LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:26:36 | LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^ attempt to divide 1_isize by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -48,103 +48,103 @@ error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 | LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ attempt to divide by zero + | ^^^^^^^ attempt to divide 1_i8 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:30:36 | LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i16 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:32:36 | LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:34:36 | LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i64 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:36:36 | LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^ attempt to divide 1_i128 by zero error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:38:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:40:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:42:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:44:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:46:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:48:36 | LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^ attempt to compute the remainder of `i128::MIN % -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:50:36 | LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^^ attempt to calculate the remainder of 1_isize with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:52:36 | LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^ attempt to calculate the remainder of 1_i8 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:54:36 | LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i16 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:56:36 | LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i32 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:58:36 | LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i64 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:60:36 | LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^ attempt to calculate the remainder of 1_i128 with a divisor of zero error: aborting due to 24 previous errors diff --git a/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr index 3556ec08247b5..eb8d66790ccea 100644 --- a/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr +++ b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:14:36 | LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize` which would overflow | = note: `#[deny(arithmetic_overflow)]` on by default @@ -10,37 +10,37 @@ error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 | LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:18:36 | LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:20:36 | LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:22:36 | LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:24:36 | LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to divide with overflow + | ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:26:36 | LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^^ attempt to divide 1_isize by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -48,103 +48,103 @@ error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 | LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ attempt to divide by zero + | ^^^^^^^ attempt to divide 1_i8 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:30:36 | LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i16 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:32:36 | LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i32 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:34:36 | LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero + | ^^^^^^^^ attempt to divide 1_i64 by zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:36:36 | LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ attempt to divide by zero + | ^^^^^^^^^ attempt to divide 1_i128 by zero error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:38:36 | LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:40:36 | LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:42:36 | LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:44:36 | LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:46:36 | LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64` which would overflow error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:48:36 | LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + | ^^^^^^^^^^^^^^ attempt to compute the remainder of `i128::MIN % -1_i128` which would overflow error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:50:36 | LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^^ attempt to calculate the remainder of 1_isize with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:52:36 | LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^ attempt to calculate the remainder of 1_i8 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:54:36 | LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i16 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:56:36 | LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i32 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:58:36 | LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^ attempt to calculate the remainder of 1_i64 with a divisor of zero error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:60:36 | LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^^^^^ attempt to calculate the remainder of 1_i128 with a divisor of zero error: aborting due to 24 previous errors diff --git a/src/test/ui/lint/lint-ctypes-fn.rs b/src/test/ui/lint/lint-ctypes-fn.rs new file mode 100644 index 0000000000000..67dd7abcf79ef --- /dev/null +++ b/src/test/ui/lint/lint-ctypes-fn.rs @@ -0,0 +1,182 @@ +#![feature(rustc_private)] + +#![allow(private_in_public)] +#![deny(improper_ctypes_definitions)] + +extern crate libc; + +use std::default::Default; +use std::marker::PhantomData; + +trait Mirror { type It: ?Sized; } + +impl Mirror for T { type It = Self; } + +#[repr(C)] +pub struct StructWithProjection(*mut ::It); + +#[repr(C)] +pub struct StructWithProjectionAndLifetime<'a>( + &'a mut as Mirror>::It +); + +pub type I32Pair = (i32, i32); + +#[repr(C)] +pub struct ZeroSize; + +pub type RustFn = fn(); + +pub type RustBadRet = extern fn() -> Box; + +pub type CVoidRet = (); + +pub struct Foo; + +#[repr(transparent)] +pub struct TransparentI128(i128); + +#[repr(transparent)] +pub struct TransparentStr(&'static str); + +#[repr(transparent)] +pub struct TransparentBadFn(RustBadRet); + +#[repr(transparent)] +pub struct TransparentInt(u32); + +#[repr(transparent)] +pub struct TransparentRef<'a>(&'a TransparentInt); + +#[repr(transparent)] +pub struct TransparentLifetime<'a>(*const u8, PhantomData<&'a ()>); + +#[repr(transparent)] +pub struct TransparentUnit(f32, PhantomData); + +#[repr(transparent)] +pub struct TransparentCustomZst(i32, ZeroSize); + +#[repr(C)] +pub struct ZeroSizeWithPhantomData(PhantomData); + +pub extern "C" fn ptr_type1(size: *const Foo) { } + +pub extern "C" fn ptr_type2(size: *const Foo) { } + +pub extern "C" fn slice_type(p: &[u32]) { } +//~^ ERROR: uses type `[u32]` + +pub extern "C" fn str_type(p: &str) { } +//~^ ERROR: uses type `str` + +pub extern "C" fn box_type(p: Box) { } +//~^ ERROR uses type `std::boxed::Box` + +pub extern "C" fn char_type(p: char) { } +//~^ ERROR uses type `char` + +pub extern "C" fn i128_type(p: i128) { } +//~^ ERROR uses type `i128` + +pub extern "C" fn u128_type(p: u128) { } +//~^ ERROR uses type `u128` + +pub extern "C" fn tuple_type(p: (i32, i32)) { } +//~^ ERROR uses type `(i32, i32)` + +pub extern "C" fn tuple_type2(p: I32Pair) { } +//~^ ERROR uses type `(i32, i32)` + +pub extern "C" fn zero_size(p: ZeroSize) { } +//~^ ERROR uses type `ZeroSize` + +pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { } +//~^ ERROR uses type `ZeroSizeWithPhantomData` + +pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData { +//~^ ERROR uses type `std::marker::PhantomData` + Default::default() +} + +pub extern "C" fn fn_type(p: RustFn) { } +//~^ ERROR uses type `fn()` + +pub extern "C" fn fn_type2(p: fn()) { } +//~^ ERROR uses type `fn()` + +pub extern "C" fn fn_contained(p: RustBadRet) { } +//~^ ERROR: uses type `std::boxed::Box` + +pub extern "C" fn transparent_i128(p: TransparentI128) { } +//~^ ERROR: uses type `i128` + +pub extern "C" fn transparent_str(p: TransparentStr) { } +//~^ ERROR: uses type `str` + +pub extern "C" fn transparent_fn(p: TransparentBadFn) { } +//~^ ERROR: uses type `std::boxed::Box` + +pub extern "C" fn good3(fptr: Option) { } + +pub extern "C" fn good4(aptr: &[u8; 4 as usize]) { } + +pub extern "C" fn good5(s: StructWithProjection) { } + +pub extern "C" fn good6(s: StructWithProjectionAndLifetime) { } + +pub extern "C" fn good7(fptr: extern fn() -> ()) { } + +pub extern "C" fn good8(fptr: extern fn() -> !) { } + +pub extern "C" fn good9() -> () { } + +pub extern "C" fn good10() -> CVoidRet { } + +pub extern "C" fn good11(size: isize) { } + +pub extern "C" fn good12(size: usize) { } + +pub extern "C" fn good13(n: TransparentInt) { } + +pub extern "C" fn good14(p: TransparentRef) { } + +pub extern "C" fn good15(p: TransparentLifetime) { } + +pub extern "C" fn good16(p: TransparentUnit) { } + +pub extern "C" fn good17(p: TransparentCustomZst) { } + +#[allow(improper_ctypes_definitions)] +pub extern "C" fn good18(_: &String) { } + +#[cfg(not(target_arch = "wasm32"))] +pub extern "C" fn good1(size: *const libc::c_int) { } + +#[cfg(not(target_arch = "wasm32"))] +pub extern "C" fn good2(size: *const libc::c_uint) { } + +pub extern "C" fn unused_generic1(size: *const Foo) { } + +pub extern "C" fn unused_generic2() -> PhantomData { +//~^ ERROR uses type `std::marker::PhantomData` + Default::default() +} + +pub extern "C" fn used_generic1(x: T) { } + +pub extern "C" fn used_generic2(x: T, size: *const Foo) { } + +pub extern "C" fn used_generic3() -> T { + Default::default() +} + +pub extern "C" fn used_generic4(x: Vec) { } +//~^ ERROR: uses type `std::vec::Vec` + +pub extern "C" fn used_generic5() -> Vec { +//~^ ERROR: uses type `std::vec::Vec` + Default::default() +} + +fn main() {} diff --git a/src/test/ui/lint/lint-ctypes-fn.stderr b/src/test/ui/lint/lint-ctypes-fn.stderr new file mode 100644 index 0000000000000..66cf195327890 --- /dev/null +++ b/src/test/ui/lint/lint-ctypes-fn.stderr @@ -0,0 +1,191 @@ +error: `extern` fn uses type `[u32]`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:67:33 + | +LL | pub extern "C" fn slice_type(p: &[u32]) { } + | ^^^^^^ not FFI-safe + | +note: the lint level is defined here + --> $DIR/lint-ctypes-fn.rs:4:9 + | +LL | #![deny(improper_ctypes_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: consider using a raw pointer instead + = note: slices have no C equivalent + +error: `extern` fn uses type `str`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:70:31 + | +LL | pub extern "C" fn str_type(p: &str) { } + | ^^^^ not FFI-safe + | + = help: consider using `*const u8` and a length instead + = note: string slices have no C equivalent + +error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:73:31 + | +LL | pub extern "C" fn box_type(p: Box) { } + | ^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout + +error: `extern` fn uses type `char`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:76:32 + | +LL | pub extern "C" fn char_type(p: char) { } + | ^^^^ not FFI-safe + | + = help: consider using `u32` or `libc::wchar_t` instead + = note: the `char` type has no C equivalent + +error: `extern` fn uses type `i128`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:79:32 + | +LL | pub extern "C" fn i128_type(p: i128) { } + | ^^^^ not FFI-safe + | + = note: 128-bit integers don't currently have a known stable ABI + +error: `extern` fn uses type `u128`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:82:32 + | +LL | pub extern "C" fn u128_type(p: u128) { } + | ^^^^ not FFI-safe + | + = note: 128-bit integers don't currently have a known stable ABI + +error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:85:33 + | +LL | pub extern "C" fn tuple_type(p: (i32, i32)) { } + | ^^^^^^^^^^ not FFI-safe + | + = help: consider using a struct instead + = note: tuples have unspecified layout + +error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:88:34 + | +LL | pub extern "C" fn tuple_type2(p: I32Pair) { } + | ^^^^^^^ not FFI-safe + | + = help: consider using a struct instead + = note: tuples have unspecified layout + +error: `extern` fn uses type `ZeroSize`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:91:32 + | +LL | pub extern "C" fn zero_size(p: ZeroSize) { } + | ^^^^^^^^ not FFI-safe + | + = help: consider adding a member to this struct + = note: this struct has no fields +note: the type is defined here + --> $DIR/lint-ctypes-fn.rs:26:1 + | +LL | pub struct ZeroSize; + | ^^^^^^^^^^^^^^^^^^^^ + +error: `extern` fn uses type `ZeroSizeWithPhantomData`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:94:40 + | +LL | pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { } + | ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe + | + = note: composed only of `PhantomData` +note: the type is defined here + --> $DIR/lint-ctypes-fn.rs:61:1 + | +LL | pub struct ZeroSizeWithPhantomData(PhantomData); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `extern` fn uses type `std::marker::PhantomData`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:97:51 + | +LL | pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData { + | ^^^^^^^^^^^^^^^^^ not FFI-safe + | + = note: composed only of `PhantomData` + +error: `extern` fn uses type `fn()`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:102:30 + | +LL | pub extern "C" fn fn_type(p: RustFn) { } + | ^^^^^^ not FFI-safe + | + = help: consider using an `extern fn(...) -> ...` function pointer instead + = note: this function pointer has Rust-specific calling convention + +error: `extern` fn uses type `fn()`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:105:31 + | +LL | pub extern "C" fn fn_type2(p: fn()) { } + | ^^^^ not FFI-safe + | + = help: consider using an `extern fn(...) -> ...` function pointer instead + = note: this function pointer has Rust-specific calling convention + +error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:108:35 + | +LL | pub extern "C" fn fn_contained(p: RustBadRet) { } + | ^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout + +error: `extern` fn uses type `i128`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:111:39 + | +LL | pub extern "C" fn transparent_i128(p: TransparentI128) { } + | ^^^^^^^^^^^^^^^ not FFI-safe + | + = note: 128-bit integers don't currently have a known stable ABI + +error: `extern` fn uses type `str`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:114:38 + | +LL | pub extern "C" fn transparent_str(p: TransparentStr) { } + | ^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider using `*const u8` and a length instead + = note: string slices have no C equivalent + +error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:117:37 + | +LL | pub extern "C" fn transparent_fn(p: TransparentBadFn) { } + | ^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout + +error: `extern` fn uses type `std::marker::PhantomData`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:161:43 + | +LL | pub extern "C" fn unused_generic2() -> PhantomData { + | ^^^^^^^^^^^^^^^^^ not FFI-safe + | + = note: composed only of `PhantomData` + +error: `extern` fn uses type `std::vec::Vec`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:174:39 + | +LL | pub extern "C" fn used_generic4(x: Vec) { } + | ^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout + +error: `extern` fn uses type `std::vec::Vec`, which is not FFI-safe + --> $DIR/lint-ctypes-fn.rs:177:41 + | +LL | pub extern "C" fn used_generic5() -> Vec { + | ^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct + = note: this struct has unspecified layout + +error: aborting due to 20 previous errors + diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr index 8dbfeff7972fb..d33b99bdc4387 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr @@ -1,152 +1,152 @@ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:17:20 + --> $DIR/lint-exceeding-bitshifts.rs:18:20 | LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 42_i32 which would overflow | note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts.rs:9:9 + --> $DIR/lint-exceeding-bitshifts.rs:10:9 | LL | #![warn(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:21:13 + --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left with overflow + | ^^^^^^^ attempt to shift left by 42_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:26:15 + --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:28:15 + --> $DIR/lint-exceeding-bitshifts.rs:29:15 | LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:30:15 + --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:32:15 + --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:34:15 + --> $DIR/lint-exceeding-bitshifts.rs:35:15 | LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:36:15 + --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:38:15 + --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:40:15 + --> $DIR/lint-exceeding-bitshifts.rs:41:15 | LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:43:15 + --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:45:15 + --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:47:15 + --> $DIR/lint-exceeding-bitshifts.rs:48:15 | LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:49:15 + --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:51:15 + --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:53:15 + --> $DIR/lint-exceeding-bitshifts.rs:54:15 | LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:55:15 + --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:57:15 + --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:61:15 + --> $DIR/lint-exceeding-bitshifts.rs:62:15 | LL | let n = n << 8; - | ^^^^^^ attempt to shift left with overflow + | ^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:63:15 + --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^ attempt to shift left by -8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:68:15 + --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:70:15 + --> $DIR/lint-exceeding-bitshifts.rs:71:15 | LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:76:15 + --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 + --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: 24 warnings emitted diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr index 8dbfeff7972fb..d33b99bdc4387 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr @@ -1,152 +1,152 @@ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:17:20 + --> $DIR/lint-exceeding-bitshifts.rs:18:20 | LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 42_i32 which would overflow | note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts.rs:9:9 + --> $DIR/lint-exceeding-bitshifts.rs:10:9 | LL | #![warn(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:21:13 + --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left with overflow + | ^^^^^^^ attempt to shift left by 42_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:26:15 + --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:28:15 + --> $DIR/lint-exceeding-bitshifts.rs:29:15 | LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:30:15 + --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:32:15 + --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:34:15 + --> $DIR/lint-exceeding-bitshifts.rs:35:15 | LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:36:15 + --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:38:15 + --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:40:15 + --> $DIR/lint-exceeding-bitshifts.rs:41:15 | LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:43:15 + --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:45:15 + --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:47:15 + --> $DIR/lint-exceeding-bitshifts.rs:48:15 | LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:49:15 + --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:51:15 + --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:53:15 + --> $DIR/lint-exceeding-bitshifts.rs:54:15 | LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:55:15 + --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:57:15 + --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:61:15 + --> $DIR/lint-exceeding-bitshifts.rs:62:15 | LL | let n = n << 8; - | ^^^^^^ attempt to shift left with overflow + | ^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:63:15 + --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^ attempt to shift left by -8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:68:15 + --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:70:15 + --> $DIR/lint-exceeding-bitshifts.rs:71:15 | LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:76:15 + --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 + --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: 24 warnings emitted diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr index 8dbfeff7972fb..d33b99bdc4387 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr @@ -1,152 +1,152 @@ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:17:20 + --> $DIR/lint-exceeding-bitshifts.rs:18:20 | LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 42_i32 which would overflow | note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts.rs:9:9 + --> $DIR/lint-exceeding-bitshifts.rs:10:9 | LL | #![warn(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:21:13 + --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left with overflow + | ^^^^^^^ attempt to shift left by 42_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:26:15 + --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:28:15 + --> $DIR/lint-exceeding-bitshifts.rs:29:15 | LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:30:15 + --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:32:15 + --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:34:15 + --> $DIR/lint-exceeding-bitshifts.rs:35:15 | LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:36:15 + --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:38:15 + --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:40:15 + --> $DIR/lint-exceeding-bitshifts.rs:41:15 | LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:43:15 + --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:45:15 + --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:47:15 + --> $DIR/lint-exceeding-bitshifts.rs:48:15 | LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:49:15 + --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:51:15 + --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^ attempt to shift right by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:53:15 + --> $DIR/lint-exceeding-bitshifts.rs:54:15 | LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 16_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:55:15 + --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:57:15 + --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:61:15 + --> $DIR/lint-exceeding-bitshifts.rs:62:15 | LL | let n = n << 8; - | ^^^^^^ attempt to shift left with overflow + | ^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:63:15 + --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^ attempt to shift left by -8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:68:15 + --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^ attempt to shift left by 8_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:70:15 + --> $DIR/lint-exceeding-bitshifts.rs:71:15 | LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:76:15 + --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 + --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^^^^^ attempt to shift left by %BITS% which would overflow warning: 24 warnings emitted diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs index 4d56d103a8343..a76ca93f8e1a3 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.rs +++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs @@ -4,6 +4,7 @@ //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O // build-pass // ignore-pass (test emits codegen-time warnings and verifies that they are not errors) +// normalize-stderr-test "shift left by (64|32)_usize which" -> "shift left by %BITS% which" #![crate_type="lib"] #![warn(arithmetic_overflow, const_err)] diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs index 12093837d2630..e15ed2e70b896 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs @@ -2,8 +2,14 @@ #![deny(confusable_idents)] #![allow(uncommon_codepoints, non_upper_case_globals)] -const s: usize = 42; //~ ERROR identifier pair considered confusable +const s: usize = 42; fn main() { - let s = "rust"; + let s = "rust"; //~ ERROR identifier pair considered confusable + not_affected(); +} + +fn not_affected() { + let s1 = 1; + let sl = 'l'; } diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr index 40ee18acb3cd4..218f94f7b5829 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr @@ -1,11 +1,11 @@ -error: identifier pair considered confusable between `s` and `s` - --> $DIR/lint-confusable-idents.rs:5:7 +error: identifier pair considered confusable between `s` and `s` + --> $DIR/lint-confusable-idents.rs:8:9 | LL | const s: usize = 42; - | ^^ + | -- this is where the previous identifier occurred ... LL | let s = "rust"; - | - this is where the previous identifier occurred + | ^ | note: the lint level is defined here --> $DIR/lint-confusable-idents.rs:2:9 diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs new file mode 100644 index 0000000000000..a5b45466da5ca --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs @@ -0,0 +1,20 @@ +// check-pass +#![feature(non_ascii_idents)] +#![deny(mixed_script_confusables)] + +struct ΑctuallyNotLatin; + +fn main() { + let λ = 42; // this usage of Greek confirms that Greek is used intentionally. +} + +mod роре { + const エ: &'static str = "アイウ"; + + // this usage of Katakana confirms that Katakana is used intentionally. + fn ニャン() { + let д: usize = 100; // this usage of Cyrillic confirms that Cyrillic is used intentionally. + + println!("meow!"); + } +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs new file mode 100644 index 0000000000000..4637b03f250de --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs @@ -0,0 +1,15 @@ +#![feature(non_ascii_idents)] +#![deny(mixed_script_confusables)] + +struct ΑctuallyNotLatin; +//~^ ERROR The usage of Script Group `Greek` in this crate consists solely of + +fn main() { + let v = ΑctuallyNotLatin; +} + +mod роре { +//~^ ERROR The usage of Script Group `Cyrillic` in this crate consists solely of + const エ: &'static str = "アイウ"; + //~^ ERROR The usage of Script Group `Japanese, Katakana` in this crate consists solely of +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr new file mode 100644 index 0000000000000..6f75a1ece3766 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr @@ -0,0 +1,34 @@ +error: The usage of Script Group `Greek` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:4:8 + | +LL | struct ΑctuallyNotLatin; + | ^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/lint-mixed-script-confusables.rs:2:9 + | +LL | #![deny(mixed_script_confusables)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: The usage includes 'Α' (U+0391). + = note: Please recheck to make sure their usages are indeed what you want. + +error: The usage of Script Group `Cyrillic` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:11:5 + | +LL | mod роре { + | ^^^^ + | + = note: The usage includes 'е' (U+0435), 'о' (U+043E), 'р' (U+0440). + = note: Please recheck to make sure their usages are indeed what you want. + +error: The usage of Script Group `Japanese, Katakana` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:13:11 + | +LL | const エ: &'static str = "アイウ"; + | ^^ + | + = note: The usage includes 'エ' (U+30A8). + = note: Please recheck to make sure their usages are indeed what you want. + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs index 057329a0a650c..20d00cf701a15 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs @@ -7,5 +7,7 @@ fn coöperation() {} //~ ERROR identifier contains non-ASCII characters fn main() { let naïveté = 2; //~ ERROR identifier contains non-ASCII characters - println!("{}", naïveté); //~ ERROR identifier contains non-ASCII characters + + // using the same identifier the second time won't trigger the lint. + println!("{}", naïveté); } diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr index 6c9f0866c017a..048b6ff5d687f 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr @@ -22,11 +22,5 @@ error: identifier contains non-ASCII characters LL | let naïveté = 2; | ^^^^^^^ -error: identifier contains non-ASCII characters - --> $DIR/lint-non-ascii-idents.rs:10:20 - | -LL | println!("{}", naïveté); - | ^^^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs index 7ac0d035d5bf1..b5e251e047b5a 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs @@ -7,5 +7,7 @@ fn dijkstra() {} //~ ERROR identifier contains uncommon Unicode codepoints fn main() { let ㇻㇲㇳ = "rust"; //~ ERROR identifier contains uncommon Unicode codepoints - println!("{}", ㇻㇲㇳ); //~ ERROR identifier contains uncommon Unicode codepoints + + // using the same identifier the second time won't trigger the lint. + println!("{}", ㇻㇲㇳ); } diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr index b270bd1f051c2..05ea3d5de7dbc 100644 --- a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr @@ -22,11 +22,5 @@ error: identifier contains uncommon Unicode codepoints LL | let ㇻㇲㇳ = "rust"; | ^^^^^^ -error: identifier contains uncommon Unicode codepoints - --> $DIR/lint-uncommon-codepoints.rs:10:20 - | -LL | println!("{}", ㇻㇲㇳ); - | ^^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/mir/mir_cast_fn_ret.rs b/src/test/ui/mir/mir_cast_fn_ret.rs index 69fd64c1c092c..4574dbd8529aa 100644 --- a/src/test/ui/mir/mir_cast_fn_ret.rs +++ b/src/test/ui/mir/mir_cast_fn_ret.rs @@ -1,8 +1,10 @@ // run-pass +#[allow(improper_ctypes_definitions)] pub extern "C" fn tuple2() -> (u16, u8) { (1, 2) } +#[allow(improper_ctypes_definitions)] pub extern "C" fn tuple3() -> (u8, u8, u8) { (1, 2, 3) } diff --git a/src/test/ui/mir/mir_codegen_calls.rs b/src/test/ui/mir/mir_codegen_calls.rs index fc0db03e3a968..d93a25c8ef4d3 100644 --- a/src/test/ui/mir/mir_codegen_calls.rs +++ b/src/test/ui/mir/mir_codegen_calls.rs @@ -74,6 +74,7 @@ fn test8() -> isize { Two::two() } +#[allow(improper_ctypes_definitions)] extern fn simple_extern(x: u32, y: (u32, u32)) -> u32 { x + y.0 * y.1 } diff --git a/src/test/ui/mir/mir_detects_invalid_ops.stderr b/src/test/ui/mir/mir_detects_invalid_ops.stderr index 0b6dbfd7c3d85..b4f74a52a74cd 100644 --- a/src/test/ui/mir/mir_detects_invalid_ops.stderr +++ b/src/test/ui/mir/mir_detects_invalid_ops.stderr @@ -2,7 +2,7 @@ error: this operation will panic at runtime --> $DIR/mir_detects_invalid_ops.rs:11:14 | LL | let _z = 1 / y; - | ^^^^^ attempt to divide by zero + | ^^^^^ attempt to divide 1_i32 by zero | = note: `#[deny(unconditional_panic)]` on by default @@ -10,7 +10,7 @@ error: this operation will panic at runtime --> $DIR/mir_detects_invalid_ops.rs:16:14 | LL | let _z = 1 % y; - | ^^^^^ attempt to calculate the remainder with a divisor of zero + | ^^^^^ attempt to calculate the remainder of 1_i32 with a divisor of zero error: aborting due to 2 previous errors diff --git a/src/test/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr b/src/test/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr index fb8562d00ead1..952985fcddee6 100644 --- a/src/test/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr +++ b/src/test/ui/moves/moves-based-on-type-cyclic-types-issue-4821.stderr @@ -8,6 +8,10 @@ LL | consume(node) + r | ^^^^ value used here after partial move | = note: move occurs because value has type `std::boxed::Box`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `node.next.0` + | +LL | Some(ref right) => consume(right), + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/namespace/namespace-mix.stderr b/src/test/ui/namespace/namespace-mix.stderr index c80055f00d7d9..ee730910ee441 100644 --- a/src/test/ui/namespace/namespace-mix.stderr +++ b/src/test/ui/namespace/namespace-mix.stderr @@ -16,7 +16,7 @@ help: consider importing one of these items instead | LL | use m2::S; | -LL | use namespace_mix::xm2::S; +LL | use xm2::S; | error[E0423]: expected value, found type alias `xm1::S` @@ -39,7 +39,7 @@ help: consider importing one of these items instead | LL | use m2::S; | -LL | use namespace_mix::xm2::S; +LL | use xm2::S; | error[E0423]: expected value, found struct variant `m7::V` @@ -61,7 +61,7 @@ help: consider importing one of these items instead | LL | use m8::V; | -LL | use namespace_mix::xm8::V; +LL | use xm8::V; | error[E0423]: expected value, found struct variant `xm7::V` @@ -83,7 +83,7 @@ help: consider importing one of these items instead | LL | use m8::V; | -LL | use namespace_mix::xm8::V; +LL | use xm8::V; | error[E0277]: the trait bound `c::Item: Impossible` is not satisfied diff --git a/src/test/ui/never_type/issue-51506.rs b/src/test/ui/never_type/issue-51506.rs new file mode 100644 index 0000000000000..d0fe6a0f59a87 --- /dev/null +++ b/src/test/ui/never_type/issue-51506.rs @@ -0,0 +1,41 @@ +#![feature(never_type, specialization)] +#![allow(incomplete_features)] + +use std::iter::{self, Empty}; + +trait Trait { + type Out: Iterator; + + fn f(&self) -> Option; +} + +impl Trait for T { + default type Out = !; //~ ERROR: `!` is not an iterator + + default fn f(&self) -> Option { + None + } +} + +struct X; + +impl Trait for X { + type Out = Empty; + + fn f(&self) -> Option { + Some(iter::empty()) + } +} + +fn f(a: T) { + if let Some(iter) = a.f() { + println!("Some"); + for x in iter { + println!("x = {}", x); + } + } +} + +pub fn main() { + f(10); +} diff --git a/src/test/ui/never_type/issue-51506.stderr b/src/test/ui/never_type/issue-51506.stderr new file mode 100644 index 0000000000000..73865a9b5a02c --- /dev/null +++ b/src/test/ui/never_type/issue-51506.stderr @@ -0,0 +1,14 @@ +error[E0277]: `!` is not an iterator + --> $DIR/issue-51506.rs:13:5 + | +LL | type Out: Iterator; + | ------------------------------- required by `Trait::Out` +... +LL | default type Out = !; + | ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator + | + = help: the trait `std::iter::Iterator` is not implemented for `!` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/nll/issue-53807.stderr b/src/test/ui/nll/issue-53807.stderr index 2b15da3710e62..4f36a4ccab28f 100644 --- a/src/test/ui/nll/issue-53807.stderr +++ b/src/test/ui/nll/issue-53807.stderr @@ -5,6 +5,10 @@ LL | if let Some(thing) = maybe { | ^^^^^ value moved here, in previous iteration of loop | = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `maybe.0` + | +LL | if let Some(ref thing) = maybe { + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr index 54008d33968bc..995afeeed880c 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-lsh-1.rs:7:14 | LL | let _x = 1_i32 << 32; - | ^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^ attempt to shift left by 32_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-lsh-1.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr index 872e71bb73796..e6f6b1ccd192d 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-lsh-2.rs:7:14 | LL | let _x = 1 << -1; - | ^^^^^^^ attempt to shift left with overflow + | ^^^^^^^ attempt to shift left by -1_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-lsh-2.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr index d55ed4a046c9d..e57b892b8085d 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-lsh-3.rs:7:14 | LL | let _x = 1_u64 << 64; - | ^^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^^ attempt to shift left by 64_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-lsh-3.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr index 1ef8dd3466c0a..f20b41c1baa4f 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-lsh-4.rs:11:13 | LL | let x = 1_i8 << 17; - | ^^^^^^^^^^ attempt to shift left with overflow + | ^^^^^^^^^^ attempt to shift left by 17_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-lsh-4.rs:7:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr index 236303e2e9aa3..18861a1b96fa8 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-1.rs:7:14 | LL | let _x = -1_i32 >> 32; - | ^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^ attempt to shift right by 32_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-1.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr index 981c8986f76b9..a2fb2b90535c3 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-2.rs:7:14 | LL | let _x = -1_i32 >> -1; - | ^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^ attempt to shift right by -1_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-2.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr index c2994503f0efc..24588b4a6b9b6 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-3.rs:7:14 | LL | let _x = -1_i64 >> 64; - | ^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-3.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr index 3db1da06dbed8..3f59653ea6075 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-4.rs:11:13 | LL | let x = 2_i8 >> 17; - | ^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^ attempt to shift right by 17_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-4.rs:7:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr index bd3eae82977e3..8b0daf1551e4b 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-5.rs:7:14 | LL | let _n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-5.rs:4:9 diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr index 5d76639fb50f3..53a1445b54e38 100644 --- a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr +++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr @@ -2,7 +2,7 @@ error: this arithmetic operation will overflow --> $DIR/overflowing-rsh-6.rs:7:14 | LL | let _n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + | ^^^^^^^^^^^^^^^ attempt to shift right by 64_i32 which would overflow | note: the lint level is defined here --> $DIR/overflowing-rsh-6.rs:4:9 diff --git a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs index 31b3407a46e08..f2d5de75b65bd 100644 --- a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs +++ b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.rs @@ -4,15 +4,15 @@ // We wrap patterns in a tuple because top-level or-patterns were special-cased. fn main() { match (0u8, 0u8) { - //~^ ERROR non-exhaustive patterns: `(2u8..=u8::MAX, _)` + //~^ ERROR non-exhaustive patterns: `(2_u8..=u8::MAX, _)` (0 | 1, 2 | 3) => {} } match ((0u8,),) { - //~^ ERROR non-exhaustive patterns: `((4u8..=u8::MAX))` + //~^ ERROR non-exhaustive patterns: `((4_u8..=u8::MAX))` ((0 | 1,) | (2 | 3,),) => {} } match (Some(0u8),) { - //~^ ERROR non-exhaustive patterns: `(Some(2u8..=u8::MAX))` + //~^ ERROR non-exhaustive patterns: `(Some(2_u8..=u8::MAX))` (None | Some(0 | 1),) => {} } } diff --git a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr index 653f4978ab350..7e8bb73190747 100644 --- a/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr +++ b/src/test/ui/or-patterns/exhaustiveness-non-exhaustive.stderr @@ -1,26 +1,26 @@ -error[E0004]: non-exhaustive patterns: `(2u8..=u8::MAX, _)` not covered +error[E0004]: non-exhaustive patterns: `(2_u8..=u8::MAX, _)` not covered --> $DIR/exhaustiveness-non-exhaustive.rs:6:11 | LL | match (0u8, 0u8) { - | ^^^^^^^^^^ pattern `(2u8..=u8::MAX, _)` not covered + | ^^^^^^^^^^ pattern `(2_u8..=u8::MAX, _)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `(u8, u8)` -error[E0004]: non-exhaustive patterns: `((4u8..=u8::MAX))` not covered +error[E0004]: non-exhaustive patterns: `((4_u8..=u8::MAX))` not covered --> $DIR/exhaustiveness-non-exhaustive.rs:10:11 | LL | match ((0u8,),) { - | ^^^^^^^^^ pattern `((4u8..=u8::MAX))` not covered + | ^^^^^^^^^ pattern `((4_u8..=u8::MAX))` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `((u8,),)` -error[E0004]: non-exhaustive patterns: `(Some(2u8..=u8::MAX))` not covered +error[E0004]: non-exhaustive patterns: `(Some(2_u8..=u8::MAX))` not covered --> $DIR/exhaustiveness-non-exhaustive.rs:14:11 | LL | match (Some(0u8),) { - | ^^^^^^^^^^^^ pattern `(Some(2u8..=u8::MAX))` not covered + | ^^^^^^^^^^^^ pattern `(Some(2_u8..=u8::MAX))` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `(std::option::Option,)` diff --git a/src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.stderr b/src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.stderr index 2eadef9cb5c11..2acf1f41c6fa6 100644 --- a/src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.stderr +++ b/src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.stderr @@ -1,8 +1,8 @@ -error[E0005]: refutable pattern in local binding: `i32::MIN..=-1i32` and `3i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `3_i32..=i32::MAX` not covered --> $DIR/issue-69875-should-have-been-expanded-earlier-non-exhaustive.rs:4:9 | LL | let 0 | (1 | 2) = 0; - | ^^^^^^^^^^^ patterns `i32::MIN..=-1i32` and `3i32..=i32::MAX` not covered + | ^^^^^^^^^^^ patterns `i32::MIN..=-1_i32` and `3_i32..=i32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html @@ -12,11 +12,11 @@ help: you might want to use `if let` to ignore the variant that isn't matched LL | if let 0 | (1 | 2) = 0 { /* */ } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0004]: non-exhaustive patterns: `i32::MIN..=-1i32` and `3i32..=i32::MAX` not covered +error[E0004]: non-exhaustive patterns: `i32::MIN..=-1_i32` and `3_i32..=i32::MAX` not covered --> $DIR/issue-69875-should-have-been-expanded-earlier-non-exhaustive.rs:5:11 | LL | match 0 { - | ^ patterns `i32::MIN..=-1i32` and `3i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=-1_i32` and `3_i32..=i32::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` diff --git a/src/test/ui/parser/byte-string-literals.stderr b/src/test/ui/parser/byte-string-literals.stderr index ca964cd4b8f21..9be9064414796 100644 --- a/src/test/ui/parser/byte-string-literals.stderr +++ b/src/test/ui/parser/byte-string-literals.stderr @@ -22,7 +22,7 @@ error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte LL | b"é"; | ^ -error: unterminated double quote byte string +error[E0766]: unterminated double quote byte string --> $DIR/byte-string-literals.rs:7:6 | LL | b"a @@ -32,3 +32,4 @@ LL | | } error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0766`. diff --git a/src/test/ui/parser/issue-62524.rs b/src/test/ui/parser/issue-62524.rs index 57de4b87b0fe6..5259dfe2e656c 100644 --- a/src/test/ui/parser/issue-62524.rs +++ b/src/test/ui/parser/issue-62524.rs @@ -1,4 +1,6 @@ // ignore-tidy-trailing-newlines // error-pattern: aborting due to 3 previous errors +#![allow(uncommon_codepoints)] + y![ Ϥ, \ No newline at end of file diff --git a/src/test/ui/parser/issue-62524.stderr b/src/test/ui/parser/issue-62524.stderr index 8191c9682cefd..d5e07622b11b9 100644 --- a/src/test/ui/parser/issue-62524.stderr +++ b/src/test/ui/parser/issue-62524.stderr @@ -1,5 +1,5 @@ error: this file contains an unclosed delimiter - --> $DIR/issue-62524.rs:4:3 + --> $DIR/issue-62524.rs:6:3 | LL | y![ | - unclosed delimiter @@ -7,7 +7,7 @@ LL | Ϥ, | ^ error: macros that expand to items must be delimited with braces or followed by a semicolon - --> $DIR/issue-62524.rs:3:3 + --> $DIR/issue-62524.rs:5:3 | LL | y![ | ___^ @@ -24,7 +24,7 @@ LL | Ϥ,; | ^ error: cannot find macro `y` in this scope - --> $DIR/issue-62524.rs:3:1 + --> $DIR/issue-62524.rs:5:1 | LL | y![ | ^ diff --git a/src/test/ui/parser/shebang/shebang-empty.rs b/src/test/ui/parser/shebang/shebang-empty.rs new file mode 100644 index 0000000000000..e38cc637e945e --- /dev/null +++ b/src/test/ui/parser/shebang/shebang-empty.rs @@ -0,0 +1,4 @@ +#! + +// check-pass +fn main() {} diff --git a/src/test/ui/parser/shebang/shebang-space.rs b/src/test/ui/parser/shebang/shebang-space.rs new file mode 100644 index 0000000000000..0978b759d2a6e --- /dev/null +++ b/src/test/ui/parser/shebang/shebang-space.rs @@ -0,0 +1,5 @@ +#! + +// check-pass +// ignore-tidy-end-whitespace +fn main() {} diff --git a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr index f2186b9298e68..8a6ea8e91a25a 100644 --- a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr +++ b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr @@ -46,6 +46,10 @@ LL | Some(_z @ ref _y) => {} | value moved here | = note: move occurs because value has type `X`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `x.0` + | +LL | Some(ref _z @ ref _y) => {} + | ^^^ error[E0382]: borrow of moved value --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:19 @@ -57,6 +61,10 @@ LL | Some(_z @ ref mut _y) => {} | value moved here | = note: move occurs because value has type `X`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `x.0` + | +LL | Some(ref _z @ ref mut _y) => {} + | ^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr index f819e671436ec..5058998f2a7c1 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr @@ -357,6 +357,10 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | value moved here | = note: move occurs because value has type `main::U`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving the value + | +LL | a @ Some((ref mut b @ ref mut c, d @ ref e)) => {} + | ^^^ error[E0382]: use of moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:61:38 @@ -379,6 +383,10 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | value moved here | = note: move occurs because value has type `main::U`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving the value + | +LL | a @ Some((mut b @ ref mut c, ref d @ ref e)) => {} + | ^^^ error[E0382]: borrow of moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:71:30 @@ -412,6 +420,10 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | value moved here | = note: move occurs because value has type `main::U`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving the value + | +LL | a @ Some((ref mut b @ ref mut c, d @ ref e)) => {} + | ^^^ error[E0382]: use of moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:83:38 @@ -434,6 +446,10 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | value moved here | = note: move occurs because value has type `main::U`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving the value + | +LL | a @ Some((mut b @ ref mut c, ref d @ ref e)) => {} + | ^^^ error[E0382]: borrow of moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:93:30 diff --git a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr index 6427a30b8f2ed..161ac477183c3 100644 --- a/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr +++ b/src/test/ui/pattern/usefulness/exhaustive_integer_patterns.stderr @@ -10,20 +10,20 @@ note: the lint level is defined here LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ -error[E0004]: non-exhaustive patterns: `128u8..=u8::MAX` not covered +error[E0004]: non-exhaustive patterns: `128_u8..=u8::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:28:11 | LL | match x { - | ^ pattern `128u8..=u8::MAX` not covered + | ^ pattern `128_u8..=u8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered +error[E0004]: non-exhaustive patterns: `11_u8..=19_u8`, `31_u8..=34_u8`, `36_u8..=69_u8` and 1 more not covered --> $DIR/exhaustive_integer_patterns.rs:33:11 | LL | match x { - | ^ patterns `11u8..=19u8`, `31u8..=34u8`, `36u8..=69u8` and 1 more not covered + | ^ patterns `11_u8..=19_u8`, `31_u8..=34_u8`, `36_u8..=69_u8` and 1 more not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` @@ -34,11 +34,11 @@ error: unreachable pattern LL | -2..=20 => {} | ^^^^^^^ -error[E0004]: non-exhaustive patterns: `i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered +error[E0004]: non-exhaustive patterns: `i8::MIN..=-8_i8`, `-6_i8`, `121_i8..=124_i8` and 1 more not covered --> $DIR/exhaustive_integer_patterns.rs:41:11 | LL | match x { - | ^ patterns `i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered + | ^ patterns `i8::MIN..=-8_i8`, `-6_i8`, `121_i8..=124_i8` and 1 more not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` @@ -52,38 +52,38 @@ LL | match 0i8 { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i8` -error[E0004]: non-exhaustive patterns: `0i16` not covered +error[E0004]: non-exhaustive patterns: `0_i16` not covered --> $DIR/exhaustive_integer_patterns.rs:91:11 | LL | match 0i16 { - | ^^^^ pattern `0i16` not covered + | ^^^^ pattern `0_i16` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i16` -error[E0004]: non-exhaustive patterns: `128u8..=u8::MAX` not covered +error[E0004]: non-exhaustive patterns: `128_u8..=u8::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:109:11 | LL | match 0u8 { - | ^^^ pattern `128u8..=u8::MAX` not covered + | ^^^ pattern `128_u8..=u8::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u8` -error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=u8::MAX, Some(_))` not covered +error[E0004]: non-exhaustive patterns: `(0_u8, Some(_))` and `(2_u8..=u8::MAX, Some(_))` not covered --> $DIR/exhaustive_integer_patterns.rs:121:11 | LL | match (0u8, Some(())) { - | ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=u8::MAX, Some(_))` not covered + | ^^^^^^^^^^^^^^^ patterns `(0_u8, Some(_))` and `(2_u8..=u8::MAX, Some(_))` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `(u8, std::option::Option<()>)` -error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered +error[E0004]: non-exhaustive patterns: `(126_u8..=127_u8, false)` not covered --> $DIR/exhaustive_integer_patterns.rs:126:11 | LL | match (0u8, true) { - | ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered + | ^^^^^^^^^^^ pattern `(126_u8..=127_u8, false)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `(u8, bool)` @@ -92,7 +92,7 @@ error: multiple patterns covering the same range --> $DIR/exhaustive_integer_patterns.rs:141:9 | LL | 0 .. 2 => {} - | ------ this range overlaps on `1u8` + | ------ this range overlaps on `1_u8` LL | 1 ..= 2 => {} | ^^^^^^^ overlapping patterns | @@ -111,20 +111,20 @@ LL | match 0u128 { = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `5u128..=u128::MAX` not covered +error[E0004]: non-exhaustive patterns: `5_u128..=u128::MAX` not covered --> $DIR/exhaustive_integer_patterns.rs:150:11 | LL | match 0u128 { - | ^^^^^ pattern `5u128..=u128::MAX` not covered + | ^^^^^ pattern `5_u128..=u128::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` -error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered +error[E0004]: non-exhaustive patterns: `0_u128..=3_u128` not covered --> $DIR/exhaustive_integer_patterns.rs:154:11 | LL | match 0u128 { - | ^^^^^ pattern `0u128..=3u128` not covered + | ^^^^^ pattern `0_u128..=3_u128` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `u128` diff --git a/src/test/ui/pattern/usefulness/issue-43253.stderr b/src/test/ui/pattern/usefulness/issue-43253.stderr index 6e65c51dd3cf3..04feef1706cf4 100644 --- a/src/test/ui/pattern/usefulness/issue-43253.stderr +++ b/src/test/ui/pattern/usefulness/issue-43253.stderr @@ -2,7 +2,7 @@ warning: multiple patterns covering the same range --> $DIR/issue-43253.rs:16:9 | LL | 1..10 => {}, - | ----- this range overlaps on `9i32` + | ----- this range overlaps on `9_i32` LL | 9..=10 => {}, | ^^^^^^ overlapping patterns | diff --git a/src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr b/src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr index 0e12b89de1b91..ffc8433403fd5 100644 --- a/src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr +++ b/src/test/ui/pattern/usefulness/match-byte-array-patterns-2.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `&[0u8..=64u8, _, _, _]` and `&[66u8..=u8::MAX, _, _, _]` not covered +error[E0004]: non-exhaustive patterns: `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered --> $DIR/match-byte-array-patterns-2.rs:4:11 | LL | match buf { - | ^^^ patterns `&[0u8..=64u8, _, _, _]` and `&[66u8..=u8::MAX, _, _, _]` not covered + | ^^^ patterns `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `&[u8; 4]` diff --git a/src/test/ui/pattern/usefulness/match-non-exhaustive.stderr b/src/test/ui/pattern/usefulness/match-non-exhaustive.stderr index c6a9329f9e8e1..a35d61e4b710b 100644 --- a/src/test/ui/pattern/usefulness/match-non-exhaustive.stderr +++ b/src/test/ui/pattern/usefulness/match-non-exhaustive.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `i32::MIN..=0i32` and `2i32..=i32::MAX` not covered +error[E0004]: non-exhaustive patterns: `i32::MIN..=0_i32` and `2_i32..=i32::MAX` not covered --> $DIR/match-non-exhaustive.rs:2:11 | LL | match 0 { 1 => () } - | ^ patterns `i32::MIN..=0i32` and `2i32..=i32::MAX` not covered + | ^ patterns `i32::MIN..=0_i32` and `2_i32..=i32::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `i32` diff --git a/src/test/ui/pattern/usefulness/non-exhaustive-match.rs b/src/test/ui/pattern/usefulness/non-exhaustive-match.rs index 9177345bc6f50..a28cfb579f4f1 100644 --- a/src/test/ui/pattern/usefulness/non-exhaustive-match.rs +++ b/src/test/ui/pattern/usefulness/non-exhaustive-match.rs @@ -11,8 +11,8 @@ fn main() { match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered None => {} } - match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, i32::MIN..=3i32)` - // and `(_, _, 5i32..=i32::MAX)` not covered + match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, i32::MIN..=3_i32)` + // and `(_, _, 5_i32..=i32::MAX)` not covered (_, _, 4) => {} } match (T::A, T::A) { //~ ERROR non-exhaustive patterns: `(A, A)` not covered diff --git a/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr b/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr index 3cdbd8a3433f4..056efb9b75ddd 100644 --- a/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr +++ b/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr @@ -36,11 +36,11 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T), = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `std::option::Option` -error[E0004]: non-exhaustive patterns: `(_, _, i32::MIN..=3i32)` and `(_, _, 5i32..=i32::MAX)` not covered +error[E0004]: non-exhaustive patterns: `(_, _, i32::MIN..=3_i32)` and `(_, _, 5_i32..=i32::MAX)` not covered --> $DIR/non-exhaustive-match.rs:14:11 | LL | match (2, 3, 4) { - | ^^^^^^^^^ patterns `(_, _, i32::MIN..=3i32)` and `(_, _, 5i32..=i32::MAX)` not covered + | ^^^^^^^^^ patterns `(_, _, i32::MIN..=3_i32)` and `(_, _, 5_i32..=i32::MAX)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `(i32, i32, i32)` diff --git a/src/test/ui/pattern/usefulness/refutable-pattern-errors.rs b/src/test/ui/pattern/usefulness/refutable-pattern-errors.rs index 3ef2ead32cb7c..75658c490c4e2 100644 --- a/src/test/ui/pattern/usefulness/refutable-pattern-errors.rs +++ b/src/test/ui/pattern/usefulness/refutable-pattern-errors.rs @@ -5,5 +5,5 @@ fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } fn main() { let (1, (Some(1), 2..=3)) = (1, (None, 2)); - //~^ ERROR refutable pattern in local binding: `(i32::MIN..=0i32, _)` and `(2i32..=i32::MAX, _)` not covered + //~^ ERROR refutable pattern in local binding: `(i32::MIN..=0_i32, _)` and `(2_i32..=i32::MAX, _)` not covered } diff --git a/src/test/ui/pattern/usefulness/refutable-pattern-errors.stderr b/src/test/ui/pattern/usefulness/refutable-pattern-errors.stderr index ac729ae9f7cdf..8d0409a6af940 100644 --- a/src/test/ui/pattern/usefulness/refutable-pattern-errors.stderr +++ b/src/test/ui/pattern/usefulness/refutable-pattern-errors.stderr @@ -6,11 +6,11 @@ LL | fn func((1, (Some(1), 2..=3)): (isize, (Option, isize))) { } | = note: the matched value is of type `(isize, (std::option::Option, isize))` -error[E0005]: refutable pattern in local binding: `(i32::MIN..=0i32, _)` and `(2i32..=i32::MAX, _)` not covered +error[E0005]: refutable pattern in local binding: `(i32::MIN..=0_i32, _)` and `(2_i32..=i32::MAX, _)` not covered --> $DIR/refutable-pattern-errors.rs:7:9 | LL | let (1, (Some(1), 2..=3)) = (1, (None, 2)); - | ^^^^^^^^^^^^^^^^^^^^^ patterns `(i32::MIN..=0i32, _)` and `(2i32..=i32::MAX, _)` not covered + | ^^^^^^^^^^^^^^^^^^^^^ patterns `(i32::MIN..=0_i32, _)` and `(2_i32..=i32::MAX, _)` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr index 7b9e30f40fbb3..9a34171a391c4 100644 --- a/src/test/ui/precise_pointer_size_matching.stderr +++ b/src/test/ui/precise_pointer_size_matching.stderr @@ -1,17 +1,17 @@ -error[E0004]: non-exhaustive patterns: `isize::MIN..=-6isize` and `21isize..=isize::MAX` not covered +error[E0004]: non-exhaustive patterns: `isize::MIN..=-6_isize` and `21_isize..=isize::MAX` not covered --> $DIR/precise_pointer_size_matching.rs:24:11 | LL | match 0isize { - | ^^^^^^ patterns `isize::MIN..=-6isize` and `21isize..=isize::MAX` not covered + | ^^^^^^ patterns `isize::MIN..=-6_isize` and `21_isize..=isize::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `isize` -error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=usize::MAX` not covered +error[E0004]: non-exhaustive patterns: `0_usize` and `21_usize..=usize::MAX` not covered --> $DIR/precise_pointer_size_matching.rs:29:11 | LL | match 0usize { - | ^^^^^^ patterns `0usize` and `21usize..=usize::MAX` not covered + | ^^^^^^ patterns `0_usize` and `21_usize..=usize::MAX` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `usize` diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.rs b/src/test/ui/range/issue-73553-misinterp-range-literal.rs new file mode 100644 index 0000000000000..e65dba0a03821 --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.rs @@ -0,0 +1,16 @@ +type Range = std::ops::Range; + +fn demo(r: &Range) { + println!("{:?}", r); +} + +fn tell(x: usize) -> usize { + x +} + +fn main() { + demo(tell(1)..tell(10)); + //~^ ERROR mismatched types + demo(1..10); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.stderr b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr new file mode 100644 index 0000000000000..5167b87fd27b8 --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:12:10 + | +LL | demo(tell(1)..tell(10)); + | ^^^^^^^^^^^^^^^^^ + | | + | expected reference, found struct `std::ops::Range` + | help: consider borrowing here: `&(tell(1)..tell(10))` + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range` + +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:14:10 + | +LL | demo(1..10); + | ^^^^^ + | | + | expected reference, found struct `std::ops::Range` + | help: consider borrowing here: `&(1..10)` + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range<{integer}>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/ref-suggestion.stderr b/src/test/ui/ref-suggestion.stderr index 9ff8e21bb58bd..97d2c174d9adb 100644 --- a/src/test/ui/ref-suggestion.stderr +++ b/src/test/ui/ref-suggestion.stderr @@ -28,6 +28,10 @@ LL | x; | ^ value used here after partial move | = note: move occurs because value has type `std::vec::Vec`, which does not implement the `Copy` trait +help: borrow this field in the pattern to avoid moving `x.0.0` + | +LL | (Some(ref y), ()) => {}, + | ^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/resolve/issue-21221-2.stderr b/src/test/ui/resolve/issue-21221-2.stderr index f9263d2af5026..d4fd7cb1257e0 100644 --- a/src/test/ui/resolve/issue-21221-2.stderr +++ b/src/test/ui/resolve/issue-21221-2.stderr @@ -4,7 +4,9 @@ error[E0405]: cannot find trait `T` in this scope LL | impl T for Foo { } | ^ not found in this scope | -help: consider importing this trait +help: consider importing one of these items + | +LL | use baz::T; | LL | use foo::bar::T; | diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index d9b1b9c59558a..16baa6c9b6233 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -132,7 +132,7 @@ LL | let _: E = m::n::Z; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0423]: expected value, found enum `m::n::Z` @@ -165,7 +165,7 @@ LL | let _: E = m::n::Z::Fn; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0412]: cannot find type `Z` in this scope @@ -183,7 +183,7 @@ LL | let _: E = m::n::Z::Struct; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0423]: expected value, found struct variant `m::n::Z::Struct` @@ -212,7 +212,7 @@ LL | let _: E = m::n::Z::Unit {}; | ^ help: consider importing this enum | -LL | use m::n::Z; +LL | use m::Z; | error[E0603]: enum `Z` is private diff --git a/src/test/ui/shebang.rs b/src/test/ui/shebang.rs deleted file mode 100644 index 3d3ba468be955..0000000000000 --- a/src/test/ui/shebang.rs +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env rustx - -// run-pass - -pub fn main() { println!("Hello World"); } diff --git a/src/test/ui/specialization/issue-44861.rs b/src/test/ui/specialization/issue-44861.rs new file mode 100644 index 0000000000000..c37a6273de366 --- /dev/null +++ b/src/test/ui/specialization/issue-44861.rs @@ -0,0 +1,40 @@ +#![crate_type = "lib"] +#![feature(specialization)] +#![feature(unsize, coerce_unsized)] +#![allow(incomplete_features)] + +use std::ops::CoerceUnsized; + +pub struct SmartassPtr(A::Data); + +pub trait Smartass { + type Data; + type Data2: CoerceUnsized<*const [u8]>; +} + +pub trait MaybeObjectSafe {} + +impl MaybeObjectSafe for () {} + +impl Smartass for T { + type Data = ::Data2; + default type Data2 = (); + //~^ ERROR: the trait bound `(): std::ops::CoerceUnsized<*const [u8]>` is not satisfied +} + +impl Smartass for () { + type Data2 = *const [u8; 1]; +} + +impl Smartass for dyn MaybeObjectSafe { + type Data = *const [u8]; + type Data2 = *const [u8; 0]; +} + +impl CoerceUnsized> for SmartassPtr + where ::Data: std::ops::CoerceUnsized<::Data> +{} + +pub fn conv(s: SmartassPtr<()>) -> SmartassPtr { + s +} diff --git a/src/test/ui/specialization/issue-44861.stderr b/src/test/ui/specialization/issue-44861.stderr new file mode 100644 index 0000000000000..b41b17e76a6ab --- /dev/null +++ b/src/test/ui/specialization/issue-44861.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `(): std::ops::CoerceUnsized<*const [u8]>` is not satisfied + --> $DIR/issue-44861.rs:21:5 + | +LL | type Data2: CoerceUnsized<*const [u8]>; + | --------------------------------------- required by `Smartass::Data2` +... +LL | default type Data2 = (); + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::CoerceUnsized<*const [u8]>` is not implemented for `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/specialization/issue-59435.rs b/src/test/ui/specialization/issue-59435.rs new file mode 100644 index 0000000000000..47323d3096f3d --- /dev/null +++ b/src/test/ui/specialization/issue-59435.rs @@ -0,0 +1,17 @@ +#![feature(specialization)] +#![allow(incomplete_features)] + +struct MyStruct {} + +trait MyTrait { + type MyType: Default; +} + +impl MyTrait for i32 { + default type MyType = MyStruct; + //~^ ERROR: the trait bound `MyStruct: std::default::Default` is not satisfied +} + +fn main() { + let _x: ::MyType = ::MyType::default(); +} diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr new file mode 100644 index 0000000000000..fd512a539a3ee --- /dev/null +++ b/src/test/ui/specialization/issue-59435.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `MyStruct: std::default::Default` is not satisfied + --> $DIR/issue-59435.rs:11:5 + | +LL | type MyType: Default; + | --------------------- required by `MyTrait::MyType` +... +LL | default type MyType = MyStruct; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `MyStruct` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.rs b/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.rs index 21fb8d4a2e68d..ac819dce6db2b 100644 --- a/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.rs +++ b/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.rs @@ -1,6 +1,6 @@ fn main() { let A = 3; - //~^ ERROR refutable pattern in local binding: `i32::MIN..=1i32` and + //~^ ERROR refutable pattern in local binding: `i32::MIN..=1_i32` and //~| interpreted as a constant pattern, not a new variable //~| HELP introduce a variable instead //~| SUGGESTION a_var diff --git a/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.stderr b/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.stderr index 7a6269da07f32..af64c09d5cadb 100644 --- a/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.stderr +++ b/src/test/ui/suggestions/const-pat-non-exaustive-let-new-var.stderr @@ -1,4 +1,4 @@ -error[E0005]: refutable pattern in local binding: `i32::MIN..=1i32` and `3i32..=i32::MAX` not covered +error[E0005]: refutable pattern in local binding: `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered --> $DIR/const-pat-non-exaustive-let-new-var.rs:2:9 | LL | let A = 3; diff --git a/src/test/ui/suggestions/invalid-bin-op.rs b/src/test/ui/suggestions/invalid-bin-op.rs new file mode 100644 index 0000000000000..bea1b91558646 --- /dev/null +++ b/src/test/ui/suggestions/invalid-bin-op.rs @@ -0,0 +1,7 @@ +pub fn foo(s: S, t: S) { + let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `S` +} + +struct S(T); + +fn main() {} diff --git a/src/test/ui/suggestions/invalid-bin-op.stderr b/src/test/ui/suggestions/invalid-bin-op.stderr new file mode 100644 index 0000000000000..7668eddf6070a --- /dev/null +++ b/src/test/ui/suggestions/invalid-bin-op.stderr @@ -0,0 +1,13 @@ +error[E0369]: binary operation `==` cannot be applied to type `S` + --> $DIR/invalid-bin-op.rs:2:15 + | +LL | let _ = s == t; + | - ^^ - S + | | + | S + | + = note: the trait `std::cmp::PartialEq` is not implemented for `S` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/suggestions/missing-trait-bound-for-op.fixed b/src/test/ui/suggestions/missing-trait-bound-for-op.fixed new file mode 100644 index 0000000000000..6b24375e41503 --- /dev/null +++ b/src/test/ui/suggestions/missing-trait-bound-for-op.fixed @@ -0,0 +1,7 @@ +// run-rustfix + +pub fn foo(s: &[T], t: &[T]) { + let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]` +} + +fn main() {} diff --git a/src/test/ui/suggestions/missing-trait-bound-for-op.rs b/src/test/ui/suggestions/missing-trait-bound-for-op.rs new file mode 100644 index 0000000000000..df47be070c9ea --- /dev/null +++ b/src/test/ui/suggestions/missing-trait-bound-for-op.rs @@ -0,0 +1,7 @@ +// run-rustfix + +pub fn foo(s: &[T], t: &[T]) { + let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]` +} + +fn main() {} diff --git a/src/test/ui/suggestions/missing-trait-bound-for-op.stderr b/src/test/ui/suggestions/missing-trait-bound-for-op.stderr new file mode 100644 index 0000000000000..0e0d397d6fc15 --- /dev/null +++ b/src/test/ui/suggestions/missing-trait-bound-for-op.stderr @@ -0,0 +1,16 @@ +error[E0369]: binary operation `==` cannot be applied to type `&[T]` + --> $DIR/missing-trait-bound-for-op.rs:4:15 + | +LL | let _ = s == t; + | - ^^ - &[T] + | | + | &[T] + | +help: consider restricting type parameter `T` + | +LL | pub fn foo(s: &[T], t: &[T]) { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr b/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr index 29216f36f5f31..507d53dc07c4c 100644 --- a/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr +++ b/src/test/ui/traits/trait-resolution-in-overloaded-op.stderr @@ -5,6 +5,11 @@ LL | a * b | - ^ - f64 | | | &T + | +help: consider further restricting this bound + | +LL | fn foo + std::ops::Mul>(a: &T, b: f64) -> f64 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs new file mode 100644 index 0000000000000..0cf77da559470 --- /dev/null +++ b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.rs @@ -0,0 +1,58 @@ +// check-pass +// +// rust-lang/rust#73592: borrow_mut through Deref should work. +// +// Before #72280, when we see something like `&mut *rcvr.method()`, we +// incorrectly requires `rcvr` to be type-checked as a mut place. While this +// requirement is usually correct for smart pointers, it is overly restrictive +// for types like `Mutex` or `RefCell` which can produce a guard that +// implements `DerefMut` from `&self`. +// +// Making it more confusing, because we use Deref as the fallback when DerefMut +// is implemented, we won't see an issue when the smart pointer does not +// implement `DerefMut`. It only causes an issue when `rcvr` is obtained via a +// type that implements both `Deref` or `DerefMut`. +// +// This bug is only discovered in #73592 after it is already fixed as a side-effect +// of a refactoring made in #72280. + +#![warn(unused_mut)] + +use std::pin::Pin; +use std::cell::RefCell; + +struct S(RefCell<()>); + +fn test_pin(s: Pin<&S>) { + // This works before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_pin_mut(s: Pin<&mut S>) { + // This should compile but didn't before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_vec(s: &Vec>) { + // This should compile but didn't before #72280. + let _ = &mut *s[0].borrow_mut(); +} + +fn test_mut_pin(mut s: Pin<&S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn test_mut_pin_mut(mut s: Pin<&mut S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn main() { + let mut s = S(RefCell::new(())); + test_pin(Pin::new(&s)); + test_pin_mut(Pin::new(&mut s)); + test_mut_pin(Pin::new(&s)); + test_mut_pin_mut(Pin::new(&mut s)); + test_vec(&vec![s.0]); +} diff --git a/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr new file mode 100644 index 0000000000000..51303adc9e533 --- /dev/null +++ b/src/test/ui/typeck/issue-73592-borrow_mut-through-deref.stderr @@ -0,0 +1,24 @@ +warning: variable does not need to be mutable + --> $DIR/issue-73592-borrow_mut-through-deref.rs:41:17 + | +LL | fn test_mut_pin(mut s: Pin<&S>) { + | ----^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/issue-73592-borrow_mut-through-deref.rs:19:9 + | +LL | #![warn(unused_mut)] + | ^^^^^^^^^^ + +warning: variable does not need to be mutable + --> $DIR/issue-73592-borrow_mut-through-deref.rs:46:21 + | +LL | fn test_mut_pin_mut(mut s: Pin<&mut S>) { + | ----^ + | | + | help: remove this `mut` + +warning: 2 warnings emitted + diff --git a/src/test/ui/utf8_idents.rs b/src/test/ui/utf8_idents.rs index f59d5502aae30..6c54086cc2009 100644 --- a/src/test/ui/utf8_idents.rs +++ b/src/test/ui/utf8_idents.rs @@ -1,3 +1,5 @@ +#![allow(mixed_script_confusables)] + fn foo< 'β, //~ ERROR non-ascii idents are not fully supported γ //~ ERROR non-ascii idents are not fully supported diff --git a/src/test/ui/utf8_idents.stderr b/src/test/ui/utf8_idents.stderr index 877412df8fa1c..2fc0b1c39effb 100644 --- a/src/test/ui/utf8_idents.stderr +++ b/src/test/ui/utf8_idents.stderr @@ -1,5 +1,5 @@ error[E0658]: non-ascii idents are not fully supported - --> $DIR/utf8_idents.rs:2:5 + --> $DIR/utf8_idents.rs:4:5 | LL | 'β, | ^^ @@ -8,7 +8,7 @@ LL | 'β, = help: add `#![feature(non_ascii_idents)]` to the crate attributes to enable error[E0658]: non-ascii idents are not fully supported - --> $DIR/utf8_idents.rs:3:5 + --> $DIR/utf8_idents.rs:5:5 | LL | γ | ^ @@ -17,7 +17,7 @@ LL | γ = help: add `#![feature(non_ascii_idents)]` to the crate attributes to enable error[E0658]: non-ascii idents are not fully supported - --> $DIR/utf8_idents.rs:8:5 + --> $DIR/utf8_idents.rs:10:5 | LL | δ: usize | ^ @@ -26,7 +26,7 @@ LL | δ: usize = help: add `#![feature(non_ascii_idents)]` to the crate attributes to enable error[E0658]: non-ascii idents are not fully supported - --> $DIR/utf8_idents.rs:12:9 + --> $DIR/utf8_idents.rs:14:9 | LL | let α = 0.00001f64; | ^ @@ -35,7 +35,7 @@ LL | let α = 0.00001f64; = help: add `#![feature(non_ascii_idents)]` to the crate attributes to enable warning: type parameter `γ` should have an upper camel case name - --> $DIR/utf8_idents.rs:3:5 + --> $DIR/utf8_idents.rs:5:5 | LL | γ | ^ help: convert the identifier to upper camel case: `Γ` diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 39baa6b8540df..614e25589601e 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -4,10 +4,7 @@ //! via `x.py dist hash-and-sign`; the cmdline arguments are set up //! by rustbuild (in `src/bootstrap/dist.rs`). -#![deny(warnings)] - use serde::Serialize; -use toml; use std::collections::BTreeMap; use std::collections::HashMap; diff --git a/src/tools/cargo b/src/tools/cargo index 089cbb80b73ba..c26576f9adddd 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 089cbb80b73ba242efdcf5430e89f63fa3b5328d +Subproject commit c26576f9adddd254b3dd63aecba176434290a9f6 diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs index 6968822c1b8ae..ecaeda68695a7 100644 --- a/src/tools/cargotest/main.rs +++ b/src/tools/cargotest/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::env; use std::fs; use std::path::{Path, PathBuf}; diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE.md b/src/tools/clippy/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 15006a07b44f2..0000000000000 --- a/src/tools/clippy/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE/blank_issue.md b/src/tools/clippy/.github/ISSUE_TEMPLATE/blank_issue.md new file mode 100644 index 0000000000000..9aef3ebe637a1 --- /dev/null +++ b/src/tools/clippy/.github/ISSUE_TEMPLATE/blank_issue.md @@ -0,0 +1,4 @@ +--- +name: Blank Issue +about: Create a blank issue. +--- diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE/bug_report.md b/src/tools/clippy/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000000000..d8f0c44148cae --- /dev/null +++ b/src/tools/clippy/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,47 @@ +--- +name: Bug Report +about: Create a bug report for Clippy +labels: L-bug +--- + + +I tried this code: + +```rust + +``` + +I expected to see this happen: *explanation* + +Instead, this happened: *explanation* + +### Meta + +- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20) +- `rustc -Vv`: + ``` + rustc 1.46.0-nightly (f455e46ea 2020-06-20) + binary: rustc + commit-hash: f455e46eae1a227d735091091144601b467e1565 + commit-date: 2020-06-20 + host: x86_64-unknown-linux-gnu + release: 1.46.0-nightly + LLVM version: 10.0 + ``` + + +
Backtrace +

+ + ``` + + ``` + +

+
diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE/config.yml b/src/tools/clippy/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000000..bd7dc0ac95c1f --- /dev/null +++ b/src/tools/clippy/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Rust Programming Language Forum + url: https://users.rust-lang.org + about: Please ask and answer questions about Rust here. diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE/ice.md b/src/tools/clippy/.github/ISSUE_TEMPLATE/ice.md new file mode 100644 index 0000000000000..3abe76bf2c497 --- /dev/null +++ b/src/tools/clippy/.github/ISSUE_TEMPLATE/ice.md @@ -0,0 +1,53 @@ +--- +name: Internal Compiler Error +about: Create a report for an internal compiler error in Clippy. +labels: L-bug, L-crash +--- + + +### Code + +```rust + +``` + +### Meta + +- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20) +- `rustc -Vv`: + ``` + rustc 1.46.0-nightly (f455e46ea 2020-06-20) + binary: rustc + commit-hash: f455e46eae1a227d735091091144601b467e1565 + commit-date: 2020-06-20 + host: x86_64-unknown-linux-gnu + release: 1.46.0-nightly + LLVM version: 10.0 + ``` + +### Error output + +``` + +``` + + +
Backtrace +

+ + ``` + + ``` + +

+
diff --git a/src/tools/clippy/.github/ISSUE_TEMPLATE/new_lint.md b/src/tools/clippy/.github/ISSUE_TEMPLATE/new_lint.md new file mode 100644 index 0000000000000..70445d7ef2503 --- /dev/null +++ b/src/tools/clippy/.github/ISSUE_TEMPLATE/new_lint.md @@ -0,0 +1,35 @@ +--- +name: New lint suggestion +about: Suggest a new Clippy lint. +labels: L-lint +--- + +### What it does + +*What does this lint do?* + +### Categories (optional) + +- Kind: *See for list of lint kinds* + +*What benefit of this lint over old code?* + +For example: +- Remove bounce checking inserted by ... +- Remove the need to duplicating/storing/typo ... + +### Drawbacks + +None. + +### Example + +```rust + +``` + +Could be written as: + +```rust + +``` diff --git a/src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md b/src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md index 97aa220afea54..137a73630940a 100644 --- a/src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md +++ b/src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md @@ -28,4 +28,5 @@ Delete this line and everything above before opening your PR. --- +*Please keep the line below* changelog: none diff --git a/src/tools/clippy/.github/driver.sh b/src/tools/clippy/.github/driver.sh index a2e87f5eb3745..2c17c4203ae5c 100644 --- a/src/tools/clippy/.github/driver.sh +++ b/src/tools/clippy/.github/driver.sh @@ -26,4 +26,16 @@ unset CARGO_MANIFEST_DIR sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr diff normalized.stderr tests/ui/cstring.stderr + +# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same +SYSROOT=`rustc --print sysroot` +diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose) + + +echo "fn main() {}" > target/driver_test.rs +# we can't run 2 rustcs on the same file at the same time +CLIPPY=`LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc` +RUSTC=`rustc ./target/driver_test.rs` +diff <($CLIPPY) <($RUSTC) + # TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR diff --git a/src/tools/clippy/clippy_lints/src/arithmetic.rs b/src/tools/clippy/clippy_lints/src/arithmetic.rs index 6cbe10a5352d1..cc09b99cf1dd1 100644 --- a/src/tools/clippy/clippy_lints/src/arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/arithmetic.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { _ => (), } - let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r)); + let (l_ty, r_ty) = (cx.tables().expr_ty(l), cx.tables().expr_ty(r)); if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); @@ -96,8 +96,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic { } }, hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => { - let ty = cx.tables.expr_ty(arg); - if constant_simple(cx, cx.tables, expr).is_none() { + let ty = cx.tables().expr_ty(arg); + if constant_simple(cx, cx.tables(), expr).is_none() { if ty.is_integral() { span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected"); self.expr_span = Some(expr.span); diff --git a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs index f8a8fdcd3aa35..c4536b57f8a99 100644 --- a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs +++ b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants { } if_chain! { if let ExprKind::Unary(_, ref lit) = e.kind; - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), lit); if is_true; then { lint_true(true); @@ -121,7 +121,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E if let ExprKind::DropTemps(ref expr) = expr.kind; if let ExprKind::Unary(UnOp::UnNot, ref expr) = expr.kind; // bind the first argument of the `assert!` macro - if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, expr); + if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables(), expr); // arm 1 pattern if let PatKind::Lit(ref lit_expr) = arms[0].pat.kind; if let ExprKind::Lit(ref lit) = lit_expr.kind; diff --git a/src/tools/clippy/clippy_lints/src/assign_ops.rs b/src/tools/clippy/clippy_lints/src/assign_ops.rs index 13e61fe98bac1..51a7647d3208f 100644 --- a/src/tools/clippy/clippy_lints/src/assign_ops.rs +++ b/src/tools/clippy/clippy_lints/src/assign_ops.rs @@ -82,8 +82,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { hir::ExprKind::Assign(assignee, e, _) => { if let hir::ExprKind::Binary(op, l, r) = &e.kind { let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { - let ty = cx.tables.expr_ty(assignee); - let rty = cx.tables.expr_ty(rhs); + let ty = cx.tables().expr_ty(assignee); + let rty = cx.tables().expr_ty(rhs); macro_rules! ops { ($op:expr, $cx:expr, @@ -167,7 +167,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps { // a = b commutative_op a // Limited to primitive type as these ops are know to be commutative if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) - && cx.tables.expr_ty(assignee).is_primitive_ty() + && cx.tables().expr_ty(assignee).is_primitive_ty() { match op.node { hir::BinOpKind::Add diff --git a/src/tools/clippy/clippy_lints/src/atomic_ordering.rs b/src/tools/clippy/clippy_lints/src/atomic_ordering.rs index fca9aaaff9dce..65e1e2c519c26 100644 --- a/src/tools/clippy/clippy_lints/src/atomic_ordering.rs +++ b/src/tools/clippy/clippy_lints/src/atomic_ordering.rs @@ -53,7 +53,7 @@ const ATOMIC_TYPES: [&str; 12] = [ ]; fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables.expr_ty(expr).kind { + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind { ATOMIC_TYPES .iter() .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) @@ -76,7 +76,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if method == "load" || method == "store"; let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); then { if method == "load" && match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { @@ -107,12 +107,12 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Call(ref func, ref args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if ["fence", "compiler_fence"] .iter() .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); + if let Some(ordering_def_id) = cx.tables().qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); then { span_lint_and_help( diff --git a/src/tools/clippy/clippy_lints/src/bit_mask.rs b/src/tools/clippy/clippy_lints/src/bit_mask.rs index ccb62cb038fd0..a53f3249b85b6 100644 --- a/src/tools/clippy/clippy_lints/src/bit_mask.rs +++ b/src/tools/clippy/clippy_lints/src/bit_mask.rs @@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, } fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option { - match constant(cx, cx.tables, lit)?.0 { + match constant(cx, cx.tables(), lit)?.0 { Constant::Int(n) => Some(n), _ => None, } diff --git a/src/tools/clippy/clippy_lints/src/booleans.rs b/src/tools/clippy/clippy_lints/src/booleans.rs index f92c564543b89..cc399a1f8a009 100644 --- a/src/tools/clippy/clippy_lints/src/booleans.rs +++ b/src/tools/clippy/clippy_lints/src/booleans.rs @@ -248,7 +248,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { }) }, ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => { - let type_of_receiver = cx.tables.expr_ty(&args[0]); + let type_of_receiver = cx.tables().expr_ty(&args[0]); if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type)) && !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type)) { @@ -450,7 +450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { self.bool_expr(e) }, ExprKind::Unary(UnOp::UnNot, inner) => { - if self.cx.tables.node_types()[inner.hir_id].is_bool() { + if self.cx.tables().node_types()[inner.hir_id].is_bool() { self.bool_expr(e); } else { walk_expr(self, e); @@ -465,7 +465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> { } fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])) } diff --git a/src/tools/clippy/clippy_lints/src/bytecount.rs b/src/tools/clippy/clippy_lints/src/bytecount.rs index 531531a654d0e..c00bb23069bf4 100644 --- a/src/tools/clippy/clippy_lints/src/bytecount.rs +++ b/src/tools/clippy/clippy_lints/src/bytecount.rs @@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind; if op.node == BinOpKind::Eq; if match_type(cx, - walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])), + walk_ptrs_ty(cx.tables().expr_ty(&filter_args[0])), &paths::SLICE_ITER); then { let needle = match get_path_name(l) { @@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount { _ => { return; } } }; - if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables.expr_ty(needle)).kind { + if ty::Uint(UintTy::U8) != walk_ptrs_ty(cx.tables().expr_ty(needle)).kind { return; } let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) = diff --git a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs index 3ba72e84fa827..78e509d2ecd83 100644 --- a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs +++ b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs @@ -60,7 +60,7 @@ impl CognitiveComplexity { let mut helper = CCHelper { cc: 1, returns: 0 }; helper.visit_expr(expr); let CCHelper { cc, returns } = helper; - let ret_ty = cx.tables.node_type(expr.hir_id); + let ret_ty = cx.tables().node_type(expr.hir_id); let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) { returns } else { diff --git a/src/tools/clippy/clippy_lints/src/comparison_chain.rs b/src/tools/clippy/clippy_lints/src/comparison_chain.rs index 93e29edcaa58f..9c0d33f928015 100644 --- a/src/tools/clippy/clippy_lints/src/comparison_chain.rs +++ b/src/tools/clippy/clippy_lints/src/comparison_chain.rs @@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain { } // Check that the type being compared implements `core::cmp::Ord` - let ty = cx.tables.expr_ty(lhs1); + let ty = cx.tables().expr_ty(lhs1); let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[])); if !is_ord { diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 22c5acca064e9..550752396c732 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -396,7 +396,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { let l = self.expr(left)?; let r = self.expr(right); match (l, r) { - (Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty(left).kind { + (Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty_opt(left)?.kind { ty::Int(ity) => { let l = sext(self.lcx.tcx, l, ity); let r = sext(self.lcx.tcx, r, ity); diff --git a/src/tools/clippy/clippy_lints/src/copies.rs b/src/tools/clippy/clippy_lints/src/copies.rs index b6d50bdfa1466..efd4a31f55960 100644 --- a/src/tools/clippy/clippy_lints/src/copies.rs +++ b/src/tools/clippy/clippy_lints/src/copies.rs @@ -192,7 +192,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) { /// Implementation of `IFS_SAME_COND`. fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(expr); h.finish() }; @@ -215,7 +215,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { /// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`. fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) { let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(expr); h.finish() }; @@ -251,7 +251,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) { if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind { let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 { - let mut h = SpanlessHash::new(cx, cx.tables); + let mut h = SpanlessHash::new(cx, cx.tables()); h.hash_expr(&arm.body); h.finish() }; @@ -320,7 +320,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap { if let Entry::Vacant(v) = map.entry(ident.name) { - v.insert(cx.tables.pat_ty(pat)); + v.insert(cx.tables().pat_ty(pat)); } if let Some(ref as_pat) = *as_pat { bindings_impl(cx, as_pat, map); diff --git a/src/tools/clippy/clippy_lints/src/default_trait_access.rs b/src/tools/clippy/clippy_lints/src/default_trait_access.rs index 635d609c38289..69ae509fb23e9 100644 --- a/src/tools/clippy/clippy_lints/src/default_trait_access.rs +++ b/src/tools/clippy/clippy_lints/src/default_trait_access.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { if let ExprKind::Call(ref path, ..) = expr.kind; if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id); if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD); then { match qpath { @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess { // TODO: Work out a way to put "whatever the imported way of referencing // this type in this file" rather than a fully-qualified type. - let expr_ty = cx.tables.expr_ty(expr); + let expr_ty = cx.tables().expr_ty(expr); if let ty::Adt(..) = expr_ty.kind { let replacement = format!("{}::default()", expr_ty); span_lint_and_sugg( diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 1cd30ae2c6381..1c6cc93690096 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -73,12 +73,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing { fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) { match method_name { "deref" => { - if cx - .tcx - .lang_items() - .deref_trait() - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(&call_expr), id, &[])) - { + if cx.tcx.lang_items().deref_trait().map_or(false, |id| { + implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + }) { span_lint_and_sugg( cx, EXPLICIT_DEREF_METHODS, @@ -91,12 +88,9 @@ fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, } }, "deref_mut" => { - if cx - .tcx - .lang_items() - .deref_mut_trait() - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(&call_expr), id, &[])) - { + if cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| { + implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[]) + }) { span_lint_and_sugg( cx, EXPLICIT_DEREF_METHODS, diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs index 9de9056c14029..014873eb13255 100644 --- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs +++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs @@ -119,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef { let lint; let msg; let arg = &args[0]; - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if let ty::Ref(..) = arg_ty.kind { if match_def_path(cx, def_id, &paths::DROP) { diff --git a/src/tools/clippy/clippy_lints/src/duration_subsec.rs b/src/tools/clippy/clippy_lints/src/duration_subsec.rs index 7171dcef968c1..5eb320ceca247 100644 --- a/src/tools/clippy/clippy_lints/src/duration_subsec.rs +++ b/src/tools/clippy/clippy_lints/src/duration_subsec.rs @@ -43,8 +43,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind; if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind; - if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::DURATION); - if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables, right); + if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::DURATION); + if let Some((Constant::Int(divisor), _)) = constant(cx, cx.tables(), right); then { let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs index f625058b6703c..e37e23b8944d7 100644 --- a/src/tools/clippy/clippy_lints/src/entry.rs +++ b/src/tools/clippy/clippy_lints/src/entry.rs @@ -109,7 +109,7 @@ fn check_cond<'a, 'tcx, 'b>( if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind; then { let map = ¶ms[0]; - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(map)); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(map)); return if match_type(cx, obj_ty, &paths::BTREEMAP) { Some(("BTreeMap", map, key)) diff --git a/src/tools/clippy/clippy_lints/src/eq_op.rs b/src/tools/clippy/clippy_lints/src/eq_op.rs index d7819d737ea04..98757624a13b5 100644 --- a/src/tools/clippy/clippy_lints/src/eq_op.rs +++ b/src/tools/clippy/clippy_lints/src/eq_op.rs @@ -103,8 +103,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { (&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {}, // &foo == &bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let lty = cx.tables.expr_ty(l); - let rty = cx.tables.expr_ty(r); + let lty = cx.tables().expr_ty(l); + let rty = cx.tables().expr_ty(r); let lcpy = is_copy(cx, lty); let rcpy = is_copy(cx, rty); // either operator autorefs or both args are copyable @@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { ) } else if lcpy && !rcpy - && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { ) } else if !lcpy && rcpy - && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then( cx, @@ -166,10 +166,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { }, // &foo == bar (&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => { - let lty = cx.tables.expr_ty(l); + let lty = cx.tables().expr_ty(l); let lcpy = is_copy(cx, lty); if (requires_ref || lcpy) - && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) + && implements_trait(cx, lty, trait_id, &[cx.tables().expr_ty(right).into()]) { span_lint_and_then( cx, @@ -190,10 +190,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { }, // foo == &bar (_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => { - let rty = cx.tables.expr_ty(r); + let rty = cx.tables().expr_ty(r); let rcpy = is_copy(cx, rty); if (requires_ref || rcpy) - && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) + && implements_trait(cx, cx.tables().expr_ty(left), trait_id, &[rty.into()]) { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |diag| { let rsnip = snippet(cx, r.span, "...").to_string(); diff --git a/src/tools/clippy/clippy_lints/src/erasing_op.rs b/src/tools/clippy/clippy_lints/src/erasing_op.rs index 3ff0506e28d00..804a9c1904b73 100644 --- a/src/tools/clippy/clippy_lints/src/erasing_op.rs +++ b/src/tools/clippy/clippy_lints/src/erasing_op.rs @@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp { } fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, span: Span) { - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) { + if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) { span_lint( cx, ERASING_OP, diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index 59af475af175e..bb74f193a48e7 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -6,7 +6,7 @@ use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_target::abi::LayoutOf; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use crate::utils::span_lint; @@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); + ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); }); for node in v.set { diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index a889856de2742..0ac8b95de8d61 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -97,7 +97,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg))); - let fn_ty = cx.tables.expr_ty(caller); + let fn_ty = cx.tables().expr_ty(caller); if matches!(fn_ty.kind, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _)); @@ -128,7 +128,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg))); - let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap(); + let method_def_id = cx.tables().type_dependent_def_id(ex.hir_id).unwrap(); if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter()); @@ -153,7 +153,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { /// Tries to determine the type for universal function call to be used instead of the closure fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option { let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; - let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id); + let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { if match_borrow_depth(expected_type_of_self, &actual_type_of_self) diff --git a/src/tools/clippy/clippy_lints/src/eval_order_dependence.rs b/src/tools/clippy/clippy_lints/src/eval_order_dependence.rs index 74144fb299de2..04af6c2c1f85d 100644 --- a/src/tools/clippy/clippy_lints/src/eval_order_dependence.rs +++ b/src/tools/clippy/clippy_lints/src/eval_order_dependence.rs @@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence { if let ExprKind::Path(ref qpath) = lhs.kind { if let QPath::Resolved(_, ref path) = *qpath { if path.segments.len() == 1 { - if let def::Res::Local(var) = cx.tables.qpath_res(qpath, lhs.hir_id) { + if let def::Res::Local(var) = cx.tables().qpath_res(qpath, lhs.hir_id) { let mut visitor = ReadVisitor { cx, var, @@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match e.kind { ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e), ExprKind::Call(ref func, _) => { - let typ = self.cx.tables.expr_ty(func); + let typ = self.cx.tables().expr_ty(func); match typ.kind { ty::FnDef(..) | ty::FnPtr(_) => { let sig = typ.fn_sig(self.cx.tcx); @@ -149,7 +149,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(..) => { - let borrowed_table = self.cx.tables; + let borrowed_table = self.cx.tables(); if borrowed_table.expr_ty(e).is_never() { self.report_diverging_sub_expr(e); } @@ -309,7 +309,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { if_chain! { if let QPath::Resolved(None, ref path) = *qpath; if path.segments.len() == 1; - if let def::Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id); + if let def::Res::Local(local_id) = self.cx.tables().qpath_res(qpath, expr.hir_id); if local_id == self.var; // Check that this is a read, not a write. if !is_in_assignment_position(self.cx, expr); diff --git a/src/tools/clippy/clippy_lints/src/float_literal.rs b/src/tools/clippy/clippy_lints/src/float_literal.rs index 4c604cd01075e..cd3d443ec58ef 100644 --- a/src/tools/clippy/clippy_lints/src/float_literal.rs +++ b/src/tools/clippy/clippy_lints/src/float_literal.rs @@ -61,7 +61,7 @@ declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { if_chain! { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Float(fty) = ty.kind; if let hir::ExprKind::Lit(ref lit) = expr.kind; if let LitKind::Float(sym, lit_float_ty) = lit.node; diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs index ad4f66c52c2c8..76713cb1afc41 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs @@ -112,7 +112,7 @@ declare_lint_pass!(FloatingPointArithmetic => [ // Returns the specialized log method for a given base if base is constant // and is one of 2, 10 and e fn get_specialized_log_method(cx: &LateContext<'_, '_>, base: &Expr<'_>) -> Option<&'static str> { - if let Some((value, _)) = constant(cx, cx.tables, base) { + if let Some((value, _)) = constant(cx, cx.tables(), base) { if F32(2.0) == value || F64(2.0) == value { return Some("log2"); } else if F32(10.0) == value || F64(10.0) == value { @@ -136,7 +136,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_, '_>, mut expr: &'a Expr<'a>) - if_chain! { // if the expression is a float literal and it is unsuffixed then // add a suffix so the suggestion is valid and unambiguous - if let ty::Float(float_ty) = cx.tables.expr_ty(expr).kind; + if let ty::Float(float_ty) = cx.tables().expr_ty(expr).kind; if let ExprKind::Lit(lit) = &expr.kind; if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node; then { @@ -188,7 +188,7 @@ fn check_ln1p(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { rhs, ) = &args[0].kind { - let recv = match (constant(cx, cx.tables, lhs), constant(cx, cx.tables, rhs)) { + let recv = match (constant(cx, cx.tables(), lhs), constant(cx, cx.tables(), rhs)) { (Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs, (_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs, _ => return, @@ -233,7 +233,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option { fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { // Check receiver - if let Some((value, _)) = constant(cx, cx.tables, &args[0]) { + if let Some((value, _)) = constant(cx, cx.tables(), &args[0]) { let method = if F32(f32_consts::E) == value || F64(f64_consts::E) == value { "exp" } else if F32(2.0) == value || F64(2.0) == value { @@ -254,7 +254,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { } // Check argument - if let Some((value, _)) = constant(cx, cx.tables, &args[1]) { + if let Some((value, _)) = constant(cx, cx.tables(), &args[1]) { let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value { ( SUBOPTIMAL_FLOPS, @@ -298,11 +298,11 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>]) { fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind; - if cx.tables.expr_ty(lhs).is_floating_point(); - if let Some((value, _)) = constant(cx, cx.tables, rhs); + if cx.tables().expr_ty(lhs).is_floating_point(); + if let Some((value, _)) = constant(cx, cx.tables(), rhs); if F32(1.0) == value || F64(1.0) == value; if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind; - if cx.tables.expr_ty(&method_args[0]).is_floating_point(); + if cx.tables().expr_ty(&method_args[0]).is_floating_point(); if path.ident.name.as_str() == "exp"; then { span_lint_and_sugg( @@ -324,8 +324,8 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { fn is_float_mul_expr<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> { if_chain! { if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind; - if cx.tables.expr_ty(lhs).is_floating_point(); - if cx.tables.expr_ty(rhs).is_floating_point(); + if cx.tables().expr_ty(lhs).is_floating_point(); + if cx.tables().expr_ty(rhs).is_floating_point(); then { return Some((lhs, rhs)); } @@ -404,7 +404,7 @@ fn are_exprs_equal(cx: &LateContext<'_, '_>, expr1: &Expr<'_>, expr2: &Expr<'_>) /// Returns true iff expr is some zero literal fn is_zero(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - match constant_simple(cx, cx.tables, expr) { + match constant_simple(cx, cx.tables(), expr) { Some(Constant::Int(i)) => i == 0, Some(Constant::F32(f)) => f == 0.0, Some(Constant::F64(f)) => f == 0.0, @@ -482,7 +482,7 @@ fn check_custom_abs(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatingPointArithmetic { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind { - let recv_ty = cx.tables.expr_ty(&args[0]); + let recv_ty = cx.tables().expr_ty(&args[0]); if recv_ty.is_floating_point() { match &*path.ident.name.as_str() { diff --git a/src/tools/clippy/clippy_lints/src/format.rs b/src/tools/clippy/clippy_lints/src/format.rs index 4cae5ca2c4326..58cf0027ea4d4 100644 --- a/src/tools/clippy/clippy_lints/src/format.rs +++ b/src/tools/clippy/clippy_lints/src/format.rs @@ -88,13 +88,13 @@ fn on_argumentv1_new<'a, 'tcx>( // matches `core::fmt::Display::fmt` if args.len() == 2; if let ExprKind::Path(ref qpath) = args[1].kind; - if let Some(did) = cx.tables.qpath_res(qpath, args[1].hir_id).opt_def_id(); + if let Some(did) = cx.tables().qpath_res(qpath, args[1].hir_id).opt_def_id(); if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD); // check `(arg0,)` in match block if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind; if pats.len() == 1; then { - let ty = walk_ptrs_ty(cx.tables.pat_ty(&pats[0])); + let ty = walk_ptrs_ty(cx.tables().pat_ty(&pats[0])); if ty.kind != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) { return None; } diff --git a/src/tools/clippy/clippy_lints/src/get_last_with_len.rs b/src/tools/clippy/clippy_lints/src/get_last_with_len.rs index 3629ba623ce43..57a7fbb565679 100644 --- a/src/tools/clippy/clippy_lints/src/get_last_with_len.rs +++ b/src/tools/clippy/clippy_lints/src/get_last_with_len.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen { // Argument 0 (the struct we're calling the method on) is a vector if let Some(struct_calling_on) = args.get(0); - let struct_ty = cx.tables.expr_ty(struct_calling_on); + let struct_ty = cx.tables().expr_ty(struct_calling_on); if is_type_diagnostic_item(cx, struct_ty, sym!(vec_type)); // Argument to "get" is a subtraction diff --git a/src/tools/clippy/clippy_lints/src/identity_op.rs b/src/tools/clippy/clippy_lints/src/identity_op.rs index 78e07d25f67c5..1c25e050997ea 100644 --- a/src/tools/clippy/clippy_lints/src/identity_op.rs +++ b/src/tools/clippy/clippy_lints/src/identity_op.rs @@ -62,8 +62,8 @@ fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Exp // `1 << 0` is a common pattern in bit manipulation code if_chain! { if let BinOpKind::Shl = cmp.node; - if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, right); - if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables, left); + if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), right); + if let Some(Constant::Int(1)) = constant_simple(cx, cx.tables(), left); then { return true; } @@ -74,8 +74,8 @@ fn is_allowed(cx: &LateContext<'_, '_>, cmp: BinOp, left: &Expr<'_>, right: &Exp #[allow(clippy::cast_possible_wrap)] fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) { - if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) { - let check = match cx.tables.expr_ty(e).kind { + if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables(), e) { + let check = match cx.tables().expr_ty(e).kind { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), ty::Uint(uty) => clip(cx.tcx, !0, uty), _ => return, diff --git a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs index 04d17c91d63c1..e357c7b3b2eb2 100644 --- a/src/tools/clippy/clippy_lints/src/if_let_mutex.rs +++ b/src/tools/clippy/clippy_lints/src/if_let_mutex.rs @@ -149,7 +149,7 @@ fn is_mutex_lock_call<'a>(cx: &LateContext<'a, '_>, expr: &'a Expr<'_>) -> Optio if_chain! { if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind; if path.ident.to_string() == "lock"; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(mutex_type)); then { Some(&args[0]) diff --git a/src/tools/clippy/clippy_lints/src/if_let_some_result.rs b/src/tools/clippy/clippy_lints/src/if_let_some_result.rs index 6a1fcdd1ce445..3f1ae9b86d387 100644 --- a/src/tools/clippy/clippy_lints/src/if_let_some_result.rs +++ b/src/tools/clippy/clippy_lints/src/if_let_some_result.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet { if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result.ok(, _) if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized; - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&result_types[0]), sym!(result_type)); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&result_types[0]), sym!(result_type)); if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some"; then { diff --git a/src/tools/clippy/clippy_lints/src/implicit_return.rs b/src/tools/clippy/clippy_lints/src/implicit_return.rs index c4308fd26a302..5a0531ff749e9 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_return.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_return.rs @@ -108,7 +108,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { ExprKind::Call(expr, ..) => { if_chain! { if let ExprKind::Path(qpath) = &expr.kind; - if let Some(path_def_id) = cx.tables.qpath_res(qpath, expr.hir_id).opt_def_id(); + if let Some(path_def_id) = cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(); if match_def_path(cx, path_def_id, &BEGIN_PANIC) || match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT); then { } diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs index fdaf37e5e08fa..1a6cb0b0c566e 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { }; // Check if the variable in the condition statement is an integer - if !cx.tables.expr_ty(cond_var).is_integral() { + if !cx.tables().expr_ty(cond_var).is_integral() { return; } @@ -93,7 +93,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub { ExprKind::Lit(ref cond_lit) => { // Check if the constant is zero if let LitKind::Int(0, _) = cond_lit.node { - if cx.tables.expr_ty(cond_left).is_signed() { + if cx.tables().expr_ty(cond_left).is_signed() { } else { print_lint_and_sugg(cx, &var_name, expr); }; diff --git a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs index c5808dd540b6f..c5e4abc94a8a6 100644 --- a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs +++ b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs @@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING] impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(ref array, ref index) = &expr.kind { - let ty = cx.tables.expr_ty(array); + let ty = cx.tables().expr_ty(array); if let Some(range) = higher::range(cx, index) { // Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..] if let ty::Array(_, s) = ty.kind { @@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing { // Catchall non-range index, i.e., [n] or [n << m] if let ty::Array(..) = ty.kind { // Index is a constant uint. - if let Some(..) = constant(cx, cx.tables, index) { + if let Some(..) = constant(cx, cx.tables(), index) { // Let rustc's `const_err` lint handle constant `usize` indexing on arrays. return; } @@ -169,14 +169,14 @@ fn to_const_range<'a, 'tcx>( range: higher::Range<'_>, array_size: u128, ) -> (Option, Option) { - let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c)); + let s = range.start.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); let start = match s { Some(Some(Constant::Int(x))) => Some(x), Some(_) => None, None => Some(0), }; - let e = range.end.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c)); + let e = range.end.map(|expr| constant(cx, cx.tables(), expr).map(|(c, _)| c)); let end = match e { Some(Some(Constant::Int(x))) => { if range.limits == RangeLimits::Closed { diff --git a/src/tools/clippy/clippy_lints/src/infinite_iter.rs b/src/tools/clippy/clippy_lints/src/infinite_iter.rs index a860a9def2422..38f086c9221fe 100644 --- a/src/tools/clippy/clippy_lints/src/infinite_iter.rs +++ b/src/tools/clippy/clippy_lints/src/infinite_iter.rs @@ -230,13 +230,14 @@ fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finitene } } if method.ident.name == sym!(last) && args.len() == 1 { - let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR) - .map_or(false, |id| !implements_trait(cx, cx.tables.expr_ty(&args[0]), id, &[])); + let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| { + !implements_trait(cx, cx.tables().expr_ty(&args[0]), id, &[]) + }); if not_double_ended { return is_infinite(cx, &args[0]); } } else if method.ident.name == sym!(collect) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if INFINITE_COLLECTORS.iter().any(|path| match_type(cx, ty, path)) { return is_infinite(cx, &args[0]); } diff --git a/src/tools/clippy/clippy_lints/src/integer_division.rs b/src/tools/clippy/clippy_lints/src/integer_division.rs index d537ef3f3238e..83ae1c1a971e1 100644 --- a/src/tools/clippy/clippy_lints/src/integer_division.rs +++ b/src/tools/clippy/clippy_lints/src/integer_division.rs @@ -50,7 +50,7 @@ fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Ex if let hir::ExprKind::Binary(binop, left, right) = &expr.kind; if let hir::BinOpKind::Div = &binop.node; then { - let (left_ty, right_ty) = (cx.tables.expr_ty(left), cx.tables.expr_ty(right)); + let (left_ty, right_ty) = (cx.tables().expr_ty(left), cx.tables().expr_ty(right)); return left_ty.is_integral() && right_ty.is_integral(); } } diff --git a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs index deb57db167896..0301f263489f4 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs @@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; - if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; + if let ty::Array(element_type, cst) = cx.tables().expr_ty(expr).kind; if let ConstKind::Value(val) = cst.val; if let ConstValue::Scalar(element_count) = val; if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx); diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 13e85fda8ffeb..e17297e969516 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -211,7 +211,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp } fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) { - if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) { + if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) + { // check if we are in an is_empty() method if let Some(name) = get_item_name(cx, method) { if name.as_str() == "is_empty" { @@ -299,7 +300,7 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { return false; } - let ty = &walk_ptrs_ty(cx.tables.expr_ty(expr)); + let ty = &walk_ptrs_ty(cx.tables().expr_ty(expr)); match ty.kind { ty::Dynamic(ref tt, ..) => { if let Some(principal) = tt.principal() { diff --git a/src/tools/clippy/clippy_lints/src/let_and_return.rs b/src/tools/clippy/clippy_lints/src/let_and_return.rs index 6d3fb317bcfc5..299202981b1f3 100644 --- a/src/tools/clippy/clippy_lints/src/let_and_return.rs +++ b/src/tools/clippy/clippy_lints/src/let_and_return.rs @@ -100,14 +100,14 @@ struct BorrowVisitor<'a, 'tcx> { impl BorrowVisitor<'_, '_> { fn fn_def_id(&self, expr: &Expr<'_>) -> Option { match &expr.kind { - ExprKind::MethodCall(..) => self.cx.tables.type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(..) => self.cx.tables().type_dependent_def_id(expr.hir_id), ExprKind::Call( Expr { kind: ExprKind::Path(qpath), .. }, .., - ) => self.cx.tables.qpath_res(qpath, expr.hir_id).opt_def_id(), + ) => self.cx.tables().qpath_res(qpath, expr.hir_id).opt_def_id(), _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/let_if_seq.rs b/src/tools/clippy/clippy_lints/src/let_if_seq.rs index e097f40f87e47..7b03812b82260 100644 --- a/src/tools/clippy/clippy_lints/src/let_if_seq.rs +++ b/src/tools/clippy/clippy_lints/src/let_if_seq.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { then { let span = stmt.span.to(if_.span); - let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze( + let has_interior_mutability = !cx.tables().node_type(canonical_id).is_freeze( cx.tcx.at(span), cx.param_env, ); diff --git a/src/tools/clippy/clippy_lints/src/let_underscore.rs b/src/tools/clippy/clippy_lints/src/let_underscore.rs index 710dec8d33fc9..0864bbe0f9127 100644 --- a/src/tools/clippy/clippy_lints/src/let_underscore.rs +++ b/src/tools/clippy/clippy_lints/src/let_underscore.rs @@ -35,7 +35,7 @@ declare_clippy_lint! { /// **What it does:** Checks for `let _ = sync_lock` /// /// **Why is this bad?** This statement immediately drops the lock instead of - /// extending it's lifetime to the end of the scope, which is often not intended. + /// extending its lifetime to the end of the scope, which is often not intended. /// To extend lock lifetime to the end of the scope, use an underscore-prefixed /// name instead (i.e. _lock). If you want to explicitly drop the lock, /// `std::mem::drop` conveys your intention better and is less error-prone. @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { if let PatKind::Wild = local.pat.kind; if let Some(ref init) = local.init; then { - let init_ty = cx.tables.expr_ty(init); + let init_ty = cx.tables().expr_ty(init); let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) @@ -94,7 +94,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore { "consider using an underscore-prefixed named \ binding or dropping explicitly with `std::mem::drop`" ) - } else if is_must_use_ty(cx, cx.tables.expr_ty(init)) { + } else if is_must_use_ty(cx, cx.tables().expr_ty(init)) { span_lint_and_help( cx, LET_UNDERSCORE_MUST_USE, diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index cd258c7b506c3..501220f28e5db 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -1,63 +1,44 @@ // error-pattern:cargo-clippy #![feature(bindings_after_at)] -#![feature(box_syntax)] #![feature(box_patterns)] +#![feature(box_syntax)] +#![feature(concat_idents)] +#![feature(crate_visibility_modifier)] +#![feature(drain_filter)] #![feature(or_patterns)] #![feature(rustc_private)] #![feature(stmt_expr_attributes)] -#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] #![recursion_limit = "512"] -#![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)] -#![deny(rustc::internal)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] -#![feature(crate_visibility_modifier)] -#![feature(concat_idents)] -#![feature(drain_filter)] +#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)] +#![warn(trivial_casts, trivial_numeric_casts)] +// warn on lints, that are included in `rust-lang/rust`s bootstrap +#![warn(rust_2018_idioms, unused_lifetimes)] +// warn on rustc internal lints +#![deny(rustc::internal)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) -#[allow(unused_extern_crates)] extern crate rustc_ast; -#[allow(unused_extern_crates)] extern crate rustc_ast_pretty; -#[allow(unused_extern_crates)] extern crate rustc_attr; -#[allow(unused_extern_crates)] extern crate rustc_data_structures; -#[allow(unused_extern_crates)] -extern crate rustc_driver; -#[allow(unused_extern_crates)] extern crate rustc_errors; -#[allow(unused_extern_crates)] extern crate rustc_hir; -#[allow(unused_extern_crates)] extern crate rustc_hir_pretty; -#[allow(unused_extern_crates)] extern crate rustc_index; -#[allow(unused_extern_crates)] extern crate rustc_infer; -#[allow(unused_extern_crates)] extern crate rustc_lexer; -#[allow(unused_extern_crates)] extern crate rustc_lint; -#[allow(unused_extern_crates)] extern crate rustc_middle; -#[allow(unused_extern_crates)] extern crate rustc_mir; -#[allow(unused_extern_crates)] extern crate rustc_parse; -#[allow(unused_extern_crates)] extern crate rustc_parse_format; -#[allow(unused_extern_crates)] extern crate rustc_session; -#[allow(unused_extern_crates)] extern crate rustc_span; -#[allow(unused_extern_crates)] extern crate rustc_target; -#[allow(unused_extern_crates)] extern crate rustc_trait_selection; -#[allow(unused_extern_crates)] extern crate rustc_typeck; use rustc_data_structures::fx::FxHashSet; @@ -82,14 +63,10 @@ use rustc_session::Session; /// # Example /// /// ``` -/// # #![feature(rustc_private)] -/// # #[allow(unused_extern_crates)] -/// # extern crate rustc_middle; -/// # #[allow(unused_extern_crates)] -/// # extern crate rustc_session; -/// # #[macro_use] -/// # use clippy_lints::declare_clippy_lint; +/// #![feature(rustc_private)] +/// extern crate rustc_session; /// use rustc_session::declare_tool_lint; +/// use clippy_lints::declare_clippy_lint; /// /// declare_clippy_lint! { /// /// **What it does:** Checks for ... (describe what the lint matches). @@ -1062,7 +1039,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap); let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports; store.register_late_pass(move || box wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)); - store.register_early_pass(|| box macro_use::MacroUseImports); store.register_late_pass(|| box verbose_file_reads::VerboseFileReads); store.register_late_pass(|| box redundant_pub_crate::RedundantPubCrate::default()); store.register_late_pass(|| box unnamed_address::UnnamedAddress); @@ -1080,6 +1056,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: single_char_binding_names_threshold, }); store.register_early_pass(|| box unnested_or_patterns::UnnestedOrPatterns); + store.register_late_pass(|| box macro_use::MacroUseImports::default()); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1187,6 +1164,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&types::OPTION_OPTION), LintId::of(&unicode::NON_ASCII_LITERAL), LintId::of(&unicode::UNICODE_NOT_NFC), + LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS), LintId::of(&unused_self::UNUSED_SELF), LintId::of(&wildcard_imports::ENUM_GLOB_USE), LintId::of(&wildcard_imports::WILDCARD_IMPORTS), @@ -1440,7 +1418,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS), LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS), LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY), - LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS), LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME), LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT), LintId::of(&unwrap::PANICKING_UNWRAP), @@ -1624,7 +1601,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&types::UNNECESSARY_CAST), LintId::of(&types::VEC_BOX), LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY), - LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS), LintId::of(&unwrap::UNNECESSARY_UNWRAP), LintId::of(&useless_conversion::USELESS_CONVERSION), LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO), diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 318d0b69d57b7..6840e82d4bf1b 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -343,7 +343,7 @@ impl<'v, 't> RefVisitor<'v, 't> { }) { let hir_id = ty.hir_id; - match self.cx.tables.qpath_res(qpath, hir_id) { + match self.cx.tables().qpath_res(qpath, hir_id) { Res::Def(DefKind::TyAlias | DefKind::Struct, def_id) => { let generics = self.cx.tcx.generics_of(def_id); for _ in generics.params.as_slice() { diff --git a/src/tools/clippy/clippy_lints/src/loops.rs b/src/tools/clippy/clippy_lints/src/loops.rs index 83093ec51bd90..18b979176a0a0 100644 --- a/src/tools/clippy/clippy_lints/src/loops.rs +++ b/src/tools/clippy/clippy_lints/src/loops.rs @@ -28,7 +28,7 @@ use rustc_middle::ty::{self, Ty, TyS}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use std::iter::{once, Iterator}; use std::mem; @@ -535,7 +535,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops { if_chain! { if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind; if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR); - if implements_trait(cx, cx.tables.expr_ty(iter_expr), iter_def_id, &[]); + if implements_trait(cx, cx.tables().expr_ty(iter_expr), iter_def_id, &[]); then { return; } @@ -985,8 +985,8 @@ fn detect_manual_memcpy<'a, 'tcx>( if_chain! { if let ExprKind::Index(seqexpr_left, idx_left) = lhs.kind; if let ExprKind::Index(seqexpr_right, idx_right) = rhs.kind; - if is_slice_like(cx, cx.tables.expr_ty(seqexpr_left)) - && is_slice_like(cx, cx.tables.expr_ty(seqexpr_right)); + if is_slice_like(cx, cx.tables().expr_ty(seqexpr_left)) + && is_slice_like(cx, cx.tables().expr_ty(seqexpr_right)); if let Some(offset_left) = get_offset(cx, &idx_left, canonical_id); if let Some(offset_right) = get_offset(cx, &idx_right, canonical_id); @@ -1254,8 +1254,8 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e lint_iter_method(cx, args, arg, method_name); } } else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) { - let receiver_ty = cx.tables.expr_ty(&args[0]); - let receiver_ty_adjusted = cx.tables.expr_ty_adjusted(&args[0]); + let receiver_ty = cx.tables().expr_ty(&args[0]); + let receiver_ty_adjusted = cx.tables().expr_ty_adjusted(&args[0]); if TyS::same_type(receiver_ty, receiver_ty_adjusted) { let mut applicability = Applicability::MachineApplicable; let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability); @@ -1300,7 +1300,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e /// Checks for `for` loops over `Option`s and `Result`s. fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) { - let ty = cx.tables.expr_ty(arg); + let ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, ty, sym!(option_type)) { span_lint_and_help( cx, @@ -1405,7 +1405,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>( /// actual `Iterator` that the loop uses. fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String { let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR) - .map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(arg), id, &[])); + .map_or(false, |id| implements_trait(cx, cx.tables().expr_ty(arg), id, &[])); if impls_iterator { format!( "{}", @@ -1416,7 +1416,7 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: & // (&mut x).into_iter() ==> x.iter_mut() match &arg.kind { ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner) - if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => + if has_iter_method(cx, cx.tables().expr_ty(&arg_inner)).is_some() => { let meth_name = match mutability { Mutability::Mut => "iter_mut", @@ -1449,7 +1449,7 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( if let PatKind::Tuple(ref pat, _) = pat.kind { if pat.len() == 2 { let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind { + let (new_pat_span, kind, ty, mutbl) = match cx.tables().expr_ty(arg).kind { ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Not), @@ -1497,7 +1497,7 @@ struct MutatePairDelegate<'a, 'tcx> { span_high: Option, } -impl<'a, 'tcx> Delegate<'tcx> for MutatePairDelegate<'a, 'tcx> { +impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: ConsumeMode) {} fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, bk: ty::BorrowKind) { @@ -1525,7 +1525,7 @@ impl<'a, 'tcx> Delegate<'tcx> for MutatePairDelegate<'a, 'tcx> { } } -impl<'a, 'tcx> MutatePairDelegate<'a, 'tcx> { +impl MutatePairDelegate<'_, '_> { fn mutation_span(&self) -> (Option, Option) { (self.span_low, self.span_high) } @@ -1580,13 +1580,13 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option ( +fn check_for_mutation<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, body: &Expr<'_>, bound_ids: &[Option], ) -> (Option, Option) { let mut delegate = MutatePairDelegate { - cx: cx, + cx, hir_id_low: bound_ids[0], hir_id_high: bound_ids[1], span_low: None, @@ -1594,7 +1594,7 @@ fn check_for_mutation<'a, 'tcx> ( }; let def_id = body.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables).walk_expr(body); + ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(body); }); delegate.mutation_span() } @@ -1688,7 +1688,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (Some(extent), self.cx.tables.node_type(seqexpr.hir_id)), + (Some(extent), self.cx.tables().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1700,7 +1700,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, - (None, self.cx.tables.node_type(seqexpr.hir_id)), + (None, self.cx.tables().node_type(seqexpr.hir_id)), ); } return false; // no need to walk further *on the variable* @@ -1768,7 +1768,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { ExprKind::Call(ref f, args) => { self.visit_expr(f); for expr in args { - let ty = self.cx.tables.expr_ty_adjusted(expr); + let ty = self.cx.tables().expr_ty_adjusted(expr); self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { if mutbl == Mutability::Mut { @@ -1779,7 +1779,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(_, _, args, _) => { - let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = self.cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.kind { @@ -1866,7 +1866,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> { fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { // no walk_ptrs_ty: calling iter() on a reference can make sense because it // will allow further borrows afterwards - let ty = cx.tables.expr_ty(e); + let ty = cx.tables().expr_ty(e); is_iterable_array(ty, cx) || is_type_diagnostic_item(cx, ty, sym!(vec_type)) || match_type(cx, ty, &paths::LINKED_LIST) || @@ -2042,7 +2042,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { if self.state == VarState::DontWarn { return; } - if SpanlessEq::new(self.cx).eq_expr(&expr, self.end_expr) { + if expr.hir_id == self.end_expr.hir_id { self.past_loop = true; return; } @@ -2241,7 +2241,7 @@ fn path_name(e: &Expr<'_>) -> Option { } fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) { - if constant(cx, cx.tables, cond).is_some() { + if constant(cx, cx.tables(), cond).is_some() { // A pure constant condition (e.g., `while false`) is not linted. return; } @@ -2292,7 +2292,7 @@ struct HasBreakOrReturnVisitor { has_break_or_return: bool, } -impl<'a, 'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { +impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { @@ -2377,7 +2377,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, ' if let Some(ref generic_args) = chain_method.args; if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0); then { - let ty = cx.tables.node_type(ty.hir_id); + let ty = cx.tables().node_type(ty.hir_id); if is_type_diagnostic_item(cx, ty, sym!(vec_type)) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) || match_type(cx, ty, &paths::BTREEMAP) || diff --git a/src/tools/clippy/clippy_lints/src/macro_use.rs b/src/tools/clippy/clippy_lints/src/macro_use.rs index b1345d0b751ae..b845b20d2c012 100644 --- a/src/tools/clippy/clippy_lints/src/macro_use.rs +++ b/src/tools/clippy/clippy_lints/src/macro_use.rs @@ -1,10 +1,13 @@ -use crate::utils::{snippet, span_lint_and_sugg}; +use crate::utils::{in_macro, snippet, span_lint_and_sugg}; +use hir::def::{DefKind, Res}; use if_chain::if_chain; use rustc_ast::ast; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::edition::Edition; +use rustc_hir as hir; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::{edition::Edition, Span}; declare_clippy_lint! { /// **What it does:** Checks for `#[macro_use] use...`. @@ -12,7 +15,7 @@ declare_clippy_lint! { /// **Why is this bad?** Since the Rust 2018 edition you can import /// macro's directly, this is considered idiomatic. /// - /// **Known problems:** This lint does not generate an auto-applicable suggestion. + /// **Known problems:** None. /// /// **Example:** /// ```rust @@ -24,29 +27,205 @@ declare_clippy_lint! { "#[macro_use] is no longer needed" } -declare_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]); +const BRACKETS: &[char] = &['<', '>']; -impl EarlyLintPass for MacroUseImports { - fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) { +#[derive(Clone, Debug, PartialEq, Eq)] +struct PathAndSpan { + path: String, + span: Span, +} + +/// `MacroRefData` includes the name of the macro +/// and the path from `SourceMap::span_to_filename`. +#[derive(Debug, Clone)] +pub struct MacroRefData { + name: String, + path: String, +} + +impl MacroRefData { + pub fn new(name: String, callee: Span, cx: &LateContext<'_, '_>) -> Self { + let mut path = cx.sess().source_map().span_to_filename(callee).to_string(); + + // std lib paths are <::std::module::file type> + // so remove brackets, space and type. + if path.contains('<') { + path = path.replace(BRACKETS, ""); + } + if path.contains(' ') { + path = path.split(' ').next().unwrap().to_string(); + } + Self { name, path } + } +} + +#[derive(Default)] +#[allow(clippy::module_name_repetitions)] +pub struct MacroUseImports { + /// the actual import path used and the span of the attribute above it. + imports: Vec<(String, Span)>, + /// the span of the macro reference, kept to ensure only one reference is used per macro call. + collected: FxHashSet, + mac_refs: Vec, +} + +impl_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]); + +impl MacroUseImports { + fn push_unique_macro(&mut self, cx: &LateContext<'_, '_>, span: Span) { + let call_site = span.source_callsite(); + let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); + if let Some(callee) = span.source_callee() { + if !self.collected.contains(&call_site) { + let name = if name.contains("::") { + name.split("::").last().unwrap().to_string() + } else { + name.to_string() + }; + + self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx)); + self.collected.insert(call_site); + } + } + } + + fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_, '_>, span: Span) { + let call_site = span.source_callsite(); + let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); + if let Some(callee) = span.source_callee() { + if !self.collected.contains(&call_site) { + self.mac_refs + .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); + self.collected.insert(call_site); + } + } + } +} + +impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) { if_chain! { - if ecx.sess.opts.edition == Edition::Edition2018; - if let ast::ItemKind::Use(use_tree) = &item.kind; + if cx.sess().opts.edition == Edition::Edition2018; + if let hir::ItemKind::Use(path, _kind) = &item.kind; if let Some(mac_attr) = item .attrs .iter() .find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string())); + if let Res::Def(DefKind::Mod, id) = path.res; then { - let msg = "`macro_use` attributes are no longer needed in the Rust 2018 edition"; - let help = format!("use {}::", snippet(ecx, use_tree.span, "_")); + for kid in cx.tcx.item_children(id).iter() { + if let Res::Def(DefKind::Macro(_mac_type), mac_id) = kid.res { + let span = mac_attr.span; + let def_path = cx.tcx.def_path_str(mac_id); + self.imports.push((def_path, span)); + } + } + } else { + if in_macro(item.span) { + self.push_unique_macro_pat_ty(cx, item.span); + } + } + } + } + fn check_attribute(&mut self, cx: &LateContext<'_, '_>, attr: &ast::Attribute) { + if in_macro(attr.span) { + self.push_unique_macro(cx, attr.span); + } + } + fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) { + if in_macro(expr.span) { + self.push_unique_macro(cx, expr.span); + } + } + fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>) { + if in_macro(stmt.span) { + self.push_unique_macro(cx, stmt.span); + } + } + fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>) { + if in_macro(pat.span) { + self.push_unique_macro_pat_ty(cx, pat.span); + } + } + fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &hir::Ty<'_>) { + if in_macro(ty.span) { + self.push_unique_macro_pat_ty(cx, ty.span); + } + } + #[allow(clippy::too_many_lines)] + fn check_crate_post(&mut self, cx: &LateContext<'_, '_>, _krate: &hir::Crate<'_>) { + let mut used = FxHashMap::default(); + let mut check_dup = vec![]; + for (import, span) in &self.imports { + let found_idx = self.mac_refs.iter().position(|mac| import.ends_with(&mac.name)); + + if let Some(idx) = found_idx { + let _ = self.mac_refs.remove(idx); + let seg = import.split("::").collect::>(); + + match seg.as_slice() { + // an empty path is impossible + // a path should always consist of 2 or more segments + [] | [_] => return, + [root, item] => { + if !check_dup.contains(&(*item).to_string()) { + used.entry(((*root).to_string(), span)) + .or_insert_with(Vec::new) + .push((*item).to_string()); + check_dup.push((*item).to_string()); + } + }, + [root, rest @ ..] => { + if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) { + let filtered = rest + .iter() + .filter_map(|item| { + if check_dup.contains(&(*item).to_string()) { + None + } else { + Some((*item).to_string()) + } + }) + .collect::>(); + used.entry(((*root).to_string(), span)) + .or_insert_with(Vec::new) + .push(filtered.join("::")); + check_dup.extend(filtered); + } else { + let rest = rest.to_vec(); + used.entry(((*root).to_string(), span)) + .or_insert_with(Vec::new) + .push(rest.join("::")); + check_dup.extend(rest.iter().map(ToString::to_string)); + } + }, + } + } + } + + let mut suggestions = vec![]; + for ((root, span), path) in used { + if path.len() == 1 { + suggestions.push((span, format!("{}::{}", root, path[0]))) + } else { + suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")))) + } + } + + // If mac_refs is not empty we have encountered an import we could not handle + // such as `std::prelude::v1::foo` or some other macro that expands to an import. + if self.mac_refs.is_empty() { + for (span, import) in suggestions { + let help = format!("use {};", import); span_lint_and_sugg( - ecx, + cx, MACRO_USE_IMPORTS, - mac_attr.span, - msg, + *span, + "`macro_use` attributes are no longer needed in the Rust 2018 edition", "remove the attribute and import the macro directly, try", help, - Applicability::HasPlaceholders, - ); + Applicability::MaybeIncorrect, + ) } } } diff --git a/src/tools/clippy/clippy_lints/src/map_clone.rs b/src/tools/clippy/clippy_lints/src/map_clone.rs index 8f4fdc685ef38..9109de9458f1c 100644 --- a/src/tools/clippy/clippy_lints/src/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/map_clone.rs @@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind; if args.len() == 2; if method.ident.as_str() == "map"; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, ty, sym!(option_type)) || match_trait_method(cx, e, &paths::ITERATOR); if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind; let closure_body = cx.tcx.hir().body(body_id); @@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { match closure_expr.kind { hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => { if ident_eq(name, inner) { - if let ty::Ref(.., Mutability::Not) = cx.tables.expr_ty(inner).kind { + if let ty::Ref(.., Mutability::Not) = cx.tables().expr_ty(inner).kind { lint(cx, e.span, args[0].span, true); } } @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone { if ident_eq(name, &obj[0]) && method.ident.as_str() == "clone" && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) { - let obj_ty = cx.tables.expr_ty(&obj[0]); + let obj_ty = cx.tables().expr_ty(&obj[0]); if let ty::Ref(_, ty, _) = obj_ty.kind { let copy = is_copy(cx, ty); lint(cx, e.span, args[0].span, copy); diff --git a/src/tools/clippy/clippy_lints/src/map_unit_fn.rs b/src/tools/clippy/clippy_lints/src/map_unit_fn.rs index 8f4b674c04f49..a4550f707ee22 100644 --- a/src/tools/clippy/clippy_lints/src/map_unit_fn.rs +++ b/src/tools/clippy/clippy_lints/src/map_unit_fn.rs @@ -101,7 +101,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { } fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::FnDef(id, _) = ty.kind { if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() { @@ -112,7 +112,7 @@ fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { } fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> bool { - is_unit_type(cx.tables.expr_ty(expr)) + is_unit_type(cx.tables().expr_ty(expr)) } /// The expression inside a closure may or may not have surrounding braces and @@ -205,9 +205,9 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String { fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr<'_>, map_args: &[hir::Expr<'_>]) { let var_arg = &map_args[0]; - let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(option_type)) { + let (map_type, variant, lint) = if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(option_type)) { ("Option", "Some", OPTION_MAP_UNIT_FN) - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(var_arg), sym!(result_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(var_arg), sym!(result_type)) { ("Result", "Ok", RESULT_MAP_UNIT_FN) } else { return; diff --git a/src/tools/clippy/clippy_lints/src/match_on_vec_items.rs b/src/tools/clippy/clippy_lints/src/match_on_vec_items.rs index ee69628e9f052..4a025e0621f96 100644 --- a/src/tools/clippy/clippy_lints/src/match_on_vec_items.rs +++ b/src/tools/clippy/clippy_lints/src/match_on_vec_items.rs @@ -88,13 +88,13 @@ fn is_vec_indexing<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) } fn is_vector(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); is_type_diagnostic_item(cx, ty, sym!(vec_type)) } fn is_full_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty = walk_ptrs_ty(ty); match_type(cx, ty, &utils::paths::RANGE_FULL) } diff --git a/src/tools/clippy/clippy_lints/src/matches.rs b/src/tools/clippy/clippy_lints/src/matches.rs index 6d7af45a47224..0c91d8885d924 100644 --- a/src/tools/clippy/clippy_lints/src/matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches.rs @@ -540,7 +540,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], // allow match arms with just expressions return; }; - let ty = cx.tables.expr_ty(ex); + let ty = cx.tables().expr_ty(ex); if ty.kind != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els); @@ -632,7 +632,7 @@ fn check_single_match_opt_like( fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. - if cx.tables.expr_ty(ex).kind == ty::Bool { + if cx.tables().expr_ty(ex).kind == ty::Bool { span_lint_and_then( cx, MATCH_BOOL, @@ -695,8 +695,8 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], e } fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) { - if arms.len() >= 2 && cx.tables.expr_ty(ex).is_integral() { - let ranges = all_ranges(cx, arms, cx.tables.expr_ty(ex)); + if arms.len() >= 2 && cx.tables().expr_ty(ex).is_integral() { + let ranges = all_ranges(cx, arms, cx.tables().expr_ty(ex)); let type_ranges = type_ranges(&ranges); if !type_ranges.is_empty() { if let Some((start, end)) = overlapping(&type_ranges) { @@ -714,7 +714,7 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<' } fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex)); + let ex_ty = walk_ptrs_ty(cx.tables().expr_ty(ex)); if is_type_diagnostic_item(cx, ex_ty, sym!(result_type)) { for arm in arms { if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind { @@ -755,7 +755,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) } fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { - let ty = cx.tables.expr_ty(ex); + let ty = cx.tables().expr_ty(ex); if !ty.is_enum() { // If there isn't a nice closed set of possible values that can be conveniently enumerated, // don't complain about not enumerating the mall. @@ -935,8 +935,8 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], "as_mut" }; - let output_ty = cx.tables.expr_ty(expr); - let input_ty = cx.tables.expr_ty(ex); + let output_ty = cx.tables().expr_ty(expr); + let input_ty = cx.tables().expr_ty(ex); let cast = if_chain! { if let ty::Adt(_, substs) = input_ty.kind; @@ -1006,13 +1006,13 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms: match match_body.kind { ExprKind::Block(block, _) => { // macro + expr_ty(body) == () - if block.span.from_expansion() && cx.tables.expr_ty(&match_body).is_unit() { + if block.span.from_expansion() && cx.tables().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, _ => { // expr_ty(body) == () - if cx.tables.expr_ty(&match_body).is_unit() { + if cx.tables().expr_ty(&match_body).is_unit() { snippet_body.push(';'); } }, @@ -1111,11 +1111,11 @@ fn all_ranges<'a, 'tcx>( { if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind { let lhs = match lhs { - Some(lhs) => constant(cx, cx.tables, lhs)?.0, + Some(lhs) => constant(cx, cx.tables(), lhs)?.0, None => miri_to_const(ty.numeric_min_val(cx.tcx)?)?, }; let rhs = match rhs { - Some(rhs) => constant(cx, cx.tables, rhs)?.0, + Some(rhs) => constant(cx, cx.tables(), rhs)?.0, None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?, }; let rhs = match range_end { @@ -1129,7 +1129,7 @@ fn all_ranges<'a, 'tcx>( } if let PatKind::Lit(ref value) = pat.kind { - let value = constant(cx, cx.tables, value)?.0; + let value = constant(cx, cx.tables(), value)?.0; return Some(SpannedRange { span: pat.span, node: (value.clone(), Bound::Included(value)), diff --git a/src/tools/clippy/clippy_lints/src/mem_discriminant.rs b/src/tools/clippy/clippy_lints/src/mem_discriminant.rs index 3f953655670cf..d315c5ef89a88 100644 --- a/src/tools/clippy/clippy_lints/src/mem_discriminant.rs +++ b/src/tools/clippy/clippy_lints/src/mem_discriminant.rs @@ -35,10 +35,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant { if let ExprKind::Call(ref func, ref func_args) = expr.kind; // is `mem::discriminant` if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_DISCRIMINANT); // type is non-enum - let ty_param = cx.tables.node_substs(func.hir_id).type_at(0); + let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); if !ty_param.is_enum(); then { diff --git a/src/tools/clippy/clippy_lints/src/mem_forget.rs b/src/tools/clippy/clippy_lints/src/mem_forget.rs index c6ddc5de63b0e..1821bd9135f98 100644 --- a/src/tools/clippy/clippy_lints/src/mem_forget.rs +++ b/src/tools/clippy/clippy_lints/src/mem_forget.rs @@ -31,7 +31,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget { if let ExprKind::Path(ref qpath) = path_expr.kind { if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() { if match_def_path(cx, def_id, &paths::MEM_FORGET) { - let forgot_ty = cx.tables.expr_ty(&args[0]); + let forgot_ty = cx.tables().expr_ty(&args[0]); if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type"); diff --git a/src/tools/clippy/clippy_lints/src/mem_replace.rs b/src/tools/clippy/clippy_lints/src/mem_replace.rs index ab6865bf0f3b7..16d31fc8346ea 100644 --- a/src/tools/clippy/clippy_lints/src/mem_replace.rs +++ b/src/tools/clippy/clippy_lints/src/mem_replace.rs @@ -135,33 +135,59 @@ fn check_replace_option_with_none(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest } } -fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span: Span) { - if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind { - if_chain! { - if repl_args.is_empty(); - if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); - then { - if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { - span_lint_and_help( - cx, - MEM_REPLACE_WITH_UNINIT, - expr_span, - "replacing with `mem::uninitialized()`", - None, - "consider using the `take_mut` crate instead", - ); - } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && - !cx.tables.expr_ty(src).is_primitive() { - span_lint_and_help( - cx, - MEM_REPLACE_WITH_UNINIT, - expr_span, - "replacing with `mem::zeroed()`", - None, - "consider using a default value or the `take_mut` crate instead", - ); - } +fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) { + if_chain! { + // check if replacement is mem::MaybeUninit::uninit().assume_init() + if let Some(method_def_id) = cx.tables().type_dependent_def_id(src.hir_id); + if cx.tcx.is_diagnostic_item(sym::assume_init, method_def_id); + then { + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + MEM_REPLACE_WITH_UNINIT, + expr_span, + "replacing with `mem::MaybeUninit::uninit().assume_init()`", + "consider using", + format!( + "std::ptr::read({})", + snippet_with_applicability(cx, dest.span, "", &mut applicability) + ), + applicability, + ); + return; + } + } + + if_chain! { + if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind; + if repl_args.is_empty(); + if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; + if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + then { + if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, repl_def_id) { + let mut applicability = Applicability::MachineApplicable; + span_lint_and_sugg( + cx, + MEM_REPLACE_WITH_UNINIT, + expr_span, + "replacing with `mem::uninitialized()`", + "consider using", + format!( + "std::ptr::read({})", + snippet_with_applicability(cx, dest.span, "", &mut applicability) + ), + applicability, + ); + } else if cx.tcx.is_diagnostic_item(sym::mem_zeroed, repl_def_id) && + !cx.tables().expr_ty(src).is_primitive() { + span_lint_and_help( + cx, + MEM_REPLACE_WITH_UNINIT, + expr_span, + "replacing with `mem::zeroed()`", + None, + "consider using a default value or the `take_mut` crate instead", + ); } } } @@ -172,7 +198,7 @@ fn check_replace_with_default(cx: &LateContext<'_, '_>, src: &Expr<'_>, dest: &E if_chain! { if !in_external_macro(cx.tcx.sess, expr_span); if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind; - if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); + if let Some(repl_def_id) = cx.tables().qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id(); if match_def_path(cx, repl_def_id, &paths::DEFAULT_TRAIT_METHOD); then { span_lint_and_then( @@ -204,12 +230,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace { // Check that `expr` is a call to `mem::replace()` if let ExprKind::Call(ref func, ref func_args) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::MEM_REPLACE); if let [dest, src] = &**func_args; then { check_replace_option_with_none(cx, src, dest, expr.span); - check_replace_with_uninit(cx, src, expr.span); + check_replace_with_uninit(cx, src, dest, expr.span); check_replace_with_default(cx, src, dest, expr.span); } } diff --git a/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs b/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs index 32e86637569ed..092702c8b8c7b 100644 --- a/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs @@ -157,7 +157,7 @@ pub(crate) trait BindInsteadOfMap { /// Lint use of `_.and_then(|x| Some(y))` for `Option`s fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - if !match_type(cx, cx.tables.expr_ty(&args[0]), Self::TYPE_QPATH) { + if !match_type(cx, cx.tables().expr_ty(&args[0]), Self::TYPE_QPATH) { return; } diff --git a/src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs b/src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs index 06138ab9783c3..d29b9adcb7d43 100644 --- a/src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs +++ b/src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs @@ -11,9 +11,9 @@ use rustc_middle::ty::{self, Ty}; /// Checks for the `INEFFICIENT_TO_STRING` lint pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) { if_chain! { - if let Some(to_string_meth_did) = cx.tables.type_dependent_def_id(expr.hir_id); + if let Some(to_string_meth_did) = cx.tables().type_dependent_def_id(expr.hir_id); if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD); - if let Some(substs) = cx.tables.node_substs_opt(expr.hir_id); + if let Some(substs) = cx.tables().node_substs_opt(expr.hir_id); let self_ty = substs.type_at(0); let (deref_self_ty, deref_count) = walk_ptrs_ty_depth(self_ty); if deref_count >= 1; diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 4f5c06e785c23..eb02314f4680a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -11,7 +11,7 @@ pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr< let arith_lhs = &args[1][0]; let arith_rhs = &args[1][1]; - let ty = cx.tables.expr_ty(arith_lhs); + let ty = cx.tables().expr_ty(arith_lhs); if !ty.is_integral() { return; } @@ -101,7 +101,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>) -> Opti } } - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); let ty_str = ty.to_string(); // `std::T::MAX` `std::T::MIN` constants diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index f25a9782813bb..c4e707ecf03ad 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -1433,7 +1433,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { lint_or_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); lint_expect_fun_call(cx, expr, *method_span, &method_call.ident.as_str(), args); - let self_ty = cx.tables.expr_ty_adjusted(&args[0]); + let self_ty = cx.tables().expr_ty_adjusted(&args[0]); if args.len() == 1 && method_call.ident.name == sym!(clone) { lint_clone_on_copy(cx, expr, &args[0], self_ty); lint_clone_on_ref_ptr(cx, expr, &args[0]); @@ -1639,7 +1639,7 @@ fn lint_or_fun_call<'a, 'tcx>( if let hir::ExprKind::Path(ref qpath) = fun.kind; let path = &*last_path_segment(qpath).ident.as_str(); if ["default", "new"].contains(&path); - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); if implements_trait(cx, arg_ty, default_trait_id, &[]); @@ -1679,7 +1679,7 @@ fn lint_or_fun_call<'a, 'tcx>( ) { if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind { if path.ident.as_str() == "len" { - let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); match ty.kind { ty::Slice(_) | ty::Array(_, _) => return, @@ -1707,7 +1707,7 @@ fn lint_or_fun_call<'a, 'tcx>( if { finder.visit_expr(&arg); finder.found }; if !contains_return(&arg); - let self_ty = cx.tables.expr_ty(self_expr); + let self_ty = cx.tables().expr_ty(self_expr); if let Some(&(_, fn_has_arguments, poss, suffix)) = know_types.iter().find(|&&i| match_type(cx, self_ty, i.0)); @@ -1786,7 +1786,7 @@ fn lint_expect_fun_call( if call_args.len() == 1 && (method_name.ident.name == sym!(as_str) || method_name.ident.name == sym!(as_ref)) && { - let arg_type = cx.tables.expr_ty(&call_args[0]); + let arg_type = cx.tables().expr_ty(&call_args[0]); let base_type = walk_ptrs_ty(arg_type); base_type.kind == ty::Str || is_type_diagnostic_item(cx, base_type, sym!(string_type)) } @@ -1805,7 +1805,7 @@ fn lint_expect_fun_call( // Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be // converted to string. fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool { - let arg_ty = cx.tables.expr_ty(arg); + let arg_ty = cx.tables().expr_ty(arg); if is_type_diagnostic_item(cx, arg_ty, sym!(string_type)) { return false; } @@ -1824,7 +1824,7 @@ fn lint_expect_fun_call( hir::ExprKind::Lit(_) => true, hir::ExprKind::Call(fun, _) => { if let hir::ExprKind::Path(ref p) = fun.kind { - match cx.tables.qpath_res(p, fun.hir_id) { + match cx.tables().qpath_res(p, fun.hir_id) { hir::def::Res::Def(hir::def::DefKind::Fn | hir::def::DefKind::AssocFn, def_id) => matches!( cx.tcx.fn_sig(def_id).output().skip_binder().kind, ty::Ref(ty::ReStatic, ..) @@ -1835,13 +1835,16 @@ fn lint_expect_fun_call( false } }, - hir::ExprKind::MethodCall(..) => cx.tables.type_dependent_def_id(arg.hir_id).map_or(false, |method_id| { - matches!( - cx.tcx.fn_sig(method_id).output().skip_binder().kind, - ty::Ref(ty::ReStatic, ..) - ) - }), - hir::ExprKind::Path(ref p) => match cx.tables.qpath_res(p, arg.hir_id) { + hir::ExprKind::MethodCall(..) => cx + .tables() + .type_dependent_def_id(arg.hir_id) + .map_or(false, |method_id| { + matches!( + cx.tcx.fn_sig(method_id).output().skip_binder().kind, + ty::Ref(ty::ReStatic, ..) + ) + }), + hir::ExprKind::Path(ref p) => match cx.tables().qpath_res(p, arg.hir_id) { hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static, _) => true, _ => false, }, @@ -1888,7 +1891,7 @@ fn lint_expect_fun_call( return; } - let receiver_type = cx.tables.expr_ty_adjusted(&args[0]); + let receiver_type = cx.tables().expr_ty_adjusted(&args[0]); let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym!(option_type)) { "||" } else if is_type_diagnostic_item(cx, receiver_type, sym!(result_type)) { @@ -1954,7 +1957,7 @@ fn lint_expect_fun_call( /// Checks for the `CLONE_ON_COPY` lint. fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'_>) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Ref(_, inner, _) = arg_ty.kind { if let ty::Ref(_, innermost, _) = inner.kind { span_lint_and_then( @@ -2018,11 +2021,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: } // x.clone() might have dereferenced x, possibly through Deref impls - if cx.tables.expr_ty(arg) == ty { + if cx.tables().expr_ty(arg) == ty { snip = Some(("try removing the `clone` call", format!("{}", snippet))); } else { let deref_count = cx - .tables + .tables() .expr_adjustments(arg) .iter() .filter(|adj| { @@ -2048,7 +2051,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir: } fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg)); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(arg)); if let ty::Adt(_, subst) = obj_ty.kind { let caller_type = if is_type_diagnostic_item(cx, obj_ty, sym::Rc) { @@ -2082,7 +2085,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi let arg = &args[1]; if let Some(arglists) = method_chain_args(arg, &["chars"]) { let target = &arglists[0][0]; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty(target)); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty(target)); let ref_str = if self_ty.kind == ty::Str { "" } else if is_type_diagnostic_item(cx, self_ty, sym!(string_type)) { @@ -2110,7 +2113,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hi } fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); if is_type_diagnostic_item(cx, obj_ty, sym!(string_type)) { lint_string_extend(cx, expr, args); } @@ -2118,7 +2121,7 @@ fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) { if_chain! { - let source_type = cx.tables.expr_ty(source); + let source_type = cx.tables().expr_ty(source); if let ty::Adt(def, substs) = source_type.kind; if cx.tcx.is_diagnostic_item(sym!(result_type), def.did); if match_type(cx, substs.type_at(0), &paths::CSTRING); @@ -2142,8 +2145,8 @@ fn lint_iter_cloned_collect<'a, 'tcx>( iter_args: &'tcx [hir::Expr<'_>], ) { if_chain! { - if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), sym!(vec_type)); - if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(expr), sym!(vec_type)); + if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])); if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite()); then { @@ -2250,7 +2253,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_ar fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) { if match_trait_method(cx, expr, &paths::ITERATOR) { - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &args[1]) { + if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &args[1]) { span_lint( cx, ITERATOR_STEP_BY_ZERO, @@ -2274,7 +2277,7 @@ fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_ parent_expr_opt = get_parent_expr(cx, parent_expr); } - if derefs_to_slice(cx, caller_expr, cx.tables.expr_ty(caller_expr)).is_some() { + if derefs_to_slice(cx, caller_expr, cx.tables().expr_ty(caller_expr)).is_some() { // caller is a Slice if_chain! { if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind; @@ -2295,8 +2298,8 @@ fn lint_iter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_ ); } } - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(caller_expr), sym!(vec_type)) - || matches!(&walk_ptrs_ty(cx.tables.expr_ty(caller_expr)).kind, ty::Array(_, _)) + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(caller_expr), sym!(vec_type)) + || matches!(&walk_ptrs_ty(cx.tables().expr_ty(caller_expr)).kind, ty::Array(_, _)) { // caller is a Vec or an Array let mut applicability = Applicability::MachineApplicable; @@ -2323,11 +2326,11 @@ fn lint_iter_nth<'a, 'tcx>( ) { let iter_args = nth_and_iter_args[1]; let mut_str = if is_mut { "_mut" } else { "" }; - let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some() { + let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables().expr_ty(&iter_args[0])).is_some() { "slice" - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vec_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vec_type)) { "Vec" - } else if is_type_diagnostic_item(cx, cx.tables.expr_ty(&iter_args[0]), sym!(vecdeque_type)) { + } else if is_type_diagnostic_item(cx, cx.tables().expr_ty(&iter_args[0]), sym!(vecdeque_type)) { "VecDeque" } else { let nth_args = nth_and_iter_args[0]; @@ -2348,7 +2351,7 @@ fn lint_iter_nth<'a, 'tcx>( fn lint_iter_nth_zero<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, nth_args: &'tcx [hir::Expr<'_>]) { if_chain! { if match_trait_method(cx, expr, &paths::ITERATOR); - if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &nth_args[1]); + if let Some((Constant::Int(0), _)) = constant(cx, cx.tables(), &nth_args[1]); then { let mut applicability = Applicability::MachineApplicable; span_lint_and_sugg( @@ -2373,7 +2376,7 @@ fn lint_get_unwrap<'a, 'tcx>( // Note: we don't want to lint `get_mut().unwrap` for `HashMap` or `BTreeMap`, // because they do not implement `IndexMut` let mut applicability = Applicability::MachineApplicable; - let expr_ty = cx.tables.expr_ty(&get_args[0]); + let expr_ty = cx.tables().expr_ty(&get_args[0]); let get_args_str = if get_args.len() > 1 { snippet_with_applicability(cx, get_args[1].span, "_", &mut applicability) } else { @@ -2479,7 +2482,7 @@ fn derefs_to_slice<'a, 'tcx>( } if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind { - if path.ident.name == sym!(iter) && may_slice(cx, cx.tables.expr_ty(&args[0])) { + if path.ident.name == sym!(iter) && may_slice(cx, cx.tables().expr_ty(&args[0])) { Some(&args[0]) } else { None @@ -2502,7 +2505,7 @@ fn derefs_to_slice<'a, 'tcx>( /// lint use of `unwrap()` for `Option`s and `Result`s fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&unwrap_args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&unwrap_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((UNWRAP_USED, "an Option", "None")) @@ -2530,7 +2533,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi /// lint use of `expect()` for `Option`s and `Result`s fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&expect_args[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&expect_args[0])); let mess = if is_type_diagnostic_item(cx, obj_ty, sym!(option_type)) { Some((EXPECT_USED, "an Option", "None")) @@ -2556,8 +2559,8 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir::Expr<'_>]) { if_chain! { // lint if the caller of `ok()` is a `Result` - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&ok_args[0]), sym!(result_type)); - let result_type = cx.tables.expr_ty(&ok_args[0]); + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&ok_args[0]), sym!(result_type)); + let result_type = cx.tables().expr_ty(&ok_args[0]); if let Some(error_type) = get_error_type(cx, result_type); if has_debug_impl(error_type, cx); @@ -2595,7 +2598,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr< } // lint if caller of `.map().flatten()` is an Option - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) { + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { let msg = "called `map(..).flatten()` on an `Option`. \ This is more succinctly expressed by calling `.and_then(..)`"; let self_snippet = snippet(cx, map_args[0].span, ".."); @@ -2621,8 +2624,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>( unwrap_args: &'tcx [hir::Expr<'_>], ) { // lint if the caller of `map()` is an `Option` - let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(result_type)); if is_option || is_result { // Don't make a suggestion that may fail to compile due to mutably borrowing @@ -2676,8 +2679,8 @@ fn lint_map_or_none<'a, 'tcx>( expr: &'tcx hir::Expr<'_>, map_or_args: &'tcx [hir::Expr<'_>], ) { - let is_option = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(option_type)); - let is_result = is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_or_args[0]), sym!(result_type)); + let is_option = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(option_type)); + let is_result = is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_or_args[0]), sym!(result_type)); // There are two variants of this `map_or` lint: // (1) using `map_or` as an adapter from `Result` to `Option` @@ -3042,7 +3045,7 @@ fn lint_chars_cmp( if segment.ident.name == sym!(Some); then { let mut applicability = Applicability::MachineApplicable; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty_adjusted(&args[0][0])); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty_adjusted(&args[0][0])); if self_ty.kind != ty::Str { return false; @@ -3174,8 +3177,8 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, call_name: &str, a if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) { // check if the type after `as_ref` or `as_mut` is the same as before let recvr = &as_ref_args[0]; - let rcv_ty = cx.tables.expr_ty(recvr); - let res_ty = cx.tables.expr_ty(expr); + let rcv_ty = cx.tables().expr_ty(recvr); + let res_ty = cx.tables().expr_ty(expr); let (base_res_ty, res_depth) = walk_ptrs_ty_depth(res_ty); let (base_rcv_ty, rcv_depth) = walk_ptrs_ty_depth(rcv_ty); if base_rcv_ty == base_res_ty && rcv_depth >= res_depth { @@ -3244,7 +3247,7 @@ fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir if args.is_empty(); if let hir::ExprKind::Path(ref path) = callee.kind; if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT); - if !is_maybe_uninit_ty_valid(cx, cx.tables.expr_ty_adjusted(outer)); + if !is_maybe_uninit_ty_valid(cx, cx.tables().expr_ty_adjusted(outer)); then { span_lint( cx, @@ -3286,7 +3289,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( ) { let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not); - let option_ty = cx.tables.expr_ty(&as_ref_args[0]); + let option_ty = cx.tables().expr_ty(&as_ref_args[0]); if !is_type_diagnostic_item(cx, option_ty, sym!(option_type)) { return; } @@ -3314,12 +3317,12 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if_chain! { if args.len() == 1; if let hir::ExprKind::Path(qpath) = &args[0].kind; - if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, args[0].hir_id); + if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, args[0].hir_id); if closure_body.params[0].pat.hir_id == local_id; - let adj = cx.tables.expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); + let adj = cx.tables().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::>(); if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj; then { - let method_did = cx.tables.type_dependent_def_id(closure_expr.hir_id).unwrap(); + let method_did = cx.tables().type_dependent_def_id(closure_expr.hir_id).unwrap(); deref_aliases.iter().any(|path| match_def_path(cx, method_did, path)) } else { false @@ -3331,7 +3334,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>( if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind; if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind; if let hir::ExprKind::Path(ref qpath) = inner2.kind; - if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, inner2.hir_id); + if let hir::def::Res::Local(local_id) = cx.tables().qpath_res(qpath, inner2.hir_id); then { closure_body.params[0].pat.hir_id == local_id } else { @@ -3614,7 +3617,7 @@ fn contains_return(expr: &hir::Expr<'_>) -> bool { fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { if_chain! { if args.len() == 2; - if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables.expr_ty(&args[0]).kind; + if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables().expr_ty(&args[0]).kind; if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)); if layout.is_zst(); then { @@ -3624,7 +3627,7 @@ fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[ } fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); if !match_type(cx, ty, &paths::FILE_TYPE) { return; diff --git a/src/tools/clippy/clippy_lints/src/methods/option_map_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/methods/option_map_unwrap_or.rs index 20c60ef33189d..7f4529a5870ac 100644 --- a/src/tools/clippy/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/src/tools/clippy/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -20,8 +20,8 @@ pub(super) fn lint<'a, 'tcx>( map_span: Span, ) { // lint if the caller of `map()` is an `Option` - if is_type_diagnostic_item(cx, cx.tables.expr_ty(&map_args[0]), sym!(option_type)) { - if !is_copy(cx, cx.tables.expr_ty(&unwrap_args[1])) { + if is_type_diagnostic_item(cx, cx.tables().expr_ty(&map_args[0]), sym!(option_type)) { + if !is_copy(cx, cx.tables().expr_ty(&unwrap_args[1])) { // Do not lint if the `map` argument uses identifiers in the `map` // argument that are also used in the `unwrap_or` argument diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs index 41c9ce7cda3e6..88243a88d9dd7 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -65,7 +65,7 @@ fn check_expression<'a, 'tcx>( if match_qpath(path, &paths::OPTION_SOME) { if_chain! { if let hir::ExprKind::Path(path) = &args[0].kind; - if let Res::Local(ref local) = cx.tables.qpath_res(path, args[0].hir_id); + if let Res::Local(ref local) = cx.tables().qpath_res(path, args[0].hir_id); then { if arg_id == *local { return (false, false) diff --git a/src/tools/clippy/clippy_lints/src/minmax.rs b/src/tools/clippy/clippy_lints/src/minmax.rs index b02c993de526b..8e6f3925d6605 100644 --- a/src/tools/clippy/clippy_lints/src/minmax.rs +++ b/src/tools/clippy/clippy_lints/src/minmax.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass { } match ( outer_max, - Constant::partial_cmp(cx.tcx, cx.tables.expr_ty(ie), &outer_c, &inner_c), + Constant::partial_cmp(cx.tcx, cx.tables().expr_ty(ie), &outer_c, &inner_c), ) { (_, None) | (MinMax::Max, Some(Ordering::Less)) | (MinMax::Min, Some(Ordering::Greater)) => (), _ => { @@ -62,15 +62,18 @@ enum MinMax { fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> { if let ExprKind::Call(ref path, ref args) = expr.kind { if let ExprKind::Path(ref qpath) = path.kind { - cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| { - if match_def_path(cx, def_id, &paths::CMP_MIN) { - fetch_const(cx, args, MinMax::Min) - } else if match_def_path(cx, def_id, &paths::CMP_MAX) { - fetch_const(cx, args, MinMax::Max) - } else { - None - } - }) + cx.tables() + .qpath_res(qpath, path.hir_id) + .opt_def_id() + .and_then(|def_id| { + if match_def_path(cx, def_id, &paths::CMP_MIN) { + fetch_const(cx, args, MinMax::Min) + } else if match_def_path(cx, def_id, &paths::CMP_MAX) { + fetch_const(cx, args, MinMax::Max) + } else { + None + } + }) } else { None } @@ -87,14 +90,14 @@ fn fetch_const<'a>( if args.len() != 2 { return None; } - if let Some(c) = constant_simple(cx, cx.tables, &args[0]) { - if constant_simple(cx, cx.tables, &args[1]).is_none() { + if let Some(c) = constant_simple(cx, cx.tables(), &args[0]) { + if constant_simple(cx, cx.tables(), &args[1]).is_none() { // otherwise ignore Some((m, c, &args[1])) } else { None } - } else if let Some(c) = constant_simple(cx, cx.tables, &args[1]) { + } else if let Some(c) = constant_simple(cx, cx.tables(), &args[1]) { Some((m, c, &args[0])) } else { None diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs index a0947608e6077..99cd864cae4e3 100644 --- a/src/tools/clippy/clippy_lints/src/misc.rs +++ b/src/tools/clippy/clippy_lints/src/misc.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints { binding != "_result" && // FIXME: #944 is_used(cx, expr) && // don't lint if the declaration is in a macro - non_macro_local(cx, cx.tables.qpath_res(qpath, expr.hir_id)) + non_macro_local(cx, cx.tables().qpath_res(qpath, expr.hir_id)) { Some(binding) } else { @@ -496,7 +496,7 @@ fn get_lint_and_message( fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { if_chain! { if !in_constant(cx, cmp_expr.hir_id); - if let Some((value, _)) = constant(cx, cx.tables, expr); + if let Some((value, _)) = constant(cx, cx.tables(), expr); then { let needs_lint = match value { Constant::F32(num) => num.is_nan(), @@ -517,7 +517,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) { } fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { - if let Some((_, res)) = constant(cx, cx.tables, expr) { + if let Some((_, res)) = constant(cx, cx.tables(), expr) { res } else { false @@ -525,7 +525,7 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) } fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool { - match constant(cx, cx.tables, expr) { + match constant(cx, cx.tables(), expr) { Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(), Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f { @@ -557,7 +557,7 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - let value = &walk_ptrs_ty(cx.tables.expr_ty(expr)).kind; + let value = &walk_ptrs_ty(cx.tables().expr_ty(expr)).kind; if let ty::Array(arr_ty, _) = value { return matches!(arr_ty.kind, ty::Float(_)); @@ -567,14 +567,14 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - matches!(&walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Array(_, _)) + matches!(&walk_ptrs_ty(cx.tables().expr_ty(expr)).kind, ty::Array(_, _)) } fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { let (arg_ty, snip) = match expr.kind { ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => { if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) { - (cx.tables.expr_ty_adjusted(&args[0]), snippet(cx, args[0].span, "..")) + (cx.tables().expr_ty_adjusted(&args[0]), snippet(cx, args[0].span, "..")) } else { return; } @@ -582,7 +582,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { ExprKind::Call(ref path, ref v) if v.len() == 1 => { if let ExprKind::Path(ref path) = path.kind { if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) { - (cx.tables.expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, "..")) + (cx.tables().expr_ty_adjusted(&v[0]), snippet(cx, v[0].span, "..")) } else { return; } @@ -593,7 +593,7 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) { _ => return, }; - let other_ty = cx.tables.expr_ty_adjusted(other); + let other_ty = cx.tables().expr_ty_adjusted(other); let partial_eq_trait_id = match cx.tcx.lang_items().eq_trait() { Some(id) => id, None => return, diff --git a/src/tools/clippy/clippy_lints/src/modulo_arithmetic.rs b/src/tools/clippy/clippy_lints/src/modulo_arithmetic.rs index 4ca90455bc4d1..f76e4721e1f63 100644 --- a/src/tools/clippy/clippy_lints/src/modulo_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/modulo_arithmetic.rs @@ -37,8 +37,8 @@ struct OperandInfo { } fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option { - match constant(cx, cx.tables, operand) { - Some((Constant::Int(v), _)) => match cx.tables.expr_ty(expr).kind { + match constant(cx, cx.tables(), operand) { + Some((Constant::Int(v), _)) => match cx.tables().expr_ty(expr).kind { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); return Some(OperandInfo { @@ -106,7 +106,7 @@ fn check_const_operands<'a, 'tcx>( } fn check_non_const_operands<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, operand: &Expr<'_>) { - let operand_type = cx.tables.expr_ty(operand); + let operand_type = cx.tables().expr_ty(operand); if might_have_negative_value(operand_type) { span_lint_and_then( cx, diff --git a/src/tools/clippy/clippy_lints/src/mut_key.rs b/src/tools/clippy/clippy_lints/src/mut_key.rs index 93569a04f7a3a..755b196c698c2 100644 --- a/src/tools/clippy/clippy_lints/src/mut_key.rs +++ b/src/tools/clippy/clippy_lints/src/mut_key.rs @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType { if let hir::PatKind::Wild = local.pat.kind { return; } - check_ty(cx, local.span, cx.tables.pat_ty(&*local.pat)); + check_ty(cx, local.span, cx.tables().pat_ty(&*local.pat)); } } diff --git a/src/tools/clippy/clippy_lints/src/mut_mut.rs b/src/tools/clippy/clippy_lints/src/mut_mut.rs index f7a20a74b85e2..6aa77b4df83aa 100644 --- a/src/tools/clippy/clippy_lints/src/mut_mut.rs +++ b/src/tools/clippy/clippy_lints/src/mut_mut.rs @@ -69,7 +69,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { expr.span, "generally you want to avoid `&mut &mut _` if possible", ); - } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables.expr_ty(e).kind { + } else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.tables().expr_ty(e).kind { span_lint( self.cx, MUT_MUT, diff --git a/src/tools/clippy/clippy_lints/src/mut_reference.rs b/src/tools/clippy/clippy_lints/src/mut_reference.rs index 7fcf15f8acbe8..dbe257069c3e2 100644 --- a/src/tools/clippy/clippy_lints/src/mut_reference.rs +++ b/src/tools/clippy/clippy_lints/src/mut_reference.rs @@ -37,14 +37,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { check_arguments( cx, arguments, - cx.tables.expr_ty(fn_expr), + cx.tables().expr_ty(fn_expr), &rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)), ); } }, ExprKind::MethodCall(ref path, _, ref arguments, _) => { - let def_id = cx.tables.type_dependent_def_id(e.hir_id).unwrap(); - let substs = cx.tables.node_substs(e.hir_id); + let def_id = cx.tables().type_dependent_def_id(e.hir_id).unwrap(); + let substs = cx.tables().node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, &path.ident.as_str()) }, diff --git a/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs b/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs index 119e0905ff442..45db5140711ad 100644 --- a/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs +++ b/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { return; }, ExprKind::Path(_) => { - if let Some(adj) = self.cx.tables.adjustments().get(expr.hir_id) { + if let Some(adj) = self.cx.tables().adjustments().get(expr.hir_id) { if adj .iter() .any(|a| matches!(a.target.kind, ty::Ref(_, _, Mutability::Mut))) diff --git a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs index 78b15afc5a7fa..c227dc54f2939 100644 --- a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs +++ b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs @@ -66,7 +66,7 @@ declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Adt(_, subst) = ty.kind { if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) { let mutex_param = subst.type_at(0); diff --git a/src/tools/clippy/clippy_lints/src/needless_bool.rs b/src/tools/clippy/clippy_lints/src/needless_bool.rs index 15b129fa09802..653f9e2ae8625 100644 --- a/src/tools/clippy/clippy_lints/src/needless_bool.rs +++ b/src/tools/clippy/clippy_lints/src/needless_bool.rs @@ -229,7 +229,7 @@ fn check_comparison<'a, 'tcx>( use self::Expression::{Bool, Other}; if let ExprKind::Binary(op, ref left_side, ref right_side) = e.kind { - let (l_ty, r_ty) = (cx.tables.expr_ty(left_side), cx.tables.expr_ty(right_side)); + let (l_ty, r_ty) = (cx.tables().expr_ty(left_side), cx.tables().expr_ty(right_side)); if l_ty.is_bool() && r_ty.is_bool() { let mut applicability = Applicability::MachineApplicable; diff --git a/src/tools/clippy/clippy_lints/src/needless_borrow.rs b/src/tools/clippy/clippy_lints/src/needless_borrow.rs index 5880d1d610206..6bb06defb7034 100644 --- a/src/tools/clippy/clippy_lints/src/needless_borrow.rs +++ b/src/tools/clippy/clippy_lints/src/needless_borrow.rs @@ -46,8 +46,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { return; } if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind { - if let ty::Ref(..) = cx.tables.expr_ty(inner).kind { - for adj3 in cx.tables.expr_adjustments(e).windows(3) { + if let ty::Ref(..) = cx.tables().expr_ty(inner).kind { + for adj3 in cx.tables().expr_adjustments(e).windows(3) { if let [Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { @@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } if_chain! { if let PatKind::Binding(BindingAnnotation::Ref, .., name, _) = pat.kind; - if let ty::Ref(_, tam, mutbl) = cx.tables.pat_ty(pat).kind; + if let ty::Ref(_, tam, mutbl) = cx.tables().pat_ty(pat).kind; if mutbl == Mutability::Not; if let ty::Ref(_, _, mutbl) = tam.kind; // only lint immutable refs, because borrowed `&mut T` cannot be moved out diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index ca87deac9891c..6954f0cc683f1 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { } = { let mut ctx = MovedVariablesCtxt::default(); cx.tcx.infer_ctxt().enter(|infcx| { - euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body); + euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables()).consume_body(body); }); ctx }; @@ -173,13 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { !preds.is_empty() && { let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); preds.iter().all(|t| { - let ty_params = &t - .skip_binder() - .trait_ref - .substs - .iter() - .skip(1) - .collect::>(); + let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1).collect::>(); implements_trait(cx, ty_empty_region, t.def_id(), ty_params) }) }, diff --git a/src/tools/clippy/clippy_lints/src/needless_update.rs b/src/tools/clippy/clippy_lints/src/needless_update.rs index d866bab2f642c..9b556dbb8540e 100644 --- a/src/tools/clippy/clippy_lints/src/needless_update.rs +++ b/src/tools/clippy/clippy_lints/src/needless_update.rs @@ -47,7 +47,7 @@ declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind { - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if let ty::Adt(def, _) = ty.kind { if fields.len() == def.non_enum_variant().fields.len() { span_lint( diff --git a/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 54536ed57d3e9..0f56daa3659e8 100644 --- a/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd { then { - let ty = cx.tables.expr_ty(left); + let ty = cx.tables().expr_ty(left); let implements_ord = { if let Some(id) = utils::get_trait_def_id(cx, &paths::ORD) { diff --git a/src/tools/clippy/clippy_lints/src/neg_multiply.rs b/src/tools/clippy/clippy_lints/src/neg_multiply.rs index 4681e990df88a..a9ce01b67b097 100644 --- a/src/tools/clippy/clippy_lints/src/neg_multiply.rs +++ b/src/tools/clippy/clippy_lints/src/neg_multiply.rs @@ -44,8 +44,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply { fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) { if_chain! { if let ExprKind::Lit(ref l) = lit.kind; - if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit)); - if cx.tables.expr_ty(exp).is_integral(); + if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables().expr_ty_opt(lit)); + if cx.tables().expr_ty(exp).is_integral(); then { span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`"); } diff --git a/src/tools/clippy/clippy_lints/src/new_without_default.rs b/src/tools/clippy/clippy_lints/src/new_without_default.rs index dd236535c18ad..42200385932b0 100644 --- a/src/tools/clippy/clippy_lints/src/new_without_default.rs +++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs @@ -33,7 +33,7 @@ declare_clippy_lint! { /// } /// ``` /// - /// To fix the lint, and a `Default` implementation that delegates to `new`: + /// To fix the lint, add a `Default` implementation that delegates to `new`: /// /// ```ignore /// struct Foo(Bar); diff --git a/src/tools/clippy/clippy_lints/src/no_effect.rs b/src/tools/clippy/clippy_lints/src/no_effect.rs index 2eacd3c80c486..5fdc656580f29 100644 --- a/src/tools/clippy/clippy_lints/src/no_effect.rs +++ b/src/tools/clippy/clippy_lints/src/no_effect.rs @@ -48,7 +48,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { } match expr.kind { ExprKind::Lit(..) | ExprKind::Closure(..) => true, - ExprKind::Path(..) => !has_drop(cx, cx.tables.expr_ty(expr)), + ExprKind::Path(..) => !has_drop(cx, cx.tables().expr_ty(expr)), ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => { has_no_effect(cx, a) && has_no_effect(cx, b) }, @@ -61,7 +61,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => has_no_effect(cx, inner), ExprKind::Struct(_, ref fields, ref base) => { - !has_drop(cx, cx.tables.expr_ty(expr)) + !has_drop(cx, cx.tables().expr_ty(expr)) && fields.iter().all(|field| has_no_effect(cx, &field.expr)) && base.as_ref().map_or(true, |base| has_no_effect(cx, base)) }, @@ -70,7 +70,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { let res = qpath_res(cx, qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) => { - !has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) + !has_drop(cx, cx.tables().expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg)) }, _ => false, } @@ -137,7 +137,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option | ExprKind::AddrOf(_, _, ref inner) | ExprKind::Box(ref inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])), ExprKind::Struct(_, ref fields, ref base) => { - if has_drop(cx, cx.tables.expr_ty(expr)) { + if has_drop(cx, cx.tables().expr_ty(expr)) { None } else { Some(fields.iter().map(|f| &f.expr).chain(base).map(Deref::deref).collect()) @@ -148,7 +148,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option let res = qpath_res(cx, qpath, callee.hir_id); match res { Res::Def(DefKind::Struct | DefKind::Variant | DefKind::Ctor(..), ..) - if !has_drop(cx, cx.tables.expr_ty(expr)) => + if !has_drop(cx, cx.tables().expr_ty(expr)) => { Some(args.iter().collect()) }, diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 230dfd2ebf566..21d7a7439f25c 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -237,13 +237,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { } let ty = if needs_check_adjustment { - let adjustments = cx.tables.expr_adjustments(dereferenced_expr); + let adjustments = cx.tables().expr_adjustments(dereferenced_expr); if let Some(i) = adjustments.iter().position(|adj| match adj.kind { Adjust::Borrow(_) | Adjust::Deref(_) => true, _ => false, }) { if i == 0 { - cx.tables.expr_ty(dereferenced_expr) + cx.tables().expr_ty(dereferenced_expr) } else { adjustments[i - 1].target } @@ -252,7 +252,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { return; } } else { - cx.tables.expr_ty(dereferenced_expr) + cx.tables().expr_ty(dereferenced_expr) }; verify_ty_bound(cx, ty, Source::Expr { expr: expr.span }); diff --git a/src/tools/clippy/clippy_lints/src/open_options.rs b/src/tools/clippy/clippy_lints/src/open_options.rs index 2d4629b683f05..2467a14cea12f 100644 --- a/src/tools/clippy/clippy_lints/src/open_options.rs +++ b/src/tools/clippy/clippy_lints/src/open_options.rs @@ -30,7 +30,7 @@ declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = e.kind { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) { let mut options = Vec::new(); get_open_options(cx, &arguments[0], &mut options); @@ -58,7 +58,7 @@ enum OpenOption { fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr<'_>, options: &mut Vec<(OpenOption, Argument)>) { if let ExprKind::MethodCall(ref path, _, ref arguments, _) = argument.kind { - let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0])); + let obj_ty = walk_ptrs_ty(cx.tables().expr_ty(&arguments[0])); // Only proceed if this is a call on some object of type std::fs::OpenOptions if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && arguments.len() >= 2 { diff --git a/src/tools/clippy/clippy_lints/src/overflow_check_conditional.rs b/src/tools/clippy/clippy_lints/src/overflow_check_conditional.rs index b90fdc232e72c..5984b09120d0e 100644 --- a/src/tools/clippy/clippy_lints/src/overflow_check_conditional.rs +++ b/src/tools/clippy/clippy_lints/src/overflow_check_conditional.rs @@ -36,8 +36,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = second.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables.expr_ty(ident1).is_integral(); - if cx.tables.expr_ty(ident2).is_integral(); + if cx.tables().expr_ty(ident1).is_integral(); + if cx.tables().expr_ty(ident2).is_integral(); then { if let BinOpKind::Lt = op.node { if let BinOpKind::Add = op2.node { @@ -61,8 +61,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional { if let ExprKind::Path(QPath::Resolved(_, ref path2)) = ident2.kind; if let ExprKind::Path(QPath::Resolved(_, ref path3)) = first.kind; if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]); - if cx.tables.expr_ty(ident1).is_integral(); - if cx.tables.expr_ty(ident2).is_integral(); + if cx.tables().expr_ty(ident1).is_integral(); + if cx.tables().expr_ty(ident2).is_integral(); then { if let BinOpKind::Gt = op.node { if let BinOpKind::Add = op2.node { diff --git a/src/tools/clippy/clippy_lints/src/path_buf_push_overwrite.rs b/src/tools/clippy/clippy_lints/src/path_buf_push_overwrite.rs index 88ad1e0914f25..f26a5258782a7 100644 --- a/src/tools/clippy/clippy_lints/src/path_buf_push_overwrite.rs +++ b/src/tools/clippy/clippy_lints/src/path_buf_push_overwrite.rs @@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; if path.ident.name == sym!(push); if args.len() == 2; - if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(&args[0])), &paths::PATH_BUF); + if match_type(cx, walk_ptrs_ty(cx.tables().expr_ty(&args[0])), &paths::PATH_BUF); if let Some(get_index_arg) = args.get(1); if let ExprKind::Lit(ref lit) = get_index_arg.kind; if let LitKind::Str(ref path_lit, _) = lit.node; diff --git a/src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs b/src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs index d23d7e59b73fc..b35a7e64bff27 100644 --- a/src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs +++ b/src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs @@ -105,12 +105,12 @@ fn expr_as_ptr_offset_call<'a, 'tcx>( // Is the type of the expression a usize? fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - cx.tables.expr_ty(expr) == cx.tcx.types.usize + cx.tables().expr_ty(expr) == cx.tcx.types.usize } // Is the type of the expression a raw pointer? fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool { - cx.tables.expr_ty(expr).is_unsafe_ptr() + cx.tables().expr_ty(expr).is_unsafe_ptr() } fn build_suggestion<'a, 'tcx>( diff --git a/src/tools/clippy/clippy_lints/src/question_mark.rs b/src/tools/clippy/clippy_lints/src/question_mark.rs index d8a73f8054bca..4a6395da01c99 100644 --- a/src/tools/clippy/clippy_lints/src/question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/question_mark.rs @@ -135,13 +135,13 @@ impl QuestionMark { } fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables.expr_ty(expression); + let expr_ty = cx.tables().expr_ty(expression); !expr_ty.is_copy_modulo_regions(cx.tcx.at(expression.span), cx.param_env) } fn is_option(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool { - let expr_ty = cx.tables.expr_ty(expression); + let expr_ty = cx.tables().expr_ty(expression); is_type_diagnostic_item(cx, expr_ty, sym!(option_type)) } @@ -158,7 +158,7 @@ impl QuestionMark { ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr), ExprKind::Path(ref qp) => { if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) = - cx.tables.qpath_res(qp, expression.hir_id) + cx.tables().qpath_res(qp, expression.hir_id) { return match_def_path(cx, def_id, &paths::OPTION_NONE); } diff --git a/src/tools/clippy/clippy_lints/src/ranges.rs b/src/tools/clippy/clippy_lints/src/ranges.rs index fcd02a196e7bf..43ef236a92420 100644 --- a/src/tools/clippy/clippy_lints/src/ranges.rs +++ b/src/tools/clippy/clippy_lints/src/ranges.rs @@ -272,10 +272,10 @@ fn check_reversed_empty_range(cx: &LateContext<'_, '_>, expr: &Expr<'_>) { if_chain! { if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr); - let ty = cx.tables.expr_ty(start); + let ty = cx.tables().expr_ty(start); if let ty::Int(_) | ty::Uint(_) = ty.kind; - if let Some((start_idx, _)) = constant(cx, cx.tables, start); - if let Some((end_idx, _)) = constant(cx, cx.tables, end); + if let Some((start_idx, _)) = constant(cx, cx.tables(), start); + if let Some((end_idx, _)) = constant(cx, cx.tables(), end); if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx); if is_empty_range(limits, ordering); then { diff --git a/src/tools/clippy/clippy_lints/src/redundant_pattern_matching.rs b/src/tools/clippy/clippy_lints/src/redundant_pattern_matching.rs index f16b916441ae8..3c528a295b044 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_pattern_matching.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_pattern_matching.rs @@ -1,10 +1,13 @@ -use crate::utils::{match_qpath, match_trait_method, paths, snippet, span_lint_and_then}; +use crate::utils::{in_constant, match_qpath, match_trait_method, paths, snippet, span_lint_and_then}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; -use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind, QPath}; +use rustc_hir::{Arm, Expr, ExprKind, HirId, MatchSource, PatKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; +use rustc_mir::const_eval::is_const_fn; use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::source_map::Symbol; declare_clippy_lint! { /// **What it does:** Lint for redundant pattern matching over `Result` or @@ -64,26 +67,37 @@ fn find_sugg_for_if_let<'a, 'tcx>( arms: &[Arm<'_>], keyword: &'static str, ) { + fn find_suggestion(cx: &LateContext<'_, '_>, hir_id: HirId, path: &QPath<'_>) -> Option<&'static str> { + if match_qpath(path, &paths::RESULT_OK) && can_suggest(cx, hir_id, sym!(result_type), "is_ok") { + return Some("is_ok()"); + } + if match_qpath(path, &paths::RESULT_ERR) && can_suggest(cx, hir_id, sym!(result_type), "is_err") { + return Some("is_err()"); + } + if match_qpath(path, &paths::OPTION_SOME) && can_suggest(cx, hir_id, sym!(option_type), "is_some") { + return Some("is_some()"); + } + if match_qpath(path, &paths::OPTION_NONE) && can_suggest(cx, hir_id, sym!(option_type), "is_none") { + return Some("is_none()"); + } + None + } + + let hir_id = expr.hir_id; let good_method = match arms[0].pat.kind { PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => { if let PatKind::Wild = patterns[0].kind { - if match_qpath(path, &paths::RESULT_OK) { - "is_ok()" - } else if match_qpath(path, &paths::RESULT_ERR) { - "is_err()" - } else if match_qpath(path, &paths::OPTION_SOME) { - "is_some()" - } else { - return; - } + find_suggestion(cx, hir_id, path) } else { - return; + None } }, - - PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => "is_none()", - - _ => return, + PatKind::Path(ref path) => find_suggestion(cx, hir_id, path), + _ => None, + }; + let good_method = match good_method { + Some(method) => method, + None => return, }; // check that `while_let_on_iterator` lint does not trigger @@ -128,6 +142,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ if arms.len() == 2 { let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind); + let hir_id = expr.hir_id; let found_good_method = match node_pair { ( PatKind::TupleStruct(ref path_left, ref patterns_left, _), @@ -142,6 +157,8 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ &paths::RESULT_ERR, "is_ok()", "is_err()", + || can_suggest(cx, hir_id, sym!(result_type), "is_ok"), + || can_suggest(cx, hir_id, sym!(result_type), "is_err"), ) } else { None @@ -160,6 +177,8 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ &paths::OPTION_NONE, "is_some()", "is_none()", + || can_suggest(cx, hir_id, sym!(option_type), "is_some"), + || can_suggest(cx, hir_id, sym!(option_type), "is_none"), ) } else { None @@ -188,6 +207,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ } } +#[allow(clippy::too_many_arguments)] fn find_good_method_for_match<'a>( arms: &[Arm<'_>], path_left: &QPath<'_>, @@ -196,6 +216,8 @@ fn find_good_method_for_match<'a>( expected_right: &[&str], should_be_left: &'a str, should_be_right: &'a str, + can_suggest_left: impl Fn() -> bool, + can_suggest_right: impl Fn() -> bool, ) -> Option<&'a str> { let body_node_pair = if match_qpath(path_left, expected_left) && match_qpath(path_right, expected_right) { (&(*arms[0].body).kind, &(*arms[1].body).kind) @@ -207,10 +229,32 @@ fn find_good_method_for_match<'a>( match body_node_pair { (ExprKind::Lit(ref lit_left), ExprKind::Lit(ref lit_right)) => match (&lit_left.node, &lit_right.node) { - (LitKind::Bool(true), LitKind::Bool(false)) => Some(should_be_left), - (LitKind::Bool(false), LitKind::Bool(true)) => Some(should_be_right), + (LitKind::Bool(true), LitKind::Bool(false)) if can_suggest_left() => Some(should_be_left), + (LitKind::Bool(false), LitKind::Bool(true)) if can_suggest_right() => Some(should_be_right), _ => None, }, _ => None, } } + +fn can_suggest(cx: &LateContext<'_, '_>, hir_id: HirId, diag_item: Symbol, name: &str) -> bool { + if !in_constant(cx, hir_id) { + return true; + } + + // Avoid suggesting calls to non-`const fn`s in const contexts, see #5697. + cx.tcx + .get_diagnostic_item(diag_item) + .and_then(|def_id| { + cx.tcx.inherent_impls(def_id).iter().find_map(|imp| { + cx.tcx + .associated_items(*imp) + .in_definition_order() + .find_map(|item| match item.kind { + ty::AssocKind::Fn if item.ident.name.as_str() == name => Some(item.def_id), + _ => None, + }) + }) + }) + .map_or(false, |def_id| is_const_fn(cx.tcx, def_id)) +} diff --git a/src/tools/clippy/clippy_lints/src/regex.rs b/src/tools/clippy/clippy_lints/src/regex.rs index a2c35c4267344..9c54c3cbac02b 100644 --- a/src/tools/clippy/clippy_lints/src/regex.rs +++ b/src/tools/clippy/clippy_lints/src/regex.rs @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { if_chain! { if self.last.is_none(); if let Some(ref expr) = block.expr; - if match_type(cx, cx.tables.expr_ty(expr), &paths::REGEX); + if match_type(cx, cx.tables().expr_ty(expr), &paths::REGEX); if let Some(span) = is_expn_of(expr.span, "regex"); then { if !self.spans.contains(&span) { @@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; if args.len() == 1; - if let Some(def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); then { if match_def_path(cx, def_id, &paths::REGEX_NEW) || match_def_path(cx, def_id, &paths::REGEX_BUILDER_NEW) { @@ -140,7 +140,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span { } fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option { - constant(cx, cx.tables, e).and_then(|(c, _)| match c { + constant(cx, cx.tables(), e).and_then(|(c, _)| match c { Constant::Str(s) => Some(s), _ => None, }) diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index 68c36f9189184..4780249bcb8e3 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -164,7 +164,7 @@ fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bin } fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool { - let var_ty = cx.tables.node_type_opt(pat_id); + let var_ty = cx.tables().node_type_opt(pat_id); if let Some(var_ty) = var_ty { match var_ty.kind { ty::Adt(..) => false, diff --git a/src/tools/clippy/clippy_lints/src/strings.rs b/src/tools/clippy/clippy_lints/src/strings.rs index d8e4bff3d702a..ef66850358e57 100644 --- a/src/tools/clippy/clippy_lints/src/strings.rs +++ b/src/tools/clippy/clippy_lints/src/strings.rs @@ -134,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd { } fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { - is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), sym!(string_type)) + is_type_diagnostic_item(cx, walk_ptrs_ty(cx.tables().expr_ty(e)), sym!(string_type)) } fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool { diff --git a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs index a9e6fa329c0f0..cf71c3144a2eb 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs @@ -184,7 +184,7 @@ struct BinaryExprVisitor { in_binary_expr: bool, } -impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor { +impl<'tcx> Visitor<'tcx> for BinaryExprVisitor { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { diff --git a/src/tools/clippy/clippy_lints/src/swap.rs b/src/tools/clippy/clippy_lints/src/swap.rs index c52e6a643f2a2..7fdc872c01f54 100644 --- a/src/tools/clippy/clippy_lints/src/swap.rs +++ b/src/tools/clippy/clippy_lints/src/swap.rs @@ -194,7 +194,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a E if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind { if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind { if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) { - let ty = walk_ptrs_ty(cx.tables.expr_ty(lhs1)); + let ty = walk_ptrs_ty(cx.tables().expr_ty(lhs1)); if matches!(ty.kind, ty::Slice(_)) || matches!(ty.kind, ty::Array(_, _)) diff --git a/src/tools/clippy/clippy_lints/src/temporary_assignment.rs b/src/tools/clippy/clippy_lints/src/temporary_assignment.rs index bbb883aaf3287..f2bbf19bea92f 100644 --- a/src/tools/clippy/clippy_lints/src/temporary_assignment.rs +++ b/src/tools/clippy/clippy_lints/src/temporary_assignment.rs @@ -26,7 +26,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { match &expr.kind { ExprKind::Struct(..) | ExprKind::Tup(..) => true, ExprKind::Path(qpath) => { - if let Res::Def(DefKind::Const, ..) = cx.tables.qpath_res(qpath, expr.hir_id) { + if let Res::Def(DefKind::Const, ..) = cx.tables().qpath_res(qpath, expr.hir_id) { true } else { false diff --git a/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs b/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs index 4f132c6db76fa..1efba3580fef0 100644 --- a/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs +++ b/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if to_digits_path.ident.name.as_str() == "to_digit"; - let char_arg_ty = cx.tables.expr_ty_adjusted(char_arg); + let char_arg_ty = cx.tables().expr_ty_adjusted(char_arg); if char_arg_ty.kind == ty::Char; then { Some((true, char_arg, radix_arg)) @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome { if_chain! { if let [char_arg, radix_arg] = &**to_digit_args; if let hir::ExprKind::Path(to_digits_path) = &to_digits_call.kind; - if let to_digits_call_res = cx.tables.qpath_res(to_digits_path, to_digits_call.hir_id); + if let to_digits_call_res = cx.tables().qpath_res(to_digits_path, to_digits_call.hir_id); if let Some(to_digits_def_id) = to_digits_call_res.opt_def_id(); if match_def_path(cx, to_digits_def_id, &["core", "char", "methods", "", "to_digit"]); then { diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs index 67121729663c6..1b233b8302f93 100644 --- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs +++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { return; } let hash = |ty| -> u64 { - let mut hasher = SpanlessHash::new(cx, cx.tables); + let mut hasher = SpanlessHash::new(cx, cx.tables()); hasher.hash_ty(ty); hasher.finish() }; diff --git a/src/tools/clippy/clippy_lints/src/transmute.rs b/src/tools/clippy/clippy_lints/src/transmute.rs index 1869638f6ffb1..9b1344949470a 100644 --- a/src/tools/clippy/clippy_lints/src/transmute.rs +++ b/src/tools/clippy/clippy_lints/src/transmute.rs @@ -299,11 +299,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { if_chain! { if let ExprKind::Call(ref path_expr, ref args) = e.kind; if let ExprKind::Path(ref qpath) = path_expr.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(qpath, path_expr.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::TRANSMUTE); then { - let from_ty = cx.tables.expr_ty(&args[0]); - let to_ty = cx.tables.expr_ty(e); + let from_ty = cx.tables().expr_ty(&args[0]); + let to_ty = cx.tables().expr_ty(e); match (&from_ty.kind, &to_ty.kind) { _ if from_ty == to_ty => span_lint( diff --git a/src/tools/clippy/clippy_lints/src/transmuting_null.rs b/src/tools/clippy/clippy_lints/src/transmuting_null.rs index 1d0332c580500..3351488a45c4d 100644 --- a/src/tools/clippy/clippy_lints/src/transmuting_null.rs +++ b/src/tools/clippy/clippy_lints/src/transmuting_null.rs @@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull { then { // Catching transmute over constants that resolve to `null`. - let mut const_eval_context = constant_context(cx, cx.tables); + let mut const_eval_context = constant_context(cx, cx.tables()); if_chain! { if let ExprKind::Path(ref _qpath) = args[0].kind; let x = const_eval_context.expr(&args[0]); diff --git a/src/tools/clippy/clippy_lints/src/trivially_copy_pass_by_ref.rs b/src/tools/clippy/clippy_lints/src/trivially_copy_pass_by_ref.rs index 8e0cb94317aff..146ac4b09d5a4 100644 --- a/src/tools/clippy/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/src/tools/clippy/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -58,7 +58,7 @@ pub struct TriviallyCopyPassByRef { limit: u64, } -impl<'a, 'tcx> TriviallyCopyPassByRef { +impl<'tcx> TriviallyCopyPassByRef { pub fn new(limit: Option, target: &SessionConfig) -> Self { let limit = limit.unwrap_or_else(|| { let bit_width = u64::from(target.ptr_width); diff --git a/src/tools/clippy/clippy_lints/src/try_err.rs b/src/tools/clippy/clippy_lints/src/try_err.rs index 7018fa6804ba7..e129dd84d15a6 100644 --- a/src/tools/clippy/clippy_lints/src/try_err.rs +++ b/src/tools/clippy/clippy_lints/src/try_err.rs @@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr { if let Some(return_type) = find_err_return_type(cx, &expr.kind); then { - let err_type = cx.tables.expr_ty(err_arg); + let err_type = cx.tables().expr_ty(err_arg); let origin_snippet = if err_arg.span.from_expansion() { snippet_with_macro_callsite(cx, err_arg.span, "_") } else { @@ -114,7 +114,7 @@ fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm if match_qpath(from_error_fn, &paths::TRY_FROM_ERROR); if let Some(from_error_arg) = from_error_args.get(0); then { - Some(cx.tables.expr_ty(from_error_arg)) + Some(cx.tables().expr_ty(from_error_arg)) } else { None } diff --git a/src/tools/clippy/clippy_lints/src/types.rs b/src/tools/clippy/clippy_lints/src/types.rs index d59a2f1bae031..ecfb6ee2a7de9 100644 --- a/src/tools/clippy/clippy_lints/src/types.rs +++ b/src/tools/clippy/clippy_lints/src/types.rs @@ -603,7 +603,7 @@ declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue { fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) { if let StmtKind::Local(ref local) = stmt.kind { - if is_unit(cx.tables.pat_ty(&local.pat)) { + if is_unit(cx.tables().pat_ty(&local.pat)) { if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { return; } @@ -688,7 +688,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables.expr_ty(left)) { + if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { let result = match &*symbol.as_str() { "assert_eq" | "debug_assert_eq" => "succeed", "assert_ne" | "debug_assert_ne" => "fail", @@ -712,7 +712,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { } if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; - if op.is_comparison() && is_unit(cx.tables.expr_ty(left)) { + if op.is_comparison() && is_unit(cx.tables().expr_ty(left)) { let result = match op { BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true", _ => "false", @@ -782,7 +782,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { let args_to_recover = args .iter() .filter(|arg| { - if is_unit(cx.tables.expr_ty(arg)) && !is_unit_literal(arg) { + if is_unit(cx.tables().expr_ty(arg)) && !is_unit_literal(arg) { if let ExprKind::Match(.., MatchSource::TryDesugar) = &arg.kind { false } else { @@ -1250,7 +1250,7 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, } // don't lint for positive constants - let const_val = constant(cx, &cx.tables, op); + let const_val = constant(cx, &cx.tables(), op); if_chain! { if let Some((const_val, _)) = const_val; if let Constant::Int(n) = const_val; @@ -1416,7 +1416,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts { return; } if let ExprKind::Cast(ref ex, _) = expr.kind { - let (cast_from, cast_to) = (cx.tables.expr_ty(ex), cx.tables.expr_ty(expr)); + let (cast_from, cast_to) = (cx.tables().expr_ty(ex), cx.tables().expr_ty(expr)); lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to); if let ExprKind::Lit(ref lit) = ex.kind { if_chain! { @@ -1804,7 +1804,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { if let ExprKind::Cast(e, _) = &expr.kind; if let ExprKind::Lit(l) = &e.kind; if let LitKind::Char(c) = l.node; - if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).kind; + if ty::Uint(UintTy::U8) == cx.tables().expr_ty(expr).kind; then { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); @@ -1880,8 +1880,8 @@ enum AbsurdComparisonResult { fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let precast_ty = cx.tables.expr_ty(cast_exp); - let cast_ty = cx.tables.expr_ty(expr); + let precast_ty = cx.tables().expr_ty(cast_exp); + let cast_ty = cx.tables().expr_ty(expr); return is_isize_or_usize(precast_ty) != is_isize_or_usize(cast_ty); } @@ -1901,7 +1901,7 @@ fn detect_absurd_comparison<'a, 'tcx>( // absurd comparison only makes sense on primitive types // primitive types don't implement comparison operators with each other - if cx.tables.expr_ty(lhs) != cx.tables.expr_ty(rhs) { + if cx.tables().expr_ty(lhs) != cx.tables().expr_ty(rhs) { return None; } @@ -1939,22 +1939,18 @@ fn detect_absurd_comparison<'a, 'tcx>( fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option> { use crate::types::ExtremeType::{Maximum, Minimum}; - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); - let cv = constant(cx, cx.tables, expr)?.0; + let cv = constant(cx, cx.tables(), expr)?.0; let which = match (&ty.kind, cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, - (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => - { + (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { Minimum }, (&ty::Bool, Constant::Bool(true)) => Maximum, - (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => - { + (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { Maximum }, (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum, @@ -2075,58 +2071,28 @@ impl Ord for FullInt { fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { if let ExprKind::Cast(ref cast_exp, _) = expr.kind { - let pre_cast_ty = cx.tables.expr_ty(cast_exp); - let cast_ty = cx.tables.expr_ty(expr); + let pre_cast_ty = cx.tables().expr_ty(cast_exp); + let cast_ty = cx.tables().expr_ty(expr); // if it's a cast from i32 to u32 wrapping will invalidate all these checks if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) { return None; } match pre_cast_ty.kind { ty::Int(int_ty) => Some(match int_ty { - IntTy::I8 => ( - FullInt::S(i128::from(i8::MIN)), - FullInt::S(i128::from(i8::MAX)), - ), - IntTy::I16 => ( - FullInt::S(i128::from(i16::MIN)), - FullInt::S(i128::from(i16::MAX)), - ), - IntTy::I32 => ( - FullInt::S(i128::from(i32::MIN)), - FullInt::S(i128::from(i32::MAX)), - ), - IntTy::I64 => ( - FullInt::S(i128::from(i64::MIN)), - FullInt::S(i128::from(i64::MAX)), - ), + IntTy::I8 => (FullInt::S(i128::from(i8::MIN)), FullInt::S(i128::from(i8::MAX))), + IntTy::I16 => (FullInt::S(i128::from(i16::MIN)), FullInt::S(i128::from(i16::MAX))), + IntTy::I32 => (FullInt::S(i128::from(i32::MIN)), FullInt::S(i128::from(i32::MAX))), + IntTy::I64 => (FullInt::S(i128::from(i64::MIN)), FullInt::S(i128::from(i64::MAX))), IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)), - IntTy::Isize => ( - FullInt::S(isize::MIN as i128), - FullInt::S(isize::MAX as i128), - ), + IntTy::Isize => (FullInt::S(isize::MIN as i128), FullInt::S(isize::MAX as i128)), }), ty::Uint(uint_ty) => Some(match uint_ty { - UintTy::U8 => ( - FullInt::U(u128::from(u8::MIN)), - FullInt::U(u128::from(u8::MAX)), - ), - UintTy::U16 => ( - FullInt::U(u128::from(u16::MIN)), - FullInt::U(u128::from(u16::MAX)), - ), - UintTy::U32 => ( - FullInt::U(u128::from(u32::MIN)), - FullInt::U(u128::from(u32::MAX)), - ), - UintTy::U64 => ( - FullInt::U(u128::from(u64::MIN)), - FullInt::U(u128::from(u64::MAX)), - ), + UintTy::U8 => (FullInt::U(u128::from(u8::MIN)), FullInt::U(u128::from(u8::MAX))), + UintTy::U16 => (FullInt::U(u128::from(u16::MIN)), FullInt::U(u128::from(u16::MAX))), + UintTy::U32 => (FullInt::U(u128::from(u32::MIN)), FullInt::U(u128::from(u32::MAX))), + UintTy::U64 => (FullInt::U(u128::from(u64::MIN)), FullInt::U(u128::from(u64::MAX))), UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)), - UintTy::Usize => ( - FullInt::U(usize::MIN as u128), - FullInt::U(usize::MAX as u128), - ), + UintTy::Usize => (FullInt::U(usize::MIN as u128), FullInt::U(usize::MAX as u128)), }), _ => None, } @@ -2136,9 +2102,9 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) } fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option { - let val = constant(cx, cx.tables, expr)?.0; + let val = constant(cx, cx.tables(), expr)?.0; if let Constant::Int(const_int) = val { - match cx.tables.expr_ty(expr).kind { + match cx.tables().expr_ty(expr).kind { ty::Int(ity) => Some(FullInt::S(sext(cx.tcx, const_int, ity))), ty::Uint(_) => Some(FullInt::U(const_int)), _ => None, @@ -2533,7 +2499,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, - body: cx.tables, + body: cx.tables(), target, suggestions: BTreeMap::new(), } @@ -2642,7 +2608,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { if let TyKind::Ptr(MutTy { mutbl: Mutability::Mut, .. }) = t.kind; if let ExprKind::Cast(e, t) = &e.kind; if let TyKind::Ptr(MutTy { mutbl: Mutability::Not, .. }) = t.kind; - if let ty::Ref(..) = cx.tables.node_type(e.hir_id).kind; + if let ty::Ref(..) = cx.tables().node_type(e.hir_id).kind; then { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/unnamed_address.rs b/src/tools/clippy/clippy_lints/src/unnamed_address.rs index 4e077b95b5c68..53e47f09ae55c 100644 --- a/src/tools/clippy/clippy_lints/src/unnamed_address.rs +++ b/src/tools/clippy/clippy_lints/src/unnamed_address.rs @@ -65,14 +65,14 @@ impl LateLintPass<'_, '_> for UnnamedAddress { } fn is_trait_ptr(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - match cx.tables.expr_ty_adjusted(expr).kind { + match cx.tables().expr_ty_adjusted(expr).kind { ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(), _ => false, } } fn is_fn_def(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { - if let ty::FnDef(..) = cx.tables.expr_ty(expr).kind { + if let ty::FnDef(..) = cx.tables().expr_ty(expr).kind { true } else { false @@ -98,11 +98,11 @@ impl LateLintPass<'_, '_> for UnnamedAddress { if_chain! { if let ExprKind::Call(ref func, [ref _left, ref _right]) = expr.kind; if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if let Some(def_id) = cx.tables().qpath_res(func_qpath, func.hir_id).opt_def_id(); if match_def_path(cx, def_id, &paths::PTR_EQ) || match_def_path(cx, def_id, &paths::RC_PTR_EQ) || match_def_path(cx, def_id, &paths::ARC_PTR_EQ); - let ty_param = cx.tables.node_substs(func.hir_id).type_at(0); + let ty_param = cx.tables().node_substs(func.hir_id).type_at(0); if ty_param.is_trait(); then { span_lint_and_help( @@ -119,8 +119,8 @@ impl LateLintPass<'_, '_> for UnnamedAddress { if_chain! { if let ExprKind::Binary(binop, ref left, ref right) = expr.kind; if is_comparison(binop.node); - if cx.tables.expr_ty_adjusted(left).is_fn_ptr() && - cx.tables.expr_ty_adjusted(right).is_fn_ptr(); + if cx.tables().expr_ty_adjusted(left).is_fn_ptr() && + cx.tables().expr_ty_adjusted(right).is_fn_ptr(); if is_fn_def(cx, left) || is_fn_def(cx, right); then { span_lint( diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs index e94eebb88e497..bb68e50b33195 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs @@ -95,7 +95,10 @@ fn mirrored_exprs( // The two exprs are method calls. // Check to see that the function is the same and the arguments are mirrored // This is enough because the receiver of the method is listed in the arguments - (ExprKind::MethodCall(left_segment, _, left_args, _), ExprKind::MethodCall(right_segment, _, right_args, _)) => { + ( + ExprKind::MethodCall(left_segment, _, left_args, _), + ExprKind::MethodCall(right_segment, _, right_args, _), + ) => { left_segment.ident == right_segment.ident && left_args .iter() @@ -174,7 +177,7 @@ fn detect_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option if let name = name_ident.ident.name.to_ident_string(); if name == "sort_by" || name == "sort_unstable_by"; if let [vec, Expr { kind: ExprKind::Closure(_, _, closure_body_id, _, _), .. }] = args; - if utils::match_type(cx, &cx.tables.expr_ty(vec), &paths::VEC); + if utils::match_type(cx, &cx.tables().expr_ty(vec), &paths::VEC); if let closure_body = cx.tcx.hir().body(*closure_body_id); if let &[ Param { pat: Pat { kind: PatKind::Binding(_, _, left_ident, _), .. }, ..}, diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 8c281126c32bf..4d3682263f14f 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -45,7 +45,7 @@ declare_clippy_lint! { /// } /// ``` pub UNNESTED_OR_PATTERNS, - complexity, + pedantic, "unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`" } diff --git a/src/tools/clippy/clippy_lints/src/unwrap.rs b/src/tools/clippy/clippy_lints/src/unwrap.rs index a6c7b5d405cda..be55982f90556 100644 --- a/src/tools/clippy/clippy_lints/src/unwrap.rs +++ b/src/tools/clippy/clippy_lints/src/unwrap.rs @@ -114,7 +114,7 @@ fn collect_unwrap_info<'a, 'tcx>( if_chain! { if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind; if let ExprKind::Path(QPath::Resolved(None, path)) = &args[0].kind; - let ty = cx.tables.expr_ty(&args[0]); + let ty = cx.tables().expr_ty(&args[0]); let name = method_name.ident.as_str(); if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); then { diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs index 78d249482d53d..5d150ad4f03e4 100644 --- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs +++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs @@ -63,8 +63,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { ExprKind::MethodCall(ref name, .., ref args, _) => { if match_trait_method(cx, e, &paths::INTO) && &*name.ident.as_str() == "into" { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet_with_macro_callsite(cx, args[0].span, "").to_string(); span_lint_and_sugg( @@ -79,8 +79,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } } if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if TyS::same_type(a, b) { let sugg = snippet(cx, args[0].span, "").into_owned(); span_lint_and_sugg( @@ -96,8 +96,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { } if match_trait_method(cx, e, &paths::TRY_INTO_TRAIT) && &*name.ident.as_str() == "try_into" { if_chain! { - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); if is_type_diagnostic_item(cx, a, sym!(result_type)); if let ty::Adt(_, substs) = a.kind; if let Some(a_type) = substs.types().next(); @@ -121,9 +121,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion { if_chain! { if args.len() == 1; if let ExprKind::Path(ref qpath) = path.kind; - if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id(); - let a = cx.tables.expr_ty(e); - let b = cx.tables.expr_ty(&args[0]); + if let Some(def_id) = cx.tables().qpath_res(qpath, path.hir_id).opt_def_id(); + let a = cx.tables().expr_ty(e); + let b = cx.tables().expr_ty(&args[0]); then { if_chain! { diff --git a/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs b/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs index e60e2a81e070b..e19a79dd8dad1 100755 --- a/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs +++ b/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs @@ -476,7 +476,7 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool { && match (&l.kind, &r.kind) { (Lifetime, Lifetime) => true, (Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)), - (Const { ty: l }, Const { ty: r }) => eq_ty(l, r), + (Const { ty: l, kw_span: _ }, Const { ty: r, kw_span: _ }) => eq_ty(l, r), _ => false, } && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 8b58bbb5e6575..910b665ccb75e 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -251,7 +251,10 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { } }, ExprKind::MethodCall(ref _method_name, ref _generics, ref _args, ref _fn_span) => { - println!("MethodCall(ref method_name, ref generics, ref args, ref fn_span) = {};", current); + println!( + "MethodCall(ref method_name, ref generics, ref args, ref fn_span) = {};", + current + ); println!(" // unimplemented: `ExprKind::MethodCall` is not further destructured at the moment"); }, ExprKind::Tup(ref elements) => { diff --git a/src/tools/clippy/clippy_lints/src/utils/conf.rs b/src/tools/clippy/clippy_lints/src/utils/conf.rs index 9e8e0ff30ec6b..c41befbf147b8 100644 --- a/src/tools/clippy/clippy_lints/src/utils/conf.rs +++ b/src/tools/clippy/clippy_lints/src/utils/conf.rs @@ -106,8 +106,8 @@ macro_rules! define_Conf { pub use self::helpers::Conf; define_Conf! { - /// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about - (blacklisted_names, "blacklisted_names": Vec, ["foo", "bar", "baz", "quux"].iter().map(ToString::to_string).collect()), + /// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses + (blacklisted_names, "blacklisted_names": Vec, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()), /// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have (cognitive_complexity_threshold, "cognitive_complexity_threshold": u64, 25), /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead. diff --git a/src/tools/clippy/clippy_lints/src/utils/higher.rs b/src/tools/clippy/clippy_lints/src/utils/higher.rs index 33fba7df8d336..0e78f35a1290a 100644 --- a/src/tools/clippy/clippy_lints/src/utils/higher.rs +++ b/src/tools/clippy/clippy_lints/src/utils/higher.rs @@ -56,7 +56,7 @@ pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr<'_>) Some(expr) } - let def_path = match cx.tables.expr_ty(expr).kind { + let def_path = match cx.tables().expr_ty(expr).kind { ty::Adt(def, _) => cx.tcx.def_path(def.did), _ => return None, }; @@ -262,7 +262,7 @@ pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Optio if let hir::ExprKind::Call(ref fun, ref args) = expr.kind; if let hir::ExprKind::Path(ref qpath) = fun.kind; if is_expn_of(fun.span, "vec").is_some(); - if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); then { return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 { // `vec![elem; size]` case diff --git a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs index 7a84f1c986aa7..a74ab18a063b2 100644 --- a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs +++ b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { Self { cx, - tables: cx.tables, + tables: cx.tables(), ignore_fn: false, } } @@ -40,7 +40,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn ignore_fn(self) -> Self { Self { cx: self.cx, - tables: self.cx.tables, + tables: self.cx.tables(), ignore_fn: true, } } @@ -309,18 +309,15 @@ fn swap_binop<'a>( rhs: &'a Expr<'a>, ) -> Option<(BinOpKind, &'a Expr<'a>, &'a Expr<'a>)> { match binop { - BinOpKind::Add - | BinOpKind::Mul - | BinOpKind::Eq - | BinOpKind::Ne - | BinOpKind::BitAnd - | BinOpKind::BitXor - | BinOpKind::BitOr => Some((binop, rhs, lhs)), + BinOpKind::Add | BinOpKind::Eq | BinOpKind::Ne | BinOpKind::BitAnd | BinOpKind::BitXor | BinOpKind::BitOr => { + Some((binop, rhs, lhs)) + }, BinOpKind::Lt => Some((BinOpKind::Gt, rhs, lhs)), BinOpKind::Le => Some((BinOpKind::Ge, rhs, lhs)), BinOpKind::Ge => Some((BinOpKind::Le, rhs, lhs)), BinOpKind::Gt => Some((BinOpKind::Lt, rhs, lhs)), - BinOpKind::Shl + BinOpKind::Mul // Not always commutative, e.g. with matrices. See issue #5698 + | BinOpKind::Shl | BinOpKind::Shr | BinOpKind::Rem | BinOpKind::Sub diff --git a/src/tools/clippy/clippy_lints/src/utils/inspector.rs b/src/tools/clippy/clippy_lints/src/utils/inspector.rs index afde971f9df4e..3f5659c3d8c0f 100644 --- a/src/tools/clippy/clippy_lints/src/utils/inspector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/inspector.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector { } match stmt.kind { hir::StmtKind::Local(ref local) => { - println!("local variable of type {}", cx.tables.node_type(local.hir_id)); + println!("local variable of type {}", cx.tables().node_type(local.hir_id)); println!("pattern:"); print_pat(cx, &local.pat, 0); if let Some(ref e) = local.init { @@ -144,8 +144,8 @@ fn has_attr(sess: &Session, attrs: &[Attribute]) -> bool { fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) { let ind = " ".repeat(indent); println!("{}+", ind); - println!("{}ty: {}", ind, cx.tables.expr_ty(expr)); - println!("{}adjustments: {:?}", ind, cx.tables.adjustments().get(expr.hir_id)); + println!("{}ty: {}", ind, cx.tables().expr_ty(expr)); + println!("{}adjustments: {:?}", ind, cx.tables().adjustments().get(expr.hir_id)); match expr.kind { hir::ExprKind::Box(ref e) => { println!("{}Box", ind); diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs index 89e2bcdd7935d..38468181d0261 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs @@ -347,7 +347,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool { ) = ty.kind { if let TyKind::Path(ref path) = inner.kind { - if let Res::Def(DefKind::Struct, def_id) = cx.tables.qpath_res(path, inner.hir_id) { + if let Res::Def(DefKind::Struct, def_id) = cx.tables().qpath_res(path, inner.hir_id) { return match_def_path(cx, def_id, &paths::LINT); } } @@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind; let fn_name = path.ident; if let Some(sugg) = self.map.get(&*fn_name.as_str()); - let ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0])); + let ty = walk_ptrs_ty(cx.tables().expr_ty(&args[0])); if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT); then { @@ -438,7 +438,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { let args = arg_lists[1]; if args.len() == 1; let self_arg = &args[0]; - let self_ty = walk_ptrs_ty(cx.tables.expr_ty(self_arg)); + let self_ty = walk_ptrs_ty(cx.tables().expr_ty(self_arg)); if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT); then { span_lint_and_sugg( diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 6d4c6c6ce1cea..69ec4b7ad6d18 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -151,7 +151,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_, '_>, ty: Ty<'_>, diag_item: /// Checks if the method call given in `expr` belongs to the given trait. pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr<'_>, path: &[&str]) -> bool { - let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap(); let trt_id = cx.tcx.trait_of_item(def_id); if let Some(trt_id) = trt_id { match_def_path(cx, trt_id, path) @@ -824,7 +824,7 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool { /// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more /// information on adjustments and coercions. pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool { - cx.tables.adjustments().get(e.hir_id).is_some() + cx.tables().adjustments().get(e.hir_id).is_some() } /// Returns the pre-expansion span if is this comes from an expansion of the @@ -898,7 +898,7 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { - let res = cx.tables.qpath_res(qp, fun.hir_id); + let res = cx.tables().qpath_res(qp, fun.hir_id); return match res { def::Res::Def(DefKind::Variant | DefKind::Ctor(..), ..) => true, def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), @@ -914,7 +914,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( - cx.tables.qpath_res(qpath, id), + cx.tables().qpath_res(qpath, id), def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _) ) } @@ -941,7 +941,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) }, PatKind::Slice(ref head, ref middle, ref tail) => { - match &cx.tables.node_type(pat.hir_id).kind { + match &cx.tables().node_type(pat.hir_id).kind { ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() @@ -1190,7 +1190,7 @@ pub fn match_function_call<'a, 'tcx>( if_chain! { if let ExprKind::Call(ref fun, ref args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; - if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id(); + if let Some(fun_def_id) = cx.tables().qpath_res(qpath, fun.hir_id).opt_def_id(); if match_def_path(cx, fun_def_id, path); then { return Some(&args) @@ -1317,14 +1317,14 @@ pub fn is_must_use_func_call(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool let did = match expr.kind { ExprKind::Call(ref path, _) => if_chain! { if let ExprKind::Path(ref qpath) = path.kind; - if let def::Res::Def(_, did) = cx.tables.qpath_res(qpath, path.hir_id); + if let def::Res::Def(_, did) = cx.tables().qpath_res(qpath, path.hir_id); then { Some(did) } else { None } }, - ExprKind::MethodCall(_, _, _, _) => cx.tables.type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(_, _, _, _) => cx.tables().type_dependent_def_id(expr.hir_id), _ => None, }; diff --git a/src/tools/clippy/clippy_lints/src/utils/sugg.rs b/src/tools/clippy/clippy_lints/src/utils/sugg.rs index 73758b7eeb7eb..e919b1522d89a 100644 --- a/src/tools/clippy/clippy_lints/src/utils/sugg.rs +++ b/src/tools/clippy/clippy_lints/src/utils/sugg.rs @@ -509,7 +509,7 @@ fn indentation(cx: &T, span: Span) -> Option { } /// Convenience extension trait for `DiagnosticBuilder`. -pub trait DiagnosticBuilderExt<'a, T: LintContext> { +pub trait DiagnosticBuilderExt { /// Suggests to add an attribute to an item. /// /// Correctly handles indentation of the attribute and item. @@ -556,7 +556,7 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext> { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl<'a, 'b, 'c, T: LintContext> DiagnosticBuilderExt<'c, T> for rustc_errors::DiagnosticBuilder<'b> { +impl DiagnosticBuilderExt for rustc_errors::DiagnosticBuilder<'_> { fn suggest_item_with_attr( &mut self, cx: &T, diff --git a/src/tools/clippy/clippy_lints/src/utils/usage.rs b/src/tools/clippy/clippy_lints/src/utils/usage.rs index 6a7a1f1ceaaef..d280fe4ab4e02 100644 --- a/src/tools/clippy/clippy_lints/src/utils/usage.rs +++ b/src/tools/clippy/clippy_lints/src/utils/usage.rs @@ -8,7 +8,7 @@ use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_middle::ty; use rustc_span::symbol::{Ident, Symbol}; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase}; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, 'tcx>) -> Option> { @@ -18,7 +18,7 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a, }; let def_id = expr.hir_id.owner.to_def_id(); cx.tcx.infer_ctxt().enter(|infcx| { - ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables).walk_expr(expr); + ExprUseVisitor::new(&mut delegate, &infcx, def_id.expect_local(), cx.param_env, cx.tables()).walk_expr(expr); }); if delegate.skip { diff --git a/src/tools/clippy/clippy_lints/src/vec.rs b/src/tools/clippy/clippy_lints/src/vec.rs index a8d4c7620b1ef..080785b177d65 100644 --- a/src/tools/clippy/clippy_lints/src/vec.rs +++ b/src/tools/clippy/clippy_lints/src/vec.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { - if let ty::Ref(_, ty, _) = cx.tables.expr_ty_adjusted(expr).kind; + if let ty::Ref(_, ty, _) = cx.tables().expr_ty_adjusted(expr).kind; if let ty::Slice(..) = ty.kind; if let ExprKind::AddrOf(BorrowKind::Ref, _, ref addressee) = expr.kind; if let Some(vec_args) = higher::vec_macro(cx, addressee); @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec { if_chain! { if let Some((_, arg, _)) = higher::for_loop(expr); if let Some(vec_args) = higher::vec_macro(cx, arg); - if is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg))); + if is_copy(cx, vec_type(cx.tables().expr_ty_adjusted(arg))); then { // report the error around the `vec!` not inside `:` let span = arg.span @@ -70,7 +70,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA let mut applicability = Applicability::MachineApplicable; let snippet = match *vec_args { higher::VecArgs::Repeat(elem, len) => { - if constant(cx, cx.tables, len).is_some() { + if constant(cx, cx.tables(), len).is_some() { format!( "&[{}; {}]", snippet_with_applicability(cx, elem.span, "elem", &mut applicability), diff --git a/src/tools/clippy/clippy_lints/src/vec_resize_to_zero.rs b/src/tools/clippy/clippy_lints/src/vec_resize_to_zero.rs index 55758efa32e67..bb315e64e5de1 100644 --- a/src/tools/clippy/clippy_lints/src/vec_resize_to_zero.rs +++ b/src/tools/clippy/clippy_lints/src/vec_resize_to_zero.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VecResizeToZero { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { if_chain! { if let hir::ExprKind::MethodCall(path_segment, _, ref args, _) = expr.kind; - if let Some(method_def_id) = cx.tables.type_dependent_def_id(expr.hir_id); + if let Some(method_def_id) = cx.tables().type_dependent_def_id(expr.hir_id); if match_def_path(cx, method_def_id, &paths::VEC_RESIZE) && args.len() == 3; if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = args[2].kind; diff --git a/src/tools/clippy/clippy_lints/src/verbose_file_reads.rs b/src/tools/clippy/clippy_lints/src/verbose_file_reads.rs index 6d420d491c50f..85f9208457448 100644 --- a/src/tools/clippy/clippy_lints/src/verbose_file_reads.rs +++ b/src/tools/clippy/clippy_lints/src/verbose_file_reads.rs @@ -62,7 +62,7 @@ fn is_file_read_to_end<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'t if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_end"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables.expr_ty(&exprs[0]); + let ty = cx.tables().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true @@ -76,7 +76,7 @@ fn is_file_read_to_string<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr if let ExprKind::MethodCall(method_name, _, exprs, _) = expr.kind; if method_name.ident.as_str() == "read_to_string"; if let ExprKind::Path(QPath::Resolved(None, _)) = &exprs[0].kind; - let ty = cx.tables.expr_ty(&exprs[0]); + let ty = cx.tables().expr_ty(&exprs[0]); if match_type(cx, ty, &paths::FILE); then { return true diff --git a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs index b637253bd0264..79f7705e281e5 100644 --- a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs +++ b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs @@ -36,7 +36,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// **What it does:** Checks for wildcard imports `use _::*`. /// - /// **Why is this bad?** wildcard imports can polute the namespace. This is especially bad if + /// **Why is this bad?** wildcard imports can pollute the namespace. This is especially bad if /// you try to import something through a wildcard, that already has been imported by name from /// a different source: /// diff --git a/src/tools/clippy/clippy_lints/src/zero_div_zero.rs b/src/tools/clippy/clippy_lints/src/zero_div_zero.rs index 0820385e01bb5..f0cf17c3b9549 100644 --- a/src/tools/clippy/clippy_lints/src/zero_div_zero.rs +++ b/src/tools/clippy/clippy_lints/src/zero_div_zero.rs @@ -36,8 +36,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv { // TODO - constant_simple does not fold many operations involving floats. // That's probably fine for this lint - it's pretty unlikely that someone would // do something like 0.0/(2.0 - 2.0), but it would be nice to warn on that case too. - if let Some(lhs_value) = constant_simple(cx, cx.tables, left); - if let Some(rhs_value) = constant_simple(cx, cx.tables, right); + if let Some(lhs_value) = constant_simple(cx, cx.tables(), left); + if let Some(rhs_value) = constant_simple(cx, cx.tables(), right); if Constant::F32(0.0) == lhs_value || Constant::F64(0.0) == lhs_value; if Constant::F32(0.0) == rhs_value || Constant::F64(0.0) == rhs_value; then { diff --git a/src/tools/clippy/doc/common_tools_writing_lints.md b/src/tools/clippy/doc/common_tools_writing_lints.md index dbc434505947d..d06e359bc7aa5 100644 --- a/src/tools/clippy/doc/common_tools_writing_lints.md +++ b/src/tools/clippy/doc/common_tools_writing_lints.md @@ -19,11 +19,11 @@ Useful Rustc dev guide links: Sometimes you may want to retrieve the type `Ty` of an expression `Expr`, for example to answer following questions: - which type does this expression correspond to (using its [`TyKind`][TyKind])? -- is it a sized type? +- is it a sized type? - is it a primitive type? - does it implement a trait? -This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckTables`][TypeckTables] struct, +This operation is performed using the [`expr_ty()`][expr_ty] method from the [`TypeckTables`][TypeckTables] struct, that gives you access to the underlying structure [`TyS`][TyS]. Example of use: @@ -31,7 +31,7 @@ Example of use: impl LateLintPass<'_, '_> for MyStructLint { fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) { // Get type of `expr` - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); // Match its kind to enter its type match ty.kind { ty::Adt(adt_def, _) if adt_def.is_struct() => println!("Our `expr` is a struct!"), @@ -41,14 +41,14 @@ impl LateLintPass<'_, '_> for MyStructLint { } ``` -Similarly in [`TypeckTables`][TypeckTables] methods, you have the [`pat_ty()`][pat_ty] method +Similarly in [`TypeckTables`][TypeckTables] methods, you have the [`pat_ty()`][pat_ty] method to retrieve a type from a pattern. Two noticeable items here: -- `cx` is the lint context [`LateContext`][LateContext]. - The two most useful data structures in this context are `tcx` and `tables`, +- `cx` is the lint context [`LateContext`][LateContext]. + The two most useful data structures in this context are `tcx` and `tables`, allowing us to jump to type definitions and other compilation stages such as HIR. -- `tables` is [`TypeckTables`][TypeckTables] and is created by type checking step, +- `tables` is [`TypeckTables`][TypeckTables] and is created by type checking step, it includes useful information such as types of expressions, ways to resolve methods and so on. # Checking if an expr is calling a specific method @@ -87,7 +87,7 @@ impl LateLintPass<'_, '_> for MyStructLint { } // 2. Using type context `TyCtxt` - let ty = cx.tables.expr_ty(expr); + let ty = cx.tables().expr_ty(expr); if cx.tcx.lang_items() // we are looking for the `DefId` of `Drop` trait in lang items .drop_trait() diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 4453ae5ce4414..decd3a79cce18 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -1,15 +1,16 @@ -#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![feature(rustc_private)] +#![cfg_attr(feature = "deny-warnings", deny(warnings))] +// warn on lints, that are included in `rust-lang/rust`s bootstrap +#![warn(rust_2018_idioms, unused_lifetimes)] +// warn on rustc internal lints +#![deny(rustc::internal)] // FIXME: switch to something more ergonomic here, once available. // (Currently there is no way to opt into sysroot crates without `extern crate`.) -#[allow(unused_extern_crates)] +extern crate rustc_data_structures; extern crate rustc_driver; -#[allow(unused_extern_crates)] extern crate rustc_errors; -#[allow(unused_extern_crates)] extern crate rustc_interface; -#[allow(unused_extern_crates)] extern crate rustc_middle; use rustc_interface::interface; @@ -93,7 +94,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { #[allow(clippy::find_map, clippy::filter_map)] fn describe_lints() { use lintlist::{Level, Lint, ALL_LINTS, LINT_LEVELS}; - use std::collections::HashSet; + use rustc_data_structures::fx::FxHashSet; println!( " @@ -137,7 +138,7 @@ Available lint options: let scoped = |x: &str| format!("clippy::{}", x); - let lint_groups: HashSet<_> = lints.iter().map(|lint| lint.group).collect(); + let lint_groups: FxHashSet<_> = lints.iter().map(|lint| lint.group).collect(); println!("Lint checks provided by clippy:\n"); println!(" {} {:7.7} meaning", padded("name"), "default"); @@ -207,6 +208,7 @@ Usage: Common options: -h, --help Print this message + --rustc Pass all args to rustc -V, --version Print version info and exit Other options are the same as `cargo check`. @@ -297,12 +299,6 @@ pub fn main() { exit(rustc_driver::catch_with_exit_code(move || { let mut orig_args: Vec = env::args().collect(); - if orig_args.iter().any(|a| a == "--version" || a == "-V") { - let version_info = rustc_tools_util::get_version_info!(); - println!("{}", version_info); - exit(0); - } - // Get the sysroot, looking from most specific to this invocation to the least: // - command line // - runtime environment @@ -348,6 +344,28 @@ pub fn main() { .map(|pb| pb.to_string_lossy().to_string()) .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust"); + // make "clippy-driver --rustc" work like a subcommand that passes further args to "rustc" + // for example `clippy-driver --rustc --version` will print the rustc version that clippy-driver + // uses + if let Some(pos) = orig_args.iter().position(|arg| arg == "--rustc") { + orig_args.remove(pos); + orig_args[0] = "rustc".to_string(); + + // if we call "rustc", we need to pass --sysroot here as well + let mut args: Vec = orig_args.clone(); + if !have_sys_root_arg { + args.extend(vec!["--sysroot".into(), sys_root]); + }; + + return rustc_driver::run_compiler(&args, &mut DefaultCallbacks, None, None); + } + + if orig_args.iter().any(|a| a == "--version" || a == "-V") { + let version_info = rustc_tools_util::get_version_info!(); + println!("{}", version_info); + exit(0); + } + // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. // We're invoking the compiler programmatically, so we ignore this/ let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref()); diff --git a/src/tools/clippy/src/lintlist/mod.rs b/src/tools/clippy/src/lintlist/mod.rs index cac3cc6bdb316..edceb75518008 100644 --- a/src/tools/clippy/src/lintlist/mod.rs +++ b/src/tools/clippy/src/lintlist/mod.rs @@ -2329,7 +2329,7 @@ pub static ref ALL_LINTS: Vec = vec![ }, Lint { name: "unnested_or_patterns", - group: "complexity", + group: "pedantic", desc: "unnested or-patterns, e.g., `Foo(Bar) | Foo(Baz) instead of `Foo(Bar | Baz)`", deprecation: None, module: "unnested_or_patterns", diff --git a/src/tools/clippy/src/main.rs b/src/tools/clippy/src/main.rs index bc43a34ed5d4a..6739a4cf2245e 100644 --- a/src/tools/clippy/src/main.rs +++ b/src/tools/clippy/src/main.rs @@ -1,4 +1,6 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] +// warn on lints, that are included in `rust-lang/rust`s bootstrap +#![warn(rust_2018_idioms, unused_lifetimes)] use rustc_tools_util::VersionInfo; use std::env; diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs b/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs new file mode 100644 index 0000000000000..ecb55d8cb48d5 --- /dev/null +++ b/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs @@ -0,0 +1,60 @@ +extern crate macro_rules; + +// STMT +#[macro_export] +macro_rules! pub_macro { + () => { + let _ = "hello Mr. Vonnegut"; + }; +} + +pub mod inner { + pub use super::*; + + // RE-EXPORT + // this will stick in `inner` module + pub use macro_rules::foofoo; + pub use macro_rules::try_err; + + pub mod nested { + pub use macro_rules::string_add; + } + + // ITEM + #[macro_export] + macro_rules! inner_mod_macro { + () => { + #[allow(dead_code)] + pub struct Tardis; + }; + } +} + +// EXPR +#[macro_export] +macro_rules! function_macro { + () => { + if true { + } else { + } + }; +} + +// TYPE +#[macro_export] +macro_rules! ty_macro { + () => { + Vec + }; +} + +mod extern_exports { + pub(super) mod private_inner { + #[macro_export] + macro_rules! pub_in_private_macro { + ($name:ident) => { + let $name = String::from("secrets and lies"); + }; + } + } +} diff --git a/src/tools/clippy/tests/ui/blacklisted_name.rs b/src/tools/clippy/tests/ui/blacklisted_name.rs index ca9d8d16b787d..cb15bdd2f1b2d 100644 --- a/src/tools/clippy/tests/ui/blacklisted_name.rs +++ b/src/tools/clippy/tests/ui/blacklisted_name.rs @@ -12,29 +12,34 @@ fn test(foo: ()) {} fn main() { let foo = 42; - let bar = 42; let baz = 42; + let quux = 42; + // Unlike these others, `bar` is actually considered an acceptable name. + // Among many other legitimate uses, bar commonly refers to a period of time in music. + // See https://github.com/rust-lang/rust-clippy/issues/5225. + let bar = 42; - let barb = 42; - let barbaric = 42; + let food = 42; + let foodstuffs = 42; + let bazaar = 42; match (42, Some(1337), Some(0)) { - (foo, Some(bar), baz @ Some(_)) => (), + (foo, Some(baz), quux @ Some(_)) => (), _ => (), } } fn issue_1647(mut foo: u8) { - let mut bar = 0; - if let Some(mut baz) = Some(42) {} + let mut baz = 0; + if let Some(mut quux) = Some(42) {} } fn issue_1647_ref() { - let ref bar = 0; - if let Some(ref baz) = Some(42) {} + let ref baz = 0; + if let Some(ref quux) = Some(42) {} } fn issue_1647_ref_mut() { - let ref mut bar = 0; - if let Some(ref mut baz) = Some(42) {} + let ref mut baz = 0; + if let Some(ref mut quux) = Some(42) {} } diff --git a/src/tools/clippy/tests/ui/blacklisted_name.stderr b/src/tools/clippy/tests/ui/blacklisted_name.stderr index 44123829fb0f6..70dbdaece8b6b 100644 --- a/src/tools/clippy/tests/ui/blacklisted_name.stderr +++ b/src/tools/clippy/tests/ui/blacklisted_name.stderr @@ -12,77 +12,77 @@ error: use of a blacklisted/placeholder name `foo` LL | let foo = 42; | ^^^ -error: use of a blacklisted/placeholder name `bar` +error: use of a blacklisted/placeholder name `baz` --> $DIR/blacklisted_name.rs:15:9 | -LL | let bar = 42; +LL | let baz = 42; | ^^^ -error: use of a blacklisted/placeholder name `baz` +error: use of a blacklisted/placeholder name `quux` --> $DIR/blacklisted_name.rs:16:9 | -LL | let baz = 42; - | ^^^ +LL | let quux = 42; + | ^^^^ error: use of a blacklisted/placeholder name `foo` - --> $DIR/blacklisted_name.rs:22:10 + --> $DIR/blacklisted_name.rs:27:10 | -LL | (foo, Some(bar), baz @ Some(_)) => (), +LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ -error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:22:20 +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:27:20 | -LL | (foo, Some(bar), baz @ Some(_)) => (), +LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ -error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:22:26 +error: use of a blacklisted/placeholder name `quux` + --> $DIR/blacklisted_name.rs:27:26 | -LL | (foo, Some(bar), baz @ Some(_)) => (), - | ^^^ +LL | (foo, Some(baz), quux @ Some(_)) => (), + | ^^^^ error: use of a blacklisted/placeholder name `foo` - --> $DIR/blacklisted_name.rs:27:19 + --> $DIR/blacklisted_name.rs:32:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ -error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:28:13 +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:33:13 | -LL | let mut bar = 0; +LL | let mut baz = 0; | ^^^ -error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:29:21 +error: use of a blacklisted/placeholder name `quux` + --> $DIR/blacklisted_name.rs:34:21 | -LL | if let Some(mut baz) = Some(42) {} - | ^^^ +LL | if let Some(mut quux) = Some(42) {} + | ^^^^ -error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:33:13 +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:38:13 | -LL | let ref bar = 0; +LL | let ref baz = 0; | ^^^ -error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:34:21 +error: use of a blacklisted/placeholder name `quux` + --> $DIR/blacklisted_name.rs:39:21 | -LL | if let Some(ref baz) = Some(42) {} - | ^^^ +LL | if let Some(ref quux) = Some(42) {} + | ^^^^ -error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:38:17 +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:43:17 | -LL | let ref mut bar = 0; +LL | let ref mut baz = 0; | ^^^ -error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:39:25 +error: use of a blacklisted/placeholder name `quux` + --> $DIR/blacklisted_name.rs:44:25 | -LL | if let Some(ref mut baz) = Some(42) {} - | ^^^ +LL | if let Some(ref mut quux) = Some(42) {} + | ^^^^ error: aborting due to 14 previous errors diff --git a/src/tools/clippy/tests/ui/crashes/ice-5389.rs b/src/tools/clippy/tests/ui/crashes/ice-5389.rs new file mode 100644 index 0000000000000..de262199004b0 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5389.rs @@ -0,0 +1,13 @@ +#![allow(clippy::explicit_counter_loop)] + +fn main() { + let v = vec![1, 2, 3]; + let mut i = 0; + let max_storage_size = [0; 128 * 1024]; + for item in &v { + bar(i, *item); + i += 1; + } +} + +fn bar(_: usize, _: u32) {} diff --git a/src/tools/clippy/tests/ui/if_same_then_else.rs b/src/tools/clippy/tests/ui/if_same_then_else.rs index 6bbf79edfcf70..9c5fe02f7519b 100644 --- a/src/tools/clippy/tests/ui/if_same_then_else.rs +++ b/src/tools/clippy/tests/ui/if_same_then_else.rs @@ -142,4 +142,16 @@ fn func() { fn f(val: &[u8]) {} +mod issue_5698 { + fn mul_not_always_commutative(x: i32, y: i32) -> i32 { + if x == 42 { + x * y + } else if x == 21 { + y * x + } else { + 0 + } + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/macro_use_imports.fixed b/src/tools/clippy/tests/ui/macro_use_imports.fixed new file mode 100644 index 0000000000000..91e34c62160a1 --- /dev/null +++ b/src/tools/clippy/tests/ui/macro_use_imports.fixed @@ -0,0 +1,43 @@ +// compile-flags: --edition 2018 +// aux-build:macro_rules.rs +// aux-build:macro_use_helper.rs +// run-rustfix +// ignore-32bit + +#![allow(unused_imports, unreachable_code, unused_variables, dead_code)] +#![allow(clippy::single_component_path_imports)] +#![warn(clippy::macro_use_imports)] + +#[macro_use] +extern crate macro_use_helper as mac; + +#[macro_use] +extern crate clippy_mini_macro_test as mini_mac; + +mod a { + use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro}; + use mac; + use mini_mac::ClippyMiniMacroTest; + use mini_mac; + use mac::{inner::foofoo, inner::try_err}; + use mac::inner; + use mac::inner::nested::string_add; + use mac::inner::nested; + + #[derive(ClippyMiniMacroTest)] + struct Test; + + fn test() { + pub_macro!(); + inner_mod_macro!(); + pub_in_private_macro!(_var); + function_macro!(); + let v: ty_macro!() = Vec::default(); + + inner::try_err!(); + inner::foofoo!(); + nested::string_add!(); + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/macro_use_imports.rs b/src/tools/clippy/tests/ui/macro_use_imports.rs index 60c64ee8146e5..9c3c50c5d49f2 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports.rs +++ b/src/tools/clippy/tests/ui/macro_use_imports.rs @@ -1,11 +1,43 @@ -// edition:2018 +// compile-flags: --edition 2018 +// aux-build:macro_rules.rs +// aux-build:macro_use_helper.rs +// run-rustfix +// ignore-32bit + +#![allow(unused_imports, unreachable_code, unused_variables, dead_code)] +#![allow(clippy::single_component_path_imports)] #![warn(clippy::macro_use_imports)] -use std::collections::HashMap; #[macro_use] -use std::prelude; +extern crate macro_use_helper as mac; + +#[macro_use] +extern crate clippy_mini_macro_test as mini_mac; + +mod a { + #[macro_use] + use mac; + #[macro_use] + use mini_mac; + #[macro_use] + use mac::inner; + #[macro_use] + use mac::inner::nested; -fn main() { - let _ = HashMap::::new(); - println!(); + #[derive(ClippyMiniMacroTest)] + struct Test; + + fn test() { + pub_macro!(); + inner_mod_macro!(); + pub_in_private_macro!(_var); + function_macro!(); + let v: ty_macro!() = Vec::default(); + + inner::try_err!(); + inner::foofoo!(); + nested::string_add!(); + } } + +fn main() {} diff --git a/src/tools/clippy/tests/ui/macro_use_imports.stderr b/src/tools/clippy/tests/ui/macro_use_imports.stderr index b5e3dbec57277..f8c86c8d9179f 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports.stderr +++ b/src/tools/clippy/tests/ui/macro_use_imports.stderr @@ -1,10 +1,28 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:5:1 + --> $DIR/macro_use_imports.rs:18:5 | -LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use std::prelude::` +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` -error: aborting due to previous error +error: `macro_use` attributes are no longer needed in the Rust 2018 edition + --> $DIR/macro_use_imports.rs:20:5 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` + +error: `macro_use` attributes are no longer needed in the Rust 2018 edition + --> $DIR/macro_use_imports.rs:22:5 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};` + +error: `macro_use` attributes are no longer needed in the Rust 2018 edition + --> $DIR/macro_use_imports.rs:24:5 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + +error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed index fc8cb0e747c73..6ba5cfb1d7177 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed @@ -1,5 +1,7 @@ // run-rustfix +#![feature(const_if_match)] +#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] @@ -67,6 +69,7 @@ fn main() { takes_bool(x); issue5504(); + issue5697(); let _ = if gen_opt().is_some() { 1 @@ -117,3 +120,42 @@ fn issue5504() { if m!().is_some() {} while m!().is_some() {} } + +// None of these should be linted because none of the suggested methods +// are `const fn` without toggling a feature. +const fn issue5697() { + if let Ok(_) = Ok::(42) {} + + if let Err(_) = Err::(42) {} + + if let Some(_) = Some(42) {} + + if let None = None::<()> {} + + while let Ok(_) = Ok::(10) {} + + while let Err(_) = Ok::(10) {} + + while let Some(_) = Some(42) {} + + while let None = None::<()> {} + + match Ok::(42) { + Ok(_) => true, + Err(_) => false, + }; + + match Err::(42) { + Ok(_) => false, + Err(_) => true, + }; + match Some(42) { + Some(_) => true, + None => false, + }; + + match None::<()> { + Some(_) => false, + None => true, + }; +} diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching.rs index 51912dade0356..17de66f9ad0eb 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.rs @@ -1,5 +1,7 @@ // run-rustfix +#![feature(const_if_match)] +#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] @@ -88,6 +90,7 @@ fn main() { takes_bool(x); issue5504(); + issue5697(); let _ = if let Some(_) = gen_opt() { 1 @@ -138,3 +141,42 @@ fn issue5504() { if let Some(_) = m!() {} while let Some(_) = m!() {} } + +// None of these should be linted because none of the suggested methods +// are `const fn` without toggling a feature. +const fn issue5697() { + if let Ok(_) = Ok::(42) {} + + if let Err(_) = Err::(42) {} + + if let Some(_) = Some(42) {} + + if let None = None::<()> {} + + while let Ok(_) = Ok::(10) {} + + while let Err(_) = Ok::(10) {} + + while let Some(_) = Some(42) {} + + while let None = None::<()> {} + + match Ok::(42) { + Ok(_) => true, + Err(_) => false, + }; + + match Err::(42) { + Ok(_) => false, + Err(_) => true, + }; + match Some(42) { + Some(_) => true, + None => false, + }; + + match None::<()> { + Some(_) => false, + None => true, + }; +} diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr index b58deb7954efe..1b9a4b40a2f02 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:8:12 + --> $DIR/redundant_pattern_matching.rs:10:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` @@ -7,67 +7,67 @@ LL | if let Ok(_) = Ok::(42) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:10:12 + --> $DIR/redundant_pattern_matching.rs:12:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:12:12 + --> $DIR/redundant_pattern_matching.rs:14:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try this: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:14:12 + --> $DIR/redundant_pattern_matching.rs:16:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:16:12 + --> $DIR/redundant_pattern_matching.rs:18:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:22:15 + --> $DIR/redundant_pattern_matching.rs:24:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:24:15 + --> $DIR/redundant_pattern_matching.rs:26:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try this: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:26:15 + --> $DIR/redundant_pattern_matching.rs:28:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try this: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:28:15 + --> $DIR/redundant_pattern_matching.rs:30:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:30:15 + --> $DIR/redundant_pattern_matching.rs:32:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:33:15 + --> $DIR/redundant_pattern_matching.rs:35:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try this: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:49:5 + --> $DIR/redundant_pattern_matching.rs:51:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -76,7 +76,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:54:5 + --> $DIR/redundant_pattern_matching.rs:56:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -85,7 +85,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:59:5 + --> $DIR/redundant_pattern_matching.rs:61:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -94,7 +94,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:64:5 + --> $DIR/redundant_pattern_matching.rs:66:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -103,7 +103,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:69:5 + --> $DIR/redundant_pattern_matching.rs:71:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: try this: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:74:5 + --> $DIR/redundant_pattern_matching.rs:76:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:79:13 + --> $DIR/redundant_pattern_matching.rs:81:13 | LL | let _ = match None::<()> { | _____________^ @@ -131,61 +131,61 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:84:20 + --> $DIR/redundant_pattern_matching.rs:86:20 | LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; | -------^^^^^--------------------- help: try this: `if Ok::(4).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:87:20 + --> $DIR/redundant_pattern_matching.rs:89:20 | LL | let x = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try this: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:92:20 + --> $DIR/redundant_pattern_matching.rs:95:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:94:19 + --> $DIR/redundant_pattern_matching.rs:97:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try this: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:96:19 + --> $DIR/redundant_pattern_matching.rs:99:19 | LL | } else if let Ok(_) = gen_res() { | -------^^^^^------------ help: try this: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:98:19 + --> $DIR/redundant_pattern_matching.rs:101:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try this: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:131:19 + --> $DIR/redundant_pattern_matching.rs:134:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:132:16 + --> $DIR/redundant_pattern_matching.rs:135:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:138:12 + --> $DIR/redundant_pattern_matching.rs:141:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try this: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:139:15 + --> $DIR/redundant_pattern_matching.rs:142:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try this: `while m!().is_some()` diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed new file mode 100644 index 0000000000000..c8bc5458067d3 --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed @@ -0,0 +1,46 @@ +// run-rustfix + +#![feature(const_if_match)] +#![feature(const_loop)] +#![feature(const_result)] +#![warn(clippy::redundant_pattern_matching)] +#![allow(unused)] + +// Test that results are linted with the feature enabled. + +const fn issue_5697() { + if Ok::(42).is_ok() {} + + if Err::(42).is_err() {} + + while Ok::(10).is_ok() {} + + while Ok::(10).is_err() {} + + Ok::(42).is_ok(); + + Err::(42).is_err(); + + // These should not be linted until `const_option` is implemented. + // See https://github.com/rust-lang/rust/issues/67441 + + if let Some(_) = Some(42) {} + + if let None = None::<()> {} + + while let Some(_) = Some(42) {} + + while let None = None::<()> {} + + match Some(42) { + Some(_) => true, + None => false, + }; + + match None::<()> { + Some(_) => false, + None => true, + }; +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs new file mode 100644 index 0000000000000..75f37ec15c622 --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs @@ -0,0 +1,52 @@ +// run-rustfix + +#![feature(const_if_match)] +#![feature(const_loop)] +#![feature(const_result)] +#![warn(clippy::redundant_pattern_matching)] +#![allow(unused)] + +// Test that results are linted with the feature enabled. + +const fn issue_5697() { + if let Ok(_) = Ok::(42) {} + + if let Err(_) = Err::(42) {} + + while let Ok(_) = Ok::(10) {} + + while let Err(_) = Ok::(10) {} + + match Ok::(42) { + Ok(_) => true, + Err(_) => false, + }; + + match Err::(42) { + Ok(_) => false, + Err(_) => true, + }; + + // These should not be linted until `const_option` is implemented. + // See https://github.com/rust-lang/rust/issues/67441 + + if let Some(_) = Some(42) {} + + if let None = None::<()> {} + + while let Some(_) = Some(42) {} + + while let None = None::<()> {} + + match Some(42) { + Some(_) => true, + None => false, + }; + + match None::<()> { + Some(_) => false, + None => true, + }; +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr new file mode 100644 index 0000000000000..c32292f0eee8b --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr @@ -0,0 +1,46 @@ +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching_const_result.rs:12:12 + | +LL | if let Ok(_) = Ok::(42) {} + | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` + | + = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching_const_result.rs:14:12 + | +LL | if let Err(_) = Err::(42) {} + | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` + +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching_const_result.rs:16:15 + | +LL | while let Ok(_) = Ok::(10) {} + | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching_const_result.rs:18:15 + | +LL | while let Err(_) = Ok::(10) {} + | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` + +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/redundant_pattern_matching_const_result.rs:20:5 + | +LL | / match Ok::(42) { +LL | | Ok(_) => true, +LL | | Err(_) => false, +LL | | }; + | |_____^ help: try this: `Ok::(42).is_ok()` + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/redundant_pattern_matching_const_result.rs:25:5 + | +LL | / match Err::(42) { +LL | | Ok(_) => false, +LL | | Err(_) => true, +LL | | }; + | |_____^ help: try this: `Err::(42).is_err()` + +error: aborting due to 6 previous errors + diff --git a/src/tools/clippy/tests/ui/repl_uninit.rs b/src/tools/clippy/tests/ui/repl_uninit.rs index 346972b7bb4e0..ad5b8e4857d17 100644 --- a/src/tools/clippy/tests/ui/repl_uninit.rs +++ b/src/tools/clippy/tests/ui/repl_uninit.rs @@ -17,6 +17,12 @@ fn main() { std::mem::forget(mem::replace(&mut v, new_v)); } + unsafe { + let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); + let new_v = might_panic(taken_v); + std::mem::forget(mem::replace(&mut v, new_v)); + } + unsafe { let taken_v = mem::replace(&mut v, mem::zeroed()); let new_v = might_panic(taken_v); diff --git a/src/tools/clippy/tests/ui/repl_uninit.stderr b/src/tools/clippy/tests/ui/repl_uninit.stderr index c1f55d7601e5c..09468eeaea4bf 100644 --- a/src/tools/clippy/tests/ui/repl_uninit.stderr +++ b/src/tools/clippy/tests/ui/repl_uninit.stderr @@ -2,26 +2,29 @@ error: replacing with `mem::uninitialized()` --> $DIR/repl_uninit.rs:15:23 | LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` | = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` - = help: consider using the `take_mut` crate instead -error: replacing with `mem::zeroed()` +error: replacing with `mem::MaybeUninit::uninit().assume_init()` --> $DIR/repl_uninit.rs:21:23 | +LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` + +error: replacing with `mem::zeroed()` + --> $DIR/repl_uninit.rs:27:23 + | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using a default value or the `take_mut` crate instead error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:33:28 + --> $DIR/repl_uninit.rs:39:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider using the `take_mut` crate instead + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 52d0cbd4bfd7a..6ac7c3b9b474a 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -4,7 +4,6 @@ use crate::errors::{Error, ErrorKind}; use crate::runtest::ProcRes; use serde::Deserialize; -use serde_json; use std::path::{Path, PathBuf}; use std::str::FromStr; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index c00b0f02c3a90..2aea4d22700f3 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -1,5 +1,4 @@ #![crate_name = "compiletest"] -#![deny(warnings)] // The `test` crate is the only unstable feature // allowed here, just to share similar code. #![feature(test)] @@ -9,8 +8,6 @@ extern crate test; use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, Pretty, TestPaths}; use crate::util::logv; -use env_logger; -use getopts; use getopts::Options; use log::*; use std::env; diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs index da1d3db49d70e..30a922057eb20 100644 --- a/src/tools/compiletest/src/read2.rs +++ b/src/tools/compiletest/src/read2.rs @@ -25,7 +25,6 @@ mod imp { #[cfg(unix)] mod imp { - use libc; use std::io; use std::io::prelude::*; use std::mem; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 95ea4fb078955..dd0c68ecd4965 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -13,7 +13,6 @@ use crate::header::TestProps; use crate::json; use crate::util::get_pointer_width; use crate::util::{logv, PathBufExt}; -use diff; use regex::{Captures, Regex}; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 3335816f09f0e..097fb1f985a74 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -1,5 +1,4 @@ #![feature(rustc_private)] -#![deny(warnings)] extern crate env_logger; extern crate rustc_ast; diff --git a/src/tools/expand-yaml-anchors/src/main.rs b/src/tools/expand-yaml-anchors/src/main.rs index f2ed8aa409a36..d8dad8fc789e9 100644 --- a/src/tools/expand-yaml-anchors/src/main.rs +++ b/src/tools/expand-yaml-anchors/src/main.rs @@ -165,7 +165,7 @@ struct StrError(String); impl Error for StrError {} impl std::fmt::Display for StrError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(&self.0, f) } } @@ -177,7 +177,7 @@ struct WithContext { } impl std::fmt::Display for WithContext { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.context) } } diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 570ffd5d30622..9e4e2c433fbed 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -14,8 +14,6 @@ //! A few whitelisted exceptions are allowed as there's known bugs in rustdoc, //! but this should catch the majority of "broken link" cases. -#![deny(warnings)] - use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet}; use std::env; diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index 1fafe109d34e1..6245b76fd6e84 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -5,8 +5,6 @@ //! Here is also where we bake in the support to spawn the QEMU emulator as //! well. -#![deny(warnings)] - use std::env; use std::fs::{self, File}; use std::io::prelude::*; diff --git a/src/tools/remote-test-server/src/main.rs b/src/tools/remote-test-server/src/main.rs index 8c56910e2dfad..d92758eb7474c 100644 --- a/src/tools/remote-test-server/src/main.rs +++ b/src/tools/remote-test-server/src/main.rs @@ -10,8 +10,6 @@ //! themselves having support libraries. All data over the TCP sockets is in a //! basically custom format suiting our needs. -#![deny(warnings)] - #[cfg(not(windows))] use std::fs::Permissions; #[cfg(not(windows))] diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index e2856c690550a..2d105c7f33a2b 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -4,8 +4,6 @@ //! etc. This is run by default on `./x.py test` and as part of the auto //! builders. The tidy checks can be executed with `./x.py test tidy`. -#![deny(warnings)] - use tidy::*; use std::env; diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 247e85603cfc2..7e77ae1db0d1b 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -67,6 +67,7 @@ const EXCEPTION_PATHS: &[&str] = &[ // std testing crates, okay for now at least "src/libcore/tests", "src/liballoc/tests/lib.rs", + "src/liballoc/benches/lib.rs", // The `VaList` implementation must have platform specific code. // The Windows implementation of a `va_list` is always a character // pointer regardless of the target architecture. As a result, diff --git a/src/tools/unstable-book-gen/src/main.rs b/src/tools/unstable-book-gen/src/main.rs index c9d1561a9d3d8..aa24881ac6bd7 100644 --- a/src/tools/unstable-book-gen/src/main.rs +++ b/src/tools/unstable-book-gen/src/main.rs @@ -1,7 +1,5 @@ //! Auto-generate stub docs for the unstable book -#![deny(warnings)] - use std::collections::BTreeSet; use std::env; use std::fs::{self, File}; diff --git a/triagebot.toml b/triagebot.toml index 5361a618d4e85..73ca7abfed363 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -76,44 +76,106 @@ exclude_labels = [ ] [notify-zulip."I-prioritize"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "I-prioritize #{number} {title}" -message_on_add = "@*WG-prioritization* issue #{number} has been requested for prioritization." +message_on_add = """\ +@*WG-prioritization/alerts* issue #{number} has been requested for prioritization. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#Unprioritized-I-prioritize) +- Priority? +- Regression? +- Notify people/groups? +- Needs `I-nominated`? +""" message_on_remove = "Issue #{number}'s prioritization request has been removed." [notify-zulip."I-nominated"] required_labels = ["T-compiler"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "I-prioritize #{number} {title}" -message_on_add = "@*WG-prioritization* #{number} has been nominated for discussion in `T-compiler` meeting." +message_on_add = """\ +@*WG-prioritization/alerts* #{number} has been nominated for discussion in `T-compiler` meeting. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#I-nominated) +- Already discussed? +- Worth the meeting time? +- Add agenda entry: + - Why nominated? + - Assignee? + - Issue? PR? What's the status? + - Summary and important details? +""" message_on_remove = "#{number}'s nomination has been removed." [notify-zulip."beta-nominated"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "Backport #{number} {title}" -message_on_add = "@*WG-prioritization* PR #{number} has been requested for beta backport." +message_on_add = """\ +@*WG-prioritization/alerts* PR #{number} has been requested for beta backport. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#StableBeta-nominations) +Prepare agenda entry: +- Why nominated? +- Author, assignee? +- Important details? +""" message_on_remove = "PR #{number}'s beta backport request has been removed." [notify-zulip."stable-nominated"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "Backport #{number} {title}" -message_on_add = "@*WG-prioritization* PR #{number} has been requested for stable backport." +message_on_add = """\ +@*WG-prioritization/alerts* PR #{number} has been requested for stable backport. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#StableBeta-nominations) +Prepare agenda entry: +- Why nominated? +- Author, assignee? +- Important details? +""" message_on_remove = "PR #{number}'s stable backport request has been removed." [notify-zulip."S-waiting-on-team"] required_labels = ["T-compiler"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "S-waiting-on-team #{number} {title}" -message_on_add = "@*WG-prioritization* PR #{number} is waiting on `T-compiler`." +message_on_add = """\ +@*WG-prioritization/alerts* PR #{number} is waiting on `T-compiler`. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#PR%E2%80%99s-waiting-on-team) +- Prepare agenda entry: + - What is it waiting for? + - Important details? +- Could be resolved quickly? Tag `I-nominated`. +""" message_on_remove = "PR #{number}'s is no longer waiting on `T-compiler`." [notify-zulip."P-critical"] -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "P-critical #{number} {title}" -message_on_add = "@*WG-prioritization* issue #{number} has been assigned `P-critical`." +message_on_add = """\ +@*WG-prioritization/alerts* issue #{number} has been assigned `P-critical`. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#P-critical-and-Unassigned-P-high-regressions) +- Notify people/groups? +- Assign if possible? +- Add to agenda: + - Assignee? + - Summary and important details? +- Other actions to move forward? +""" [notify-zulip."P-high"] required_labels = ["regression-from-stable-to-[bn]*"] # only nightly and beta regressions -zulip_stream = 227806 # #t-compiler/wg-prioritization +zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts topic = "P-high regression #{number} {title}" -message_on_add = "@*WG-prioritization* issue #{number} has been assigned `P-high` and is a regression." +message_on_add = """\ +@*WG-prioritization/alerts* issue #{number} has been assigned `P-high` and is a regression. + +# [Procedure](https://hackmd.io/WJ0G17DHTHGgv0OW9I2PxA?view#P-critical-and-Unassigned-P-high-regressions) +Is issue assigned? If not: +- Try to find an assignee? +- Otherwise add to agenda: + - Mark as unassigned. + - Summary and important details? +"""